akhauriyash/Code-Regression huggingface dataset:
<?php
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($N,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$have=array_fill(0,$N,0);
for($i=0;$i<$K;$i++) {
  $D = (int)trim(fgets(STDIN));
  $A = array_map('intval',explode(" ",trim(fgets(STDIN))));
  foreach($A as $a) {
    $have[$a-1]+=1;
  }
}
$ans=0;
foreach($have as $v) {
  if ($v==0)
    $ans++;
}
printf("%d\n",$ans);

Measured memory_bytes: 16004
fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
    val N = sc.nextInt()
    val X = IntArray(N) { sc.nextInt() }

    val Xs = X.sorted()
    val midL = Xs[N / 2 - 1]
    val midR = Xs[N / 2]

    for (i in 0 until N) {
        pw.println(if (X[i] < midR) midR else midL)
    }
}


Measured memory_bytes: 81020
#include <bits/stdc++.h>
#define fore(i,a,b) for(int i=int(a); i < int(b); i++)
#define foro(i,a,b) for(int i=int(a); i >= int(b); i--)
#define prnt(a) cout << a << endl

using namespace std;

int main() {
	int n; cin >> n;
	string s, t; cin >> s >> t;
	
	fore(i,0,n){
		cout << s[i];
		cout << t[i];
	}


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <string>

int main() {
  std::string s;
  std::cin >> s;

  std::int_fast32_t result = 0;
  char prev_c = s[0];
  for (const char& c : s) {
    if (c != prev_c) {
      ++result;
      prev_c = c;
    }
  }

  std::cout << result << std::endl;
  return 0;
}

Measured memory_bytes: 512
#include <vector>
#include <iostream>
using namespace std;
int A, B, C, Q; vector<int> a, b, c, t, x;
int main() {
	while (cin >> A >> B >> C, A) {
		cin >> Q;
		a.resize(Q);
		b.resize(Q);
		c.resize(Q);
		t.resize(Q);
		for (int i = 0; i < Q; i++) {
			cin >> a[i] >> b[i] >> c[i] >> t[i];
			a[i]--, b[i]--, c[i]--;
		}
		x = vector<int>(A + B + C, 2);
		for (int i = 0; i < Q; i++) {
			if(t[i] == 1) {
				x[a[i]] = 1;
				x[b[i]] = 1;
				x[c[i]] = 1;
			}
		}
		for (int i = 0; i < Q; i++) {
			if (t[i] == 0) {
				int ta = (x[a[i]] == 1 ? 1 : 0);
				int tb = (x[b[i]] == 1 ? 1 : 0);
				int tc = (x[c[i]] == 1 ? 1 : 0);
				if (ta + tb + tc == 2) {
					if (ta == 0) x[a[i]] = 0;
					if (tb == 0) x[b[i]] = 0;
					if (tc == 0) x[c[i]] = 0;
				}
			}
		}
		for (int i = 0; i < A + B + C; i++) cout << x[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    string a, b;
    cin >> a >> b;
    if (a.size() > b.size())
        cout << "GREATER"
             << "\n";
    else if (a.size() < b.size())
        cout << "LESS"
             << "\n";
    else
    {
        rep(i, a.size())
        {
            if (strcmp(&a[i], &b[i]) > 0)
            {
                cout << "GREATER"
                     << "\n";
                return 0;
            }
            else if (strcmp(&a[i], &b[i]) < 0)
            {
                cout << "LESS"
                     << "\n";
                return 0;
            }
        }
        cout << "EQUAL"
             << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
card = [
    list(map(int, input().split(' '))),
    list(map(int, input().split(' '))),
    list(map(int, input().split(' ')))
]

count = int(input())

result = [[0 for _ in range(3)] for _ in range(3)]

for _ in range(count):
    b = int(input())
    for i, cc in enumerate(card):
        for j, c in enumerate(cc):
            if c == b:
                result[i][j] = 1

for i in range(3):
    if result[i][0] == result[i][1] == result[i][2] == 1:
        print('Yes')
        exit(0)
    if result[0][i] == result[1][i] == result[2][i] == 1:
        print('Yes')
        exit(0)
if result[0][0] == result[1][1] == result[2][2] == 1:
    print('Yes')
    exit(0)
if result[0][2] == result[1][1] == result[2][0] == 1:
    print('Yes')
    exit(0)
print('No')


Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main()
{
    char ch;
    cin>>ch;
    if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') cout<<"vowel"<<endl;
    else cout<<"consonant"<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

void print(int i, int j, int k) {
        cout << i << " " << j << " " << k << endl;
}

int main()
{
        int n, y;

        cin >> n >> y;

        for (int i = 0; i <= n; i++) {
                for (int j = 0; j+i <= n; j++) {
                        for (int k = 0; k+j+i <= n; k++) {
                                if (i + k + j != n)
                                        continue;
                                if (i * 10000 + j * 5000 + k * 1000 == y) {
                                        print(i, j, k);
                                        goto end;
                                }
                        }
                }
        }
        print(-1, -1, -1);
end:
        return 0;
}

Measured memory_bytes: 256
def i_input(): return int(input())


n = i_input()
cnt = 0

for i in range(1, n):
    q = n // i
    r = n % i
    if q != 0 and r != 0:
        cnt += q
    elif q != 0 and r == 0:
        cnt += q - 1

print(cnt)


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

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

li = [a,b,c,d,e]

ma = 0
s = 0
for i in li:
    tmp = ((i + (10 - 1)) // 10) * 10
    s += tmp
    ma = max(ma, abs(i - tmp))

print(s - ma)


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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main() {

    string s;
    cin >> s;

    long long int n = s.size();

    long long int p[2019] = {};

    p[ s[0] - '0' ] = 1;

    long long int ans = 0;
    for ( long long int i = 1; i < n; i++ ) {
        long long int pp[2019] = {};
        for ( long long int j = 0; j < 2019; j++ ) {
            pp[ ( j * 10 ) % 2019 ] += p[j];
        }
        for ( long long int j = 0; j < 2019; j++ ) {
            p[ ( j + ( s[i] - '0' ) ) % 2019 ] = pp[j];
        }
        p[ ( ( s[i] - '0' ) ) % 2019 ]++;
        ans += p[0];
//        if ( p[0] > 0 ) cout << i << endl;
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 3740
N, M = map(int, input().split())
G = [[False] * N for _ in range(N)]
A = []
B = []
C = [False] * N
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    A.append(a)
    B.append(b)
    G[a][b] = True
    G[b][a] = True


def dfs(v):
    C[v] = True
    for vv in range(N):
        if G[v][vv] is False:
            continue
        if C[vv] is True:
            continue
        dfs(vv)


def main():
    ans = 0
    for i in range(M):
        G[A[i]][B[i]] = False
        G[B[i]][A[i]] = False
        for j in range(N):
            C[j] = False
        dfs(0)
        G[A[i]][B[i]] = True
        G[B[i]][A[i]] = True
        if all(C) is False:
            ans += 1
            continue
    print(ans)


main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
  
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline A abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol x,k,d;
  cin >>x>>k>>d;
  lol ans=inf;
  chmin(ans,abs(abs(x)-k*d));
  x=abs(x);
  if(x/d<=k){
    k-=x/d;
    x-=d*(x/d);
    
  }else{
    x-=d*k;
    k=0;
  }
  if(k&1){
    chmin(ans,x+d);
    chmin(ans,abs(x-d));
  }else {
    chmin(ans,x);
  }
  cout <<ans<<'\n';

  return(0);
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int a[1001][1001], n, d1, d2, p;
void work(int k) {
	int b = 0;
	while (k % 4 == 0) 
	{
	      k /= 4;
	      b++;
	}
	if (k & 1) {
		for (int i = 0; i < 2 * n; i++) 
		{
			for (int j = 0; j < 2 * n; j++) 
			{
				if (((i >> b) + (j >> b)) & 1) 
				{
					a[i][j] = 1;
				}
			}
		}
	} 
	else 
	{
		for (int i = 0; i < 2 * n; i++) 
		{
			for (int j = 0; j < 2 * n; j++) 
			{
				if ((i >> b) & 1) 
				{
					a[i][j] = 1;
				}
			}
		}
	}
}
int main() 
{
	scanf("%d%d%d", &n, &d1, &d2);
	work(d1);
	work(d2);
	for (int i = 0; i < 2 * n; i++) 
	{
		for (int j = 0; j < 2 * n; j++) 
		{
			if (p < n * n && !a[i][j]) 
			{
				printf("%d %d\n", i, j);
				p++;
			}
		}
	}
	return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n ;
  int ans = 0 ;
  vector<int> v(n+1) ; 
  int now = 0;
  v.at(n) = INF*2 ;
  
  rep(i,n) cin >> v.at(i);
  
  rep(i,n){
   if(v.at(i) < v.at(i+1)){
     ans = max(ans,now);
     now = 0;
   }
    else 
      now ++ ;
  }
   cout << ans ;
}


Measured memory_bytes: 640
/// --- In the name of ALLAH --- ///


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


typedef long long              ll;
typedef vector<int>            vi;
typedef vector<ll>             vl;
typedef vector<vi>             vvi;
typedef vector<vl>             vvl;
typedef pair<int,int>          pii;
typedef pair<double, double>   pdd;
typedef pair<ll, ll>           pll;
typedef vector<pii>            vii;
typedef vector<pll>            vll;
typedef double                 dl;

#define endl                   '\n'
#define PB                     push_back
#define F                      first
#define S                      second
#define all(a)                 (a).begin(),(a).end()
#define rall(a)                (a).rbegin(),(a).rend()
#define sz(x)                  (ll)x.size()
#define wt                     ll t; cin>>t; while(t--)
#define input(a,n)             for(int i=0;i<n;i++) cin>>a[i];

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;


#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))
#define mod 10000007
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

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


const ll mx=1e9;









int main()
{
    optimize();
int a,b,c,k,sum=0,s;
cin>>k;
for(a=1;a<=k;a++)
{
    for(b=1;b<=k;b++)
    {
        for(c=1;c<=k;c++){

            s=gcd(a,b);
            sum=sum+gcd(s,c);
        }

    }
}
cout<<sum<<endl;





    return 0;
}









































Measured memory_bytes: 3648
n = int(input())
S = tuple(input())
ans = 0
R = S.count('R')
G = S.count('G')
B = S.count('B')
for i in range(n):
    a = S[i]
    for j in range(i):
        b = S[j]
        if a == b:
            continue
        else:
            for d in ['R','G','B']:
                if d ==a or d == b:
                    continue
                else:
                    c = d
            if c == 'R':
                ans+=R
            elif c =='G':
                ans+=G
            else:
                ans+=B
            if (2*j-i)<0 :
                pass
            elif S[2*j-i] == c :
                ans -=1
            if (2 * i - j) >= n:
                pass
            elif S[2*i-j] ==c:
                ans -=1
            if (i+j)%2 == 0:
                if S[(i+j)//2] == c:
                    ans -=1
ans /=3
print(int(ans))


Measured memory_bytes: 69564
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int o=0;
    double d=0.0,w=2147483648.0;
    for(int i=0;i<8;i++)w/=2;
    string s;
    cin>>s;
    for(int i=0;i<8;i++){
      int p;
      if(s[i]>='0'&&s[i]<='9')p=s[i]-'0';
      else p=s[i]-'a'+10;
      int ss[4]={};
      for(int j=3;j>=0;j--)ss[j]=(p>>j)&1;
      for(int j=3;j>=0;j--){//cout<<w<<endl;
	if(!i&&j==3){if(ss[j])o++;}
	else{
	  if(ss[j])d+=w;
	  w/=2.0;
	  if(w==0)w=0.5;//cout<<w<<endl;
	}
      }
    }
    if(o)cout<<'-';
    if(d-(long int)d){
      printf("%.99g\n",d);
    }
    else{
      printf("%ld",(long int)d);cout<<".0"<<endl;
    }
   }
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

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

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

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

  int a, b;
  rep(i, N-1){
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> dist(N);
  rep(i, N) dist[i] = -1;

  queue<int> q;

  q.push(0);
  dist[0] = 0;

  while(!q.empty()){

    int v = q.front();
    q.pop();

    for(auto nv : G[v]){

      if(dist[nv] >= 0) continue;

      q.push(nv);
      dist[nv] = dist[v] + 1;
      
    }

  }

  int start = 0;
  int max_dist = 0;

  rep(i, N){

    if(chmax(max_dist, dist[i])){
      start = i;
    }

  }

  q.push(start);
  rep(i, N) dist[i] = -1;
  dist[start] = 0;

  while(!q.empty()){

    int v = q.front();
    q.pop();

    for(auto nv : G[v]){

      if(dist[nv] >= 0) continue;

      q.push(nv);
      dist[nv] = dist[v] + 1;
      
    }

  }

  max_dist = 0;

  rep(i, N){
    chmax(max_dist, dist[i]);
  }

  if(max_dist % 3 == 1){
    cout << "Second" << endl;
  }else{
    cout << "First" << endl;
  }
  

  return 0;
}


Measured memory_bytes: 13556
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> a(n + 2);
    a[0] = 0;
    a[n + 1] = 0;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    vector<ll> pref(n + 2, 0);
    for (int i = 1; i < n + 2; ++i)
        pref[i] = pref[i - 1] + abs(a[i] - a[i - 1]);
    vector<ll> suf(n + 2, 0);
    for (int i = n; i >= 0; --i)
        suf[i] = suf[i + 1] + abs(a[i] - a[i + 1]);
    for (int i = 1; i <= n; ++i)
        cout << pref[i - 1] + suf[i + 1] + abs(a[i - 1] - a[i + 1]) << endl;
    return 0;
}


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

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void)
{
	int N;
	cin >> N;
	int ans = 0;
	Rep(i, N){
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
using namespace std;

int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	cout << max(0ll,(b*(n - 1) + a) - (a*(n - 1) + b) + 1)<< endl;
	return 0;
}

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

int K, N;
vector<int> ans;

void solve(int n) {
    if(n == 0) return;

    int sz = ans.size();

    ans.push_back(K / 2 + 1);
    solve(n - 1);

    if(n % 2 == 0) {
        if(ans.back() == 1) ans.pop_back();
        else {
            ans.back()--;
            while((int)ans.size() - sz < n) ans.push_back(K);
        }
    }
}

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

    if(K % 2 == 0) {
        printf("%d ", K / 2);
        for(int i = 1; i < N; i++) {
            printf("%d ", K);
        }
        return 0;
    }

    solve(N);

    for(int i = 0; i < ans.size(); i++) {
        printf("%d ", ans[i]);
    }
}


Measured memory_bytes: 17648
import math
from collections import Counter


def comb(x, y):
    if x - y < 0:
        return 0
    return math.factorial(x) // (math.factorial(y) * math.factorial(x - y))


N = int(input())

A = map(int, input().split())


c = Counter()

ints = list()
for a in A:
    ints.append(a)
    c[a] += 1

t = 0
for a in set(ints):
    t += comb(c[a], 2)

for a in ints:
    print(t - (c[a] - 1))


Measured memory_bytes: 30372
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
//#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 1000000000

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void swap2(double* a, double* b)
{
	double tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)  //最大公約数
{
	if (a < b)
		swap(&a, &b);

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

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

long power(long x, int n) { //x^n 計算量O(logn)
	long ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x;
		}
		x = x * x; //一周する度にx, x^2, x^4, x^8となる
		n >>= 1; //桁をずらす n = n >> 1
	}
	return ans;
}

int choose(int n, int k) {
	return k == 0 ? 1 : (long long)choose(n - 1, k - 1) * n % MOD * power(k, MOD - 2) % MOD;
}

void bubble_sort(int a[], int n)
{
	int i, j, tmp;

	for (i = 0; i < n; i++)
	{
		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (j = n - 1; j > i; j--)
		{
			if (a[j - 1] > a[j])
			{
				tmp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = tmp;
			}
		}
		printf("\n");
	}
}

void selection_sort(int a[], int n)
{
	int i, j, tmp, min, key;

	for (i = 0; i < n - 1; i++)
	{
		min = i;
		key = a[i];

		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (j = i + 1; j < n; j++)
		{
			if (a[j] < a[min])
			{
				min = j;
				key = a[j];
			}
		}

		tmp = a[i];
		a[i] = a[min];
		a[min] = tmp;

		printf("\n");
	}

	for (int k = 0; k < n; k++)
		printf("%d ", a[k]);
}

void insertion_sort(int a[], int n)
{
	int i, j, tmp;

	for (i = 1; i < n; i++)
	{
		j = i;

		while (j >= 1 && a[j - 1] > a[j])
		{
			tmp = a[j];
			a[j] = a[j - 1];
			a[j - 1] = tmp;
			j--;
		}
	}
}

void shell_sort(int a[], int n)
{
	int h, i, j;

	for (h = 1; h < n / 9; h = h * 3 + 1)
		;

	for (; h > 0; h /= 3)
	{
		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (i = h; i < n; i++)
		{
			j = i;
			while (j >= h && a[j - h] > a[j])
			{
				swap(&a[j - h], &a[j]);
				j -= h;
			}
		}
		printf("\n");
	}

	for (int k = 0; k < n; k++)
		printf("%d ", a[k]);
}

int partition(int a[], int l, int r)
{
	int i, j, pivot;

	i = l - 1;
	j = r;
	pivot = a[r];

	for (;;)
	{
		while (a[++i] < pivot)
			;
		while (i < j-- && pivot < a[j])
			;

		if (i >= j)
			break;

		swap(&a[i], &a[j]);
	}

	swap(&a[i], &a[r]);
	return i;
}

void quick_sort1(int a[], int l, int r)
{
	int v;

	if (l >= r)
		return;

	v = partition(a, l, r);

	quick_sort1(a, l, v - 1);
	quick_sort1(a, v + 1, r);
}

void quick_sort(int a[], int n)
{
	quick_sort1(a, 0, n - 1);
}

int main() {
	
	int N, X;
	int a[100000];

	scanf("%d%d", &N, &X);

	for (int i = 0; i < N; i++)
		scanf("%d", &a[i]);

	int max = INF;
	int ans;

	if (N == 1)
		 max= ABS(a[0]-X);

	for (int i = 0; i < N-1; i++)
	{
		ans = gcd(ABS(X-a[i]), ABS(X-a[i+1]));
		if (ans < max)
			max = ans;
	}

	printf("%d", max);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N,M,X;
    cin >> N >> M >> X;
    int up = 0;
    int dw = 0;
    rep(i, M) {
        int a;cin >> a;
        if(a<=X) ++dw;
        else ++up;
    }
    cout << min(up,dw) << endl;   
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int t,h,m,s;
	scanf("%d",&t);
	h=t/3600;
	m=(t%3600)/60;
	s=(t%3600)%60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 1836
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#define INF INT_MAX
using namespace std;

long long c1, c2;
int N, K;

int main(){
	cin >> N >> K;
	for (int i = 1; i <= N; i++){
		if (i%K == 0)c1++;
		if (K % 2 == 0 && i%K == K / 2)c2++;
	}
	cout << c1*c1*c1 + c2*c2*c2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
const int MAXN=int(1e8);
LL H,W,N,x,y;
LL ans[10],tl=0;
LL no[MAXN],cxh=1e9+7;
int main()
{
	scanf("%lld%lld%lld",&H,&W,&N);
	ans[0]=(H-2)*(W-2);
	for(int t=1;t<=N;t++) {
		scanf("%lld%lld",&x,&y);
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				if(1<=x-i&&x-i<=H-2&&1<=y-j&&y-j<=W-2)
					no[++tl]=cxh*(x-i)+(y-j);
	}
	sort(no+1,no+tl+1);
	int sum=1;
	for(int i=1;i<=tl;i++) {
		if(no[i]==no[i+1])
			sum++;
		else {
			ans[sum]++;
			sum=1;
			ans[0]--;
		}
	}
	/*
	for(int i=1;i<=N;i++)
		Build(i);
	*/
	for(int j=0;j<=9;j++)
		printf("%lld\n",ans[j]);
	return 0;
}

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

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

  string ans = "No";
  rep (i, x) {
    if(i*4 + (x - i) * 2 == y || i*2 + (x - i) * 4 == y) {
      ans = "Yes";
      break;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P = pair<ll,ll>;
const ll INF = ll(1e18)+5;

int main() {
    ll N,K;
    cin >> N >> K;
    vector<P> vec(N);
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        --a;
        vec[i].first = a;
    }
    ll maxVal = -INF;
    for(int i=0;i<N;i++){
        cin >> vec[i].second;
        maxVal = max(maxVal,vec[i].second);
    }
    if(maxVal<=0){
        cout << maxVal << endl;
        return 0;
    }
    ll ans =0;
    for(int i=0;i<N;i++){
        if(vec[vec[i].first].second <=0){
            continue;
        }
        vector<ll> sum(1,0);
        unordered_set<ll> alredy;
        ll loupLen =0;
        ll target = i;
        while(alredy.find(target) == alredy.end()){
            loupLen++;
            alredy.insert(target);
            target = vec[target].first;
            sum.push_back(sum.back() + vec[target].second);
        }
        if(loupLen>= K || sum.back()<=0){
            for(int j=0;j<min(loupLen,K);j++){
                ans = max(ans,sum[j+1]);
            }
            continue;
        }
        ll maxloupNum = K/loupLen;
        maxloupNum--;
        ll temp = sum.back()*maxloupNum;
        ll remain = K - maxloupNum * loupLen;
        for(int j=0;j<remain;j++){
            if(j < loupLen){
                ans = max(ans,temp+sum[j+1]);
            }else{
                ans = max(ans,temp + sum.back()+ sum[j+1-loupLen]);
            }
        }
        // cerr <<"ans=" <<ans << endl;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3952
import Data.List

commaToSpace :: String->String
commaToSpace "" = ""
commaToSpace (x:xs) = if x==',' then ' ':(commaToSpace xs) else x:(commaToSpace xs)

readCard :: String->[Int]
readCard str = map (\x->read x::Int) $ words $ commaToSpace str

--
fourcard :: [Int]->Bool
fourcard card = or $ map (\i->(length $ filter (==i) card)>=4) $ nub card

fullhouse :: [Int]->Bool
fullhouse card = ((c!!0)==(c!!1)&&(c!!1)==(c!!2)&&(c!!3)==(c!!4)) ||
                 ((c!!0)==(c!!1)&&(c!!2)==(c!!3)&&(c!!3)==(c!!4)) 
    where c = sort card

straight :: [Int]->Bool
straight card
    | h==1        = c==[1,2,3,4,5] || c==[1,10,11,12,13]
    | otherwise   = c==[h,h+1,h+2,h+3,h+4]
    where c = sort card
          h = head c

threecard :: [Int]->Bool
threecard card = or $ map (\i->(length $ filter (==i) card)>=3) $ nub card

twopair :: [Int]->Bool
twopair card = 2==(length $ filter (\i->(length $ filter (==i) card)==2) $ nub card)

onepair :: [Int]->Bool
onepair card = or $ map (\i->(length $ filter (==i) card)>=2) $ nub card
--

solve :: [Int]->IO ()
solve card = do
    if fourcard card then putStrLn "four card"
    else if fullhouse card then putStrLn "full house"
    else if straight card then putStrLn "straight"
    else if threecard card then putStrLn "three card"
    else if twopair card then putStrLn "two pair"
    else if onepair card then putStrLn "one pair"
    else putStrLn "null"

main = do
    ss <- getContents
    mapM_ solve $ map readCard $ lines ss

Measured memory_bytes: 4040
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 3e2 + 5;
const double eps = 1e-9;
int dp[MAXN][MAXN][MAXN];
char str[MAXN];

int main() {
	scanf("%s", str);
	int n = strlen(str), k; ni(k);
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j < n; j++)
			dp[i][j][j] = 1;
		for (int len = 1; len < n; len++) {
			for (int l = 0; l + len < n; l++) {
				int r = l + len;
				dp[i][l][r] = max(dp[i][l+1][r], dp[i][l][r-1]);
				if (str[l] == str[r])
					dp[i][l][r] = dp[i][l+1][r-1] + 2;
				else if (i)
					dp[i][l][r] = max(dp[i][l][r], dp[i-1][l+1][r-1] + 2);
			}
		}
	}
	pri(dp[k][0][n-1]);
	return 0;
}


Measured memory_bytes: 110848
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <cstring>

#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()

using namespace std;

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

const int INF = 0x3c3c3c3c;
const ll LINF = 1ll*INF*INF*2;

const int N = 200011;
int n,m;
char input[N];
bool ab[N];
vector<int> v[N][2];

bool imp[N];

int cnt;
int visited[N];
bool dfs(bool prev, int x) {
	if(imp[x]) return false;
	if(visited[x] == cnt) return true;
	visited[x] = cnt;

	bool cur = ab[x];
	
	for(int i=0; i<sz(v[x][!prev]); i++) {
		if(dfs(cur, v[x][!prev][i])) return true;
	}

	imp[x] = true;
	return false;
}

int main(void) {
	scanf("%d%d", &n, &m);
	scanf("%s", input);
	for(int i=0; i<n; i++) ab[i+1] = (input[i]=='A');

	int x, y;
	for(int i=0; i<m; i++) {
		scanf("%d%d", &x, &y);
		v[x][ab[y]].push_back(y);
		v[y][ab[x]].push_back(x);
	}

	for(int i=1; i<=n; i++) {
		cnt++;

		if(dfs(0,i) && dfs(1,i)) {
			visited[i] = 0;
			if(dfs(1,i)) {
				printf("Yes");
				return 0;
			}
		}
	}

	printf("No");
}


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

// limit
#define mod1 22439423LL
#define mod2 42342432LL
#define mod3 56454765LL
#define mod4 66867574LL
#define oo 1000000007LL
#define OO 1000000000000000007LL

// loop
#define fto(i, x, y) for(int i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(int i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(int i = (x); i <= (y); i += a)
#define fdtoa(i, x, y, a) for(int i = (x); i >= (y); i -= a)
#define ftosqrt(i, x, y) for(int i = (x); i*i <= (y); ++i)
#define ftoit(it, var) for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define fdtoit(rit, var) for (__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); ++rit)

// debug
#define debug cout << "*" << endl;
#define bug1d(a, x, y) { cout << #a << ": "; fto(_, x, y) cout << a[_] << ' '; cout << endl; }
#define bug2d(a, x, y, u, v) { cout << #a << ": " << endl; fto(i, x, y) {fto(j, u, v) cout << a[i][j] << ' '; cout << endl;}; cout << endl;}
#define bug(a) cout << #a << " = " << a << endl;
#define bug2(a, b) cout << #a << " = " << a << "; "; cout << #b << " = " << b << endl;
#define bug3(a, b, c) cout << #a << " = " << a << "; "; cout << #b << " = " << b << "; "; cout << #c << " = " << c << endl;

// operation
#define mp make_pair
#define pb push_back
#define pf push_front
// structure
#define ii pair<int, int>
#define iii pair<ii, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define matrix vector<vi>

// get value
#define FF first
#define SS second

// data type
#define ll long long
#define ull unsigned long long

// function
#define lb lower_bound
#define ub upper_bound

// const value
#define pi 3.14159265358979323846264338327950288419716939937510

using namespace std;

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T min(T a, T b, T c, T d) {
    return min(a, min(b, min(c, d)));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

template <class T>
T max(T a, T b, T c, T d) {
    return max(a, max(b, max(c, d)));
}

bool cmp(const ii& a, const ii& b) {return (a.FF > b.FF || (a.FF == b.FF && a.SS >= b.SS));}
ll GCD(ll a, ll b) {return (a%b) ? GCD(b, a%b) : b;}

const string namePro = "tmp";
#define maxN 1000007

int a[maxN];
map <int, int> check;

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen((namePro+".inp").c_str(), "r", stdin);
    //     freopen((namePro+".out").c_str(), "w", stdout);
    // #endif // ONLINE_JUDGE

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

    fto (i, 1, n) {
    	scanf("%d", &a[i]);
    	check[a[i]]++;
    }

    multiset <int> st;
    fto (i, 1, n) {
    	if (check[a[i]] >= 2) {
    		st.insert(-a[i]);
    		if (check[a[i]] >= 4) st.insert(-a[i]);
    		check[a[i]] = 0;
    	}
    }

    if (st.size() < 2) {
    	puts("0");
    	return 0;
    }

    int x = *st.begin();
    st.erase(st.begin());

    int y = *st.begin();
    cout << (ll)x*y << endl;
    return 0;
}


Measured memory_bytes: 5376
/*input

*/
/*
Contest: 
Problem: 
*/
#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;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#define F first
#define S second
#define mp make_pair
#define append push_back
#define vi vector<ll>
#define pii pair<ll,ll>
#define qi queue<ll>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define print(a) cout<<a<<endl
#define sorted(a) sort(arr.begin(), arr.end())
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define read(a) scanf("%d", &a)
 
const int MOD = 1e9 + 7;

signed main(){
    
    int n, m;
    cin>> n >> m;

    int dp[n][m];
    char grid[n][m];

    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin>> grid[i][j];

    mem(dp, 0);

    for(int i = 0; i < n; i++){
        if(grid[i][0] == '.')
            dp[i][0] = 1;
        else
            break;
    }

    for(int i = 0; i < m; i++){
        if(grid[0][i] == '.')
            dp[0][i] = 1;
        else
            break;
    }

    for(int i = 1; i < n; i++){
        for(int j = 1; j < m; j++){
            if(grid[i][j] == '.')
                dp[i][j] = (dp[i-1][j]%MOD + dp[i][j-1]%MOD)%MOD;
        }
    }

    print(dp[n-1][m-1]%MOD);

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
} 

Measured memory_bytes: 5120
#include <cstdlib>
#include <iostream>
#include <typeinfo>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  bool ok = false;
  int f = (b + c) % a;
  int i = 2;
  while (true)
  {
    int d = b * i + c;
    if (f == 0)
    {
      ok = true;
      break;
    }
    if (d % a == 0)
    {
      ok = true;
      break;
    }
    if (d % a == f)
    {
      break;
    }
    i++;
  }
  if(ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;


public class Main {
	
	public static final int MAX = 20;
	
	public static boolean is_ok(int x, int y, int H, int W){
		if(x < 0 || y < 0 || x >= W || y >= H){
			return false;
		}else{
			return true;
		}
	}
	
	public static final int[][] move_dir = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		boolean[][] can_enter = new boolean[MAX][MAX];
		boolean[][] visited = new boolean[MAX][MAX];
		
		while(true){
			final int W = sc.nextInt();
			final int H = sc.nextInt();
			
			if(W == 0 && H == 0){
				break;
			}
			
			int s_x = -1, s_y = -1;
			
			for(int i = 0; i < H; i++){
				char[] input = sc.next().toCharArray();
				
				for(int j = 0; j < W; j++){
					if(input[j] == '#'){
						can_enter[i][j] = false;
					}else{
						can_enter[i][j] = true;
					}
					
					if(input[j] == '@'){
						s_x = j;
						s_y = i;
					}
					
					visited[i][j] = false;
				}
			}
			
			LinkedList<Integer> x_queue = new LinkedList<Integer>();
			LinkedList<Integer> y_queue = new LinkedList<Integer>();
			visited[s_y][s_x] = true;
			x_queue.add(s_x);
			y_queue.add(s_y);
			
			int count = 0;
			while(!x_queue.isEmpty()){
				final int x = x_queue.poll();
				final int y = y_queue.poll();
				
				count++;
				
				for(int[] move : move_dir){
					final int nx = x + move[0];
					final int ny = y + move[1];
					
					if(!is_ok(nx, ny, H, W)){
						continue;
					}else if(!can_enter[ny][nx]){
						continue;
					}else if(visited[ny][nx]){
						continue;
					}
					
					visited[ny][nx] = true;
					x_queue.add(nx);
					y_queue.add(ny);
				}
			}
			
			System.out.println(count);
		}
		
	}
}

Measured memory_bytes: 34160
#include<cstdio>
#include<map>
#include<vector>
#include<queue>

using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> edge; // cost, source, target


typedef struct UF {
    int par[10005];
    void init(int n) {
        for(int i=0; i<n; i++)
            par[i] = i;
    }
    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(x==y) return true;

        par[x] = y;
        return false;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
} UF;


int v,e;
UF uf;
priority_queue<edge, vector<edge>, greater<edge> > edges;

int main(void) {
    scanf("%d%d",&v,&e);
    for(int i=0; i<e; i++) {
        int s,t,d;
        scanf("%d%d%d",&s,&t,&d);
        edges.push(edge(d,P(s,t)));
    }
    int res = 0;
    uf.init(v);
    while(!edges.empty()) {
        edge e = edges.top(); edges.pop();
        int cost = e.first;
        int src = e.second.first, dst = e.second.second;
        if(uf.same(src,dst)) continue;
        res += cost;
        uf.unite(src,dst);
    }

    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    vector<vector<int>> alpha(N, vector<int>(26, 0));
    rep(i, N) {
        string s;
        cin >> s;
        rep(j, s.size()) { alpha[i][s[j] - 'a']++; }
    }

    string s = "";
    rep(j, 26) {
        int cnt = 10000;
        bool judge = 1;
        rep(i, N) {
            if (alpha[i][j] == 0)
                judge = 0;
            cnt = min(cnt, alpha[i][j]);
        }
        if (judge) {
            s += string(cnt, (j + 'a'));
        }
    }

    cout << s << endl;
}

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

#include <math.h>
#include <stdlib.h>


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

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int r, g, b; cin >> r >> g >> b;
    int ans = r * 100 + g * 10 + b;
    if(ans %4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
num_list = input().split()
A = [int(s) for s in num_list]
A.sort()
B = []
for i in range(N):
    if A[i] != int(num_list[i]):
        B.append(1)

if len(B) == 2 or len(B) == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
#include <numeric>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }



struct C
{
	ll x = 0;
	ll y = 0;
	ll z = 0;
	ll value() { return abs(x) + abs(y) + abs(z); }
	ll value(int mode) const {
		ll result = 0;
		result += (mode & 1) ? x : -x;
		result += (mode & 2) ? y : -y;
		result += (mode & 4) ? z : -z;
		return result;
	}
};

int main(int argc, char* argv[])
{
	for (;;) {
		int N;

		cin >> N;
		if (cin.fail()) break;

		vector<ll> V(N);
		for (int i = 0; i < N; i++) {
			cin >> V[i];
		}
		auto test = [&](int mode) {
			ll result = 0;
			ll sum = 0;
			for (int i = 0; i < N; i++) {
				bool b = (i & 1) == mode;
				if (b && sum + V[i] <= 0) {
					result += abs(sum + V[i]) + 1;
					sum = 1;
				} else if (!b && sum + V[i] >= 0) {
					result += abs(sum + V[i]) + 1;
					sum = -1;
				} else {
					sum += V[i];
				}
			}
			return result;
		};
		ll result = min(test(0), test(1));
		cout << result << endl;
	}

	return 0;
}


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

using namespace std;

using ll= long long ;

void solve() {
    int n; cin >> n;
    vector<ll> a(n);
    for (auto& x: a) {
        cin >> x;
    }
    ll res = 0;

    while (*max_element(a.begin(), a.end()) >= n) {
        ll cnt = 0;
        for (auto& x: a) {
            cnt += x/n;
        }
        res += cnt;
        for (auto& x: a) {
            x = (x%n) + cnt - (x/n);
        }
    }
    cout << res;
}

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


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, A, B;

  std::cin >> N >> A >> B;

  std::cout << std::min(A * N, B) << std::endl;

  return 0;
}


Measured memory_bytes: 888
//CazadorDivino
#include "bits/stdc++.h"
#include <cmath>
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)


#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<int,int> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

//~ struct no{
	//~ int x, y;
	//~ int cust;
	//~ no(int x ,int y, int cust):x(x),y(y),cust(cust){
	//~ }
//~ };
//~ vector<no> g;
//~ bool vis[N];
//~ int v[N];
//~ void dfs(int u){
    //~ vis[u] = true;
    //~ rep(i,0,sz(g[u].x)-1){
        //~ if(!vis[g[u]])
            //~ dfs(g[u][i]);
    //~ }
    //~ return;
//~ }

//~ void add(int x, int y, int z){
	//~ no a(x,y,z);
	//~ g[x].pb(a);
	//~ g[y].pb(a);
//~ }

int main(){	
	int a, b, k;
	cin>> a >> b >> k;
	int ok = true;
	while(k--){
		if(ok){
			if(a%2 == 1)
				a-=1;
			b += a /2;
			a -= a/2;
			ok = false;
		}
		else{
			if(b%2 == 1)
				b-=1;
			a += b /2;
			b -= b/2;
			ok = true;
		}
	}
	cout<< a << " "<<b;
	return 0;
}
	


Measured memory_bytes: 256
from operator import itemgetter
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
BC.sort(key=itemgetter(1), reverse=True)

for b, c in BC:
    A.extend([c]*b)
    if len(A) >= 2*N:
        break

A.sort(reverse=True)
print(sum(A[:N]))


Measured memory_bytes: 35788
N,A,B = map(int,raw_input().split())
X = map(int,raw_input().split())

result=0
for i in range(N-1):
    if (X[i+1]-X[i])*A > B:
        result+=B
    else:
        result+=(X[i+1]-X[i])*A
print result

Measured memory_bytes: 11320
using System;

class program
{
    public static void Main()
    {
        string W = Console.ReadLine().ToUpper();
        int count = 0;

        while (true)
        {
            string T = Console.ReadLine();

            if (T.Equals("END_OF_TEXT")) break;

            T = T.ToUpper();

            foreach (string t in T.Split(' '))
            {
                if (W.Equals(t)) count++;
            }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 5592
process.stdin.resume();
process.stdin.setEncoding('utf8'); 
var lines = [];
var reader = require('readline').createInterface({
	input: process.stdin,
	output: process.stdout
});
 
reader.on('line', (line) => {
	lines.push(line);
});

reader.on('close', () => {
	const N = +lines[0];
	const A = +lines[1];
	const B = +lines[2];
	const C = +lines[3];
	const D = +lines[4];
	const E = +lines[5];
	
	const bottleneck = Math.min(A,B,C,D,E);
	
	console.log(Math.ceil(N/bottleneck) + 4);
});

Measured memory_bytes: 7628
#include<bits/stdc++.h>
#define M 100005
#define LL long long
using namespace std;
const int mod=1e9+7;
int n,ans=0;
char S[M];
int cnt[26];
LL qkpow(LL a,LL b){
	LL res=1;
	while(b){
		if(b&1)res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
int main(){
	scanf("%d%s",&n,S+1);
	for(int i=1;i<=n;i++){
		int &c=cnt[S[i]-'a'];
		int res=1;
		for(int j=0;j<26;j++)
			if(j!=S[i]-'a')res=1LL*res*(cnt[j]+1)%mod;
		ans=1LL*(ans+res)%mod;
		c++;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
	int a, b, x;
	cin >> a >> b;
	x = a + b;
	if (x % 3 == 0)
		cout << "Possible";
	else if (a % 3 == 0 || b % 3 == 0)
		cout << "Possible";
	else
		cout << "Impossible";

	
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define cpresent(c,x) ((c).find(x) != (c).end()) 
#define vpresent(c,x) (find(all(c),x) != (c).end())
#define endl '\n'
#ifdef LOCAL
#include "/home/iggaboi/Desktop/CP/debug.h"
#else
#define debug(Args...)
#endif
using ll = long long;
using namespace __gnu_pbds;
using namespace std;
template<class T>
using indexed_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

int a;

void shit() {
	cin >> a;
    cout << a + a*a + a*a*a <<endl;
}

int32_t main() {
	ios_base::sync_with_stdio(false),cin.tie(nullptr);
	// int t; cin >> t;
	// while(t--)
		shit();
	return 0;
}


Measured memory_bytes: 3556
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
from collections import Counter
data=Counter(a)
if n%2==1:
    if 0 not in a:
        print(0)
        exit()
    else:
        a.remove(0)
        data=Counter(a)
        for i in data.values():
            if i!=2:
                print(0)
                exit()
    print((2**(n//2))%mod)
else:
    for i in data.values():
        if i!=2:
            print(0)
            exit()
    print((2**(n//2))%mod)
    

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

int m, n;
int ans[150];

int dp[2050][2050]; // S?????????????????£??????

using Set = bitset<12>;

int rec(int asked, int answer){ // ??????????????????aked???answer??¨??????????????????
    int &res = dp[asked][answer];
    if(res != -1) return res;
    res = m;

    // vector<int> a;
    {
        int cnt = 0;
        for(int i = 0; i < n; ++i){
            if((ans[i] & asked) == answer){
                ++cnt;
            }
        }
        if(cnt <= 1) return res = 0;
    }

    // cout << "A " << Set(asked) << ' ' << Set(answer) << endl;
    // cout << "B ";
    // for(int &x : a) cout << Set(ans[x]) << ' ';
    // cout << endl;

    for(int i = 0; i < m; ++i){
        if(asked >> i & 1) continue;
        int cnt[2] = {};
        for(int j = 0; j < n; ++j){
            if((ans[j] & asked) == answer){
                ++cnt[ans[i] >> j & 1];
            }
        }
        // if(cnt[0] == 0 || cnt[1] == 0) continue;
        int tmp = 0;
        for(int j = 0; j < 2; ++j){
            tmp = max(tmp, 1 + rec(asked | 1<<i, answer | (j << i)));
        }
        res = min(res, tmp);
    }

    // assert(res != 1e9);
    return res;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    while(cin >> m >> n && m){
        for(int i = 0; i < n; ++i){
            char buf[100];
            cin >> buf;
            ans[i] = 0;
            for(int j = 0; j < m; ++j){
                if(buf[j]-'0') ans[i] |= 1 << j;
            }
        }
        memset(dp,-1,sizeof(dp));
        cout << rec(0,0) << endl;
        // cout << "=================" << endl;
    }
}

Measured memory_bytes: 19412