akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num), lower_bound(A, A+N, num)
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>		// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>			// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>		// push(x), front(), pop()
#include <deque>
#include <stack>		// push(x), top(), pop()
#include <map>			// M[key],  insert(key, val), erase(key), find(key), 
#include <set>			// insert(key), erase(key), find(key)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define PI 3.141592653589793)
#define MOD 1000000007
#define REP(i, n) for(int i = 0; i < n; i++)

map<pair<int, int>, int> mp;
int N, K, L;
int ans[200002];
int par[200001*2];	//親
int rnk[200001*2];	//木の深さ

//n要素で初期化
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		rnk[i] = 0;
	}
}

//木の根を求める
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (rnk[x] < rnk[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rnk[x] == rnk[y])rnk[x]++;
	}
}

//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}
void solve() {
	cin >> N >> K >> L;
	init(N*2);
	for (int i = 0; i < K; i++) {
		int p, q;
		cin >> p >> q;
		p--, q--;
		unite(p, q);
	}
	
	for (int i = 0; i < L; i++) {
		int r, s;
		cin >> r >> s;
		r--, s--;
		unite(r+N, s+N);
	}
	for (int i = 0; i < N; i++) {
		mp[P(find(i), find(i+N))]++;
	}
	for (int i = 0; i < N; i++) {
		cout << mp[P(find(i), find(i + N))] << (i != N - 1 ? " " : "\n");
	}
}

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

Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	ll f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
int main(){
	int n=read();
	int lstx=0,lsty=0,lstt=0;
	REP(i,1,n){
		int t=read(),x=read(),y=read();
		int u=abs(x-lstx)+abs(y-lsty);
		if(u>t-lstt || (u&1)!=((t-lstt)&1)){
			printf("No\n");
			return 0;
		}
		lstx=x,lsty=y,lstt=t;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#B
N = int(input())
ABCD = [list(map(int,input().split())) for i in range(N*(N-1)//2)]

point = [[0,i] for i in range(N)]

for abcd in ABCD:
    a,b,c,d = abcd
    if c > d:
        point[a-1][0]+=3
    elif c < d:
        point[b-1][0]+=3
    else:
        point[a-1][0]+=1
        point[b-1][0]+=1
        
rank = [0]*N
point.sort(reverse=True)

mae = 0
now = 0
for i in range(N):
    p = point[i][0]
    ind = point[i][1]
    if p != mae:
        mae = p
        now = i
        rank[ind] = now+1
    else:
        rank[ind] = now+1
        
for r in rank:
    print(r)





Measured memory_bytes: 6164
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Palindrome-philia
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

char s[MAX_N + 4];

/* subroutines */

/* main */

int main() {
  scanf("%s", s);
  int n = strlen(s);

  int cnt = 0;
  for (int i = 0, j = n - 1; i < j; i++, j--)
    if (s[i] != s[j]) cnt++;

  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <cstdint>

int main()
{
	typedef std::array<std::uint16_t, 4> NumArray;
	NumArray num_a;
	while (std::cin >> num_a[0] >> num_a[1] >> num_a[2] >> num_a[3]) {
		std::uint16_t num_hit = 0, num_blow = 0;
		for (std::uint16_t i = 0; i < 4; ++i) {
			std::uint16_t b;
			std::cin >> b;
			if (b == num_a[i]) {
				++num_hit;
			}
			else if (std::find(num_a.begin(), num_a.end(), b) != num_a.end()) {
				++num_blow;
			}
		}
		std::cout << num_hit << ' ' << num_blow << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1156
// Problem : D. Omkar and Bed Wars
// Contest : Codeforces - Codeforces Global Round 10
// URL : https://codeforces.com/contest/1392/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize(2)
#include<iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <cstring>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <map>
#include <unordered_map>
#include <vector> 
#include <bitset>
#include <cctype>
#include <set>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>
#include <random>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAXN = 200005;
const int MAXM = 20500;
const int MOD = 1e9+7;

#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template <typename T> inline T min(T a, T b, T c) { return min(min(a, b), c); }
#define mst(X,Y) memset(X,Y,sizeof(X)) 
#define rep(i, a, n) for (int i=(a); i<=(n); i++)
#define per(i, a, n) for (int i=(a); i>=(n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) { cerr << " " << to_string(H);    debug_out(T...);}


// void solve()
// {
	
	
// }

int main()
{closeSync;
#ifdef DEBUG
	//freopen("C:/Users/86159/Desktop/input.txt", "r", stdin);
	//freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif
	//clock_t c1 = clock();
	// int T;
	// cin>>T;
	// while (T--)
	// 	solve();
	ll n,x,t;
	cin>>n>>x>>t;
	if (n%x==0)
	{
		cout<<(n/x)*t<<endl;
	}
	else 
		cout<<(n/x+1)*t<<endl;
    //cerr << "Time:" << clock() - c1 << "ms" <<endl;
    return 0;
}

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

int main(){
  int H, R;
  cin >> H >> R;
  if (H + R < 0) {
    cout << "-1" << endl;
  } else if (H + R == 0) {
    cout << "0" << endl;
  } else {
    cout << "1" << endl;
  }

  return 0;
}



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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define PI 3.141592653589793

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

    int a, b, x; cin >>a>>b>>x;

    double ans;

    if ((double)x >= a * a * b / 2.0) {
        ans = atan2(2.0*b - 2.0*x / a / a, a) * 180 / PI;
    } else {
        ans = atan2(b, 2.0*x / a / b) * 180 / PI;
    }

    cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
  {
      cin >> a[i];
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int Alice = 0;
  int Bob = 0;
  int i = 0;
  while (i < N)
  {
      Alice += a[i];
      if (i + 1 < N)
      {
          Bob += a[i + 1];
      }
      i += 2;
      
  }

  cout << Alice - Bob << endl;
  return 0;
}


Measured memory_bytes: 256
#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>;

int main() {
	int	N;
	cin >> N;
	vector<int> vec(N);
	rep(i, N)
		cin >> vec.at(i);
	int	Q;
	cin >> Q;
	rep(i, Q)
	{
		int	k;
		cin >> k;
		vector<int>::iterator it;
		it = partition_point(vec.begin(), vec.end(), [k](int element){return (element < k);});
		cout << distance(vec.begin(), it) << endl;
	}
}



Measured memory_bytes: 3096
#include <stdio.h>
#include <stdlib.h>
#define iMAX 1000000000

long long marge ( long *A, long left, long mid, long right)
{
    long d1,d2,i,j,k;
    long long cnt=0l;
    d1 = mid - left;
    d2 = right - mid;
    long *L = malloc(sizeof(long long)*(d1+1));
    long *R = malloc(sizeof(long long)*(d2+1));
    
    for( i=0l; i<d1; i++ ) L[i] = A[left+i];
    for( i=0l; i<d2; i++ ) R[i] = A[mid+i];

    L[d1] = iMAX;
    R[d2] = iMAX;

    for( k=left,i=0l,j=0l; k<right; k++ )
    {
        if( L[i] <= R[j] )
        {
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
            cnt += d1-i;
        }
    }
    
    free(L);
    free(R);
    return cnt;
}


long long margeSort( long  *A, long  left,  long right)
{
    long mid;
    long long cnt=0l;
    
    if( left+1l < right )
    {
        mid = ( left + right ) /2l;
        cnt += margeSort( A, left, mid );
        cnt += margeSort( A, mid, right );
        cnt += marge( A, left, mid, right );
    }
    
    return cnt;
}


int main()
{
    long n,i;
    scanf( "%ld", &n );
    long *S = malloc(sizeof(long)*n);
    
    for( i=0l; i<n; i++ ){
        scanf( "%ld", &S[i] );
    }
    
    printf( "%lld\n",margeSort( S, 0l, n ));
    free(S);
    return 0;
}


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

int main() {
  int n; cin >> n; 
  for(int i = 1 ; i <= n ; ++i) {
    if(floor(i * 1.08) == n) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << ":(\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int hanshu(char a[]);
int main()
{
    char a[10];
    gets(a);
    int flag = hanshu(a);
    if(flag == 1) printf("AC");
    if(flag == 0) printf("WA");
    return 0;
}
int hanshu(char a[])
{
    int num = strlen(a);
    if(a[0] == 'A')
    {
        if(strchr(a,'C') == strrchr(a,'C'))
        {
            if(strchr(a,'C') == NULL) return 0;
            if(strchr(a,'C') != strchr(a,a[1]) && strrchr(a,'C') != strchr(a,a[num-1]))
            {
                for(int i = 1; i < num; i++)
                {
                    if(strchr(a,a[i]) == strchr(a,'C')) continue ;
                    if(a[i] < 'a' || a[i] >'z') return 0;
                }
                return 1;
            }
            else return 0;
        }
        else return 0;
    }
    else return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  int count = 0;
  for (int i = 0; i < n-1; i++) {
    if (a.at(i) == a.at(i+1)) {
      cout << "NO" << endl;
      break;
    }
    else {
      count++;
    }
  }
  if (count == n-1) {
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
typedef long long ll;
const ll mod = 1e9+7;
const int MAX = 2e5+1;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * (ll)i % mod;
        inv[i] = mod - inv[mod%i] * (mod / (ll)i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
    COMinit();
    ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        for(ll j = 1; j <= m; j++){
            ans += (i*(i-1)/2 + (n-i+1)*(n-i)/2)*m + (j*(j-1)/2 + (m-j+1)*(m-j)/2)*n;
        }
    }
    (ans /= 2) %= mod;
    cout << ans*COM(n*m-2,k-2) % mod << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

const int timeLimit = 1985;

i64 xor128()
{
  static i64 x = 123456789, y = 362436069, z = 521288629, w = 88675123;
  i64 t = (x ^ (x << 11));
  x = y;
  y = z;
  z = w;
  return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

i64 D;
i64 c[26];
i64 s[365][26];
vector<i64> ans;
vector<i64> ts;

i64 eval(vector<i64> &ans, i64 t = 0)
{
  i64 score = ts[t];
  i64 last[26] = {};
  for (i64 i = 0; i < t; i++)
    last[ans[i]] = i + 1;
  for (i64 i = t; i < D; i++)
  {
    ts[i] = score;
    score += s[i][ans[i]];
    last[ans[i]] = i + 1;
    for (i64 j = 0; j < 26; j++)
      score -= c[j] * (i + 1 - last[j]);
  }
  return score;
}

void solve()
{
  chrono::system_clock::time_point start = chrono::system_clock::now();
  double C = timeLimit * 100, forceLine;
  i64 currentTime;
  vector<i64> now = ans;
  i64 bestScore = -1e18, nowScore = eval(now), loop = 0;
  while ((currentTime = chrono::duration_cast<chrono::microseconds>(chrono::system_clock::now() - start).count() / 1000) < timeLimit)
  {
    i64 t[3] = {xor128() % D, xor128() % 26};
    t[2] = now[t[0]];
    now[t[0]] = t[1];
    i64 score = eval(now, t[0]);
    forceLine = (timeLimit - currentTime) / C;
    if (bestScore < score)
    {
      ans = now;
      bestScore = score;
    }
    if (nowScore < score || forceLine * 1000 > rand() % 1000)
    {
      nowScore = score;
    }
    else
    {
      now[t[0]] = t[2];
    }
    loop++;
  }
  cerr << "score: " << bestScore + (i64)(1e6) << endl
       << "loop: " << loop << endl;
}

void init()
{
  for (i64 i = 0; i < D; i++)
  {
    i64 m = -1e9;
    for (i64 j = 0; j < 26; j++)
    {
      if (m < s[i][j])
      {
        m = s[i][j];
        ans[i] = j;
      }
    }
  }
}

void input()
{
  cin >> D;
  for (i64 i = 0; i < 26; i++)
    cin >> c[i];
  for (i64 i = 0; i < D; i++)
    for (i64 j = 0; j < 26; j++)
      cin >> s[i][j];
  ans.resize(D);
  ts.resize(D);
}

void output()
{
  for (i64 i = 0; i < D; i++)
    cout << ans[i] + 1 << endl;
}

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


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  long count=0;
  cin >>N;
  vector<int>A(N+1);
  for(int i=0;i<N+1;i++){
    cin >>A.at(i);
  }
  vector<int>B(N);
  for(int i=0;i<N;i++){
    cin >>B.at(i);
  }
  for(int i=0;i<N;i++){
    if(A.at(i)>=B.at(i)){
      count+=B.at(i);
    }
    //A<B
    else if(A.at(i)+A.at(i+1)>B.at(i)){
      count+=B.at(i);
      A.at(i+1)=A.at(i)+A.at(i+1)-B.at(i);
    }
    else{
      count+=A.at(i)+A.at(i+1);
      A.at(i+1)=0;
    }
  }
  cout <<count<<endl;
  
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> v(k);
	for (int i = 1; i <= n; i++) {
		v[(k - (i % k)) % k]++;
	}

	ll ans = 0;
	for (int a = 1; a <= n; a++) {
		int b = (k - (a % k)) % k;
		int c = (k - (a % k)) % k;
		if ((b + c) % k != 0) continue;
		ans += v[b] * v[c];
	}
	cout << ans << endl;
}

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

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

  int count = 0;

  rep(i, n) {
    int a, b;
    cin >> a >> b;

    if (a != b) {
      count = 0;
    } else {
      count++;
    }
    if (count == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
void solve(int n)
{
	long int c=0,f,j,s=0,i;
	for(i=2;;i++)
	{
		f=0;
		for(j=2;j*j<=i;j++)
			if(i%j==0)
			{
				f=1;
				break;
			}
		if(!f)
		{
			s+=i;
			if(++c>=n)
			{
				printf("%d\n",s);
				return;
			}
		}
	}
}

int main()
{
	int n;
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
			break;
		else
			solve(n);
	}
	return 0;
}

Measured memory_bytes: 600
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

int DP[4100][4100] = {};

int main(){
	int N;
	cin >> N;
	
	vector<long long int> vx, vy;
	
	long long int x1[3000], x2[3000], y1[3000], y2[3000];
	
	for(int i = 0; i < N; i++){
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		vx.push_back(x1[i]);
		vx.push_back(x2[i]);
		vy.push_back(y1[i]);
		vy.push_back(y2[i]);
	}
	
	sort(vx.begin(), vx.end());
	sort(vy.begin(), vy.end());
	
	
	for(int i = 0; i < N; i++){
		int X1 = find(vx.begin(), vx.end(), x1[i]) - vx.begin();
		int X2 = find(vx.begin(), vx.end(), x2[i]) - vx.begin();
		int Y1 = find(vy.begin(), vy.end(), y1[i]) - vy.begin();
		int Y2 = find(vy.begin(), vy.end(), y2[i]) - vy.begin();
		DP[X1][Y1]++;
		DP[X1][Y2]--;
		DP[X2][Y1]--;
		DP[X2][Y2]++;
	}
	
	for(int i = 0; i < N * 2; i++){
		for(int j = 1; j < N * 2; j++){
			DP[i][j] += DP[i][j - 1];
		}
	}
	
	for(int i = 0; i < N * 2; i++){
		for(int j = 1; j < N * 2; j++){
			DP[j][i] += DP[j - 1][i];
		}
	}
	
	long long int ans = 0;
	for(int i = 0; i < N * 2 - 1; i++){
		for(int j = 0; j < N * 2 - 1; j++){
			if(DP[i][j]){
				ans += (vx[i + 1] - vx[i]) * (vy[j + 1] - vy[j]);
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 67384
import sys
readline = sys.stdin.readline

V, E, r = map(int, readline().split())
inf = 10**10
edges = [[] for _ in [None]*V]

for _ in [None]*E:
    s, t, d = map(int, readline().split())
    edges[s].append((t, d))

vertices = [inf] * V
vertices[r] = 0

for i in range(V):
    flag = 0
    for v in range(V):
        cost = vertices[v]
        if cost == inf:
            continue
        for dist, _cost in edges[v]:
            newcost = cost + _cost
            if vertices[dist] > newcost:
                vertices[dist] = newcost
                flag = 1
    if flag == 0:
        for v in vertices:
            print(v if v != inf else "INF")
        break
else:
    print("NEGATIVE CYCLE")

Measured memory_bytes: 7976
(* O(1) *)
let get_coins a b i j =
  let buttons = Array.of_list [a; b] in
  let first = buttons.(i) in
  buttons.(i) <- first - 1;
  first + buttons.(j)

(* O(n) *)
let fold_int f a n =
  let rec fold f a i n =
    if i >= n then
      a
    else
      fold f (f a i) (i + 1) n
  in
    fold f a 0 n

(* O(1) *)
let solve a b =
  fold_int
    (fun sofar1 i ->
      fold_int
        (fun sofar2 j ->
          max sofar2 (get_coins a b i j))
        sofar1
        2)
    0
    2

let read_ints () = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let _ =
  match read_ints () with
  | [a; b] -> solve a b |> string_of_int |> print_endline
  | _ -> ()

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
#define MAX_N 200000
vector<int> A(MAX_N,0);
int main(){
    int N,K,input,ans;
    cin >> N >> K;
    REP(i,N){
        cin >> input;
        A[input-1]++;
    }
    sort(A.begin(),A.end(),greater<int>());
    ans = N;
    REP(i,K) ans -= A[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

typedef struct {
  int x;				       
  int y;
} Point;

int main() {
  int N;	
  int dx[] = { -1, 0 , 1 , 0} ;		
   int dy[] = { 0, -1, 0, 1 };
  while (cin >> N, N != 0) {
    Point point[200];
     point[0].x = 0;				
     point[0].y = 0;
    for (int i = 1; i < N; i++) {
      int n, d;
      cin >> n >> d;
      point[i].x = point[n].x + dx[d];
      point[i].y = point[n].y + dy[d];
    }
   
    int max_x=0;
    int max_y=0,min_x=10000,min_y=10000;
    for (int i = 0; i < N; i++) {
      max_x=max(max_x,point[i].x);
      max_y=max(max_y,point[i].y);
      min_x=min(min_x,point[i].x);
      min_y=min(min_y,point[i].y);

    }
    
    int width=max_x-min_x+1;
    int height=max_y-min_y+1;
    cout<<width<<" " <<height<<"\n";
  }

  return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int X, Y, c[20][20], dp[20][20];
int dx[3] = {-1, 0, 1};

int main()
{
  while (cin >> X >> Y && (X && Y)) {
    
    for (int i = 1; i <= Y; i++)
      for (int j = 1; j <= X; j++)
        cin >> c[i][j];
    
    for (int x = 1; x <= X; x++) {
      dp[Y + 1][x] = dp[Y + 2][x] = 1;
      if (c[Y][x] == 1) {
        dp[Y][x] = 0;
      } else {
        dp[Y][x] = 1;
      }
    }
    
    for (int y = Y - 1; y >= 1; y--) {
      for (int x = 1; x <= X; x++) {
        dp[y][x] = 0;
        if (c[y][x] == 2) {
          dp[y][x] += dp[y + 2][x];
        } else if (c[y][x] == 0) {
          for (int k = 0; k < 3; k++) {
            int nx = x + dx[k];
            if (nx >= 1 && nx <= X) {
              if (nx != x) {
                if (c[y + 1][nx] == 0) {
                  dp[y][x] += dp[y + 1][nx];
                }
              } else {
                if (c[y + 1][nx] != 1) {
                  dp[y][x] += dp[y + 1][nx];
                }
              }
            }
          }
        }
      }
    }
    
    int res = 0;
    for (int x = 1; x <= X; x++) 
      res += dp[1][x];

    cout << res << endl;
  }
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);

int h=scan.nextInt();
int n=scan.nextInt();
int[] a=new int[n];
 int i=0;
  for(i=0;i<n;i++){
    a[i]=scan.nextInt();
  }

int sum=0;
for(i=0;i<n;i++){
  sum=sum+a[i];
}
  
  if(sum<h){
  System.out.println("No");
  }else{
    System.out.println("Yes");
  }
}
}


Measured memory_bytes: 48916
#y,m,d=map(int,input().split())
#a,b=map(int,input().split())
n=int(input())
#a=int(input())
#b=int(input())
#s=list(input())
#T=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
#s=[list(input())for _ in range(n)]
#b=list(map(int,input().split()))
#b=list(map(int,input().split()))
#a=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#a=[list(input().split())for _ in range(n)]
a=[int(input())for _ in range(n)]
ans=0
total=0
noncardin_judge=False#カードが0枚のものがないかを記録する
for i in range(n):
    total+=a[i]
    if a[i]==0:
        ans+=total//2
        total=0
        noncardin_judge=True
if noncardin_judge:
    print(ans+total//2)
else:
    print(sum(a)//2)



Measured memory_bytes: 7072
#include<stdio.h>
int main (void)
{
	int tyu,kim,sai;
	int gou;

	while(1)
	{
		scanf("%d %d %d",&tyu,&kim,&sai);

		if((tyu==-1)&&(kim==-1)&&(sai==-1)) break;
		gou = tyu + kim;

		if((kim<0)||(tyu<0)||(gou<30))
		{
			printf("F");
		}
		else if(gou>=80)
		{
			printf("A");
		}
		else if((gou>=65)&&(gou<80))
		{
			printf("B");
		}
		else if((gou>=50)&&(gou<65)||(sai>=50))
		{
			printf("C");
		}
		else if((gou>=30)&&(gou<50))
		{
			printf("D");
		}

		printf("\n");
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

#define MOD 998244353
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);


ll arr[100001];
bool vis[100001];
ll lvl[100001];



ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll pow(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;
}


/*const int N=200000;

ll fac[N+1];
ll inv[N+1];
ll p=998244353;

ll c(ll a, ll b,ll m)
{
  if(a<b)return 0;
  return (fac[a]*inv[b]%m)*(inv[a-b])%m;
}

void fill()
{
inv[0]=1;
fac[0]=1;

for(int i=1;i<=N;i++)
{
  fac[i]=fac[i-1]*i%p;
  inv[i]=powM(fac[i],p-2,p);
}

}
*/
//ld dp[2001][2001];


int main()
{  fast

ll n,m;
cin>>n>>m;

ll d=m;

vl dig(n+1,-1);

while(d--)
{
  ll a,b;
  cin>>a>>b;
  if(dig[a]==-1)dig[a]=b;
  else 
  {
    if(b!=dig[a])
    {
      cout<<-1<<"\n";
      return 0;
    }
  }
}

if(m==0&&n==1)
{
  cout<<0<<"\n";
  return 0;
}

for(int i=1;i<=n;i++)
{
  if(dig[i]==-1)
  {
    if(i==1)dig[i]=1;
    else dig[i]=0;
  }
}

//cout<<"hi";

for(int i=1;i<=n;i++)
{
  if(n!=1&&dig[1]==0)
  {
    cout<<-1<<"\n";
    return 0;
  }
  cout<<dig[i]; 
}




 return 0;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999


class JOI{
public:
    int j,o,i;
    
    JOI():j(0),o(0),i(0){}
    JOI(int a,int b,int c):j(a),o(b),i(c){};
    
    JOI operator + (JOI obj) {
        return JOI(this->j+obj.j, this->o+obj.o, this->i+obj.i);
    }
    JOI operator - (JOI obj) {
        return JOI(this->j-obj.j, this->o-obj.o, this->i-obj.i);
    }
};

vector<string> data;

vector<vector<JOI>> dp(1001,vector<JOI>(1001));
int m,n;

void makeDP(){
    rep(i,m){
        rep(j,n){
            JOI ad(0,0,0);
            if(data[i][j]=='J')ad.j++;
            if(data[i][j]=='O')ad.o++;
            if(data[i][j]=='I')ad.i++;
            
            JOI cent,right,under;
            if(i-1>=0&&j-1>=0)cent = dp[i-1][j-1];
            if(i-1>=0)right = dp[i-1][j];
            if(j-1>=0)under = dp[i][j-1];
            
            dp[i][j] = right + under - cent + ad;
        }
    }
}


int main(){
    cin>>m>>n;
    int q;
    cin>>q;
    data.resize(n);
    rep(i,m) cin>>data[i];
    
    makeDP();
    
    
    rep(i,q){
        int y1,x1,y2,x2;
        cin>>y1>>x1>>y2>>x2;
        x1--,y1--,x2--,y2--;
        JOI a,b,c;
        if(y1-1>=0)a = dp[y1-1][x2];
        if(x1-1>=0)b = dp[y2][x1-1];
        if(y1-1>=0&&x1-1>=0)c=dp[y1-1][x1-1];
        //        cout<<dp[y2][x2].j<<" "<<a.j<<" "<<b.j<<" "<<c.j<<endl;
        
        JOI res = dp[y2][x2] - a - b + c;
        cout<<res.j<<" "<<res.o<<" "<<res.i<<endl;
    }
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    a,b,c,d=MI()
    
    t=(c+b-1)//b
    a=(a+d-1)//d
    
    if t<=a:
        print("Yes")
    else:
        print("No")

main()


Measured memory_bytes: 61764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> h(N);
    REP(i, 0, N) {
        cin >> h[i];
    }
    sort(rbegin(h), rend(h));
    ll ans = 1LL << 60;
    REP(i, 0, N - K + 1) {
        ans = min(ans, h[i] - h[i + K - 1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
from operator import itemgetter
N,M = map(int,input().split())
S = [list(map(int,input().split()))+[i] for i in range(M)]

S.sort(key=itemgetter(1))
S.sort(key=itemgetter(0))
p = 0
m = 0
j = 1
while m < M:
    if S[m][0] == p:
        S[m][1] = j
        j += 1
        m += 1
    else:
        p += 1
        j = 1
        continue
S.sort(key=itemgetter(2))
for i in range(M):
    print(str(S[i][0]).zfill(6)+str(S[i][1]).zfill(6))



Measured memory_bytes: 24996
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
#======================================================#
def main():
    x, a, b = MII()
    print('A' if abs(a-x) < abs(x-b) else 'B')

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
p=print
r=range
def a(i,j,k,l=0):p("+<"[l],i,j,k)
def b(i):a(i,i,i+1)
def d(x,i):
	for t in r(30):b(p:=i+t+30);a(q:=p+1,3,q);[*map(b,r(q,v:=i+60))];a(v,x,i+t,1);b(p);a(q,i+t,q)
p(3934)
a(0,1,3)
a(2,3,3,1)
a(0,3,0)
a(1,3,1)
d(0,9)
d(1,50)
for t in r(60):a(2,2,2);[t-31<s<30!=(a(8+t-s,50+s,5),a(3,5,6,1),a(2,6,2))for s in r(t)]

Measured memory_bytes: 9292
#include<iostream>
#include<string>
using sll = signed long long;
auto d(sll u,sll x) {
	//sll a, b;
	if (u < 0) { u = 0; }
	return std::make_pair( u / x, u%x);
}

template<class T,class U>
void put(const std::pair<T, U>& p) {
//	std::cout << p.first << ", " << p.second << "\n";
}

int main() {
	sll a, b, x;
	std::cin >> a >> b >> x;
	auto ap = d( a-1 , x);
	auto bp = d( b , x);
	//auto con = a == b ? 0 : 1;
	//auto res = bn <= an ? 0 : bn - an + 1;
	auto con = (ap.second == 0 && bp.second == 0 ? 1 : 0);
	auto res = ap.first >= bp.first ?0 : bp.first - ap.first;
	if (x > b) { res = 0; }
//	std::cout << bp.first << ", " << bp.second << "\n";
	put(ap);
	put(bp);
	if (a == 0) { res +=1; }
	std::cout << res << "\n";
	return 0;
}

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

int main()
{
	long long int a,uangseribuan,c,sisa,sum;
	cin >> a;
	uangseribuan = a/500*1000;
	c = a%500/5*5;
	sisa = a%500%5;
	sum = uangseribuan + c;
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int n; cin >>n;
  li cnt=0;
  map<li,int> mp;
  rep(i,n){
    li a; cin >>a;
    auto itr=mp.find(i-a);
    if(itr!=mp.end()){
      cnt+=itr->second;
    }
    mp[a+i]++;
  }
  print(cnt);
}


Measured memory_bytes: 16100
import java.util.Scanner;
public class Main {
    static int[] H;
    static int result = 0;
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        final int N = scan.nextInt();
        H = new int[N];
        for(int i = 0; i < N; i++){
            H[i] = scan.nextInt();
        }
        int i = 0;
        while(i < N - 1){
            i = constH(i, N);
        }
        System.out.println(result);
        scan.close();
        
    }
    // I番目から右隣へ移動した場合の移動量を返す
    // 戻り値は次に調べる位置
    public static int constH(int I, int N){
        int i = 0;
        int temp = 0;
        for(i = I; i < N - 1; i++){
            if(H[i+1] <= H[i]){
                temp++;
            }else{
                break;
            }
        }
        if(result < temp){
            result = temp;
        }
        return i + 1;
    }
    
}


Measured memory_bytes: 52812
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        s: String,
    }

    let b = s == "AAA" || s == "BBB";
    println!("{}", if b { "No" } else { "Yes" });
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxN = 2e5+7;
const int maxM = 1e5+7;
const int maxV = 90010;
//const int INF = 1e9+9;
//const ll INF = (1ll)<<60;
const int INF = 2e9+9;
const int MOD = 1e9+7;

int n,k;
char a[5]; 
int main()
{
	scanf("%s",a+1);
	sort(a+1,a+5);
	if(a[1] == a[2] && a[3] == a[4] && a[2] != a[3])
		puts("Yes");
	else
		puts("No"); 

	return 0;
}


Measured memory_bytes: 256
package main

import (
        "fmt"
        "strconv"
)

func solution(s string) int {
        out := 1 << 31
        for i := 0; i < len(s)-2; i++ {
                n, _ := strconv.Atoi(s[i : i+3])
                out = min(out, abs(n, 753))
        }
        return out
}

func abs(x, y int) int {
        if x < y {
                return y - x
        }
        return x - y
}
func min(x, y int) int {
        if x < y {
                return x
        }
        return y
}

func main() {
        var s string
        fmt.Scan(&s)
        fmt.Println(solution(s))
}

Measured memory_bytes: 512
s = input()

for i in range(2**3):
    t = int(s[0])
    for j in range(3):
        if (i>>j)&1:
            t += int(s[j+1])
        else:
            t -= int(s[j+1])
    if t == 7:
        x = i
        break
print(s[0],end="")
for k in range(3):
    if (x>>k)&1:
        print("+",end="")
    else:
        print("-",end="")
    print(s[k+1],end="")
print("=7")

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
int a,b,c,d,e,f;
scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
int g=a+b*5+c*10+d*50+e*100+f*500;
if(g>=1000)printf("1\n");else printf("0\n");
}

Measured memory_bytes: 1012
n,m=map(int,input().split())
A=set(int(input()) for i in range(m))
 
x=[0]*(n+1)
x[0]=1
if 1 in A:
    x[1]=0
else:
    x[1]=1
 
for j in range(2,n+1):
    if j in A:
        x[j]=0
    else:
        x[j]=(x[j-1]+x[j-2])%(10**9+7)
        
 
print(x[n])

Measured memory_bytes: 11884
N = int(input())
A = list(map(int,input().split()))
s = sum(A)
left_sum = 0
min_diff = s
for i in range(N):
    left_sum += A[i]
    diff = abs((s-left_sum)-left_sum)
    if min_diff > diff:
        min_diff = diff
print(min_diff)


Measured memory_bytes: 26220
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sum = 0;
        for(int i=0; i<n; i++){
            int a = sc.nextInt();
            sum += a-1;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 25524
#include<bits/stdc++.h>
const int MN=100000+5;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T>T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n;
int fa[MN];
set<int>h[MN];
set<int>::iterator it;
map<pii,int>mp;
queue<pii>q;pii e;
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void add(int u,int v){
	if(u>v)swap(u,v);
	h[u].insert(v),h[v].insert(u);mp[pii(u,v)]++;
	if(mp[pii(u,v)]==2)q.push(pii(u,v));
}
void input(){
	IN(n);
	for(int i=1;i<=n;++i)fa[i]=i;
	for(int i=1,u,v;i<=2*n-2;++i)IN(u),IN(v),add(u,v);
	for(int i=1,u,v;i<n;++i){
		while(1){
			if(q.empty())return puts("NO"),void();
			e=q.front();q.pop();u=find(e.first),v=find(e.second);
			if(u!=v)break;
		}
		if(h[u].size()>h[v].size())swap(u,v);
		fa[u]=v;mp.erase(e),h[v].erase(u);
		for(it=h[u].begin();it!=h[u].end();it++){
			int x=find(*it);if(x==v)continue;
			add(x,v);
		}
	}
	puts("YES");
}
int main(){
	input();
	return 0;
}

Measured memory_bytes: 46464
n = int(input())
A = list(map(int,input().split()))
f = 1 
c = 0

while f == 1:
    f = 0
    for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            inc = A[j]
            A[j] = A[j-1] 
            A[j-1] = inc
            f = 1
            c += 1
print(" ".join(map(str,A)))
print(c)

Measured memory_bytes: 7636
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    int n; cin >> n;
    if(n % 1000 == 0){
        cout << 0 << endl;
        return 0;
    }

    cout << 1000 * (n/1000 + 1) - n << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
 
 
long long int l , r;
long long int ans = 0x3f3f3f3f;
int main()
{
	scanf("%lld%lld",&l,&r);
	for(int i = l ; i <= min(l+2019,r);i++)
	{
		for(int j = i+1;j<=min(l+2019,r);j++)
		{
			ans = min(ans,1ll*i*j%2019);
		}
		
	}
	
	printf("%lld",ans);
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=100005;
int n,a[N],dp[N][3],opt[N];
int get(){
	char s[2];
	scanf("%s",s);
	if (s[0]=='-')return 1;
	return 0;
}
signed main(){
	scanf("%lld",&n);
	scanf("%lld",&a[1]);
	for (int i=2;i<=n;i++)opt[i]=get(),scanf("%lld",&a[i]);
	dp[1][0]=a[1];
	dp[1][1]=dp[1][2]=-1e18;
	for (int i=2;i<=n;i++){
		for (int j=0;j<=2;j++)dp[i][j]=-1e18;
		for (int j=0;j<=2;j++){
			int t=(opt[i]==1),now=((j^t)&1)?-a[i]:a[i];
			if (t&&j<2)dp[i][j+1]=max(dp[i][j+1],dp[i-1][j]+now);
			for (int l=0;l<=j;l++)dp[i][l]=max(dp[i][l],dp[i-1][j]+now);
		}
	}
	printf("%lld\n",max(max(dp[n][0],dp[n][1]),dp[n][2]));
}


Measured memory_bytes: 4096
#include<iostream>
#include<cstdio>
using namespace std;
char a[51][51];
int main()
{
	int n,m,i,j,x;
	cin>>n>>m;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			cin>>a[i][j];
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(a[i][j]=='#')
				cout<<a[i][j];
			else
			{
				x=0;
				if(a[i-1][j]=='#') 
					x++;;
				if(a[i+1][j]=='#')
					x++;
				if(a[i][j-1]=='#')
					x++;
				if(a[i][j+1]=='#')
					x++;
				if(a[i-1][j-1]=='#')
					x++;
				if(a[i-1][j+1]=='#')
					x++;
				if(a[i+1][j-1]=='#')
					x++;
				if(a[i+1][j+1]=='#')
					x++;
				cout<<x;
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 2019
int main()
{
    int n;
    cin>>n;
    int digit=n%10;
    if(digit==2 || digit==4 || digit==5 || digit==7 || digit==9)
        cout<<"hon\n";
    else if(digit==0 || digit==1 || digit==6 || digit==8)
        cout<<"pon\n";
    else
        cout<<"bon\n";
    return 0;
}


Measured memory_bytes: 3628
using System;

namespace AIZUJudge {
    class RightTriangle {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++) {
                string input = Console.ReadLine();
                var tmp = input.Split(' ');
                int a = int.Parse(tmp[0]) * int.Parse(tmp[0]);
                int b = int.Parse(tmp[1]) * int.Parse(tmp[1]);
                int c = int.Parse(tmp[2]) * int.Parse(tmp[2]);
                int[] arr = new int[]{a,b,c};
                Array.Sort(arr);
                if (arr[0] + arr[1] == arr[2]) {
                    Console.WriteLine("YES");
                } else {
                    Console.WriteLine("NO");
                }
            }
        }
    }
}

Measured memory_bytes: 9148
#include <iostream>

using namespace std;

int main() {
    int N{};
    cin >> N;

    string s{};

    for (; N != 0;) {
        int r = ((N % 2) + 2) % 2;
        s = to_string(r).append(s);
        N = (N - r) / (-2);
    }
    
    if (s.length() == 0) {
        cout << 0 << endl;
    } else {
        cout << s << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

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__) << "] "
// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 


template <typename T> void max_self(T &a, T b)
{
    a = max(a,b);
}

bool first(pair<int,int> p)
{
    return p.first == 0 || p.second == 0;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s,t;

    vector<vector<pair<int, pair<int,int>>>> dp(3001, vector<pair<int,pair<int,int>>>(3001, {0,{0,0}}));
    cin >> s >> t;
    int n = (int)s.length();
    int m = (int)t.length();

    for(int i =0; i< n; ++i)
    {
        for(int j = 0; j< m; ++j)
        {
            if(s[i] == t[j])
            {
                max_self(dp[i+1][j+1], make_pair(dp[i][j].first + 1, make_pair(i,j)));
            }
            max_self(dp[i+1][j], make_pair(dp[i][j].first, make_pair(i,j)));
            max_self(dp[i][j+1], make_pair(dp[i][j].first, make_pair(i,j)));
        }
    }


    pair<int, pair<int,int>> ans = {0,{0,0}};
    for(int i = 0; i <= n; ++i)
    {
        for(int j = 0; j<= m; ++j)
        {
            max_self(ans, make_pair(dp[i][j].first, make_pair(i,j)));
        }
    }
    if(ans.first == 0)
    {
        return 0;
    }
    string res = "";


    pair<int,int> cur = ans.second;
    while(!first(cur))
    {
        int i = cur.first;
        int j = cur.second;
        pair<int,int> previous = dp[i][j].second;

        if(previous == make_pair(i-1,j-1))
        {
            res+= s[i-1];
        }
        cur = previous;
    }
    reverse(res.begin(),res.end());
    cout << res;

    return 0;
}

Measured memory_bytes: 105984
loop do
    t, p, r = gets.split.map(&:to_i)
    break if t == 0 && p == 0 && r == 0
    rec = r.times.map{gets.gsub(/WRONG|CORRECT/, "WRONG" => "0", "CORRECT" => "1").split.map(&:to_i)}
    wa = Array.new(t).map{Array.new(p+1,0)}
    grade = Array.new(t).map{Array.new(2,0)}
    rec.each do |rr|
        case rr[3]
        when 0
            wa[rr[0]-1][rr[1]] += 1
        when 1
            grade[rr[0]-1][0] += 1
            grade[rr[0]-1][1] += rr[2] + 1200 * wa[rr[0]-1][rr[1]]
        end
    end
    puts grade.map.with_index(1){|g,i| [i] + g}.sort{
        |a,b| (b[1] <=> a[1]).nonzero? || (a[2] <=> b[2]).nonzero? || (a[0] <=> b[0])
     }.map{|a,b,c| "#{a} #{b} #{c}"}
end

Measured memory_bytes: 6192
<?php
    $S = str_split(trim(fgets(STDIN)));
    
    //最初の色を0にするか1にするかしかない。
    //ので２つのパターンをそれぞれ何階で作れるか全探査で行ける。
    
    //最初が0
    $counta=0;
    for($i=0;$i<count($S);$i++){
        //偶数の所が0
        if($i%2==0){
            if($S[$i]==1){
                $counta++;
            }
        }else{
            if($S[$i]==0){
                $counta++;
            }
        }
    }
    
    //最初が１；
    $countb=0;
    for($i=0;$i<count($S);$i++){
        //偶数の所が0
        if($i%2==0){
            if($S[$i]==0){
                $countb++;
            }
        }else{
            if($S[$i]==1){
                $countb++;
            }
        }
    }
    
    echo min($counta,$countb);

?>

Measured memory_bytes: 22236
#include<stdio.h>
#define MAX 101
#define BLACK 2
#define GLAY 1
#define WHITE 0

int a[MAX][MAX],color[MAX],d[MAX],f[MAX],n,time;

void visit(int u){
  int v;
  color[u]=GLAY;
  d[u]=++time;
  for(v=1;v<=n;v++){
    if(a[u][v]==0)continue;
    if(color[v]==WHITE)visit(v);
  }
  color[u]=BLACK;
  f[u]=++time;
}

void dfs(){
  int u;
  for(u=1;u<=n;u++)color[u]=WHITE;
  time=0;
  for(u=1;u<=n;u++){
    if(color[u]==WHITE)visit(u);
  }
}
  
int main(){
    int i,j,u,k,v;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      a[i][j]=0;
    }}

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

  dfs();


  for(u=1;u<=n;u++)printf("%d %d %d\n",u,d[u],f[u]);

  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int N;
int a[101];
signed main() {
    cin>>N;
    REP(i,N) cin>>a[i];
    sort(a,a+N);
    int A=0,B=0;
    REP(i,N) {
        if(i%2) {
            B+=a[N-i-1];
        } else {
            A+=a[N-i-1];
        }
    }
    cout<<A-B<<endl;
    return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())
A = list(map(int, input().split()))

_sum = [0]
for a in A:
    _sum.append(_sum[-1] + a)
del _sum[0]

ans = 10**100
for i in range(n-1):
    ans = min(ans, abs(_sum[i] - (_sum[-1] - _sum[i])))

print(ans)


Measured memory_bytes: 24812
N = int(input())

alf = [
    'a',
    'b',
    'c',
    'd',
    'e',
    'f',
    'g',
    'h',
    'i',
    'j',
    'k',
    'l',
    'm',
    'n',
    'o',
    'p',
    'q',
    'r',
    's',
    't',
    'u',
    'v',
    'w',
    'x',
    'y',
    'z',
]

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n)-1, n)+alf[(X%n)]
    return alf[(X%n)]

N26 = Base_10_to_n(N-1, 26)
print(N26)


Measured memory_bytes: 9188