akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3


def digit_sum(n):
    return sum(int(c) for c in str(n))


def find_max(x):
    a = x
    b = 1
    while x:
        c = (x - 1) * b + (b - 1)
        dsc = digit_sum(c)
        dsa = digit_sum(a)
        if dsc > dsa or dsc == dsa and c > a:
            a = c
        x //= 10
        b *= 10
    return digit_sum(a)


def main():
    print(find_max(int(input())))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}


ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}







/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  for(ll i=1;i<=9;i++){
    for(ll j=1;j<=9;j++){
      cout<<i<<'x'<<j<<'='<<i*j<<endl;
    }
  }
  
}


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

int main()
{

  int d;
  cin >> d;

  vector<int> c(26);
  for(int i=0; i<26; ++i)
    cin >> c[i];

  vector<vector<int> > s(d, vector<int>(26));
  for(int i=0; i<d; ++i)
    for(int j=0; j<26; ++j)
      cin >> s[i][j];

  vector<int> t(d);
  /*
  for(int i=0; i<d; ++i){
    cin >> t[i];
    --t[i];
  }
  */

  for(int i=0; i<d; ++i){
    int maxj = 0;
    for(int j=0; j<26; ++j){
      if(s[i][j] > s[i][maxj]) maxj = j;
    }
    t[i] = ++maxj;
  }

  for(int i=0; i<d; ++i)
    cout << t[i] << endl;

  /*
  int ans = 0;
  vector<int> last(26,-1);
  for(int i=0; i<d; ++i){

    for(int l=0; l<26; ++l){
      ans += s[i][l];

      last[l] = i;
      for(int j=0; j<26; ++j)
	ans -= c[j]*(i - last[j]);

      if(ans > oldans){

      }
      else{
	last[l] = oldlast;
	ans = oldans;
      }
    }
  */
    
    //cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3680
N, K = map(int, input().split())
no_okashi = set(range(1, N+1))

for _ in range(K):
  num_hito = int(input())
  has_okashi = set(map(int, input().split()))
  no_okashi = no_okashi - has_okashi
  
print(len(no_okashi))

Measured memory_bytes: 9176
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int N,T,A; cin>>N>>T>>A;
  vector<int> H(N);
  int idx = 0;
  double temperature = MAX_SIZE;
  for(int i = 1; i <= N; i++) {
    int h; cin>>h;
    double temperature_i = T - h * 0.006;
    if(abs(temperature - A) > abs(temperature_i - A)) {
      idx = i;
      temperature = temperature_i;
    }
  }

  cout << idx << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <cmath>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define is_in(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
using namespace std;
typedef long long ll;
typedef vector<vector<int> > VVI;
const int INF = 1e9;
typedef pair<int, int> PII;

const int MAX_N = 100010;
const double THRESH_HOLD = 1e-15;

int main()
{
	int N;
	while (cin >> N, N) {
		double dp[MAX_N] = {0.0};
		dp[0] = 1.0;

		double prob[MAX_N], r_prob[MAX_N], tmp=1.0;
		prob[0] = r_prob[0] = 1.0;
		for (int i=1; i<N; i++) {
			tmp *= 0.5;
			prob[i] = prob[i-1] * tmp;
			r_prob[i] = prob[i-1] * (1.0 - tmp);
			// cerr << "r_prob[" << i << "] = " << r_prob[i] << endl;
		}

		for (int i=1; i<N; i++) {
			dp[i] += (i+1) * prob[i];
			dp[i] += i * r_prob[i];

			for (int j=i-2; j>=0; j--) {
				// cerr << "dp[i] += " << r_prob[i-j-1] * (dp[j] + i - j - 1) << endl;
				if (r_prob[i-j-1] < THRESH_HOLD) break;
				dp[i] += r_prob[i-j-1] * (dp[j] + i - j - 1);
			}
		}

		cout << fixed << setprecision(10);
		cout << dp[N-1] << endl;
	}
}

Measured memory_bytes: 3576
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

bool isPal(string& str, int l, int r){
	if(l > r)
		return true;

	if(l == r)
		return true;

	while(l < r){
		if(str[l] != str[r])
			return false;
		l++;
		r--;
	}

	return true;
}

signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("error.txt", "w", stderr);
// #endif
	crap;

	string str;
	cin>>str;
	int n = str.length();

	int x = (n-1)/2;
	int y = (n+3)/2;

	bool val = isPal(str, 0, n-1) and isPal(str,0,x-1) and isPal(str,y-1,n-1);
	cout << (val ? "Yes": "No") << endl;


	return 0;
}






Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

map < pair <int,int> , int > M;

int x[100],y[100];
int i,j,n,s;

int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%d%d",&x[i],&y[i]);
	for (i=1;i<=n;i++)
		for (j=1;j<=n;j++)
			if (i!=j)
			{
				M[make_pair(x[i]-x[j],y[i]-y[j])]++;
				s=max(s,M[make_pair(x[i]-x[j],y[i]-y[j])]);
			}
	printf("%d",n-s);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int pro = 1;
  
  for (int i = 0; i < 3; i++) {
    pro *= 10;
    if ((n % pro) / (pro / 10) == 7) {
      cout << "Yes" << endl;
      break;
    }
    else if (i == 2) {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 3576
// 2014/10/27 Tazoe

#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

map<string, int> Item;
map<string, vector<string> > Recipe;

int getCost(string name)
{
	if(Recipe.find(name)==Recipe.end())	// レシピがなかったら
		return Item[name];

	int sum = 0;
	for(int i=0; i<Recipe[name].size(); i++){
		sum += getCost(Recipe[name][i]);
	}

	return min(sum, Item[name]);
}

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

		if(n==0)
			break;

		Item.clear();
		for(int i=0; i<n; i++){
			string s;
			int p;
			cin >> s >> p;

			Item[s] = p;
		}

		int m;
		cin >> m;

		Recipe.clear();
		for(int i=0; i<m; i++){
			string o;
			int k;
			cin >> o >> k;

			for(int j=0; j<k; j++){
				string q;
				cin >> q;

				Recipe[o].push_back(q);
			}
		}

		string name;
		cin >> name;

		cout << getCost(name) << endl;
	}

	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    map<int, int> m1, m2;
    int n, v;
    cin >> n;
    bool first = true;
    REP(i, n) {
        cin >> v;
        if (first) m1[v]++;
        else m2[v]++;
        first = !first;
    }

    int max1 = 0, max2 = 0, max1s = 0, max2s = 0, n1, n2;
    for (auto p : m1) {
        if (p.second >= max1) {
            max1s = max1;
            max1 = p.second;
            n1 = p.first;
        }
        else if (p.second > max1s) {
            max1s = p.second;
        }
    }
    for (auto p : m2) {
        if (p.second >= max2) {
            max2s = max2;
            max2 = p.second;
            n2 = p.first;
        }
        else if (p.second > max2s) {
            max2s = p.second;
        }
    }

    if (n1 == n2) {
        if (max1 + max2s > max1s + max2) max2 = max2s;
        else                             max1 = max1s;
    }

    cout << n - max1 - max2 << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
#define ll long long
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define VPLL vector<PLL>
#define VPII vector<PII>
#define PQ priority_queue<PLL,VPLL, greater<PLL> > 
#define PQI priority_queue<PII,VPII,greater<PII> >
#define S second
#define F first
#define PB push_back
 
const ll MAX=1000000000000000;
ll dp[101][100001];
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
 
    ll n,W;
    cin>>n>>W;
    ll i,v[n],w[n],sm=0;
    for(i=0;i<n;i++) {
        cin>>w[i]>>v[i];
        sm+=v[i];
    }
    ll ans=0;
    for(i=1;i<=sm;i++)
        dp[0][i]=MAX;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=sm;j++)
        {
            if(v[i-1]>j)
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=min(dp[i-1][j-v[i-1]]+w[i-1],dp[i-1][j]);
            //cout << dp[i][j] << " ";
            if(dp[i][j]<=W)
            {
                if(j>ans)
                    ans=j;
            }
        }
        //cout << "\n";
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 79232
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    long a[9];
    for(int i=0;i<9;i++)
    {
        scanf("%ld",&a[i]);
    }

    long n;
    scanf("%ld", &n);

    long b[n];
    for(int i=0;i<n;i++)
    {
        scanf("%ld",&b[i]);
        for(int j=0;j<9;j++)
        {
            if(a[j]==b[i])
            {
                a[j]=0;
            }
        }
    }
    if(a[0]==0&&a[1]==0&&a[2]==0)
    {
        printf("Yes\n");
    }
    else if(a[3]==0&&a[4]==0&&a[5]==0)
    {
        printf("Yes\n");
    }
    else if(a[6]==0&&a[7]==0&&a[8]==0)
    {
        printf("Yes\n");
    }
    else if(a[0]==0&&a[3]==0&&a[6]==0)
    {
        printf("Yes\n");
    }
    else if(a[1]==0&&a[4]==0&&a[7]==0)
    {
        printf("Yes\n");
    }
    else if(a[2]==0&&a[5]==0&&a[8]==0)
    {
        printf("Yes\n");
    }
    else if(a[0]==0&&a[4]==0&&a[8]==0)
    {
        printf("Yes\n");
    }
    else if(a[2]==0&&a[4]==0&&a[6]==0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int arr1[n-1],arr2[n];

	for (int i =0; i < n-1; i++){
		cin >> arr1[i];
	}
	if(arr1[0] > arr1[1]){
		arr2[0] = arr1[0];
		for(int i = 1; i < n-1; i++){
                if(arr1[i-1] <= arr1[i]){
                        arr2[i] = arr1[i-1];
                }
                else{
                        arr2[i] = arr1[i];
                }
        	}
	}
	else{
	arr2[0] = arr1[0];
	arr2[1] = arr1[0];
	
	for(int i = 2; i < n-1; i++){
		if(arr1[i-1] <= arr1[i]){
			arr2[i] = arr1[i-1];
		}
		else{
			arr2[i] = arr1[i];
		}
	}
	}
	arr2[n-1] = arr1[n-2];
	int sum = 0;
	for(int i = 0; i < n; i++){
		sum += arr2[i];
	}
	cout << sum << endl;
	return 0;
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

void cnt(ll p, ll q, ll m, ll &x, ll &y, ll &num){
	x = y = num = 0;
	for(ll i = 0; i*p <= m; ++i){
		ll j = (m-i*p)/q;
		x += i*(j+1);
		y += j*(j+1)/2;
		num += j+1;
	}
}

void calc(ll p, ll q, ll c, ll &r, ll &b, ll &k){
	bool foo = false;
	if(p < q){
		swap(p,q);
		foo = true;
	}
	ll lo = 0, hi = p*1818;
	while(lo+1 < hi){
		ll mi = (lo + hi)/2;
		ll x, y, junk;
		cnt(p,q,mi,x,y,junk);
		if(p*x + q*y >= c) hi = mi;
		else lo = mi;
	}
	
	ll x, y, num;
	cnt(p, q, lo, x, y, num);
	ll bd = (c - x*p - y*q)/hi;
	k = num + bd;

	for(int i = 0; true; i++) if((hi-i*p)%q == 0){
		int j = (hi-i*p)/q;
		r = x + i*bd + bd*(bd-1)/2 * q;
		while(j >= p){
			j -= p;
			i += q;
		}
		b = y + j*bd + bd*(bd-1)/2 * p;
		break;
	}

	if(foo) swap(r,b);
}

pii eval(ll r, ll b, ll p, ll q){
	ll x, y, k;
	calc(p, q, r*p + b*q, x, y, k);
	if(x <= r && y <= b) return pii(0, (int)k-1);
	if(x > r) return pii( 1,0);
	else 	  return pii(-1,0);
}

int solve(int r, int b, ll p0, ll q0, ll p1, ll q1){
	ll lo = 0, hi = 1;
	while(true){
		pii pa = eval(r, b, p0 + hi*p1, q0 + hi*q1);
		if(pa.first == 0) return pa.second;
		if(pa.first > 0) break;
		hi *= 2;
	}
	while(lo+1 < hi){
		ll mi = (lo+hi)/2;
		pii pa = eval(r, b, p0 + mi*p1, q0 + mi*q1);
		if(pa.first == 0) return pa.second;
		if(pa.first > 0) hi = mi;
		else lo = mi;
	}
	return solve(b,r, q1, p1, q0 + lo*q1, p0 + lo*p1);
}

int main(){
	int r, b;
	cin >> r >> b;
	cout << solve(r,b,1,0,0,1) << endl;
}


Measured memory_bytes: 384
#create date: 2020-03-18 07:48

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    s = ns()
    s0 = s[0]
    n = len(s)
    m = (n-1)//2 + 1
    for i in range(1, m):
        if s[i] == s0:
            if s[:i] ==s[i:2*i]:
                ans = i*2
    print(ans)

if __name__ == "__main__":
    main()

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

int main()
{
    int N;
    cin >> N;
    vector<int> B(N - 1);
    for (int i = 0; i < N - 1; i++)
        cin >> B[i];
    vector<int> A(N, 0);
    A[0] = B[0];
    for (int i = 0; i < N - 2; i++)
    {
        A[i + 1] = min(B[i], B[i + 1]);
    }
    A[N - 1] = B[N - 2];
    int ans = 0;
    for (int i = 0; i < N; i++)
        ans += A[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int n;
  cin >> n;
  ll ans=0;
  vl l(n,0);
  // vi r(n,0);
  orep(i,n) {
    ll a;cin >> a;
    if(i-a>0) ans+=l.at(i-a);
    if(a+i <= n-1) l.at(a+i)++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4852
import collections
import queue


class Dinic:
    def __init__(self, N):
        self.N = N
        self.edges = collections.defaultdict(list)
        self.level = [0 for _ in range(self.N)]
        self.iter = [0 for _ in range(self.N)]

    def add(self, u, v, c, directed=True):
        if directed:
            self.edges[u].append([v, c, len(self.edges[v])])
            self.edges[v].append([u, 0, len(self.edges[u])-1])
        else:  # TODO: must be Verified
            self.edges[u].append([v, c, len(self.edges[v])])
            self.edges[v].append([u, 0, len(self.edges[u]) - 1])
            self.edges[v].append([u, c, len(self.edges[u])])
            self.edges[u].append([v, 0, len(self.edges[v]) - 1])

    def bfs(self, s):
        self.level = [-1 for _ in range(self.N)]
        self.level[s] = 0
        que = queue.Queue()
        que.put(s)
        while not que.empty():
            v = que.get()
            for i in range(len(self.edges[v])):
                e = self.edges[v][i]
                if e[1] > 0 and self.level[e[0]] < 0:
                    self.level[e[0]] = self.level[v] + 1
                    que.put(e[0])

    def dfs(self, v, t, f):
        if v == t:
            return f
        for i in range(self.iter[v], len(self.edges[v])):
            self.iter[v] = i
            e = self.edges[v][i]
            if e[1] > 0 and self.level[v] < self.level[e[0]]:
                d = self.dfs(e[0], t, min(f, e[1]))
                if d > 0:
                    e[1] -= d
                    self.edges[e[0]][e[2]][1] += d
                    return d
        return 0

    def maxFlow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t] < 0:
                return flow
            self.iter = [0 for _ in range(self.N)]
            f = self.dfs(s, t, float('inf'))
            while f > 0:
                flow += f
                f = self.dfs(s, t, float('inf'))


H, W = map(int, input().split())
graph = Dinic(H+W+2)

for h in range(H):
    tmp = str(input())
    for w in range(W):
        if tmp[w] == 'o':
            graph.add(h+1, H+1+w, 1)
            graph.add(H + w + 1, h + 1, 1)
        if tmp[w] == 'S':
            start = [h, w]
            graph.add(0, h+1, float('inf'))
            graph.add(0, H+w+1, float('inf'))
        if tmp[w] == 'T':
            goal = [h, w]
            graph.add(h+1, H+W+1, float('inf'))
            graph.add(H+1+w, H+W+1, float('inf'))

if start[0] == goal[0] or start[1] == goal[1]:
    print(-1)
    quit()
print(graph.maxFlow(0, H+W+1))

Measured memory_bytes: 8048
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
int n,m;
int a[1005][1005];
int vis[1005][1005];
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct Node
{
	int x,y;
	int step;
	Node(int xx=0,int yy=0,int ss=0)
	{
		x=xx;y=yy;step=ss;
	}
};
bool check(int x,int y)
{
	if(x>=1&&x<=n&&y>=1&&y<=m)
	{
		return true;
	}
	return false;
}
queue<Node> q;
int main()
{
    scanf("%d%d",&n,&m);
    getchar(); 
    for(int i=1;i<=n;i++)
    {
		for(int j=1;j<=m;j++)
		{
			scanf("%c",&a[i][j]);
		}
		getchar();	
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]=='#')
			{
				q.push(Node(i,j,0));	
				vis[i][j]=true;
			}
		}
	}
//	for(int i=1;i<=n;i++)
//	{
//		for(int j=1;j<=m;j++)
//		{
//			printf("%c",a[i][j]);
//		}
//		printf("\n");
//	}
	int ans=0;
	while(!q.empty())
	{
		Node s=q.front();
		q.pop();
		for(int i=0;i<4;i++)
		{
			int xx=s.x+dir[i][0];
			int yy=s.y+dir[i][1];
			if(check(xx,yy)&&vis[xx][yy]==0)
			{
				vis[xx][yy]=1;
				q.push(Node(xx,yy,s.step+1));
				ans=max(ans,s.step+1);
			}
		}
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 20240
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
const long long mod = 1e9 + 7;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> vec(m);
    rep(i, m)
    {
        int k;
        cin >> k;
        vec[i].resize(k);
        rep(j, k)
        {
            cin >> vec[i][j];
            vec[i][j]--;
        }
    }
    vector<int> p(m);
    rep(i, m) cin >> p[i];
    int ans = 0;
    for (int i = 0; i < (1 << n); i++)
    {
        bool hantei = true;
        for (int j = 0; j < m; j++)
        {
            int c = 0;
            for (int id : vec[j])
            {
                if ((i >> id) & 1)
                {
                    c++;
                }
            }
            c %= 2;
            if (c != p[j])
                hantei = false;
        }
        if (hantei)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
h,w,k=map(int,input().split())
ans=[[0 for i in range(w)] for j in range(h)]
l=[]
for i in range(h):
  l.append(list(input()))
now=0
for i in range(h):
  for j in range(w):
    if l[i][j]=="#":
      now+=1
      ans[i][j]=now
      for k in range(j+1,w):
        if l[i][k]=="#" or ans[i][k]!=0:
          break
        else:
          ans[i][k]=now
      for k in range(1,j+1):
        if l[i][j-k]=="#" or ans[i][j-k]!=0:
          break
        else:
          ans[i][j-k]=now
for i in range(h):
  if ans[i][0]!=0:
    num=i
    break
if num==0:
  pass
else:
  for i in range(1,num+1):
    for j in range(w):
      ans[num-i][j]=ans[num][j]
for i in range(num+1,h):
  if ans[i][0]==0:
    for j in range(w):
      ans[i][j]=ans[i-1][j]
for i in range(h):
  w1=""
  for j in range(w):
    w1+=str(ans[i][j])+" "
  print(w1)

Measured memory_bytes: 7932
import sys
input = sys.stdin.readline
N = int(input())
res = set()
a = ord("a")
def dfs(s, x):
  global res
  if len(s) == N:
    res.add(s)
    return
  for i in range(x + 1):
    dfs(s + chr(a + i), x)
  dfs(s + chr(a + x + 1), x + 1)

dfs("a", 0)
res = sorted(res)
for r in res: print(r)

Measured memory_bytes: 64476
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

vector<int> G[1<<17];
vector<int> dp(1<<17,0);
int r = 3;

int dfs(int u,int v){
    int ret = 0;
    for(auto g:G[u]){
        if(g == v) continue;
        chmax(ret, dfs(g, u));
    }
    return dp[u] = ret + 1;
}

void dfs2(int u,int v,P x){
    vector<P> vv;
    vv.pb(mp(0, -1));
    for(auto g:G[u]){
        if(g == v){
            vv.pb(x);
        }
        else{
            vv.pb(mp(dp[g], g));
        }
    }
    sort(RALL(vv));
    for(auto g:G[u]){
        if(g == v) continue;
        if(g == vv[0].sc){
            dfs2(g, u, mp(vv[1].fs + 1, u));
        }
        else{
            dfs2(g, u, mp(vv[0].fs + 1, u));
        }
    }
    if(vv.size() >= 4){
        int a = vv[0].fs, b = vv[1].fs, c = vv[2].fs;
        chmax(r, a + c + (a != c));
    }
}


int main(){
    int n;cin >> n;
    for (int i = 0; i < n-1; i++) {
        int a,b;cin >> a >> b;
        a--,b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    dfs(0,-1);
    dfs2(0,-1,mp(0,-1));
    string ans(n, '1');
    for (int i = 3; i < r; i++) {
        ans[i - 1] = '0';
    }
    cout << ans << endl;
    return 0;
}



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

const int N = 60;

int n, m;
int a[N][2], b[N][2];

int main(){
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++ i){
		scanf("%d%d", &a[i][0], &a[i][1]);
	}
	for (int i = 1; i <= m; ++ i){
		scanf("%d%d", &b[i][0], &b[i][1]);
	}
	for (int i = 1; i <= n; ++ i){
		int min = INT_MAX, sit;
		for (int j = 1; j <= m; ++ j){
			int x = std::abs(a[i][0] - b[j][0]) + std::abs(a[i][1] - b[j][1]);
			if (x < min){
				min = x;
				sit = j;
			}
		}
		printf("%d\n", sit);
	}
	return 0;
}

Measured memory_bytes: 256
import numpy as np
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(input()))
a = np.array(a)
b = []
for _ in range(m):
    b.append(list(input()))
b = np.array(b)
for dy in range(n-m+1):
    for dx in range(n-m+1):
        if (a[dy:m+dy, dx:m+dx]==b).all():
            print('Yes')
            break
    else:
        continue
    break
else:
    print('No')

Measured memory_bytes: 12508
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) {
		int n = scan.nextInt();
		int[] a = new int[n];

		for(int i = 0; i < n; i++) {
			a[i] = scan.nextInt() - (i + 1);
		}

		Arrays.sort(a);
		int b = a[n / 2];

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

		System.out.println(ans);
    }
}


Measured memory_bytes: 91620
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    BTAKOYAKIFESTIVAL2019 solver = new BTAKOYAKIFESTIVAL2019();
    solver.solve(1, in, out);
    out.close();
  }

  static class BTAKOYAKIFESTIVAL2019 {

    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();
      int[] arr = in.nextIntArray(n);
      long sum = 0;
      for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
          sum += arr[i] * (long) arr[j];
        }
      }
      out.println(sum);
    }

  }

  static interface FastInput {

  }

  static class InputReader implements FastInput {

    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer;
    private int bytesRead;

    public InputReader(InputStream is) {
      din = new DataInputStream(is);
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public InputReader(String file_name) throws IOException {
      din = new DataInputStream(new FileInputStream(file_name));
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public int nextInt() {
      int ret = 0;
      byte c = read();
      while (c <= ' ') {
        c = read();
      }
      boolean neg = (c == '-');
      if (neg) {
        c = read();
      }
      do {
        ret = ret * 10 + c - '0';
      } while ((c = read()) >= '0' && c <= '9');

      if (neg) {
        return -ret;
      }
      return ret;
    }

    public int[] nextIntArray(int size) {
      int[] arr = new int[size];
      for (int i = 0; i < size; ++i) {
        arr[i] = nextInt();
      }
      return arr;
    }

    private void fillBuffer() {
      try {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
      } catch (IOException e) {
        throw new RuntimeException("trying to read from null input, verify constraints ");
      }
      if (bytesRead == -1) {
        buffer[0] = -1;
      }
    }

    private byte read() {
      if (bufferPointer == bytesRead) {
        fillBuffer();
      }
      return buffer[bufferPointer++];
    }

  }
}



Measured memory_bytes: 21332
fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let s = read1::<String>();
    if s == "ABC".to_string() {
        println!("ARC");
    } else {
        println!("ABC");
    }
}

Measured memory_bytes: 2140
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    sc.close();

    long g = gcd(A, B);

    HashMap<Long, Long> m = prime_factor(g);

    System.out.println(m.size() + 1);

  }

  static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);
  }

  static HashMap<Long, Long> prime_factor(long N) {
    HashMap<Long, Long> map = new HashMap<>();
    for (long i = 2; i * i <= N; i++) {
      while (N % i == 0) {
        if (map.containsKey(i)) {
          long v_ = map.get(i);
          map.put(i, v_ + 1);
        } else {
          map.put(i, (long) 1);
        }
        N /= i;
      }
    }
    if (N != 1) {
      map.put(N, (long) 1);
    }
    return map;
  }

}

Measured memory_bytes: 25172
#include <bits/stdc++.h>  // ver2.1.9
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lW,0,a.size()){Vout(a[lW]);}
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ
 
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
 
signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  
  int h,w,bl=0,minn;
  cin >> h >> w;
  minn = min(h,w);
  vector<string> maze(h);
  rep(i,0,h) cin >> maze[i];
  
  Pii S=mp(0,0),G=mp(h-1,w-1);
  
  rep(i,0,h){
    rep(j,0,w){
      if(maze[i][j]=='#') bl++;
    }
  }
  int wh = h*w - bl;
  
  
  if(bl < minn) {cout << (h-1)*(w-1)-bl << endl;return 0;}
  
  // ここから
  
  vector<string> maze2 = maze;
  stack<Pii> st2;
  st2.push(S);
  int x2,y2;
  bool ok=false;
  
  while(true){
  while(!st2.empty()){
    x2 = st2.top().first;
    y2 = st2.top().second;
    st2.pop();
    if(mp(x2,y2)==G) {ok = true;break;}
    
    if(y2+1 < w) {if(maze2[x2][y2+1]=='.') st2.push(mp(x2,y2+1));}
    if(y2-1 >= 0) {if(maze2[x2][y2-1]=='.') st2.push(mp(x2,y2-1));}
    if(x2+1 < h) {if(maze2[x2+1][y2]=='.') st2.push(mp(x2+1,y2));}
    if(x2-1 >= 0) {if(maze2[x2-1][y2]=='.') st2.push(mp(x2-1,y2));}
    maze2[x2][y2] = '#';
    
  }
  if(ok) break;
  cout << -1 << endl;
  return 0;
  }
  
  //　　ここまで
  
  queue<Pii> st;
  st.push(S);
  int x,y,ct=0,now;
  
  while(!st.empty()){
    now = st.size();
    if(now >= 10000) {cout << (h-1)*(w-1)-bl << endl;return 0;}
    ct++;
    rep(i,0,now){
      x = st.front().first;
      y = st.front().second;
      st.pop();
      if(mp(x,y)==G) {cout << wh-ct << endl;return 0;}
    
      if(y+1 < w) {if(maze[x][y+1]=='.') st.push(mp(x,y+1));}
      if(y-1 >= 0) {if(maze[x][y-1]=='.') st.push(mp(x,y-1));}
      if(x+1 < h) {if(maze[x+1][y]=='.') st.push(mp(x+1,y));}
      if(x-1 >= 0) {if(maze[x-1][y]=='.') st.push(mp(x-1,y));}
 
      //VVout(maze);
      maze[x][y] = '#';
    }
  }
  
  
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <vector>
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (b == 1){
        cout << 0 << endl;
        return 0;
    }
    
    int res;
    int c = b - a;
    if (c > 0){
        a = a - 1;
        res = (c / a) + 1;
        if (c % a != 0)
            res += 1;
    }
    else{
        res = 1;
    }
    cout << res << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;
 
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 
	int n; cin >> n;
	ll sum = 0;
	for(int i = 1; i <= n; i++){
		if(i%3 == 0 || i%5 == 0)
			continue;
		sum+=i;
	}

	cout << sum << '\n';
 
	return 0;
}

Measured memory_bytes: 3640
import itertools

N = int(input())
t = tuple('MARCH')
dic = {}

for _ in range(N):
    s = input()
    x = s[0]

    if x not in t:
        continue

    if x in dic:
        dic[x] += 1
    else:
        dic[x] = 1

count = [v for v in dic.values()]
if len(count) < 3:
    print(0)
    exit()

ans = 0
for a, b, c in itertools.combinations(count, 3):
    ans += a * b * c

print(ans)


Measured memory_bytes: 9084
h=[2,4,5,7,9]
p=[0,1,6,8]
a=list(map(int,input()))
t=len(a)
if(a[t-1] in h):
  print("hon")
elif(a[t-1] in p):
  print("pon")
else:
  if(a[t-1]==3):
    print("bon")
    

Measured memory_bytes: 9160
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

struct OwnNode
{
	int key;
	OwnNode* parent;
	OwnNode* left;
	OwnNode* right;

	OwnNode(int key):key(key),parent(nullptr),left(nullptr),right(nullptr){}
};

void Insert(OwnNode* &top, OwnNode* &z)
{
	OwnNode* y = nullptr;
	OwnNode* x = top;

	while (x != nullptr)
	{
		y = x;
		if (z->key < x->key)
		{
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}

	z->parent = y;

	if (y == nullptr)
	{
		top = z;
	}
	else if (z->key < y->key)
	{
		y->left = z;
	}
	else
	{
		y->right = z;
	}
}

bool Find(OwnNode* top, int key)
{
	if (top == nullptr)
	{
		return false;
	}
	if (top->key == key)
	{
		return true;
	}
	else
	{
		if (top->key < key)
		{
			if (top->right == nullptr)
			{
				return false;
			}
			else
			{
				return Find(top->right, key);
			}
		}
		else
		{
			if (top->left == nullptr)
			{
				return false;
			}
			else
			{
				return Find(top->left, key);
			}
		}
	}
}

void PrintPre(OwnNode* top)
{
	printf(" %d", top->key);
	if (top->left != nullptr)
	{
		PrintPre(top->left);
	}
	if (top->right != nullptr)
	{
		PrintPre(top->right);
	}
}

void PrintIn(OwnNode* top)
{
	if (top->left != nullptr)
	{
		PrintIn(top->left);
	}
	printf(" %d", top->key);
	if (top->right != nullptr)
	{
		PrintIn(top->right);
	}
}

void Print(OwnNode* top)
{
	if (top == nullptr)
	{
		return;
	}
	PrintIn(top);
	printf("\n");
	PrintPre(top);
	printf("\n");
}

int main()
{
	OwnNode* T;
	OwnNode* z;
	T = nullptr;

	int m;
	cin >> m;

	for (int i = 0; i < m; i++)
	{
		char command[10];
		//int key;

		scanf("%s", command);

		//string command;

		//cin >> command;

		if (command[0] == 'i')
		{
			int key;
			scanf("%d", &key);
			z = new OwnNode(key);
			Insert(T, z);
		}
		else if (command[0] == 'f')
		{
			int key;
			cin >> key;
			printf(Find(T, key) ? "yes\n" : "no\n");
		}
		else
		{
			Print(T);
		}
	}

	return 0;
}


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

int main(int argc, const char * argv[]) {
    uint64_t H, W;
    cin >> H;
    cin >> W;
    
    if (H == 1 || W == 1) {
        std::cout << "1";
    }else {
        uint64_t ans = 0;
        uint64_t w0 = (W%2==0) ? W/2 : W / 2 + 1;
        uint64_t w1 = W / 2;
        uint64_t h0 = (H % 2 == 0) ? H / 2 : H / 2 + 1;
        uint64_t h1 = H / 2;
        ans = w0 * h0 + w1 * h1;
        std::cout << ans;
    }
    return 0;
}


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

int n;
int num[3];
int g;

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}

int primes(int k) {
    for (int i=1; i<=k; i++) {
        if (k%i == 0) printf("%d\n", i);
    }
}

int main() {
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        scanf("%d", &num[i]);
    }

    g = num[0];
    for (int i=1; i<n; i++) {
        g = gcd(g, num[i]);
    }

    primes(g);
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

char a, b, c, d;
int A, B, C, D;

int main(void)
{
	cin >> a >> b >> c >> d;
	A = a - '0',B = b - '0', C = c - '0', D = d - '0';
	
	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;
	
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var n int

	n = readInt()
	if n%2 == 1 {
		fmt.Println(n/2 + 1)
	} else {
		fmt.Println(n / 2)
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 640
// copy from https://github.com/MathProgrammer/AtCoder/blob/master/Contests/Educational%20DP%20Contest/Explanations/Coins%20Explanation.txt
#include <bits/stdc++.h>
using namespace std;
#define NAME "COIN"
double p[3000];
double dp[3000][3000];
int main(){
    //ifstream cin(NAME".inp");
    //ofstream cout(NAME".out");
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>p[i];
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        dp[0][i] = (1-p[i])*dp[0][i-1];
        for(int j = 1;j<=i;j++)
            dp[j][i] = p[i]*dp[j-1][i-1] + (1.0-p[i])*dp[j][i-1];
    }
    double res=0;
    for(int i=n/2+1;i<=n;i++) res +=dp[i][n];
    cout<<setprecision(10)<<res;
}




Measured memory_bytes: 74124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		ll n;
		cin>>n;
		ll arr[n];
		f(i,n) cin>>arr[i];
		ll pre[n];
		pre[0] = arr[0];
		for(int i=1; i<n; i++) {
			pre[i] = pre[i-1] + arr[i];
		}
		ll sum = pre[n-1];
		ll ans = 0;
		ll mod = pow(10,9) + 7;
		for(int i=0; i<n-1; i++) {
			ans += arr[i]*((sum-pre[i])%mod);
			ans %= mod;
		}
		cout<<ans<<"\n";
 	}
 	return 0;
}


Measured memory_bytes: 6728
#include <bits/stdc++.h>  
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
ll l=1000000007;
string alphabet="abcdefghijklmnopqrstuvwxyz";
 
int main() {
  string s; cin>>s;
  if(s.size()!=26){
    cout<<s;
    rep(i,26){
      if(count(s.begin(),s.end(),alphabet[i])==0){
        cout<<alphabet[i]; break;
      }
    }
  }
  else{
    if(s=="zyxwvutsrqponmlkjihgfedcba"){cout<<-1;}
    else{
      rep(i,25){
        if(s[25-i]>s[24-i]){
          rep(j,24-i){cout<<s[j];}
          for(int j=25; j>=25-i; j--){
            if(s[j]>s[24-i]){cout<<s[j]; break;}
          }
          break;
        }
      }
    }
  }
 
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rkc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define rfl(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define test ll t;cin>>t;while(t--)
#define lld long double
#define vpp vector<pair<ll,ll>>
#define ff first
#define ss second
const ll M = 1e9 + 7;
const double pi  =3.141592653589793238463;
int main()
{
    rkc;
    ll a,b,c;
    cin>>a>>b>>c;
    if(c<=a-b)cout<<0;
    else cout<<c-a+b;
}


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

using namespace std;

using ll = long long;

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

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

    if (sum % (N * (N + 1) / 2) > 0) {
        cout << "NO" << endl;
        return 0;
    }

    // 合計操作回数
    ll M = sum / (N * (N + 1) / 2);

    for (ll i = 0; i < N; ++i) {
        ll d = A[(i + 1) % N] - A[i];

        // 箱iの選ばれる回数は(M-d)/Nとなる
        // この値は非負整数でなくてはならない
        if (M < d || (M - d) % N > 0) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := NewScanner()
	K, X := sc.NextInt(), sc.NextInt()

	ans := make([]int, 0)
	for i := X - K + 1; i <= X+K-1; i++ {
		ans = append(ans, i)
	}
	PrintI(ans...)

}

func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}

func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int r = sc.nextInt();
			if(n == 0 && r == 0) break;
			int[] hf = new int[n];
			for(int i = 0; i < n; i++){
				hf[i] = n-i;
			}
			for(int i = 0; i < r; i++){
				int p = sc.nextInt();
				int c = sc.nextInt();
				int[] next = new int[p+c-1];
				for(int j = 0; j < c;j++){
					next[j] = hf[p-1+j];
				}
				for(int j = c; j < p+c-1; j++){
					next[j] = hf[j-c];
				}
				for(int j = 0; j < p+c-1; j++){
					hf[j] = next[j];
				}
			}
			System.out.println(hf[0]);
		}
	}
}

Measured memory_bytes: 36568