akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9+1;
const ll LINF = 1e18+1;
const long double PI = acos(-1.0);

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}
template<typename T> T lcm(T a,T b){return a*b/gcd(a, b);}


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
    map<char, char> a = {MP('T', 'A'),MP('A', 'T'),MP('G', 'C'),MP('C', 'G')};
    IN(char, c);
    COUT(a[c]);
}


Measured memory_bytes: 3600
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H,W = map(int, readline().split())
grid = np.frombuffer(read(), 'S1').reshape(H,-1)[:,:W]

X,Y = np.where(grid == b'#')

A = np.ones((H,W), np.int32)
B = np.ones((H,W), np.int32)

A[X,Y] = 0
B[X,Y] = 0

for w in range(W-1):
	A[:,w+1] += A[:,w] * (A[:,w+1] != 0)
for w in range(W-2,-1,-1):
	A[:,w] = np.maximum(A[:,w], A[:,w+1]) * (A[:,w] != 0)


for h in range(H-1):
	B[h+1,:] += B[h,:] * (B[h+1,:] != 0)
for h in range(H-2,-1,-1):
	B[h,:] = np.maximum(B[h,:], B[h+1,:]) * (B[h,:] != 0)

C = A+B

print(np.max(C)-1)


Measured memory_bytes: 129556
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,M = map(int,input().split())

AB = [[int(x) for x in input().split()] for _ in range(M)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

# 二部グラフかどうかを判定する
color = [None] * (N+1)
color[1] = 0
q = [1]
while q:
    x = q.pop()
    for y in graph[x]:
        if color[y] is None:
            color[y] = 1 - color[x]
            q.append(y)

bl = all(color[a] != color[b] for a,b in AB)

if bl:
    # 完全二部グラフにする
    x = sum(color[1:])
    y = N - x
    answer = x*y - M
else:
    # 完全グラフにする
    answer = N*(N-1)//2 - M

print(answer)


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

int n;
string s;

bool checkA(string s) {
	if (s.length() < 6) return false;
	if (s[0] != '>') return false;
	if (s[1] != '\'') return false;
	
	int i;
	for (i = 2; i < s.length() && s[i] == '='; i++);
	if (i == s.length() || s[i] != '#') return false;
	int cnt = i - 2;
	for (i = i + 1; i < s.length() && s[i] == '='; i++, cnt--);
	if (cnt != 0) return false;
	if (s.length() != i + 1) return false;
	if (s[i] != '~') return false;
	return true;
}

bool checkB(string s) {
	if (s.length() < 6) return false;
	if (s[0] != '>') return false;
	if (s[1] != '^') return false;
	int i;
	for (i = 2; i < s.length(); i += 2) {
		if (i + 1 >= s.length()) return false;
		if (s[i] != 'Q') break;
		if (s[i + 1] != '=') return false;
	}
	if (s.length() != i + 2) return false;
	if (s[i] != '~' || s[i + 1] != '~') return false;
	return true;
}

int main() {
	cin >> n;
	while (n--) {
		cin >> s;
		if (checkA(s)) cout << "A" << endl;
		else if (checkB(s)) cout << "B" << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  bool a = true;
  for (int i = 0; i < N; i++){
    char n = S.at(i);
    if(i % 2 == 0){
      if(n == 'L'){
        a = false;
        break;
      }
    } else {
      if(n == 'R'){
        a = false;
        break;
      }
    }
  }
  if(a){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;

const int N = 311; 
int a[N][N];

void solve() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    long long res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            int direct = a[i][j];
            bool important = true;
            for (int k = 0; k < n; k++) {
                if (k==i||k==j) continue;
                int other = a[i][k] + a[k][j];
                if (other < direct) {
                    cout << -1; return;
                }else if (other == direct) {
                    important = false;
                }
            }
            if (important) res += direct;
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{

    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] S = new int[10001]; //for sentinel                                    
        int[] T = new int[500];
        int n = Integer.parseInt(br.readLine());
        String[] in_S = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            S[i] = Integer.parseInt(in_S[i]);
        }
        int q = Integer.parseInt(br.readLine());
        String[] in_T = br.readLine().split(" ");
        int sum = 0;
        for(int i = 0; i < q; i++){
            T[i] = Integer.parseInt(in_T[i]);
            if( search(S, n, T[i]) ) sum++;
        }
        System.out.println(sum);
    }

    public static boolean search(int[] S, int n, int key){
        int i = 0;
        S[n] = key;
        while(S[i] != key) i++;
        return i != n;
    }

}

Measured memory_bytes: 26968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;




int main(){
    string T;
    cin >> T;

    Int N;
    N = T.size();

    vector<Int> zeros, ones;
    Int numof0 = 0, numof1 = 0, temp0 = 0, temp1 = 0;

    if (T[0] == '1') zeros.push_back(0);
    rep(i,N - 1) {
        if (T[i] == '0') {
            numof0++;
            temp0++;
            if (T[i+1] == '1') {
                zeros.push_back(temp0);
                temp0 = 0;
            }
        }
        else {
            numof1++;
            temp1++;
            if (T[i+1] == '0') {
                ones.push_back(temp1);
                temp1 = 0;
            }
        }
    }

    if (T[N-1] == '0') {
        numof0++;
        temp0++;
        zeros.push_back(temp0);
    }
    else {
        numof1++;
        temp1++;
        ones.push_back(temp1);
    }


    //試しに
    //rep(i,zeros.size()) cout << zeros[i] << endl;

    Int ans = 0;

    if (numof0 == 0) {
        Int y = numof1 / 2;
        if (numof1 % 2 == 0) {
            ans += y * (y + 1);
        }
        else {
            ans += (y + 1) * (y + 1);
        }
        cout << ans << endl;
        return 0;
    }
    if (numof1 == 0) {
        cout << 0 << endl;
        return 0;
    }

    rep(i, ones.size()) {
        ans += (numof0 + 1) * (ones[i] / 2);
    }

    //cout << ans << endl;

    Int x = numof1 / 2;
    if (numof1 % 2 == 0) {
        ans += x * x;
    }
    else {
        ans += (x + 1) * x;
    }

    //cout << ans << endl;


    bool flag = true;
    rep(i,ones.size()) {
        if (ones[i] % 2 == 1) flag = false;
    }
    if (flag) {
        cout << ans << endl;
        return 0;
    }


    vector<Int> essones, esszeros;





    //if (T[0] == '0') {
        esszeros.push_back(zeros[0]);
        rep1(i,zeros.size()-1) {
            if (ones[i-1] % 2 == 0) {
                esszeros[esszeros.size()-1] += zeros[i];
            }
            else {
                esszeros.push_back(zeros[i]);
            }
        }
        if (T[N-1] == '1') {
            if (ones[ones.size()-1] % 2 == 1) esszeros.push_back(0);
        }

        //試しに
        //rep(i,esszeros.size()) cout << esszeros[i] << endl;

        Int sumess0 = 0;
        rep(i,esszeros.size() - 1) {
            sumess0 += esszeros[i];
            ans += numof0 + 1;
            if (sumess0 % 2 == 0 && i % 2 == 0) {
                ans -= (sumess0 + 1) / 2;
            }
            if (sumess0 % 2 == 1 && i % 2 == 0) {
                ans -= (sumess0 + 1) / 2;
            }
            if (sumess0 % 2 == 0 && i % 2 == 1) {
                ans -= (sumess0 + 2) / 2;
            }
            if (sumess0 % 2 == 1 && i % 2 == 1) {
                ans -= (sumess0 + 1) / 2;
            }
        }
    //}

    cout << ans << endl;
}

Measured memory_bytes: 6464
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 3005;
int n, mod, S[N][N], C[N][N];
int qpow(int a, int b, int mo = mod) {
   int ans = 1;
   for(; b >= 1; b >>= 1, a = 1ll * a * a % mo)
      if(b & 1) ans = 1ll * ans * a % mo;
   return ans;
}
void init(int n) {
   S[0][0] = C[0][0] = 1;
   for(int i = 1; i <= n; i ++) {
      C[i][0] = 1;
      for(int j = 1; j <= i; j ++) {
         S[i][j] = (1ll * j * S[i - 1][j] + S[i - 1][j - 1]) % mod;
         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
      }
   }
}
int main() {
   scanf("%d%d", &n, &mod); init(n + 1);
   int ans = 0;
   for(int i = 0; i <= n; i ++) {
      int cur = 0, t1 = qpow(2, n - i), t2 = 1;
      for(int j = 0; j <= i; j ++, t2 = 1ll * t2 * t1 % mod) {
         (cur += 1ll * S[i + 1][j + 1] * t2 % mod) %= mod;
      }
      cur = 1ll * cur * C[n][i] % mod * qpow(2, qpow(2, n - i, mod - 1)) % mod;
      if(i & 1) (ans += mod - cur) %= mod;
      else (ans += cur) %= mod;
   }
   printf("%d\n", ans);
   return 0;
}

Measured memory_bytes: 69504
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if (s==u){
    cout << a-1 << " " << b << endl;
  }
  else {
    cout << a << " " << b-1 << endl;
  }  
}    

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int xw[1001][2];
int yw[1001][2];

int u[2002][2002];

pair<int,pair<int,int> > sox[2002];
pair<int,pair<int,int> > soy[2002];

int stx[4004004];
int sty[4004004];

bool su[2001][2001];

int main()
{
	while(1)
	{
		int w,h;
		scanf("%d%d",&w,&h);
		if(w == 0)
		{
			break;
		}
		int n;
		scanf("%d",&n);
		for(int i = 0; i < n; i++)
		{
			int x1,y1,x2,y2;
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			sox[i * 2] = make_pair(x1,make_pair(i,0));
			sox[i * 2 + 1] = make_pair(x2,make_pair(i,1));
			soy[i * 2] = make_pair(y1,make_pair(i,0));
			soy[i * 2 + 1] = make_pair(y2,make_pair(i,1));
		}
		sox[n * 2] = make_pair(0,make_pair(n + 1,0));
		sox[n * 2 + 1] = make_pair(w,make_pair(n + 1,1));
		soy[n * 2] = make_pair(0,make_pair(n + 1,0));
		soy[n * 2 + 1] = make_pair(h,make_pair(n + 1,1));
		sort(sox,sox + (n + 1) * 2);
		sort(soy,soy + (n + 1) * 2);
		int xk = 0;
		int yk = 0;
		int xmae = -1;
		int ymae = -1;
		for(int i = 0; i < (n + 1) * 2; i++)
		{
			if(xmae != sox[i].first)
			{
				xmae = sox[i].first;
				xk++;
			}
			xw[sox[i].second.first][sox[i].second.second] = xk - 1;
			if(ymae != soy[i].first)
			{
				ymae = soy[i].first;
				yk++;
			}
			yw[soy[i].second.first][soy[i].second.second] = yk - 1;
		}
		for(int i = 0; i < yk; i++)
		{
			for(int ii = 0; ii < xk; ii++)
			{
				u[i][ii] = 0;
			}
		}
		for(int i = 0; i < n; i++)
		{
			u[yw[i][0]][xw[i][0]]++;
			u[yw[i][1]][xw[i][0]]--;
			u[yw[i][0]][xw[i][1]]--;
			u[yw[i][1]][xw[i][1]]++;
		}
		xk--;
		yk--;
		for(int i = 0; i < yk; i++)
		{
			int now = 0;
			for(int ii = 0; ii < xk; ii++)
			{
				now += u[i][ii];
				u[i][ii] = now;
			}
		}
		for(int i = 0; i < xk; i++)
		{
			int now = 0;
			for(int ii = 0; ii < yk; ii++)
			{
				now += u[ii][i];
				u[ii][i] = now;
			}
		}
		for(int i = 0; i < yk; i++)
		{
			for(int ii = 0; ii < xk; ii++)
			{
				if(u[i][ii] == 0)
				{
					su[i][ii] = false;
				}
				else
				{
					su[i][ii] = true;
				}
			}
		}
		int all = 0;
		for(int i = 0; i < yk; i++)
		{
			for(int ii = 0; ii < xk; ii++)
			{
				if(!su[i][ii])
				{
					all++;
					su[i][ii] = true;
					sty[0] = i;
					stx[0] = ii;
					int stn = 1;
					while(stn > 0)
					{
						stn--;
						int x = stx[stn];
						int y = sty[stn];
						if(0 <= x - 1)
						{
							if(!su[y][x - 1])
							{
								sty[stn] = y;
								stx[stn] = x - 1;
								stn++;
								su[y][x - 1] = true;
							}
						}
						if(x + 1 < xk)
						{
							if(!su[y][x + 1])
							{
								sty[stn] = y;
								stx[stn] = x + 1;
								stn++;
								su[y][x + 1] = true;
							}
						}
						if(0 <= y - 1)
						{
							if(!su[y - 1][x])
							{
								sty[stn] = y - 1;
								stx[stn] = x;
								stn++;
								su[y - 1][x] = true;
							}
						}
						if(y + 1 < yk)
						{
							if(!su[y + 1][x])
							{
								sty[stn] = y + 1;
								stx[stn] = x;
								stn++;
								su[y + 1][x] = true;
							}
						}
					}
				}
			}
		}
		printf("%d\n",all);
	}
	return 0;
}

Measured memory_bytes: 14572
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	while(1){
		char str[128];
		scanf("%s", str);
		if(str[0] == '0'){
			break;
		}
		int n = strlen(str);
		int a = 0, b = 0;
		reep(i, 1, n){
			++(str[i] == 'A' ? a : b);
		}
		++(a > b ? a : b);
		printf("%d %d\n", a, b);
	}

	return 0;
}

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

int main() {
  // input
  vector<int> a(5);
  int k=10;
  int sum=0;
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < 5;i++){
      if(a[i]%10==0){
        sum += a[i];
      }else{
        sum += (a[i] / 10) * 10 + 10;
        if(k>a[i]%10){
          k = a[i] % 10;
        }
      }
  }
    if(k==10){
      cout << sum << endl;
    }else{
      cout << sum-(10-k) << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int& i : vec) cin >> i;
  sort(vec.begin(), vec.end());
  cout << abs(vec.back() - vec.front()) << '\n';
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n < 1200)
        cout << "ABC";
    else if (n < 2800)
        cout << "ARC";
    else
        cout << "AGC";
}


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

// #pragma comment(linker, "/STACK:16777216")

using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define int ll
#define pii pair<int, int>
const int SZ = 3e5 + 4;
const double EPS = 1e-7;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

struct custom_hash {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return x + FIXED_RANDOM;
    }
};

int gcd(int a, int b) {
    while (b != 0) {
        int c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int a, b;

void read() {
    cin >> a >> b;
}

void solve() {
    cout << a * b / gcd(a, b);
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    read();
    solve();

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,K;
int main()
{
	scanf("%d%d",&n,&m);
	if(m==n) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 1000000007 //998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define PI 3.141592653589793238
#define pq priority_queue<ll>
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}
void solve()
{
   ll ans=0;
   ll n;
   
   cin>>n;
   
   ll a[n];
   for(ll i=0;i<n;i++){
       cin>>a[i];
   }
   
   for(ll i=0;i<n;i++){
       for(ll j=0;j<i;j++){
           for(ll k=0;k<j;k++){
               if(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]){
                   if(a[i]+a[j]>a[k]&&a[j]+a[k]>a[i]&&a[i]+a[k]>a[j])
                   ans++;
               }
           }
       }
   }
   
   cout<<ans<<endl;
}
int32_t main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
//Start from Here.

  ll t;
  t=1;
 // cin>>t;
  while(t--)
  solve();
  
//Good Bye!
    return 0;
}

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

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cerr.tie(0);
	
	int a, b; cin >> a >> b;
	if (a % 2 == 1 && b % 2 == 1) {
		cout << "Yes";
	} else {
		cout << "No";
	}
}


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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b == c + d)
		cout << "Balanced" << endl;
	else
		cout << (a + b < c + d ? "Right" : "Left") << endl;
	return 0;
}

Measured memory_bytes: 256
from scipy.sparse.csgraph import dijkstra
import numpy as np
from itertools import permutations
N,M,R = map(int,input().split())
r = list(map(int,input().split()))

"""
https://juppy.hatenablog.com/entry/2018/11/01/%E8%9F%BB%E6%9C%AC_python_%E5%85%A8%E7%82%B9%E5%AF%BE%E6%9C%80%E7%9F%AD%E7%B5%8C%E8%B7%AF%E6%B3%95%EF%BC%88%E3%83%AF%E3%83%BC%E3%82%B7%E3%83%A3%E3%83%AB%E3%83%95%E3%83%AD%E3%82%A4%E3%83%89%E6%B3%95
"""

def warshall_floyd(d):
    n = len(d)
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

graph = [[float("inf") for i in range(N)] for j in range(N)] 
for i in range(M):
    A,B,C = map(int,input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C

dist = dijkstra(graph)

ans = 1e10
for i in permutations(r):
    flag = True
    way = list(i)
    tmp = 0
    for i in range(len(way)-1):
        if dist[way[i]-1][way[i+1]-1] < 0:
            flag = False
            break
        tmp += dist[way[i]-1][way[i+1]-1]
    if flag:
        ans = min(tmp,ans)

print(int(ans))
    

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

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

	int n;
	cin>>n;
	vector<int> arr(n+1,0);
	for(int i=1; i<=n; ++i){
		cin>>arr[i];
	}
	vector<int> ans;
	vector<int> cnt(n+1,0);
	for(int i=n; i>=1; --i){
		int cn = cnt[i] % 2;
		if( cn != arr[i] ){
			ans.push_back(i);
			cnt[i]++;
			for(int j=1; j<= sqrt(i); ++j){
				if( i % j == 0 ){
					cnt[j]++;
					if( j != (i/j) ){ cnt[i/j]++; }
				}
			}
		}
	}
	cout<<ans.size()<<'\n';
	for(auto i : ans){
		cout<<i<<" ";
	}
	cout<<'\n';

	return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    rep(i,0,n-1)cin >> a[i] >> b[i];
    SORT(a);SORT(b);
    ll ans;
    if(n%2 == 1){
        ans = b[n/2] - a[n/2] + 1;
    }else{
        ll l = b[n/2-1] - a[n/2-1] + 1;
        ll r = b[n/2] - a[n/2] + 1;
        ans = l + r - 1;
    }


    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int n;
  cin>>n;
  string a,b,c;
  cin>>a;
  cin>>b;
  cin>>c;
  int ans = 0;
  REP(i,n){
    if(a[i] == b[i] && b[i] == c[i]){
      continue;
    }else if(a[i] == b[i] || b[i] == c[i] || c[i] == a[i]){
      ans++;
      continue;
    }
    ans += 2;
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ll n, p;
  cin >> n >> p;

  ll pos = 2;
  vector<ll> vec;
  ll tmp = p;
  ll cnt = 1;
  ll last = -1;
  while (true) {
    if (tmp == 1 || sqrt(p) < pos) {
      break;
    }
    else if (tmp / pos * pos == tmp) {
      tmp /= pos;
      cnt += last == pos;
      last = pos;
      if (cnt == n) {
        vec.push_back(pos);
        cnt = 0;
      }
    }
    else {
      last = pos;
      ++pos;
      cnt = 1;
    }
  }

  ll ans = 1;
  for (auto &v : vec)
    ans *= v;
  cout << (n != 1 ? ans : p) << endl;
}


Measured memory_bytes: 3692
#include<stdio.h>
int main(){
  int n,m,l,i,j,k;
  long long int c[100][100]={0},a[100][100],b[100][100];
  scanf("%d %d %d",&n,&m,&l); 
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      scanf("%lld",&a[i][j]);
    }
  }
  for(j=0;j<m;j++){
    for(k=0;k<l;k++){
      scanf("%lld",&b[j][k]);
    }
  }
  for(i=0;i<n;i++){
    for(k=0;k<l;k++){
      for(j=0;j<m;j++){
	c[i][k]+=a[i][j]*b[j][k];
      }	
    }
  }
  for(i=0;i<n;i++){
    for(k=0;k<l;k++){
      printf("%lld",c[i][k]);
      if(k!=l-1)printf(" ");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 844
#include<iostream>
using namespace std;
int main(){
  int n,m;
  while(cin >> n >> m){
    if(n==0 && m==0) break;
    int a[1000][100];
    for(int i=0; i<n; i++)
      for(int j=0; j<m; j++)
	cin >> a[i][j];

    int count[100];
    for(int i=0; i<m; i++){
      count[i]=0;
      for(int j=0; j<n; j++){
	if(a[j][i] == 1) count[i]++;
      }
    }

    bool first=true;
    for(int i=0; i<m; i++){
      int Max=-1, Max_num=-1;
      for(int j=0; j<m; j++){
	if(count[j] > Max) Max=count[j],Max_num=j; 
      }
      if(first)
	cout << Max_num+1;
      else
	cout << " " << Max_num+1;
      first=false;
      count[Max_num]=-1;
    }
    cout << endl;
  }
  return 0;
}

    

Measured memory_bytes: 1232
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int x;
  while (cin >> x, x) {
    x     = 1000 - x;
    int c = 0;
    vi v  = {500, 100, 50, 10, 5, 1};
    rep(i, v.size()) {
      c += x / v[i];
      x %= v[i];
    }
    cout << c << endl;
  }
}

Measured memory_bytes: 2972
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(long long N, std::vector<long long> A, std::vector<long long> K){

}

int main(){
    LL N;
    LL ans=0;
    cin>>N;
    for(LL i=1; i <= sqrt(N); i++){
        if(N%i==0){
            LL m = N/i;
            m=max((LL)1, m-1);
            if(N/m == N%m){
                ans+=m;
            }
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 384
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))

d = []
for i in range(m-1):
    d.append(x[i+1] - x[i])
d.sort(reverse=True)

if n >= m:
    print(0)
else:
    print(sum(d[n-1:]))

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

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

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

const ll MAX = 1e9;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int A, B;

int main(){
    cin >> A >> B;

    if(B < A) swap(A, B);
    int X = B - A;
    if(X % 2) cout << "IMPOSSIBLE" << endl;
    else cout << B - X / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n-1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	vint a(3);
	rep(i,3) cin >> a[i];
	int k; cin >> k;
	sort(be(a));
	rep(i,k) a[2]=a[2]*2;
	cout << a[0]+a[1]+a[2] << endl;
}

Measured memory_bytes: 3564
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int x[110],y[110],h[110];
int main()
{
	int n,hm=0;
	cin>>n;
	rep(i,n){
		cin>>x[i]>>y[i]>>h[i];
		hm=max(hm,h[i]);
	}
	rep(i,111) rep(j,111) REP(k,max(1,hm-250),hm+250){
		int f=0;
		rep(l,n){
			int he=max(0,k-abs(x[l]-i)-abs(y[l]-j));
			if(he!=h[l]) f=1;
		}
		if(f==0){
			cout<<i<<' '<<j<<' '<<k<<endl;return 0;
		}
	}
	//assert(false);
}


Measured memory_bytes: 256
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double EPS = 1e-10;


int main(void) {
  int D, T, S;
  cin >> D >> T >> S;

  if (T * S >= D) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

#define int long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;
const long long INF = 1LL << 60;

signed main()
{
    int D;
    cin >> D;
    vector<int> c(26);
    rep(i, 26)
    {
        cin >> c[i];
    }
    vector<vector<int>> s(D, vector<int>(26));

    rep(i, D)
    {
        rep(j, 26)
        {
            cin >> s[i][j];
        }
    }

    int last[26] = {0};

    //vector<int> t(D);
    rep(i, D)
    {
        int m = 0;
        int d_event = 0;

        int down = 0;
        /*
        rep(j, 26)
        {
            down += c[j] * ((i + 1) - last[j]);
        }*/

        rep(j, 26)
        {
            int score = s[i][j] + c[j] * ((i + 1) - last[j]);
            if (m < score)
            {
                d_event = j;
                m = score;
            }
        }
        last[d_event] = i + 1;

        cout << d_event + 1 << endl;
    }

    /*
    vector<int> v(D);

    int last[26] = {0};

    rep(d, D)
    {
        v[d] = s[d][t[d]];
        if (d > 0)
        {
            v[d] += v[d - 1];
        }
        last[t[d]] = d + 1;
        int down = 0;
        rep(i, 26)
        {
            down += c[i] * ((d + 1) - last[i]);
        }
        v[d] -= down;
    }

    rep(i, D)
    {
        cout << v[i] << endl;
    }*/
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll W,H,X,Y;cin>>W>>H>>X>>Y;
  printf("%lf %d\n",(double)W*(double)H*0.5,(bool)(2*X==W&&2*Y==H));
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
  
struct node{
  
int id;
struct node* parentNode;
struct node* leftChild;
struct node* rightChild;
  
};
  
struct node *createNode(int);
struct node *searchNode(int);
void insert(struct node*);
void printNodes(void);
void preOrder(struct node *);
void inOrder(struct node *);
  
struct node* nodes[500001];
struct node* root;
 
int n; 
 
main(){
  
int i, id;
char command[7];
 struct node* tmpNode;
  
scanf("%d",&n);
  
for(i=0; i<n; i++){
  
scanf("%s",command);
if(command[0]=='i'){
scanf("%d",&id);
insert(createNode(id));
}else if(command[0]=='p'){
printNodes();
}
  
}/* END OF LOOP */
 
 return 0;
  
}
 
struct node *createNode(int id){
  struct node *newNode;
 
    if(id<0) return NULL;
 
    if(newNode = searchNode(id)) return newNode;
 
  newNode=(struct node*)malloc(sizeof(struct node));
  newNode->id=id;
  newNode->parentNode=NULL;
  newNode->rightChild=NULL;
  newNode->leftChild=NULL;
   
  nodes[id]=newNode;
  return newNode;
}
 
struct node *searchNode(int id){
  if(nodes[id]){
    return nodes[id];
  }
  return NULL;
}
  
void insert(struct node* z){
  
  struct node* y = NULL;
  struct node* x = root;
 
  while(x != NULL){
    y = x;
    if(z->id < x->id){
      x = x->leftChild;
    }else{
      x = x->rightChild;
    }
  }
  z->parentNode = y;
  if(y == NULL){
    root = z;
  }else{
    if(z->id < y->id){
      y->leftChild = z;
    }else{
      y->rightChild = z;
    }
  }
  
}
  
void printNodes(void){
	
  inOrder(root);
  printf("\n");
  preOrder(root);
  printf("\n"); 
 
}
  
void preOrder(struct node* nd){
  printf(" %d",nd->id);
  if(nd->leftChild){
    preOrder(nd->leftChild);
  }
  if(nd->rightChild){
    preOrder(nd->rightChild);
  }
  
}
  
void inOrder(struct node* nd){
  if(nd->leftChild){
    inOrder(nd->leftChild);
  }
  printf(" %d",nd->id);
  if(nd->rightChild){
    inOrder(nd->rightChild);
  }
  
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

vector<ll> yakusu(ll x){
	vector<ll> ans;
	if(x==1){return {1};}
	ll p=x;
	ans.push_back(1);
	for(ll i=2;i*i<=x;i++){
		ll j=0,l=1;
		while(p%i==0){
			p /= i;
			j++;
		}
		vector<ll> s=ans;
		for(ll k=0;k<j;k++){
			l*=i;
			for(auto y:ans){
				s.push_back(y*l);
			}
		}
		ans = s;
	}
	if(p!=1){
		vector<ll> s=ans;
		for(auto x:ans){
			s.push_back(x*p);
		}
		ans = s;
	}
	return ans;
}

int main(){
	ll N,ans=0;
	cin >> N;
	vector<ll> a(N);
	FOR(i,0,N)cin>>a[i];
	SORT(a);
	FOR(i,0,2){
		for(auto x:yakusu(a[i])){
			ll k = 0;
			FOR(j,0,N){
				if(a[j]%x==0)k++;
			}
			if(k>=N-1){
				ans = max(ans,x);
			}
		}
	}
	cout << ans << endl;
}


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

/* constant */

const int MAX_N = 100000;
const int MAX_P = 100;

const int MAX_PNUM = MAX_N + MAX_P * 10;

/* typedef */

typedef vector<int> vi;

/* global variables */

bool primes[MAX_PNUM + 1];
vi pnums;

/* subroutines */

int calc_prime(int max_p) {
  memset(primes, true, sizeof(primes));
  primes[0] = primes[1] = false;

  for (int p = 2; p * p <= max_p; p++)
    if (primes[p])
      for (int q = p * p; q <= max_p; q += p) primes[q] = false;

  for (int p = 2; p <= max_p; p++)
    if (primes[p]) pnums.push_back(p);

  return pnums.size();
}

/* main */

int main() {
  calc_prime(MAX_PNUM);
  
  for (;;) {
    int n, p;
    cin >> n >> p;
    if (n < 0) break;

    vi::iterator pbgn = upper_bound(pnums.begin(), pnums.end(), n);
    vi::iterator pend = min(pbgn + 2 * p, pnums.end());
    
    vi sums;
    for (vi::iterator pit0 = pbgn; pit0 != pend; pit0++)
      for (vi::iterator pit1 = pit0; pit1 != pend; pit1++)
	sums.push_back(*pit0 + *pit1);
    sort(sums.begin(), sums.end());

    cout << sums[p - 1] << endl;
  }
  
  return 0;
}

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

const int N = 55;
int n;
long long a[N];
long long ans;

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

	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];

	bool found = true;
	
	while(found) {
		found = false;
		for (int i = 1; i <= n; ++i) {
			if (a[i] >= n) {
				found = true;
				
				long long add = a[i] / n;
				a[i] %= n;
				ans += add;
				for (int j = 1; j <= n; ++j) {
					if (j != i) a[j] += add;
				}
			}
		}

		if (!found) break;
	}

	cout << ans << endl;
}

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

using namespace std;

int main() {
    vector<int> primes;
    vector<int> is_prime(60001, 1);
    is_prime[0] = is_prime[1] = 0;
    int lim = (int)sqrt(60000);
    for(int i = 2; i <= lim; ++i) {
        if(is_prime[i]) {
            if(i < lim) {
                for(int j = i*i; j <= 60000; j += i) is_prime[j] = 0;
            }
        }
    }
    for(int i = 2; i <= 60000; ++i) 
        if(is_prime[i]) primes.push_back(i);

    int n;
    while(cin >> n) {
        cout << *(lower_bound(primes.begin(), primes.end(), n)-1) << ' ' << *upper_bound(primes.begin(), primes.end(), n) << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import numpy as np
def main():
    N,W = map(int,input().split())
    w,v = [],[]
    for _ in range(N):
        w_,v_ = map(int,input().split())
        w.append(w_)
        v.append(v_)

    Vmax = max(v)*N
    INF = 10**9

    dp = np.ones((N+1,Vmax+1),dtype=np.int64)*INF
    dp[0][0]=0

    for i in range(N):
        tmp = np.ones(Vmax+1,dtype=int)*INF
        if i==0:tmp[0]=0
        tmp[v[i]:] = dp[i][:-v[i]] + w[i]
        dp[i+1] = np.minimum(dp[i],tmp)

    ans = 0   
    for i in range(Vmax,-1,-1):
        if dp[N][i] <= W:
            ans = i
            break
    print(ans)
    
main()

Measured memory_bytes: 107788
#include<stdio.h>
#include<string.h>

#define M 1000000
#define L 12

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int j1(int key){ return key % M; }
int j2(int key){ return 1 + (key % (M -1)); }

int find(char str[]){

   
  long long key,i,j;

  key = getKey(str);
  for(i=0;;i++){
    j=(j1(key)+i*j2(key))%M;
    if(strcmp(H[j],str)==0)return 1;
    else if(strlen(H[j])==0)return 0;
  }
}

int insert(char str[]){

  
  long long key,i,j;

  key = getKey(str);
  for(i=0;;i++){
    j=(j1(key)+i*j2(key))%M;
    if(strcmp(H[j],str)==0)return 1;
    else if(strlen(H[j])==0){
      strcpy(H[j],str);
      return 0;
    }
  }
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 13424
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        a: chars,
        b: chars,
        c: chars,
    }

    let mut count = 0;

    for i in 0..n {
        match (a[i] == b[i], b[i] == c[i], c[i] == a[i]) {
            (false, false, false) => count += 2,
            (true, true, true) => count += 0,
            _ => count += 1
        };
    }

    println!("{}", count);
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void){
  double r, s, l;
  cin >> r;
  s = M_PI * pow(r, 2);
  l = 2 * M_PI * r;
  // output: s, l
  cout << fixed;
  cout << setprecision(6) << s << " " << l << endl;
  return 0;
}


Measured memory_bytes: 3288
S = gets.chomp

m2, m3 = S =~ /([a-z])\1/, S =~/([a-z]).\1/
if m2
  printf "%d %d\n", m2 + 1, m2 + 2
elsif m3
  printf "%d %d\n", m3 + 1, m3 + 3
else
  puts "-1 -1"
end

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" );
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const ll INF = 1e9+9, LINF = 1e18;


int main()
{
    ll n,m,a,b,c,ans=0;
    cin>>n>>m;
    vi x[8];
    rep(i,n){
        cin>>a>>b>>c;
        rep(i,8){
            x[i].pb(a*((i/4)*2-1)+b*((i/2%2)*2-1)+c*(i%2*2-1));
        }
    }
    rep(i,8){
        sort(all(x[i]));
        reverse(all(x[i]));
        ll q=0;
        rep(j,m) q+=x[i][j];
        ans=max(q,ans);
    }
;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	string s;
	int a[105];
	long long sum=0,k;
	cin>>s>>k;
	int  l=s.length();
	for(int i=0;i<l;i++)
	{
		a[i]=s[i]-'0';
	}
	int x,y;
	int flag=1;
	for(int i=0;i<l;i++)
	{
		if(a[i]!=1)
			flag=0;
	}
	if(flag==1)
	{
		if(k<=l)
			cout<<1<<"\n";
		else
			cout<<"\n";
	}
	else
	{
		for(int i=0;i<l;i++)
		{
			if(a[i]==1)
				continue;
			else
			{
				x=a[i];
				y=i;
				break;
			}
		}
		if(k-1<y)
		cout<<1<<"\n";
		else
		cout<<x<<"\n";
	}
}

Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

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

vector<int> edge[100001];
struct Qu{
  int v, d, c;
  Qu(){}
  Qu(int v, int d, int c): v(v), d(d), c(c){}
};

int dp[100001][11];

void update(int v, int d, int c){
  if(d < 0)return;
  if(dp[v][d] != 0)return;
  int tc = d;
  while(tc >= 0 && dp[v][tc] == 0)dp[v][tc] = c, tc--;
  for(auto e: edge[v]){
    update(e, d - 1, c);
  }
}

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  rep(i, m){
    int a, b;
    cin >> a >> b, a--, b--;
    edge[a].pb(b);
    edge[b].pb(a);
  }
  int q;
  cin >> q;
  vector<Qu> vec(q);
  rep(i, q){
    int v, d, c;
    cin >> v >> d >> c, v--;
    vec[i] = Qu(v, d, c);
  }
  for(int i = 0; i < n; i++){
    for(int j = 0;  j < 11; j++){
      dp[i][j] = 0;
    }
  }
  reverse(all(vec));
  for(int i = 0; i < q; i++){
    int v = vec[i].v, d = vec[i].d, c = vec[i].c;
    update(v, d, c);
  }
  for(int i = 0; i < n; i++){
    cout << dp[i][0] << endl;
  }
	return 0;
}


Measured memory_bytes: 12024