akhauriyash/Code-Regression huggingface dataset:
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

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

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

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n , m;
int type[maxn];
string s;
set < int > adj[maxn][2];
queue < int > q;
set < int > st;

bool bad(int v){
    return(adj[v][0].size() == 0 or adj[v][1].size() == 0);
}

void remove(int v){
    st.erase(v);
    for(auto u : adj[v][0]){
        adj[u][type[v]].erase(v);
        if(st.count(u) and bad(u))
            q.push(u);
    }
    for(auto u : adj[v][1]){
        adj[u][type[v]].erase(v);
        if(st.count(u) and bad(u))
            q.push(u);
    }
}

int32_t main(){
    migmig
    cin >> n >> m;
    cin >> s;
    int cnt = 1;
    for(auto i : s)
        type[cnt++] = (i=='A');
    for(int i = 0 ; i < m ; i ++){
        int u , v;
        cin >> u >> v;
        adj[u][type[v]].insert(v);
        adj[v][type[u]].insert(u);
    }
    for(int i = 1 ; i <= n ; i ++)
        st.insert(i);
    for(int i = 1 ; i <= n;  i ++)
        if(bad(i))
            q.push(i);
    while(q.size()){
        int v = q.front();
        q.pop();
        remove(v);
    }
    cout << (st.size()?"Yes" : "No");
    return(0);
}

Measured memory_bytes: 312556
#include<stdio.h>
#include<stdlib.h>

int main()
{
	int i, j, n, m;
	int kyori;
	int ans;
	int cp;
	int a[50] = {0};
	int b[50] = {0};
	int c[50] = {0};
	int d[50] = {0};
	
	
	scanf("%d %d", &n, &m);
	
	for(i = 0; i < n; i++) {
		scanf("%d %d", &a[i], &b[i]);
	}
	
	for(i = 0; i < m; i++) {
		scanf("%d %d", &c[i], &d[i]);
	}
	
	for(i = 0; i < n; i++) {
	    for(j = 0; j < m; j++) {
	        kyori = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			
	        if(j == 0) {
	            ans = kyori;
				cp = 0;
	        }else if(ans > kyori) {
	            ans = kyori;
	            cp = j;
	        }
	    }
	    cp++;
	    printf("%d\n", cp);
	}
}

Measured memory_bytes: 128
def main():
    W, H, x, y, r = list(map(int, input().split()))
    if 0 <= x - r and x + r <= W and 0 <= y - r and y + r <= H:
        print("Yes")
    else:
        print("No")
    return 0


if __name__ == "__main__":
    main()


Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    ll a[n];
    fill(a, a+n, 0LL);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i != 0) a[i] += a[i-1];
    }

    ll ans = 1e+15;
    for (int i = 0; i < n-1; i++) {
        ans = min(ans, abs(a[n-1] - 2*a[i]));
    }

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

Measured memory_bytes: 1792
#!/usr/bin/python
# -*- Coding: utf-8 -*-

x, y = (int(x) for x in input().split())

c = 4 * x - y
t = y - 2 * x

#print(c,t)
if c % 2 == 0 and t % 2 == 0:
    if c < 0 or t < 0:
        print("No")
    else:
        print("Yes")
else:
    print("No")

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

int H, W;
int cost[10][10];
int A[222][222];
void input() {
  rep(i, 0, 221) {
    rep(j, 0, 221) { A[i][j] = -INF; }
  }

  cin >> H >> W;
  rep(i, 0, 9) {
    rep(j, 0, 9) { cin >> cost[i][j]; }
  }
  rep(i, 1, H){rep(j, 1, W){cin >> A[i][j];
}
}
;
;
}
int dp[10];
void solve() {
  rep(i, 0, 9) dp[i] = INF;
  dp[1] = 0;
  rep(i, 0, 9) {
    ;
    ;
    rep(j, 0, 9) {
      ;
      ;
      rep(k, 0, 9) {
        ;
        ;
        dp[j] = min(dp[j], cost[j][k] + dp[k]);
      }
    }
  };
  ;
  int ans = 0;
  rep(i, 1, H) {
    rep(j, 1, W) {
      if (A[i][j] != -1) {
        ans += dp[A[i][j]];
      }
    }
  }
  cout << ans << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

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


int A,B,C;

int solve(){
	int ans=0;
	if(A+B < C){
		ans = A+2*B+1;
	}else{
		ans = B+C;
	}
	cout << ans << endl;
	return 0;
}


int main(){
	cin >> A >> B >> C;
	solve();
	return 0;
}

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

int main() {

  int K;
  cin >> K;
  
  string S;
  cin >> S;
  
  int length = S.size();
  
  if(length<=K) cout << S << endl;
  
  else {
    
    for(int i = 0; i < K; i++) {
      cout << S.at(i);     
    }
    
    cout << "..." << endl;    
  }
  
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n,C; cin >> n >> C;
    int num[200010] = {};
    vector<vector<pair<int,int> > > data(C);
    rep(i,n){
        int s,t,c; cin >> s >> t >> c;
        data[--c].push_back({s,t});
    }
    rep(i,C)sort(all(data[i]));

    int ans = 0;
    rep(i,C){
        rep(j,data[i].size()){
        int s = data[i][j].first, t = data[i][j].second;
        //同じチャネルで連続する区間があるか
        while(j < data[i].size() - 1 && data[i][j + 1].first == t) {
            t = data[i][++j].second;
        }
        ++num[s * 2 - 1];
        --num[t * 2];
        }
    }
    for(int i = 1; i <= 200000; ++i) {
        num[i] += num[i - 1];
        ans = max(ans, num[i]);
    }
    out(ans);
}


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


int main() {
	
	int64_t N,M;
	cin >> N >> M;
	if (N > M/2) cout << M/2 << endl;
	else cout << N + (M - 2*N) / 4 << endl;
	
	
	return 0;
}

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  vector<ll> csum{0};
  partial_sum(va.begin(), va.end(), back_inserter(csum));

  map<ll, ll> cnts;
  for (int i = 0; i < csum.size(); ++i) {
    cnts[csum[i] % m]++;
  }

  ll ans = 0;
  for (auto &p : cnts) {
    ans += p.second * (p.second - 1) / 2;
  }

  cout << ans << '\n';
}

Measured memory_bytes: 8596
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int i_index;
int tmp;
int main(){
    int K, S;
    cin >> K >> S;
    rep(i, K + 1) rep(j, K + 1){
        tmp = S - i - j;
        if(tmp <= K && i + j <= S && i <= K && j <= K)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
var a,b:longint;
begin
  readln(a,b);
  if a>0 then writeln('Positive')
  else if (a=0)or((a<0)and(b>0)) then writeln('Zero')
  else if ((abs(b)-abs(a))mod 2<>0)then writeln('Positive')
  else writeln('Negative');
end.

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; }
    public static void Main()
    {
        int N = NextInt();
        List<int>[] relate = new List<int>[N];
        for (int i = 0; i < N; i++) relate[i] = new List<int>();
        for (int i = 0; i < N - 1; i++)
        {
            int a = NextInt() - 1;
            int b = NextInt() - 1;
            relate[a].Add(b);
            relate[b].Add(a);
        }
        int[] costA = new int[N];
        int[] costB = new int[N];
        for (int i = 0; i < N; i++) costA[i] = costB[i] = INF;
        costA[0] = costB[N - 1] = 0;
        Queue<int> Q = new Queue<int>();
        Q.Enqueue(0);
        while (Q.Count() != 0)
        {
            int next = Q.Dequeue();
            foreach (var i in relate[next])
            {
                if (costA[i] != INF) continue;
                costA[i] = costA[next] + 1;
                Q.Enqueue(i);
            }
        }
        Q.Enqueue(N - 1);
        while (Q.Count() != 0)
        {
            int next = Q.Dequeue();
            foreach (var i in relate[next])
            {
                if (costB[i] != INF) continue;
                costB[i] = costB[next] + 1;
                Q.Enqueue(i);
            }
        }
        int c1 = 0;
        int c2 = 0;
        for (int i = 0; i < N; i++)
        {
            if (costA[i] > costB[i])
            {
                c2++;
            }
            else c1++;
        }
        Console.WriteLine((c1 > c2 ? "Fennec" : "Snuke"));
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


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

long long fact[1000005];
long long dp[1000005];

const long long MOD = 1e9+7;

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

    long long retainWays = 0;
    fact[0] = 1;
    for(int i = 1; i <= N; i ++){
        fact[i] = fact[i-1]*i%MOD;
        retainWays += fact[i]%MOD;
    }
    retainWays %= MOD;

    //printf("retainWays=%lld\n", retainWays);

    dp[0] = fact[N];
    long long slidingWindowSum = dp[0];
    for(int i = 1; i <= H; i ++){
        dp[i] = slidingWindowSum;

        /*for(int j = 1; j <= min(i, D); j ++){
            dp[i] += dp[i-j];
        }*/

        dp[i] %= MOD;

        if(i == H){break;}

        dp[i] = dp[i]*retainWays%MOD;
        slidingWindowSum += dp[i];
        if(i-D >= 0){
            slidingWindowSum -= dp[i-D];
        }
        slidingWindowSum = (slidingWindowSum+2*MOD)%MOD;

        //printf("dp[%d]=%lld\n", i, dp[i]);
    }

    printf("%lld", dp[H]);
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  vector<int> v(26);
  for (int i = 0; i < n; i++) {
    v[s[i] - 'a']++;
  }

  long long ans = 1;
  for (int i = 0; i < 26; i++) {
    ans = ans * (v[i] + 1) % 1000000007;
  }
  cout << ans - 1 << endl;
}

Measured memory_bytes: 512
def month?(n)
  return n >= 1 && n <= 12
end

s = gets.strip
h = s[0, 2].to_i
l = s[2, 2].to_i

hm = month?(h)
lm = month?(l)

if !hm && lm
  puts 'YYMM'
elsif hm && !lm
  puts 'MMYY'
elsif hm && lm
  puts 'AMBIGUOUS'
else
  puts 'NA'
end


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <stdint.h>
using namespace std;

int main()
{
  string str; cin >> str;
  reverse(str.begin(), str.end());
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 1180
// AtCoder165 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>
#include <ctype.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int revcompare(const void* a, const void* b) {
    return *(int*)b- *(int*)a;
}

double dmax(double x, double y){
    if(x < y) return y;
    return x;
}

int main() {
    int i,j;
    int n;

    double a ,b;
    double h,m;

    scanf("%lf %lf %lf %lf", &a, &b, &h, &m);

    double ans;
    double hdeg = h * 30.0 + (m/60) * 30;
    double mdeg = m / 5.0 * 30.0;
    double deg;

    deg = dmax(hdeg-mdeg, mdeg-hdeg);
    if(deg > 180) deg = 360-deg;

    //printf("hdeg: %f, mdeg:%f, deg:%f\n", hdeg, mdeg, deg);
    if(deg == 180){
        ans = a+b;
    }else if(deg == 0){
        ans = dmax(a-b,b-a);
    }else{
        double rad = deg * 3.141592653589793 / 180;
        ans = (a*a) + (b*b) - (2 * a * b * cos(rad));
        ans = sqrt(ans);
        //printf("%f %f %f\n",a*a, b*b, 2 * a * b * cos(rad));
        //printf("rad:%f\n", rad);
    }

    printf("%.10f", ans);
    return 0;

}

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

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

  int a[n];

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

    if(!(a[i] % 2)){
      if(a[i] % 3 && a[i] % 5){
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }

  cout << "APPROVED" << endl;

  return 0;

}

Measured memory_bytes: 256
import sys

def kensho(x,tlist):
    for lis in tlist:
        if((x>>(lis[1]-1)) & 1 == lis[2]):
            pass
        else:
            return -1

    return bin(x).count('1')


def main():
    N = int(input())
    xy=[]
    ans=0

    for i in range(1,N+1):
        An= int(input())
        for j in range(0,An):
            x, y = map(int, input().split())
            xy.append([i,x,y])

    cnt = N

    tlist=[]
    for x in range (2 ** cnt):
        for y in range(cnt):
            if((x>>y) & 1):
                for z in xy:
                    if(z[0]==y+1):
                        tlist.append(z)

        anstack = kensho(x,tlist)
        if(ans<anstack):
            ans=anstack

        del tlist[:]

    print(ans)

main()

Measured memory_bytes: 43484
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,m,i,j,x,y,suu[100001],flg[100001],sum;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)	{
		suu[i]=1;
		flg[i]=0;
	}
	flg[1]=1;
	for(i=0;i<m;i++)	{
		scanf("%d %d",&x,&y);
		if(suu[x]==1)	{
			if(flg[x]==1)	{
				flg[y]=1;
			}
			flg[x]=0;
			suu[x]--;
			suu[y]++;
		}
		else {
			if(flg[x]==1)	{
				flg[y]=1;
			}
			suu[x]--;
			suu[y]++;
		}
	}
	sum=0;
	for(i=1;i<=n;i++)	{
		if(flg[i]==1)	sum++;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 896
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000

ll n,m,v,i;

ll gcd(ll a,ll b){
  if(b==0) return a;
  else gcd(b,a%b);
}
void solve(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  ll ans = 1;
  rep(i,n){
    cin>>m;
    ans = ans / gcd(ans,m) * m;
  }
  cout<<ans<<endl;

}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int a[n+1],i;
	for (i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	a[n]/=2;
	long long ans;
	ans=0;
	for (i=1;i<=n;i++)
	{
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define em3 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define EPS 1e-7
long long mod = 1e9 +7;
typedef long long ll;
typedef long double ld;
const double pi = acos(-1);
typedef complex <double> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
int n, ans[3];

int main()
{

    em3
    cin >> n;
    int a, b, c;
    cin >> a >> b >> c;
    ans[0] = a;
    ans[1] = b;
    ans[2] = c;
    for(int i = 1 ; i < n ; i++)
    {
        cin >> a >> b >> c;
        int x = ans[0] , y = ans[1] , z = ans[2];
        ans[0] = max(y + a, z + a);
        ans[1] = max(x + b, z + b);
        ans[2] = max(x + c, y + c);

    }
    cout << max(ans[0], max(ans[1], ans[2]));

    return 0;
}



Measured memory_bytes: 256
// Gaurav Nuti
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define ar array
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define INF 1e9 

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

ll power_without_mod(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x); 
        y = y>>1;
        x = (x*x); 
    } 
    return res; 
}

bool comparep(pair<ll, ll> i1, pair<ll, ll> i2){
	return (i1.S < i2.S);
} 

ll modInverse(ll a)
{
    return power(a , mod - 2);
}

vector<vector<ll>> graph;
vector<bool> visited;
vector<ll> dist;
map<ll,ll> mymap;
ll max_dist = 1;

void bfs(int u1){
    visited[u1] = 1;
    dist[u1] = 1;
    mymap[1] = u1;
    queue<ll> q;
    q.push({u1});
    while(!q.empty()){
        ll u = q.front();
        q.pop();
        for(auto i=graph[u].begin();i!=graph[u].end();i++){
            if(!visited[*i]){
                dist[*i] = dist[u] + 1;
                visited[*i] = 1;
                max_dist = max(dist[*i],max_dist);
                mymap[dist[*i]] = *i;
                q.push({*i});
            }
        }
    }
}

// int next_lunlun(ll n){
//     vector<int> digits;
//     while(n){
//         digits.pb(n%10);
//         n /= 10;
//     }
//     // reverse(digits.begin(),digits.end());
//     ll num_digits = digits.size(); 
//     int count_9 = 0;
//     for(int i: digits)
//         if(i == 9)
//             count_9++;
//     if(count_9 == num_digits)
//         return ;
//     for(int i=0;i<(num_digits-1);i++){
//         if(digits)
//     }
// }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif  
	
    ll t;
    // cin>>t;
    t = 1;
    for(ll z=0;z<t;z++){
        ll n, w;
        cin>>n>>w;
        ar<ll,2> wv[n];
        for(ll i = 0;i<n;i++){
            cin>>wv[i][0]>>wv[i][1];
        }
        ll dp[n+1][w+1];
        for(ll i=0;i<=n;i++){
            for(ll j=0;j<=w;j++){
                if(i == 0 || j == 0){
                    dp[i][j] = 0;
                    continue;
                }
                dp[i][j] = dp[i-1][j];
                if(wv[i-1][0] <= j)
                    dp[i][j] = max(dp[i][j], dp[i-1][j-wv[i-1][0]]
                        + wv[i-1][1]);
            }
        }
        cout<<dp[n][w];
    }
}

Measured memory_bytes: 82460
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int d[3],K;
    R(d[0],d[1],d[2],K);
    VL AA[3];
    REP(i,3){
        REP(j,d[i]){
            LL v;
            R(v);
            AA[i].PB(v);
        }
        sort(ALL(AA[i]),greater<LL>());
    }
    priority_queue<pair<LL,int>>h;
    REP(i,d[0])REP(j,d[1]){
        h.push(MP(AA[0][i]+AA[1][j]+AA[2][0],0));
    }
    while(K){
        K--;
        auto now=h.top(); h.pop();
        W(now.F);
        if(now.S+1<d[2]){
            now.F+=AA[2][now.S+1]-AA[2][now.S];
            now.S++;
            h.push(now);
        }
    }
    return 0;
}


Measured memory_bytes: 18804
N = int(input())
s = [input() for _ in range(N)]

Dict = {} # 空の辞書を用意(集合ともみれるが)
ans = 0

for i in range(N):
    s[i] = ''.join(sorted(s[i])) # 文字列をソートすると配列になる
    if s[i] in Dict:
        ans += Dict[s[i]] # あったら過去にあった個数をansに代入
        Dict[s[i]] += 1 # 値に1追加
    else:
        Dict[s[i]] = 1 # なかったら辞書にキー(文字列)と値1を格納

print(ans)

Measured memory_bytes: 19472
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  divisors.sort()
  return divisors

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

L=[]
for k in K:
  if k*N<=M:
    L.append(k)
print(max(L))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int p[2],point[2]={};
        cin>>p[0]>>point[0]>>point[1];
        point[0]+=point[1];
        for(int i=0;i<n-1;i++){
            point[1]=0;
            cin>>p[1];
            for(int j=0,num;j<2;j++){
                cin>>num;
                point[1]+=num;
            }
            if(point[0]<point[1]){
                p[0]=p[1];
                point[0]=point[1];
            }
        }
        cout<<p[0]<<" "<<point[0]<<endl;
    }
}

Measured memory_bytes: 1160
def euclid(a, b)
  if a%b == 0 || b%a == 0
    return [a, b].min
  end
  a, b = b, a if a < b
  euclid(a - b*(a/b), b)
end

while nums = gets do
  a, b = nums.split.map(&:to_i)
  puts euclid(a, b)
end

Measured memory_bytes: 6096
#include <iostream>
using namespace std;
bool check(int i, int A, int B);
int main()
{
    int N,A,B;
    cin >> N >> A >> B;
    int sum = 0;
    for(int i=1; i<=N; i++)
    {
    	if(check(i,A,B)) sum+= i;
    }
    cout << sum << endl;
	return 0;
}
bool check(int x, int A, int B)
{
	int d[5];
	int y = 10000;
	for(int i=0; i<5; i++)
	{
        d[i] = x/y; 
        x -= d[i]*y;
        y /= 10;
	}
	int S = 0;
	for(int i=0; i<5; i++)
	{
		S += d[i];
	}
	if(A<=S && S<= B) return true;
	else return false;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        LinkedList<Integer> res = new LinkedList<>();
        boolean atEnd = true;
        for(int i=0;i<n;i++){
            if(atEnd) res.addLast(a[i]);
            else res.addFirst(a[i]);
            atEnd = !atEnd;
        }
        if(n%2==1){
            while(res.size()>0){
                System.out.print(res.removeLast());
                System.out.print(" ");
            }
        }
        else{
            while(res.size()>0){
                System.out.print(res.poll());
                System.out.print(" ");
            }
        }
    }
}
 

Measured memory_bytes: 97020
#include<stdio.h>
int main(){
int a,i,max,min,b;
long sum;
	scanf("%d\n",&a);
	for(i=0,sum = 0;i<a;i++){
		scanf("%d ",&b);
		if(i==0){max=min=b;}
		else{
			if(max<b){max = b;}
			if(min>b){min = b;}
		}
		sum += b;
	}
	printf("%d %d %ld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 604
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    ll a;
    const ll MOD=1e9+7;
    modint(ll a_=0){
        a=((a_%MOD)+MOD)%MOD;
    }
    modint inv()const{
        ll n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y(a+x.a);
        return y;
    }
    modint operator-(const modint& x){
        modint y(a-x.a);
        return y;
    }
    modint operator*(const modint& x){
        modint y(a*x.a);
        return y;
    }
    modint operator/(const modint& x){
        return *this * x.inv();
    }
    modint& operator+=(const modint& x){
        *this=*this+x;
        return *this;
    }
    modint& operator-=(const modint& x){
        *this=*this-x;
        return *this;
    }
    modint& operator*=(const modint& x){
        *this=*this*x;
        return *this;
    }
    modint& operator/=(const modint& x){
        *this=*this/x;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    ll a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(ll a,ll b){
    modint n(1),A(a);
    while(b){
        if(b&1) n*=A;
        A*=A;
        b>>=1;
    }
    return n;
}

class FSmallProducts {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,k,m;
        in>>n>>k;
        m=(int)sqrt(n);
        vector<modint> c(2*m),s(2*m+1),ns(2*m+1);
        fr(i,m) c[i]=1,c[i+m]=n/(m-i)-n/(m-i+1);
        if(n/m==m) c[m]-=1;
        s[0]=1;
        fr(_,k){
            ifr(i,2*m) ns[i]=ns[i+1]+(s[0]-s[2*m-i])*c[i];
            s.swap(ns);
        }
        out<<s[0]<<endl;
    }
};

int main() {
    FSmallProducts solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

int main(){
  string s;
  cin>>s;
  long long a=0;
  for(int i=0;i<int(s.size());i++){
    char c;
    c=s[i];
    a+=c-'0';
  }
  if(a%9==0) cout<<"Yes";
  else cout<<"No";
}
  

Measured memory_bytes: 3748
import java.util.Scanner;

public class Main
{
	private static final int[] D = { 1, 0, -1, 0 };
	
	private static int W, H;
	
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		for(;;)
		{
			W = sc.nextInt();
			H = sc.nextInt();
			if (W==0 && H==0) break;
			
			boolean[][] red = new boolean[W][H];
			int sx = -1, sy = -1;
			for (int y = 0; y < H; y++)
			{
				String line = sc.next();
				for (int x = 0; x < W; x++)
				{
					char c = line.charAt(x);
					switch (c)
					{
					case '#':
						red[x][y] = true;
						break;
					case '@':
						sx = x;
						sy = y;
						break;
					}
				}
			}
			System.out.println(dfs(red, sx, sy));
		}
	}
	
	private static boolean valid(int x, int y)
	{
		return 0 <= x && x < W && 0 <= y && y < H;
	}
	
	private static int dfs(boolean[][] red, int sx, int sy)
	{
		red[sx][sy] = true;
		
		int count = 1;
		for (int i = 0; i < 4; i++)
		{
			int x = sx + D[i];
			int y = sy + D[(i + 1) % 4];
			if (valid(x, y) && !red[x][y])
			{
				count += dfs(red, x, y);
			}
		}
		return count;
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

ll h[100000];

int main(void){
    ll n, k; cin >> n >> k; for(int i = 0;i < n;i++)cin >> h[i];
    ll ans = INF;
    sort(h, h + n);
    for(int i = 0;i <= n-k;i++)ans = min(ans, h[i+k-1]-h[i]);
    cout << ans << endl;
	return 0;
}

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

#define int long long
#define PB push_back
#define PPB pop_back
#define ALL(X) (X).begin(),(X).end()
typedef pair<int, int> pii;

static const int INF = 1LL << 61;
static const int MAX_N = 100005;

int n, a[MAX_N];

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

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

    int temp = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] == 0) {
            ans += temp / 2;
            temp = 0;
            continue;
        }
        temp += a[i];
    }
    ans += temp / 2;

    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		boolean f = false;
		for(int i = 1; i <= b; i++) {
			if((a * i) % b == c) {
				f = true;
				break;
			}
		}
      
		if(f == false) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
	}
}

Measured memory_bytes: 23124
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e12+1);
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	int a,b,c,ans=0;cin>>a>>b>>c;
	for(int i=a;i<=b;i++){
		if(c%i==0){ans++;}
	}
	cout<<ans<<endl;
	RE;
}


Measured memory_bytes: 3104
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<a[k-1];	

	return 0;
}

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

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 2e5 + 100;

int N, Nr[MAX_N], Cnt[MAX_N];
int impos() {puts("Impossible"); return 0;}
int main() {
	cin >> N;
	REP(i, N) scanf("%d", &Nr[i]), Cnt[Nr[i]]++;
	int maxV = -1, minV = N+1;
	REP(i, N) maxV = max(maxV, Nr[i]), minV = min(minV, Nr[i]);
	if(minV != (maxV + 1) / 2 || Cnt[minV] > 2) return impos();
	if(maxV % 2 == 0 && Cnt[minV] == 2) return impos();
	if(maxV % 2 == 1 && Cnt[minV] == 1) return impos();
	for(int i=minV+1; i<=maxV; i++) if(Cnt[i] < 2) return impos();
	puts("Possible");
	return 0;
}



Measured memory_bytes: 256
//AtCoder ABC047 A - キャンディーと2人の子供 / Fighting over Candies
#include <bits/stdc++.h>
using namespace std;
using lli=int64_t;

int main() {
    vector<int> abc(3);
    for(auto&& d:abc){
        cin>>d;
    }
    sort(abc.begin(),abc.end(), greater<int>());
    cout<<(abc[0]==abc[1]+abc[2]?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <algorithm> 
#include <cstring> 
#include <cstdio>
#include <vector> 
#include <queue> 
#include <cstdlib> 
#include <iomanip>
#include <cmath> 
#include <ctime> 
#include <map> 
#include <set> 
using namespace std; 
#define lowbit(x) (x&(-x)) 
#define max(x,y) (x>y?x:y) 
#define min(x,y) (x<y?x:y) 
#define MAX 100000000000000000 
#define MOD 1000000007
#define pi acos(-1.0) 
#define ei exp(1) 
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f3f 
#define mem(a) (memset(a,0,sizeof(a))) 
typedef long long ll;
ll n,k,x,m;
priority_queue<ll>q;
int main()
{
    ios();
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&x);
        q.push(x);
    }
    k=0;
    while(q.top()+k>=n)
    {
        ll ans=q.top()+k;
        q.pop();
        m=ans/n;
        ans-=m*n;
        k+=m;
        q.push(ans-k);
    }
    printf("%lld\n",k);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int digit_sum(int n) {
    int ret = 0;
    while(n > 0) {
        ret += n%10;
        n /= 10;
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    int s = digit_sum(n);
    if(n%s == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define int long long

const int N = 1e5 + 5;

int A[N], n, T, E, dp[N];

int calc(int x, int y) {
	if(y == x + 1) return dp[x] + A[y] - A[x] + T;
	else return dp[x] + A[x + 1] - A[x] + (A[y] - A[x + 1]) * 3 + max(0LL, T - (A[y] - A[x + 1]) * 2);
}

multiset <int> C, D;

main() {
	cin >> n >> E >> T;
	for(int i = 1; i <= n; ++ i) scanf("%lld", &A[i]);
	int ans = 1e18, res = 0;
	dp[0] = 0;
	int cur = 0, cnt = 1000;
	int now = 0;
	C.insert(dp[0] - A[0] + T);
	for(int i = 1; i <= n; ++ i) {
		dp[i] = 1e18;
		while((A[i] - A[now + 1]) * 2 >= T && now < i) {
			C.erase(C.find(dp[now] - A[now] + T));
			D.insert((dp[now] - A[now + 1] * 2 - A[now])); 
			++ now;
		}

		if(C.size()) dp[i] = min(dp[i], *C.begin() + A[i]);
		if(D.size()) dp[i] = min(dp[i], *D.begin() + A[i] * 3);

		C.insert(dp[i] - A[i] + T);
		dp[i] = min(dp[i], calc(i - 1, i));
	}
	cout << dp[n] + E - A[n] << endl;
}

Measured memory_bytes: 10016
#include<cstdio>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int sum=0;
    int m;
    for(int i = 0;i < n; i++){
        scanf("%d",&m);
        sum += m/n;
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 1020
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int A,B,C,D,E,F;
int main() {
	cin>>A>>B>>C>>D>>E>>F;

	int S,T;
	int M=A;
	if(B<M)M=B;
	if(C<M)M=C;
	if(D<M)M=D;
	S=A+B+C+D-M;
	int N=E;
	if(F<N)N=F;
	T=E+F-N;
	cout<<S+T<<endl;


	return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define MOD 1000000007

int pow(int n, int x){
   if(x == 0)
     return 1;
   if(x == 1)
     return n;
   int power = pow(n, x / 2);
   if(x % 2 == 0)
     return ((power % MOD) * (power % MOD)) % MOD;
   else
     return ((n % MOD) * (power % MOD) * (power % MOD)) % MOD;
}

int32_t main(){
    int n;
    cin >> n;
    vector<int> p, q;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        p.push_back(a+b);
        q.push_back(a-b);
    }
    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    cout << max(p[n-1] - p[0], q[n-1] - q[0]);
}

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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  
  L = A + B;
  R = C + D;
  if ( L > R ) {
    cout << "Left" << endl;
  }else if ( L == R ) {
  	cout << "Balanced" << endl;
  }else {
  	cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
//ABC111-999
#include<stdio.h>

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

	for(int i=0;i<3;i++){
		if(n%10 == 9){
			answer += 1000;
		}else{
			answer += 9000;
		}
		answer /=10;
		n /= 10;
	}

	printf("%d\n",answer);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)
#define all(a) a.begin(), a.end()
#define gr greater<LL>()

using namespace std;

void solve(long long K, long long X){
    LL a = max(X-K+1, -1000000LL);
    LL b = min(X+K-1, 1000000LL);
    for(LL i=a; i<=b; i++)
        cout << i << " ";
    cout << endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    long long X;
    scanf("%lld",&X);
    solve(K, X);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, i;
    int* arr;
    scanf("%d", &n);
    arr = (int*)malloc(sizeof(int) * n);
    for (i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }
    for (i = n - 1; i >= 0; i--) {
        printf("%d", arr[i]);
        if (i) printf(" ");
    }
    printf("\n");
    free(arr);

    return 0;
}


Measured memory_bytes: 2104
#![allow(unused_imports, non_snake_case)]

use std::io::*;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::str::FromStr;

const MOD: i32 = 1_000_000_007;

macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, m) = get!(i64, i64);
    if (n - m).abs() > 1 {
        println!("0");
        return
    } else {
        let mut fact: Vec<i64> = vec![1; 100001];
        for i in 1..fact.len() {
            let j = i as i64;
            fact[i] = (fact[i - 1] * j) % (MOD as i64);
        }
        let mut ans = (fact[n as usize] * fact[m as usize]) % (MOD as i64);
        if n == m {
            ans = ans * 2 % (MOD as i64);
        }
        println!("{}", ans);
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

using pi = pair<int,int>;
struct second_greater{
    bool operator()(const pi a, const pi b){ return a.second > b.second; }
};

int main()
{
    int d;
    cin >> d;
    if(d == 25)
        cout << "Christmas" << endl;
    else if(d == 24)
        cout << "Christmas Eve" << endl;
    else if(d == 23)
        cout << "Christmas Eve Eve" << endl;
    else
        cout << "Christmas Eve Eve Eve" << endl;

    return 0;
}

Measured memory_bytes: 256