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

int main() {
  int N;
  cin >> N;
  
  int64_t ans = 1;
  
  for(int i=1; i<=N; i++){
    ans *=i;
    ans %= 1000000007;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3500
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	int n;
	scanf("%d", &n);
	vector<long long> a(n);
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

	long long x = 0;
	for (int i = 0; i < n-1; i++) x += a[i];
	x = (x - a[n-1]) / 2;

	// x is the sum of a[1] ... a[n-2]
	for (int i = 2; i < n-2; i += 2)
		x -= a[i];
	// now x is ans[1]
	vector<long long> ans(n);
	ans[1] = x;
	ans[0] = a[0] - x;
	for (int i = 2; i < n; i++)
		ans[i] = a[i-1] - ans[i-1];

	for (long long y : ans)
		printf("%lld ", 2*y);
	printf("\n");
}


Measured memory_bytes: 2816
#include<stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	int d;
	int e;
	int f;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if(a < b){
		d = b;
		e = a;
	}
	else {
		d = a;
		e = b;
	}
	if(d < c){
		f = e;
		e = d;
		d = c;
	}
	else if(e < c){
		f = e;
		e = c;
	}
	else{
		f = c;
	}
	
	printf("%d %d %d\n",f ,e, d);
	
	return (0);
}

Measured memory_bytes: 596
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
ans = tmp = sum(a2) + a1[0]
for i in range(n-1):
    tmp += a1[i+1] - a2[i]
    ans = max(ans, tmp)
print(ans)

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> MAS(H,vector<char>(W));
  for (int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++){
      cin >> MAS.at(i).at(j);
    }
  }

  // ここにプログラムを追記
  // (ここで"試合結果の表"の2次元配列を宣言)
  vector<bool> BY(H), BT(W);
  for(int i = 0; i<H; i++){
    bool x = false;
    for(int j = 0; j < W; j++){
      if(MAS.at(i).at(j) == '#')x = true;
    }
    BY.at(i) = x;
  }
  for(int i = 0; i<W; i++){
    bool x = false;
    for(int j = 0; j < H; j++){
      if(MAS.at(j).at(i) == '#')x = true;
    }
    BT.at(i) = x;
  }
  
  for(int i=0;i<H;i++){
    if(BY.at(i)){
      for(int j=0;j<W;j++){
        if(BT.at(j)){
          cout << MAS.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
    
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    sort(a.begin(), a.end(), greater<ll>());

    ll ans = 0;

    priority_queue<ll> q;
    q.push(a[0]);

    for(int i=1; i<n; i++){
        ll toru = q.top();
        q.pop();
        ans += toru;
        q.push(a[i]);
        q.push(a[i]);
    }

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


Measured memory_bytes: 6844
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	vector<long long> a(n), b(m);
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < m; i++)
		cin >> b[i];
	for(int i = 1; i < n; i++)
		a[i] += a[i - 1];
	for(int i = 1; i < m; i++)
		b[i] += b[i - 1];
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(a[i] <= k){
			int r = k - a[i];
			int p = lower_bound(b.begin(), b.end(), r + 1) - b.begin();
			ans = max(ans, p + i + 1);
		}
	}
	for(int i = 0; i < m; i++){
		if(b[i] <= k){
			ans = max(ans, i + 1);
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 6368
using System;
using System.Linq;
using System.Collections.Generic;

public class Test
{
	public static void Main()
	{
        int n = int.Parse(Console.ReadLine());
        
        int[,] nums = new int[2,n];

        int index = 0;

        string[] line = Console.ReadLine().Split(' ');
        for(int i = 0 ; i < n ; i++){
            nums[0,i] = int.Parse(line[i]);
        }
        line = Console.ReadLine().Split(' ');
        for(int i = 0 ; i < n ; i++){
            nums[1,i] = int.Parse(line[i]);
        }

        int a = 0;
        int b = 0;
        int Max = 0;
        int Sum = 0;
        for(int i = 0 ; i < n ; i++){
            a = 0;
            b = 0;
            Sum = 0;
            for(int j = 0 ; j < n ; j++){
                Sum += nums[b, j];
                if(i == a){
                    b++;
                    j--;
                }
                a++;
            }
            if(Max < Sum){
                Max = Sum;
            }
        }

        Console.WriteLine(Max);
    }                                                                                                                                                                       
}

Measured memory_bytes: 13140
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

vector<ll> enum_div(ll n){
	vector<ll> ret;
	for(ll i=1;i*i<=n;++i){
		if(n%i==0){
			ret.push_back(i);
			if(i*i!=n){
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	int sum = 0;
	for(int i=1;i<=N;i++){
		if(!(i%2)) continue;
		auto res = enum_div(i);
		if(res.size()==8) sum++;
	}
	
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var s = next(1);
  return s[1] === "B" ? "ARC" : "ABC";
}

Measured memory_bytes: 30252
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
using namespace std;


ll gcd(ll a, ll b)   //Function to find gcd of two numbers
{
    if (a == 0)
    return b;
    return gcd(b % a, a);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin>>n;
    
    string str;
    cin>>str;
    
    int cntw=0;
    
    for(int i=0;i<n;i++)
    {
        if(str[i]=='W')
        cntw++;
    }
    
    int ans = cntw;
    
    for(int i=n-1;i>=n-cntw;i--)
    {
        if(str[i]=='W')
        ans--;
    }
    
    cout<<ans<<endl;
    
    return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/04  Problem: ABC 043 B / Link: http://abc043.contest.atcoder.jp/tasks/abc043_b  ----- */


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

	string s; cin >> s;
	string ans;

	for (auto c : s) {
		if (c == 'B') {
			if(SZ(ans))ans.pop_back();
		}
		else {
			ans += string(1, c);	
		}
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    # ヒープキューをインポート
    from heapq import heappush, heappop

    n, m = map(int, input().split())
    jobs = [[] for _ in range(m)]  # 締め切り別に，報酬を管理

    for i in range(n):
        ai, bi = map(int, input().split())

        # 報酬が振り込まれる日がM日よりも後になる場合は除外
        if ai > m:
            continue

        # i件目のアルバイトを遅くてもいつまでに始める必要があるかを計算
        # heappopは最小値を返す．biを-1倍することで，最大値が取り出せる
        deadline = m - ai
        jobs[deadline].append(-bi)

    ans = 0
    reward = []

    # M-1日に始める必要があるアルバイトのうち，最も報酬の高いものを選択
    # 以降，今日始める必要があるアルバイトまで，順番に調べる
    # ある時点で得られる報酬の大小に着目
    for i in range(m - 1, -1, -1):
        for job in jobs[i]:
            # ヒープキューに，報酬の候補を追加
            heappush(reward, job)

        # 条件を満たすもののうち，最大の報酬を選択
        if reward:
            ans += heappop(reward)

    # ヒープキューに追加するときに，-1倍した分を元に戻す
    print(-ans)


if __name__ == '__main__':
    main()


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

int main()
{
    long n;
    cin >> n;
    vector<int> h(n);
    for(long i=0;i<n;i++)
        cin >> h[i];

    int dp[n];
    for(int i=0;i<n;i++)
    {
        if(i<3)
        {
            if(i==0)
                dp[i] = h[i];
            if(i==1)
                dp[i] = abs(h[i] - h[i-1]);
            if(i==2)
                dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),abs(h[i-2]-h[i]));
        }
        else{
            dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        }
    }
    cout << dp[n-1] << "\n";

}


Measured memory_bytes: 4048
#include <iostream>
#include <vector>
#define llint long long

using namespace std;

struct edge{
	llint to, cost;
	edge(){}
	edge(llint a, llint b){
		to = a, cost = b;
	}
};

llint n;
vector<edge> G[100005];
int ans[100005];

void dfs(int v, int p, llint d)
{
	ans[v] = d%2;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i].to == p) continue;
		dfs(G[v][i].to, v, d+G[v][i].cost);
	}
}

int main(void)
{
	cin >> n;
	llint u, v, w;
	for(int i = 1; i <= n-1; i++){
		cin >> u >> v >> w;
		G[u].push_back(edge(v, w));
		G[v].push_back(edge(u, w));
	}
	dfs(1, -1, 0);
	for(int i = 1; i <= n; i++) cout << ans[i] << endl;
	
	return 0;
}

Measured memory_bytes: 10624
/*  Isn't it lovely, all alone?             */
/*  Heart made of glass, my mind of stone   */
/*  Tear me to pieces, skin to bone         */
/*  Hello, welcome home                     */

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod 998244353
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

int main()
{
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);


ll t=1;
//cin>>t;
while(t--)
{

ll n,k;
cin>>n>>k;
ll a[n],i;
for(i=0;i<n;i++)
cin>>a[i];


for(i=k;i<n;i++)
{
if(a[i]>a[i-k])
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}

}
return 0;
}

















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

int main(){
	ios :: sync_with_stdio(false);
	cin.tie(0);
	int h, w, n;
	cin >> h >> w >> n;
	int m = max(h, w);
	for(int i = 1; i <= n; i++){
		int x = m * i;
		if(x >= n){
			cout << i;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>


     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define sz size()
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

     
const ll MOD = 1e9 + 7;
const ll ZER = 0;


int main(){
    char c;
    cin >> c;
    if(islower(c)){
        cout << 'a' << endl;
    }
    else {
        cout << 'A' << endl;
    }
}





Measured memory_bytes: 3596
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			String str=sc.next();
			int n=0,s=0,e=0,w=0;
			for(int i=0;i<str.length();i++){
				char c=str.charAt(i);
				if(c=='N') n++;
				else if(c=='S') s++;
				else if(c=='E') e++;
				else w++;
			}
			if(n==0 && s!=0 || s==0 && n!=0) System.out.println("No");
			else if(e==0 && w!=0 || w==0 && e!=0) System.out.println("No");
			else System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 10192
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MP make_pair
#define endl '\n'
const int mod = 10007;
const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;

int main(int argc, char* argv[]) {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    if (a == 2)
        cout << 1 << endl;
    else
        cout << (b == 2 ? 3 : 2) << endl;
    return 0;
}


Measured memory_bytes: 256
s = str(input())
 
if s == "SUN":
  print(7)
elif s == "MON":
  print(6)
elif s == "TUE":
  print(5)
elif s == "WED":
  print(4)
elif s == "THU":
  print(3)
elif s == "FRI":
  print(2)
else:
  print(1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 1000;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	ll ans=0;
	vector<ll> a;
	FOR(i,0,n){
		ll k;cin>>k;
		a.pb(k);
	}
	FOR(i,0,n){
		if(i!=n-1&&a[i]==i+1){
			swap(a[i],a[i+1]);
			ans++;
		}else if(i==n-1&&a[i]==n){
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
using namespace std;
typedef long long LL;
const int N=2050,mo=1e9+7;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n,ans;
int f[N][N],g[N][N];
int fv[N];
int main()
{
	int q,w;	
	read(n),read(m);
	fo(i,1,n)f[1][i]=fv[i]=1,g[1][i]=i-1;
	fo(i,2,n)
	{
		fo(j,i,n)
		{
			((g[i][j]=g[i][j-1]+fv[j-1])>=mo?g[i][j]-=mo:0);
			((f[i][j]=g[i][j-1]+fv[j-1])>=mo?f[i][j]-=mo:0);
			((fv[j-1]+=f[i][j-1])>=mo?fv[j-1]-=mo:0);
		}
	}
	ans=f[m][n];
	fo(i,1,n-m-1)((ans=(ans<<1))>=mo?ans-=mo:0);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 33024
from bisect import bisect
N = int(input())
*A, = map(int, input().split())
B = {}
for a in A:
    B[a] = B.get(a, 0) + 1
R = sorted(B.items())
C = []; D = []
for k, v in sorted(B.items()):
    C.append(k)
    D.append(v)
M = len(C)
j = 0
ans = 0
for i in range(M-1, -1, -1):
    if D[i] == 0:
        continue
    a = C[i]
    b = 2**(a).bit_length()
    j = bisect(C, b-a-1)
    if j < M and C[j] == b-a:
        if i == j:
            ans += D[i]//2
            D[i] %= 2
        else:
            c = min(D[i], D[j])
            ans += c
            D[i] -= c; D[j] -= c
print(ans)

Measured memory_bytes: 121508
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int v){
    return a>v;
}
int main(){
    int n,m;
    cin>>n>>m;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1,cmp);
    int ans=0;
    for(int i=1;i<=m;i++){
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
def main():
    x = int(input())
    if(x>6):
        res = 1
    if(x%11<=6 and x%11!=0):
        a = math.ceil((x+5)/11)
        b = a-1
        print(a+b)
    else:
        a=math.ceil((x)/11)
        b=a
        print(a+a)
if __name__ == '__main__':
    main()


Measured memory_bytes: 61556
N=int(input())
true=False
can=False
for num7 in range(100):
    if can:
        break
    for num4 in range(100):
        sum=num7*7+num4*4
        if sum>N:
            break
        if sum==N:
            true=True
            can=True
            break
if true:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
import math
def prime(v):
  if v == 2: return 1
  if v > 2 and v % 2 == 0: return 0

  for i in range(int(math.sqrt(v)), 2, -1):
    if v % i == 0: return 0
  return 1

N = int(raw_input())
n = []
count = 0
for i in range(N):
  count += prime(int(raw_input()))
print count


Measured memory_bytes: 5368
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;

int main() {
	int N;
	cin >> N;
	vector<int> A(3 * N);
	for (int i = 0; i < 3 * N; i++)
		cin >> A[i];
	
	priority_queue<int,vector<int>,greater<int>> pq;  //小さい順
	ll Lsum = 0;
	for (int i = 0; i < N; i++) {
		Lsum += A[i];
		pq.push(A[i]);
	}
	vector<ll> L(N + 1), R(N + 1);
	L[0] = Lsum;
	for (int i = 0; i < N; i++) {
		ll temp = pq.top();
		if (temp < A[N + i]) {
			Lsum = Lsum - temp + A[N + i];
			pq.pop();
			pq.push(A[N+i]);
		}
		L[i + 1] = Lsum;
	}

	ll Rsum = 0;
	priority_queue<int> pq2;   //大きい順
	for (int i = 0; i < N; i++) {
		Rsum += A[2 * N + i];
		pq2.push(A[2*N+i]);
	}
	R[N] = Rsum;
	for (int i = N - 1; i >= 0; i--) {
		ll temp = pq2.top();
		if (A[N + i] < temp) {
			Rsum = Rsum - temp + A[N + i];
			pq2.pop();
			pq2.push(A[N+i]);
		}
		R[i] = Rsum;
	}

	ll ans = (ll)-1e18;
	for (int i = 0; i <= N; i++) {
		ans = max(ans,L[i]-R[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4088
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
int main()
{
    fio;
    int t=1;;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n];
        rep(i,n)
        cin>>a[i];
        ll sum=0;
        rep(i,n-1)
        {
            if(a[i]>a[i+1])
            {
                sum=sum+(abs(a[i]-a[i+1]));
                a[i+1]+=(abs(a[i]-a[i+1]));
            }
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 5204
#include <iostream>
#include <cstring>

int main(){
	int count[4][3][10];
	memset(count, 0, sizeof(int)*4*3*10);
	int n, b, f, r, v;
	
	std::cin >> n;
	for(int i=0; i<n; i++){
		std::cin >> b >> f >> r >> v;
		count[b-1][f-1][r-1] += v;
	}
	
	for(b=0; b<4; b++){
		for(f=0; f<3; f++){
			for(r=0; r<10; r++){
				std::cout << ' ' << count[b][f][r];
			}
			std::cout << std::endl;
		}
		if(b-3)
			std::cout << "####################" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

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

  ll K = -1;
  for (ll k = 1; k < 1000; k++)
  {
    if (N == (k - 1) * k / 2)
    {
      K = k;
      break;
    }
    if (N < (k - 1) * k / 2)
      break;
  }
  if (K == -1)
    FINALANS("No");

  queue<ll> Q;
  for (ll i = 0; i < N; i++)
  {
    Q.push(i + 1);
  }
  vector<vector<ll>> S(K, vector<ll>(K - 1));

  cout << "Yes" << endl;
  cout << K << endl;
  for (ll i = 0; i < K; i++)
  {
    cout << K - 1 << ' ';

    for (ll j = 0; j < K - 1; j++)
    {
      if (j < i)
      {
        S.at(i).at(j) = (S.at(j).at(i - 1));
      }
      else
      {
        S.at(i).at(j) = Q.front();
        Q.pop();
      }
      cout << S.at(i).at(j) << ((j == K - 2) ? '\n' : ' ');
    }
  }
}

/*
1 2
1 3
2 3

1 2 3
1 4 5
2 4 6
3 5 6

1 2 3 4
1 5 6 7
2 5 8 9
3 6 8 10
4 7 9 10
*/

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

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] map = new int[71][71];
        String[][] str = new String[71][71];
        Arrays.fill(str[0], "");
        int w, h;
        String temp, max;
        while(true){
            w = sc.nextInt();
            h = sc.nextInt();
            if(w==0 && h==0) break;

            for(int i=1; i<=h; i++){
                temp = sc.next();
                Arrays.fill(map[i], -1);
                Arrays.fill(str[i], "");
                for(int j=1; j<=w; j++){
                    if(temp.charAt(j-1)>='0' && temp.charAt(j-1)<='9'){
                        map[i][j] = temp.charAt(j-1) - '0';
                    }
                }
            }
            Arrays.fill(map[h+1], -1);
            Arrays.fill(str[h+1], "");

            max = "";
            for(int i=1; i<=h; i++){
                for(int j=1; j<=w; j++){
                    temp = "";
                    if(map[i][j]>=0){
                        if(str[i-1][j].length() < str[i][j-1].length()){
                            temp = str[i][j-1];
                        }else if(str[i-1][j].length()==str[i][j-1].length() && !str[i-1][j].equals(str[i][j-1])){
                            if(str[i-1][j].compareTo(str[i][j-1])>0){
                                temp = str[i-1][j];
                            }else{
                                temp = str[i][j-1];
                            }
                        }else{
                            temp = str[i-1][j];
                        }
                        if(!(temp.length()==0 && map[i][j]==0)){
                            str[i][j] = temp + String.valueOf(map[i][j]%10);
                        }

                        if(map[i+1][j]==-1 && map[i][j+1]==-1){
                            if(max.length() < str[i][j].length()){
                                max = str[i][j];
                            }else if(max.length()==str[i][j].length() && !max.equals(str[i][j])){
                                if(max.compareTo(str[i][j])<0){
                                    max = str[i][j];
                                }
                            }
                        }
                    }
                }
            }

            System.out.println(max);
        }
    }
}

Measured memory_bytes: 59108
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define _GLIBCXX_DEBUG

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

int main(void){

    int N, M;

    cin >> N >> M;

    int a, b;
    int ans = 0;

    int H[N];
    vector<int> result(N);

    for(int i=0; i < N; i++){
        cin >> H[i];
    }

    // qsort(H, sizeof(H) / sizeof(int), sizeof(int), asc);

    // cout << endl;

    // for(int i=0; i < N; i++){
    //     cout << H[i] << " ";
    // }

    // cout << endl;

    for(int i=0; i < M; i++){
        cin >> a >> b;
        if(H[a-1] > H[b-1]){
            result[b-1] += 1;
        }

        else if(H[a-1] < H[b-1]){
            result[a-1] += 1;
        }

        else {
            result[a-1] += 1;
            result[b-1] += 1;
        }

    }

    // for(int i=0; i < N; i++){
    //     cout << result[i] << " ";
    // }

    // cout << endl;

    for(int i=0; i < N; i++){
        if(result[i] == 0){
            ans++;
        }
    }

    cout << ans << endl;


}

Measured memory_bytes: 3988
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <cstdlib>

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define pb push_back

using namespace std;

const int N = 100010;

int n, k;
int L[N], R[N], dep[N];

vector<int> G[N];

void DFS_init(int o, int f){
	if(L[o] == R[o] && L[o] % 2 != dep[o]){
		puts("No");
		exit(0);
	}
	for(int v : G[o]){
		if(v == f) continue;
		dep[v] = dep[o] ^ 1;
		DFS_init(v, o);
		L[o] = max(L[v] - 1, L[o]), R[o] = min(R[v] + 1, R[o]);
	}
	if(L[o] > R[o]){
		puts("No");
		exit(0);
	}
}

void DFS_work(int o, int f){
	R[o] = L[o];
	for(int v : G[o]){
		if(v == f) continue;
		L[v] = max(L[v], L[o] - 1), R[v] = min(R[v], R[o] + 1);
		DFS_work(v, o);
	}
}

int main(){
	scanf("%d", &n);
	For(i, 2, n){
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].pb(v), G[v].pb(u);
	}
	For(i, 1, n) L[i] = -1e6, R[i] = 1e6;
	int root = 1;
	scanf("%d", &k);
	For(i, 1, k){
		int x, v;
		scanf("%d%d", &x, &v);
		L[x] = R[x] = v;
		root = x;
	}
	dep[root] = L[root] & 1;
	DFS_init(root, 0), DFS_work(root, 0);
	puts("Yes");
	For(i, 1, n) printf("%d\n", L[i]);
	return 0;
}

Measured memory_bytes: 13824
n,k=map(int,input().split())
c=[i for i in range(1,n+1)]
ans=0

def ta(m,cnt):
    if k>m:
        cnt+=1
        m*=2
        return ta(m,cnt)
    else:
        return cnt

for i in c:
    cnt=0
    x=(0.5**ta(i,cnt))/n
    ans+=x
print(ans)

Measured memory_bytes: 7064
#include <stdio.h>
#include <math.h>
int main()
{   
long int X;
scanf("%ld",&X); 
long int anser1=X/500;
long int amari=X%500;
long int anser2=amari/5;
printf("%ld", anser1*1000+anser2*5);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  // 入力読み込み用の配列
  vector<int> mochisize(N);
  // サイズのダブりチェック結果を格納する配列
  vector<int> mochidaburi(N);
  
  // 標準入力から読み込み
  for (int i = 0; i < N; i++) {
    cin >> mochisize.at(i);
  }
  
  // 後にダブりがあるものはフラグを立てる
  for (int i = 0; i < N; i++) {
    for (int j = i+1; j < N; j++) {
      if (mochisize.at(i) == mochisize.at(j)){
        mochidaburi.at(i) = 1;
        // デバッグ用 ダブったものを出力
//        cout << i  << ":" << mochisize.at(i)  << ":" << mochidaburi.at(i) << endl;
      }
    }
  }
  
  // ダブっている枚数をカウント
  int daburicnt = 0;
  for (int i = 0; i < N; i++) {
    if (mochidaburi.at(i) > 0) {
      daburicnt++;
    }
  }
  
  // ダブりを抜いた枚数を出力する
  cout << N - daburicnt << endl;
  
  return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

	struct card{
		char suit;
		int value;
	};
	
	int main() {
		int n, i, j, min, s;
		char k;
		struct card x[36],y[36],z;
		
		scanf("%d\n", &n);
		
		for( i = 0; i < n; i++) {
			scanf("%c%d", &x[i].suit, &x[i].value);
			scanf("%c",&k);
		}
		
		for( i = 0; i < n; i++) {
			y[i] = x[i];
		}
		
		for( i = 0; i < n; i++) {
			for( j = n-1; j > i; j--) {
				if( x[j].value < x[j-1].value) {
					z = x[j];
					x[j] = x[j-1];
					x[j-1] = z;
				}
			}
		}
		
		for( i = 0; i < n; i++) {
			min = i;
			for( j = i; j < n; j++) {
				
				if(y[j].value < y[min].value) {
					min = j;
				}
			}
			z = y[i];
			y[i] = y[min];
			y[min] = z;
		}
		
		for( i = 0; i < n-1; i++) {
			printf("%c%d ", x[i].suit,x[i].value);
		}
		printf("%c%d\n", x[n-1].suit,x[n-1].value);
		printf("Stable\n");
		
		for( i = 0; i < n-1; i++) {
			printf("%c%d ", y[i].suit, y[i].value);
		}
		printf("%c%d\n", y[n-1].suit, y[n-1].value);
		
		s = 1;
		
		for( i = 0; i < n; i++) {
			if( x[i].suit != y[i].suit) {
				s = 0;
			}
		}
		if( s == 0) {
			printf("Not stable\n");
		}else{
			printf("Stable\n");
		}
		
		return 0;
		
	}
	

Measured memory_bytes: 1848
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int n, q;
	long long S[10000];
	long long T[500];

	cin >> n;
	for(int i=0; i<n; ++i){
		cin >> S[i];
	}
	cin >> q;
	for(int i=0; i<q; ++i){
		cin >> T[i];
	}
	int count = 0;

	for(int i=0; i<q; ++i)
		for(int j=0; j<n; ++j){
			if(T[i] == S[j]){
				count++;
				break;
			}
		}

	cout << count << endl;

	return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vi a(n), b(n);
  vi c(m), d(m);
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, m) cin >> c[i] >> d[i];
  rep(i, n){
    int shortest = mod;
    int shortNum = 0;
    rep(j, m){
      int kyori = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if(shortest > kyori){
        shortest = kyori;
        shortNum = j;
      }
    }
    cout << shortNum + 1 << endl;
  }
}

Measured memory_bytes: 256
def main():
    h, w, m = map(int, input().split())
    hp = [0]*h
    wp = [0]*w
    hw = set()
    for _ in range(m):
        h1, w1 = map(int, input().split())
        hp[h1-1] += 1
        wp[w1-1] += 1
        hw.add((h1, w1))

    h_max = max(hp)
    w_max = max(wp)

    hh = [i+1 for i, v in enumerate(hp) if v == h_max]
    ww = [i+1 for i, v in enumerate(wp) if v == w_max]
    ans = h_max + w_max

    for hb in hh:
        for wb in ww:
            if (hb, wb) not in hw:
                print(ans)
                exit()
    print(ans-1)


if __name__ == '__main__':
    main()

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

using namespace std;

int x, n;

int main(){
	while(cin >> n, n){
		int res = 0;
		for(int i = 0;i < n *(n-1)/2;i++){
			cin >> x;
			res += x;
		}
		cout << res / (n-1) << endl;
	}                               
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

ll mod = 1000000007;

int main() {
  ll n;
  cin >> n;
  vector<ll> vec(n);
  for (auto &v : vec)
    cin >> v;

  sort(vec.begin(), vec.end(), greater<ll>());

  vector<ll> vec2;
  for (int i = n - 1; 0 <= i; i -= 2) {
    if (i != 0) {
      vec2.push_back(i);
      vec2.push_back(i);
    }
    else
      vec2.push_back(i);
  }

  if (vec != vec2) {
    cout << 0 << endl;
  } else {
    ll ans = 1;
    for (int i = n - 1; 0 < i; i -= 2)
      ans = ans * 2 % mod;
    cout << ans << endl;
  }
}


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

int main(){
    string S;
    cin >> S;
    string A="abcdefghijklmnopqrstuvwxyz";
    bool flag[26];
    for(size_t i=0;i<26;i++){
        flag[i] = false;
    }
    for(size_t i = 0;i < S.length();i++){
        for(size_t j = 0;j < 26;j++){
            if(S[i] == A[j]){
                if(flag[j]){
                    cout << "no";
                    return 0;
                }else{
                    flag[j] = true;
                }
            }
        }
    }
    cout << "yes";
    return 0;
}

Measured memory_bytes: 256
// F*** the exam

#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 200005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
    ll animal,leg;
    cin >> animal >> leg;
    for(ll i=0;i<=animal;i++)
    {
        ll sum = (i*2) + (animal-i)*4;
        if(sum==leg)  
        {
            cout<<"Yes\n";
            return;
        }
    }
    cout<<"No\n";
}

int main()
{
    FAST;
    ll t = 1;
 //   cin >> t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    string s; cin >> s;
    string t;
    s = "Q" + s + "Q";

    for(int i = (int)s.size() - 1; i > 0; i--){
        if(s[i] == 'C' && s[i - 1] == 'B'){
            t = t + "X";
            i--;
        }else if(s[i] == 'A') t = t + "A";
        else t = t + "G";
    }

    int cnt = 0;
    int ans = 0;
    for(int i = 0; i < (int)t.size(); i++){
        if(t[i] == 'A') ans += cnt;
        else if(t[i] == 'X') cnt++;
        else cnt = 0;
    }

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


Measured memory_bytes: 1420
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#define llint long long

using namespace std;
typedef pair<int, int> P;

struct BIT{
	int size;
	vector<llint> bit;
	BIT(){size = 0;}
	BIT(int s){
		size = s;
		bit.resize(size+1);
		init();
	}
	void init(){
		for(int i = 1; i <= size; i++) bit[i] = 0;
	}
	llint query(int i){
		llint ret = 0;
		while(i > 0){
			ret += bit[i];
			i -= i&(-i);
		}
		return ret;
	}
	void add(int i, llint x){
		while(i <= size){
			bit[i] += x;
			i += i&(-i);
		}
	}
};

llint n;
llint p[2005], a[2005], ainv[2005];
vector<int> G[2005];
llint depth[2005];
vector<llint> vec[2005];
vector<P> node;
int dest[2005];
bool used[2005], need[2005];
BIT bit[2005];
vector<int> ans;

void rotate(int s)
{
	int v = s, c, t;
	while(v != 1){
		ainv[a[v]] = p[v];
		v = p[v];
	}
	ainv[a[1]] = s;
	
	v = s, c = a[1];
	do{
		t = a[v];
		a[v] = c;
		c = t;
		v = p[v];
	}while(v != 0);
	
	v = s, c = false;
	do{
		t = need[v];
		need[v] = c;
		c = t;
		v = p[v];
	}while(v != 0);
	
	ans.push_back(s);
}

void depdfs(int v, int d)
{
	depth[v] = d;
	for(int i = 0; i < G[v].size(); i++){
		depdfs(G[v][i], d+1);
	}
}

int dfs(int v)
{
	int cnt = 0;
	for(int i = 0; i < G[v].size(); i++){
		if(used[G[v][i]]) continue;
		cnt++;
	}
	if(cnt == 0){
		vec[v].push_back(v);
		return v;
	}
	for(int i = 0; i < G[v].size(); i++){
		if(used[G[v][i]]) continue;
		int res = dfs(G[v][i]);
		if(cnt == 1 && res != -1){
			vec[res].push_back(v);
			return res;
		}
	}
	return -1;
}

int main(void)
{
	cin >> n;
	for(int i = 2; i <= n; i++){
		cin >> p[i];
		p[i]++;
		G[p[i]].push_back(i);
	}
	for(int i = 1; i <= n; i++) cin >> a[i], a[i]++;
	for(int i = 1; i <= n; i++) ainv[a[i]] = i;
	
	depdfs(1, 0);
	for(int i = 1; i <= n; i++) node.push_back(P(depth[i], i));
	sort(node.rbegin(), node.rend());
	
	for(int i = 1; i <= n; i++) bit[i] = BIT(2005);
	
	while(!used[1]){
		dfs(1);
		llint rem = 0;
		for(int i = 1; i <= n; i++){
			if(used[i]) continue;
			if(vec[i].size() == 0) continue;
			reverse(vec[i].begin(), vec[i].end());
			for(int j = 0; j < vec[i].size(); j++){
				int x = vec[i][j];
				need[ainv[x]] = true;
				used[x] = true;
				dest[x] = i;
				rem++;
			}
		}
		llint k = 0;
		while(rem){
			if(need[1]){
				int d = dest[a[1]];
				int cnt = bit[d].query(n+1) - bit[d].query(a[1]);
				int v = vec[d][(int)vec[d].size()-1-cnt];
				bit[d].add(a[1], 1);
				rotate(v);
				rem--;
			}
			else{
				int v = node[k].second;
				if(need[v]) rotate(v);
				k++;
			}
		}
	}
	
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++) cout << ans[i]-1 << endl;
	
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}

using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

constexpr char sp = ' ';
constexpr char cmm = ',';
constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s<<'[';for(size_t i=0;i<v.size();++i){s << v[i];if(i < v.size()-1) s << ", ";}s<<']';return s;
}
struct __f{
    __f(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    }
};


vector<vector<int>> G;
vector<int> ans;
vector<int> e;

void dfs(int i){
    int m = 0;
    for(int c : G[i]){
        if(ans[i] == ++m) ++m;
        ans[c] = m;
        dfs(c);
    }
}

int main(){

    int n;
    scanf("%d", &n);
    G.resize(n);
    ans.resize(n, 0);
    e.resize(n-1);

    rep(i, n-1){
        int a, b;
        scanf("%d%d", &a, &b);  
        --a; --b;
        G[a].emplace_back(b);
        e[i] = b;
    }
    
    dfs(0);

    ppp(*max_element(ans.begin(), ans.end()));
    for(int edge : e)
        ppp(ans[edge]);
    

    return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}
int main() {
  int n, x, a, ans = 0;
  cin >> n >> x;
  rep(i,n)
  {
    cin >> a;
    a = abs(x - a);
    if (ans) {
      ans = gcd(ans, a);
    } else {
      ans = a;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <fstream>
#define F first
#define S second
#define PI 3.141592653589793238
#define pb push_back

using namespace std;

//doesn't work for arrays
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i,j,tt=1;
    //cin>>tt;
    while(tt--)
    {
        lli n,k;
        cin>>n>>k;
        vector<lli> a(n);
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        j=0;
        for(i=k;i<n;i++)
        {
            if(a[i]>a[j])
                cout<<"Yes\n";
            else
                cout<<"No\n";
            j++;
        }
    }
    return 0;
}


Measured memory_bytes: 4760
<?php
fscanf(STDIN, "%s", $A);
fscanf(STDIN, "%s", $B);
if (strlen($A) > strlen($B)) {
    echo 'GREATER';
} elseif(strlen($A) < strlen($B)) {
    echo 'LESS';
} else {
    for ($i = 0; $i < strlen($A); $i++) {
        if ((int)$A[$i] > (int)$B[$i]) {
            echo 'GREATER';
            break;
        } elseif ((int)$A[$i] < (int)$B[$i]) {
            echo 'LESS';
            break;
        } elseif($i + 1 === strlen($A)) {
            echo 'EQUAL';
        }
    }
}

Measured memory_bytes: 3828
package main

import (
	"fmt"
)

func main() {
	var (
		n, m int
		s    string
	)
	fmt.Scanf("%d %d", &n, &m)
	if n == m {
		s = "Yes"
	} else {
		s = "No"
	}
	fmt.Printf("%s\n", s)
}


Measured memory_bytes: 512
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count=0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if x==500*i + 100*j + 50*k:
        count+=1
print(count)

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import java.math.BigInteger;

@SuppressWarnings("unchecked")
public class Main {

	static boolean fileIO = false;
	static boolean DEBUG = false;



	final static int INF = 0x7FFFFFFF;
	final static int MOD = (int)(1 << 30);
	final static int EPS = (int)1e6;

	final static String input = "input.txt";
	final static String output = "output.txt";

	public static void main(String args[]) throws IOException {
		InputStream is = null;
		OutputStream os = null;
		if (fileIO) {
			is = new FileInputStream(input);
			os = new FileOutputStream(output);
		} else {
			is = System.in;
			os = System.out;
		}
		InputReader in = new InputReader(is);
		PrintWriter out = new PrintWriter(os);
		new Task_A().solve(in, out);
		out.close();
	}


	static class Task_A {

		public void solve(InputReader in, PrintWriter out) {
			int a[][] = new int[2][3];
			char row1[] = in.nextString().toCharArray();
			char row2[] = in.nextString().toCharArray();
			for (int j = 0; j < 3; ++j) {
				a[0][j] = row1[j];
				a[1][j] = row2[j];
			}
			int b[][] = new int[2][3];
			b[1][1] = a[0][1];
			b[0][1] = a[1][1];
			b[1][2] = a[0][0];
			b[0][0] = a[1][2];
			b[1][0] = a[0][2];
			b[0][2] = a[1][0];
			boolean ans = true;
			for (int i = 0; i < 2; ++i) {
				for (int j = 0; j < 3; ++j) {
					if (a[i][j] != b[i][j]) {
						ans = false;
					}
				}
			}
			out.println(ans ? "YES" : "NO");
		}
	}




	static class InputReader {

		private StringTokenizer tokenizer;
		private BufferedReader reader;

		public InputReader(InputStream is) {
			tokenizer = null;
			reader = new BufferedReader(new InputStreamReader(is), 32768);

		}

		public String nextString() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					String line = reader.readLine();
					if (line == null) return null;
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public String nextLine() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					String line = reader.readLine();
					if (line == null) return null;
					tokenizer = new StringTokenizer(line, "\n");
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public Integer nextInt() { return Integer.parseInt(nextString()); }
		public Integer[] nextIntArray(int n) {
			Integer ret[] = new Integer[n];
			int i = 0;
			while (n-- > 0) ret[i++] = nextInt();
			return ret;
		}
		public Long nextLong() { return Long.parseLong(nextString()); }
		public Long[] nextLongArray(int n) {
			Long ret[] = new Long[n];
			int i = 0;
			while (n-- > 0) ret[i++] = nextLong();
			return ret;
		}
	}
}

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

int main(){
    double x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double ans = (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2);
    cout << fixed << sqrt(ans) << endl;
}

Measured memory_bytes: 3272
#include<stdio.h>

char shop[5]={'A','B','C','D','E'};

void doit(){
  int s1[5];
  int s2[5];
  int a[5];
  int t=0;
  int i;
  int tmp;
  scanf("%d %d",&s1[0],&s2[0]);
  if(s1[0]!=0){
    a[0]=s1[0]+s2[0];
    tmp=a[0];
    for(i=1;i<5;i++){
      scanf("%d %d",&s1[i],&s2[i]);
      a[i]=s1[i]+s2[i];
      if(tmp<a[i]){
	tmp=a[i];
	t=i;
      }
    }
    printf("%c %d\n",shop[t],a[t]);
    doit();
  }
}

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

Measured memory_bytes: 612
ac = 0
tle = 0
wa = 0;re=0;
for _ in range(int(input())):
    x = input()
    if(x=='AC'):ac+=1
    elif(x=='TLE'):tle+=1    
    elif(x=='WA'):wa+=1
    else:re+=1
    
print("AC x {}".format(ac))
print("WA x {}".format(wa))
print("TLE x {}".format(tle))
print("RE x {}".format(re))


Measured memory_bytes: 9048