akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int dp[]={};
int main(){
    fast_io
    
    string s;
    cin>>s;
    bool flag=false;
    int n=s.size();
    int left=0, right=n-1;
    while(left<=right){
        if(s[left]!=s[right]){
            cout<<"No"<<endl;
            return 0;
        }
        left++;
        right--;
    }
    left=0;
    right=(n-1)/2-1;
    while(left<=right){
        if(s[left]!=s[right]){
            cout<<"No"<<endl;
            return 0;
        }
        left++;
        right--;
    }
    left=(n+3)/2-1;
    right=n-1;
    while(left<=right){
        if(s[left]!=s[right]){
            cout<<"No"<<endl;
            return 0;
        }
        left++;
        right--;
    }

    cout<<"Yes"<<endl;
    return 0;
}

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

Measured memory_bytes: 596
#include <stdio.h>
#include <queue>

using namespace std;

queue<int> que;
int h,w;
char s[55][55];
int d[55][55]={};
bool visited[55][55]={};
int vecx[]={1,-1,0,0};
int vecy[]={0,0,1,-1};

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

void bfs(int x,int y)
{
    for(int i=0;i<4;i++)//上下左右やる
    {
        if(vecx[i]+x<0||vecx[i]+x>h-1||vecy[i]+y<0||vecy[i]+y>w-1) continue;
        if(s[x+vecx[i]][y+vecy[i]]=='#') continue;
        if(visited[x+vecx[i]][y+vecy[i]]) continue;
        d[x+vecx[i]][y+vecy[i]]=max(d[x+vecx[i]][y+vecy[i]],d[x][y]+1);
        que.push(x+vecx[i]);
        que.push(y+vecy[i]);
        visited[x+vecx[i]][y+vecy[i]]=true;
    }
}



int main()
{
    scanf("%d %d",&h,&w);
    for(int i=0;i<h;i++)
    {
        scanf("%s",s[i]);
    }

    
    que.push(0);
    que.push(0);
    while(!que.empty())
    {
        int tmpx=que.front();
        que.pop();
        int tmpy=que.front();
        que.pop();
        // printf("bfs(%d,%d)\n",tmpx,tmpy);
        bfs(tmpx,tmpy);
    }
    if(d[h-1][w-1]==0) printf("-1\n");
    else
    {
        int ans=0;
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                if(s[i][j]=='.')
                {
                    ans++;
                }
            }
        }
        printf("%d\n",ans-d[h-1][w-1]-1);
    }
}

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int A,B,C; R(A,B,C);
    W(min(B/A,C));
    return 0;
}


Measured memory_bytes: 256
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 500+10;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

string s[maxn], ans[2][maxn];

int H, W;

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	// 
	cin >> H >> W;
	for (int i = 0; i < H; i++)
		cin >> s[i];
	//
	for (int i = 0; i < H; i++) 
		for (int t = 0; t < W; t++) {
			ans[0][i] += ((i % 2) ? "." : "#");
			ans[1][i] += ((i % 2) ? "#" : ".");
		}
	for (int i = 0; i < H; i++) {
		int num = 0;
		for (int t = 0; t < W; t++)
			if (s[i][t] == '#') {
				num++;
				ans[1 - i % 2][i][t] = '#';
			}
		if (num == 0) {
			if (i % 2) {
				ans[1 - i % 2][i][0] = '#';
				ans[i % 2][i][0] = '.';
			}
			else {
				ans[1 - i % 2][i][W - 1] = '#';
				ans[i % 2][i][W - 1] = '.';
			}
		}
	}
	//
	for (int i = 0; i < H; i++)
		cout << ans[0][i] << "\n";
	cout << "\n";
	for (int i = 0; i < H; i++)
		cout << ans[1][i] << "\n";
}



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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

main(){

  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  cin>>a;

  map<ll,ll> cnt;
  for(auto x:a)cnt[x]++;
  vector<ll> b;
  for(auto x:cnt)b.emplace_back(x.second);
  sort(b.begin(),b.end(),greater<>());
  ll ans=0;
  for(ll i=k;i<b.size();++i){
    ans += b[i];
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 16500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int a; cin >> a;
        if (a % 2 == 1 && i % 2 == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>

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

using namespace std;

int main(){
	int n,T,S; scanf("%d%d%d",&n,&T,&S);
	int a[3000],b[3000];
	rep(i,n) scanf("%d%d",a+i,b+i);

	// dp[t][i+1] := ( 時刻 t で夜店 0..i だけを考えたときの満足度 )
	static int dp[3001][3001];
	rep(i,n+1) dp[0][i]=0;
	for(int t=1;t<=T;t++) rep(i,n+1) {
		// 何もせずに 1 秒すごす
		dp[t][i]=dp[t-1][i];
		if(i>0){
			// 夜店 i を見逃す
			dp[t][i]=max(dp[t][i],dp[t][i-1]);
			// 夜店 i で遊ぶ
			if(t-b[i-1]>=0 && !(t-b[i-1]<S && S<t)){
				dp[t][i]=max(dp[t][i],dp[t-b[i-1]][i-1]+a[i-1]);
			}
		}
	}

	printf("%d\n",dp[T][n]);

	return 0;
}

Measured memory_bytes: 36232
function main()
    N = parse(Int, readline()) 
    a = zeros(Int, N)
    b = zeros(Int, N)
    c = zeros(Int, N)
    for i in 1:N
        x, y = map(x -> parse(Int, x), split(readline()))
        a[i] = x
        b[i] = y
        c[i] = x + y
    end
    c_index = sortperm(c, rev=true)
    ans = 0
    for i in 1:N
        if i % 2 == 0
            ans -= b[c_index[i]]
        else
            ans += a[c_index[i]]
        end
    end
    print(ans)
end

main()

Measured memory_bytes: 155392
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

#include <iostream>
#include <vector>
using namespace std;

//重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
      // ここで所望の作業を行う
      for(ll itr:buf){
        cout << itr;
      }
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            permutation(i + 1, size, range_start, range_end);
        }
    }
}

int main(void)
{
  ll n, k, sum, ans = -pow(10,9)-1000, place, count, num, check, roop, roop_num;
  cin >> n >> k;
  vector<ll> P(n), C(n);
  vector<vector<ll>> Max(n, vector<ll> (n, 0));
  RAP(i,n){
    cin >> P[i];
    P[i]--;
  }
  RAP(i,n){
    cin >> C[i];
  }
  RAP(i,n){
    place = i;
    sum = 0;
    roop = place;
    RAP(j,n){
      place = P[place];
      sum += C[place];
      if(j==0){
        Max[i][j] = sum;
      }else{
        Max[i][j] = max(Max[i][j-1],sum);
      }
      if(roop == place){
        roop_num = j+1;
        break;
      }
    }
    if(k<=roop_num){
      ans = max(ans, Max[i][k-1]);
    }else{
      if(sum<=0){
        ans =max(ans,Max[i][roop_num-1]);
      }else{
        count = k/roop_num;
        num = k%roop_num;
        if(num == 0){
          check = max(count*sum, (count-1)*sum+Max[i][roop_num-1]);
        }else{
          check = max(count*sum+Max[i][num-1], (count-1)*sum+Max[i][roop_num-1]);
        }
        ans = max(ans, check);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 198828
// C.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	int n, q;
	cin >> n;
	string s;
	cin >> s;
	cin >> q;
	vector<int> k(q);
	for (int i = 0; i < q; ++i) {
		cin >> k[i];
	}
	int sz = (int)s.length();
	vector<LL> rc(n);
	for (int i = 0; i < q; ++i) {
		LL ans = 0, dc = 0, mc = 0, mt = 0;
		for (int j = 0; j < sz; ++j) {
			if (j >= k[i] && s[j - k[i]] == 'D') {
				--dc;
				mt -= mc;
			}
			if (j >= k[i] && s[j - k[i]] == 'M') {
				--mc;
			}
			switch (s[j]) {
			case 'D':
				++dc;
				break;
			case 'M':
				++mc;
				mt += dc;
				break;
			case 'C':
				ans += mt;
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 9220
#include <cstdio>
using namespace std;

long long N, K;
long long cnt;

long long maxlld(long long a, long long b)
{
	return a > b ? a : b;
}

int main(void)
{
	int n, k;
	scanf("%d %d", &n, &k);
	N = (long long)n;
	K = (long long)k;
	
	if (K == 0)
		printf("%lld", N * N);
	else
	{
		cnt = 0LL;
		for (long long b = K + 1; b <= N; ++b)
		{
			long long temp = (b - K) * (N / b);
			if (N % b > 0)
				temp += maxlld(0, N % b - K + 1);
			//printf("b = %d then pile = %d, cnt = %lld\n", b, N / b, temp);
			cnt += temp;
		}
		printf("%lld", cnt);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

int w, h;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
bool flg[32][32];
char t[32][32];

int main(){
  while(cin >> w >> h, w || h){
    int rem = 0;

    for(int i = 0; i < h; i++){
      cin >> t[i];
      for(int j = 0; j < w; j++){
        if(t[i][j] == 'E') { t[i][j] = 0; rem++; }
        if(t[i][j] == 'N') { t[i][j] = 1; rem++; }
        if(t[i][j] == 'W') { t[i][j] = 2; rem++; }
        if(t[i][j] == 'S') { t[i][j] = 3; rem++; }
      }
    }

    int i;
    int ans = -1;

    for(i = 0; rem != 0 && i <= 180; i++){
      for(int x = 0; x < w; x++){
        for(int y = 0; y < h; y++){
          if(t[y][x] < 4){
            for(int j = 0; j < 4; j++){
              int nd = (t[y][x] + j + 3) % 4;
              int nx = x + dx[nd];
              int ny = y + dy[nd];

              if(4 <= t[ny][nx] && (t[ny][nx] == '.' || t[ny][nx] == 'X')){
                t[y][x] = nd;
                break;
              }
            }
          }
        }
      }

      memset(flg, 0, sizeof(flg));

      for(int x = 0; x < w; x++){
        for(int y = 0; y < h; y++){
          if(t[y][x] == '.' || t[y][x] == 'X'){
            for(int j = 0; j < 4; j++){
              int nx = x + dx[j];
              int ny = y + dy[j];

              if(0 <= nx && nx < w && 0 <= ny && ny < h && t[ny][nx] == (j + 2) % 4 && !flg[ny][nx]){
                flg[ny][nx] = true;
                break;
              }
            }
          }
        }
      }

      for(int x = 0; x < w; x++){
        for(int y = 0; y < h; y++){
          if(flg[y][x]){
            int d = t[y][x];
            int nx = x + dx[d];
            int ny = y + dy[d];

            if(t[ny][nx] == 'X'){
              rem--;
            }
            else{
              t[ny][nx] = d;
            }
            t[y][x] = '.';
          }
        }
      }
    }

    if(i <= 180){
      cout << i << endl;
    }
    else{
      cout << "NA\n";
    }
  }
}

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

int main() {
  ll n; cin >> n;
  int ans = 0;
  while (n > 0) {
    int x = n % 10;
    n /= 10;
    if (n > 0) ans += 9;
    else ans += x;
    if (x != 9) n--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>

using namespace std;
 
int main() {
	int n, m; cin >> n >> m;
	vector<vector<bool> > s(m, vector<bool>(n));
	vector<int> p(m);
	int tmp;
	for (int i = 0; i < m; ++i) {
		int k;  cin >> k;
		for (int j = 0; j < k; ++j) {
			cin >> tmp;
			s[i][tmp - 1] = true;
		}
	}
	for (int i = 0; i < m; ++i) cin >> p[i];
	int ans = 0;
	for (int i = 0; i < (1 << n); ++i) {
		bool flag = true;
		for (int j = 0; j < m; ++j) {
			int cnt = 0;
			for (int k = 0; k < n; ++k)
				if ((i & (1 << k)) && s[j][k]) cnt++;
			if (cnt % 2 != p[j]) {
				flag = false;
				break;
			}
		}
		if (flag) ans++;
	}
	cout << ans <<endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int H,W,i,j;
  do{
    scanf("%d %d",&H,&W);
    if(H == 0 && W == 0)
      break;
    for(i=1;i <= H;i++){
      for(j=1;j <= W;j++){
    
	if((i+j) % 2 == 0){
	  printf("#");
      }
      if((i+j) % 2 != 0){
	printf("#");
	  }
      if(j == W){
	printf("\n");
      }
    }
  }
    printf("\n");
  }while(H <= 300 && W <= 300);
  return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
 
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)  for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define ALL(X)      (X).begin(),(X).end()
typedef long long LL;
 
using namespace std;
 
int main(void){
    int n;
    cin>>n;
    deque<int> de;
    REP(i,n){
        int a;
        cin>>a;
        if(i%2==0)
            de.push_back(a);
        else
            de.push_front(a);
    }
    if((n-1)%2==0)
        reverse(ALL(de));
    REP(i,n)
        cout<<de[i]<<" ";
    cout<<endl;
}

Measured memory_bytes: 2944
from collections import deque
import numpy as np


def bfs(maze, sx, sy):
    H = len(maze)
    W = len(maze[0])

    dist = np.zeros((H, W), dtype=int)
    dist[:, :] = -1

    q = deque([(sx, sy)])
    dist[sx, sy] = 0

    while q:
        x, y = q.popleft()
        d = dist[x, y]
        for dx, dy in [[1,0],[0,1],[-1,0],[0,-1]]:
            nx = x + dx
            ny = y + dy
            if 0 <= nx < H and 0 <= ny < W and maze[nx][ny]=="." and dist[nx, ny] == -1:
                q.append((nx, ny))
                dist[nx, ny] = d+1
    return dist.max()


def main():
    H, W = [int(x) for x in input().split()]

    maze = [input() for _ in range(H)]

    ans = 0
    for sx, sy in [(x, y) for x in range(H) for y in range(W) if maze[x][y] == "."]:
        ans = max(ans, bfs(maze, sx, sy))
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 12444
#include <bits/stdc++.h>

using namespace std;

const int Mod = 1e9 + 7, Nmax = 105;
typedef long long ll;

int dp[Nmax][Nmax*Nmax];
int N, K;


void add_to(int &x, int y)
{
    x += y;
    if(x >= Mod) x-=Mod;
        else if(x<0) x+=Mod;
}

int solve()
{
    int i, j;

    dp[0][0] = 1;

    for(i=1; i<=N; ++i)     /// lungime i, j eliminate
        for(j=0; j<=N*K; ++j)
        {
            int val = N - i + 1;
            int k;

            for(k=0; k<=K; ++k)
                if(k<=val)
                    add_to(dp[i][j+(k+j)/val], dp[i-1][j]);
                else
                    add_to(dp[i][j], dp[i-1][j]);
        }

    int ans = 0;
    for(i=0; i<=N*K; ++i)
        add_to(ans, (ll) dp[N][i] * i % Mod);
    return ans;
}

int main()
{
 //   freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> N >> K;

    int ans0 = (ll) K * (K+1) / 2 % Mod;
    int i;

    ans0 = (ll) N * ans0 % Mod;
    for(i=1; i<N; ++i) ans0 = (ll) ans0 * (K+1) % Mod;

    int ans = solve();

    ans = (ans0 - ans + Mod) % Mod;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 4608
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
        	while(true) {
        		int n = sc.nextInt();
        		int m = sc.nextInt();
        		int a = sc.nextInt();
        		if(n==0 && m==0 && a==0) break;
        		
        		int [][] line = new int[m][3];
        		for(int i=0;i<m;i++) {
        			for(int j=0;j<3;j++) {
        				line[i][j] = sc.nextInt();
        			}
        		}
        		for(int k=m-1;k>0;k--) {
        			for(int i=0;i<k;i++) {
            			if(line[i][0]<line[i+1][0]) {
            				for(int j=0;j<3;j++) {
            				int temp = line[i][j];
            				line[i][j] = line[i+1][j];
            				line[i+1][j] = temp;
            				}
            			}
            		}
        		}
        		
        		for(int i=0;i<m;i++) {
        			if(a == line[i][1]) {
        				a = line[i][2];
        			}else if(a == line[i][2]) {
        				a = line[i][1];
        			}
        		}
        		System.out.println(a);
        	}
        }
    }
}
        		


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

namespace D_XXOR
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            //int N = int.Parse(Console.ReadLine());
            // スペース区切りの整数の入力
            string[] input1 = Console.ReadLine().Split(' ');
            int N = int.Parse(input1[0]);
            long K = long.Parse(input1[1]);

            int[] column = new int[40];// 各桁の１の数を記録
            string[] A = new string[N];
            long[] numA = new long[N];
            string[] input2 = Console.ReadLine().Split(' ');
            for (var i = 0; i < N; i++)
            {
                numA[i] = long.Parse(input2[i]);
                string tmp = Convert.ToString(long.Parse(input2[i]), 2);// 2進数へ
                A[i] = string.Join("", tmp.Reverse()); // 桁表示を反転
                for (var j = 0; j < A[i].Length; j++)
                {
                    string s = A[i].Substring(j, 1);
                    if (s == "1")
                    {
                        column[j]++; // 各桁の１の数
                    }
                }
            }
            /*
            for(var k = 0; k < N; k++)
            {
                Console.Write(A[k]+" ");
            }
            Console.WriteLine();
            for(var k = 0; k < column.Length; k++)
            {
                Console.WriteLine(k+":"+column[k]);
            }
            */
            //
            long X = 0;
            for (var k = column.Length-1; k >=0 ; k--)
            {
                if (column[k] < N - column[k])
                {
                    X += (long)Math.Pow(2, k);
                    if (X > K)
                    {
                        X -= (long)Math.Pow(2, k);
                    }
                }
            }
            //Console.WriteLine(X);
            long ans = 0;
            foreach (long num in numA)
            {
                ans += X ^ num;
                //ans = X ^ num;
                //Console.WriteLine(ans);
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 39616
#include<stdio.h>
#include<stdlib.h>
int main()
{
  long A,B,K;
  scanf("%ld%ld%ld",&A,&B,&K);
  if(A+B>=K)
  {
  if(A>=K)
  {
    A=A-K;
    printf("%ld %ld",A,B);
    exit(0);
  }
  else if(B>=K-A)
  {
    B=B-(K-A);
    printf("%d %ld",0,B);
  }
  }
  else
  {
    printf("%d %d",0,0);
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n-1), b(n-1);
    vector<vector<PII>> g(n);
    REP(i, n-1) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        g[a[i]].push_back({b[i], i});
        g[b[i]].push_back({a[i], i});
    }
    vector<ll> s(n);
    REP(i, n) cin >> s[i];

    vector<ll> sz(n, 1), par(n, -1);
    function<void(ll,ll)> dfs = [&](ll v, ll p) {
        par[v] = p;
        for(auto to: g[v]) if(to.first != p) {
            dfs(to.first, v);
            sz[v] += sz[to.first];
        }
    };
    dfs(0, -1);

    dump(sz);
    dump(par);

    ll tu = -1, pos = -1;
    vector<ll> ans(n-1);
    REP(i, n-1) {
        ll u = a[i], v = b[i];
        if(par[u] != v) swap(u, v);

        if(n - 2*sz[u] == 0) {
            tu = u;
            pos = i;
        } else {
            ans[i] = (s[u] - s[v]) / (n - 2*sz[u]);
        }
    }

    dump(ans);

    ll sum = 0;
    function<void(ll,ll,ll)> dist = [&](ll v, ll p, ll d) {
        sum += d;
        for(auto to: g[v]) if(p != to.first) {
            dist(to.first, v, d+ans[to.second]);
        }
    };
    if(pos != -1) {
        dist(tu, -1, 0);
        dump(sum);
        ans[pos] = (s[tu] - sum) / (n/2);
    }

    REP(i, n-1) cout << ans[i] << "\n";
    cout << flush;

    return 0;
}

Measured memory_bytes: 22016
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

public class Main {

  public static void main(String[] args) {
  
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      final Pattern delim = Pattern.compile(" ");
      int[] seq = delim.splitAsStream(br.readLine())
        .mapToInt(Integer::parseInt)
        .toArray();

      int q = partition(seq, 0, n-1);
      dispIntArrayPartition(seq, q);
    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }

  public int partition(int[] seq, int p, int r) {

    int x = seq[r];
    int i = p-1;
    int t;

    for(int j=p; j<r; j++) {
      if(seq[j] <= x) {
        t = seq[++i]; seq[i] = seq[j]; seq[j] = t;
      }
    }
    t = seq[i+1]; seq[i+1] = seq[r]; seq[r] = t;

    return i+1;
  }

public void dispIntArrayPartition(int[] target, int q) {
  StringBuilder s = new StringBuilder();
  int l=target.length-1;

  for (int i=0; i<q; i++) { s.append(target[i]).append(" "); }
  s.append("[").append(target[q]).append("] ");
  for (int i=q+1; i<l; i++) { s.append(target[i]).append(" "); }
  s.append(target[l]);

  System.out.println(s);
  }
}


Measured memory_bytes: 44924
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
n = list(map(int,[i for i in str(N)]))

if N%sum(n)==0:
    print("Yes")
else:
    print("No")

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

const int N = 2e5 + 10;

char s[N];

int main(){
	int n, cnt, ans;
	scanf("%s", s + 1);
	n = strlen(s + 1);
	ans = cnt = 0;
	for (int i = 1; i <= n; i++){
		if (s[i] == 'S') cnt++;
		else{
			if (cnt == 0) ans++;
			else cnt--; 
		}
	}
	printf("%d\n", ans + cnt);
	return 0;
}

Measured memory_bytes: 384
let [|h;w;a;b|] = stdin.ReadLine().Split() |> Array.map int

for i in 1..h do
 [for j in 1..w do yield (if (i <= b && j <= a) || (i > b && j > a) then "0" else "1")]
 |>List.reduce (fun x y -> x + y)
 |>stdout.WriteLine

Measured memory_bytes: 22364
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
#define PI 3.14159265359
typedef long long ll;
//

int main(){
    int n;cin>>n;
    int ans;
    if(400<=n&&n<600)ans=8;
    else if(600<=n&&n<800)ans=7;
    else if(800<=n&&n<1000)ans=6;
    else if(1000<=n&&n<1200)ans=5;
    else if(1200<=n&&n<1400)ans=4;
    else if(1400<=n&&n<1600)ans=3;
    else if(1600<=n&&n<1800)ans=2;
    else if(1800<=n&&n<2000)ans=1;
    cout<<ans<<endl;
}

Measured memory_bytes: 3620
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("O2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
////
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#include <bits/stdc++.h>

#include <random>

#define all(x) (x).begin(), (x).end()
#define allp(x) (x)->begin(), (x)->end()

#define pb push_back


using namespace std;
void dout() { cerr << endl; }
//typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

using ll = long long;
//#ifdef __int128
//using hll = __int128;
//#endif
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

clock_t timestamp_start = clock();
void time_calc()
{
    cerr << (ld)(clock() - timestamp_start) / CLOCKS_PER_SEC << "\n";
}


#ifdef _getchar_nolock
#else
#define _getchar_nolock getchar_unlocked
#endif

//#define solvsh
//#define multi

#ifdef solvsh
#else

ll mod = 1e4 + 7;

ll add(ll a, ll b){
    return (a + b) % mod;
}
ll ml(ll a, ll b) {
    return (a * b) % mod;
}

ll sub(ll a, ll b) {
    return add(a, mod - b);
}

ll b_p(ll b, ll p) {
    if (p == 0) return 1;
    if (p & 1) return ml(b, b_p(b, p ^ 1));
    ll v = ml(b, p >> 1);
    return ml(v, v);
}
const int MAXN = 5e4+ 12;

void solve() {

    int n;
    cin >> n;

    vector<bool> v;

    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        v.push_back(x == y);
    }

    for (int i = 0; i <= n - 3; ++i) {
        bool ok = true;
        for (int j = 0; j <3 ; ++ j) {
            ok &= v[i + j];
        }
        if (ok) {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}

#endif

void multisolve() {
    int t;
    cin >> t;

    int i = 1;
    while (t--) {
        solve();
        i++;
    }
}

#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);


#ifdef multi
    //        gen();
    multisolve();
#else
    solve();
//    gen();
#endif
//    time_calc();
}


Measured memory_bytes: 3676
import math

def equals(a, b):
    return abs(a - b) < 1e-10


class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

    def __add__(self, p):
        return Point(self.x + p.x, self.y + p.y)

    def __sub__(self, p):
        return Point(self.x - p.x, self.y - p.y)

    def __mul__(self, a):
        return Point(self.x * a, self.y * a)

    def __rmul__(self, a):
        return self * a

    def __truediv__(self, a):
        return Point(self.x / a, self.y / a)

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

    def __lt__(self, p):
        if self.x != p.x:
            return self. x < p.x
        else:
            return self.y < p.y

    def __eq__(self, p):
        return equals(self.x, p.x) and equals(self.y, p.y)


class Segment:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2


def dot(a, b):
    return a.x * b.x + a.y * b.y


def cross(a, b):
    return a.x * b.y - a.y * b.x


def project(s, p):
    base = s.p2 - s.p1
    r = dot(p - s.p1, base) / base.norm()
    return s.p1 + base * r


if __name__ == '__main__':
    x1, y1, x2, y2 = [int(v) for v in input().split()]
    s = Segment(Point(x1, y1), Point(x2, y2))
    q = int(input())
    ans = []
    for i in range(q):
        x, y = [int(v) for v in input().split()]
        p = Point(x, y)
        ans.append(project(s, p))

    for v in ans:
        print('{0:.10f} {1:.10f}'.format(v.x, v.y))


Measured memory_bytes: 6012
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,n,m,x,y,x1,y1,mx,my,flg;
	scanf("%d %d %d %d",&n,&m,&x,&y);
	mx=-101;
	for(i=0;i<n;i++)	{
		scanf("%d",&x1);
		mx=max(mx,x1);
	}
	my=101;
	for(i=0;i<m;i++)	{
		scanf("%d",&y1);
		my=min(my,y1);
	}
	flg=0;
	for(i=x+1;i<=y;i++)	{
		if(i>mx && i<=my)	{
			flg=1;	break;
		}
	}
	if(flg==1)	printf("No War\n");
	else printf("War\n");
		
	return 0;
}

Measured memory_bytes: 128
from math import atan,pi
A,B,X=map(int,input().split())

if 2*X>=A*A*B:
    P=atan(2*(A*A*B-X)/(A*A*A))*180/pi
    print(P)
else:
    Q=atan((A*B*B)/(2*X))*180/pi
    print(Q)


Measured memory_bytes: 62280
#include <iostream>
using namespace std;

class dice{
  
public:
  int _1,_2,_3,_4,_5,_6,sus;

  void moveN(){
    sus=_1;
    _1=_2;
    _2=_6;
    _6=_5;
    _5=sus;
  }
  
  void moveE(){
    sus=_1;
    _1=_4;
    _4=_6;
    _6=_3;
    _3=sus;
  }
  
  void moveW(){
    sus=_1;
    _1=_3;
    _3=_6;
    _6=_4;
    _4=sus;
  }
  
  void moveS(){
    sus=_1;
    _1=_5;
    _5=_6;
    _6=_2;
    _2=sus;
  }
  
  void spin(){
    sus=_2;
    _2=_3;
    _3=_5;
    _5=_4;
    _4=sus;
  }

};

int main(){
  
  dice d1;
  dice d2;
  
  int i;

cin>>d1._1>>d1._2>>d1._3>>d1._4>>d1._5>>d1._6;
  cin>>d2._1>>d2._2>>d2._3>>d2._4>>d2._5>>d2._6;
    
  if(d1._3==d2._1||d1._4==d2._1)d1.moveE();
  for(i=0; i<4; i++){
   if(d2._1==d1._1)break;
   d1.moveN();
    }
  for(i=0; i<4; i++){
    if(d2._2==d1._2)break;
    d1.spin();
  }

  if(d1._1==d2._1 && d1._2==d2._2 && d1._3==d2._3 && d1._4==d2._4 && d1._5==d2._5 && d1._6==d2._6)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
  
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
//typedef pair<int, int> P;

double EPS = 1e-10;

double add(double a, double b)
{
	if (fabs(a + b) < EPS * (fabs(a) + fabs(b))) return 0;
	return a + b;
}

struct P
{
	double x, y;
	P() {}
	P(double x, double y) : x(x), y(y) {
	}
	P operator + (P p) {
		return P(add(x, p.x), add(y, p.y));
	}
	P operator - (P p) {
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator * (double d) {
		return P(x * d, y * d);
	}
	double dot(P p) {
		return add(x * p.x, y * p.y);
	}
	double det(P p) {
		return add(x * p.y, -y * p.x);
	}
};

bool cmp_x(const P& p, const P& q) {
	if (p.x != q.x) return p.x < q.x;
	return p.y < q.y;
}

vector<P> convex_hull(P* ps, int n) {
	sort(ps, ps + n, cmp_x);
	int k = 0;
	vector<P> qs(n * 2);
	for (int i=0; i<n; i++) {
		while (k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) k--;
		qs[k++] = ps[i];
	}
	for (int i=n-2, t=k; i>=0; i--) {
		while (k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) k--;
		qs[k++] = ps[i];
	}
	qs.resize(k - 1);
	return qs;
}

int n;
double x, y;
char comma;
P ps[100];

int main()
{
	while (cin >> n, n)
	{
		rep(i, n) cin >> ps[i].x >> comma >> ps[i].y;
		vector<P> qs = convex_hull(ps, n);
		cout << n - qs.size() << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1236
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

void solve(){
  string s;
  cin >> s;
  ll k;
  cin >> k;
  ll n = len(s);
  int i = 0;
  while (i + 1 < k and i < n and s[i] == '1'){
    i++;
  }
  s += '1';
  cout << s[i];
}

int main() {
  ios::sync_with_stdio(false); 
  cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

1
1000000000000000000


*/

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
const int maxn=109;
const int P=1000000007;

long long ksm(long long a,int k){
	long long ret=1;a=(a%P+P)%P;
	for(;k;k>>=1,a=a*a%P){
		if(k&1)ret=ret*a%P;
	}
	return ret;
}
long long INV(long long x){
	return ksm(x,P-2);
}

struct STR{
	int n;
	long long xx[maxn],yy[maxn];
	long long L(long long x){
		long long ret=0;
		for(int i=1;i<=n;++i){
			long long tmp=1;
			for(int j=1;j<=n;++j){
				if(i==j)continue;
				tmp=tmp*INV(xx[i]-xx[j]+P)%P*(x-xx[j]+P)%P;
			}
			ret=(ret+tmp*yy[i])%P;
		}
		return ret;
	}
}F0,F1;

long long C(int n){
	return n*(n-1)*(n-2)*(n-3)/1/2/3/4;
}

int main(){
	for(int i=0;i<=40;++i){
		long long tmp=0;
		for(int a=1;a<=i;++a){
			for(int b=1;b<=i;++b){
				for(int c=1;c<=i;++c){
					for(int d=1;d<=i;++d){
						for(int e=1;e<=i;++e){
							int t=i-a-b-c-d-e;
							int k=a*b*c*d*e;
							if(t<0)continue;
							t>>=1;
							t+=5;
							while(t>=4){
								tmp=(tmp+k*C(t-1))%P;
								--t;
							}
						}
					}
				}
			}
		}
		if(i&1){
			int t=++F1.n;
			F1.xx[t]=i;F1.yy[t]=tmp;
		}else{
			int t=++F0.n;
			F0.xx[t]=i;F0.yy[t]=tmp;
		}
	}
	
	int Tn;scanf("%d",&Tn);
	while(Tn--){
		long long x;scanf("%lld",&x);
		if(x&1)printf("%lld\n",F1.L(x));
		else printf("%lld\n",F0.L(x));
	}
	return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

int imos[100001];

int main()
{
	CIN(int, N);
	rep(i, N) {
		ll t, tt;
		CIN(ll, a);
		t = a - 1;
		tt = a + 2;
		t = max(0ll, t);
		tt = min(tt, 100000ll);
		imos[t]++;
		imos[tt]--;
	}
	int res = imos[0];
	reps(i, 1, 100001) {
		imos[i] += imos[i-1];
		res = max(res, imos[i]);
	}
	cout << res << endl;
}


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

using ll = long long;

int main(){
    ll n;
    cin >> n;
    vector<ll> v{istream_iterator<ll>(cin), istream_iterator<ll>()}, diff(n, 0ll);
    const ll sum = accumulate(begin(v), end(v), 0ll);
    const ll take_once = (n * (n+1)) / 2ll;
    if(sum%take_once){ cout<< "NO" << endl; return 0; }
    const ll nr_moves = sum / take_once;

    for(int i = 0; i < n; ++i) diff[i] = (v[(i+1)%n] - v[i]), diff[i] -= nr_moves;

    for(auto& x : diff) if(x > 0){ cout << "NO" << endl; return 0; }
    for(auto& x : diff) if(x%n){ cout << "NO" << endl; return 0; }
    ll nr = 0;
    for(auto& x : diff) nr -= x/n;
    if(nr == nr_moves) cout << "YES";
    else cout << "NO";
    return 0; }


Measured memory_bytes: 1908
#include<stdio.h>
#define   MAX 100
#define   INFTY 5000000
#define   WHITE 0
#define   GRAY 1
#define   BLACK 2

int n, M[MAX][MAX];

void dijkstra()
{
   int minv;
   int d[MAX], color[MAX];
   int i, v;

   for (i=0; i<n; i++){
      d[i] = INFTY;
      color[i] = WHITE;
   }

   d[0] = 0;
   color[0] = GRAY;

   while (1){
      minv = INFTY;
      int u = -1;
      for (i=0; i<n; i++){
         if (minv>d[i] && color[i]!=BLACK){
            u = i;
            minv = d[i];
         }
      }
      if (u==-1)
         break;
      color[u] = BLACK;
      for (v=0; v<n; v++){
         if (color[v]!=BLACK && M[u][v]!=INFTY){
            if (d[v] > d[u]+M[u][v]){
               d[v] = d[u] + M[u][v];
               color[v] = GRAY;
            }
         }
      }
        }

   for (i=0; i<n; i++)
      printf("%d %d\n", i, d[i] == INFTY ? -1 : d[i]);
}

int main()
{
   int i, j;
   int k, c, u, v;

   scanf("%d", &n);
   for (i=0; i<n; i++){
      for (j=0; j<n; j++)
         M[i][j] = INFTY;
   }

   for (i=0; i<n; i++){
      scanf("%d %d", &u, &k);
      for (j=0; j<k; j++){
         scanf("%d %d", &v, &c);
         M[u][v] = c;
      }
   }

   dijkstra();

   return 0;
}



Measured memory_bytes: 2052
#include <iostream>

using namespace std;

int main()
{
    int A;
    int B;
    A>1;
    A<=13;
    B>1;
    B<=13;

    cin>>A>>B;
    if (A==B) cout<<"Draw"<<endl;
    else if  (A==1) cout<<"Alice";
    else if  (B==1) cout<<"Bob";
    else if (A>B) cout<<"Alice";
    else if (B>A) cout<<"Bob";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<long long> a(n + 1), b(n);
    rep(i, n + 1) cin >> a[i];
    rep(i, n) cin >> b[i];
    long long ans = 0;
    rep(i,n){
        ans += min(b[i], a[i]);
        b[i] -= min(b[i], a[i]);
        ans += min(b[i], a[i + 1]);
        a[i + 1] -= min(a[i+1], b[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
using ll = long long;
int main() {
    vector<int> C(26);
    for (int i=0;i<4;i++){
        char tmp; cin >> tmp;
        C[tmp-'A']++;
    }
    int ok = 0;
    for(int i=0;i<26;i++){
        if (C[i]==2) ok++;
    }
    if (ok==2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Monad

import Data.Ord
import Data.List
import Data.Function
import Data.Maybe

import qualified Data.ByteString.Char8 as BS

import Debug.Trace

tuplify2 :: [a] -> (a, a)
tuplify2 (x:y:_) = (x, y)
tuplify2 _ = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInt
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents

main = do
  [nSw,nLight] <- getIntList
  ss <- getIntNList nLight
  swAllOn <- getIntList
  let swMatrix = map (indexToVec nSw 1 . sort . drop 1) ss
  print . sum . map (f swAllOn swMatrix) $ allSw nSw

indexToVec :: Int -> Int -> [Int] -> [Int]
indexToVec n i [] = take (n-i+1) [0,0..]
indexToVec n i indices@(x:xs)
  | x == i    = (1 : indexToVec n (i+1) xs)
  | otherwise = (0 : indexToVec n (i+1) indices)

f :: [Int] -> [[Int]] -> [Int] -> Int
f ps swMatrix sw
  | ps' == ps = 1
  | otherwise  = 0
  where
    ps' = map (flip mod 2 . sum . zipWith (*) sw) swMatrix

allSw :: Int -> [[Int]]
allSw 0 = [[]]
allSw n = [x:y | x <- [0,1], y <- allSw (n-1)]


Measured memory_bytes: 1020
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    static class Course {
        final int cost;
        final int time;

        Course(final int cost, final int time) {
            this.cost = cost;
            this.time = time;
        }
    }

    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int T = sc.nextInt();

        final PriorityQueue<Course> queue = new PriorityQueue<>((c1, c2) -> (c1.cost - c2.cost));
        for (int i = 0; i < N; i++) {
            final int c = sc.nextInt();
            final int t = sc.nextInt();
            if (t <= T) {
                queue.offer(new Course(c, t));
            }
        }
        if (queue.isEmpty()) {
            System.out.println("TLE");
            return;
        }
        System.out.println(queue.poll().cost);
    }
}


Measured memory_bytes: 28500
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int n;
int a[100005];
int cnt[100005];

int main()
{
	while (scanf ("%d",&n)!=EOF){
		memset (cnt,0,sizeof (cnt));
		for(int i=1;i<=n;i++){
			scanf ("%d",&a[i]);
			cnt[a[i]]++;
			cnt[a[i]+1]++;
			cnt[a[i]+2]++;
		}
		int ans=0;
		for (int i=0;i<100005;i++){
			ans=max(ans,cnt[i]);
		}
		printf ("%d\n",ans);
		
	}
	return 0;
}

Measured memory_bytes: 1024
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var d = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

        var sum = 0L;
        var minus = 0;
        var min = int.MaxValue;
        for (int i = 0; i < n; i++)
        {
            sum += Math.Abs(d[i]);
            min = Math.Min(min, Math.Abs(d[i]));
            if (d[i] < 0) minus++;
        }

        if (minus % 2 == 0)
        {
            Console.WriteLine(sum);
        }
        else
        {
            Console.WriteLine(sum - min * 2);
        }
    }
}


Measured memory_bytes: 29276
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (inputString)
{
 const stringArray = inputString.split(' ');
  let numArray = [];
  let result ='';
  
  stringArray.forEach(function(num){
   numArray.push(Number(num));
  })
  
  numArray.sort(function(a,b){
        if( a < b ) return -1;
        if( a > b ) return 1;
        return 0;
  });
  
  numArray.forEach(function(num){
    result += String(num) + ' ';
  });
  
  result = result.slice( 0, -1 );
  console.log(result);
});


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;

    for (int i = 1; i <= 9; i++){
        if (n / i <= 9 && n / i * i == n){
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 100001;

int main() {
    int n, m;
    cin >> n >> m;
    VI x(n);
    REP(i,n) scanf("%d", &x[i]);
    VI p(N), a(m), b(m);
    REP(i,n) p[x[i]]++;
    REP(i,N){
        a[i%m] += p[i];
        b[i%m] += p[i]/2;
    }

    int ans = 0;
    REP(i,m/2+1){
        int j = (m-i) % m;
        if (i == j){
            ans += a[i]/2;
        }else{
            int y = min(a[i], a[j]);
            ans += y;
            if (a[i] > a[j]) {
                ans += min((a[i]-y)/2, b[i]);
            }else{
                ans += min((a[j]-y)/2, b[j]);
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define each(i, mp) for (auto &i : mp)
#define sz(x) int(x.size())

int main()
{
  string s, t;
  cin >> s >> t;
  int n = sz(s), m = sz(t);
  vector<vector<int>> is(26);
  rep(i, n) is[s[i] - 'a'].push_back(i);
  rep(i, n) is[s[i] - 'a'].push_back(i + n);
  ll ans = 0;
  int p = 0;
  rep(i, m)
  {
    int c = t[i] - 'a';
    if (sz(is[c]) == 0)
    {
      puts("-1");
      return 0;
    }
    p = *lower_bound(is[c].begin(), is[c].end(), p) + 1;
    if (p >= n)
    {
      p -= n;
      ans += n;
    }
  }
  ans += p;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1724