akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;



const double PI = asinl(1) * 2;
struct Point{
  double x,y;
  Point(){}
  Point(double x,double y) :x(x),y(y){}
  Point operator + (Point p) {return Point(x+p.x,y+p.y);}
  Point operator - (Point p) {return Point(x-p.x,y-p.y);}
  Point operator * (double k) {return Point(x*k,y*k);}
  Point operator / (double k) {return Point(x/k,y/k);}
  double norm(){return x*x+y*y;}
  double abs(){return sqrt(norm());}

  bool operator < (const Point &p) const{
    return x!=p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const{
    return fabs(x-p.x) < (1e-10) && fabs(y-p.y) < (1e-10);
  }
};
typedef Point Vector;
typedef vector<Point> Polygon;

struct Segment{
  Point p1,p2;
  Segment(){}
  Segment(Point p1, Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

struct Circle{
  Point c;
  double r;
  Circle(Point c,double r):c(c),r(r){}
};

double norm(Vector a){
  return a.x*a.x+a.y*a.y;
}
double abs(Vector a){
  return sqrt(norm(a));
}
double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}

bool isOrthogonal(Vector a,Vector b){
  return (fabs((dot(a,b))-(0.0)) < (1e-10));
}

bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
  return isOrthogonal(a1-a2,b1-b2);
}

bool isOrthogonal(Segment s1,Segment s2){
  return (fabs((dot(s1.p2-s1.p1,s2.p2-s2.p1))-(0.0)) < (1e-10));
}

bool isParallel(Vector a,Vector b){
  return (fabs((cross(a,b))-(0.0)) < (1e-10));
}

bool isParallel(Point a1,Point a2,Point b1,Point b2){
  return isParallel(a1-a2,b1-b2);
}

bool isParallel(Segment s1,Segment s2){
  return (fabs((cross(s1.p2-s1.p1,s2.p2-s2.p1))-(0.0)) < (1e-10));
}

Point project(Segment s,Point p){
  Vector base = s.p2 - s.p1;
  double r = dot(p-s.p1,base)/norm(base);
  return s.p1 + base * r;
}

Point reflect(Segment s,Point p){
  return p+ (project(s,p)-p)*2.0;
}


int main(){
    Point p1,p2;
    cin >> p1.x >> p1.y >> p2.x >> p2.y;
    int q;cin >> q;
    Segment s = Segment(p1,p2);
    cout << fixed;
    cout << setprecision(8);
    for(int i=0;i<q;i++){
        Point p;cin >> p.x >> p.y;
        cout << reflect(s,p).x << " " << reflect(s,p).y << endl;
    }
}


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

        #define ll long long
        #define pb push_back
        #define printV(v) for(int i=0;i<(int)v.size();i++){cout << v[i]<< " ";} cout << endl
        #define printRev(v) for(int i=(int)v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
        #define sortV(v) sort(v.begin(),v.end())
        #define revV(v) reverse(v.begin(),v.end())
    

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;

       
        
        void solve(){
            cin >> n;
            vector<ll> v(n);
            for(int i=0;i<n;i++) cin >> v[i];
            sortV(v);
            int cnt = 0;
            for(int i=0; i < n;i++){
                for(int j=i+1; j < n; j++){
                    if(v[i] == v[j]) continue;
                    for(int k = j+1; k < n; k++){
                        if(v[k] == v[j]) continue;
                        if(v[i] + v[j] > v[k]) cnt++;
                    }
                }
            }
            cout << cnt << endl;

        }



        int main(){
            ios_base::sync_with_stdio(false);

            

          
            int cases = 1;
            //cin >> cases;

            while(cases--) solve();
            return 0;

        }

Measured memory_bytes: 3656
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
v = na()
c = na()

k = [v[i]-c[i] for i in range(n)]

a=0
for j in k:
    if j >0:
        a+=j
print(a)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); ++i)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */


template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight; //親との差分

    UnionFind(int n = 1, Abel SUM_UNITY = 0){
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0){
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for(int i=0; i<n; i++) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x){
        if(par[x] == x){
            return x;
        }
        else{
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x){
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    // weight[y] - weight[x] = w になるようにマージする（x yがそれぞれの木でrootになってるわけではないことに注意）
    bool merge(int x, int y, Abel w){
        // xとyそれぞれについて、rootとの重み差分を補正
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y), w = -w;
        if(rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y){
        return weight(y) - weight(x);
    }
};

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

    int n, m; cin >> n >> m;
    UnionFind<int> uni(n);

    rep(i, m){
        int l, r, d; cin >> l >> r >> d;
        --l, --r;
        if(uni.issame(l, r) && uni.diff(l, r) != d){
            cout << "No\n";
            return 0;
        }
        else if(!uni.issame(l, r)){
            uni.merge(l, r, d);
        }
    }
    cout << "Yes\n";

	return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

int main(void) {
	int a,b;
	int end=0;
	char op;
	

	
	while(end != 1){
		scanf("%d",&a);
		scanf(" %c",&op);	
		scanf(" %d",&b);
		switch(op){
		
			case '+':
				printf("%d\n",a+b);
				break;
			case '-':
				printf("%d\n",a-b);
				break;
			
			case '/':
				printf("%d\n",a/b);
				break;
			
			case '*':
				printf("%d\n",a*b);
				break;
			case '?':
				end = 1;

				break;
			default:
				break;
				
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N, K; cin >> N >> K;
    int a[110]; rep(i, N) cin >> a[i];
    ll dp[110][100100], sum[110][100100];
    rep(j, K + 1) {
        if(j <= a[0]) dp[0][j] = 1LL;
        else dp[0][j] = 0;
        sum[0][j + 1] = sum[0][j] + dp[0][j];
    }
    rep1(i, N - 1) {
        rep(j, K + 1) {
            dp[i][j] = (sum[i - 1][j + 1] - sum[i - 1][max(0, j - a[i])] + mod) % mod;
            sum[i][j + 1] = (sum[i][j] + dp[i][j]) % mod;
        }
    }
    cout << dp[N - 1][K] << endl;
	return 0;
}

Measured memory_bytes: 159872
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
    int N;
    cin >> N;
    vector<int> values(N);
    vector<int> costs(N);
    vector<int> profits(N);
    for (int i = 0; i < N; i++) cin >> values[i];
    for (int i = 0; i < N; i++) cin >> costs[i];
    for (int i = 0; i < N; i++) profits[i] = values[i] - costs[i];
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (profits[i] > 0) ans += profits[i];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int a,b,k;
    int menor,cont = 0;
    int res;
    cin >> a >> b >> k;
    if(a > b)
    {
        menor = b;
    }
    else
    {
        menor = a;
    }
    for (int i = menor ; i >= 0 ; i--)
    {
        if(cont >= k)
        {
            cout << res << endl;
            break;
        }
        if(a%i == 0 && b%i == 0 && cont <= k)
        {
            res = i;
            cont ++;
        }
    }
    return 0;
}

Measured memory_bytes: 256
n,W=map(int,input().split())
v=[]
w=[]
for i in range(n):
    val,wei=map(int,input().split())
    v.append(val)
    w.append(wei)

dp=[-1]*(W+1)
dp[0]=0
for i in range(n):
    for j in range(W+1):
        if dp[j]!=-1 and j+w[i]<W+1:
            dp[j+w[i]]=max(dp[j]+v[i],dp[j+w[i]])

print(max(dp))



Measured memory_bytes: 5920
N = int(input())
words = [input() for _ in range(N)]

for i, w in enumerate(words):
    if i == 0:
        continue
    if words.count(w) > 1:
        print('No')
        break
    if w[0] != words[i - 1][-1]:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    vector<double> v(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    sort(ALL(v));

    double current = v[0];
    FOR(i, 1, n) {
        current = (current + v[i]) / 2;
    }
    printf("%.12f\n", current);
    
    return 0;
}

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

main(){
	long long l,r;
	int ans;
	ans = 20200000;
	cin>>l>>r;
	if(r - l > 2017){
		cout<<0<<endl;
		return 0;
	}
	for(long long i=l;i<r;i++){
		for(long long j=i+1;j<=r;j++){
			if((i*j)%2019 < ans)
				ans = (i*j)%2019;
		}
	}	
	cout<<ans<<endl;
}

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

int main(){
	int sx, sy, tx, ty;

	cin >> sx >> sy >> tx >> ty;
	string a[4];
	int x, y;
	
	for(y=sy; y<ty; y++){
		a[0] += 'U';
	}
	for(y=sy; y>ty; y--){
		a[0] += 'D';
	}
	for(x=sx; x<tx; x++){
		a[0] += 'R';
	}
	for(x=sx; x>tx; x--){
		a[0] += 'L';
	}

	int i;
	for(i=0; i<a[0].size(); i++){
		if(a[0][i]=='U') a[1]+='D';
		if(a[0][i]=='D') a[1]+='U';
		if(a[0][i]=='L') a[1]+='R';
		if(a[0][i]=='R') a[1]+='L';
	}
	a[2]+="LU";
	a[2]+=a[0];
	a[2]+="RD";

	a[3]+="RD";
	a[3]+=a[1];
	a[3]+="LU";

	cout << a[0] << a[1] << a[2] << a[3] << endl;

	return 0;
}

Measured memory_bytes: 256
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
if v <= w:
    print("NO")
else:
    dis = abs(b-a)
    sp = abs(v-w)
    if 0 < dis/sp <= t:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9168
#include <stdio.h>

int main(){
  int i,t,n,money[4]={6000,4000,3000,2000};

  for(i=0;i<4;i++){
    scanf("%d %d",&t,&n);
    if(t==1) printf("%d\n",money[0]*n);
    else if(t==2) printf("%d\n",money[1]*n);
    else if(t==3) printf("%d\n",money[2]*n);
    else if(t==4) printf("%d\n",money[3]*n);
  }
  return 0;
}

Measured memory_bytes: 600
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll
//#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
template<class T> inline bool chmax(T & x, T const & y){ return x<y ? x=y,true : false; }
template<class T> inline bool chmin(T & x, T const & y){ return x>y ? x=y,true : false; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif
// ll const mod = 1000000007;
// ll const inf = 1LL<<60;

int main(){
    int a[] = {1,5,10,50,100,500};
    int x = 0;
    rep(i,6){
        int y;
        cin >> y;
        x += y*a[i];
    }
    cout << (x>=1000) << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=200005;
int v[Maxn],prt[Maxn],fa[Maxn],cnt[Maxn][2],tag[Maxn];
ll ans;
struct node{
    int cnt[2],id,tag;
    node(int cnt0,int cnt1,int _id,int _tag){
        cnt[0]=cnt0;cnt[1]=cnt1;id=_id;tag=_tag;
    }
    bool operator<(const node&rhs)const{
        return 1ll*cnt[0]*rhs.cnt[1]<1ll*cnt[1]*rhs.cnt[0];
    }
};
inline int Getfa(int x){return fa[x]=(fa[x]==x?x:Getfa(fa[x]));}
int main(){
    int n;scanf("%d",&n);
    for(int i=2;i<=n;i++)scanf("%d",&prt[i]);
    for(int i=1;i<=n;i++)scanf("%d",&v[i]),fa[i]=i,cnt[i][v[i]]++;
    priority_queue<node>Q;
    for(int i=1;i<=n;i++)Q.push(node(v[i]==0,v[i]==1,i,0));
    while(Q.size()){
        static int ts;
        node o=Q.top();Q.pop();
        int x=Getfa(o.id),y=Getfa(prt[x]);
        if(x==1||o.tag!=tag[x])continue;
        ans+=1ll*cnt[y][1]*cnt[x][0];
        cnt[y][0]+=cnt[x][0];
        cnt[y][1]+=cnt[x][1];
        fa[x]=y;tag[y]=++ts;
        Q.push(node(cnt[y][0],cnt[y][1],y,tag[y]));
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 10352
def resolve():
    n, t = map(int, input().split())
    a = list(map(int, input().split()))
    ans = t * n
    for i in range(1, n):
        if a[i - 1] + t > a[i]:
            ans -= a[i - 1] + t - a[i]
    print(ans)


if __name__ == "__main__":
    resolve()


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

int main() {

	/*
	H�̓����X�^�[�̗̑́B
	N�̓A���C�O�}�̕K�E�Z�̎�ށB
	*/
	int H, N;

	cin >> H >> N;

	for (int i = 0; i < N; i++) {
		/*
		for���̍ŏ���int A ���쐬���āA�����cin>>A ���邱�ƂŁA
		�z����g�킸�� H �ɑ�����邱�Ƃ��ł���B
		int A �͖���for���̍ŏ��ɍč쐬(������)�����B
		*/
		int A;

		cin >> A;

		H -= A;
	}

	if (H <= 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdint>
using namespace std;
 
const int MAX = 200000;
int main() {
	static int N, A[MAX];
	cin >> N;
	for (int i = 0;i < N;i ++) cin >> A[i];
	
	static int64_t sum[MAX + 1]; // 累積和
	sum[0] = 0;
	for (int i = 0;i < N;i ++) sum[i + 1] = A[i] + sum[i];
	sort(sum, sum+N+1);
	int64_t ans = 0;
	int num = 1;
	for (int i = 1;i <= N;i ++) {
		if (sum[i] == sum[i - 1]) num ++; // 累積和が同値になるものの個数
		else {
			ans += (int64_t)num * (num - 1) / 2; // 総和が0になる区間の数
			num = 1;
		}
	}
	ans += (int64_t)num * (num - 1) / 2;
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
 
まず、連続する～と総和～と来た場合は累積和を作りましょう。それで大きく話が変わるから。
ここで、1からxの区間の総和をsum[x]とするよ
この時、ある区間i～jの総和が0であることは、sum[j]-sum[i+1]=0、つまりsum[j]=sum[i+1]と言えるよね
つまり、sum[x]が同値になるようなx同士でしか総和は0にならないし、逆に同値になるようなx同士から任意の2個を選んで良い訳だ
ここで、もしk個が同値になるとして、その中から2個を選ぶ方法はk(k-1)/2通りあるよ
後は一度ソートしておくと左から順に確認できるので、O(NlogN)で解けるよ
*/

Measured memory_bytes: 2560
# AGC018A - Getting Difference
from fractions import gcd
from functools import reduce


def main():
    n, k = tuple(map(int, input().rstrip().split()))
    A = tuple(map(int, input().rstrip().split()))
    G, M = reduce(gcd, A), max(A)  # gcd, max of A
    flg = k <= M and k % G == 0
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Measured memory_bytes: 16224
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int r,g,b,n;
  cin>>r>>g>>b>>n;
  Int ans=0;
  for(Int i=0;i<=n;i++){
    for(Int j=0;j<=n;j++){
      Int k=(n-(r*i+g*j))/b;
      if(0<=k&&k<=n)
        if((r*i+g*j+b*k)==n) ans++;      
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
	
	int n,r,p,c;
	
	while(1){
	cin>>n>>r;
	if(n==0&&r==0)return 0;
	int ca[50],d[50];
	for(int i=0;i<n;i++){ca[i]=n-i;d[i]=0;}
	
	for(int i=0;i<r;i++){
		cin>>p>>c;
		for(int j=0;j<p-1;j++)d[j]=ca[j];
		for(int j=0;j<c;j++)ca[j]=ca[p-1+j];
		for(int j=0;j<p-1;j++)ca[c+j]=d[j];
	}
	cout<<ca[0]<<endl;
	}
}

Measured memory_bytes: 0
import Control.Applicative ((<$>))
import Control.Monad (unless)
import Data.List (unfoldr)

main :: IO ()
main = do
  a <- readLn
  unless (a == 0) $ do
    solve a >>= print
    main

solve :: Int -> IO Int
solve = return . foldr f 0 . unfoldr g
  where g x | x == 0 = Nothing
            | otherwise = let (q, r) = divMod x 10 in Just (r, negate q)
        f x y = x + 10 * y



Measured memory_bytes: 4144
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    // 入力
    long int N;
    cin >> N;
    vector<long int> d;
    long int d_tmp;
    for (long int i = 0; i < N; i++) {
        cin >> d_tmp;
        d.push_back(d_tmp);
    }

    sort(d.begin(), d.end());

    long int K;
    long int count = 0;
    long int end = static_cast<long int>( d[d.size()-1]);
    for (long int i = 0; i <= end; i++) {
        K = i;
        if (d[N / 2 - 1] <= K && d[N / 2] > K) {
            count++;
        }
    }
    // cout << d[N / 2 - 1] << " " << d[N / 2] << " " << end;
    cout << count << endl;

}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
vector<int> divisor(int n){
  vector<int> ret;
  for(int i = 1;i*i <= n;i++){
    if(n % i == 0){
      ret.push_back(i);
      if(n/i != i)ret.push_back(n/i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
map<int, int> prime_factor(int n){
  map<int, int> ret;
  for(int i = 2;i*i <= n;i++){
    while(n % i == 0){
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1){
    ret[n] = 1;
  }
  return ret;
}
////////////////////////////////////////////////////////////////////

int n,a[60], b[60];
signed main(){
  cin>>n;rep(i,n)cin>>a[i];
  int ans = 0;
  while(true){
    int sum = 0, m = 0;
    rep(i,n){
      b[i] = a[i]/n;
      ans += b[i];
      sum += b[i];
    }
    rep(i,n){
      a[i] = (a[i]%n) + sum - b[i];
      chmax(m, a[i]);
    }
    if(m < n)break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] s = new String[n];

    for (int i = 0; i < n; i++) {
      s[i] = sc.next();
    }

    int a = 0;
    int w = 0;
    int t = 0;
    int r = 0;

    for (int i = 0; i < n; i++) {
      if (s[i].equals("AC")) {
        a++;
      }
      if (s[i].equals("WA")) {
        w++;
      }
      if (s[i].equals("TLE")) {
        t++;
      }
      if (s[i].equals("RE")) {
        r++;
      }
    }

    System.out.println("AC x "+a);
    System.out.println("WA x "+w);
    System.out.println("TLE x "+t);
    System.out.println("RE x "+r);

  }

}


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

int main() {
  int N;
  cin >> N;
  
  int longest = 0;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int L;
    cin >> L;
    if (longest < L) longest = L;
    sum += L;
  }
  if (sum > 2 * longest) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt()-1;
        String S = sc.next();
        char[] C = S.toCharArray();
        char targetChar = C[K];

        String targetString = String.valueOf(targetChar);
        targetString = targetString.toLowerCase();

        char[] tmp = targetString.toCharArray();
        C[K] = tmp[0];

        for (char c : C) {
            System.out.print(c);
        }
    }
}


Measured memory_bytes: 21844
import java.io.*;

public class Main
{
	public static void main(String[] args) throws IOException
	{
		String s;
		int a;
		int b;
		BufferedReader buf = new BufferedReader (new InputStreamReader(System.in));
		s=buf.readLine();
		a=Integer.parseInt(s);
		b=a*a*a;
		System.out.println(b);
	}
}

Measured memory_bytes: 16864
# include <iostream>
# include <algorithm>

constexpr int MAX_N = 2000;
using ll = long long int;

int n;
ll a[MAX_N];
ll memo[MAX_N][MAX_N];//first:????¨?????????´??????,second:???????¨?????????´??????

ll solve(int l, int r) {
	if (memo[l][r] > 0)
		return memo[l][r];
	int diff;
	if (l > r)
		diff = n - l + r + 1;
	else
		diff = r - l + 1;

	if (diff == n)
		return 0;

	ll res = 0;

	if (diff % 2)
		res = (a[(n + l - 1) % n] > a[(r + 1) % n]) ? solve((n + l - 1) % n, r) : solve(l, (r + 1) % n);
	else
		res = std::max(solve((n + l - 1) % n, r) + a[(n + l - 1) % n], solve(l, (r + 1) % n) + a[(r + 1) % n]);

	return memo[l][r] = res;
}

int main() {

	std::cin >> n;
	for (int i = 0; i < n; ++i)
		std::cin >> a[i];
	ll ans = 0;
	for (int i = 0; i < n; ++i)
		ans = std::max(ans, solve(i, i) + a[i]);

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 34372
sx,sy,tx,ty = map(int,input().split())

dx = tx-sx
dy = ty-sy

ans = ("U")*dy + ("R")*dx + ("D")*dy +("L")*dx +("L") + ("U")*(dy+1) + ("R")*(dx+1) + ("D") + ("R") + ("D")*(dy+1) + ("L")*(dx+1) + ("U")

print(ans)

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

int main()
{
  int H,W;
  cin >> H >> W;
  int A[H][W];
  int min = 1000000;
  for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
          cin >> A[i][j];
      }
  }
  for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
          int h = 0;
          for(int k = 0; k < H; k++){
              for(int l = 0; l < W; l++){
                  int a = 0;
                  int b = 0;
                  if(i <= k) a = k - i;
                  else if(i > k)  a = i - k;
                  if(j <= l) b = l - j;
                  else if(j > l)  b = j - l;
                  if(a <= b){
                      h += a * A[k][l];
                  }else if(a > b){
                      h += b * A[k][l];
                  }
              }
          }
          if(h < min) min = h;
          h = 0;
      }
  }
  cout << min << endl;
  
  return 0;
      
}


Measured memory_bytes: 3116
#include <iostream>
#include <cstring>
using namespace std;
int i,l,j,ok;
bool dp[1<<17];
char s[1<<17],a[]="dream",b[]="dreamer",c[]="erase",d[]="eraser";
int main()
{
    cin>>(s+1);
    l=strlen(s+1);
    dp[0]=1;
    for(i=0;i<l;++i)
        if(dp[i])
    {
        ok=1;
        for(j=0;j<5;++j)
            if(s[i+j+1]!=a[j]) ok=0;
        if(ok) dp[i+5]=1;
        ok=1;
        for(j=0;j<7;++j)
            if(s[i+j+1]!=b[j]) ok=0;
        if(ok) dp[i+7]=1;
        ok=1;
        for(j=0;j<5;++j)
            if(s[i+j+1]!=c[j]) ok=0;
        if(ok) dp[i+5]=1;
        ok=1;
        for(j=0;j<6;++j)
            if(s[i+j+1]!=d[j]) ok=0;
        if(ok) dp[i+6]=1;
    }
    if(dp[l]) cout<<"YES";
    else cout<<"NO";
    return 0;
}


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

	int main(){
      int a,b,c,d;
      cin >> a >> b >> c >> d;
      string S={};
      for (int i=0;i<c-a;i++){
        S+="R";
      }
      for (int i=0;i<d-b;i++){
        S+="U";
      }
      for (int i=0;i<c-a;i++){
        S+="L";
      }
      for (int i=0;i<=d-b;i++){
        S+="D";
      }
      for (int i=0;i<=c-a;i++){
        S+="R";
      }
      for (int i=0;i<=d-b;i++){
        S+="U";
      }
      S+="LU";
      for (int i=0;i<=c-a;i++){
        S+="L";
      }
      for (int i=0;i<=d-b;i++){
        S+="D";
      }
      S+="R";
      cout << S << endl;
    }

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
  int i,j;
  int n;
  string s;
  while(1){
    cin>>n;
    cin.ignore();
    if(n==0)break;
    map<string,int> mp;
    rep(i,n){
      string s;
      getline(cin,s);
      string tmp;
      rep(j,s.size()){
        if(s[j]!=' '&&s[j]!='\0')
          tmp.push_back(s[j]);
        else{
          mp[tmp]++;
          tmp.clear();
        }
      }
      mp[tmp]++;
    }
    char k;
    cin>>k;
    pair<int,string> p[20];
    int m=0;
    for(std::map<string,int>::const_iterator itr=mp.begin();\
itr!=mp.end();++itr)
      if(itr->first[0]==k){
        p[m].first=-(itr->second);
        p[m].second=itr->first;
        m++;
      }
    if(m==0){
      cout<<"NA"<<endl;
    }else{
      sort(p,p+m);
      rep(i,min(5,m)){
        cout<<p[i].second;
        if(i<min(5,m)-1)cout<<" ";
      }
      cout<<endl;

    }
  }
}

Measured memory_bytes: 3132
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static void AssertEquals<T>(
				       T expected,
				       T actual,
				       [CallerLineNumber] int lno = 0
				       )
	where T : IComparable
    {
	if (expected.CompareTo(actual) != 0)
	{
	    WriteLine($"Assertion Error at line {lno}:");
	    WriteLine($"\texpected: {expected}");
	    WriteLine($"\t  actual: {actual}");
	    Environment.Exit(1);
	}
    }
    
    public static int Gcd(int a, int b)
    {
	if (a < b){ return Gcd(b, a); }
	while (b != 0)
	{
	    var r = a % b;
	    a = b;
	    b = r;
	}
	return a;
    }

    public static void Swap<T>(ref T a, ref T b)
    {
	var t = a;
	a = b;
	b = t;
    }

    public static void WarshallFloyd(int[,] d, int v)
    {
	for (int k = 0; k < v; k++)
	    for (int i = 0; i < v; i++)
		for (int j = 0; j < v; j++)
		    d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
    }

    public static bool NextPermutation<T>(T[] a) where T : IComparable
    {
	if (a.Length <= 1) return false;

	for (int i = a.Length - 1; i > 0; i--)
	{
	    int k = i - 1;
	    if (a[k].CompareTo(a[i]) < 0)
	    {
		int j = a.Length - 1;
		while (a[k].CompareTo(a[j]) >= 0){ j--; }
		Swap(ref a[k], ref a[j]);
		Array.Reverse(a, i, a.Length - i);
		return true;
	    }
	}
	Array.Reverse(a);
	return false;
    }
    
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    static int res;
    static bool[] used;
    static int R;
    static int[] rs;
    static int[,] d;
    
    static void dfs(int c, int las, int dist)
    {
	if (c == R)
	{
	    if (res > dist) res = dist;
	    return;
	}
	for (int i=0; i < R; i++)
	{
	    if(!used[i])
	    {
		used[i] = true;
		if (las==-1) dfs(c+1, i, 0);
		else dfs(c+1, i, dist+d[rs[las], rs[i]]);
		used[i] = false;
	    }
	}
       
    }
        
    public static void Main()
    {
	int inf = (1 << 29);
	
	var tmp = ReadIntArray();
	int n = tmp[0], m = tmp[1], r = tmp[2];

	rs = ReadIntArray();
	for (int i = 0; i < r; i++) rs[i]--;
	Array.Sort(rs);

	d = new int[n, n];
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j) d[i, j] = inf;

	for (int i = 0; i < m; i++)
	{
	    tmp = ReadIntArray();
	    int a = tmp[0], b = tmp[1], c = tmp[2];
	    a--; b--;
	    if (d[a, b] > c)
	    {
		d[a, b] = c;
		d[b, a] = c;
	    }
	}

	WarshallFloyd(d, n);

	res = inf;
	used = new bool[8];
	R = r;
	dfs(0, -1, 0);
	
	WriteLine(res);
    }
}


Measured memory_bytes: 15564
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;
using tdata=pair<datas,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll modncr(ll n,ll r){
  if(r*2>n)return modncr(n,n-r);
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i,N;
  cin>>N>>i;
  vec a(N),M(N,0),sa(N,0);
  rep(i,N){
    cin>>a[i];
  }
  M[N-1]=a[N-1];
  for(i=N-2;i>=0;i--){
    M[i]=max(M[i+1],a[i]);
    sa[i]=M[i+1]-a[i];
  }
  vrsort(sa);
  i=0;
  while(sa[i+1]==sa[i])i++;
  cout<<i+1<<endl;
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
        int h, w;
        while (1) {
                cin >> h >> w;
                if (h==0 && w==0) break;

                for (int i=0; i<h; i++) {
                        for (int j=0; j<w; j++) {
                                if((i+j)%2 == 0) {
                                        cout << "#";
                                } else {
                                        cout << ".";
                                }
                        }
                        cout << "\n";
                }
                cout << endl;
        }
        return 0;
}

Measured memory_bytes: 3084
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func scanInts(n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = nextInt()
	}
	return is
}

func main() {
	var S, T string
	fmt.Scan(&S)
	fmt.Scan(&T)
	sLen := len(S)
	tLen := len(T)
	if tLen == 0 {
		fmt.Println(sLen)
		return
	}
	nearI := 0
	MAX := 0
	for i := 0; i <= len(S)-tLen; i++ {
		d := sameCount(S[i:i+tLen], T)
		MAX = max(d, MAX)
		if MAX == d {
			nearI = i
		}
	}
	fmt.Println(diffCount(S[nearI:nearI+tLen], T))
}

func sameCount(a, b string) int {
	var count int
	for i := 1; i <= len(a); i++ {
		if a[i-1:i] == b[i-1:i] {
			count++
		}
	}
	return count
}

func diffCount(a, b string) int {
	var count int
	for i := 1; i <= len(a); i++ {
		if a[i-1:i] != b[i-1:i] {
			count++
		}
	}
	return count
}

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


Measured memory_bytes: 1900
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws java.io.IOException
	{
		int[] is = new int[10];
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		for( int i = 0; i < 10; ++i){
			String c = r.readLine();
			is[i] = Integer.parseInt(c);
		}
		java.util.Arrays.sort(is);
		for (int i = 1; i <= 3; i++) {
			System.out.println(is[is.length-i]);
		}
	}
}

Measured memory_bytes: 16864
#include <stdio.h>
#include <string.h>
int main(void){
    int n,next,ans=0,a[100001] ;
    scanf ("%d",&n) ;
    for (int i=0; i<n; i++) {
        scanf ("%d",&a[i]) ;
    }
    next = a[0] ;
    while (next!=2 && ans<n+1) {
        next=a[next-1] ;
        ans++ ;
    }
    if (ans>n) {
        printf ("-1\n") ;
    } else {
        printf ("%d\n",ans+1) ;
    }
    return 0 ;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define M 1000000007
#define pb push_back
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);



int dp[3001][3001];
string s,t;

int solve(int n,int m)
{
    if(n==0 || m==0)
        return 0;
    if(dp[n][m]!=-1)
        return dp[n][m];
    if(s[n-1]==t[m-1])
    {
        dp[n][m]=1+solve(n-1,m-1);
    }
    else
    {
        dp[n][m]=max(solve(n-1,m),solve(n,m-1));
    }
    return dp[n][m];
}
signed main()
{
    boost
  //  #ifndef ONLINE_JUDGE 
   // NAYAN
   // #endif
   
    //int n;
    cin >> s  >> t;
    
    int n,m;
    n=s.length();
    m=t.length();
    memset(dp,-1,sizeof(dp));
    
    int ans=solve(n,m);
    

    string temp;
    temp="";
    int i=n,j=m;
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
            temp=s[i-1]+temp;
            i--;
            j--;
        }
       // else if(i>0 && j>0)
       // {
         else   if(dp[i-1][j]>dp[i][j-1])
                i--;
            else
                j--;
       // }
    }
    cout << temp << endl;
}

Measured memory_bytes: 70912
#include <iostream>
#include <cstdio>
#include <cstring>
 
using namespace std;

int main()
{
    int N, M;
    int T[100];
    
    int sum = 0;
    int mSum[100];
    
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> T[i];
        sum += T[i];
    }
    
    cin >> M;
    for (int i = 0; i < M; i++)
    {
        int p, x;
        cin >> p >> x;
        mSum[i] = sum - T[p - 1] + x;
    }

//    printf("sum=%d\n", sum);
    
    for (int i = 0; i < M; i++)
    {
        printf("%d\n", mSum[i]);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int gcd(long long a, long long b) {
	return (b == 0) ? a : gcd(b, a % b);
}

int main() {

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

	int n;
	cin >> n;

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

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

	cout << g << "\n";

	return 0;

}

Measured memory_bytes: 640
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cmath>
#include<stack>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 105
#define inf (int)1e9
#define ll long long
#define mm 1000000007
#define eps 1e-9
#define low(x) x&(-x)
#define pb push_back
#define mp make_pair
#define PII pair<int,int>
using namespace std;

ll read(){
    ll x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int n,m,cnt,nowi,nowj,op,a[105][105];
void get(int col,int sum){
	rep(i,1,sum) {
		if (!a[nowi][nowj]) a[nowi][nowj]=col;
		rep(j,op,8) {
			int xx=nowi+dx[j%4],yy=nowj+dy[j%4];
			if (1<=xx&&xx<=n&&1<=yy&&yy<=m&&(!a[xx][yy])) {nowi=xx,nowj=yy; op=j%4; break;}
		}
	}
}
int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	n=read(); m=read();
	cnt=read();
	nowi=1,nowj=1; op=0;
	rep(i,1,cnt) {
		int x=read();
		get(i,x);
	}	
	rep(i,1,n) {
		rep(j,1,m) printf("%d ",a[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

vector<string> split(const string &str, char sep){
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while( getline(ss, buffer, sep ) ) v.pb(buffer);
  if(str[str.size()-1] == sep) v.pb("");
  return v;
}

int solve(string &s, string &t){
  auto v = split(s, '"');
  auto u = split(t, '"');
  if(v.size()!=u.size()) return 0;
  int x = 0;
  rep(i,v.size()) if(v[i]!=u[i]){
    if(i%2==0) return 0;
    else x++;
  }
  if(x>1) return 0;
  if(x==1) return 1;
  else return 2;
}

int main(){
  string s,t;
  while(cin>>s, s!="."){
    cin>>t;
    int r = solve(s,t);
    if(r==0) cout << "DIFFERENT" << endl;
    else if(r==1) cout << "CLOSE" << endl;
    else cout << "IDENTICAL" << endl;
  }

  return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<int>>;
const int MOD = 1e9 + 7;

vector<int> bfs(int s, Graph &G) {
    int N = G.size();
    vector<int> dist(N, INT_MAX);
    queue<int> que;
    dist[s] = 0;
    que.push(s);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (auto nv : G[v]) {
            if (dist[nv] < INT_MAX)
                continue;
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
    return dist;
}

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

    int N;
    cin >> N;
    Graph G(N);
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> dist1 = bfs(0, G);
    vector<int> dist2 = bfs(N - 1, G);
    int cnt = 0;
    for (int i = 0; i < N; ++i)
        cnt += (dist1[i] <= dist2[i]);

    cout << (cnt > N - cnt ? "Fennec" : "Snuke") << endl;
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <iomanip>
#include <cmath>
using namespace std;
const double INF = 1e18;
const double EPS = 1e-10;

struct info{
	double d;
	int l,r;
	info(double d, int l, int r):d(d),l(l),r(r){}
	info(){}
	bool operator<(const info &a) const{
		return d > a.d;
	}
};

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		vector<double> x(n), y(n);
		vector<pair<double, double> > p;
		for(int i=0; i<n; i++){
			cin >> x[i] >> y[i];
			p.push_back(make_pair(x[i], y[i]));
		}
		for(int i=0; i<n; i++){
			for(int j=0; j<n-1; j++){
				if((y[j]<y[i] && y[i]<y[j+1]) || (y[j+1]<y[i] && y[i]<y[j])){
					double rate = (y[i] -y[j])/(y[j+1] -y[j]);
					p.push_back(make_pair(x[j] +rate*(x[j+1] -x[j]), y[i]));
				}
			}
		}
		sort(p.begin(), p.end());
		p.erase(unique(p.begin(), p.end()), p.end());
		
		int m = p.size();
		priority_queue<info> wait;
		wait.push(info(0, 0, m-1));
		map<pair<int, int>, double> mindist;
		mindist[make_pair(0, m-1)] = 0;
		double ans = INF;
		while(!wait.empty()){
			double d = wait.top().d;
			int l = wait.top().l;
			int r = wait.top().r;
			wait.pop();
			if(d > mindist[make_pair(l,r)] +EPS) continue;
			if(l == r) ans = min(ans, d);
			for(int i=-1; i<=1; i+=1){
				for(int j=-1; j<=1; j+=1){
					if(l+i<0 || m<=l+i) continue;
					if(r+j<0 || m<=r+j) continue;
					if(abs(p[l+i].second -p[r+j].second) <EPS){
						double x1 = p[l].first -p[l+i].first;
						double x2 = p[r].first -p[r+j].first;
						double y1 = p[l].second -p[l+i].second;
						double y2 = p[r].second -p[r+j].second;
						double nd = d +sqrt(x1*x1 +y1*y1) +sqrt(x2*x2 +y2*y2);
						pair<double, double> nlr(l+i, r+j);
						if(mindist.count(nlr) == 0 || nd +EPS < mindist[nlr]){
							mindist[nlr] = nd;
							wait.push(info(nd, l+i, r+j));
						}
					}
				}
			}
		}
		cout << fixed << setprecision(10);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 8960
#include<stdio.h>

int main() {
	int x, y;
	int tmp;

	scanf("%d%d", &x, &y);
	if (x < y) {
		tmp = x;
		x = y;
		y = tmp;
	}

	while (y != 0) {
		tmp = x;
		x = y;
		y = tmp % y;
	}

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

	return 0;
}


Measured memory_bytes: 2080
from collections import defaultdict as dic
s = int(input())

flag = dic(int)
flag[s - 1] = 1
def f(n, i):
    if flag[n - 1] == 1:
        print(i)
        exit()
    else:
        flag[n - 1] = 1
        if n % 2 == 1:
            f(3 * n + 1, i + 1)
        else:
            f(int(n / 2), i + 1)
        

if s % 2 == 1:
    f(3 * s + 1, 2)
else:
    f(int(s / 2), 2)


Measured memory_bytes: 3316
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	total := make([]int, n+1)
	for i := 1; i < n+1; i++ {
		sc.Scan()
		w, _ := strconv.Atoi(sc.Text())
		total[i] = w + total[i-1]
	}

	ans := 9999
	for t := 1; t < n; t++ {
		if a := abs(total[n] - total[t]*2); a < ans {
			ans = a
		}
	}
	fmt.Println(ans)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


Measured memory_bytes: 640
n = gets.to_i
s = gets.chomp.split("")
alpha = Array.new(26,0)

for i in 0..n-1
  alpha[s[i].ord - 97] += 1
end
ans = 1
for i in 0..25
  ans *= alpha[i]+1
end
ans -= 1
ans %= (10**9 + 7)
puts ans


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

long long inv(long long n) {
    long long res = 1;
    while (n > 1) {
        res *= (MOD - MOD/n);
        res %= MOD;
        n = MOD % n;
    }
    return res;
}

void solve() {
    int n, k;
    cin >> n >> k;

    vector<ll> comb0(n), comb1(n);
    ll nume0 = 1, nume1 = 1, deno = 1;
    for (int i=0; i<n; ++i) {
        comb0.at(i) = nume0 * inv(deno) % MOD;
        comb1.at(i) = nume1 * inv(deno) % MOD;
        nume0 *= n-i;
        nume0 %= MOD;
        nume1 *= n-i-1;
        nume1 %= MOD;
        deno *= (i+1);
        deno %= MOD;
    }
    ll res = 0;
    for (int i=0; i<min(n, k+1); ++i) {
        res += comb0.at(i) * comb1.at(i) % MOD;
        res %= MOD;
    }
    cout << res << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3328