akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

int calc(int a,int b){
  if(b == 0) return 1;
  if(b%2 == 0){
    int d = calc(a,b/2);
    return (d*d)%MOD;
  }
  return (a*calc(a,b-1))%MOD;
}

int comb(int n,int r){
  int tmp = 1,ttmp = 1;
  for(int i = n;i >= n-r+1;i--) tmp = (tmp*i)%MOD;
  for(int i = 1;i <= r;i++) ttmp = (ttmp*i)%MOD;
  return (tmp*calc(ttmp,MOD-2))%MOD;
}

signed main() {
  int N, M;
  cin >> N >> M;

  cout << comb(N, 2)+comb(M, 2) << endl;

  return 0;
}

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

int main () {
  int N; cin >> N;
  
  int a[N];
  int count =1, values = 0;
  for (int i=0; i<N; i++) {
    cin >> a[i];
  }
  for (int i=0; i<N-1; i++) {
    if (a[i] < a[i+1]) {
      if (values == 0) values =1;
      else if (values == 2) {
        values = 0;
        count++;
      }
    }
    else if (a[i]> a[i+1]){
      if (values == 0) values = 2;
      else if (values == 1) {
        values = 0;
        count++;
         }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 640
local ffi=require"ffi"
ffi.cdef[[
int open(const char*,int,...);
int close(int);
void* mmap(void*,size_t,int,int,int,int);
int munmap(void*,size_t);
]]
local C=ffi.C
local program="\x48\x89\xf8\x48\x21\xf0\x48\x83\xe0\x01\xc3"
local fd=C.open("/dev/zero",0)
local mem=C.mmap(nil,#program,6,2,fd,0)
ffi.copy(mem,program,#program)
local fn=ffi.cast("int(*)(int,int)",mem)
print(fn(io.read"*n",io.read"*n")~=0 and"Odd"or"Even")
C.munmap(mem,#program)
C.close(fd)

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 0x3f3f
using namespace std;
const int maxn=1e3+10;
int f[maxn],n,dp[2][maxn*5],x[maxn];
vector<int>g[maxn];

void dfs(int u){
    for (auto v:g[u]) dfs(v);
    memset(dp[0],inf,sizeof(dp[0]));
    int cur=0;
    dp[cur][0]=0;
    for (auto v:g[u]){
        cur^=1;
        memset(dp[cur],inf,sizeof(dp[cur]));
        for (int j=0; j<=x[u]; j++){
            if(j-x[v]>=0) dp[cur][j]=min(dp[cur][j],dp[cur^1][j-x[v]]+f[v]);
            if(j-f[v]>=0) dp[cur][j]=min(dp[cur][j],dp[cur^1][j-f[v]]+x[v]);
        }
    }
    for (int i=0; i<=x[u]; i++) f[u]=min(f[u],dp[cur][i]);
}

int main(){
    scanf("%d",&n);
    for (int p,i=2; i<=n; i++) {
        scanf("%d",&p);
        g[p].push_back(i);
    }
    for (int i=1; i<=n; i++) scanf("%d",&x[i]);
    memset(f,inf,sizeof(f));
    dfs(1);
//    for (int i=1; i<=n; i++) printf("%d ",f[i]);
//    printf("\n");
    if(f[1]<0x3f3f3f) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 384
N = int(input())
H = list(map(int,input().split()))
A = list(map(int,input().split()))

class SegTreeMax:
    def __init__(self,arr):
        n = 1
        while n < len(arr):
            n *= 2
        self.n = n
        nodes = [0]*(2*n-1)
        nodes[n-1:n-1+len(arr)] = arr
        for i in range(n-2,-1,-1):
            nodes[i] = max(nodes[2*i+1],nodes[2*i+2])
        self.nodes = nodes

    def update(self,i,val):
        i += self.n-1
        self.nodes[i] = val
        while i:
            i = (i-1)//2
            self.nodes[i] = max(self.nodes[2*i+1],self.nodes[2*i+2])

    def query(self,a,b,k=0,l=0,r=-1):
        if r < 0: r = self.n
        if r <= a or b <= l: return 0
        if a <= l and r <= b: return self.nodes[k]
        return max(self.query(a,b,2*k+1,l,(l+r)//2), self.query(a,b,2*k+2,(l+r)//2,r))

segt = SegTreeMax([0]*N)
ans = 0
for h,a in zip(H,A):
    v = segt.query(0,h) + a
    segt.update(h-1,v)
    ans = max(ans, v)
print(ans)

Measured memory_bytes: 121040
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	vector<int> deg(4);
	for (int i = 0; i < 6; ++i) {
		int a;
		cin >> a;
		++deg[--a];
	}
	cout << (*max_element(deg.begin(), deg.end()) == 2 ? "YES" : "NO") << endl;
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N,A,B;
int h[100010];

bool eval(int z){
	LL s = 0;
	LL p = (LL)B * z;
	repp(i,0,N){
		if((LL)h[i] <= p) continue;
		s += (h[i] - p + A - 1) / A;
	}
	return s <= (LL)z;
}

int BS(int x , int y){
	if(x-y<2) return x;
	int z = (x+y)/2;
	return eval(z) ? BS(z,y) : BS(x,z);
}

int main(){
	scanf("%d%d%d" , &N , &A , &B);
	repp(i,0,N){
		scanf("%d" , h + i);
	}
	A -= B;
	printf("%d\n" , BS(1000000002,0));
	return 0;
}


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

#define Q 1000000007

int main(void){
  int dp[1010][1010];
  int tlen,blen;
  string t,b;
  
  cin >> t >> b;
  tlen = t.size(); blen = b.size(); 
  // init
  for (int i=0; i<=tlen; i++) dp[i][0] = 1;
  for (int i=1; i<=blen; i++) dp[0][i] = 0;
  // dp
  for (int i=1; i<=tlen; i++){
    for (int j=1; j<=blen; j++){
      dp[i][j] = dp[i-1][j];
      if (t[i-1]==b[j-1]) dp[i][j] += dp[i-1][j-1];
      dp[i][j] %= Q;
    }
  }
/*  
  for (int i=0; i<=tlen; i++){
    for (int j=0; j<=blen; j++)
      cout << dp[i][j] << " ";
    cout << endl;
  }
*/
  cout << dp[tlen][blen] << endl;
  return 0;
}


Measured memory_bytes: 7156
#include<bits/stdc++.h>
using namespace std;
void s2()
{
    int a,b;
    cin>>a>>b;
    string res;
    int small=min(a,b);
    int large=max(b,a);
    for(int i=0;i<large;i++){
        res.append(1,small+'0');
    }
    cout<<res<<endl;
}

int main()
{
    //s1();
    s2();
    //s3();
    //s4();
}


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

double solve(int n, int k)
{
  double result = n >= k ? static_cast<double>(n - k + 1) / n : 0;
  for (int i = 1; i < std::min(n + 1, k); ++i) {
    const int z = std::ceil(std::log2(k) - std::log2(i));
    result += static_cast<double>(1) / n / (1 << z);
std::cerr <<  std::setprecision(10) << "i=" << i << ", z=" << z << ", 1<<z=" << (1 << z) << ", result=" << result << std::endl;
  }
  return result;
}

int main()
{
  int n, k;
  std::cin >> n >> k;

  std::cout << std::setprecision(20) << solve(n, k) << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n,T;
  cin >> n >> T;
  int c,t;
  int mini = 100000;
  rep(i,n){
    cin >> c >> t;
    if(t > T) continue;
    mini = min(mini,c);
  }
  if(mini == 100000) cout << "TLE";
  else cout << mini;
}


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

int main() {
	static long long L[500000], R[500000], N, ANS = 0;
	string S;
	cin >> S;
	N = S.size() + 1;
	L[0] = 0, R[N - 1] = 0;
	for (int i = 0; i < N - 1; i++) {
		if (S[i] == '<') L[i + 1] = L[i] + 1;
		else L[i + 1] = 0;
	}
	for (int i = N - 2; i >= 0; i--) {
		if (S[i] == '>') R[i] = R[i + 1] + 1;
		else R[i] = 0;
	}
	for (int i = 0; i < N; i++) {
		ANS += max(L[i], R[i]);
	}
	cout << ANS << endl;
}

Measured memory_bytes: 8708
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 

int a[maxs];
int tree[4*maxs];

void build(int node,int s,int e)
{
    if(s==e)
    {
        tree[node]=a[s];
    }
    else
    {
        int mid=(s+e)/2;
        build(node*2,s,mid);
        build(node*2+1,mid+1,e);
        tree[node]=tree[node*2]+tree[node*2+1];
    }
}
void update(int node,int s,int e,int idx,int val)
{
    if(s==e)
    {
        a[idx]=val;
        tree[node]=val;
    }
    else
    {
       int mid=(s+e)/2;
        if(idx>=s&&idx<=mid)
        update(node*2,s,mid,idx,val);
        else
        update(node*2+1,mid+1,e,idx,val);
         tree[node]=tree[node*2]+tree[node*2+1];
    }
}
int query(int node,int s,int e,int l,int r)
{
    if(l>e||s>r)
    return 100005;
    if(l<=s&&r>=e)
    return tree[node];
    else
    {
        int mid=(s+e)/2;
        int p1=query(2*node,s,mid,l,r);
        int p2=query(2*node+1,mid+1,e,l,r);
        return p1+p2;
    }
    
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int i;
    for(i=1;i<=5;i++)
    cin>>a[i];
    
   for(i=1;i<=5;i++)
   if(a[i]==0)
   break;
   
   cout<<i;
}




Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main() {
    int a, b, h;
    scanf("%d%d%d", &a, &b, &h);
    int s = (a + b) * h >> 1;
    printf("%d\n", s);
    return 0;
}

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

using namespace std;

int checkdig(int inp[]);

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

  
  
  int nums[12];
  int q=0;
  int ans=-1;

  for(int i=0;i<12;i++){
    char chara=inp.at(12-i-1);
    
    if(chara=='?'){
      q=i;

      
    }
    

    nums[i]=(int)inp.at(12-i-1)-(int)'0';
  
  }
  
  if(q==0){
    cout << checkdig(nums)<<endl;
    return 0;
  }else{
    int dig;
    for(int j=0;j<10;j++){
      nums[q]=j;
      dig=checkdig(nums);
    
      if(dig==nums[0]){
	if(ans==-1){
	  ans=j;
	}else{
	  cout << "MULTIPLE" << endl;
	  return 0;
	}
      }
    }
   
  }
  cout << ans << endl;
  return 0;
}

int checkdig(int inp[]){
  int ans=-1;
  int temp=0;
  for(int i=1;i<12;i++){
      if(1<=i && i<=6){
	temp+=inp[i]*(i+1);
      }else{
	temp+=inp[i]*(i-5);
      }
  }
  if(temp%11<2){
    ans=0;
  }else{
    ans=11-temp%11;
  }
  return ans;

}

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

class Dictionary {
private:
    set<string> word;

public:
    void insert(string str) {
        word.insert(str);
    };
    void find(string str) {
        auto itr = word.find(str);
        cout << ((itr != word.end()) ? "yes" : "no") << endl;
    };
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    Dictionary dic;
    while (n--) {
        string order, str;
        cin >> order >> str;
        if (order == "insert") {
            dic.insert(str);
        } else if (order == "find") {
            dic.find(str);
        }
    }

    return 0;
}


Measured memory_bytes: 28936
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <bitset>
#define R register
#define IN inline
#define gc getchar()
#define W while
#define MX 5050
template <class T>
IN void in(T &x)
{
	x = 0; R char c = gc;
	W (!isdigit(c)) c = gc;
	W (isdigit(c))
	x = (x << 1) + (x << 3) + c -48, c = gc;
}
std::bitset <MX> bt;
int num, kth, dat[MX];
IN bool check(const int &now)
{
	bt.reset();
	bt[0] = true; int bd = kth - dat[now];
	for (R int i = 1; i <= num; ++i) if(i != now) bt |= bt << dat[i];
	for (R int i = kth - 1; i >= bd; --i) if(bt[i]) return true;
	return false;
}
int main(void)
{
	in(num); in(kth);
	for (R int i = 1; i <= num; ++i) in(dat[i]);
	std::sort(dat + 1, dat + 1 + num);
	int ans = 0, mid, lef = 1, rig = num;
	W (lef <= rig)
	{
		mid = lef + rig >> 1;
		if(!check(mid)) ans = mid, lef = mid + 1;
		else rig = mid - 1;
	}
	printf("%d", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
    sort(s.at(i).begin(),s.at(i).end());
  }
  sort(s.begin(),s.end());
  long long count = 0;
  long long count2 = 0;
  
  for (int i = 1; i < N;i++) {
    if (s.at(i-1) == s.at(i)) count2++;
    else {
      count += (count2 + 1) * count2 / 2;
      count2 = 0;
    }
  }
  
  count += (count2 + 1) * count2 / 2;
      
  
  cout << count << endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;



int main(){
	string s;
	cin >> s;
	int n = s.size();
	for(int i=0;i<n;i++){
		if(s.at(i) != s.at(n-1-i)){
			cout << "No" << endl;
			return 0;
		}
	}
	for(int i=0;i<(n-1)/2;i++){
		if(s.at(i) != s.at((n-1)/2-1-i)){
			cout << "No" << endl;
			return 0;
		}
	}
	for(int i=0;i<(n-1)/2;i++){
		if(s.at((n+1)/2+i) != s.at(n-1-i)){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import OrderedDict

reader = list(map(int, input().split()))
cake_num = reader[0]
eat_num = reader[1]

def rev_sign(x, v):
    return x*v

def max_value(x, y, z, cakes):
    cake_values = {}
    for c in range(cake_num):
        beautiful = rev_sign(x, cakes[c][0])
        tasty = rev_sign(y, cakes[c][1])
        popular = rev_sign(z, cakes[c][2])
        cake_values.update({c:beautiful + tasty + popular})
    value_sorted = list(OrderedDict(sorted(cake_values.items(), key=lambda x:x[1])).values())
    answer = 0
    for c in range(eat_num):
        answer += value_sorted[c]
    return answer    

cakes = []
for c in range(cake_num):
    reader = list(map(int, input().split()))
    cakes.append(reader)

max_value_log = 0
for x in [-1, 1]:
    for y in [-1, 1]:
        for z in [-1, 1]:
            tmp = max_value(x, y, z, cakes)
            if max_value_log < abs(tmp):
                max_value_log = abs(tmp)
                
print(str(max_value_log))


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

int INF = (10 * 10 * 10) * (10 * 10 * 10) * (10 * 10 * 10);

void calc_shortest_distance(int *ds, int N, pair<int, int> *es, int M) {
    while (true) {
        bool updated = false;
        for (int i = 0; i < M * 3; ++i) {
            int src = es[i].first;
            int dst = es[i].second;
            if (ds[src] + 1 < ds[dst]) {
                ds[dst] = ds[src] + 1;
                updated = true;
            }
        }
        if (!updated) {
            break;
        }
    }
}

int main() {
    int N, M;
    cin >> N; cin >> M;

    pair<int, int> es[M * 3];
    for (int i = 0; i < M; ++i) {
        int src, dst;
        cin >> src; cin >> dst;
        src--;
        dst--;
        es[i*3].first = src;
        es[i*3].second = dst + N;
        es[i*3+1].first = src + N;
        es[i*3+1].second = dst + 2 * N;
        es[i*3+2].first = src + 2 * N;
        es[i*3+2].second = dst;
    }
    int S, T;
    cin >> S; cin >> T;
    int ds[N * 3];
    for (int i = 0; i < N * 3; ++i) {
        ds[i] = INF;
    }
    ds[S - 1] = 0;
    calc_shortest_distance(ds, N, es, M);
    int ans = ds[T - 1];
    if (ans == INF) {
        cout << "-1" << "\n";
    } else {
        cout << (ds[T - 1] / 3) << "\n";
    }
    return 0;
}


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

int main()
{
  int n,d;
  cin>>n>>d;
  int x[n][d];
  for(int i=0; i<n; i++)
  {
    for(int j=0; j<d; j++)
    {
      cin>>x[i][j];
    }
  }
  int sq_sum, sq_root;
  int count=0;
  for(int i=0; i<n; i++)
  {
    for(int j=i+1; j<n; j++)
    {
      sq_sum=0;
      for(int k=0; k<d; k++)
      {
        sq_sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      sq_root= (int)floor(sqrt(sq_sum));
      if(sq_sum==sq_root*sq_root) count++;
    }
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#define rep(i,n) for (int i=0;i<n;i++)
#include <vector>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const long long INF = 1LL<<60;

int main(){
  
  int N;
  cin >> N;
  
  vector<double> p(N);
  rep(i,N)
    cin >> p.at(i);
  
  int n=N/2;
  
  vector<vector<double>> dp(N,vector<double>(n+1,0));
  dp.at(0).at(0)=p.at(0);
  
  rep(i,N){
    rep(j,n+1){
      if(j==0){
        if(i!=0){
        	dp.at(i).at(j)=dp.at(i-1).at(j)*p.at(i);
          //cout << dp.at(i).at(j) << endl;
        }
        //cout << dp.at(i).at(j) << endl;
        
      }
      
      else if(i==0 && j==1)
      	dp.at(i).at(j)=1-p.at(0);
      else if(i==0)
        dp.at(i).at(j)=0;
      else
      dp.at(i).at(j)=dp.at(i-1).at(j)*p.at(i)+dp.at(i-1).at(j-1)*(1-p.at(i));
      
      
      
      //cout << i << j << dp.at(i).at(j) << endl;
      
    }
   
  }
  
  
  double ans=0;
  
  rep(i,n+1)
    ans+=dp.at(N-1).at(i);
  
  cout << fixed << setprecision(10) << ans << endl;
  
  
  
}

Measured memory_bytes: 35584
n = int(input())
A = list(map(int,input().split()))
sum1,sum2 = 0,0
ans1,ans2 = 0,0 #ans1:正負正負...,ans2:負正負正...

if(n == 1):
  if(A[0] != 0): ans = 0
  else: ans = 1
    
else:
 for i in range(n):
    sum1 += A[i]
    if(i%2 == 0):
     if(sum1 <= 0):
        ans1 += abs(1-sum1)
        sum1 = 1
    else:
     if(sum1 >= 0):
        ans1 += abs(sum1-(-1))
        sum1 = -1

    sum2 += A[i]    
    if(i%2 == 1):
     if(sum2 <= 0):
        ans2 += abs(1-sum2)
        sum2 = 1
    else:  
     if(sum2 >= 0):
        ans2 += abs(sum2-(-1))
        sum2 = -1   
 ans = min(ans1,ans2)

print(ans)    

Measured memory_bytes: 14468
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> V(M);
  vector<vector<int>> Y(N);
  for (int i = 0; i != M; ++i) {
    cin >> V[i].first >> V[i].second;
    Y[V[i].first - 1].push_back(V[i].second);
  }

  for (int i = 0; i != N; ++i) sort(begin(Y[i]), end(Y[i]));

  for (auto &p : V) {
    cout << setfill('0')
         << setw(6) << p.first
         << setw(6)
         << lower_bound(begin(Y[p.first - 1]), end(Y[p.first - 1]), p.second) -
                begin(Y[p.first - 1]) + 1
         << endl;
  }
}


Measured memory_bytes: 9472
#if 1

#include <bits/stdc++.h>
using namespace std;
int n,w;
long long d[100005];

int main()
{
    int n,w;
    memset(d,63,sizeof(d));
    scanf("%d %d", &n, &w);
    d[0] = 0;
    for(int i = 1;i <= n;i++)
    {
        int n1,n2;
        scanf("%d %d", &n1, &n2);
        for(int j = 100000;j >= n2;j--)
        {
            d[j] = min(d[j],d[j-n2] + n1);
        }
    }
    int ans = 0;
    for(int i = 0;i <= 100000;i++)
    {
        if(d[i] <= w) ans = i;
    }
    printf("%d",ans);
}

#endif // 1++


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main() {
  string s; cin >> s;
  int ans = 0;
  for(int i = 0; i < 6; i++) {
    if(s[i] == '1') ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
import math
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
A,B,C = na()

if(A<=C and C<=B):
    print("Yes")
elif(B<=C and C<=A):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<stdio.h>

int main(void){
  int a,b,i,j,temp,tmp[5],ans=0;
  scanf("%d %d",&a,&b);
  for(i=a;i<=b;i++){
    temp=i;
    for(j=0;j<5;j++){
      tmp[j]=temp%10;
      temp/=10;
    }
    if(tmp[0]==tmp[4] && tmp[1]==tmp[3]) ans++;
  }
  printf("%d\n",ans);
  return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, x;
    cin >> n >> m >> x;

    vector<vector<int>> a(n, vector<int>(m + 1));
    for (int i = 0; i < n; i++)
        for (int j = 0; j <= m; j++)
            cin >> a[i][j];
    
    int ans = 0x3f3f3f3f;
    for (int i = 0; i <= (1 << n) - 1; i++){
        vector<int> level(m);
        int cost = 0;
        for (int j = 0; j < n; j++){
            if ((1 << j) & i){
                for (int k = 1; k <= m; k++)
                    level[k - 1] += a[j][k];
                cost += a[j][0];
            }
        }
        
        bool ok = true;
        for (auto j: level){
            if (j < x){
                ok = false;
                break;
            }
        }

        if (ok)
            ans = min(ans, cost);
    }

    if (ans == 0x3f3f3f3f)
        cout << -1 << '\n';
    else
        cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位
ll n;
ll ans = 0;
void func(ll a){
    string s = to_string(a);
    vector<bool> ok(3, false);
    for(ll i = 0; i < s.length(); i++){
        if(s[i]=='3') ok[0] = true;
        if(s[i]=='5') ok[1] = true;
        if(s[i]=='7') ok[2] = true;
    }
    if(ok[0]&&ok[1]&&ok[2]&&a<=n) {
        ans++;
     //   cout << a << endl;
    }
    if(a<n){
        func(a*10+3); func(a*10+5); func(a*10+7);
    }
}
int main(void) {
    cin >> n;
    func(3);
    func(5);
    func(7);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

func m() {
	n := getInt()
	ls := getIntSlice(n)
	sort.Ints(ls)

	ans := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			a, b := ls[i], ls[j]
			r := sort.Search(len(ls), func(i int) bool { return ls[i] >= (a + b) })
			cntC := r - j - 1
			ans += cntC
		}
	}

	puts(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// -----------------------------------------

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// scanner.Buffer(make([]byte, buf), buf)
	scanner.Split(bufio.ScanWords)
	m()
	writer.Flush()
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}

func puts(a ...interface{}) {
	if _, err := fmt.Fprintln(writer, a...); err != nil {
		panic(err)
	}
}


Measured memory_bytes: 640
def main():
    from itertools import accumulate
    n, k = map(int, input().split())
    p = list(map(int, input().split()))

    p_acc = tuple(accumulate(p))
    p_max = p_acc[k-1]
    if n == k:
        print((p_acc[-1]+k)/2)
        return
    for i in range(n-k):
        p_max = max(p_acc[i+k]-p_acc[i], p_max)
    print((p_max+k)/2)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 25152
/*g++ main.cpp -o main.out*/
/*./main.out*/
/*std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);*/

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

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(n,a) memset(n,a,sizeof(n));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

int a[9]={0,1,2,4,8,16,32,64,128};

int main()
{
    int n;
    cin>>n;
    rep(i,9)
    {
        if(a[i]>n)
        {
            cout<<a[i-1]<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a, suma = 0, sumb = 0;
	for (int i = 1; i <= 4; ++i) {
		cin >> a;
		suma += a;
	}
	for (int i = 1; i <= 4; ++i) {
		cin >> a;
		sumb += a;
	}
	cout << ((suma >= sumb) ? suma : sumb) << endl;
	return 0;
}


Measured memory_bytes: 3072
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main(){
    input!{
        cs0: chars,
        cs1: chars,
        cs2: chars,
    }

    let A = cs0[0];
    let B = cs1[0];
    let C = cs2[0];
   
    if (A==B && B!=C) || (B==C && C!=A) || (C==A && A!=B){
        println!("Yes");
    } else {
        println!("No");
    }

}

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

void refull_shuffle(vector<int> &cards) {
  int n = (cards.size()-1) / 2;
  vector<int> next_cards(2*n+1);
  for(int i=1;i<=n;i++) {
    int j = i*2 - 1;
    next_cards[j] = cards[i];
    next_cards[j+1] = cards[n+i];
  }
  cards = next_cards;
  return;
}
void shuffle(vector<int> &cards,int k) {
  int n = (cards.size()-1) / 2;
  vector<int> next_cards(2*n+1);
  int j=1;
  for(int i=k+1;i<=2*n;i++) {
    next_cards[j] = cards[i];
    j++;
  }
  for(int i=1;i<=k;i++) {
    next_cards[j] = cards[i];
    j++;
  }
  cards = next_cards;
  return;
}

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

  int n,m,k;
  cin >> n;
  vector<int> cards(2*n+1);
  for(int i=1;i<=2*n;i++) {
    cards[i] = i;
  }
  cin >> m;
  for(int i=0;i<m;i++) {
    cin >> k;
    if( k == 0 )
      refull_shuffle(cards);
    else
      shuffle(cards,k);
  }
  for(int i=1;i<=2*n;i++) {
    cout << cards[i] << "\n";
  }

}

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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

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

	for( int i=0; i<n-1; i++ )	ans[ a[i]-1 ]++;

	for( int i=0; i<n; i++ )	cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 5196
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i;
  cin>>n;
  vector<string> s(n);
  int ans=n;
  for(i=0;i<n;i++){
    cin>>s.at(i);
  }
  sort(s.begin(),s.end());
  for(i=1;i<n;i++){
    if(s.at(i-1)==s.at(i)){
      ans--;
    }
  }cout<<ans<<endl;
}

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

int main()
{
int n,b,i,a,k=0,m=0,c=0;
cin>>n>>k;
int arr[n+5],brr[n+5]={0};
for(i=1;i<=n;i++)
cin>>arr[i];



for(i=1;i<=k;i++)
{
	cin>>a>>b;
	if(arr[b]<=arr[a])
	{
		brr[b]=-1;
		
	}
	 if(arr[a]<=arr[b])
	{
		brr[a]=-1;
	}
}

for(i=1;i<=n;i++)
{
	if(brr[i]==0)
	c++;
}
cout<<c;

}


Measured memory_bytes: 4388
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])

    if n % 2 != 0:
        return '0'

    ret = 0
    d = 10
    while d <= n:
        ret += n//d
        d *= 5

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 2940
n,d  = gets.chomp.split(" ").map(&:to_i)
array = []

n.times do |i|
  array << gets.chomp.split(" ").map(&:to_i)
end

count = 0
array.each do |a|
  sum = (a[0] ** 2) + (a[1] ** 2)
  if Math.sqrt(sum) <= d
    count += 1
  end
end


puts count


Measured memory_bytes: 28492
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*
    add utility Algorithm
*/

int abcd[50][4];
int N, M, Q;
ll ans = 0;

void dfs(vector<int> v, int cnt, int las) {
    if (cnt == N) {
        ll res = 0;
        REP(Q) {
            if (v[abcd[i][1]] - v[abcd[i][0]] == abcd[i][2]) res += abcd[i][3];
        }
        ans = max(ans, res);
    }
    else {
        REPinit(i, las, M + 1) {
            vector<int> new_v = v;
            new_v.push_back(i);
            dfs(new_v, cnt + 1, i);
        }
    }
}

int main(int argc, char const* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);


    cin >> N >> M >> Q;

    for (int i = 0; i < Q; i++) {
        cin >> abcd[i][0] >> abcd[i][1] >> abcd[i][2] >> abcd[i][3];
        abcd[i][0]--;
        abcd[i][1]--;
    }

    vector<int> v;
    dfs(v, 0, 1);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3600
import numpy as np 

kind, popular = map(int, input().split(" "))
data = np.array(input().split(" "), dtype=np.int)
level = np.sum(data) / (4 * popular)
count = 0
for i in range(kind):
    if data[i] >= level:
        count += 1
        
if count >= popular:
    print("Yes")
else:
    print("No")

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

int dp[100010];
int a[]={1,6,36,216,1296,1296*6,1296*36,1296*216,9,81,729,729*9,729*81};
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<=n;i++)dp[i]=10000000;
	dp[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<13;j++){
			if(i<a[j])continue;
			dp[i]=min(dp[i],dp[i-a[j]]+1);
		}
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 640
N, W = map(int, input().split())
wvs = []
for i in range(N):
  w, v = map(int, input().split())
  wvs.append((w, v))
w0 = wvs[0][0]
vs0 = []
vs1 = []
vs2 = []
vs3 = []
for w, v in wvs:
  if w == w0:
    vs0.append(v)
  if w == w0+1:
    vs1.append(v)
  if w == w0+2:
    vs2.append(v)
  if w == w0+3:
    vs3.append(v)
vs0.sort(reverse=True)
vs1.sort(reverse=True)
vs2.sort(reverse=True)
vs3.sort(reverse=True)
#print(w0, vs0, vs1, vs2, vs3)
rs = [0]
for i0 in range(len(vs0)+1):
  for i1 in range(len(vs1)+1):
    for i2 in range(len(vs2)+1):
      for i3 in range(len(vs3)+1):
        if w0*i0+(w0+1)*i1+(w0+2)*i2+(w0+3)*i3 <= W:
          r = sum(vs0[:i0])+sum(vs1[:i1])+sum(vs2[:i2])+sum(vs3[:i3])
          rs.append(r)
r = max(rs)
print(r)


Measured memory_bytes: 9836
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define fi first
#define se second
using namespace std;

const int mx = 1e5 + 1;

void solve() {
	int n;
	cin>>n;
	cout<<n+(n*n)+(n*n*n)<<"\n";
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3660
#include <iostream>
using namespace std;
int main() {
 
  int k, a, b,c, d;
  cin >> k;
  a = k / 1000;
  b = (k-a*1000) / 100;
  c = (k-a*1000-b*100) / 10;
  d = (k-a*1000-b*100-c*10);
 
  
  if(a == b || b == c || c == d){
    cout << "Bad" <<endl;
  }

   else{ 
	cout << "Good" << endl;}
  }


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
int n, k;
using namespace std;
int main() {
	priority_queue<int>q;	/*生成一个空的优先级数列*/
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) {
		int x;
		scanf("%d", &x);
		q.push(x);
	}
	long long ans = 0;
	for (int i = 1; i <= k; i++) {
		int temp = q.top();
		q.pop();
		temp = temp/2;
		q.push(temp);
	}
	while (!q.empty()) {
		int temp = q.top();
		q.pop();
		ans =ans+ temp;
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 892
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
  int key;
  Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while ( cur != nil && cur->key != key ){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printlist() {
  Node *cur = nil->next;
  int isf = 0;
  while ( 1 ) {
    if ( cur == nil ) break;
    if ( isf++ > 0 ) printf(" ");
    printf("%d", cur->key);
    cur = cur -> next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if ( t == nil ) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x-> prev =nil;
}

int main() {
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ) {
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) { insert(key); np++; size++; }
    else if ( com[0] == 'd' ) {
      if ( strlen(com) > 6 ) {
        if ( com[6] == 'F' ) deleteFirst();
        else if ( com[6] == 'L' ) deleteLast();
      } else {
        deleteKey(key); nd++;
      }
      size--;
    }
  }

  printlist();

  return 0;
}


Measured memory_bytes: 33904
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	priority_queue<int> que;
	rep(i, n) que.push(a[i]);
	int ans = 0;
	while (ans < 100000) {
		int q = que.top(); que.pop();
		if (q + ans < n) {
			cout << ans << endl;
			return 0;
		}
		que.push(q - n - 1);
		ans++;
	}
	int sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	vector<int> b(n);
	rep(i, n) b[i] = a[i] % (n + 1);
	int cnt = 0;
	rep(_, n + 1) {
		bool flag = true;
		int s = 0;
		rep(i, n) {
			if (b[i] == n) flag = false;
			s += b[i];
			b[i] = (b[i] + 1) % (n + 1);
		}
		if (flag) chmax(cnt, s);
	}
	bool check = false;
	sort(all(a)); reverse(all(a));
	if (a[0] >= n * n || a[1] >= n) check = true;
	if (check) cout << max(sum - cnt, 0LL) << endl;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,a[50],sum = 0,ans = 0;
	cin >> n;
	for(int i = 0;i < n;i++) {
		cin >> a[i];
	}
	while(1){
		int ma = -INF,mai;
		for(int i = 0;i < n;i++){
			if(ma < a[i]){
				mai = i;
				ma = a[i];
			}
		}
		if(ma < n) break;
		int cnt = a[mai] / n;
		ans += cnt;
		for(int i = 0;i < n;i++){
			if(mai == i) a[i] %= n;
			else a[i] += cnt;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=1e6+5;
int ans[MAX];
int fastpow(int a,int b,int mod)
{
	int wynik=1;
	while (b)
	{
		if (b&1)wynik=(wynik*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return wynik;
}
string s;
int n;
int getval(int mod)
{
	int akt=0;
	for (int i=0;i<sz(s);i++)
	{
		int pos=sz(s)-i-1;
		if (s[i]=='1')
		akt=(akt+fastpow(2,pos,mod))%mod;
	}
  return akt;
}

int32_t main()
{
  BOOST;
   for (int i=1;i<=1000000;i++)
   {
   	int akt=0,j=i;
   	while (j)j%=__builtin_popcount(j),akt++;
   	ans[i]=akt;
   }
  int jedynki=0;
  int ile0=0,ile2=0;
  
  cin>>n;
  
  cin>>s;
  for (int i=0;i<sz(s);i++) if (s[i]=='1')jedynki++;
  
  if (jedynki==0)
  {
  	for (int i=1;i<=n;i++)cout<<"1\n";
  }
  else if (jedynki==1)
  {
  	int ile=getval(2);
  	for (int i=0;i<sz(s);i++)
  	{
  		int pos=sz(s)-i-1;
  		if (s[i]=='1')cout<<"0\n";
  		else cout<<1LL+ans[(ile+fastpow(2,pos,2))%2]<<"\n";
  	}
  }
  else
  {
  	int ile1=getval(jedynki-1);
  	int ile2=getval(jedynki+1);
  	for (int i=0;i<sz(s);i++)
  	{
  		if (s[i]=='1')
  		{
  			int pos=sz(s)-i-1;
  			int x=jedynki-1;
  			int akt=(ile1-fastpow(2,pos,x)+(x))%x;
  			cout<<1LL+ans[akt]<<"\n";
  		}
  		else
  		{
  			int pos=sz(s)-i-1;
  			int x=jedynki+1;
  			int akt=(ile2+fastpow(2,pos,x)+(x))%x;
  			cout<<1LL+ans[akt]<<"\n";
  		}
  	}
  }
  return 0;
}


Measured memory_bytes: 11592
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

int isp[55556];

void prime_init(int n){
  isp[0] = 1;
  isp[1] = 1;
  for(int i=2;i<n;i++){
    if(isp[i] == 0){
      for(int j=i+i;j<n;j+=i){
        isp[j] = 1;
      }
    }
  }
}

int main(){
  int n;
  cin>>n;
  int cnt = 0;
  vector<int> vs;
  prime_init(55556);
  for(int i=0;i<55556;i++){
    if(isp[i]==0){
      if(i%5==1)vs.push_back(i);
    }
  }
  for(int i=0;i<n;i++)cout<<vs[i]<<" ";cout<<endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.LinkedList;
import java.util.Scanner;



public class Main{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		LinkedList<String> qName = new LinkedList<>();
		LinkedList<Integer> qTime = new LinkedList<>();
		
		int amount = in.nextInt();
		int quantum = in.nextInt();
		for(int i= 0; i < amount; i++) 
		{
			qName.addLast(in.next());
			qTime.addLast(in.nextInt());
		}

		int time = 0;
		while(qName.size() != 0)
		{
			String cName = qName.removeFirst();
			int cTime = qTime.removeFirst();
			if(cTime > quantum)
			{
				time = time + quantum;
				cTime = cTime - quantum;
				
				qName.addLast(cName);
				qTime.addLast(cTime);
			}else
			{
				time = time + cTime;
				System.out.println(cName + " " + time);
			}
		}
	}

	
}


Measured memory_bytes: 75176
#include<stdio.h>

#define MAXLENGTH 100

int main(void)
{
	int i, j, n, m;
	int a[MAXLENGTH][MAXLENGTH], b[MAXLENGTH], c[MAXLENGTH];

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

	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			scanf("%d", &a[i][j]);

	for (j = 0; j < m; j++)
	{
		c[j] = 0;
		scanf("%d", &b[j]);
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			c[i] += a[i][j] * b[j];
		}
		printf("%d\n", c[i]);
	}

}


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

using namespace std;

long long S1[200001], S2[200001], S[200001];
vector <int> D1[200001], D2[200001], T;

int main()
{
    srand(time(0));
    int n, m1, m2, a, b;
    cin >> n >> m1 >> m2;
    int G[n+1];
    map <long long,int> Ma;
    for (int i = 0; i < m1; i++)
    {
        cin >> a >> b;
        D1[a].push_back(b);
        D1[b].push_back(a);
    }
    for (int i = 0; i < m2; i++)
    {
        cin >> a >> b;
        D2[a].push_back(b);
        D2[b].push_back(a);
    }
    for (int i = 0; i <= n; i++)
    {
        G[i] = 1;
    }
    for (int i = 1; i <= n; i++)
    {
        if (G[i] == 1)
        {
            G[i] = 0;
            S1[i] = rand();
            S1[i] *= RAND_MAX;
            S1[i] += rand();
            S1[i] *= RAND_MAX;
            S1[i] += rand();
            T.push_back(i);
            for (int y = 0; y < T.size(); y++)
            {
                a = T[y];
                for (int u = 0; u < D1[a].size(); u++)
                {
                    b = D1[a][u];
                    if (G[b] == 1)
                    {
                        G[b] = 0;
                        S1[b] = S1[i];
                        T.push_back(b);
                    }
                }
            }
            T.clear();
        }
    }
    for (int i = 1; i <= n; i++)
    {
        G[i] = 1;
    }
    for (int i = 1; i <= n; i++)
    {
        if (G[i] == 1)
        {
            G[i] = 0;
            S2[i] = rand();
            S2[i] *= RAND_MAX;
            S2[i] += rand();
            S2[i] *= RAND_MAX;
            S2[i] += rand();
            T.push_back(i);
            for (int y = 0; y < T.size(); y++)
            {
                a = T[y];
                for (int u = 0; u < D2[a].size(); u++)
                {
                    b = D2[a][u];
                    if (G[b] == 1)
                    {
                        G[b] = 0;
                        S2[b] = S2[i];
                        T.push_back(b);
                    }
                }
            }
            T.clear();
        }
    }
    for (int i = 1; i <= n; i++)
    {
        S[i] = S1[i] + S2[i];
        Ma[S[i]]++;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << Ma[S[i]] << " ";
    }
    return 0;
}


Measured memory_bytes: 32120
#include<stdio.h>
int main(){
	int a,b,c,i,n=0;
	scanf("%d%d%d",&a,&b,&c);
	for(i=1;;i++){
		n+=a;
		if(i%7==0)n+=b;
		if(n>=c)break;
	}
	printf("%d\n",i);
	return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    int flag = 0;
    char s[5], t[5];
    gets(s);
    gets(t);
    for(int i = 0; i < 3; i ++ ){
        if(s[i] == t[i]) flag ++ ;
    }
    printf("%d", flag);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ab = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int min = Math.min(x, y);
		int cost = 0;
		if ((a + b) > 2 * ab) {
			cost += ab * min * 2;
			x = x - min;
			y = y - min;
			if (x > y) {
				if (a > ab * 2) {
					cost += ab * 2 * x;
				} else {
					cost += a * x;
				}
			} else {
				if (b > ab * 2) {
					cost += ab * 2 * y;
				} else {
					cost += b * y;
				}
			}
		} else {
			cost += a * x + b * y;
		}
		System.out.println(cost);

	}
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char in[110000];
int main(){
	int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a+b<c+d)printf("Right\n");
	else if(a+b>c+d)printf("Left\n");
	else printf("Balanced\n");
}

Measured memory_bytes: 128