akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N];
void bfs(int s) {
    queue<int> q;
    q.push(s);
    for ( int i = 0; i < n; i++ ) d[i] = INFTY;

    d[s] = 0;
    int u;
    while ( !q.empty() ) {
        u = q.front();
        q.pop();
        for ( int v = 0; v < n; v++ ) {
            if ( M[u][v] == 0 ) continue;
            if ( d[v] != INFTY ) continue;
            d[v] = d[u] + 1;
            q.push(v);
            }

    }
    for ( int i =0; i<n; i++){
         cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
         }

}
         int main() {
             int u, k, v;
             cin >> n;
             for ( int i =0; i<n; i++){
                 for ( int j=0; j<n; j++)  M[i][j] = 0;
                       }

             for ( int i =0; i<n; i++){
                            cin >> u >> k;
                 u--;
                 for ( int j =0; j<k; j++){
                                 cin >> v;
                     v--;
                     M[u][v] =1;
                                 }

             }
           bfs(0);
       return 0;

         }



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

void main_()
{
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> ps;
    ps.reserve(A);
    copy_n(istream_iterator<ll>(cin), A, back_inserter(ps));
    vector<ll> qs;
    qs.reserve(B);
    copy_n(istream_iterator<ll>(cin), B, back_inserter(qs));

    vector<ll> ss(X + Y);
    ss.reserve(X + Y + C);
    partial_sort_copy(begin(ps), end(ps), begin(ss), begin(ss) + X, greater<ll>());
    partial_sort_copy(begin(qs), end(qs), begin(ss) + X, begin(ss) + X + Y, greater<ll>());
    copy_n(istream_iterator<ll>(cin), C, back_inserter(ss));

    nth_element(begin(ss), begin(ss) + X + Y - 1, end(ss), greater<ll>());

    ll ans = accumulate(begin(ss), begin(ss) + X + Y, 0LL);

    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 5376
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
maze = [input() for i in range(H)]

queue = deque()
queue.append((Ch-1, Cw-1, 0))
inf = float("inf")
table = [[inf] * W for i in range(H)]
table[Ch-1][Cw-1] = 0
walk_move = ((-1, 0), (0, -1), (1, 0), (0, 1))
magic_move = []
for i in range(-2, 3):
  for j in range(-2, 3):
    if not i and not j:
      continue
    else:
      magic_move.append([i, j])

while queue:
  x, y, cost = queue.popleft()
  for i,j in walk_move:
    dx = x+i
    dy = y+j
    if 0 <= dx <= H-1 and 0 <= dy <= W-1 and maze[dx][dy] == "." and table[dx][dy] > cost:
      queue.appendleft((dx, dy, cost))
      table[dx][dy] = cost
  for k,l in magic_move:
    dx = x+k
    dy = y+l
    if 0 <= dx <= H-1 and 0 <= dy <= W-1 and maze[dx][dy] == "." and table[dx][dy] > cost+1:
      queue.append((dx, dy, cost+1))
      table[dx][dy] = cost+1

ans = table[Dh-1][Dw-1]
if ans == inf:
  print("-1")
else:
  print(table[Dh-1][Dw-1])

Measured memory_bytes: 137480
/*
?????????????????????????????????????´????????????????4?¨??????????????????¨??????????????????????????????
sAry
hAry
cAry
dAry

?????¨?????????????????????????¢????????????????????´????0??¨??????
0??§??????????????????????¶????????????????????????§??????
*/

import java.io.*;

public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char c;
		int n,num;
		int[] sAry = {1,2,3,4,5,6,7,8,9,10,11,12,13};
		int[] hAry = {1,2,3,4,5,6,7,8,9,10,11,12,13};
		int[] cAry = {1,2,3,4,5,6,7,8,9,10,11,12,13};
		int[] dAry = {1,2,3,4,5,6,7,8,9,10,11,12,13};
		
		n = Integer.parseInt(br.readLine());
		//?????¨????????????????????????????????????????´????0?????????
		for(int i=0; i<n; i++){
			String[] ary = br.readLine().split(" ");
			c = ary[0].charAt(0);
			num = Integer.parseInt(ary[1]);
			
			switch(c){
			case 'S':
				sAry[num-1] = 0;
				break;
			case 'H':
				hAry[num-1] = 0;
				break;
			case 'C':
				cAry[num-1] = 0;
				break;
			case 'D':
				dAry[num-1] = 0;
				break;
			default:
				break;
			}
		}
		//0??§??????????´??????±????????????????????????????¨??????¨??°????????¨?????????
		for(int i=0; i<13; i++){
			if(sAry[i] != 0){
				System.out.println("S "+sAry[i]);
			}
		}
		for(int i=0; i<13; i++){
			if(hAry[i] != 0){
				System.out.println("H "+hAry[i]);
			}
		}
		for(int i=0; i<13; i++){
			if(cAry[i] != 0){
				System.out.println("C "+cAry[i]);
			}
		}
		for(int i=0; i<13; i++){
			if(dAry[i] != 0){
				System.out.println("D "+dAry[i]);
			}
		}
	}
}

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

using namespace std;
 
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
 
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
 
#define pint(x) printf("%d",x)
#define plint(x) printf("%lld",x)
#define endl '\n'
#define nl printf("\n");
#define ps printf(" "); 
 
#define all(x) x.begin(),x.end()
#define pb push_back
#define Set(a, s) memset(a, s, sizeof (a))
#define mod1 (lli)(1e9 + 7)
#define mod2 (lli)(1e9 + 9)
#define EPS 1e-9

#define fore(i,n) for(int i=n; i>=0; i--)
#define fors(i,a,n) for(int i=a; i<n; i++)
#define fora(i,ele) for(auto i: ele)
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<lli> vli;
 
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
 
double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}
float roundoff(float val, float p){ return floor(val*pow(10.0,p)+0.5)/pow(10.0,p);}
lli power(lli a, lli b, lli mod){lli x=1,y=a; while(b > 0){if(b&1){x=(x*y)%mod;}y = (y*y)%mod; b /= 2;}return x;}
 
const int INF = 0x3f3f3f3f;
const float pi = 3.14159265;
 
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1};
 
int main(void) {
    ios_base::sync_with_stdio(true);
    cin.tie(NULL);
    cout.tie(NULL);
	//srand (time(NULL));
	/*
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	*/
    // cout<<"Execution time : "<<tick()<<"\n";
    lli n;
    int1(n);
    
    lli h,w;
    lint2(h,w);

	int cnt = 0;
	
	fors(i,0,n){
		lli hh,ww;
		lint2(hh,ww);
		if(hh>=h and ww>=w) cnt++;
	}
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define N 100010
using namespace std;

ll f[N],g[N],a[N];
char op,lst;

int main(){
    int n,x,y=0,i,cnt=0;
    cin>>n;
    ll ans=0;
    for(i=1;i<=n;++i){
        cin>>x;lst=op;
        if(i<n) cin>>op;
        if(lst=='-'){
            x=-x;
            a[++cnt]=x;
        }
        if(y<=0 && x>0) cnt++,a[cnt]=x;
        if(y>0 && x>0) a[cnt]+=x;
        y=x;
    } f[1]=a[1];
    for(i=cnt;i>=1;--i) g[i]=g[i+1]+abs(a[i]);
    for(i=2;i<=cnt;++i) f[i]=f[i-1]+a[i];
    ans=f[cnt];
    for(i=1;i<cnt;++i)
        if(a[i+1]<0) ans=max(ans,f[i+1]-a[i+2]+g[i+3]);
    cout<<ans; 
} 

Measured memory_bytes: 2560
import sys
N, M = map(int, input().split())

ans = [-1] * (N + 1)  # not evaluated yet

for line in sys.stdin:
    ans[int(line)] = 0  # unreachable

ans[0] = 1  # reachable

if ans[1]:  # if not unreachable
    ans[1] = 1

for i in range(2, N + 1):
    if ans[i]:
        ans[i] = (ans[i - 1] + ans[i - 2]) % 1000000007

print(ans[N])


Measured memory_bytes: 6900
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <set>
#include <unordered_map>
using namespace std;

int main()
{
//    A B C价格
//    x,y各需要几盒
    int a,b,c,x,y,res=0;
    scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
//c*2可以一盒A，一盒B；
//    c*2=a+b;
    if(c*2<a && x>y){
        printf("%d",c*2*x);
    }else if(c*2<b && y>x){
        printf("%d",c*2*y);
    }else if(c*2<a+b){
        if(x==y){
            printf("%d",c*2*x);
        }else{
            int needc=min(x,y);
            res=needc*c*2;
            int needa=x-needc,needb=y-needc;
            if(needa>0){
                res=res+needa*a;
            }
            if(needb>0){
                res=res+needb*b;
            }
            printf("%d",res);
        }
    }else{
        res=a*x+b*y;
        printf("%d",res);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,d,ans;
ll gcd(ll a,ll b)
{
	return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b)
{
 	ll g=gcd(a,b);
	return a/g*b;
}
ll cal(ll l,ll r,ll x)
{
	return r/x-(l-1)/x;
}
int main()
{
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	ans+=cal(a,b,c);
	ans+=cal(a,b,d);
	ans-=cal(a,b,lcm(c,d));
	ans=(b-a+1)-ans;
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#define INF 1e9 + 5
using namespace std;

int calMinCost(vector<int>& height, int i, vector<int>& cache) {

if (i == height.size() - 1)
  return 0;

if (cache[i] != -1)
  return cache[i];

cache[i] = calMinCost(height, i+1, cache) + abs(height[i]-height[i+1]);
if (i+2 < height.size())
  cache[i] = min(calMinCost(height, i+2, cache) + abs(height[i]-height[i+2]), cache[i]);
                
return cache[i];
}
int main() {
  
  int n;
  cin>>n;
  vector<int> height(n, 0);
  for (int i = 0; i<n; i++) {
    cin >> height[i];
  }

  vector<int> cache(n, -1);

  cout << calMinCost(height, 0, cache) << endl;
}

Measured memory_bytes: 8404
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int N,ans=0,cnt=0;
  cin>>N;
  int H[N];
  for(int i=0;i<N;i++) cin>>H[i];
  
  for(int i=0;i<N-1;i++){
      if(H[i]>=H[i+1]) cnt++;
      else{
        ans=max(ans,cnt);
        //cout<<ans<<endl;
        //i+=cnt;
        cnt=0;
      }
    if(i==N-2) ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}


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

int main(){
//int W,H,x,y,r;
   int A;
   int B;
   string opr;
    
    while(opr!="?"){
      cin >>A;
      cin >>opr;
      cin >>B;
      
   if(opr=="+")
    cout<<A+B<<endl;
   if(opr=="-")
    cout<<A-B<<endl;
   if(opr=="*")
    cout<<A*B<<endl;
   if(opr=="/")
    cout<<A/B<<endl;
    }

}


Measured memory_bytes: 3148
#include <stdio.h>

char func(int number,int count){
	switch(number){
	case 1:
		switch(count%5){
		case 0:return '\'';
		case 1:return ',';
		case 2:return '.';
		case 3:return '!';
		case 4:return '?';
		}
		break;
	case 2:
		switch(count%6){
		case 0:return 'a';
		case 1:return 'b';
		case 2:return 'c';
		case 3:return 'A';
		case 4:return 'B';
		case 5:return 'C';
		}
		break;
	case 3:
		switch(count%6){
		case 0:return 'd';
		case 1:return 'e';
		case 2:return 'f';
		case 3:return 'D';
		case 4:return 'E';
		case 5:return 'F';
		}
		break;
	case 4:
		switch(count%6){
		case 0:return 'g';
		case 1:return 'h';
		case 2:return 'i';
		case 3:return 'G';
		case 4:return 'H';
		case 5:return 'I';
		}
		break;
	case 5:
		switch(count%6){
		case 0:return 'j';
		case 1:return 'k';
		case 2:return 'l';
		case 3:return 'J';
		case 4:return 'K';
		case 5:return 'L';
		}
		break;
	case 6:
		switch(count%6){
		case 0:return 'm';
		case 1:return 'n';
		case 2:return 'o';
		case 3:return 'M';
		case 4:return 'N';
		case 5:return 'O';
		}
		break;
	case 7:
		switch(count%8){
		case 0:return 'p';
		case 1:return 'q';
		case 2:return 'r';
		case 3:return 's';
		case 4:return 'P';
		case 5:return 'Q';
		case 6:return 'R';
		case 7:return 'S';
		}
		break;
	case 8:
		switch(count%6){
		case 0:return 't';
		case 1:return 'u';
		case 2:return 'v';
		case 3:return 'T';
		case 4:return 'U';
		case 5:return 'V';
		}
		break;
	case 9:
		switch(count%8){
		case 0:return 'w';
		case 1:return 'x';
		case 2:return 'y';
		case 3:return 'z';
		case 4:return 'W';
		case 5:return 'X';
		case 6:return 'Y';
		case 7:return 'Z';
		}
		break;

	}
}

int main(){
	char buf[10001],pre,div;

	while(scanf("%s",buf)!=EOF){
		div = 0;
		for(int i=0; buf[i] != '\0'; i++){
			if(i == 0){
				pre = buf[i];
			}else{
				if(buf[i] == pre){
					if(pre == '0'){
						printf(" ");
					}else{
						div++;
						if(buf[i+1] == '\0'){
							printf("%c",func(pre-'0',div));
						}
					}
				}else if(buf[i] != pre && buf[i] == '0'){
					printf("%c",func(pre-'0',div));
					div = 0;
					pre = buf[i];
				}else if(buf[i] != pre && pre == '0'){
					pre = buf[i];
					div = 0;

					if(buf[i+1] == '\0'){
						printf("%c",func(pre-'0',div));
					}
				}else{
					printf("%c",func(pre-'0',div));
					div = 0;
					pre = buf[i];

					if(buf[i+1] == '\0'){
						printf("%c",func(pre-'0',div));
					}
				}
			}
		}
		printf("\n");
	}
}

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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long

int main(){
  int a, b, c, now = 0;
  cin >> a >> b >>c;
  FOR(i, 1, b){
    now += a;
    if (now % b == c) {
      puts("YES")
      exit(0);
    }
  }
  puts("NO")
}


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

#define MAX_N 200010
#define INF   1000000000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll A[MAX_N];
ll cnt[MAX_N];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    fill(cnt, cnt + MAX_N, 0);
    
    ll N;
    cin >> N;
    for(ll i = 0; i < N; i++) {
      cin >> A[i];
      cnt[ A[i] ]++;
    }

    ll total = 0;
    for(ll i = 0; i < MAX_N; i++) {
      if(cnt[i] != 0) total += cnt[i]*(cnt[i]-1)/2;
    }
    
    for(ll i = 0; i < N; i++) cout << total - (cnt[ A[i] ] - 1) << endl;
    return 0;
}


Measured memory_bytes: 5760
#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);
  
  int button = 1;
  int i = 0;
  for(int j = 0; j < N; j++){
    i++;
    button = a.at(button - 1);
    if(button == 2)break;
    if(button == 1 || j == N - 1){
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << i << endl;
}


Measured memory_bytes: 640
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n=o.a();
  var a = o.l();
  var b = o.l();
  var c = o.l();
  var ans = b[0];
  for(var i = 1; i < n; i++){
    if(a[i-1]+1 === a[i])ans += c[a[i]-2];
    ans += b[i];
  }
  return ans;
}

Measured memory_bytes: 7372
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fixed cout.setf(ios::fixed);
#define rep1    for( i=0; i<n; i++)
#define Precise cout.precision(7);
using namespace std;

int main()
{
    ll n,a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin>>n;
     cout<<a[n-1]<<endl;

    return 0;
}





Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

long long int f(const vector<int>& v, int k, const vector<int>& vc) {
    vector<long long int> val;
    for (int i = 0; i < v.size(); i++) {
        val.push_back(vc[v[i]]);
    }
    int flag = 1;
    for (int i = 0; i < val.size(); i++) {
        if (val[i] > 0) flag = 0;
    }
    if (flag == 1) {
        return *max_element(val.begin(), val.end());
    }
    long long int s = accumulate(val.begin(), val.end(), (long long int)0);
    long long int ret = 0;
    int n = v.size();
    if (s >= 0 && k >= v.size()) {
        if (k % n == 0) {
            ret += s * (k / v.size() - 1);
            k = v.size();
        } else {

            ret += s * (k / v.size());
            k %= v.size();
        }
    }
    long long int res = -0x3f3f3f3f;
    for (int i = 0; i < n; i++) {
        val.push_back(val[i]);
    }
    long long int r = 0;
    int l = 0;
    for (int i = 0; i < 2 * n; i++) {
        if (l == k) {
            r -= val[i - l];
            l--;
        }
        r += val[i];
        l++;
        if (r < 0) {
            r = 0;
            l = 0;
        }
        res = max(r, res);
    }
    while (l > 0) {
        r -= val[2 * n - l];
        res = max(res, r);
        l--;
    }
    return max(res + ret, ret);
}


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> vp(n + 1, 0), vc(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> vp[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> vc[i];
    }
    vector<int> v(n + 1, 0);
    long long int res = -0x3f3f3f3f;
    for (int i = 1; i <= n; i++) {
        if (v[i] == 1) continue;
        int index = i;
        vector<int> myv;
        while (v[index] == 0) {
            v[index] = 1;
            myv.push_back(index);
            index = vp[index];
        }

        res = max(res, f(myv, k, vc));
    }
    cout << res << endl;
}


Measured memory_bytes: 3812
N,C=map(int,input().split())

D=[list(map(int,input().split())) for i in range(C)]
grid=[list(map(int,input().split())) for i in range(N)]

a=[[0]*C for i in range(3)]


for i in range(N):
    tmp=i%3
    for j in range(N):
        a[tmp][grid[i][j]-1]+=1
        tmp=(tmp+1)%3

b=[[0]*C for i in range(3)]
for i in range(3):
    for j in range(C):
        b[i][j]=sum([ D[k][j] * a[i][k] for k in range(C)])

b=[ sorted([ [b[i][j],j] for j in range(C)]) for i in range(3)]

ans=1000000000
for i in range(3):
    for j in range(3):
        for k in range(3):
            if b[0][i][1]!=b[1][j][1] and b[1][j][1]!=b[2][k][1] and b[2][k][1]!=b[0][i][1]:
                ans=min(ans,b[0][i][0]+b[1][j][0]+b[2][k][0])

print(ans)

Measured memory_bytes: 5620
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int a[30000], b[30000];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	int k = 0, sum = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] > b[i]) {
			k += a[i] - b[i];
			b[i] = a[i];
		}
		else {
			sum += (b[i] - a[i]) / 2;
		}
	}
	if (sum < k) {
		cout << "No\n";
	}
	else {
		cout << "Yes\n";
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define long long int;

signed main(){
	int x = 0, cnt = 0, n, itr = 1000000; cin>>n;
	while(itr >= 0){
		x = x*10 + 7;
		x %= n;
		cnt++;
		itr--;
		if(x == 0){
			cout<<cnt<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[2000];
	int oushugeshu=0;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
		if(arr[i]%2==0)
		{
			oushugeshu++;
			if(arr[i]%3==0||arr[i]%5==0)
			ans++;
		}
	}
	if(oushugeshu==ans)cout<<"APPROVED"<<endl;
	else cout<<"DENIED"<<endl;
	return 0;
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)

using namespace std;
void solve()
{

    int a,b,x;
    cin>>a>>b>>x;
    if(a>x)cout<<"NO"<<endl;
    else if(a+b>x)cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;

int cnt[4];
double p[310][310][310];
double ev[310][310][310];

int main(){
	int n, x;
	scanf("%d", &n);
	for(int i=0; i < n; i++) {
		scanf("%d", &x);    cnt[x]++;
	}
	p[cnt[1]][cnt[2]][cnt[3]] = 1;
	for(int k=n; k >= 0; k--) {
		for(int j=n; j >= 0; j--) {
			for(int i=n; i >= 0; i--) {
				if(i+j+k > n || i+j+k == 0) continue;
				double p_waste = (double) (n - (i + j + k)) / n;
				double ev_waste = p_waste / (1 - p_waste);
				ev[i][j][k] += (ev_waste + 1) * p[i][j][k];
				if(i != 0) {
					double p_onedish = (double) i / (i + j + k);
					p[i-1][j][k] += p[i][j][k] * p_onedish;
					ev[i-1][j][k] += ev[i][j][k] * p_onedish;
				}
				if(j != 0) {
					double p_twodish = (double) j / (i + j + k);
					p[i+1][j-1][k] += p[i][j][k] * p_twodish;
					ev[i+1][j-1][k] += ev[i][j][k] * p_twodish;
				}
				if(k != 0) {
					double p_threedish = (double) k / (i + j + k);
					p[i][j+1][k-1] += p[i][j][k] * p_threedish;
					ev[i][j+1][k-1] += ev[i][j][k] * p_threedish;
				}
			}
		}
	}
	printf("%.12lf\n", ev[0][0][0]);
}


Measured memory_bytes: 452864
function abc100_b()

	# STEP.01
	# get the number of the slice of cake
	D, N = Base.parse.( Base.split( Base.readline( Base.STDIN ) ) )

	if Base.isequal( N, 100 )
		num_presents = 101*100^D
	else
		num_presents = N*100^D
	end

	# STEP.02
	Base.println( Base.STDOUT, num_presents )

	# STEP.TRUE_END
	return nothing

end

#==================================================================================================#

Main.abc100_b()


Measured memory_bytes: 177468
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
const int INF=(1<<21);
const int N=100;
int G[N][N],n,vis[N]={0},dis[N];
void dij(int s){
	dis[s]=0;
	while(1){
		int min=INF,u=-1;
		for(int i=0;i<n;i++){
			if(!vis[i]&&min>dis[i]){
				min=dis[i];
				u=i;
			} 
		}
		if(u==-1) break;
		vis[u]=1;
		for(int v=0;v<n;v++)
			if(G[u][v]!=INF&&!vis[v])
				if(dis[v]>dis[u]+G[u][v]) 
					dis[v]=dis[u]+G[u][v];
	}
}
int main(){
	scanf("%d",&n);
	int u,v,deg,w;
	for (int i=0;i<n;i++){
		dis[i]=INF;
		for (int j=0;j<n;j++) G[i][j]=INF;
	}
	for (int i=0;i<n;i++){
		scanf("%d%d",&u,&deg);
		for (int j=0;j<deg;j++){scanf("%d%d",&v,&w);G[u][v]=w;}
	}
	dij(0);
	for (int i=0;i<n;i++) printf("%d %d\n",i,dis[i]);
	return 0;
}


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

int main()
{
    int n,m,cnt = 0,flag = 1;
    cin >> n >> m;
    string a[n],b[m],s;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];

    for(int i = 0; i <= n - m; i++){
        for(int j = 0; j <= n - m; j++){
            for(int k = 0; k < m; k++){
                s = a[i+k].substr(j,m);
                if(b[k] == s) cnt++; 
            }
            if(cnt == m){
                flag = 0;
                break;
            }else cnt = 0;
        }
    }

    cout << (flag == 0 ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int n;
  cin >> n;
  int a[n+1]={0},b[n+1]={0};
  for(int i=1;i<=n;i++){
    cin >> a[i] >> b[i];
  }
  for(int i=1;i<=n-2;i++){
    if(a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2]){
      cout << "Yes" << endl;return 0;
    }
  }
  cout << "No" << endl;


return 0;
}
///....


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int main() {
    #ifdef LOCAL
    assert(freopen("b.in", "r", stdin));
    #else
    #endif
    int n;
    cin >> n;
    vector<int> a(n);
    forn (i, n)
        cin >> a[i];
    ll res = 0;
    forn (i, n - 1) {
        res += a[i] / 2;
        a[i] %= 2;
        if (a[i] && a[i + 1]) {
            --a[i], --a[i + 1];
            ++res;
        }
    }
    res += a[n - 1] / 2;
    cout << res << '\n';
}


Measured memory_bytes: 640
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using ll = long long;
const int maxn = 1<<20, mod = 924844033;
int n;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	vi a(n);
	for(auto &i : a) cin >> i;
	vi b = a;
	sort(all(b));
	for(auto &i : a) i = lower_bound(all(b), i) - b.begin();
	int ans = 0;
	for(int i = 0; i < n; i++) {
		if((a[i]^i)&1) ans++;
	}
	cout << ans/2;
}


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

int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int main(void){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        bool judge = 0;
        for(int j = 0; j < i; j++){
            if(h[i] < h[j]) judge = 1;
        }
        if(judge == 0) ans += 1;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
main = do
  n <- getLine
  a <- (map read . words) <$> getLine
  putStrLn .show $ solve a

solve:: [Int] -> Int
solve a = solve' (sum a) a

solve' to (a:as) = cho to a (abs (to - a - a)) as

cho:: Int -> Int -> Int -> [Int] -> Int
cho to su d [] = d
cho to su d (a:as)
  | as == [] = d
  | otherwise = min d $ cho to (su + a) (abs (to - su - su - a - a)) as 


Measured memory_bytes: 59772
import java.util.*;import java.io.*;import java.math.*;

public class Main
{

    public static void process()throws IOException
    {
        int n=ni(),r=ni();
        if(n>=10){
            pn(r);
            return;
        }

        pn(r+100l*(10l-n));
    }


    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new AnotherReader();
        boolean oj = true;

        //oj = System.getProperty("ONLINE_JUDGE") != null;
        if(!oj) sc=new AnotherReader(100);

        long s = System.currentTimeMillis();
        int t=1;
        while(t-->0)
            process();
        out.flush();
        if(!oj)
            System.out.println(System.currentTimeMillis()-s+"ms");
        System.out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;



/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
    
    
    

Measured memory_bytes: 21204
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AABD solver = new AABD();
        solver.solve(1, in, out);
        out.close();
    }

    static class AABD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            out.println(n < 1000 ? "ABC" : "ABD");
        }

    }
}



Measured memory_bytes: 20684
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>
#include <stack>

using namespace std;

long long n, k;
long long a[200010];
long long elemCount[200010];
std::vector<long long> elems[200010];
long long toPrevElem[200010];	//到上一个同名元素的位置 
long long toNextElem[200010];	//到上一个同名元素的位置 

int main()
{
	scanf("%lld%lld", &n, &k);
	
	for (int i = 0 ; i < n ; i++)
		scanf("%lld", &(a[i]));
	memset(elemCount, 0, sizeof(elemCount));
	
	for (int i = 0 ; i < n ; i++)
		elems[a[i]].push_back(i);

	for (int i = 1 ; i <= 200000 ; i++)
	{
		if (elems[i].size() == 0)
			continue;
		
		if (elems[i].size() == 1)
		{
			toPrevElem[elems[i][0]] = elems[i][0];
			toNextElem[elems[i][0]] = elems[i][0];
			continue;
		}

			
		for (int j = 0 ; j < elems[i].size() - 1 ; j++)
			toPrevElem[elems[i][j + 1]] = elems[i][j];
		toPrevElem[elems[i][0]] = elems[i][elems[i].size() - 1];
		
		for (int j = 0 ; j < elems[i].size() - 1 ; j++)
			toNextElem[elems[i][j]] = elems[i][j + 1];
		toNextElem[elems[i][elems[i].size() - 1]] = elems[i][0];
	}
		
	int section = 1;
	int p = n - 1;
	while (true)
	{
		if (p <= toPrevElem[p])
			section++;
		p = toPrevElem[p];
		if (p == 0)
			break;
		
		p--;
		if (p < 0)
		{
			p = n - 1;
			section++;			
		}
	}
	
	int left = k % section;
	p = 0;
	while (left > 1)
	{
		if (p >= toNextElem[p])
			left--;
		p = toNextElem[p];
		p++;
	}
	
	std::stack<long long> ss;
	std::set<long long> numInStack;
	
	ss.push(a[p]);
	numInStack.insert(a[p]);
	p++;
	
	while (p < n)
	{
		if (numInStack.find(a[p]) != numInStack.end())
		{
			while (ss.empty() == false)
			{
				int curP = ss.top();
				ss.pop();
				numInStack.erase(curP);
				
				if (curP == a[p])
					break;
			}
		}
		else
		{
			ss.push(a[p]);
			numInStack.insert(a[p]);
		}
		p++;
	}
	
	std::vector<long long> ans;
	
	while (ss.empty() == false)
	{
		ans.push_back(ss.top());
		ss.pop();
	}
	
	for (int i = ans.size() - 1 ; i >= 0 ; i--)
	{
		printf("%lld ", ans[i]);
	}
	printf("\n");
	
	
	return 0;
}


Measured memory_bytes: 31344
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin>>n>>q;
    queue<pair<string,int>> que;
    REP(i,n){
        string s;
        int num;
        cin>>s>>num;
        que.push({s,num});
    }
    int sum=0;
    while(!que.empty()){
        auto top=que.front();que.pop();
        if(top.second<=q){
            sum+=top.second;
            cout<<top.first<<" "<<sum<<endl;
        }
        else{
            top.second-=q;
            que.push({top.first,top.second});
            sum+=q;
        }
    }
}


Measured memory_bytes: 6376
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 ANS = 0;


	cin >> N;

	vector<SINT32> DATA(N);
	
	for (SINT32 i = 1; i < N+1; i++) {
		SINT32 count = 0;
		for (SINT32 j = 1; j < i+1; j++) {
			if ((i%j) == 0) {
				count++;
			}
		}
		if (count == 8) {
			ANS++;
		}
		i++;
	}

	cout << ANS << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();

Measured memory_bytes: 256
def cumsum(itr):
    arr = []
    val = 0
    for x in itr:
        val += x
        arr.append(val)
    return arr


def main(N, scores):
    M = N - 1

    def max_score(d):
        steps = (scores[i] + scores[-i - 1] for i in range(0, M - d, d))
        cum_scores = cumsum(steps)

        if M % d > 0:
            return max(cum_scores)
        else:
            k = M // d + 1
            return max(cum_scores[: k // 2])

    corner_case = scores[0] + scores[M]
    otherwise = max(max_score(d) for d in range(1, M))
    return max(corner_case, otherwise)


N = int(input())
scores = [int(a) for a in input().split()]
result = main(N, scores)

print(result)

Measured memory_bytes: 14468
from collections import deque

def main():
    N, M = map(int, input().split())
    edge = [[] for i in range(N)]
    for i in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        edge[A].append(B)
        edge[B].append(A)
    cnt = [float('inf')] * N  
    cnt[0] = 0
    Q = deque([0])
    visited = [False] * N
    visited[0] = True
    while Q:
        s = Q.popleft()

        for v in edge[s]:
            if visited[v]:
                continue
            cnt[v] = s + 1
            visited[v] = True
            Q.append(v)

    for i in range(N):
        if cnt[i] == float('inf'):
            print('No')
            exit()
    print('Yes')
    for i in range(1,N):
        print(cnt[i])


if __name__ == "__main__":
    main()

Measured memory_bytes: 94700
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair

using namespace std;


int main() {
    
    ll n; cin >> n;
    
    ll pay = (ll)ceil((double)n/1000);
    if(n%1000 == 0) cout<<0;
    else{
        ll left = (pay*1000 - n);
        cout<<left;
    }
}

Measured memory_bytes: 3640
#include <iostream>
#include <cmath>

using namespace std;

int main(){
 int N,L;
 cin >> N >> L;
 int minA=100000;
 int min_i;
 int tastes=0;
 for(int i=1;i<=N;i++){
     if(abs(L+i-1) < minA){
         minA = abs(L+i-1);
         min_i = i;
     }
     tastes += L+i-1; 
 }
 cout << tastes - (L+min_i-1) << endl;
}

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;

const long long mod = 1000000007;
const int INF = 1000000000;
const double EPS = 1e-9;

vector<ll> factorial(101010, 1);

ll ext_gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll g = ext_gcd(b, a % b, y, x);
    y -= (a / b) * x;
    return g;
}

ll mod_inv(ll a, ll mod) {
    ll x, y;
    ext_gcd(a, mod, x, y);
    return (x % mod + mod) % mod;
}

ll fact(ll n, ll mod) {
    ll res = 1;
    for (ll i = 2; i <= n; ++i) res = (res * i) % mod;
    return res;
}

ll comb(ll n, ll r) {
    if (n < r) return 0;
    if (n <= 0) return 0;
    if (r <= 0) return 0;
    //   ll numerator = fact(n, mod);
    ll numerator = factorial[n];
    // ll denominator = (fact(r, mod) * fact(n - r, mod)) % mod;
    ll denominator = (factorial[r] * factorial[n - r]) % mod;
    return (numerator * mod_inv(denominator, mod)) % mod;
}

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

    for (int i = 1; i < (int)factorial.size(); ++i) {
        factorial[i] = (i * factorial[i - 1]) % mod;
    }

    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    if (K == 1) {
        cout << 0 << endl;
        return 0;
    }
    sort(A.begin(), A.end());
    // vector<ll> c(N - 1, 0);
    // for (int i = 0; i < N - 1; ++i) {
    //     c[i] = comb(N, K) - comb(i + 1, K) - comb(N - i - 1, K);
    // }
    // ll ans = 0;
    // for (int i = 0; i < N - 1; ++i) ans = (ans + (c[i] * (A[i + 1] - A[i]) % mod)) % mod;
    ll ans = 0;
    rep(i, 2) {
        rep(j, N) {
            ll now = (A[j] * comb(j, K - 1)) % mod;
            if (i == 1) now = -now;
            ans = (ans + now) % mod;
        }
        reverse(A.begin(), A.end());
    }
    cout << ans << endl;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = 1000000000000ll;
static const int MIN = INT_MIN;
static const LL LMIN = -LINF;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int a, b, q;
    cin >> a >> b >> q;
    vector<LL> va(a + 1), vb(b + 1);
    for(int i = 0; i < a; ++i) cin >> va[i]; va[a] = LINF;
    for(int i = 0; i < b; ++i) cin >> vb[i]; vb[b] = LINF;

    LL x;
    LL la, ra, lb, rb;
    while(q--) {
        la = ra = lb = rb = LMIN;
        cin >> x;
        auto ita = lower_bound(all(va), x); ra = *ita;
        auto itb = lower_bound(all(vb), x); rb = *itb;
        if(ita != va.begin()) la = *(ita - 1);
        if(itb != vb.begin()) lb = *(itb - 1);
        LL lmin = min({llabs(x - la) + llabs(la - lb), llabs(x - la) + llabs(la - rb),
                        llabs(x - ra) + llabs(ra - rb), llabs(x - ra) + llabs(ra - lb)});
        LL rmin = min({llabs(x - lb) + llabs(lb - la), llabs(x - lb) + llabs(lb - ra),
                        llabs(x - rb) + llabs(rb - ra), llabs(x - rb) + llabs(rb - la)});
        cout << min(lmin, rmin) << endl;
    }

    return 0;
}



Measured memory_bytes: 2944
#include <iostream>
#include <string>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  string b;
  cin >> b;
  for (int i=0; i<b.size(); i++) {
    switch (b[i]) {
      case 'A': cout << 'T'; break;
      case 'T': cout << 'A'; break;
      case 'C': cout << 'G'; break;
      case 'G': cout << 'C'; break;
    }
  }
  cout << endl;
}

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

int min_length(vector<int> x, int k) {
	int n = x.size();
	vector<int> dif(n);

	for (int i = 0; i < n - 1; i++) {
		dif[i] = x[i + 1] - x[i];
	}

	sort(dif.begin(), dif.end());
	int all_length = x.back() - x.front();
	reverse(dif.begin(), dif.end());
	int unnecessary = 0;

	for (int i = 0; i < k - 1; i++) {
		unnecessary += dif[i];
	}
	return all_length - unnecessary;
}

int main() {
	int t;
	cin >> t;
	
	for (int i = 0; i < t; i++) {
		int n, k;
		cin >> n >> k;
		vector<int> x(n);

		for (int i = 0; i < n; i++) {
			cin >> x[i];
		}

		if (n <= k) cout << 0 << endl;
		else cout << min_length(x, k) << endl;
	}
}



Measured memory_bytes: 4220
n, k = map(int, input().split())
ary = list(map(int, input().split()))


# ruisekiwa
ruiseki = [0] * (n+1)

for i, x in enumerate(ary):
    ruiseki[i+1] = ruiseki[i] + x

kmax = 0
for i in range(n+1-k):
    ksum = ruiseki[i+k] - ruiseki[i]
    kmax = max(kmax, ksum)

print((kmax+k) / 2)


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

using namespace std;
int i,n,dp[3005][3005],t[3005][3005],x,W,v,w,j,m;
char s[3005],t1[3005];
void print(int i,int j)
{
   if(t[i][j]==1)print(i,j-1);
   if(t[i][j]==2){
        print(i-1,j-1);
        cout<<s[i];
   }
   if(t[i][j]==3)print(i-1,j);
}
int main()
{
    cin>>s+1>>t1+1;
    n=strlen(s+1);
    m=strlen(t1+1);
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
    {
        if(s[i]==t1[j])
        {
            dp[i][j]=dp[i-1][j-1]+1;
            t[i][j]=2;
        }
        else if(dp[i-1][j]<=dp[i][j-1])
        {
            dp[i][j]=dp[i][j-1];
            t[i][j]=1;
        }
        else {
            dp[i][j]=dp[i-1][j];
            t[i][j]=3;
        }
    }
    print(n,m);
    return 0;
}


Measured memory_bytes: 71040
mod = 10**9+7
N = int(input())
A = [int(x) for x in input().split()]

def po2(x) :
    ans = 1
    for i in range(x) :
        ans = (ans*2)%mod
    return ans

if N%2 == 0 :
    B = [2*i+1 for i in range(N//2)] * 2
else :
    B = [0] + [2*(i+1) for i in range(N//2)] * 2

A.sort()
B.sort()

if A != B :
    print(0)
else :
    print(po2(N//2))


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

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v.at(i);
    }

    int sum = 0;
    int ans = 1;
    for(int i = 0; i < n; i++){
        sum += v.at(i);
        if(sum > x) break;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256