akhauriyash/Code-Regression huggingface dataset:
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N,M;
map<string,int> mp;
bool e[200][200],ee[200][200];
int t[200];
void dfs(int x,int c){
	t[x]=c;
	rep(i,N){
		if(e[x][i]&&t[i]==0) dfs(i,-c);
		else if(e[x][i]) assert(t[i]==-t[x]);
	}
	rep(i,N){
		if(e[i][x]&&t[i]==0) dfs(i,-c);
		else if(e[i][x]) assert(t[i]==-t[x]);
	}
}
int main(){
	while(true){
		cin>>M;
		if(M==0) break;
		mp.clear();
		rep(i,200) rep(j,200) e[i][j]=0,ee[i][j]=(i==j);
		rep(i,200) t[i]=0;
		int J=0;
		rep(i,M){
			string st;
			cin>>st;
			int j=0;
			while(st[j]!='-') j++;
			string xx=st.substr(0,j),yy=st.substr(j+1);
			if(!mp.count(xx)) mp[xx]=J++;
			if(!mp.count(yy)) mp[yy]=J++;
			int x=mp[xx],y=mp[yy];
			e[x][y]=1;
		}
		N=mp.size();
		cout<<N<<endl;
		int I=1;
		rep(i,N) if(t[i]==0) dfs(i,I++);
		rep(i,N) rep(j,N){
			bool a=0,b=1;
			rep(k,N){
				if((e[i][k]||e[k][i])&&(e[j][k]||e[k][j])) a=1;
				if((e[i][k]&&e[k][j])||(e[j][k]&&e[k][i])) b=0;
			}
			if(a&&b) ee[i][j]=1;
		}
		rep(i,N) rep(j,N) e[i][j]|=ee[i][j];
		rep(i,N) rep(j,N) rep(k,N) if(e[j][i]&&e[i][k]) e[j][k]=1;
		int Q;
		cin>>Q;
		rep(tt,Q){
			string st;
			cin>>st;
			int j=0;
			while(st[j]!='-') j++;
			string xx=st.substr(0,j),yy=st.substr(j+1);
			if(!mp.count(xx)||!mp.count(yy)){
				puts("NO");
				continue;
			}
			int x=mp[xx],y=mp[yy];
			if(t[x]==-t[y]&&e[x][y]) puts("YES");
			else puts("NO");
		}
	}
}

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

int main(){
    int a,b; cin >> a >> b;
    int ans = -1;
    for(int i=1;i<=1300;i++){
        if(i*2/25 == a && i/10 == b){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


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

int main(){

    int X,A,B,C,D;
    cin>>X;
    D=X%10;
    X/=10;
    C=X%10;
    X/=10;
    B=X%10;
    X/=10;
    A=X%10;
    if(A+B+C+D==7) cout<<A<<"+"<<B<<"+"<<C<<"+"<<D<<"=7"<<endl;
    else if(A-B+C+D==7) cout<<A<<"-"<<B<<"+"<<C<<"+"<<D<<"=7"<<endl;
    else if(A+B-C+D==7) cout<<A<<"+"<<B<<"-"<<C<<"+"<<D<<"=7"<<endl;
    else if(A+B+C-D==7) cout<<A<<"+"<<B<<"+"<<C<<"-"<<D<<"=7"<<endl;
    else if(A-B-C+D==7) cout<<A<<"-"<<B<<"-"<<C<<"+"<<D<<"=7"<<endl;
    else if(A-B+C-D==7) cout<<A<<"-"<<B<<"+"<<C<<"-"<<D<<"=7"<<endl;
    else if(A+B-C-D==7) cout<<A<<"+"<<B<<"-"<<C<<"-"<<D<<"=7"<<endl;
    else if(A-B-C-D==7) cout<<A<<"-"<<B<<"-"<<C<<"-"<<D<<"=7"<<endl;
}
    


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

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

void solve(void) {
  ll n; cin >> n;
  vector<ll> a(n);
  rep(n, i) cin >> a[i];

  vector<ll> ruiseki_max(n+2, -1);
  vector<ll> ruiseki_max_inv(n+2, -1);
  for(ll i = 1; i <= n; ++i) ruiseki_max[i] = max(ruiseki_max[i-1], a[i-1]);
  for(ll j = n; j > 0; --j) ruiseki_max_inv[j] = max(ruiseki_max_inv[j+1], a[j-1]);

  for(ll i = 1; i <= n; ++i) {
    cout << max(ruiseki_max[i-1], ruiseki_max_inv[i+1]) << endl;
  }
}

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


Measured memory_bytes: 7964
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int main(){
    int n;
    cin >> n;
    multiset<ll,greater<ll> >st;
    rep(i,n){
        ll a;
        cin >> a;
        st.insert(a);
    }
    int ans = 0;
    for(auto itr = st.begin();itr!=st.end();){
        ll a = *itr;
        itr = st.erase(itr);
        ll s = 0;
        ll ok = 32;
        ll ng = 0;
        while(ok-ng>1){
            ll mid = (ok+ng)/2;
            if((1LL<<mid) > a){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        s = 1LL<<ok;
        if(st.count(s-a)>0){
            auto itr2 = st.find(s-a);
            if(itr==itr2){
                itr = st.erase(itr);
            }else{
                st.erase(itr2);
            }
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a > b){
        cout << "a > b" << endl;
    }
    if(a < b){
        cout << "a < b" << endl;
    }
    if(a == b){
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3088
n,a,b = map(int, input().split())
if n == 1:
  if a != b:
    print(0)
  else:
    print(1)
elif n == 2:
  if a == b or a < b:
    print(1)
  else:
    print(0)
else:
  if  a > b:
    print(0)
  else:
    print((b - a) * (n - 2) + 1)

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean f(String s, String t, String x) {
		boolean f = true;
		int pos = 0;
		int n = s.length(), m = t.length();
		for (int i=0, j=0; i<n || j<m;) {
			if (f) {
				while (i < n) if (s.charAt(i++) == x.charAt(pos)) {
					pos++;
					f = !f;
					break;
				}
				if (f) break;
			} else {
				while (j < m) if (t.charAt(j++) == x.charAt(pos)) {
					pos++;
					f = !f;
					break;
				}
				if (!f) break;
			}
			if (pos == x.length()) return true;
		}

		return false;
	}

	static void solve() {
		String s = in.next();
		String t = in.next();
		out.println(f(s, t, s) || f(t, s, s) ? "Yes" : "No");
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 26368
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    int a[101];
    REP(i, n)
    {
        cin >> a[n - 1 - i];
    }
    REP(i, n)
    {
        if (i > 0)
            cout << " ";
        cout << a[i];
    }
    cout << endl;
}


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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

typedef long double ld;

const int MAX = 302;

ld memo[MAX][MAX][MAX];

int n;

ld dp(int a, int b, int c) {
	if(a < 0 or b < 0 or c < 0) return 0;
	if(!a and !b and !c) return 0;
	ld& p = memo[a][b][c];
	if(p != -1) return p;

	ld tot = a+b+c;
	
	ld ret = n/tot;
	ret += (ld) (a/tot)*dp(a-1,b,c);
	ret += (ld) (b/tot)*dp(a+1,b-1,c);
	ret += (ld) (c/tot)*dp(a,b+1,c-1);

	return p = ret;
}

int main(){ _

	for(int i=0; i<MAX; i++) 
		for(int j=0; j<MAX; j++) 
			for(int k=0; k<MAX; k++) 
				memo[i][j][k] = -1;

	cin >> n;
	int n1=0, n2=0, n3=0;
	for(int i=0; i<n; i++) {
		int a; cin >> a;
		if(a==1) n1++;
		else if(a==2) n2++;
		else n3++;
	}

	cout << fixed << setprecision(10);

	cout << dp(n1,n2,n3) << endl;

	return 0;
}


Measured memory_bytes: 434144
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int x,y,z;
vector<string> ss;

int main(void){
	scanf("%d%d%d",&x,&y,&z);
	for(int i=0;i<x;i++){
		ss.push_back("a");
	}
	for(int i=0;i<y;i++){
		ss.push_back("b");
	}
	for(int i=0;i<z;i++){
		ss.push_back("c");
	}
	while(ss.size()>1){
		sort(ss.begin(),ss.end());
		ss[0]+=ss[ss.size()-1];
		ss.pop_back();
	}
	cout << ss[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#define LIMIT 2000001

void CountingSort(short A[], short B[], int n) {
    int C[LIMIT];
    for (int i = 0; i < LIMIT; i++) {
        C[i] = 0;
    }
    for (int j = 0; j < n; j++) {
        C[A[j]]++;
    }
    for (int i = 1; i < LIMIT; i++) {
        C[i] = C[i] + C[i-1];
    }
    for (int j = n - 1; j >= 0; j--) {
        B[C[A[j]]-1] = A[j];
        C[A[j]]--;
    }
}

int main() {
    int n;
    scanf("%d", &n);

    short A[n], B[n];
    for (int i = 0; i < n; i++) {
        scanf("%hd", &A[i]);
    }

    CountingSort(A, B, n);
    
    for (int i = 0; i < n; i++) {
        if (i) printf(" ");
        printf("%hd", B[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 18196
#include<stdio.h>
#include<math.h>
double Koch(int,double,double,double,double);
int main()
{
  int n;
  scanf("%d",&n);
  printf("%.8f %.8f\n",0.0,0.0);
  Koch(n,0,0,100,0);
  printf("%.8f %.8f\n",100.0,0.0);
  return 0;
}
 
double Koch(int n,double leftx,double lefty,double rightx,double righty)
{
  if(n!=0){
  double santou[3][2];
  santou[0][0]=(2*leftx+rightx)/3;
  santou[0][1]=(2*lefty+righty)/3;
  santou[2][0]=(leftx+2*rightx)/3;
  santou[2][1]=(lefty+2*righty)/3;
 
  santou[1][0]=(santou[2][0]-santou[0][0])/2-(santou[2][1]-santou[0][1])*sqrt(3)/2+santou[0][0];
  santou[1][1]=(santou[2][0]-santou[0][0])*sqrt(3)/2+(santou[2][1]-santou[0][1])/2+santou[0][1];
   
Koch(n-1,leftx,lefty,santou[0][0],santou[0][1]);
  printf("%.8f %.8f\n",santou[0][0],santou[0][1]);
  Koch(n-1,santou[0][0],santou[0][1],santou[1][0],santou[1][1]);
  printf("%.8f %.8f\n",santou[1][0],santou[1][1]);
  Koch(n-1,santou[1][0],santou[1][1],santou[2][0],santou[2][1]); 
  printf("%.8f %.8f\n",santou[2][0],santou[2][1]);
  Koch(n-1,santou[2][0],santou[2][1],rightx,righty); 
  }
  if(n==0)return 0;
   
}


Measured memory_bytes: 2112
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

map<string, vector<int> > book_index;

int main(void){
  string name;
  int page;
  while(cin >> name >> page){
    book_index[name].push_back(page);
  }

  for(auto word : book_index){
    cout << word.first << endl;
    sort(word.second.begin(), word.second.end());
    for(int i = 0; i < word.second.size(); i++){
      cout << word.second[i];
      if(i < word.second.size() - 1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}

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

bool kaisuu(int a){
  int a1, a2, a4, a5;
  a5 = a % 10;
  a /= 10;
  a4 = a % 10;
  a /= 100;
  a2 = a % 10;
  a /= 10;
  a1 = a;
  if (a1 == a5 && a2 == a4) return true;
  else return false;
}

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = a; i <= b; i++) {
    if (kaisuu(i)) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//
/*
ID: kfoozmi1
LANG: C++
TASK:
*/
#include <bits/stdc++.h>
using namespace std;

#ifdef kfoozminus
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu() {
	cerr << endl;
}

template <typename T>
void faltu(T a[], int n) {
	for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename First, typename ... hello>
void faltu(First arg, const hello&... rest) {
	cerr << arg << ' ';
	faltu(rest...);
}
#else
#define dbg(args...)
#endif

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define SQR(a) ((a) * (a))
#define vsort(v) sort(v.begin(), v.end())
#define PQ priority_queue
#define PI acos(-1)
#define EPS 1e-9

#define B1 43
#define B2 43

#define MOD1 1000000007
#define MOD2 1000000009
#define MOD  1000000007

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

inline bool checkBit(ll n, int i) { return n & (1LL << i); }
inline ll setBit(ll n, int i) { return n | (1LL << i); }
inline ll resetBit(ll n, int i) { return n & (~ (1LL << i)); }
inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }
inline double dist(double ix, double iy, double jx, double jy) { return sqrt(SQR(ix - jx) + SQR(iy - jy)); }

#define PMX 1000000

int marked[PMX/64+2];

#define mark(x) marked[x>>6] |= (1<<((x&63)>>1))
#define check(x) (marked[x>>6] & (1<<((x&63)>>1)))

bool isPrime(int x)
{
    return (x>1) && ((x==2) || ((x&1) && (!(check(x)))));
}

void seive(int n)
{
    int i, j;
    for(i=3; i*i<=n; i+=2)
    {
        if(!check(i))
        {
            for(j=i*i; j<=n; j+=i<<1)
            {
                mark(j);
            }
        }
    }
}

ll bigMod(ll a, ll b)
{
	ll r = 1;
	while(b) {
		if(b & 1) (r *= a) %= MOD;
		b >>= 1;
		(a *= a) %= MOD;
	}
	return r;
}

#define INF 100000000
#define MX 100007

int a[MX];

int main()
{
#ifdef kfoozminus
	//freopen("in", "r", stdin);
#endif
	int n, l, i, pos, f = 0;

	scanf("%d %d", &n, &l);
	for(i = 1; i <= n; i ++) {

		scanf("%d", &a[i]);
		if(i >= 2) {
			
			if(f) continue;
			if(a[i] + a[i - 1] >= l) {
				f = 1;
				pos = i - 1;
			}
		}
	}
	if(f == 0) printf("Impossible\n");
	else {
		printf("Possible\n");
		for(i = 1; i < pos; i ++) printf("%d\n", i);
		for(i = n - 1; i >= pos; i --) printf("%d\n", i);
	}
        return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;

int main() {
    int N;
    cin >> N;
    // int* A = new int[N];
    std::vector<int> array;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        array.push_back(a);
    }
    std::vector<size_t> indices(array.size());
    std::iota(indices.begin(), indices.end(), 0);

    // ソートする。
    std::sort(indices.begin(), indices.end(), [&array](size_t i1, size_t i2) {
        return array[i1] < array[i2];
    });

    for (auto v : indices)
        std::cout << v + 1 << " ";
    std::cout << std::endl;
}

Measured memory_bytes: 2168
import math#numpy as np
 
N, D = map(int, input().split())
zh = []
for i in range(N):
    zh.append(list(map(int, input().split())))
    

count = 0
for i in range(N):
    for j in range(i+1, N):
        tmp = 0
        for k in range(D):
            tmp += (zh[i][k] - zh[j][k])**2
        
       
        
        tmp = math.sqrt(tmp)
        if tmp - int(tmp) == 0:
            count += 1
 
print(count)

Measured memory_bytes: 3064
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define ll long long
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}


ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int main(){
  string S; cin >> S;
  int p = 0;
  rep(i, S.size()) if(S[i] == 'p') p++;
  
  cout << S.size() / 2 - p << endl;

}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

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;}
template <class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) { return (a * b) / GCD(a, b);}

int main() {
    int k;
    string s;
    cin >> k >> s;
    if (s.size()<=k){
        cout << s << endl;
    }
    else{
        rep(i,k){
            cout << s[i];
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
    
struct Node{
    ll cost;
    int parent;  // index of parent node
    int index;   // index in node list
    vector< ll > connect;
};
    
int reach[200001];
vector< ll > p(200001);
    
void dfs(vector<Node> &node, int index){
    
    reach[index] = 1;
    
    for(int i = 0; i < node[index].connect.size(); i++){
        int next_index = node[index].connect[i];
        if(reach[next_index] == 0){
            p[next_index] += p[index];
            dfs(node, next_index);
        }
    }
       
}
    
int main(){
    
    int N, Q;
    cin >> N >> Q;
    
    vector<Node> node(N);
    for(int i = 0; i < N; i++){
        node[i].cost = 0;
        node[i].parent = -1;
        node[i].index = i;
    }
    for(int i = 0; i < N-1; i++){
        ll a, b;
        cin >> a >> b ;
        a --;
        b --;
        node[a].connect.push_back(b);
        node[b].connect.push_back(a);
    }
    
    for(int i = 0; i < N; i++) p[i] = 0;
    for(int i = 0; i < Q; i++){
        ll a, b;
        cin >> a >> b;
        a --;
        p[a] += b;
    }

    dfs(node, 0);
    for(int i = 0; i < N; i++){
        cout << p[i] << endl;
    }

}

Measured memory_bytes: 28160
#!/usr/bin/env python3
import sys
from math import gcd

def solve(K: int):
    sum = 0
    #1つしか数字がない時
    for i1 in range(1,K+1):
        sum+=i1
        # print(f"i1:{i1}")
    #2つ数字がある時
    for i2 in range(1,K+1):
        for j2 in range(i2+1,K+1):
            sum+=6*gcd(i2,j2)
            # print(f"i2:{i2},j2:{j2}")
    #3つ数字がある時
    for i in range(1,K+1):
        for j in range(i+1,K+1):
            for k in range(j+1,K+1):
                sum+=6*gcd(gcd(i,j),k)
    print(sum)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sc = new Scanner();
            int n = sc.NextInt();
            int k = sc.NextInt();
            string s = sc.NextString();

            int[] stand = new int[n];
            stand[0] = s[0] == '0' ? 1 : 0;
            for (int i = 1; i < n; i++)
            {
                stand[i] = (stand[i] == '0' ? 1 : 0) + stand[i - 1];
            }

            int max = 0;
            int left = 0;
            // 0始点だけ
            while (left < n && s[left] != '0') left++;
            int right = left;
            for (int j = 0; j < k; j++)
            {
                while (right < n && s[right] == '0') right++;
                while (right < n && s[right] == '1') right++;
            }
            while (right <= n)
            {
                int sum = right - left;
                if (sum > max) max = sum;

                if (right == n) break;

                while (left < n && s[left] == '0') left++;
                while (left < n && s[left] == '1') left++;

                while (right < n && s[right] == '0') right++;
                while (right < n && s[right] == '1') right++;
            }

            // 1始点だけ
            left = 0;
            while (left < n && s[left] != '1') left++;
            right = left;

            for (int j = 0; j < k; j++)
            {
                while (right < n && s[right] == '1') right++;
                while (right < n && s[right] == '0') right++;
                while (right < n && s[right] == '1') right++;
            }
            while (right <= n)
            {
                int sum = right - left;
                if (sum > max) max = sum;

                if (right == n) break;

                while (left < n && s[left] == '1') left++;
                while (left < n && s[left] == '0') left++;

                while (right < n && s[right] == '0') right++;
                while (right < n && s[right] == '1') right++;
            }

            Console.WriteLine(max);
        }
    }

    class Scanner
    {
        int index = -1;
        string[] buf;

        public Scanner()
        {
        }

        public int NextInt()
        {
            CheckNext();
            return int.Parse(buf[index++]);
        }

        public string NextString()
        {
            CheckNext();
            return buf[index++];
        }

        private void CheckNext()
        {
            if (index >= 0 && index < buf.Length) return;

            buf = Console.ReadLine().Split(' ');
            index = 0;
        }
    }
}


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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define ll long long
#define mod 1000000007

using namespace std;

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

  int sum = 0;
  rep(i, n + 1) {
    sum += i;
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
int main(){
  vi in(5); rep(i,5) cin >> in[i];  int k; cin >> k;
  sort(ALL(in));
  if(in[4]-in[0] <= k)  cout << "Yay!" << endl;
  else  cout << ":(" << endl;
}

Measured memory_bytes: 256
S = list(input())
T = list(input())
N = len(S)

for i in range(N):
    cnt = 0
    for j in range(N):
        if S[j] != T[(j+i) % N]:
            break
        cnt += 1
    if cnt == N:
        break
if cnt == N:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define For(i, s, e) for(int i = s;i <= e;i++)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;

int main() {
    int h,w;
    cin>>h>>w;
    string s;
    For(i,1,h) {
        For(j,1,w) {
            cin >> s;
            if(s == "snuke") {
                printf("%c",'A'+j-1);
                cout << i;
            }
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>

using namespace std;

typedef long long in;

int main(){
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        for(int j=i+1;j<s.size();j++){
            if(s[i]==s[j]){
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int check(vector<PII> &x, vector<PII> &y, VI &order)
{
    int idxx = 0;
    int curx, cury;
    curx = x[0].first;
    rep(i, y.size())
    {
        int idxy = order[i];
        cury = y[idxy].first;
        while (cury > 0)
        {
            if (x[idxx].second == y[idxy].second)
            {
                return i;
            }
            if (curx > cury)
            {
                curx -= cury;
                cury = 0;
            }
            else
            {
                cury -= curx;
                curx = 0;
            }
            if (curx == 0)
            {
                idxx++;
                curx = x[idxx].first;
            }
        }
    }
    return -1;
}

int main()
{
    int n;
    cin >> n;
    VI a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    int preva = -1, prevb = -1;
    int j = 0;
    rep(i, n)
    {
        if (preva != a[i] || prevb != b[i])
            j = 0;
        if (a[i] == b[i])
        {
            prevb = b[i];
            for (; j < n; j++)
            {
                if (b[i] != a[j] && b[j] != a[i])
                {
                    swap(b[i], b[j]);
                    break;
                }
            }
            if (a[i] == b[i])
            {
                cout << "No" << endl;
                return 0;
            }
        }
        preva = a[i];
    }
    cout << "Yes" << endl;
    rep(i, n)
    {
        cout << b[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4752
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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 mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll n;
    ll ans=1;
    scanf("%lld",&n);
    ll a[n],num[100000]={};
    rep(i,0,n){
        scanf("%lld",&a[i]);
        num[a[i]]++;
    }
    if(n==2){
        if(ABS(a[0]-a[1])<2  ){
            ans=2;
        }
    }
    rep(i,0,n-2){
        ans = max2(ans, num[i]+num[i+1]+num[i+2] );
    }
    


    
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<complex>
#include<bitset>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, X;
int S[220];

template<typename... Args>
void debug(Args... args) {
    for (auto arg:{args...})cerr << arg << " ";
    cerr << endl;
}

//const int mod = //998244353;
const int mod = 1000000007;
const int FacN = 220;//使わないなら0

constexpr int power(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)res *= a;
        a *= a;
        res %= mod;
        a %= mod;
        b /= 2;
    }
    return res;
}

constexpr int inv(int x) {
    return power(x, mod - 2);
}

const struct Fac {
    int val[FacN];

    constexpr Fac() : val() {
        if (FacN == 0)return;
        val[0] = 1;
        for (int i = 1; i < FacN; ++i) val[i] = val[i - 1] * i % mod;
    }

    const int &operator[](size_t i) const {
        return val[i];
    }
} fac;

const struct FacInv {
    int val[FacN];

    constexpr FacInv() : val() {
        if (FacN == 0)return;
        val[FacN - 1] = 1;
        for (int i = 1; i < FacN; ++i)val[FacN - 1] = val[FacN - 1] * i % mod;
        val[FacN - 1] = inv(val[FacN - 1]);
        for (int i = FacN - 1; i >= 1; --i)val[i - 1] = val[i] * i % mod;
    }

    const int &operator[](size_t i) const {
        return val[i];
    }
} fac_inv;

int Perm(int n, int r) {
    if (n < r) return 0;
    return fac[n] * fac_inv[n - r] % mod;
}

int Comb(int n, int r) {
    return Perm(n, r) * fac_inv[r] % mod;
}
//mod,Factorial書き換え
//要検証


signed main() {
    cin >> N >> X;
    rep(i, N) {
        cin >> S[i];
    }
    sort(S, S + N, greater<int>());
    map<pii, int> a, b;
    b[pii(0, X)] = 1;
    rep(i, N) {
        for (auto e:b) {
            pii key = e.first;
            int val = e.second;
            a[pii(1, key.second)] += val * (N - i - 1);
            a[pii(1, key.second)] %= mod;
            a[pii(0, key.second % S[i])] += val;
            a[pii(0, key.second % S[i])] %= mod;
        }
        swap(a, b);
        a.clear();
    }
    int ans = 0;
    for (auto e:b) {
        pii key = e.first;
        int val = e.second;
        if (key.first != 0)continue;
        ans += key.second * val;
        ans %= mod;
    }
    (ans += mod) %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2688
def main():
    mod=1000000007
    s=input()
    l=len(s)
    DP=[[0]*13 for _ in range(l+1)]
    DP[0][0]=1
    for i in range(1,l+1):
        d=s[-i]
        tmp=pow(10,i-1,13)
        if d=='?':
            for j in range(10):
                for k in range(13):
                    m=(k+tmp*j)%13
                    DP[i][m]+=DP[i-1][k]
                    if DP[i][m]>=mod:
                        DP[i][m]-=mod
        else:
            d=int(d)
            for k in range(13):
                m=(k+tmp*d)%13
                DP[i][m]+=DP[i-1][k]
                if DP[i][m]>=mod:
                    DP[i][m]-=mod
    print(DP[-1][5])

if __name__ == '__main__':
    main()

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

int main() {
  int N = 0;
  cin >> N;
  int count = N;
  
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N - 1; j++) {
      if (d.at(N - j - 1) > d.at(N - j - 2)) {
        int tmp = d.at(N - j - 2);
        d.at(N - j - 2) = d.at(N - j - 1);
        d.at(N - j - 1) = tmp;
      }
    }
  }
  
  for (int i = 0; i < N - 1; i++) {
    if (d.at(i) == d.at(i + 1)) {
      count--;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 
int main() {
  int n, m; cin >> n; cin >> m;
  vector<pair<long, long> > pairs(n);
  for(int i=0; i<n; ++i){
    long a, b; cin >> a; cin >> b;
    pairs[i] = make_pair(a, b);
  }
  sort(pairs.begin(), pairs.end());
  long cost, thing; cost = 0; thing = 0;
  int i; i = 0;
  while (thing < m) {
    if (thing + pairs[i].second < m){
      thing += pairs[i].second;
      cost += pairs[i].first * pairs[i].second;
      i += 1;
    }else{
      cost += pairs[i].first * (m - thing);
      thing = m;
    }
  }
  cout << cost << endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;
typedef long long LL;
const LL p = 1e9 + 7;

LL pow(LL a, LL b, LL m) {
    LL ans = 1;
    a %= m;
    while (b) {
        if (b & 1) {
            ans = (ans % m) * (a % m) % m;
        }
        b /= 2;
        a = (a % m) * (a % m) % m;
    }
    ans %= m;
    return ans;
}

LL inv(LL x, LL p) {
    return pow(x, p - 2, p);
}

LL C(LL n, LL m, LL p) {
    if (m > n) {
        return 0;
    }
    LL up = 1, down = 1;
    for (int i = n - m + 1; i <= n; i++) {
        up = up * i % p;
    }
    for (int i = 1; i <= m; i++) {
        down = down * i % p;
    }
    return up * inv(down, p) % p;
}

LL Lucas(LL n, LL m, LL p) {
    if (m == 0) {
        return 1;
    }
    return C(n % p, m % p, p) * Lucas(n / p, m / p, p) % p;
}

int main() {
    LL n, a, b, ans = 0;
    cin >> n >> a >> b;
    LL cnt = pow(2, n, p);
    ans = (cnt - 1 - Lucas(n, a, p) - Lucas(n, b, p) + (p << 1)) % p;
    cout << ans << endl;
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int n = S.size(), ans = n;
  for (int i=0; i<n-1; i++) {
    if (S[i] != S[i+1]) {
      ans = min(ans, max(i+1, n-i-1));
    }
  }
  cout << ans << endl;
  return 0;
}

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

public class Program{

	public static void Main(){

		string line;
		List <string> numberList = new List<string> ();

		// ??\???
		while (true) {

			line = Console.ReadLine ();
			if (line != null) {
				numberList.Add (line);
			} else {
				break;
			}
		}

		foreach (var n in numberList) {

			string[] numbers = n.Split (' ');

			long least = LeastCommonMultiple (long.Parse(numbers[0]), long.Parse(numbers[1]));
//			long greatest = GreatestCommonDivisor (int.Parse(numbers[0]), int.Parse(numbers[1]));
			long greatest = long.Parse (numbers [0]) * long.Parse (numbers [1]) / least;
			// ??????
			Console.WriteLine ("{0} {1}",greatest, least);
		}

	}

	// ????°???¬?????°
	public static long LeastCommonMultiple(long n1, long n2){

		long temp=Math.Max(n1,n2);
		n2=Math.Min(n1,n2);//n2?????????????????°???????°????

		n1=temp;//n1?????????????????°????????§???

		long product=n1*n2;//?±?????????°???????§?

		while(n2!=0)
		{
			n1=n1>n2?n1:n2;//???n1????????°??§???n2????????°
			long m=n1%n2;
			n1=n2;
			n2=m;
		}
		return(product/n1);//????°???¬?????°
	}

//	// ?????§??¬?´???°
//	public static long GreatestCommonDivisor(long n1, long n2){
//
//
//		long temp=Math.Max(n1,n2);
//		n2=Math.Min(n1,n2);//n2?????????????????°???????°????
//
//		n1=temp;//n1?????????????????°????????§???
//
//		long result = 1;
//
//
//		for (long i = n2; i >= 1; i--) {
//
//			if (n1 % i == 0 && n2 % i == 0) {
//				result = i;
//				break;
//			}
//		}
//
//		return result;
//
//	}
}

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

string FILENAME = "template";
#define io ifstream fin(FILENAME + ".in"); ofstream fout(FILENAME + ".out")
#define fwrite(X) fout << X;
#define fwriteln(X) fout << X << endl;

#define forl(V, N) for(int V = 0; V < N; V++)
#define fore(E, X) for(auto &E:X)
#define print(X) cout << X
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
#define rem(X) X.top(); X.pop()
#define mid(A, B) ((A+B) / 2)
#define setmin(A, B) A = min(A, B)
#define setmax(A, B) A = max(A, B)
#define graph unordered_map<int, unordered_set<int>>
#define vi vector<int>
#define pb push_back
#define ll long long

int main() {
    int N;
    cin >> N;
    vector<vi> active;
    forl(i, N) {
        int A, B, C;
        cin >> A >> B >> C;
        active.pb({A, B, C});
    }
    ll dp[200000][3];
    dp[0][0] = active[0][0];
    dp[0][1] = active[0][1];
    dp[0][2] = active[0][2];
    forl(i, N-1) {
        forl(j, 3){
            forl(k, 3) {
                if(k == j) continue;
                setmax(dp[i+1][k], active[i+1][k] + dp[i][j]);
            }
        }
    }
    println(max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])));
}

Measured memory_bytes: 10672
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    exrep(i, 1, n-1) {
        exrep(j, i+1, n) {
            exrep(d, 0, 8) {
                if((i & 1<<d)^(j & 1<<d)) {
                    cout << d+1;
                    break;
                }
            }
            if(j < n) {
                cout << " ";
            }
        }
        cout << "\n";
    }
    
    re0;
}

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

int main() {
  string S;
  cin >> S;
  if(S.at(2) == S.at(3) && S.at(4) == S.at(5)) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


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

typedef long long ll;
const int MAX_N = 100030;    // Change as necessary
const ll  MODD = 1000000009; //

int A[MAX_N];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int N; cin >> N;
  for(int i=0;i<N;i++) cin >> A[i];
  
  vector<int> v;
  for(int i=-100;i<=100;i++){
    int x = 0;
    for(int j=0;j<N;j++)
      x += (A[j]-i)*(A[j]-i);
    v.push_back(x);
  }
  
  cout << *min_element(v.begin(),v.end()) << endl;
  
  return 0;
}


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

int main() {
    string input;
    int length, flag = 1;
    cin >> input;
    length = input.size();
    for (int i = 0; i < length; i++) {
        string tmp_5, tmp_7, tmp_8, tmp_6;
        tmp_5 = input.substr(i , 5);
        tmp_7 = input.substr(i , 7);
        tmp_8 = input.substr(i , 8);
        tmp_6 = input.substr(i , 6);
        if (tmp_5 == "dream") {
            if (tmp_7 == "dreamer") {
                if (tmp_8 == "dreamera") {
                    i += 4;
                } else {
                    i += 6;
                }
            } else {
                i += 4;
            }
        } else if (tmp_5 == "erase") {
            if (tmp_6 == "eraser") {
                i += 5;
            } else {
                i += 4;
            }
        } else {
            flag = 2;
            break;
        }
    }
    if (flag == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 512
# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=1e2+10;
const int Max=1e2;
const int Inf=0x3f3f3f3f;

int DP[maxm][maxm][maxm];
int A,B,C;

int main(){
	register int i,j,k,Ans=Inf;
	scanf("%d%d%d",&A,&B,&C);
	for(i=0;i<=Max;i++){
		for(j=0;j<=Max;j++){
			for(k=0;k<=Max;k++){
				DP[i][j][k]=Inf;
			}
		}
	}
	DP[A][B][C]=0;
	for(i=A;i<=Max;i++){
		for(j=B;j<=Max;j++){
			for(k=C;k<=Max;k++){
				if(i>1) DP[i][j][k]=min(DP[i-2][j][k]+1,DP[i][j][k]);
				if(j>1) DP[i][j][k]=min(DP[i][j-2][k]+1,DP[i][j][k]);
				if(k>1) DP[i][j][k]=min(DP[i][j][k-2]+1,DP[i][j][k]);
				if(i>0 && j>0) DP[i][j][k]=min(DP[i-1][j-1][k]+1,DP[i][j][k]);
				if(i>0 && k>0) DP[i][j][k]=min(DP[i-1][j][k-1]+1,DP[i][j][k]);
				if(j>0 && k>0) DP[i][j][k]=min(DP[i][j-1][k-1]+1,DP[i][j][k]);
			}
		}
	}
	for(i=0;i<=Max;i++) Ans=min(Ans,DP[i][i][i]);
	printf("%lld",Ans);
	return 0;
}

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

typedef long long ll;

int sum;
int a[5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for (int i = 0; i < 5; ++i) {
        cin >> a[i];
    }
    sort(a, a + 5, [](int x, int y){
        if (x % 10 == 0) return true;
        if (y % 10 == 0) return false;
        return x % 10 > y % 10;
    });
    for (int i = 0; i < 4; ++i) {
        sum += a[i];
        int d = sum % 10;
        if (d != 0)
            sum += 10 - d;
    }
    sum += a[4];
    cout << sum << endl;

    return 0;
}



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

int main(){

    int n;
    int red = 0;
    int white = 0;
    int cnt = 0;

    cin >> n;
    vector <char> c;
    char tmp;

    for(int i = 0; i < n; i++){
        cin >> tmp;
        c.push_back(tmp);
        if(tmp == 'R')red++;
        else white++;    
    }

    // for(int i = 0 ; i < n - 1; i++){
    //     for(int j = 0; j < n - 1; j++){
    //         if(c[n - j] == 'R' && c[n - j - 1] == 'W'){
    //             for(int k = 0; k < n; k++){
    //                 if(c[k] == 'W'){
    //                     c[k] = 'R';
    //                     c[n - j] = 'W';
    //                     cnt++;
    //                     break;
    //                 }
    //             }
    //         }
    //     }
    // }

    for(int i = 0 ; i < red; i++){
        if(c[i] == 'W' )cnt++;
    }

    cout << cnt << endl;
    return 0;
    
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    string S; cin >> S;
    sort(_all(S));
    string res = "No";
    if(S[0] == S[1] and S[1] != S[2] and S[2] == S[3]){
        res = "Yes";
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;
int a[maxn];
int main(){
	int n;cin>>n;
	map<int,int> mp;ll ans=0;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		ans+=mp[i-x];
		mp[i+x]++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 20596
#include <iostream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>

using namespace std;

int main()
{
	string s;
	cin >> s;
	if (s.find("9") != string::npos) cout << "Yes" << endl;
	else cout << "No" << endl;
    return 0;
}


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

using namespace std;

int a, b;

int main() {
	cin >> a >> b;
	if((a == 1 || a == 2) && (b == 1 || b == 2)) cout << 3;
	else if((a == 1 || a == 3) && (b == 1 || b == 3)) cout << 2;
	else cout << 1;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k,a[105],mn;short f[2][100005];
bool dfs(int r,bool tu){
    if(r<mn) return f[tu][r]=!tu;
    if(f[tu][r]!=-1) return f[tu][r];bool p=0;
    if(!tu) p=1;else p=0;
    for(int i=1;i<=n;i++){
        if(r<a[i]) break;
        bool t=dfs(r-a[i],!tu);
        if((!tu)&&(!t)&&p) p=0;
        if(tu&&t&&(!p)) p=1;
    }
    return f[tu][r]=p;
}
int main()
{
    mn=1e6;scanf("%d%d",&n,&k);
    for(int i=0;i<=k;i++) f[0][i]=f[1][i]=-1;
    for(int i=1;i<=n;i++) scanf("%d",a+i),mn=min(mn,a[i]);
    sort(a+1,a+n+1);
    dfs(k,0);
    if(!f[0][k]) printf("First");
    else printf("Second");
    return 0;
}

Measured memory_bytes: 8320