akhauriyash/Code-Regression huggingface dataset:
import bisect
class UnionFind:

    # n要素で初期化
    def __init__(self,n):
        self.par = list(range(n))
        self.rank = [0]*n
        self.memo = {}

    # 木の根を求める
    def find(self,x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    # xとyの属する集合を併合
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return None
        
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # xとyが同じ集合に属するか否か
    def same(self,x,y):
        return self.find(x) == self.find(y)

if __name__ == '__main__':
    n,k,l = map(int,input().split())
    UF_k = UnionFind(n)
    UF_l = UnionFind(n)
    for i in range(k):
        p,q = map(int,input().split())
        UF_k.unite(p-1,q-1)
    for i in range(l):
        r,s = map(int,input().split())
        UF_l.unite(r-1,s-1)
    l = []
    dic = {}
    for i in range(n):
        tmp = (UF_k.find(i),UF_l.find(i))
        l.append(tmp)
        if tmp in dic:
            dic[tmp] += 1
        else:
            dic[tmp] = 1
    
    for fac in l:
        print(dic[fac],end=' ')
    



Measured memory_bytes: 125400
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int* cost = new int[n];
    for(int i =0; i < n; i++){
        cin >> cost[i];
    }
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(cost[1] - cost[0]);
    for(int i =2; i < n; i++){
        dp[i] = min(dp[i-1] + abs(cost[i]-cost[i-1]), dp[i-2] + abs(cost[i] - cost[i-2]));
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin>>n;
    vector <int> nums(n);
    for(int i=0;i<n;i++){
        cin>>nums[i];
    }
    sort(nums.begin(),nums.end());
    nums.push_back(-1);
    int tmp = nums[0];
    int cnt = 0, ans=0;
    for(int i=0;i<n+1;i++){
          if(nums[i]==tmp) cnt++;
          else{
              if(cnt%2==1) ans++;
              cnt=1;
              tmp = nums[i];
          }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
main(){
int x,y;cin>>x>>y;
for(int i=0;i<x*y;i++){
  string s;cin>>s;
  if(s=="snuke"){
    cout<<char(65+i%y)<<i/y+1<<endl;
    return 0;
  }
}
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1'000'000'009;

// 素数判定:O(sqrt(N))
const bool IsPrime(const LLONG N)
{
    if (N == 1) return false;
    for (LLONG d = 2; d * d <= N; ++d)
    {
        if (N % d == 0) return false;
    }
    return true;
}

int main()
{
	// Nが「2017に近い数」かどうかはO(log(N))でチェックできる
	// N <= 1e5 より，「2017に近い数」のリストを O(NlogN) で計算しておく

	int imos[100'000];
	imos[0] = 0;
	int sum = 0;
	for (int N = 1; N <= 100'001; N += 2)
	{
		if (IsPrime(N) && IsPrime((N + 1) / 2))
		{
			++sum;
		}
		imos[N / 2 + 1] = sum;
	}

	int Q; cin >> Q;
	REP(i, Q)
	{
		int li, ri; cin >> li >> ri;
		cout << imos[ri / 2 + 1] - imos[li / 2 - 1 + 1] << endl;
	}
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int INF = 1e9;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  rep(i, h) rep(j, w) cin >> s[i][j];

  queue<P> Q;
  vector<vector<int>> d(h, vector<int>(w, INF));
  d[0][0] = 1;
  Q.push(make_pair(0, 0));
  while (Q.size()) {
    P p = Q.front();
    Q.pop();
    rep(i, 4) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if (s[nx][ny] == '#' || d[nx][ny] != INF) continue;
      d[nx][ny] = d[p.first][p.second] + 1;
      Q.push(make_pair(nx, ny));
    }
  }
  int cw = 0;
  rep(i, h) rep(j, w) if (s[i][j] == '.') ++cw;
  int ans = -1;
  if (d[h-1][w-1] != INF) ans = cw - d[h-1][w-1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;
using ll = long long;
auto const INF = static_cast<ll>(1e9);
void a(){
    int a,b;
    int c[3] = {1,2,3};
    cin >> a >> b;
    for(int i:c){
        if(i==a||i==b)continue;
        cout <<i << endl;
        return;
    }
}

void b(){
    int n;
    string s,t;
    cin >> n;
    cin >> s >> t;
    for(int i=0;i<n;i++){
        cout << s[i] << t[i];
    }
}
int main()
{
    b();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1000000007;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double n;
	cin >> n;
	double cnt = 0;
	reps(i,n){
		if(i % 2 == 1) ++cnt;
	}
	cout << fixed << cnt / n<< '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  int N;
  cin>>N;
  int a,ans=0;
  vector<int> cnt(1e5+1);
  for(int i=0;i<N;i++){
    cin>>a;
    if(a>N) ans++;
    else cnt[a]++;
  }
  for(int i=1;i<=N;i++){
    if(cnt[i]>=i) ans+=cnt[i]-i;
    else ans+=cnt[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;

int deg[N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);
	REP(i,0,2)
	{
		int a,b;
		cin >> a >> b;
		deg[a]++;
		deg[b]++;
	}
	bool b = 1;
	REP(i,1,4)
	{
		if (deg[i] > 2) b = 0;
	}
	if (b) cout << "YES" << endl;
	else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
BB = list(map(int, input().split()))
ans = 0
for _ in range(N):
    aa = list(map(int, input().split()))
    if sum(aa[i]*BB[i] for i in range(M)) + C > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
n, m = map(int, input().split())
xs = sorted(set(map(int, input().split())))
ds = sorted([y - x for x, y in zip(xs, xs[1:])])
ds = ds[:max(0, len(ds) - n + 1)]
if len(ds) > 0:
    print(sum(ds))
else:
    print(0)

Measured memory_bytes: 18952
#include <stdio.h>

int main(void)
{
	int c1, c5, c10, c50, c100, c500;
	int sum;
	
	scanf("%d %d %d %d %d %d", &c1, &c5, &c10, &c50, &c100, &c500);
	
	c5   = c5   * 5;
	c10  = c10  * 10;
	c50  = c50  * 50;
	c100 = c100 * 100;
	c500 = c500 * 500;
	
	sum = c1 + c5 + c10 + c50 + c100 + c500;
	
	if (sum >= 1000){
		printf("1\n");
	}
	else {
		printf("0\n");
	}
	
	return (0);
}

Measured memory_bytes: 584
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <iomanip>
#include <numeric>
#include <bitset>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

  int r;
  cin >> r;
  cout << r*r << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  cin >> n;
  string s;
  vector<int> alpha(26, 1e9);
  REP(i,n){
    cin >> s;
    REP(j,26) alpha[j] = min(alpha[j], (int)count(s.cbegin(), s.cend(), 'a'+j));
  }
  
  REP(i,26){
    REP(j,alpha[i]) cout << (char)('a'+i);
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    int H,W;cin>>H>>W;
    int info[10][10];
    rep(i,10)rep(j,10)cin>>info[i][j];
    rep(k,10)rep(i,10)rep(j,10){
        info[i][j]=min(info[i][j],info[i][k]+info[k][j]);
    }
    int ans=0;
    rep(i,H)rep(j,W){
        int p;cin>>p;
        if(p+1)ans+=info[p][1];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#define DEBUG
#include <iostream>
#include <vector>
#include <bitset>
#include <math.h>
using namespace std;
typedef long long int ll;
ll digit_xor(ll const a, int const digit);
ll sum_xor(ll const a);

/** f(0, a) */
ll sum_xor(ll const x)
{
    ll sum = 0;
    ll cnt1 = (x + 1) / 2;
    sum = cnt1 % 2;
    if (x % 2 == 0)
        sum ^= x;

    // if (x < 0)
    // {
    //     return sum;
    // }

    // for (int i = 0; i < 50; i++)
    // {
    //     ll loop = (1ll << (i + 1));
    //     ll cnt = (x / loop) * (loop / 2);
    //     cnt += max(0ll, (x % loop) - (loop / 2) + 1);

    //     if (cnt % 2 == 1)
    //     {
    //         sum += (1ll << i);
    //     }
    // }
    return sum;
}

int main()
{
    ll a, b;
    cin >> a >> b;

    ll sum = sum_xor(b) ^ sum_xor(a - 1);
    cout << sum << endl;
}

Measured memory_bytes: 256
# ABC062 C - Chocolate Bar
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

h,w = nm()

if h==2 and w==2:
    print(1)
    exit()

s = h*w
s1 = 0
s2 = 0
s3 = 0
wm = w//2
hm = h//2
s_max = 0
s_min = 0
ans_1 = 10**10
ans_2 = 10**10
ans_3 = 10**10
ans_4 = 10**10

for i in range(1,h-1):
    s1 = i*w
    s2 = ((h-i)//2)*w
    s3 = s-s1-s2
    s_max = max(s1,s2,s3)
    s_min = min(s1,s2,s3)
    ans_1 = min(ans_1,s_max-s_min)

for i in range(1,h-1):
    s1 = i*w
    s2 = (h-i)*wm
    s3 = s-s1-s2
    s_max = max(s1,s2,s3)
    s_min = min(s1,s2,s3)
    ans_2 = min(ans_2,s_max-s_min)

for i in range(1,w-1):
    s1 = i*h
    s2 = ((w-i)//2)*h
    s3 = s-s1-s2
    s_max = max(s1,s2,s3)
    s_min = min(s1,s2,s3)
    ans_3 = min(ans_3,s_max-s_min)

for i in range(1,w-1):
    s1 = i*h
    s2 = (w-i)*hm
    s3 = s-s1-s2
    s_max = max(s1,s2,s3)
    s_min = min(s1,s2,s3)
    ans_4 = min(ans_4,s_max-s_min)

print(min(ans_1,ans_2,ans_3,ans_4))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;

int main(){
    int A,B;
    cin >> A >> B;
    vector<long long int> T(A);
    for(int i = 0; i < A; i++){
        cin >> T.at(i);
    }
    sort(T.begin(),T.end());
    if(A-B < 0){
        cout << "0" << endl;
    }
    else{
        long long int sum = 0;
        for(int i = 0; i < A-B; i++){
            sum += T.at(i);
        }
        cout << sum << endl;
    }


}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;

/*-------------------Define Start-------------------*/
typedef bool BL;    					// 布尔类型
typedef char SB;    					// 有符号1字节,8位
typedef unsigned char UB;    			// 无符号1字节,8位
typedef short SW;    					// 有符号短整型,16位
typedef unsigned short UW;    			// 无符号短整型,16位
typedef long SDW;    					// 有符号整型,32位
typedef unsigned long UDW;   			// 无符号整型,32位
typedef long long SLL;    				// 有符号长整型,64位
typedef unsigned long long ULL;			// 无符号长整型,64位
typedef char CH;    					// 单个字符
typedef float R32;    					// 单精度浮点数
typedef double R64;    					// 双精度浮点数

#define Rep(i, n) for (register SDW i = 0; i < (n); ++i)
#define For(i, s, t) for (register SDW i = (s); i <= (t); ++i)
#define rFor(i, t, s) for (register SDW i = (t); i >= (s); --i)
#define foreach(i, c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,0x7f,sizeof(a))
#define LOWBIT(x) ((x)&(-x))

#define MP make_pair
#define PB push_back
#define ft first
#define sd second
#define ALL(x) x.begin(),x.end()

#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl

const ULL mod = 1e9 + 7;				//常用模数(可根据题目需要修改)
const ULL inf = 0x7fffffff;				//用来表示无限大
const ULL infLL = 0x7fffffffffffffffLL;	//用来表示无限大
/*-------------------Define End-------------------*/

const UDW maxN = 1e6 + 7;
string N;
SDW dp[maxN][2]; 
SDW ans;

void input(){
	cin >> N;
}

void solve(){
	dp[1][0] = N[N.size() - 1] - '0';
	dp[1][1] = 11 - N[N.size() - 1] + '0'; 
	
	For(i, 2, N.size()) {
		SDW Y = N[N.size() - i] - '0';

		dp[i][0] = min(Y + dp[i - 1][0], Y + dp[i - 1][1]);
		dp[i][1] = min(1 + 10 - Y + dp[i - 1][0], 1 + 10 - (Y + 1) + dp[i - 1][1] - 1);
	}
	
	ans = min(dp[N.size()][0], dp[N.size()][1]);
}

void output(){
	cout << ans << endl;
}

int main() {
	input();
	solve();
	output();
	return 0;
}


Measured memory_bytes: 17028
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        b.at(i)=a.at(i);
    }
    sort(b.begin(),b.end());
    for(int i=0;i<n;i++){
        if(b.at(n-1)!=a.at(i))cout << b.at(n-1) << endl;
        else cout << b.at(n-2) << endl;
    }
    return 0;
}

Measured memory_bytes: 4780
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var nk = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            Console.WriteLine(((int)Math.Log(nk[0], nk[1])) + 1);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define crap ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846264338327950288419716939937510
#define pb(a) push_back(a)
#define pf(a) push_front(a)
using namespace std;

int main()
{
	crap;
	char ch;
	cin >> ch;
	if(ch>='A' && ch<='Z')
		cout << 'A' endl;
	else
	{
		cout << 'a' endl ;
	}
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

#define MOD 10000

int N ,K ;
int plan[ 100 + 1 ][ 4 + 1 ][ 4 + 1 ] ;
int _now[ 100 + 1 ] ;

int Cnt( int day ,int prev ,int now )
{
	if( day == N )
	{
		return 1 ;
	}

	int *next = &_now[ day ] ;
	if( *next > 0 )
	{
		if( prev == now && now == *next )
		{
			return 0 ;
		}
		
		return Cnt( day + 1 ,now ,*next ) ;
	}

	int *value = &plan[ day ][ prev ][ now ] ;
	if( *value > 0 )
	{
		return *value ;
	}

	int nex ,cnt = 0 ;
	for( nex = 1 ; nex <= 3 ; ++nex )
	{
		if( prev != now || now != nex )
		{
			cnt = (cnt + Cnt( day + 1 ,now ,nex )) % MOD ;
		}
	}

	return (*value = cnt) ;
}


int main( void )
{
	scanf( "%d %d" ,&N ,&K ) ;

	++N ;

	int i ,day ,menu ;
	for( i = 0 ; i < K ; ++i )
	{
		scanf( "%d %d" ,&day ,&menu ) ;

		_now[ day ] = menu ;
	}

	printf( "%d\n" ,Cnt( 1 ,0 ,0 )) ;

	return 0 ;
}


Measured memory_bytes: 2100
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from collections import deque

class Dinic:
    def __init__(self,n,edges):
        self.n=n
        self.edges=[[] for _ in range(n)]
        self.iter=[0]*n
        self.level=None
        self.graph(edges)
    def graph(self,E):
        edges=self.edges
        for fr,to,cap in E:
            edges[fr].append([to,cap,len(edges[to])])
            edges[to].append([fr,0,len(edges[fr])-1])
    def maxflow(self,source,sink):
        max_flow=0
        while True:
            self.bfs(source)
            if self.level[sink]<0:
                return max_flow
            self.iter=[0]*self.n
            flow=self.dfs(source,sink,float('inf'))
            while flow:
                max_flow+=flow
                flow=self.dfs(source,sink,float('inf'))
    def bfs(self,source):
        edges=self.edges
        level=[-1]*self.n
        level[source]=0
        q=deque([source])
        while q:
            fr=q.popleft()
            for to,cap,_ in edges[fr]:
                if cap>0>level[to]:
                    level[to]=level[fr]+1
                    q.append(to)
        self.level=level
    def dfs(self,source,sink,flow):
        if source==sink:
            return flow
        while self.iter[source]<len(self.edges[source]):
            to,cap,rev=self.edges[source][self.iter[source]]
            if cap>0 and self.level[source]<self.level[to]:
                f=self.dfs(to,sink,min(flow,cap))
                if f:
                    self.edges[source][self.iter[source]][1]-=f
                    self.edges[to][rev][1]+=f
                    return f
            self.iter[source]+=1
        return 0

def BipartiteMatching(Pairs,a,b):
    Edges=[]
    for x,y in Pairs:
        Edges.append((x+1,a+y+1,1))
    for x in range(a):
        Edges.append((0,x+1,1))
    for y in range(b):
        Edges.append((a+y+1,a+b+1,1))
    solver=Dinic(a+b+2,Edges)
    return solver.maxflow(0,a+b+1)

n=int(input())
R=[list(map(int,input().split())) for _ in range(n)]
B=[list(map(int,input().split())) for _ in range(n)]
Pairs=[]
for i in range(n):
    for j in range(n):
        if R[i][0]<B[j][0] and R[i][1]<B[j][1]:
            Pairs.append((i,j))
print(BipartiteMatching(Pairs,n,n))

Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;
const int mod = 1e9 + 7;

int main(){
    vector<int> x(5);
    for (int i = 0; i < 5; ++i) {
        cin >> x[i];
    }
    for (int i = 0; i < 5; ++i) {
        if (x[i] == 0) cout << i+1 << endl;
    }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    int a, b; cin >> a >> b;
    string s; cin >> s;
    if(s[a] != '-') { cout << "No" << endl; return 0; }
    rep(i, a) if(!isdigit(s[i])) { cout << "No" << endl; return 0; }
    FOR(i, a+1, a+b+1) if(!isdigit(s[i])) { cout << "No" << endl; return 0; }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>


double max(double a, double b) {
	return a > b ? a : b;
}

int main() {
	
	while(1) {
		double bairitu[101][101] = {0.0};
		double dp[101][101] = {0.0}; // dp[i][j] := i回肥料を与えて、直前の肥料がjのときの最大身長
		int N, M, i, j, k;
		scanf("%d %d", &N, &M);
		if (N == 0) break;
		for(i = 0; i < N; i++) {
			for(j = 0; j < N; j++) {
				scanf("%lf", &bairitu[i][j]);
			}
		}
		
		
		for(j = 0; j < N; j++) {
			dp[1][j] = 1.0;				
		}
		

		for(i = 1; i < M; i++) {
			for(j = 0; j < N; j++) {
				for(k = 0; k < N; k++) {
					dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] * bairitu[j][k]);
				}
			}
		}

		double ans = 0.0;
		for(j = 0; j < N; j++) {
			ans = max(ans, dp[M][j]);
		}
		printf("%3.2f\n", ans);
	}
	return 0;
}

Measured memory_bytes: 828
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) for(int i = a, i <= b; i++)
#define REPD(i, a, b) for(int i = a, i >= b; i--)
#define SQ(a) (a) * (a)
#define all(c) c.begin(), c.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); ++it)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define sz(a) int((a).size())
#define endl "\n"
#define PI 3.1415926535
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(t) int x; cin >> t; while(t--)
using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void fio()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int32_t main()
{
	fio();
	int h, w, k;
	cin >> h >> w >> k;
	int ans = 0;
	string s[6];
	for (int i = 0; i < h; i++)
		cin >> s[i];
	for (int i = 0; i < (1 << h); i++)
	{
		for (int j = 0; j < (1 << w); j++)
		{
			int cnt = 0;
			for (int k = 0; k < h; k++)
			{
				for (int l = 0; l < w; l++)
				{
					if ((i & (1 << k)) || (j & (1 << l)))
						continue;
					cnt += s[k][l] == '#';
				}
			}
			if (cnt == k)
				ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
using namespace std;
#include <bits/stdc++.h>
#define rep(i, k, n) for(int i = k; i < (n); i++)
using ll = long long;


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(m);
    vector<char> c(m);
    rep(i, 0, m){
        cin >> s[i] >> c[i];
        s[i] --;
    }
    int ans = -1;
    rep(i, 0, 1000){
        string si = to_string(i);
        if (si.size() != n) continue;
        bool check = 1;
        for(auto i = 0; i < m; ++i){
            if (si[s[i]] != c[i]){
                check = 0;
                break;
            }
        }
        if (check){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359;
#define inf (1 << 21);
#define mod 1000000007;

int main() {
    ll N, K; cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    vector<bool> J(N, false); //町iを訪れたかどうか
    ll now = 1, next, cnt = 0;
    J.at(0) = true;
    while (true) {
        next = A.at(now - 1);
        now = next;
        cnt++;
        if (J.at(next - 1) == false) {
            J.at(next - 1) = true;
        }
        else {
            break;
        }
        if (cnt == K) {
            break;
        }
    }
    ll loop = 0;
    J.at(now - 1) = false;
    while (cnt < K) {
        next = A.at(now - 1);
        now = next;
        loop++;
        if (J.at(next - 1) == true) {
            J.at(next - 1) = false;
        }
        else {
            break;
        }
    }
    K -= cnt;
    ll n;
    if (loop != 0) {
        n = K % loop;
    }
    else {
        n = K;
    }
    for (int i = 0; i < n; i++) {
        next = A.at(now - 1);
        now = next;
    }
    cout << now << endl;
    return 0;
}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    int li;
    vector<int> L;
    for(int i=0;i<N;i++){
        cin >> li;
        L.push_back(li);
    }
    for(int i=N;i<8;i++){
        L.push_back(0);
    }

    int vmin = numeric_limits<int>::max();
    for(int bit=0; bit < (1<<16); bit++){
        int lA = 0;
        int lB = 0;
        int lC = 0;
        int MP = 0;
        for(int i = 0; i < 8; i++){
            if     (((bit>>2*i)&3) == 0){ MP += lA==0? 0:10; lA += L[i];}
            else if(((bit>>2*i)&3) == 1){ MP += lB==0? 0:10; lB += L[i];}
            if     (((bit>>2*i)&3) == 2){ MP += lC==0? 0:10; lC += L[i];}
        }
        if(lA == 0) continue;
        if(lB == 0) continue;
        if(lC == 0) continue;
        MP += abs(lA - A);
        MP += abs(lB - B);
        MP += abs(lC - C);
        vmin = min(vmin, MP);
    }

    cout<<vmin<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n; cin >> n;

    vector<int> a(n+1);
    vector<int> b(n);
    for (int i = 0; i < n+1; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    long long beaten1 = 0;
    for (int i = n; i >= 1; i--) {
        int diff = min(a[i], b[i-1]);
        int diff2 = min(a[i-1], abs(b[i-1] - diff));
        beaten1 += diff;
        beaten1 += diff2;
        a[i-1] -= diff2;
    }

    cout << beaten1 << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

bool dislike(int N, const vector<int> &D){
    while(N > 0){
        if(find(D.begin(), D.end(), N % 10) != D.end()) return true;
        N /= 10;
    }
    return false;
}

int main(void){
    int N, K;
    cin >> N >> K;
    vector<int> D(K);
    for(int i = 0; i < K; i++) cin >> D[i];
    while(dislike(N, D)) N++;
    cout << N << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){

  int n;//参加人数
  long int k;//初めのポイント
  int q;//正解の数
  int i,j;

  scanf("%d%ld%d",&n,&k,&q);

  int a[q];//正解した穂との番号
  int motiten[n];//持ち点
  int b[n];//n番目のひとがが加算される点数

  for(i=0;i<n;i++){
    b[i]=0;
  }

  for(i=0;i<q;i++){
    //正解した人の番号
    scanf("%d",&a[i]);
    b[a[i]-1]++;
    }



  for(i=0;i<n;i++){
    motiten[i]=k-q+b[i];
  }

  for(i=0;i<n;i++){
    if(motiten[i]>0)
    printf("Yes\n");
    else
    printf("No\n");
  }


return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
int main(void)
{//A=65 B=66 C=67                                                                    
  int a,b,c=65;
  char x, y;
  while(scanf(" %c,%c",&x,&y)!=EOF){
    if (x==c)
      c=y;

    else if (y==c)
      c=x;
  }

  x=c;

  printf("%c\n",x);


  return 0;
}

Measured memory_bytes: 540
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<u64> = procon_read();
	let a = v[0];
	let b = v[1];
	let x = v[2];
	if a == 0 {
		println!("{}", b/x + 1);
	}else{
		println!("{}", b/x + 1 - (a - 1)/x - 1);
	}
}

Measured memory_bytes: 4352
#include <stdio.h>
 int main(void)
  {
    int a,b,i;
 a=0;b=0;i=0;
 scanf("%d",&a);
     for(i=0;i<=a;i++)                                                        
  b=b+i;
  
 printf("%d\n",b);
  return 0;
  }


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;
    ll n = s.size();

    if(s[0] == s[n-1]) {  // 最初と最後の文字が同じとき
        // 最終的には奇数文字残る
        if(n%2 == 0) {
            out("First");
        }
        else {
            out("Second");
        }
    }
    else {  // 最初と最後の文字が異なるとき
        // 最終的には2文字残る
        if(n%2 == 1) {
            out("First");
        }
        else {
            out("Second");
        }
    }   

    re0;
}

Measured memory_bytes: 512
import sys
N,Y=input().split(' ')
N=int(N)
Y=int(Y)
tmp=Y
x=int(tmp/10000)
tmp-=x*10000
y=int(tmp/5000)
tmp-=y*5000
z=int(tmp/1000)
 
while True:
  sum=x+y+z
  if(sum==N):break
  elif(N-sum>=4 and y>=1):
    y-=1
    z+=5
  
  
  elif(x>=1):
    x-=1
    y+=2
  else:
    print('-1 -1 -1')
    sys.exit()
print(x,y,z)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, b, k;
    cin >> a >> b >> k;

    vector<bool> flag(b-a+1, false);
    for (int i = 0; i < k; i++) {
        flag[i] = true;
    }
    for (int i = flag.size()-k; i < flag.size(); i++) {
        flag[i] = true;
    }

    for (int i = 0; i < flag.size(); i++) {
        if (flag[i])
            cout << a+i << endl;
    }
}

Measured memory_bytes: 125092
#include <iostream>

using namespace std;

int main(void){

  int a, b;
  cin >> a >> b;
  if(a > b){
    cout << "a > b" << endl;
  }else if(a < b){
    cout << "a < b" << endl;
  }else{
    cout << "a == b" << endl;
  }

  return 0;
}

Measured memory_bytes: 1156
x1, y1, x2, y2 = gets.chomp!.split.map(&:to_i)
x_dist = x2 - x1
y_dist = y2 - y1
y3 = y2 + x_dist
x3 = x2 - y_dist
y4 = y3 - y_dist
x4 = x3 - x_dist
p x3, y3, x4, y4

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int l[105];
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
		scanf("%d",&l[i]);
	int ans = 0;
	for(int i=0;i<n-2;i++)
		for(int j=i+1;j<n-1;j++)
			for(int k=j+1;k<n;k++)
				if(l[i] != l[j] && l[j] != l[k]  && l[k] != l[i] && l[i]+l[j] > l[k] && l[i]+l[k] > l[j] && l[j]+l[k] > l[i]) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
int main(){
    double x1, y1, x2, y2, ans;
    cin >> x1 >> y1 >> x2 >> y2;
    ans = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
    cout << fixed << setprecision(6) << ans << endl;
    return 0;
}


Measured memory_bytes: 3296
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int h,w;
bool a[55][55];
bool isrange(int x,int y){
    return 0<=x and x < h and 0<=y and y < w;
}
bool used[55][55];
int d[55][55];
int dx[] = {-1,0,0,1};
int dy[] = {0,1,-1,0};
int main(){
    cin >> h >> w;
    string s;
    int cnt = 0;
    rep(i,h){
        cin >> s;
        rep(j,w){
            if(s[j] == '.'){
                a[i][j] = true;
            }else{
                cnt++;
            }
        }
    }
    queue<pii>q;
    q.push(pii(0,0));
    used[0][0] = true;
    while(!q.empty()){
        pii k = q.front();
        q.pop();
        int x = k.first;
        int y = k.second;
        rep(i,4){
            int xx = x+dx[i];
            int yy = y+dy[i];
            if(isrange(xx,yy)and a[xx][yy] and !used[xx][yy]){
                d[xx][yy] = d[x][y]+1;
                used[xx][yy] = true;
                q.push(pii(xx,yy));
            }
        }
    }
    if(!used[h-1][w-1]){
        cout << -1 << endl;
        return 0;
    }else{
        cout << h*w-cnt-d[h-1][w-1]-1 << endl;
        return 0;
    }
}

Measured memory_bytes: 888
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,n) for(int j=0;j<n;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<ll> ve;
typedef vector<pair<int, int> > vepa;
typedef set<string>se;
typedef map<int,int> mpp;
const ll N=1024,OO=1e14,MOD=1e9+7;
const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};
ll TC,n,m,k,a,b,cnt,sum,mx,mn,arr[N];
bool f,vis[N];
int main(){
   IOS;
   cin>>n;
   rep(i,n&&cin>>arr[i]);
   sort(arr,arr+n);
   rep(i,n)
   {
        for(int j=i+1 ; j<n&&!f ; j++)
       {

           for(int k=j+1;k<n;k++)
           {

               if(arr[i]+arr[j]>arr[k] && arr[i]!=arr[j]&&arr[j]!=arr[k]&&arr[k]!=arr[i] )cnt++;
            }
       }
   }
   cout<<cnt;

go;
}


Measured memory_bytes: 3660
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}


int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  double t, x;
  cin >> t >> x;
  cout << setprecision(12);
  cout << t / x << endl;
	return 0;
}


Measured memory_bytes: 256
s = gets.chomp

i = 0
ri = s.length - 1
xdiff = 0
res = 0

while i < ri
  while i < s.length && s[i] == "x"
    xdiff += 1
    i += 1
  end
  while ri >= 0 && s[ri] == "x"
    xdiff -= 1
    ri -= 1
  end
  
  if i < s.length && ri >= 0
    if s[i] != s[ri]
      res = -1
      break
    end
    
    res += xdiff.abs
    xdiff = 0
    
    i += 1
    ri -= 1
  end
end

puts res

Measured memory_bytes: 2044
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#pragma gcc target ("avx2")
#pragma gcc optimization ("Ofast")
#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	string s;
	scans(s);
	ll ans = 0;
	bool flagi = false, flagj = false;
	rep(i, 10) {
		rep(j, 10) {
			rep(k, 10) {
				flagi = false, flagj = false;
				rep(l, n) {
					if (not flagi) {
						if (s[l] - '0' == i)flagi = true;
					}
					else if (not flagj) {
						if (s[l] - '0' == j)flagj = true;
					}
					else {
						if (s[l] - '0' == k) {
							++ans;
							break;
						}
					}
				}
			}
		}
	}
	printf("%lld\n", ans);

	Please AC;
}

Measured memory_bytes: 256
// Codeforces 1.12.6
// AtCoder 1.6
// Paiza 1.7.3

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type in struct {
	Scanner *bufio.Scanner
}

func (in *in) s() string {
	in.Scanner.Scan()
	return in.Scanner.Text()
}

func (in *in) i() int64 {
	return in.irad(10)
}

func (in *in) irad(base int) int64 {
	i, _ := strconv.ParseInt(in.s(), base, 64)
	return i
}

func (in *in) ss(n int64) []string {
	a := make([]string, n)
	for i := range a {
		a[i] = in.s()
	}
	return a
}

func (in *in) is(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = in.i()
	}
	return a
}

func stdin() in {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	max := 200000
	buf := make([]byte, max)
	scn.Buffer(buf, max)
	return in{Scanner: scn}
}

func max(a int64, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func min(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func abs(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func z() int64 {
	return int64(0)
}

func farr(slice []int64) string {
	ret := make([]string, len(slice))
	for i, x := range slice {
		ret[i] = strconv.FormatInt(x, 10)
	}
	return strings.Join(ret, " ")
}

func fbool(b bool) string {
	if b {
		return "Yes"
	}
	return "No"
}

func up(s string) string {
	return strings.ToUpper(s)
}

func low(s string) string {
	return strings.ToLower(s)
}

func main() {
	in := stdin()
	n, k := in.i(), in.i()
	a := in.is(n)

	// solve here
	MOD := int64(1000000007)
	ans := z()
	for i := z(); i < n; i++ {
		bef := z()
		for j := int64(0); j < i; j++ {
			if a[i] > a[j] {
				bef++
			}
		}
		aft := z()
		for j := i + 1; j < n; j++ {
			if a[i] > a[j] {
				aft++
			}
		}
		ans += aft * k % MOD
		ans %= MOD
		ans += k * (k - 1) / 2 % MOD * ((bef + aft) % MOD) % MOD
		ans %= MOD
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
 
/*--------------------template--------------------*/
 
 
 
 
int main() {
    string t;
    cin >> s >> t;
    if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 2e5 + 5;

int n, k;
int a[N];

bool valid(int x) {
	ll need = 0;
	for (int i = 0; i < n; i++) {
		need += a[i] / x - !bool(a[i] % x);
	}
	return need <= k;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int st = 1, en = 1e9;
	while (st < en) {
		int mid = st + (en - st) / 2;
		if (!valid(mid))
			st = mid + 1;
		else
			en = mid;
	}
	cout << st << endl;
	return 0;
}


Measured memory_bytes: 4396
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

// #define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::lowest();
using namespace std;

void solve() {
  int N, M;
  cin >> N >> M;

  vector<bool> v(M, false);

  vector<pair<int, int>> A, B;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    A.emplace_back(a, i);
    B.emplace_back(b, i);
  }

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  int ans = 0;
  int idxa = 0;
  for (auto &b : B) {
    if (v[b.second]) {
      continue;
    }

    ans++;
    while (idxa < A.size() && A[idxa].first < b.first) {
      v[A[idxa].second] = true;
      idxa++;
    }
  }

  cout << ans << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 2036
N = int(input())
A = list(map(int,input().split()))
over_value = 10 ** 18
total = 1
cnt = 0
while cnt < N:
    total *= A[cnt]
    if total > over_value:
        total = -1
        break
    cnt += 1
    
for i in range(N):
    if A[i] == 0:
        total = 0
print(total)

Measured memory_bytes: 21476
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [int(input()) for i in range(m)]

c = [0] * n
for i in range(n):
    for j in range(m):
        c[i] += a[i][j] * b[j]
    print(c[i])


Measured memory_bytes: 6016
piza_a, piza_b, piza_ab, x, y = gets.split(" ").map(&:to_i)
#piza_ab2枚でabそれぞれ一枚
#aの最小のコスト
a_min = [piza_a, piza_ab*2].min
b_min = [piza_b, piza_ab*2].min
ab_min = [piza_a + piza_b, piza_ab*2].min

total_cost = ab_min * ([x, y].min)
if x > y
  total_cost = total_cost + a_min * (x - y)
elsif x < y
  total_cost = total_cost + b_min * (y - x)
else
end
puts total_cost

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	string T;
	cin >> T;
	rep(i, T.size()) {
		if (T[i] == '?')
			T[i] = 'D';
	}
	cout << T << endl;
	return 0;
}

Measured memory_bytes: 3756
import sys
input = sys.stdin.readline

# D - Moving Piece
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

# 問題文とインデックスの位置を揃える
P.insert(0, 0)
C.insert(0, 0)

# マス目を周期ごとに分割する
groups = []
appeared = set()

for i in range(1, N + 1):
	if not i in appeared:
		group = []
		s = set()
		j = i

		while not j in s:
			group.append(j)
			s.add(j)
			appeared.add(j)
			j = P[j]

		groups.append(group)

minus_max = -sys.maxsize
ans = minus_max

# 周期ごとにハイスコアを算出
for group in groups:
	n = len(group)

	# スタート位置を1マスずつズラす
	for g in group:
		score = 0
		max_score = minus_max
		scores = []
		scores.append(minus_max)
		Pi = P[g]

		for j in range(n):
			score += C[Pi]
			max_score = max(max_score, score)
			scores.append(max_score)
			Pi = P[Pi]

		if K > n and score > 0:
			s = scores[K % n] + score * (K // n)
			ans = max(ans, s)

			s = scores[n] + score * (K // n - 1)
			ans = max(ans, s)
		elif K > n:
			ans = max(ans, scores[n])
		else:
			ans = max(ans, scores[K])

print(ans)

Measured memory_bytes: 80856