akhauriyash/Code-Regression huggingface dataset:
//  IT'S NEVER TOO LATE...

		    #include <bits/stdc++.h>
			#include <complex>
		    #define ll long long

			#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
			#define forn(i, n) fore(i, 0, n)
			#define fori(i, l, r) fore(i, l, (r) + 1)
			#define sz(v) int((v).size())
			#define all(v) (v).begin(), (v).end()
			#define pb push_back
			#define mp make_pair
		    #define ff first
		    #define ss second
		    
			//#define C complex<int>
			#define X real()
			#define Y imag()

		    using namespace std; 

		    const double PI = atan(1)*4;
		    #define inf 1e9
		    const int mod=1e9+7;


		    int main()
		    {
		    	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		     
		    	#ifndef ONLINE_JUDGE
		        freopen("input.txt","r", stdin);
		        freopen("output.txt", "w", stdout);
		        #endif
		     
		    	int tt=1;
		    	//cin>>tt;
		    	
		    	while(tt--)
		    	{
		    		ll n,k,d;
		    		cin>>n>>k>>d;

		    		if(n<0) n=n*(-1);

		    		ll steps=ceil((long double)abs(n)/d);
		    		//cout<<steps;

		    		if(k<=steps)
		    		{
		    			cout<<abs(n-((ll)k*d));
		    		}
		    		else
		    		{
		    			if((k-steps)%2)
		    				cout<<abs(n-((ll)steps*d)+d);
		    			else
		    				cout<<abs(n-((ll)steps*d));
		    		}

		    	}
		    	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";

		    	return 0;
		    }
		    				//              NOW IT'S TIME TO WAKE UP... 

Measured memory_bytes: 3784
//om namah shivaay
//faith over fear
//no one wants to die,yet death is the destination we all share 
// don't think you are,know you are!!

#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
   double a,b,v,w,t;
   cin>>a>>v>>b>>w>>t;
   if(v<=w){
       cout<<"NO";
       return 0;
   }
   double t1=abs(a-b)/(v-w);
   if(t1<=t) cout<<"YES";
   else cout<<"NO";
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int d[110000];
int main(){
    int n,m;cin>>n>>m;
    rep(i,110000) d[i]=0;
    rep(i,m){
        int u,v;cin>>u>>v;
        d[u]++;
        d[v]++;
    }
    rrep(i,n){
        if(d[i]%2!=0){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.*;

public class Main {

    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
        try {
            str = br.readLine();
            if(str.length()<21){
                StringBuilder sb = new StringBuilder();
                sb.append("");
                for(int i = 0;i < str.length();i++){
                    sb.insert(0,str.charAt(i));
                }
                System.out.println(sb);
            }
        } catch (IOException ex) {
        }
        
    }
}

Measured memory_bytes: 24160
#include <stdio.h>
#define MAX(x,y) (x) > (y) ? (x) : (y)
int x[100000];
int main() {
	int n, k, dis, min = 3e8;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%d", &x[i]);
	k--;
	for (int i = 0; i < n - k; i++) {
		if (x[i + k] <= 0) {
			dis = -x[i];
		} else if (0 <= x[i]) {
			dis = x[i + k];
		} else {
			dis = (x[i + k] - x[i]) * 2;
			dis -= MAX(-x[i], x[i + k]);
		}
		if (min > dis)
			min = dis;
	}
	printf("%d\n", min);
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){
    int n;
    int i,sum;
    int maxl = 0;
    scanf("%d",&n);
    int a[100];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for (i=0;i<n;i++){
        if (a[i]>maxl){
            maxl = a[i];
        }
    }
    for (i=0;i<n;i++){
        sum += a[i];
    }
    // printf("%d\n",sum);
    if (maxl<sum-maxl){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <bits/stdc++.h>
#include <iterator>

using namespace std;

int main (){
    string s; cin >> s;
    int leng = s.size();
    string str = "";
    //char a = s[3];
    //cout << a;
    //string::iterator itr = str.end();
    for (int i = 0; i < leng; i++ ){
       // cout << s[i-1];
        //cout << int(s[i]-'0')<< endl;
        switch(int(s[i]-'0')){
            //case 0: str.insert(itr,'0'); break;
            //case 1: str.insert(itr,'1'); break;
            case 0: str.insert(str.end(),'0'); break;
            case 1: str.insert(str.end(),'1'); break;
            default : 
               if (str.empty() == 0){
               str.erase(str.end()-1);
               }
                break;
            //defoult : if (!str.empty()){
            }
        }
//cout << "str=" << str;
cout << str;
}

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

using namespace std;

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

    vector<long long> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] -= i + 1;
    }

    sort(a.begin(), a.end());
    long long b = a[n / 2];

    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += (long long) abs(a[i] - b);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
const int maxn = 110;
const int maxk = 2e5+10;
const int mod = 1e9+7;

int n, k;
int niz[maxn];
int dp[maxk];
int loga[maxk];

int query(int x) {
    int out = 0;
    for (x += 2; x > 0; x -= x & -x)
        out += loga[x], out %= mod;
    return out;
}

void update(int x, int val) {
    for (x += 2; x < maxk; x += x & -x)
        loga[x] += (val + mod) % mod, loga[x] %= mod;
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", niz+i);

    dp[0] = 1; update(0, 1);
    for (int i = 0; i < n; i++) {
        for (int j = k; j > 0; j--) {
            int tren = (query(j) - query(max(0, j - niz[i]) - 1) + mod) % mod;
            update(j, tren - dp[j]);
            dp[j] = tren;
        }
        //for (int j = 0; j <= k; j++) printf("%d ", dp[j]); printf("\n");
    }
    printf("%d", dp[k]);
    return 0;
}


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

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

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

#define MP make_pair
#define PB push_back
#define ft first
#define sd second

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

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

const UDW maxN = 1e6 + 7;
SLL r1, c1, r2, c2;
SLL ans;

SLL fac[maxN * 2];
void init_fact() {
	fac[0] = 1;
	For(i, 1, 2 * maxN - 1) {
		fac[i] = (i * fac[i - 1]) % mod;
	}
}

void input(){
	cin >> r1 >> c1 >> r2 >> c2;
	init_fact();
}

//ax + by = gcd(a, b) = d
// 扩展欧几里德算法
/**
 *	a*x + b*y = 1
 *	如果ab互质，有解
 *	x就是a关于b的逆元
 *	y就是b关于a的逆元
 *	 
 *	证明： 
 *		a*x % b + b*y % b = 1 % b
 *		a*x % b = 1 % b
 *		a*x = 1 (mod b)
 */
inline void ex_gcd(SLL a, SLL b, SLL &x, SLL &y, SLL &d){
    if (!b) {d = a, x = 1, y = 0;}
    else{
        ex_gcd(b, a % b, y, x, d);
        y -= x * (a / b);
    }
}

// 求a关于p的逆元，如果不存在，返回-1 
// a与p互质，逆元才存在 
inline SLL inv_mod(SLL a, SLL p = mod){
    SLL d, x, y;
    ex_gcd(a, p, x, y, d);
    return d == 1 ? (x % p + p) % p : -1;
}

inline SLL comb_mod(SLL m, SLL n) {
	SLL ret;

	if(m > n) swap(m, n);
	
	ret = (fac[n] * inv_mod(fac[m], mod)) % mod;
	ret = (ret * inv_mod(fac[n - m], mod)) % mod;
	
	return ret;
}

void solve(){
	For(i, r1, r2) {
		ans = (ans + comb_mod(i + 1, c2 + i + 1) - comb_mod(i + 1, c1 + i) + mod) % mod;
	}
}

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

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

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

int main () {
    int N,L,s_count=0,m=999;
    cin >> N >> L;
    vector<int> smell(N);
    for(int i=0;i<N;i++){
     smell[i]=L+i;
     s_count+=smell[i];
     m=min(m,abs(smell[i]));
    }
    if(s_count<0) cout << s_count+m << endl;
    else cout << s_count-m << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  bool ans = false;
  int x, y;
  cin >> x >> y;
  rep(i, x + 1) {
    int turu = i * 2;
    int kame = (x - i) * 4;
    if (turu + kame == y) ans = true;
  }

  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;

}

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

#define ll long long
const int inf = 1e9+7;
const ll INF = 1e18+7;

using namespace std;

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

  //dp[i] max value with weight i;
  //dp[0] = 0; dp[i] = max(dp[i-w]+v,dp[i]);
  int n, W;
  
  cin>>n>>W;
  vector<ll> dp(W+1,-1);
  dp[0] = 0;
  ll m = 0;
  for(int i = 0; i < n; ++i){
    ll w, v;
    cin>>w>>v;
    for(int j = W; j >= w; --j){
      if(dp[j-w] != -1){
	dp[j] = max(dp[j],dp[j-w]+v);
	m = max(m, dp[j]);
      }
    }
  }
  cout<<m<<"\n";
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

typedef struct item {
  i32 v, w;
} node;

int cmp (const void *a, const void *b) {
  node *p = (node *)a;
  node *q = (node *)b;
  i64 d = (i64)p->v * q->w - (i64)p->w * q->v;
  return d == 0 ? 0 : d > 0 ? -1 : 1;
}

void run (void) {
  i32 n, w;
  scanf ("%" SCNi32 "%" SCNi32, &n, &w);
  node *p = (node *) calloc (n, sizeof (node));
  for (i32 i = 0; i < n; ++i) {
    i32 a, b;
    scanf ("%" SCNi32 "%" SCNi32, &a, &b);
    p[i] = (node) {a, b};
  }
  qsort (p, n, sizeof (node), cmp);
  double ans = 0;
  for (i32 i = 0; i < n && w > 0; ++i) {
    if (p[i].w <= w) {
      ans += p[i].v;
      w -= p[i].w;
    } else {
      ans += (double)p[i].v / p[i].w * w;
      w = 0;
    }
  }
  printf ("%.7f\n", ans);
}

int main (void) {
  run ();
  return 0;
}



Measured memory_bytes: 2976
// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vector<vector<int>> tree(N);
	int C[N-1];
	rp(i, 0, N-1){
		int p; scanf("%d%d", &p, C+i); p--,C[i]--;
		tree[p].push_back(C[i]);
	}

	int K = 0;
	int colors[N]; rp(i, 0, N) colors[i] = 0;

	queue<int> q;
	q.push(0);
	colors[0] = -1;
	while(!q.empty()){
		int p = q.front(); q.pop();
		int color = 1;
		for(auto c:tree[p]){
			if(colors[c]) continue;
			q.push(c);
			colors[c] = color==colors[p]? ++color: color;
			K = max(K, color++);
		}
	}

	printf("%d\n", K);
	for(int c:C) printf("%d\n", colors[c]);
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
#define N 10
int c[N][N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h, w;
    cin >> h >> w;
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }
    for(int k = 0; k < 10; k++) {
        for(int i = 0; i < 10; i++) {
            for(int j = 0; j < 10; j++) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            int aij;
            cin >> aij;
            if(aij != -1) {
                ans += c[aij][1];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long dp[104][100004];

int main(){
	int n, W;
	cin >> n >> W;
	vector<long> v(n);
	vector<long> w(n);
	for(int i = 0; i < n; i++) {
		dp[i][0] = 0;
      	cin >> w[i] >> v[i];
	}
  	for(int i = 0; i < w[0]; i++) {
    	dp[0][i] = 0; 
    }
  	for(int i = w[0]; i <= W; i++) {
    	dp[0][i] = v[0]; 
    }
  	for(int i = 0; i < n-1; i++) {
    	for(int j = 1; j <= W; j++) {
			if(j - w[i+1] >= 0) {
            	dp[i+1][j] = max(dp[i][j-w[i+1]] + v[i+1], dp[i][j]);
            } else {
             	dp[i+1][j] = dp[i][j]; 
            }
        }
    }
  	cout << dp[n-1][W] << endl;	
}

Measured memory_bytes: 80128
import numpy
import collections
N = int(input())
arr = []
for i in range(N):
    a,b = map(int,input().split())
    arr.append([a+b,a,b])

arr = sorted(arr,reverse=True)
ansa,ansb = 0 , 0
for i in range(N):
    if i % 2 == 0:
        ansa += arr[i][1]
    else:
        ansb += arr[i][2]
print(ansa - ansb)


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

int main(){
  string str;
  char c;
  int cnt = 0;
  bool chk = true;
  
  cin >> str;
  
  if(str.substr(0,1) != "A") chk = false;
  
  for(int i = 2; i < str.size()-1; i++){
    c = str.at(i);
    if(str.substr(i,1) == "C") cnt++;
    else if(islower(c) == false) chk = false;
  }
  if(cnt != 1) chk = false;
  
  c = str.at(1);
  if(islower(c) == false) chk = false;
  c = str.at(str.size()-1);
  if(islower(c) == false) chk = false;
  
  if(chk == true) cout << "AC";
  else cout << "WA";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin>>s;
    int l=s.length();
    if(s[0]==s[l-1]){
        if(l%2==0){
            cout<<"First"<<endl;
            return 0;
        }
        else{
            cout<<"Second"<<endl;
            return 0;
        }
    }
    else{
        if(l%2==0){
            cout<<"Second"<<endl;
            return 0;
        }
        else{
            cout<<"First"<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int a, b;
	cin >> a >> b;
	if (b == 1) {
		cout << 0;
		return 0;
	}
	int ans;
	for (ans = 1; 1; ans++) {
		if (ans == 1)
			b--;
		b -= a - 1;
		if (b <= 0)
			break;
	}
	cout << ans;
}

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

int main(){
	int n,i,j;
	while(cin >> n && n){
		int table[11][11] = {{0}};
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				cin >> table[i][j];
				table[i][n] += table[i][j];
				table[n][j] += table[i][j];
			}
			table[n][n] += table[i][n];
		}
		for(i = 0;i <= n;i++){
			for(j = 0;j <= n;j++){
				printf("%5d",table[i][j]);
			}
			cout << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 0
char buf[2<<20];
sz;
cnt[1<<20];
main()
{
	read(0,buf,2<<20);
	int N=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(int i=0;i<N;i++)
	{
		int A=0;
		for(;;)
		{
			char k=buf[sz++];
			if(k<'0')break;
			A=A*10+k-'0';
		}
		cnt[A]++;
	}
	int ans=0;
	for(int i=1;i<=1000000;i++)
	{
		if(cnt[i])
		{
			ans+=cnt[i]<2;
			for(int j=i+i;j<=1000000;j+=i)cnt[j]=0;
		}
	}
	printf("%d",ans);
}


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

int main(){
  string s;
  int pos, pos2;
  bool finded = false;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A' && finded==false){
      pos = i;
      finded = true;
    }
    else if(s[i]=='Z')pos2 = i;
  }
  cout << pos2-pos+1 << endl;
  return 0;
}


Measured memory_bytes: 640
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100000;

int aa[N + 1], ii[N + 1];
long long kk[N + 1];

int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> aa[i];
		ii[i] = i;
	}
	sort(ii, ii + n + 1, [] (int i, int j) { return aa[i] > aa[j]; });
	for (int h = 0, h_, i = n, i_; h < n; h = h_) {
		int a = aa[ii[h]];
		h_ = h;
		while (aa[i_ = ii[h_]] == a) {
			i = min(i, i_);
			h_++;
		}
		int b = aa[ii[h_]];
		kk[i] += (long long) (a - b) * h_;
	}
	for (int i = 1; i <= n; i++)
		cout << kk[i] << '\n';
	return 0;
}


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

#define MOD 1000000007

typedef long long ll;

int N;
char S[2][100] = {0};
ll ans = 1;


int main()
{
    scanf("%d",&N);
    scanf("%s%s",S[0],S[1]);
    for(int i = 0; i < N; i++)
    {
        if(i == 0)
        {
            if(S[0][i] == S[1][i])
            {
                ans = 3;
            }
            else
            {
                ans = 6;
                i++;
            }
            continue;
        }
        if(S[0][i] == S[1][i])
        {
            if(S[0][i - 1] == S[1][i - 1])
            {
                ans *= 2;
            }
        }
        else
        {
            if(S[0][i - 1] == S[1][i - 1])
            {
                ans *= 2;
            }
            else
            {
                ans *= 3;
            }
            i++;
        }
        ans %= MOD;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll X;
  cin>>X;
  if(X==3||X==5||X==7) {
cout<<"YES"<<endl;
  }
  else {
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 3640
s = input()
n = len(s)-1
N = []
total = 0
for i in range(2**n):
  nums = ""
  for j in range(n+1):
    nums+=s[j]
    if ((i>>j)&1):
      nums+="+"
  nums = nums.split("+")
  
  N.append([int(i) for i in nums])

for _ in N:
  total +=sum(_)
  
print(total)

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
// const ll MOD = 1000000007;

ll MOD;
ll binpow(ll x, ll e) {
  ll ret = 1, p = x;
  while(e > 0) {
    if(e&1) {(ret *= p) %= MOD; e--;}
    else {(p *= p) %= MOD; e /= 2;}
  }
  return ret;
}

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

    ll p;
    cin >> p;
    vector<ll> a(p);
    REP(i, p) cin >> a[i];

    MOD = p;
    vector<ll> inv(p+2);
    REP(i, p+2) inv[i] = binpow(i, p-2);

    vector<ll> ans(p);
    REP(j, p) {
        if(a[j] == 0) continue;
        ll c = 1, po = 1;
        REP(k, p) {
            (ans[p-1-k] += p - (c * po % p)) %= p;
            (po *= p-j) %= p;
            (c *= p-1-k) %= p;
            (c *= inv[k+1]) %= p;
        }
        ans[0]++;
    }
    ans[0] %= p;

    REP(i, p) cout << ans[i] << (i==p-1?'\n':' ');

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define mx 100009
ll n,k;
ll ar[mx+10];
ll br[mx+10];

ll dp(ll a){
    br[n-1]=0;
    for(ll i=n-2;i>=0;i--){
        ll mn=INT_MAX;
        for(ll j=1;j<=k;j++){
            if(i+j<=n-1){
                ll x=abs(ar[i]-ar[i+j])+br[i+j];
                mn=min(mn,x);
            }
        }
        br[i]=mn;
    }
    return br[0];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin>>n>>k;
    for(ll i=0;i<n;i++){
        cin>>ar[i];
    }
    cout<<dp(0)<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10

ll N;

bool check(ll ipt) {
	set<int>s;
	while (ipt != 0) {
		s.insert(ipt % 10);
		ipt /= 10;
	}
	if (s.size() == 3)return true;
	else return false;
}

ll dfs(ll cur) {
	if (cur > N)return 0;
	ll out = 0;

	if (check(cur))out++;


	out += dfs(cur * 10 + 3);
	out += dfs(cur * 10 + 5);
	out += dfs(cur * 10 + 7);
	return out;
}

int main() {
	cin >> N;

	ll cnt = dfs(3);
	cnt += dfs(5);
	cnt += dfs(7);
	print(cnt);


	return 0;
}


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


const int MAX = 200005;
const int MOD = 1000000007;
//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


signed main(){
    init();
    int  b,w,ans=inv[2],p=1;
    cin >>b>>w;
 
    for(int i=1;i<=b+w;i++){
      p=(p*inv[2])% MOD;
      ans= (ans +p*(COM(i-2,w-1)+MOD-COM(i-2,b-1)))%MOD;
        cout<< ans<<endl;
    }
   
    return 0;
}


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

void mod_inverse(int n, vector<long long>& inv, int mod)
{
    inv.assign(n+1, -1);
    inv[1] = 1;
    for(int i=2; i<=n; ++i)
        inv[i] = inv[mod % i] * (mod - mod / i) % mod;
}

class FactorialCalculation
{
private:
    const int mod;
    vector<long long> factorial;
    vector<long long> invFactorial;
public:
    FactorialCalculation(int n, int mod) : mod(mod)
    {
        factorial.resize(n+1, 1);
        invFactorial.resize(n+1, 1);
        vector<long long> inv;
        mod_inverse(n, inv, mod);
        for(int i=1; i<=n; ++i){
            factorial[i] = factorial[i-1] * i % mod;
            invFactorial[i] = invFactorial[i-1] * inv[i] % mod;
        }
    }
    long long getFactorial(int n){
        return factorial[n];
    }
    long long getInvFactorial(int n){
        return invFactorial[n];
    }
    long long getPermutation(int n, int r){
        if(n < r)
            return 0;
        return factorial[n] * invFactorial[n-r] % mod;
    }
    long long getCombination(int n, int r){
        if(n < r)
            return 0;
        return getPermutation(n, r) * invFactorial[r] % mod;
    }
    long long getHomogeneous(int n, int r){
        return getCombination(n+r-1, r);
    }
};

const int MOD = 1000000007;

int main()
{
    int n, k;
    cin >> n >> k;
    FactorialCalculation fc(n, MOD);

    for(int i=1; i<=k; ++i){
        long long ans = fc.getCombination(n-k+1, i);
        ans *= fc.getHomogeneous(i, k-i);
        ans %= MOD;
        cout << ans << endl;
    }

    return 0;
}


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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    int k;
    cin >> k;

    string s;
    cin >> s;

    int size = s.size();

    if(size <= k){
        cout << s << endl;
    }else{
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool ask(ll x){
    printf("? %lld\n",x);
    fflush(stdout);
    char res;scanf(" %c",&res);
    if(res=='Y')return true;
    else return false;
}
int n;
int main(){
    ll ans=0;
    while(1){
        int l=0,r=9;
        int mid,res;
        while(l<=r){
            mid=l+r>>1;
            if(ask(ans*10+mid))res=mid,l=mid+1;
            else r=mid-1;
        }
        if(res!=9)ans=ans*10+res;
        else{
            if(ask(ans*100+10)){
                ll t=ans*100+10;
                while(t<=1000000000)t*=10;
                if(ask(t)){
                    t=ans*100;
                    if(t&&ask(t))ans=ans*10;
                    else ans=ans*10+1;
                    break;
                }
                else ans=ans*10+9;
            }
            else{
                l=2,r=9;
                while(l<=r){
                    mid=l+r>>1;
                    if(ask(ans*100+mid*10))res=mid,r=mid-1;
                    else l=mid+1;
                }
                ans=ans*10+res;
                break;
            }
        }
    }
    printf("! %lld\n",ans);
    fflush(stdout);
    return 0;
}

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

signed main(){

  int q;
  cin>>q;
  map<string,int> mp;
  while(q--){
    int c;
    cin>>c;
    if(c==0){
      string key;
      int x;
      cin>>key>>x;
      mp[key] = x;
    }
    if(c==1){
      string key;
      cin>>key;
      cout<<mp[key]<<endl;
    }
  }

}


Measured memory_bytes: 27860
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main()
{
    vector<string> list(3);
    rep(i, 3) cin >> list.at(i);
    rep(i, 2)
    {
        if (list.at(i).at(list.at(i).size() - 1) != list.at(i + 1).at(0))
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define MOD2 (lli) 998244353  
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int n;
vector<int> vec[MAXN];
int q;
lli sum[MAXN];

void dfs(int x, int p){
  for(auto i : vec[x]){
    if(i == p) continue;
    sum[i] += sum[x];
    dfs(i, x);
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  cin >> n >> q;
  for(int i=0;i<n-1;i++){
    int a, b;
    cin >> a >> b;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }

  while(q--){
    int a, b;
    cin >> a >> b;
    sum[a] += b;
  }

  dfs(1, -1);

  for(int i=1;i<=n;i++) cout << sum[i] << " ";
  cout << endl;

  return 0;
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    if(n==2){
        ll x,y;cin>>x>>y;
        if(x>y)swap(x,y);
        ll res=y-x;
        cout<<res<<endl;
        cout<<y<<" "<<x<<endl;
        return 0;
    }
    vector<ll> b,c;
    rep(i,n){
        ll a;cin>>a;
        if(a>0)b.push_back(a);
        else c.push_back(a);
    }
    vector<pair<ll,ll>> p;
    ll res=0;
    if(b.size()==0){
        sort(c.begin(),c.end());
        res=c[n-1]-c[0];
        p.push_back({c[n-1],c[0]});
        rep(i,n-2){
            p.push_back({res,c[i+1]});
            res-=c[i+1];
        }
    }else{
        if(b.size()==n){
            sort(b.begin(),b.end());
            res=b[n-1]-b[0];
            p.push_back({b[0],b[n-1]});
            rep(i,n-3){
                p.push_back({-res,b[i+1]});
                res+=b[i+1];
            }
            p.push_back({b[n-2],-res});
            res+=b[n-2];
        }else{
            res=b[0];
            rep(i,b.size()-1){
                p.push_back({c[0],b[i+1]});
                c[0]-=b[i+1];
            }
            rep(i,c.size()){
                p.push_back({res,c[i]});
                res-=c[i];
            }
        }
    }
    cout<<res<<endl;
    rep(i,n-1)cout<<p[i].first<<" "<<p[i].second<<endl;
}

Measured memory_bytes: 7028
def euler_phi(n):
    ans = n
    if n < 2:
        return ans
    if n % 2 == 0:
        while n % 2 == 0:
            n //= 2
        ans -= ans // 2
    p = 3
    while p*p <= n:
        if n % p == 0:
            while n % p == 0:
                n //= p
            ans -= ans // p
        p += 2
    if n > 1:
        ans -= ans // n
    return ans

n = int(input())
print(euler_phi(n))


Measured memory_bytes: 5596
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use proconio::{marker::*, *};
const MOD: i64 = 1000000007;
fn main() {
    input! {
        l:Chars,
    }
    let n = l.len();
    let mut dp = vec![vec![0; 2]; 111111]; // iけためまで
    dp[0][1] = 1;//limited
    for i in 0..n {
        if l[i] == '1' {
            dp[i + 1][0] += dp[i][0] * 3 + dp[i][1];
            dp[i + 1][1] += dp[i][1] * 2;
        } else {
            // '0'
            dp[i + 1][0] += dp[i][0] * 3;
            dp[i + 1][1] += dp[i][1];
        }
        dp[i + 1][0] %= MOD;
        dp[i + 1][1] %= MOD;
    }
    println!("{}", (dp[n][0] + dp[n][1]) % MOD);
}


Measured memory_bytes: 8572
n,k=map(int,input().split())
A=[int(i) for i in input().split()]

went={i:0 for i in range(1,n+1)}

now=1
cnt=1
for i in range(n+1):
    if went[now]>0:
        t=cnt-1
        s=went[now]
        break
    else:
        went[now]=cnt
        now=A[now-1]
        cnt+=1


if k <= t-1:
    val=k+1
else:
    val=((k+1-t)%(t-s+1)-1)%(t-s+1)+s
for ele in went:
    if went[ele]==val:
        print(ele)
        break

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

using namespace std;

using ll = long long;

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

    vector<int> deg(4);
    for (int i = 0, a, b; i < 3; ++i) {
        cin >> a >> b;
        ++deg[a - 1]; ++deg[b - 1];
    }

    bool is_path = !any_of(deg.begin(), deg.end(),
                           [](int d) { return d == 3; });
    cout << (is_path ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.readInt;
object Main {
    def main(args: Array[String]): Unit = {
        println(fibonacci(readInt));
    }
    def fibonacci(n: Int): Int = {
        def _fibonacci(cnt: Int, list: List[Int]): Int = {
            if (cnt < 0) list.head;
            else list match {
                case x1 :: x2 :: xs => _fibonacci(cnt - 1, (x1 + x2) :: list);
                case _ => _fibonacci(cnt - 1, 1 :: list);
            }
        }
        _fibonacci(n, Nil);
    }
}


Measured memory_bytes: 43772
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double[] p = new double[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextDouble();
        }
        
        // dp[i][j] = i枚目までやったときに、j枚表が出る確率
        double[][] dp = new double[n + 1][n + 1];
        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= i; j++) {
                dp[i + 1][j + 1] += dp[i][j] * p[i];
                dp[i + 1][j] += dp[i][j] * (1 - p[i]);
            }
        }
        
        double answer = 0;
        for (int x = n / 2 + 1; x <= n; x++) {
            answer += dp[n][x];
        }
        
        System.out.println(answer);
    }
}

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

const ll INF = 1e18L + 9;

int main(){
    int n, w;
    cin >> n >> w;
    vector<ll> wt(n) , val(n);
    for(int i = 0; i < n; i++)
        cin >> wt[i] >> val[i];
    int sum_val = 0;
    for(int x: val){
        sum_val += x;
    }
    vector <ll> dp(sum_val + 1, INF);
    // stores minimum weight that provides value i;
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int value_already = sum_val - val[i]; value_already >=0; --value_already){
            dp[value_already + val[i]] = min(dp[value_already + val[i]], dp[value_already]+wt[i]);
        }
    }
    ll ans = 0;
    for(int i = 0; i <= sum_val; i++){
        if(dp[i] <= w){
            ans = max(ans, (ll)i);
        }
    }
    cout << ans;
}


Measured memory_bytes: 4024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int main() {
  while(1) {
    int n;
    vector<int> s;
    double m=0, res=0;

    cin >> n;
    if(n == 0) break;

    for(int i=0; i<n; i++) {
      int temp;
      cin >> temp;
      s.push_back(temp);
    }

    for(auto itr=s.begin(); itr!=s.end(); itr++) {
      m += *itr;
    }
    m /= n;

    for(auto itr=s.begin(); itr!=s.end(); itr++) {
      res += pow((double)(*itr) - m, 2);
    }
    res /= n;
    res = sqrt(res);

    cout << to_string(res) << endl;
  }
  return 0;
}


Measured memory_bytes: 3280
import math

N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]

ans = 0

for i in range(N):
    for j in range(i+1,N):
        dist = 0
        for p in range(D):
            dist += (X[i][p]-X[j][p])*(X[i][p]-X[j][p])
        dist = math.sqrt(dist)
        if dist == int(dist):
            ans+=1
                
print(ans)

Measured memory_bytes: 9096
//B - Strings with the Same Length

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

int main()
{
	int n;
	scanf("%d",&n);
	char a[n],b[n];
	scanf("%s %s",&a,&b);
	for(int i=0; i<n; i++){
		printf("%c%c",a[i],b[i]);
	}	
	printf("\n");
	return 0;
}	


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

int main(void){
  double a,b,c,phi,S,L,h,rad;
  
  scanf("%lf %lf %lf",&a,&b,&phi);
  rad=M_PI*phi/180.0;
  S=a*b*sin(rad)/2.0;
  c=sqrt(a*a+b*b-2*a*b*cos(rad));
  L=a+b+c;
  h=S*2/a;
  printf("%0.8lf\n%0.8lf\n%0.8lf\n",S,L,h);
  
  return(0);
}

Measured memory_bytes: 652
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int NMAX = 100010;
int num[NMAX];
bool red[NMAX];

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, M; cin >> N >> M;
  vector<int> x(M), y(M);
  for(int i = 0; i < NMAX; ++i) {
    num[i] = 1;
    red[i] = false;
  }
  red[0] = true;

  for(int i = 0; i < M; ++i) {
    cin >> x[i] >> y[i]; x[i]--, y[i]--;
    if(red[x[i]]) red[y[i]] = true;
    num[x[i]] -= 1;
    num[y[i]] += 1;
    if(num[x[i]] == 0) red[x[i]] = false;
  }

  int ans = 0;
  for(int i = 0; i < NMAX; ++i) {
    if(red[i]) ans++;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 1536
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    int N;
    cin >> N;
    vector<int> a(N);

    int sum = 0;
    REP(i, N) {
        cin >> a[i];
        sum += a[i];
    }

    int d = INF;
    int ans = -1;
    REP(i, N) {
        if (abs(a[i] * N - sum) < d) {
            d = abs(a[i] * N - sum);
            ans = i;
        }
    }
    cout << ans << endl;

    return 0;
}


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


int main() {
	char a, b;
	cin >> a >> b;
	string aa(b - '0', a);
	string bb(a - '0', b);
	cout << (aa < bb ? aa : bb) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int kiriage(int &number) {
	if (number % 10 == 0) return number;
	number++;
	return kiriage(number);
}

int main() {
	int sum = 0;
	int amari_min = 10;
	rep(i, 0, 5) {
		int menu = 0;
		cin >> menu;
		int amari = menu % 10;
		if (amari != 0) {
			amari_min = min(amari_min, amari);
			kiriage(menu);
		}
		sum += menu;
	}
	cout << sum - (10 - amari_min) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7
#define INF 1000000007 //10^9+7

ll N, Q;

pair<ll, ll> QUERY[200005];

/*
 *範囲の和を取得
 */
//区間[l, r)
struct segtree {
	vector<long long> data;
	long long n;
	segtree(long long nin){
		n = pow( 2, ceil( log(nin) / log(2) ) );
		long long size = 2 * n - 1;
		this->data.resize(size, 1e9);
	}

	//API for update val
	void update(long long idx, long long val){
		update(idx, val, 0, 0, n);
	}

	long long update(long long idx, long long val, long long node_id, long long left, long long right){
		//if query idx is within range return val
		if( !( left <= idx && idx < right ) ){
			return data[node_id];
		}
		if( left + 1 < right ) {
			//when node range is not 1, get update children val and update node data
			long long mid = (left + right) / 2 ;
			long long L = update(idx, val, 2 * node_id + 1, left, mid);
			long long R = update(idx, val, 2 * node_id + 2, mid, right);
			data[node_id] = min(L, R);
		} else {
			//when node range is 1, update node data
			data[node_id] = min(data[node_id], val);
		}
		return data[node_id];
	}
	
	//API for get value of [l, r)
	long long get(long long l, long long r){
		return get(l, r, 0, 0, n);
	}

	/*
	 *internaly used function
	 *query_l: query left range
	 *query_r: query right range
	 *node_id: node id of 
	 *node_l:  node left range 
	 *node_r:  node right range
	 */
	long long get(long long query_l, long long query_r, long long node_id, long long node_l, long long node_r){
		//query range is outside of node range: return INF
		if( query_r <= node_l || node_r <= query_l ){
			return INF;
		}
		//query range is within node range: return node val
		if( query_l <= node_l && node_r <= query_r ){
			return data[node_id];
		}
		long long mid = (node_l + node_r) / 2;
		long long L = get(query_l, query_r, 2 * node_id + 1, node_l, mid);
		long long R = get(query_l, query_r, 2 * node_id + 2, mid, node_r);
		return min(L, R);
	}
};

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

	rep(i, Q) {
		cin >> QUERY[i].first >> QUERY[i].second;
		QUERY[i].second--;
	}
	ll ans =  (N-2) * (N-2);


	segtree yokosg(N + 2);
	segtree tatesg(N + 2);

	rep(i, N + 4) {
		yokosg.update(i, N-2);
		tatesg.update(i, N-2);
	}

	rep(i, Q) {
		ll pos = QUERY[i].second;

		if(QUERY[i].first == 1) {
			//下に行く
			ll haba = tatesg.get(pos, N);

			ans -= haba;

			yokosg.update(haba, pos - 1);
		} else {
			//右に行く
			ll haba = yokosg.get(pos, N);

			ans -= haba;

			tatesg.update(haba, pos - 1);
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 14964
////////////////////////////////////////////////////////////////
//
//    (☝ ՞ਊ ՞)☝ << Be accept!!
//
//    C++ format for competitive professional v1.0
//
//    need gcc & boost::c++
//
////////////////////////////////////////////////////////////////
#define BOOST
#define CGCC
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#ifdef BOOST
#include<boost/multiprecision/cpp_int.hpp>// cpp_int 
using namespace boost::multiprecision;
#endif
#define rep(i,n) for(int i = 0;i < n;i++)
using ll = long long;
using namespace std;
#ifdef CGCC
#pragma once
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
int inline setup(void) {//set
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	return 0;
}
int lenght(char* str){//getcharlengh
	int i = 0;
	while (str[i]) {
		i++;
	}
	return i;
}
int gcd(long long a, long long b) {
	if (a < b)return gcd(b, a);
	long long r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
#define DEBUG
int main(int argc, const char* argv[]) {
	setup();
		
	string w;
	cin >> w;
	rep(i, w.length()) {
		cout << "x";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/ruby

a, b = STDIN.readline.split(/\s+/).map{|m| m.to_i}
s = STDIN.readline.chomp.split(//)

def yes
  puts "Yes"
  exit
end

def no
  puts "No"
  exit
end

no if s[a] != "-"
s[a] = "0"

s.each do |d|
  no if d !~ /\d/
end

yes


Measured memory_bytes: 1916
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define PB push_back
#define POP pop_back()
#define PII pair<int,int>
#define FI first
#define SE second
#define ULL unsigned long long
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
vector<int>edg[200005];
int vis[200005];

void dfs(){
	queue<int>num;
	vis[1]=1;
	num.push(1);
	while(num.size()){
		int tmp=num.front();
		num.pop();
		int len=edg[tmp].size();
		for(int i=0;i<len;i++){
			if(vis[edg[tmp][i]]==0){
				vis[edg[tmp][i]]=tmp;
				num.push(edg[tmp][i]);
			}
		}
	}
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<200005;i++){
		vis[i]=0;
	}
	int ta,tb;
	for(int i=0;i<m;i++){
		scanf("%d%d",&ta,&tb);
		edg[ta].PB(tb);
		edg[tb].PB(ta);
	}
	dfs();
	for(int i=1;i<=n;i++){
		if(vis[i]==0){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	for(int i=2;i<=n;i++){
		printf("%d\n",vis[i]);
	}
 	return 0;
}







Measured memory_bytes: 13408
#include<iostream>
#include<cstdio>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
#define MAX 100

enum {SPACE, LOSE, BACK};

double C[MAX+2][MAX+1];
int S[MAX+1];
int N, T, L, B;

void compute(){
    C[0][0] = 1;
    for ( int i = 0; i < T; i++ ){
	for ( int j = 0; j < N; j++ ){
	    for ( int k = 1; k <= 6; k++ ){
		int t =  j+k;
		if ( t >= N ) t = N-(t-N);
		int s = i+1;
		if ( S[j] == LOSE ) s++;
		if ( S[t] == BACK ) t = 0;
		C[s][t] += C[i][j]/6;
	    }
	}
	C[i+1][N] += C[i][N];
    }

    printf("%.8lf\n", C[T][N]);
}

main(){
    while( cin >> N >> T >> L >> B && N){
	rep(i, T+1) rep(j, N+1) C[i][j] = 0;
	int x;
	rep(i, N+1) S[i] = SPACE;
	rep(i, L) { cin >> x; S[x] = LOSE; }
	rep(i, B) { cin >> x; S[x] = BACK; }
	compute();
    }
}

Measured memory_bytes: 0