akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	int res = 1000000;
	int ans = 0;
	rep(i, n) {
		if (i == 0) {
			res = p[i];
			continue;
		}
		if (res < p[i]) ans++;
		res = min(res, p[i]);
	}

	dunk(n - ans);

	return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict

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

DP = [0] * (10 ** 6 + 1)

A.sort()
Sum = 0

d = defaultdict(int)
for key in A:
    d[key] += 1

for i in range(N):

    if DP[A[i]] == 0:
        for j in range(1, 10 ** 6):
            if A[i] * j <= 10 ** 6:
                DP[A[i] * j] = 1
            else:
                break

        if d[A[i]] == 1:
            Sum += 1
print(Sum)


Measured memory_bytes: 133420
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  vector<int> h(5);
  for(int i = 0; i<5; i++){
    int temp;
    cin >> temp;
    h[i] = temp;
  }
  int k;
  cin >> k;

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

  if(h[4]-h[0] > k){
    cout << ":(" << endl;
  } else{
    cout << "Yay!" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
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();
		Integer l[] = new Integer[N];
		for(int i=0; i<N; i++){
			l[i] = sc.nextInt();
		}
 		sc.close();
 		
 		Arrays.sort(l, Collections.reverseOrder());	
 		int ans = 0;
 		for(int i=0; i<K; i++ ){
 			ans += l[i];
 		}
		
 		System.out.println(ans);

	}

}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define MAX 100000
using namespace std;
int n, A[MAX + 1], L[MAX];
int lis()
{
    L[0] = A[0];
    int l=1;
    for(int i=1; i<n; i++){
        if (L[l - 1] < A[i])
        {
            L[l++] = A[i];
        }
        else
        {
            *lower_bound(L, L + l, A[i]) = A[i];
        }
    }
    return l;
}
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> A[i];
    cout << lis() << endl;
}


Measured memory_bytes: 3876
N = int(input())

res = []
x = N
y = 2
while y*y <= x:
    while x % y == 0:
        res.append(y)
        x //= y
    y += 1
if x > 1:
    res.append(x)

ans = 0
# 10**12 < 2 ** 40
while res:
    nn = res.pop()
    ans += 1
    for i in range(2,41,1):
        cnt = res.count(nn)
        if i <= cnt:
            ans +=1
            for _ in range(i):
                res.remove(nn)
        else:
            res = [i for i in res if i != nn]

print(ans)


Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, N, A[100001] = {}, ans = 0;
  
  cin >> N;
  
  for (int i = 0; i < N; i++){
    cin >> a;
    for (int j = -1; j <= 1; j++) if (0 <= a+j && a+j <= 100000) A[a+j]++;
  }
  
  for (int i = 0; i < 100001; i++) ans = max(ans, A[i]);
  
  cout << ans << endl;
  
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

#define INF (1 << 30)
#define MAX_V 200

int cost[MAX_V][MAX_V];
bool used[MAX_V];
long long int d[MAX_V];
int V;// V???????????°

// O(V^2)??§?????????????????£??¨??????

void shortest_path(int s){
	for(int i = 0; i < V; i++){
		d[i] = INF;
		used[i] = false;
	}
	d[s] = 0;
	while(true){
		
		int add_v = -1;
		
		for(int u = 0; u < V; u++){
			if(!used[u] && (add_v == -1 || d[u] < d[add_v])){
				add_v = u;
			}
		} // ??´??°????????????????±????
		
		if(add_v == -1){
			break;
		} // ??´??°???????????????????????´????????????
		used[add_v] = true;
		
		for(int u = 0; u < V; u++){
			d[u] = min(d[u], d[add_v] + cost[add_v][u]);
		} // ???????????????????????????????°???????????????´??°
	}
}

int main(){
	
	int n, k;
	
	while(true){
		
		cin >> n >> k;
		
		if(n == 0 && k == 0){
			break;
		}
		
		V = n + 1;
		
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				cost[i][j] = INF;
			}
		}
		
		for(int loop = 0; loop < k; loop++){
			int mode;
			int a, b, from, to, c;
			cin >> mode;
			if(mode == 0){
				cin >> a >> b;
				shortest_path(a);
				if(d[b] >= INF){
					printf("-1\n");
				}else{
					printf("%lld\n", d[b]);
				}
			}else if(mode == 1){
				cin >> from >> to >> c;
				if(cost[from][to] > c){
					cost[from][to] = c;
					cost[to][from] = c;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1228
n,m=map(int,input().split())
a=set(map(int,input().split()))
b=set(map(int,input().split()))
c=1;N=0;M=0
for k in range(m*n,0,-1):
  if k in a and k in b:
    N+=1;M+=1
  elif k in a:
    c*=M;N+=1
  elif k in b:
    c*=N;M+=1
  else:
    c*=M*N-m*n+k
  c=c%(10**9+7)
print(c)

Measured memory_bytes: 3188
n,k = map(int,input().split())
hate_nums = list(input().split())
affordable = n

while True:
    is_hate = False
    for digit in list(str(affordable)):
        if digit in hate_nums:
            is_hate = True
    if is_hate:
        affordable += 1
    else:
        print(affordable)
        break

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include <algorithm>
using namespace std;
using ll = long long;

typedef pair<ll,ll> P;
 


int main(void){
    int N;
    cin >>N;
    ll ans=0;
    for(int a=1;a<N;a++){
        ans+=(N-1)/a;
    }
    cout <<ans<<endl;


    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
 
int main(void)
{
    int n ,j ,i ,o ,cnt=1;
    scanf("%d",&n);
    for(j=0;j<n;j++){
        scanf("%d %d" ,&i ,&o);
        printf("%d" ,i);
        if(i<o||(i>5&&i<10)){
            while(1){
                if(i>=9){
                    i=6;
                    cnt *= -1;
                }
                if(i==0&&cnt<0){
                    cnt *= -1;
                }
                i += cnt;
                printf(" %d" ,i);
                if(i==o){
                    cnt = 1;
                    break;
                }
            }
            puts("");
        }else if(i==o){
            puts("");
        }else{
            cnt *= -1;
            while(1){
                i += cnt;
                printf(" %d" ,i);
                if(i==o){
                    cnt = 1;
                    break;
                }
            }
            puts("");
        }
    }
    return 0;
}

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

typedef long long int ll;



int main(){
  ll n;
  cin>>n;
  map <ll,ll> m;
  ll i;
  vector <ll> a(n+1);
  for(i=1;i<=n;i++){
    ll x;
    cin>>x;
    a[i]=x;
    m[a[i]+i]++;
  }
  ll ans=0;
  for(i=n;i>=1;i--){
    ans+=m[i-a[i]];
  }
  cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 27456
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

/** 素因数分解
 */
template<typename T>
std::map<T, size_t>&
factor( T n, const std::vector<T>& primes, std::map<T, size_t>& ret) {
    auto f = primes.begin();
    while (n > 1) {
        while (n % *f == 0) {
            ret[*f] = ret[*f] + 1;
            n /= *f;
        }
        ++f;
    }

    return ret;
}


int main()
{
    int64_t N;
    std::cin >> N;

    int64_t noTwo = 0;
    int64_t two = 0;
    int64_t four = 0;

    std::vector<int64_t> A;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        if (t % 4 == 0) {
            four++;
        }
        else if (t % 2 == 0) {
            two++;
        }
        else {
            noTwo++;
        }
    }

    if (noTwo <= four || ((noTwo <= four+1) && (two %2) == 0)) {
        std::cout << "Yes" << std::endl;
    }
    else {
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
c(char*a,char*b){return *a-*b;}r(char*a,char*b){return *b-*a;}s[2][30];n;main(m){scanf("%s%s",s,s[1]);n=strlen(s);m=strlen(s[1]);qsort(s,n,1,c);qsort(s[1],m,1,r);puts(bcmp(s,s[1],n>m?n:m)<0?"Yes":"No");}

Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in(),m=in(),x=in();
    vector<ll>c(n);
    auto a=vec2<ll>(n,m);
    for(ll i=0;i<n;++i){
        c[i]=in();
        for(ll j=0;j<m;++j)a[i][j]=in();
    }
    
    constexpr ll maxi=100000000;
    ll ans=maxi;
    for(ll p2=(1<<n)-1;p2>=0;--p2){
        ll money=0;
        vector<ll>rikai(m);
        for(ll i=0;i<n;++i){
            if((p2>>i)&1){
                money+=c[i];
                for(ll j=0;j<m;++j)rikai[j]+=a[i][j];
            }
        }
        if(all_of(rikai.begin(),rikai.end(),[x](ll foo){return foo>=x;}))ans=min(ans,money);
    }
    cout<<(ans==maxi?-1:ans)<<endl;
}


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

public class Main implements Runnable {
	public static void main (String[] args) {new Thread(null, new Main(), "_cf", 1 << 28).start();}

	char[] str;
	int n;
	int[][] dp;
	
	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		str = fs.next().toCharArray();
		n = str.length;
		dp = new int[13][n];
		for(int[] d : dp) Arrays.fill(d, -1);
		out.println(solve(0, 0));
		
		out.close();
	}
	
	int MOD = (int)1e9+7;
	int solve(int rem, int idx) {
		if(idx >= n) {
			return rem == 5 ? 1 : 0;
		}
		if(dp[rem][idx] != -1) return dp[rem][idx];
		if(str[idx] != '?') {
			int nrem = (10*rem+(str[idx]-'0'))%13;
			return dp[rem][idx] = solve(nrem, idx+1);
		}
		int res = 0;
		for(int k = 0; k < 10; k++) {
			int nrem = (10*rem+k)%13;
			int ret = solve(nrem, idx+1);
			res += ret;
			if(res >= MOD) res -= MOD;
		}
		return dp[rem][idx] = res;
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}

Measured memory_bytes: 40728
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define ll long long
const long long INF = 1LL << 60;

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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(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);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}



int main() {
	ll N, M;
	cin >> N >> M;
	ll f = 2;
	vector<ll>fac;
	while (M != 1) {
		if (M%f == 0) {
			M /= f;
			fac.push_back(f);
		}
		else {
			f++;
		}
	}
	map<ll, ll> ma;
	for (int i = 0; i < fac.size(); i++)ma[fac[i]]++;
	ll ans = 1;
	for (auto itr : ma) {
		ans *= nCr(itr.second + N - 1, itr.second, MOD);
		ans %= MOD;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>

#define pb push_back
#define FOR(i, a, b) for(int i=a, _n=b; i<=_n; ++i)
using namespace std;

const int N = 2e3+5, INF = 1e9;
int n, f[N], s[N], d[N], par[N];
vector<int> ke[N];
char a[N];

void dfs(int u)
{
    int sm = 0, ma = 0, mf = INF;
    f[u] = 0; s[u] = 0; d[u] = a[u]-'0';

    for(int v: ke[u]) if (v != par[u]) {
        par[v] = u; dfs(v);

        sm += s[v]+d[v];
        if (ma <= s[v]+d[v]) {
            if (ma == s[v]+d[v])
                mf = min(f[v], mf); else
                mf = f[v], ma = s[v]+d[v];
        }
        d[u] += d[v]; f[u] += f[v];
    }

    if (ma > sm-ma && ma+ma-sm > 2*(f[u]-mf)) {
        f[u] += sm-ma;
        s[u] = ma+ma-sm;
    } else {
        f[u] += sm/2;
        s[u] = sm%2;
    }
}
int main()
{
    ios::sync_with_stdio(); cin.tie(0);

    cin >> n >> (a+1);
    FOR(i, 1, n-1) {
        int u, v;
        cin >> u >> v;
        ke[u].pb(v);
        ke[v].pb(u);
    }

    int ans = INF;
    FOR(i, 1, n) {
        par[i] = 0; dfs(i);
        if (!s[i]) ans = min(ans, f[i]);
        ///cout << i <<' ' << f[i] <<' '<< s[i] << endl;
    }
    if (ans == INF) ans = -1;
    cout << ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MOD 100000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    string S;
    int Q;
    bool hantenMode = false;
    cin >> S >> Q;
    FOR(i, 0, Q){
        int T;
        cin >> T;
        if(T == 1){
            hantenMode = !hantenMode;
        }else{
            int F;
            string c;
            cin >> F >> c;
            if(F == 1) hantenMode ? S.append(c) : S.insert(0, c);
            else S = hantenMode ? S.insert(0, c) : S.append(c);
        }
        //cout << S << endl;
    }

    if(hantenMode){
        for(int i = S.length() - 1; i >= 0; i--){
            cout << S[i];
        }
        cout << endl;
    }else{
        cout << S << endl;
    }

    return 0;
}


Measured memory_bytes: 900
n,m,l = map(int,input().split())
A=[]
B=[]
for i in range(n): A.append(list(map(int,input().split())))
for j in range(m): B.append(list(map(int,input().split())))
for A_r in A:
    print(" ".join(map(str,[sum([x*y for x,y in zip(A_r,[B_r[k] for B_r in B])]) for k in range(l)])))

Measured memory_bytes: 6320
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

typedef long long i64;

int main(int argc, const char *argv[]) {
	string S;
	i64 K;
	getline(cin, S);
	cin >> K;

	i64 N = S.size();
	vector<i64> Cs;
	i64 C = 1;
	for(int i=0;i<S.size()-1;++i) {
		if(S[i] == S[i+1]) {
			++C;
		}
		else {
			Cs.push_back(C);
			C = 1;
		}
}
Cs.push_back(C);

/*
 for(auto C: Cs) {
   cout << C << endl;
 }
*/
 
i64 ans;
if (Cs.size() == 1) {
	ans = (K * S.size()) / 2;
}
else if (S[0] == S[N-1]) {
  ans = 0;
  for(auto it=Cs.begin()+1;it!=Cs.end()-1;++it) {
    ans += ((*it) / 2) * K;
  }
  ans += Cs[0] / 2 + Cs.back() / 2 + ((Cs[0] + Cs.back()) / 2) * (K-1);
}
else {
  ans = 0;
  for(auto it=Cs.begin();it!=Cs.end();++it) {
    ans += ((*it) / 2) * K;
  }
}
cout << ans << endl;
}


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

int main() {
  //freopen("input.txt", "r", stdin);
  int a,b;
  while(cin>>a>>b) {
    if(a<=b) {
      for(int i=0; i<b; i++) {
	cout<<a;
      }
      cout<<endl;
    } else {
      for(int i=0; i<a; i++) {
	cout<<b;
      }
      cout<<endl;
    }
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
ll N,K; cin >> N >> K; ll sum = 0;
  
  ll m = N / K; sum += pow(m,3.0);
  
  if( K % 2 == 0){ ll n = ( N + K / 2) / K; sum += pow(n,3.0);}
  
  cout << sum << endl; return 0;}
  

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    int answer = 0;
    for (int i = 0; i < a.size(); i++) {
        if (i % 2 == 0) {
            answer += a.at(i);
        } else {
            answer -= a.at(i);
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O #-}

import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.List
import Control.Monad.Trans.State.Strict
import Data.Char (isSpace)
import Data.Maybe (fromJust,fromMaybe,isNothing,isJust)
import qualified Data.ByteString.Lazy.Char8 as B

import Data.Array.ST
import Data.Array.Unsafe
import Data.Array

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT (B.readInt . B.dropWhile isSpace)

parseInt2 :: Parser (Int,Int)
parseInt2 = liftM2 (,) parseInt parseInt

parseInt3 :: Parser (Int,Int,Int)
parseInt3 = liftM3 (,,) parseInt parseInt parseInt

parse :: Parser ((Int,Int), [(Int,Int,Int)])
parse = do
    (n,m)<-parseInt2
    rs<-replicateM m parseInt3
    return ((n,m),rs)

main=do
    ((n,m),rs)<-fromJust.evalStateT parse <$> B.getContents
    let da = wf n rs :: Array (Int,Int) (Maybe Int)
    print $ length $ filter (\(a,b,c)-> fmap (< c) (da!(a,b)) == Just True) rs

wf::Int->[(Int,Int,Int)]->Array (Int,Int) (Maybe Int)
wf n rs = runST $ do
    d <- newArray ((1,1),(n,n)) Nothing :: ST s (STArray s (Int,Int) (Maybe Int))
    forM_ [1..n] $ \v -> writeArray d (v,v) (Just 0)
    forM_ rs $ \(u,v,l) -> writeArray d (u,v) (Just l) >> writeArray d (v,u) (Just l)
    forM_ [(k,i,j)|k<-[1..n],i<-[1..n],j<-[1..n]] $ \(k,i,j) -> do
        dc <- readArray d (i,j)
        dn <- liftA2 (+) <$> readArray d (i,k) <*> readArray d (k,j)
        when (isNothing dc || liftA2 (>) dc dn == Just True) $ writeArray d (i,j) dn
    freeze d


Measured memory_bytes: 2428
int main(void)
{
	int skin=100000;
	int skin2;
	int shu;
	int i;
	scanf("%d",&shu);
	for(i=0;shu>i;i++){
		skin=skin*1.05;
	if(skin%1000!=0){
		skin2=skin%1000;
		skin=skin-skin2+1000;
	}
	}
		printf("%d\n",skin);
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>

#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
double start_moment = 0;
double get_runtime() { return 1.0*clock()/CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime(){cout<<fixed<<setprecision(5)<<get_runtime()<<'\n';}
 
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
 
template <class T>void read(vector<T> &a,ll n){T x; a.clear();for(ll i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}

int n;
vector<int> a;
set<int> have;

int gcd(int a,int b)
{
    if(!b) return a;
    return gcd(b,a%b);
}


int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt","r",stdin);
//    freopen("OUTPUT.txt", "w", stdout);
    
    cin>>n;
    read(a,n);
    
    bool ok1=1;
    bool ok2=1;
    
    int g=a[0];
    for(int i=1;i<a.size();i++)
        g=gcd(g,a[i]);
    if(g!=1)
        ok2=0;
    
    for(int i=0;i<n && ok1;i++)
    {
        for(int j=2;j*j<=a[i];j++)
            if(a[i]%j==0)
            {
                while(a[i]%j==0)
                    a[i]/=j;
                if(have.count(j))
                    ok1=0;
                have.insert(j);
            }
        if(a[i]>1)
        {
            if(have.count(a[i]))
                ok1=0;
            have.insert(a[i]);
        }
    }
    
    
    if(ok1)
        cout<<"pairwise coprime";
    else if(ok2)
        cout<<"setwise coprime";
    else
        cout<<"not coprime";
    
}


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

const int N = (int) 1e5 + 5;
const int INF = (int) 1e9 + 5;

int n;
int dp[N];

int main() {
	//freopen(".inp", "r", stdin); freopen(".out", "w", stdout);
	cin >> n;
	fill(dp, dp + n + 5, INF);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + 1);
		for (int x = 6; i + x <= n; x *= 6) dp[i + x] = min(dp[i + x], dp[i] + 1);
		for (int x = 9; i + x <= n; x *= 9) dp[i + x] = min(dp[i + x], dp[i] + 1);
	}
	cout << dp[n];
	return 0;
}

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

int main(void){
  int N;
  int A[110];
  int i, j, k;
  int max = 0;
  int buf;
  scanf("%d", &N);
  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
  }
  for(i = 0; i < N; i++){
    for(j = i+1; j < N; j++){
      buf = abs(A[i] - A[j]);
      if(buf > max){
        max = buf;
      }
    }
  }
  printf("%d\n", max);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
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; }

int n;
int main() {
    cin >> n;
    vector<long long> a(n, 0);
    for(int i = 0; i < n; ++i) cin >> a.at(i);
    long long sum = 0;
    long long ansp = 0;
    int check = 0;
    for(int i = 0; i < n; ++i) {
        long long nowp = a.at(i);
        sum += nowp;
        if(i % 2 == 0) {
            check = 1;
            if(sum > 0) {
                ansp += 0;
            }else {
                ansp += abs(sum-check);
                sum = check;
            }
        }else {
            check = -1;
            if(sum < 0) {
                ansp += 0;
            }else {
                ansp += abs(sum-check);
                sum = check;
            }
        }
    }

    long long ansm = 0;
    sum = 0;
    for(int i = 0; i < n; ++i) {
        long long nowm = a.at(i);
        sum += nowm;
        if(i % 2 == 0) {
            check = -1;
            if(sum < 0) {
                ansm += 0;
            }else {
                ansm += abs(sum-check);
                sum = check;
            }
        }else {
            check = 1;
            if(sum > 0) {
                ansm += 0;
            }else {
                ansm += abs(sum-check);
                sum = check;
            }
        }
    }

    // cout << ansp << " " << ansm << endl;

    cout << min(ansp, ansm) << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdint>
#include <vector>
#include <string>

int main() {
  size_t a, b;
  scanf("%zu %zu", &a, &b);
  --a, --b;

  size_t n = 100;
  std::vector<std::string> s(n);
  for (size_t i = 0; i < n/2; ++i)
    s[i] = std::string(n, '#');
  for (size_t i = n/2; i < n; ++i)
    s[i] = std::string(n, '.');

  {
    size_t i = 0;
    size_t j = 0;
    while (a--) {
      s[i][j] = '.';
      j += 2;
      if (j >= n) {
        i += 2;
        j = 0;
      }
    }
  }
  {
    size_t i = n/2 + 1;
    size_t j = 0;
    while (b--) {
      s[i][j] = '#';
      j += 2;
      if (j >= n) {
        i += 2;
        j = 0;
      }
    }
  }

  printf("%zu %zu\n", n, n);
  for (auto const& si: s)
    printf("%s\n", si.c_str());
}


Measured memory_bytes: 256
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)


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

    int n; cin >> n;
    ll a,b,a_max = -1, b_last;
    rep(i,n){
        cin >> a >> b;
        if(a_max < a){
            a_max = a;
            b_last = b;
        }
    }
    cout << a_max + b_last << endl;
}

Measured memory_bytes: 256
def main():
    n, s = int(input()), input()

    cnt, f = 0, 0
    for i in range(n):
        if s[i] == "(":
            cnt += 1
        else:
            cnt -= 1
            if cnt < 0:
                f += 1
                cnt = 0

    ans = f * "(" + s + cnt * ")"
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    
    if(c<b && b<=d && a<=c){
    	System.out.println(b-c);
    }else if(c<b && d<b && a<=c){
    	System.out.println(d-c);
    }else if(c<a && a<d && d<=b){
    	System.out.println(d-a);
    }else if(c<a && a<d && b<d){
    	System.out.println(b-a);
    }else{
    	System.out.println(0);
    }
  }
}

Measured memory_bytes: 24916
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    #[allow(dead_code)]
    pub fn ctoi(c: char) -> i64 {
        c as i64 - 48
    }
}

#[allow(unused_imports)]
use util::*;

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        s:String
    }
    let t = match s.as_str() {
        "Sunny" => "Cloudy",
        "Cloudy" => "Rainy",
        "Rainy" => "Sunny",
        _ => unreachable!()
    };
    println!("{}", t);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int in(){int x; scanf("%d",&x); return x;}
static const int MAX = 100;


int main() {
  double W, H, x, y;
  cin >> W >> H >> x >> y;

  cout << W*H / 2 << " " << (x*2 == W && y*2 == H ? "1" : "0") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    string t;
    cin >> t;
    int n = t.size();
    for(int i = 0; i < n; i++){
        if(t[i] == '?') t[i] = 'D';
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3748
"use strict";
    
const main = arg => {
    let A = parseInt(arg.split("\n")[0].split(" ")[0]);
    let B = parseInt(arg.split("\n")[0].split(" ")[1]);
    
    if(A == 1) A = 14;
    if(B == 1) B = 14;
    
    if(A == B) {
        console.log("Draw");
    } else if(A > B) {
        console.log("Alice")
    } else {
        console.log("Bob")
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
k, n = map(int, input().split())
h_list = list(map(int, input().strip().split()))

d = h_list[0] + k - h_list[n - 1]
for i in range(n - 1):
    d = max(d, h_list[i + 1] - h_list[i])
out = k - d
print(out)

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=300005;
int n;
int p[maxn];

class Fenwick{
public:
	int t[maxn];
	void add(int v,int val){
		for(;v<=n;v+=(v&-v))t[v]+=val;
	}
	int sum(int v){
		int res=0;
		for(;v;v-=(v&-v))res+=t[v];
		return res;
	}
}Tree[2];

int main(){
	scanf("%d",&n);
	bool ok=true;
	int last=-2,lastval=-1,plast[2]={-1,-1};
	REP(i,n){
		scanf("%d",&p[i]);
		ok&=((i&1)==(p[i]&1));
		int ori=p[i];
		ori+=2*((i-1)/2-Tree[i&1].sum(p[i]));
		if(i<ori){
			ok&=(i>plast[(i+1)&1]);
			ok&=(i>last+1);
			ok&=(p[i]>lastval);
			last=i;
			lastval=p[i];
			plast[i&1]=ori;
		}
		Tree[i&1].add(p[i],1);
	}
	puts(ok?"Yes":"No");
	return 0;
}

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

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

    ll ans = 0;
    ans += (X/500) * 1000LL;
    X %= 500;
    ans += (X/5)*5;

    cout << ans << endl;
}


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

//まずK種類のネタを選ぶことを考える。このとき選ぶネタのは各ネタを美味しさの大きい順に
//ならべた時の最大値。
//残りを大きい順に見ていきネタの種類を減らしても美味しさが大きくなるか調べる。

int main(){
    ll N,K;
    cin >> N >> K;
    vector<vector<ll> > sushi(N);
    rep(i,N){
        int t,d;cin >> t >> d;
        t--;
        sushi[t].push_back(d);
    }
    for(auto &e : sushi){
        sort(e.rbegin(),e.rend());
        if(e.empty())e.push_back(-INF);
    }
    sort(sushi.begin(),sushi.end(),[&](vector<ll> a, vector<ll> b){return a[0]>b[0];});
    //まずK種類選ぶ
    ll cur = 0;
    priority_queue<ll> que;
    rep(i,K){
        cur += sushi[i][0];
        for(int j = 1; j < sushi[i].size();j++)que.push(sushi[i][j]);
    }
    for(int i = K; i < N; i++)rep(j,sushi[i].size())que.push(sushi[i][j]);

    //最大値を更新していく
    ll res = cur + K*K;
    for(ll x = K-1; x >= 1; --x){
        ll v = sushi[x][0];
        ll w = que.top();
        if(v < w){
            que.pop();cur += w;
            que.push(v); cur -= v;
        }
        res = max(res,cur + x*x);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8696
#include <stdio.h>

int main()
{
	int n;
	int i;
	double x1,x2,x3,x4;
	double y1,y2,y3,y4;
	double a1,a2;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%lf %lf",&x1,&y1);
		scanf("%lf %lf",&x2,&y2);
		scanf("%lf %lf",&x3,&y3);
		scanf("%lf %lf",&x4,&y4);
		a1=a2=0;
		if(x2-x1==0 || x4-x3==0){
			if(x2-x1==0 && x4-x3==0){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
		}
		else if(x2-x1==0||x4-x3==0){
			printf("NO\n");
		}
		else if(x2-x1!=0&&x4-x3!=0){
			a1=(y2-y1)/(x2-x1);
			a2=(y4-y3)/(x4-x3);
			if(a1==a2){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main{
    public static void main(String[] args){
	Scanner in = new Scanner(System.in);
	double x1,x2;
	double y1,y2,result;

	x1 = in.nextDouble();
	y1 = in.nextDouble();
	x2 = in.nextDouble();
	y2 = in.nextDouble();

	result = Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2));
	System.out.printf("%.8f\n",result);
    }
}



Measured memory_bytes: 28200
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
 
    while(cin>>n)
    {
        int a,b;
        cin>>a>>b;
 
        if(n==1)
            cout<<"Hello World"<<endl;
        else
            cout<<a+b<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define fi first
#define se second
const int N=55;
int f[N],n,m,ans;
int gf(int x)
{
	return f[x]==x?x:f[x]=gf(f[x]);
}
pair<int,int>a[N];
int main()
{
	cin>>n>>m;
	for (int i=1;i<=m;i++)
		cin>>a[i].fi>>a[i].se;
	for (int i=1;i<=m;i++)
	{
		for (int j=1;j<=n;j++)
			f[j]=j;
		for (int j=1;j<=m;j++)
			if (j!=i)
				f[gf(a[j].fi)]=gf(a[j].se);
		for (int j=2;j<=n;j++)
			if (gf(j)!=gf(1))
			{
				ans++;
				break;
			}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int  n,x;
  vector< pair<int,int> > v;
  cin>>n;
  for(int i=1 ; i <= n ; i++){
  	cin>>x;
    v.push_back(make_pair(x,i));
  }
  sort(v.begin(),v.end());
  for(int i=0 ; i < v.size() ; i++){
  	cout<<v[i].second<<" ";
  }
  
return 0;
}

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

int main(){
    int N,X;
    cin >> N >> X;
    int L[N];
    for(int i = 0;i<N;i++){
        cin >> L[i];
    }

    int count = 1;
    int D = 0;
    for(int i = 0;i<N;i++){
        D += L[i];
        if(D > X)break;
        count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main(){
	int N; cin >> N;
	REP(i,10){
		if(i*111 < N and (i+1)*111 >= N) cout << (i+1)*111 << endl;
	}
}


Measured memory_bytes: 256
#!/usr/bin/perl

my ($n) = map {$_ - 0} split(/\s+/o,<STDIN>);

my %wc = ();
my $prev = '';
my $ans = 'Yes';
for(my $i=0;$i<$n;$i++){
  ( my $w = <STDIN> ) =~ s/[\x00-\x20]+$//io;
  if( ( ( $wc{$w} - 0 ) > 0 ) or ( $prev ne '' and substr($w,0,1) ne substr($prev,-1,1) ) ){
    $ans = 'No';
    last;
  }
  $wc{$w} = 1;
  $prev = $w;
}

print "$ans\n";
exit(0);


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

bool nums[11111];

int main() {
    int x, n;
    cin >> x >> n;
    for (int i = 0, p; i < n; i++) {
        cin >> p;
        nums[p] = true;
    }
    for (int i = 0; ; i++) {
        if (!nums[x - i]) {
            cout << x - i << endl;
            return 0;
        }
        if (!nums[x + i]) {
            cout << x + i << endl;
            return 0;
        }
    }
}

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

#define p pair<int,int>
#define f first
#define s second
#define ll long long
#define db double

const int maxn=1e6+10;
const int inf=1e9;
ll d[maxn],b[maxn],a[200][200];
int main()
{
    //ios::sync_with_stdio(0),cin.tie(0);
    ll n,m,k,per=1;
    cin>>n>>m>>k;
    for(int i=1;i<=k;i++)cin>>d[i];
    for(int i=1;i<=k;i++)
    {
        while(d[i])
       {
           b[per++]=i;
           d[i]--;
       }
    }
    //for(int i=0;i<per;i++)cout<<b[i]<<" ";
    ll tot=1,y,x;
    a[x = 0][y = m - 1] = b[1];
    while (tot < n * m)
    {
        while (x + 1 < n && !a[x + 1][y]) a[++x][y] = b[++tot];
        while (y - 1 >= 0 && !a[x][y - 1]) a[x][--y] = b[++tot];
        while (x - 1 >= 0 && !a[x - 1][y]) a[--x][y] = b[++tot];
        while (y + 1 < m && !a[x][y + 1]) a[x][++y] = b[++tot];
    }
    for (x = 0; x < n; x++) {
        for (y = 0; y < m; y++)
            printf("%lld ", a[x][y]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 4608
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using ll = long long;

using namespace std;

int main(){
	string s;
	cin >> s;
	
	string t = s;
	reverse(t.begin() , t.end());
	if(s == t){
		cout << 0 << endl;
		return 0;
	}
	
	vector<int> table(26,0);
	for(int i = 0; i < s.size(); i++){
		table[s[i]-'a']++;
	}
	
	int ng_cnt = 0;
	for(int i = 0; i < 26; i++){
		if(i == ('x'-'a'))continue;
		if(table[i] == 1){
			ng_cnt++;
			if(ng_cnt >= 2){
				cout << -1 << endl;
				return 0;
			}
		}
	}
	
	int ans = 0;
	int n = s.size();
	int l = 0;
	int r = n - 1;
	
	while(1){
		if(l >= r){
			cout << ans << endl;
			return 0;
		}
		if(s[l] == s[r]){
			l++;
			r--;
			continue;
		}
		if(s[l] == 'x'){
			ans++;
			l++;
			continue;
		}	
		if(s[r] == 'x'){
			ans++;
			r--;
			continue;
		}	
		if(s[l] != s[r]){
			cout << -1 << endl;
			return 0;
		}
	}
	return 0;
}
 

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

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
using namespace std;
using ll = long long;
using lld = long long;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

ll gcd(ll a, ll b)
{
  if (a < b)
  {
    return gcd(b, a);
  }
  while (b != 0)
  {
    ll tmp = b;
    b = a % b;
    a = tmp;
  }
  return a;
}

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

int bit_counter(int x) {
  if (x == 0) return 0;
  return bit_counter(x >> 1) + (x&1);
}


int main() {
  ll X, Y;
  cin >> X >> Y;

  ll tx = 2 * X - Y;
  ll ty = 2 * Y - X;

  if (tx%3 != 0 || ty%3 != 0) {
    print(0);
    return 0;
  }

  if (tx < 0 || ty < 0 ) {
    print(0);
    return 0;
  }

  tx /= 3;
  ty /= 3;

  ll result = 1;
  ll bb = tx + ty;
  ll bc = min(tx, ty);
  while(bc > 0) {
    result = (result * bb) % DIV;
    result = (result * modinv(bc, DIV)) % DIV;
    bb--;
    bc--;
  }
  print(result);
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using vl = vector<ll>;                   //   | grep -v ' .* '  1300111 ~2^20.31
using vvl = vector<vl>;                  //                    10300777 ~2^23.30
using pll = pair<ll,ll>;                 //                   100400999 ~2^26.58
using vb = vector<bool>;                 //                  1300400999 ~2^30.28
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //                 10200500333 ~2^33.25
const double eps = 1e-9;                 //                100200400777 ~2^36.54
#define sz(c) ll((c).size())             //               1200300700111 ~2^40.13
#define all(c) begin(c),end(c)           //              10200300500777 ~2^43.21
#define mp make_pair                     //             100200300400777 ~2^46.51
#define mt make_tuple                    //            1200300400600999 ~2^50.09
#define pb push_back                     //           10200300400600111 ~2^53.18
#define eb emplace_back                  //          100200300400600333 ~2^56.48
#define xx first                         //         1200300400500800999 ~2^60.06
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

vector<vector<ll> >  edges;
vl node_lengths_dp;

ll rec(ll node){
    if(edges[node].empty()){
        return 0;
    }
    if(node_lengths_dp[node] != 0){
        return node_lengths_dp[node];
    }
    ll res = 0;
    for(ll edge : edges[node]){
        res = max(res, rec(edge));
    }
    res++;
    node_lengths_dp[node] = res;
    return res;
}

int main() {

    ll n_v, n_e;
    cin >> n_v >> n_e;
    edges.assign(n_v, vector<ll>());
    node_lengths_dp.resize(n_v);
    FOR(i, 0, n_e){
       ll from, to;
       cin >> from >> to;
       edges[from-1].pb(to-1);
    }

    ll res = 0;
    FOR(i, 0, n_v){
        res = max(res, rec(i));
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 8576
#include <stdio.h>
#include <algorithm>

using std::max;
using std::min;

int main()	{
	
	int N, n, d, dx, dy, xmax, xmin, ymax, ymin;
	int xpos[200];
	int ypos[200];
	
	while (true)	{
		
		scanf("%d", &N);
		if (N == 0)	break;
		if (N == 1)	{
			printf("1\n");
			continue;
		}
		
		for (int i = 0; i < 200; i++)	{
			ypos[i] = 0;
			xpos[i] = 0;
		}
		xmax = 0;
		ymax = 0;
		xmin = 200;
		ymin = 200;
		
		for (int i = 1; i < N; i++)	{
			
			scanf("%d %d", &n, &d);
			
			// 上が正、右が正
			switch (d)	{
			case 0:
				dy = 0;
				dx = -1;
				break;
			case 1:
				dy = -1;
				dx = 0;
				break;
			case 2:
				dy = 0;
				dx = 1;
				break;
			case 3:
				dy = 1;
				dx = 0;
				break;
			}
			
			ypos[i] = ypos[n] + dy;
			xpos[i] = xpos[n] + dx;
		}
		
		for (int i = 0; i < N; i++)	{
			ymax = max(ymax, ypos[i]);
			xmax = max(xmax, xpos[i]);
			ymin = min(ymin, ypos[i]);
			xmin = min(xmin, xpos[i]);
		}
		
		printf("%d %d\n", xmax - xmin + 1, ymax - ymin + 1);
	}
	
	return 0;
}


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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const ll MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  ll sum = 0;
  for (int i = 0; i < N; i++) sum += a[i];
  ll ans = 0;
  for (int i = 0; i < N - 1; i++) {
    sum -= a[i];
    ans += (a[i] % MOD) * (sum % MOD) % MOD;
    ans %= MOD;
  }

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


Measured memory_bytes: 5188
e1,e2,e3,e4=map(int,input().split())
if e1 == e2 and e3 == e4:
    print("yes")
elif e1 == e3 and e2 == e4:
    print("yes")
elif e1 == e4 and e2 == e3:
    print("yes")
else:
    print("no")


Measured memory_bytes: 5596
#include <stdio.h>
int main(void){
    int candy;
    while(scanf("%d", &candy) != EOF){
        int num=candy % 39;
        if(num == 0) printf("3C39\n");
        else if(num >= 1 && num <= 9) printf("3C0%d\n", num);
        else printf("3C%d\n", num);
    }
return 0;    
}



Measured memory_bytes: 2044