akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n,q,m;
vector<ll> s;
vector<ll> t;
int main()
{
//	    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
//	    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	gbtb;
	ll x;
	cin>>n>>m>>q;
	repd(i,1,n)
	{
	    cin>>x;
	    s.push_back(x);
	}
	repd(i,1,m)
	{
	    cin>>x;
	    t.push_back(x);
	}
	sort(ALL(s));
	sort(ALL(t));
	ll pos;
	repd(qq,1,q)
	{
	    cin>>pos;
	    int id=lower_bound(ALL(s),pos)-s.begin();
	    int fid=lower_bound(ALL(t),pos)-t.begin();
	    ll ans=1e18;
	    repd(i,max(0,id-1),id)
	    {
	        repd(j,max(0,fid-1),fid)
	        {
	            ans=min(ans,abs(pos-s[i])+abs(s[i]-t[j]));
	            ans=min(ans,abs(pos-t[j])+abs(t[j]-s[i]));
	        }
	    }
	    cout<<ans<<endl;
	}

    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();}
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9')
{*p = *p * 10 + ch - '0';}}}


Measured memory_bytes: 3060
N = int(input())
a = list(map(int,input().split()))

cnt_0 = 0
cnt_2 = 0
cnt_4 = 0

for i in range(N):
    if a[i] % 4 == 0:
        cnt_4 += 1
    elif a[i] % 2 == 0:
        cnt_2 += 1
    else:
        cnt_0 += 1

if cnt_4 < cnt_0 - 1:
    print("No")
    exit()

if cnt_2 == 0:
    if cnt_4 >= cnt_0 - 1:
        print("Yes")
    else:
        print("No")
else:
    if cnt_4 >= cnt_0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 15020
s = list(input())
dp = [[0]*13 for _ in range(100005)]
n = len(s)
res = 0
mod = 10**9+7
dp[0][0] = 1
for i in range(n):
    c = int(s[i]) if s[i] !='?' else -1
    for j in range(10):
        if c!=-1 and c!=j: continue
        for k in range(13):
            dp[i+1][(k*10+j)%13] += dp[i][k]
    for j in range(13):
        dp[i+1][j] %= mod

print(dp[n][5])

Measured memory_bytes: 101592
#include <iostream>
#include <vector>
#include <queue>
#include<algorithm>

using namespace std;
using Graph = vector<vector<int>>;

int main() {
    // 頂点数と辺数
    int n, x,y; 
    cin >> n >> x >> y;

    // グラフ入力受取 (ここでは無向グラフを想定)
    
    Graph G(n);
    for (int i = 0; i < n-1; ++i) {
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }

    G[x-1].push_back(y-1);
    G[y-1].push_back(x-1);

    vector<int> A;

    for(int i=0;i<n;i++){
        // BFS のためのデータ構造
        vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
        queue<int> que;

        // 初期条件 (頂点 0 を初期ノードとする)
        dist[i] = 0;
        que.push(i); // 0 を橙色頂点にする

        // BFS 開始 (キューが空になるまで探索を行う)
        while (!que.empty()) {
            int v = que.front(); // キューから先頭頂点を取り出す
            que.pop();

            // v から辿れる頂点をすべて調べる
            for (int nv : G[v]) {
                if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

                // 新たな白色頂点 nv について距離情報を更新してキューに追加する
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }

        for(int j=i;j<n;j++){
            A.push_back(dist[j]);
        }

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

    for(int i=1;i<n;i++){
        cout << upper_bound(A.begin(),A.end(), i)-lower_bound(A.begin(),A.end(), i) << endl;
    }

}

Measured memory_bytes: 10732
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll>a(n),f(n);

    rep(i,n){
        cin>>a[i];    
    }
    rep(i,n)cin>>f[i];
    sort(a.begin(),a.end());
    sort(f.begin(),f.end());
    ll l=-1,r=1e12;
    while(l+1<r){
        auto ok=[&](ll now){
            bool res=true;
            ll ch=0;
            rep(i,n){
               ch+=max((ll)0,a[i]-now/f[n-i-1]);
            }
            if(ch>k)res=false;
            return res;
        };
        ll now=(l+r)/2;
        if(ok(now))r=now;
        else l=now;
    }
    cout<<r<<endl;
    return 0;
}

Measured memory_bytes: 3456
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
history = set()
now = 0
cnt = 0
while(True):
    if now in history:
        cnt = -1
        break
    else:
        cnt += 1
        history.add(now)
        now = a[now]-1
        if now == 1:
            break
print(cnt)

Measured memory_bytes: 21416
from sys import stdin
N = list(map(int, (stdin.readline().strip().split())))[0]
S= list(stdin.readline().strip())
ans = S.count("R")*S.count("G")*S.count("B")
for i in range(N):
    for j in range(i+1,N):
        k=2*j-i
        if k>=N:break
        if S[i]!=S[j] and S[j]!=S[k] and S[i] !=S[k]:
                ans-=1
print(ans)

Measured memory_bytes: 9204
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int n, m;
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0) break;
    vector<int> t(n), h(m);
    int tt = 0, th = 0;
    rep(i, n) cin >> t[i], tt += t[i];
    rep(i, m) cin >> h[i], th += h[i];

    int sum = 1e9, tans = -1, hans = -1;
    rep(i, n) {
      tt -= t[i];
      rep(j, m) {
        th -= h[j];
        if (tt + h[j] == th + t[i]) {
          if (t[i] + h[j] < sum) {
            tans = t[i];
            hans = h[j];
            chmin(sum, t[i] + h[j]);
          }
        }
        th += h[j];
      }
      tt += t[i];
    }
    if (tans == -1 && hans == -1)
      cout << -1 << "\n";
    else
      cout << tans << " " << hans << "\n";
  }

  return 0;
}


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

int main(){
  int a,b,k,j=0;cin>>a>>b>>k;
  for(int i=min(a,b);i>=1;i--) if((!(a%i))&&(!(b%i))){
    j++;
    if(j==k) cout<<i;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    string S; cin >> S;
    int ans = 0;
    int now = 0;
    REP(i,S.length()){
        if(S[i] == 'R'){
            now++;
            ans = max(ans,now);
        }
        else{
            ans = max(ans,now);
            now = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#l=list(map(int, input().split()))
#a,b=map(int, input().split())
#n=int(input())

s = input()

for i in range(1,len(s)+1):
    if (i%2 == 0):
        if (s[i-1] != "L" and s[i-1] != "U" and s[i-1] != "D"):
            print("No")
            exit()
    else:
        if (s[i-1] != "R" and s[i-1] !="U" and s[i-1] != "D"):
            print("No")
            exit()
print("Yes")


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

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N+1);
  REP(i,N) cin >> A[i];
  A[N] = 0;
  bool pos = false;
  ll k = 0;
  ll ans = 1000;
  REP(i,N) {
    if ( pos ) {
      // 上昇中
      if ( A[i+1] < A[i] ) {
        ans += k * A[i];
        pos = false;
      }
    } else {
      // 下降中
      if ( A[i+1] > A[i] ) {
        k = ans / A[i];
        ans -= k * A[i];
        pos = true;
      }
    }
  }
  cout << ans << endl;
}


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

int a[10010];

bool linearSearch(int *a, int n, int x){
	a[n] = x;
	int i = 0;
	while(a[i] != x)
		i++;
	if(i == n) return false;
	else return true;
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", a + i);
	int q;
	scanf("%d", &q);
	int ans = 0, x;
	for(int i = 0; i < q; i++) {
		scanf("%d", &x);
		if(linearSearch(a, n, x)) ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int N,M;
int A,B,C;
int L[10];
int dfs(int k, int a, int b, int c){
    if(k == N){
        if(min(a, min(b,c)) == 0){
            return MAX;
        } else {
            return abs(a-A)+abs(b-B)+abs(c-C);
        }
    }
    int ans = MAX; //k==Nのときのみを調べるので毎回ansを初期化しておく
    ans = min(ans, dfs(k+1, a+L[k], b, c) + (a>0 ? 10:0));//a==0は初期値ではないのでこのときのaの変化においてMPは発生しない
    ans = min(ans, dfs(k+1, a, b+L[k], c) + (b>0 ? 10:0));
    ans = min(ans, dfs(k+1, a, b, c+L[k]) + (c>0 ? 10:0));
    ans = min(ans, dfs(k+1, a, b, c));
    return ans;
}

int main(){
    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; i++) cin >> L[i];
    int res = dfs(0,0,0,0);
    cout << res << endl;
}



Measured memory_bytes: 256
/*using System;
using System.Linq;


    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string a;
                a = Console.ReadLine();
                if (a == null) break;
                string[] b = a.Split();
                int sum, cou = 0;
                sum = int.Parse(b[0]) + int.Parse(b[1]);
                for (; ; )
                {
                    if (sum >= 10)
                    {
                        sum = sum / 10;
                        cou++;
                    }
                    else
                    {
                        cou++;
                        break;
                    }
                }
                Console.WriteLine(cou);
            }
        }
    }

*/
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;



class Program
{
    public const int INF = 1 << 25;

    static void Main()
    {
        string str;
        while (!string.IsNullOrEmpty(str = Console.ReadLine()))
        {
            string[] input = str.Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = a + b;
            int ans = 1;
            while (c / 10 != 0)
            {
                c /= 10;
                ans++;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 5632
x=[]
y=[]
count=0
while True:
    i,j=map(int,raw_input().split())
    if (i,j)==(0,0):
        break
    count+=1
    x.append(i)
    y.append(j)

for i in range(count):
    for j in range(x[i]):
        print('#'*y[i])
    print('')

Measured memory_bytes: 6332
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static private final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static private final int upper(long v) {return (int)(v >> 32);}
	static private final int lower(long v) {return (int)(v & 0xFFFFFFFF);}

	//-----------------------------------------

	static private final long load(int end, int length) {
		return pair(end, length);
	}
	static private final int end(long load) {
		return upper(load);
	}
	static private final int length(long load) {
		return lower(load);
	}
	static private final long score(int count, int last) {
		return pair(count, last);
	}
	static private final int count(long score) {
		return upper(score);
	}
	static private final int last(long score) {
		return lower(score);
	}

	//------------------------------------------

	public void exec() throws Exception{
		final int N = sc.nextInt();
		final long[][] P = new long[N][2];
		final int x = 0;
		final int y = 1;

		for(int i=0;i<N;i++) {
			P[i][x] = sc.nextLong();
			P[i][y] = sc.nextLong();
		}

		final double[][] D = new double[N][N];
		for(int i=0;i<N;i++) {
			for(int j=0;j<N;j++) {
				if(i!=j) {
					D[i][j] = Math.sqrt(
							1.0*(
									(P[i][x]-P[j][x])*(P[i][x]-P[j][x]) +
									(P[i][y]-P[j][y])*(P[i][y]-P[j][y])
							));
				}
			}
		}
		boolean[] flags = new boolean[N];
		double sum = 0;
		int route[] = new int[N];
		cnt=0;
		for(int i=0;i<N;i++) {
			flags[i]=true;
			route[0]=i;
			sum += search(route, flags, D, 1, N, i, 0);
			flags[i]=false;
		}
//		err.println(sum);
//		err.println(N*(N+1)/2);
//		err.println(cnt);
		out.println(sum/cnt);
	}
	private int cnt = 0;

	private double search(int[] route, boolean[] flags, double[][] D, int depth, int N, int pos, double now) {
		if(depth == N-1) {
			cnt++;
			// 次が最終
			for(int i=0;i<N;i++) {
				if(!flags[i]) {
					route[depth]=i;
//					err.println(Arrays.toString(route));
					return now+D[pos][i];
				}
			}
		}
		double sum = 0;
		for(int i=0;i<N;i++) {
			if(!flags[i]) {
				flags[i]=true;
				route[depth]=i;
				sum+=search(route, flags, D, depth+1, N, i, now+D[pos][i]);
				flags[i]=false;
			}
		}
		return sum;
	}

}


Measured memory_bytes: 23892
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a,b=[0],[0]
for i in range(N): 
  a.append(a[i] + A[i]) 
for i in range(M): b.append(b[i] + B[i])
ans,j= 0,M
for i in range(N + 1): 
  if a[i]>K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47308
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=21;

int n,l;
char d[MAX_N];
int p[MAX_N];

void solve(){
    int ansl,ansr,ok=1,cnt=0;
    while(ok){
        ++cnt;
        ansl=ansr=0;
        for (int i=0;i<n;++i){
            if (p[i]==0||p[i]==l) continue;
            p[i]+=(d[i]=='L'?-1:1);
            if (p[i]==0) ansl=i+1;
            if (p[i]==l) ansr=i+1;
        }
        for (int i=0;i<n;++i){
            if (0<p[i]&&p[i]<l){
                for (int j=i+1;j<n;++j){
                    if (p[i]==p[j]){
                        d[i]=(d[i]=='L'?'R':'L');
                        d[j]=(d[j]=='L'?'R':'L');
                    }
                }
            }
        }
        ok=0;
        for (int i=0;i<n;++i){
            if (0<p[i]&&p[i]<l) ok=1;
        }
    }
    cout << cnt << ' ' << (ansl?ansl:ansr) << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> l,n){
        for (int i=0;i<n;++i) cin >> d[i] >> p[i];
        solve();
    }
}


Measured memory_bytes: 3124
#include <stdio.h>
#include <math.h>

int main(){
	int h,w;
	int i,j,k;
	int taikaku;
	double d;
	int flag;
	
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0&&w==0){
			break;
		}
		taikaku=h*h+w*w;
		while(1){
			flag=0;
			for(i=h+1;(double)i<sqrt(taikaku-i*i);i++){
				d=sqrt(taikaku-i*i);
				d=d-(double)(int)d;
				//printf("%d %d %f\n",i,(int)sqrt(taikaku-i*i),d);
				if(d){
					//printf("!\n");
				}else{
					flag=1;
					break;
				}
			}
			if(flag){
				break;
			}
			h=0;
			taikaku++;
		}
		printf("%d %d\n",i,(int)sqrt(taikaku-i*i));
		
	}
	return 0;
}

Measured memory_bytes: 600
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, n = map(int, readline().split())

x = min(b - 1, n)
# if b == n:
#     x = b - 1
# if x == 0:
#     print(a)
#     exit()
ans = math.floor((a * x) / b) - a * math.floor(x / b)
print(ans)

Measured memory_bytes: 9536
//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/
 
#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define forn(x,y) for(int x = 1 ; x <= y ; ++x)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout <<"---"<<x<< ' ';
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
using namespace std;
 
typedef long long ll;
typedef unsigned int uint;
const int nmax = 505;
const ll linf = LLONG_MAX;
const ll mod = 1e9+7;
const int inf = INT_MAX;
 
int n;
vec < pii > ord(nmax*nmax);
int dp[nmax][nmax];
int a[nmax][nmax];
vec < pii > d = {{-1,0},{1,0},{0,1},{0,-1}};



int main(){
	cin >> n;
	forn(i,n)
		forn(j,n){
			dp[i][j] = min( min ( i-1 , j-1 ) , min( n - i , n - j));
			a[i][j] = 1;
		}
	ll rez = 0 , tt = n*n;
	while(tt--){
		ll b;
		cin >> b;
		pii c = {(b-1)%n + 1,(b-1)/n + 1};
		rez += dp[c.fr][c.sc];
		a[c.fr][c.sc] = 0;
		queue < pii > bfs;
		bfs.push(c);
		while(bfs.size()){
			c = bfs.front();
			bfs.pop();
			for(pii pr : d){
				if(c.fr + pr.fr == 0 || c.fr + pr.fr == n+1 || c.sc + pr.sc == 0 || c.sc + pr.sc == n+1)
					continue;
				if(dp[c.fr + pr.fr][c.sc + pr.sc] > dp[c.fr][c.sc] + a[c.fr][c.sc]){
					dp[c.fr + pr.fr][c.sc + pr.sc] = dp[c.fr][c.sc] + a[c.fr][c.sc];
					bfs.push(make_pair(c.fr + pr.fr , c.sc + pr.sc));
				}	
	 		}
		}
	}
	cout << rez << '\n';

}



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

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

using namespace std;

vector<int> Z_algorithm(const string& s){
	int n=s.length();
	vector<int> z(n);
	for(int i=1,pre=0;i<n;i++){
		if(z[pre]>(i-pre)+z[i-pre]){
			z[i]=z[i-pre];
		}
		else{
			int j=max(pre+z[pre]-i,0);
			while(i+j<n && s[j]==s[i+j]) j++;
			z[i]=j;
			pre=i;
		}
	}
	z[0]=n;
	return z;
}

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

	int ans=0;
	rep(i,n){
		auto z=Z_algorithm(s.substr(i));
		rep(j,n-i) ans=max(ans,min(z[j],j));
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES  // M_PI等のフラグ

#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <list>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))

using namespace std;


void solve(){
    int a;
    cin >> a;
    cout << a+pow(a,2)+pow(a,3) << endl;
}

int main(int argc, char const *argv[]){
    solve();
    return 0;
}

Measured memory_bytes: 4184
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int INF = INT_MAX / 2;

class SegmentTree
{
public:
    typedef pair<int, int> T1;
    typedef int T2;

    // データの初期値、以下の条件を満たすこと
    //   uniteData(v, INIT_DATA) == v
    static const T1 INIT_DATA;

    // 2つの区間の計算結果v1,v2に対して、
    // その2つの区間を統合した区間における計算結果を返す
    static T1 uniteData(T1 v1, T1 v2){
        return min(v1, v2);
    }

private:
    // 前回の値がprevである要素に対して、
    // パラメータxを用いた更新処理を適用した後の計算結果を返す
    T1 updateData(T1 prev, T2 x){
        return make_pair(x, prev.second);
    }

    int n;
    vector<T1> data;
    void updateTree(int a, int k, int l, int r, T2 x){
        if(r - l == 1 && a == l){
            data[k] = updateData(data[k], x);
        }
        else if(l <= a && a < r){
            updateTree(a, k*2+1, l, (l+r+1)/2, x);
            updateTree(a, k*2+2, (l+r+1)/2, r, x);
            data[k] = uniteData(data[k*2+1], data[k*2+2]);
        }
    }
    T1 getValue(int a, int b, int k, int l, int r){
        if(a <= l && r <= b){
            return data[k];
        }
        else if(a < r && l < b){
            T1 v1 = getValue(a, b, k*2+1, l, (l+r+1)/2);
            T1 v2 = getValue(a, b, k*2+2, (l+r+1)/2, r);
            return uniteData(v1, v2);
        }
        else{
            return INIT_DATA;
        }
    }

public:
    SegmentTree(int n0){
        n = 1;
        while(n < n0)
            n *= 2;
        data.assign(2*n-1, INIT_DATA);
    }
    SegmentTree(const vector<T1>& v) : SegmentTree((int)v.size()){
        for(unsigned i=0; i<v.size(); ++i)
            data[n-1+i] = v[i];
        for(int k=n-2; k>=0; --k)
            data[k] = uniteData(data[k*2+1], data[k*2+2]);
    }
    // a番目の要素にパラメータxによる更新処理を適用
    void update(int a, T2 x){
        updateTree(a, 0, 0, n, x);
    }
    // 区間[a,b)の計算結果を返す
    T1 get(int a, int b){
        return getValue(a, b, 0, 0, n);
    }
};
const SegmentTree::T1 SegmentTree::INIT_DATA(INF, -1);

int main()
{
    int n, m;
    string s;
    cin >> n >> m >> s;

    vector<pair<int, int> > init(n+m, make_pair(INF, -1));
    for(int i=0; i<=n; ++i)
        init[i].second = i;
    init[n].first = 0;
    SegmentTree st(init);

    for(int i=n-1; i>=0; --i){
        if(s[i] == '0'){
            int x = st.get(i+1, i+m+1).first;
            st.update(i, x+1);
        }
    }
    if(st.get(0, 1).first == INF){
        cout << -1 << endl;
        return 0;
    }

    vector<int> ans;
    int i = 0;
    while(i < n){
        int j = st.get(i+1, i+m+1).second;
        ans.push_back(j - i);
        i = j;
    }

    cout << ans[0];
    for(int i=1; i<(int)ans.size(); ++i)
        cout << ' ' << ans[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 6144
//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)


int main(){
  int X,Y;
  string judge(int, int);
  cin >> X >> Y;
  cout << judge(X, Y);
}

string judge(int x, int y){
  rep1(i, x+1){
    if(2*i + 4*(x-i) == y){
      return "Yes";
    }
  }
  return "No";
}

Measured memory_bytes: 3624
#UnionFind
import sys
sys.setrecursionlimit(10**9)
class UnionFind:
  def __init__(self, n):
    self.n = [-1]*n
    self.r = [0]*n
    self.siz = n

  def find_root(self, x):
    if self.n[x] < 0:
      return x
    else:
      self.n[x] = self.find_root(self.n[x])
      return self.n[x]

  def unite(self, x, y):
    x = self.find_root(x)
    y = self.find_root(y)
    if x == y:
      return
    elif self.r[x] > self.r[y]:
      self.n[x] += self.n[y]
      self.n[y] = x
    else:
      self.n[y] += self.n[x]
      self.n[x] = y
      if self.r[x] == self.r[y]:
        self.r[y] += 1
    self.siz -= 1

  def root_same(self, x, y):
    return self.find_root(x) == self.find_root(y)

  def count(self, x):
    return -self.n[self.find_root(x)]

  def size(self):
    return self.siz

n,m=map(int,input().split())
u=UnionFind(n)
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  u.unite(a,b)
ans=0
for i in range(n):
  ans=max(ans,u.count(i))
print(ans)

Measured memory_bytes: 77944
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    int q;
    cin>>q;
    int t[q];
    for(int i=0;i<q;i++){
        cin>>t[i];
    }
    
    int sum=0;
    
    for(int i=0;i<q;i++){
        for(int j=0;j<n;j++){
            if(t[i]==s[j]){
               sum++;
               break;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3084
#include<stdlib.h>

int n,k,x,y,sum;

int main () {

    scanf("%d",&n);
    scanf("%d",&k);
    scanf("%d",&x);
    scanf("%d",&y);
    
    if (n <= k){
    
        sum = x * n;
    
    } else {
    
        sum = (x * k) + (y * (n-k));
        
    }
    
    printf ("%d\n",sum);
    
    return 0;


}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		System.out.println(Math.min(a,b) + Math.min(c,d));

	}

}


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

//template
#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 ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
    int n; scanf("%d",&n);
    printf("%d\n",n*n);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (int i = 0; i < N; i++){
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    int ans_f = 2 * pow(10, 9);
    for(int i = 0; i < N - K + 1; i++){
        int ans = h.at(i + K - 1) - h.at(i);
        ans_f = min(ans, ans_f);
    }
    cout << ans_f << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;

int main(){
  int n; cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  map<int, ll> mp;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  int q; cin >> q;
  vector<ll> b(q), c(q);
  for(int i = 0; i < q; i++){
    cin >> b[i] >> c[i];
  }
  for(int i = 0; i < q; i++){
    if(mp.find(b[i]) == mp.end()){
      cout << sum << endl;
      continue;
    }
    sum -= mp[b[i]] * b[i];
    sum += mp[b[i]] * c[i];
    mp[c[i]] += mp[b[i]];
    mp[b[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 10648
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
const int maxn = 200010;

int N,x,y;
int32_t main() {
	FAST
	cin >> N >> x >> y;
	
	for (int k =1;k<N;k++) {
		int ans = 0;
		for (int i = 1;i<N;i++) {
			if (i + k > N) continue;
			if (abs(i - x) + abs(i + k - y) + 1 >= k) ans++;
			int p1 = y - (k - abs(i - x) - 1);
			int p2 = y + (k - abs(i - x) - 1);
			
			if (k >= abs(i-x) + 1 and p1 > i + k) ans++;
			if (k >= abs(i-x) + 1 and p2 > i + k and p2 > y and p2 <= N) ans++;
			
			//cout << i << " " << ans << "\n";
		}
		cout << ans << "\n";
	}
	
}









Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	var x float64
	var u string
	fmt.Scan(&N)
	ans := 0.0
	for i := 0; i < N; i++ {
		fmt.Scan(&x, &u)
		p := x
		if u == "BTC" {
			p = x * 380000.0
		}
		ans += p
	}
	fmt.Println(ans)
}


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

int main() {
  long N,K; cin >> N >> K;
  long a = N / K;
  long minP = N % K;
  long minN = (N % K - K) * (-1);
  
  cout << min(minP,minN) << endl;
}
  

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n;

int main() {
    cin >> n;
    cout << (n-2) * 180 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll POW(ll a, ll n) {
    ll ret = 1;
    for (; n > 0; n >>= 1, a = a * a) {
        if (n % 2 == 1) ret = ret * a;
    }
    return ret;
}

int main(void) {
    ll n, a, sum = 1; cin >> n;
    const ll r = 1000000000000000000;
    bool t = true;
    REP(i, n) {
        cin >> a;
        if (log10(sum) + log10(a) > 18) {
            t = false;
        }
        if (a == 0) {
            sum = 0;
            t = true;
        }
        sum *= a;
    }
    if (!t || sum > r) cout << -1 << endl;
    else cout << sum << endl;
}

Measured memory_bytes: 3996
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

// dp[i][j] = min(dp[i-1][j],dp[i-1][j-1]+p[i])
vector<vector<ll>> dp(5010,vector<ll>(5010,1e15));

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

    int n;cin>>n;
    vector<P> v(n);
    for(int i=0;i<n;i++){
      ll h,p;cin>>h>>p;
      v[i]=P(h+p,h);
    }
    sort(v.begin(),v.end());
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
      dp[i][0]=0;
      for(int j=1;j<=i;j++){
        dp[i][j]=dp[i-1][j];
        ll h=v[i-1].second,p=v[i-1].first-h;
        if(dp[i-1][j-1]>h) continue;
        dp[i][j]=min(dp[i][j],dp[i-1][j-1]+p);
      }
    }
    int res=0;
    for(int i=1;i<=n;i++){
      if(dp[n][i]!=1e15) res=i;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 196608
#include <stdio.h>

int main(void){
	int h, w, i, j;
	while(1){
		scanf("%d %d", &h, &w);
		if (h == 0 && w == 0) break;
		for (i = 0; i < w; i++) printf("#");
		for (j = 1; j < h-1; j++){
			printf("\n#");
			for (i = 1; i < w-1; i++) printf(".");
			printf("#");
		}
		printf("\n");
		for (i = 0; i < w; i++) printf("#");
		printf("\n\n");
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int n, k, x, y ;
  cin >>n >>k >>x >>y ;
  if(n>k){
    cout << k*x + (n-k)*y <<endl ;
  }
  else{
    cout << n*x <<endl ;
  }
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
N, M = map(int, input().split())
switch = [[int(_) for _ in input().split()] for _ in range(M)]
p = [int(_) for _ in input().split()]
ans = 0

for i in range(2**N):
    for j in range(M):
        switchnum = 0
        for k in switch[j][1:]:
            switchnum += 2**(k-1)
        
        if (bin(i & switchnum).count('1') % 2 != p[j]):
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 3064
n = int(input())
s = input()
c = 0
def cha_3(num_):
    d = 3 - len(num_)
    return d*"0" + num_

for i in range(1000):
    num = cha_3(str(i))
    num_c = 0
    for j in range(len(s)):
        if s[j] == num[num_c]:
            num_c += 1
            if num_c == 3:
                c += 1
                break
print(c)






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

int main(void){
    int inp;
    int h, t, o;
    cin >> inp;
    h = inp / 100;
    t = (inp-h*100)/10;
    o = (inp-h*100-t*10);
    if(h==o){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
def main():
    while True:
        N = int(input())
        if N == 0:
            return
        m = [1, 2, 3, 4, 5, 6]
        ans = 1
        for i in range(N):
            o = input()[0]
            if o == 'N':
                m = [m[1], m[5], m[2], m[3], m[0], m[4]]
            elif o == 'S':
                m = [m[4], m[0], m[2], m[3], m[5], m[1]]
            elif o == 'W':
                m = [m[2], m[1], m[5], m[0], m[4], m[3]]
            elif o == 'E':
                m = [m[3], m[1], m[0], m[5], m[4], m[2]]
            elif o == 'R':
                m = [m[0], m[2], m[4], m[1], m[3], m[5]]
            elif o == 'L':
                m = [m[0], m[3], m[1], m[4], m[2], m[5]]
            ans += m[0]

        print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5628
#include<stdio.h>

int main()
{
  int x, y, temp1, temp2, temp3;

  scanf("%d%d", &x, &y);

  if( x>=y )
    {
      temp1 = x;
      temp2 = y;
    }

  if( x<y )
    {
      temp1 = y;
      temp2 = x;
    }

  while(1)
    {   
      if( temp2 == 0 ) break;
      
      if( temp1 % temp2 == 0 ) break;

      if( temp1 % temp2 > temp2 )
	{
	  temp1 = temp1 % temp2;
	}

      else if( temp1 % temp2 < temp2 )
	{
	  temp3 = temp2;
	  temp2 = temp1 % temp2;
	  temp1 = temp3;
	}
    }

    printf("%d\n", temp2);

  return 0;
}



Measured memory_bytes: 2072
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int N, M;;
	scanf("%d %d", &N, &M);
	vector<vector<int> > memo(N + 2, vector<int>(N + 2, 0));
	for(int i = 0; i < M; i++){
		int a, b, x;
		scanf("%d %d %d", &a, &b, &x);
		a--; b--;
		memo[a][b]++;
		memo[a][b + 1]--;
		memo[a + x + 1][b]--;
		memo[a + x + 1][b + x + 2]++;
		memo[a + x + 2][b + 1]++;
		memo[a + x + 2][b + x + 2]--;
	}
	int res = 0;
	for(int i = 0; i < N + 2; i++){
		for(int j = 0; j < N + 2; j++){
			if(j > 0) memo[i][j] += memo[i][j - 1];
		}
	}
	for(int i = 0; i < N + 2; i++){
		for(int j = 0; j < N + 2; j++){
			if(i > 0) memo[i][j] += memo[i - 1][j];
		}
	}
	for(int i = 0; i < N + 2; i++){
		for(int j = 0; j < N + 2; j++){
			if(i > 0 && j > 0) memo[i][j] += memo[i - 1][j - 1];
			if(memo[i][j] > 0) res++;
		}
	}
	printf("%d\n", res);
	return 0;
}



Measured memory_bytes: 100348
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size()
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e15 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //  // freopen("output.txt", "w", stdout);
    // #endif
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector <int> A(a), B(b), C(c);
    for(int i = 0; i < a; i++) cin >> A[i];
    for(int i = 0; i < b; i++) cin >> B[i];
    for(int i = 0; i < c; i++) cin >> C[i];
    sort(all(A)); sort(all(B)); sort(all(C));
    reverse(all(A)); reverse(all(B)); reverse(all(C));
    deque <int> d;
    for(int i = 0; i < x; i++) d.pb(A[i]);
    for(int i = 0; i < y; i++) d.pb(B[i]);
    sort(all(d));
    int sum = 0;
    for(auto i : C) {
       if(i < d.front() || d.empty()) break;
       sum += i;
       d.pop_front();
    }
    for(auto i : d) sum += i;
    cout << sum << '\n';
}



Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
ll n,m;
int main()
{
    ll sum=1;
    scanf("%lld%lld",&n,&m);
    if(abs(n-m)>1)
        printf("0\n");
    else
    {
        if(abs(n-m)==0)
        {
            for(ll i=1;i<=n;i++)
            {
                    sum*=i;
                    sum%=mod;
            }
            sum*=sum;
            sum%=mod;
            sum*=2;
            sum%=mod;
        }
        else if(abs(n-m)==1)
        {
            for(ll i=1;i<=min(n,m);i++)
            {
                sum*=i;
                sum%=mod;
            }
            sum*=sum;
            sum%=mod;
            sum*=max(n,m);
            sum%=mod;
        }
        printf("%lld\n",sum);
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long[] pts=new long[N];
		for(int i=0; i<N; i++) {
			pts[i]=sc.nextLong();
		}
		long lm=1;
		for(int i=0; i<N; i++) {
			lm=lcm(lm,pts[i]);
		}
		System.out.println(lm);
	}
	public static long lcm(long m, long n) {
		return m / gcd(m, n)*n;
	}
	public static long gcd(long m, long n) {
		if(m < n) return gcd(n, m);
		if(n == 0) return m;
		return gcd(n, m % n);
	}
}


Measured memory_bytes: 26244
a = int(input())
check = 0
for p in range(10):
    if check == 0:
        for q in range(10):
            ans = p * q
            if a == ans:
                print('Yes')
                check += 1
            elif ans == 81 and a is not 81:
                print('No')
                
            else:
                pass

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;

class Program {

    static int Main(string[] args) {
        List<int[]> list = InputIntList();

        for (int i = 0; i < list.Count; i++) {
            Check(list[i]);
            if (i < list.Count - 1) {
                Console.WriteLine("");
            }
        }

        return 0;
    }

    static int InputN() {
        string v = Console.ReadLine();
        return int.Parse(v);
    }

    static List<int[]> InputIntList() {
        List<int[]> list = new List<int[]>();

        while (true) {
            string v = Console.ReadLine();
            if (v == "0 0") { break; }

            string[] vs = v.Split(' ');

            list.Add(new int[] { int.Parse(vs[0]), int.Parse(vs[1]) });
        }

        return list;
    }

    static decimal[] InputDecimal() {
        string v = Console.ReadLine();
        string[] vs = v.Split(' ');

        decimal[] vd = new decimal[vs.Length];
        for (int i = 0; i < vs.Length; i++) {
            vd[i] = decimal.Parse(vs[i]);
        }

        return vd;
    }

    static void Check(int[] v) {
        int a = v[0];
        int b = v[1];
        bool ex = false;

        for (int i = a; i <= b; i++) {
            if (i % 400 == 0) {
                ex = true;
                Console.WriteLine(i);
            }
            else if ((i % 4 == 0) && (i % 100 != 0)) {
                ex = true;
                Console.WriteLine(i);
            }
        }

        if (ex == false) {
            Console.WriteLine("NA");
        }
    }
}

Measured memory_bytes: 9188
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class Program{
  public static void Main(){
    
    int n = int.Parse(Console.ReadLine());
    var input = Console.ReadLine().Split();
    int[] a = new int[n];
    for(int i=0; i<n; i++){
      a[i] = int.Parse(input[i]);
    }
    
    long e = 0;
    long o = 0;
    long ewa = 0;
    long owa = 0;
    for(int i=0; i<n; i++){
      ewa += a[i];
      owa += a[i];
      if(i % 2 == 0){
        if(ewa >= 0){
          e += ewa +1;
          ewa = -1;
        }
        if(owa <= 0){
          o += Abs(owa) +1;
          owa = 1;
        }
      }
      else{
        if(ewa <= 0){
          e += Abs(ewa) +1;
          ewa = 1;
        }
        if(owa >= 0){
          o += owa +1;
          owa = -1;
        }
      }
    }
    Console.Write(Min(o,e));
  }
}


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

int main()
{
  ll n, m, x, i, sum=0;

  cin>>m>>n;

  for(i=0; i<n; i++)
  {
    cin>>x;
    sum+=x;
  }
  //cout<<sum<<endl;
  if(sum>m)
  {
    cout<<-1<<endl;
  }
  else cout<<m-sum<<endl;
}

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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string arg;
  	cin >> arg;
    if (arg == "Y") { // Yが出た時点で4色確定
    	cout << "Four" << endl;
      	return 0;
    }
  }
  cout << "Three" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main (void)
{
        int H, W, h, w, v, x, y, a;
        scanf("%d%d",&H, &W);
        scanf("%d%d",&h, &w);

        v=H*W;

        x=h*W+(H-h)*w;

        a=v-x;
        printf("%d\n",a);
        return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
struct dice{
    int d1,d2;
};
int main()
{
    int n;
    cin>>n;
    struct dice d[n];
    for(int i=0;i<n;i++)
        cin>>d[i].d1>>d[i].d2;
    int j=0;
    while(j<n&&j+2<n)
    {
        if(d[j].d1==d[j].d2)
        {
            if(j<n&&d[j+1].d1==d[j+1].d2)
            {
                if(j<n&&d[j+2].d1==d[j+2].d2){
                     cout<<"Yes";
                     exit(0);
                }
            }
        }
        j++;
   }
    cout<<"No";
}


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

int main() {
	int Q;
	cin >> Q;
	for(int q = 0; q < Q; q++) {
		string s;
		cin >> s;
		int in = 0;
		for(int i = 0; i < s.size(); i++) {
			in *= 16;
			if('0' <= s[i] && s[i] <= '9')
				in += s[i] - '0';
			else
				in += s[i] - 'a' + 10;
		}
		if(in & (1 << 31))
			cout << '-';
		cout << ((in & ~(1 << 31)) >> 7);
		double a, b;
		a = 0.0; b = 1.0;
		for(int i = 0; i < 7; i++) {
			b /= 2;
			if(in & (1 << (6-i)))
				a += b;
		}
		stringstream sstr;
		string tmp;
		sstr.precision(10);
		sstr << a;
		sstr >> tmp;
		int j;
		for(j = tmp.size() - 1; j >= 0; j--) {
			if(tmp[j] != '0') break;
		}
		cout << '.';
		cout << string(tmp.begin() + tmp.find('.') + 1, tmp.begin() + j + 1);
		if(tmp.find('.') == j)
			cout << 0;
		cout << endl;
	}
}

Measured memory_bytes: 1296
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ld,ld>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define FORs(i,st) for(auto i : st)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

vector<string> jfen_to_matrix(string s){
  vector<string> v;
  string tmp;
  s.push_back('/');
  FOR(i,0,s.size()){
    if(s[i] == '/'){
      v.push_back(tmp);
      tmp = "";
    }
    else if(s[i] == 'b') tmp.push_back('b');
    else{
      ll range = s[i] - '0';
      FOR(j,0,range){
        tmp.push_back('.');
      }
    }
  }
  return v;
}

string matrix_to_jfen(vector<string> &v){
  string res;

  FOR(i,0,v.size()){
    ll t = 0;
    FOR(j,0,v[0].size()){
      if(v[i][j] == '.') t++;
      else{
        if(t != 0)res.push_back(t + '0');
        res.push_back('b');
        t = 0;
      }
    }
    if(t != 0) res.push_back(t+'0');
    res.push_back('/');
  }
  res.pop_back();
  return res;
}

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

    string s;
    cin>>s;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    while(s != "#"){
      vector<string> v = jfen_to_matrix(s);
      v[a-1][b-1] = '.';
      v[c-1][d-1] = 'b';
      cout<<matrix_to_jfen(v)<<endl;
      cin>>s>>a>>b>>c>>d;
    }



}



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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  ll a, b;
  cin >> a >> b;

  a = max(0LL, a - 1);
  if      (a % 4 == 0);
  else if (a % 4 == 1) a = 1;
  else if (a % 4 == 2) a += 1;
  else if (a % 4 == 3) a = 0;

  if      (b % 4 == 0);
  else if (b % 4 == 1) b = 1;
  else if (b % 4 == 2) b += 1;
  else if (b % 4 == 3) b = 0;

  cout << (a ^ b);
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3644
s = input().rstrip()
s = sorted(s)
while True:
    if len(s) == 0:
        print("Yes")
        break
    l = s.count(s[0])
    if l % 2 != 0:
        print("No")
        break
    else:
        for i in range(l):
            s.remove(s[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n, k, x, y;
  cin >> n >> k >> x >> y;

  if(n <= k){
    cout << n * x << endl;
  }else{
    cout << k * x + (n - k) * y << endl;
  }

  return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long tmp = n;
        int s = 0;
        while (n > 0) {
            s += n %10;
            n /= 10;
        }

        if (tmp % s == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844