akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	public static void main(String[] args) {
		GridComponents();
	}
	
	public static void GridComponents() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		boolean[][] hw = new boolean[100][100];
		for(int i = 0; i < 50; i++) {
			for(int j = 0; j < 100; j++) {
				hw[i][j] = true;
			}
		}
		for(int i = 0; i < A - 1; i++) {
			int x = i / 50 * 2;
			int y = i % 50 * 2;
			hw[x][y] = false;
		}
		for(int i = 0; i < B - 1; i++) {
			int x = i / 50 * 2 + 51;
			int y = i % 50 * 2;
			hw[x][y] = true;
		}
		
		System.out.println("100 100");
		for(int i = 0; i < 100; i++) {
			for(int j = 0; j < 100; j++) {
				System.out.print(hw[i][j] ? '#' : '.');
			}
			System.out.println();
		}
	}
	
}

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

int main()
{
    int K, N, answer = 0;
    cin >> K >> N;
    vector<int> A(N, 0);
    vector<int> B(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    for (int j = 0; j < N-1; j++)
    {
        B.at(j) = A.at(j+1) - A.at(j);
    }

    B.at(N-1) = K - A.at(N-1) + A.at(0);

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

    for (int k = 0; k < N-1; k++)
    {
        answer += B.at(k);
    }
    
    cout << answer;
}


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

int main(){
    //エラトステネスのふるい
    int MAX = 101010;
    vector<int> is_prime(MAX,1);
    is_prime[0] = 0,is_prime[1] = 0;
    for(int i = 2; i < MAX;i++){
        if(!is_prime[i])continue;
        for(int j = i*2; j < MAX; j += i)is_prime[j] = 0;
    }
    
    //2017-like数かどうか
    vector<int> a(MAX,0);
    for(int i = 0; i < MAX;i++){
        if(i % 2 == 0)continue;
        if(is_prime[i] && is_prime[(i+1)/2])a[i] = 1;
    }
    
    //累積和
    vector<int> s(MAX+1,0);
    for(int i = 0; i < MAX;i++)s[i+1] = s[i] + a[i];
    
    //クエリ処理
    int Q; cin >> Q;
    for(int q = 0; q < Q;++q){
        int l,r;
        cin >> l >> r;
        ++r;
        cout << s[r] - s[l] << endl;
    }
    
}

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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,q; cin >> n;
    vector<ll> a(n);
    ll d[100010] = {};
    ll sum = 0;
    rep(i,0,n){
        cin >> a[i];
        d[a[i]]++;
        sum += a[i];
    }
    cin >> q;
    rep(i,0,q){
        ll b,c; cin >> b >> c;
        sum -= b * d[b];
        sum += c * d[b];
        d[c] += d[b] ;
        d[b] = 0; 
        cout << sum << endl;
    }
}

Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
long long p3(int n){
  return (long long)n*n*n;
}

int main(){
  int n,k;
  long long ans;
  cin >> n >> k;
  if(k%2==1)
    ans=p3(n/k);
  else{
    int j=k/2;
    ans=p3(n/k)+p3(n/j-n/k);
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
/*  ex5_3 Grid Compression
    pandacodeb  */

#include <stdio.h>

int main(void){
    int height, width;
    int i, j;
    scanf("%d %d", &height, &width);
    char a[height][width];
    
    //各行・列には最終的に消すかを表す配列；最初の値は 0 (false)
    int rowDel[height], colDel[width];
    for (i = 0; i < height; i++){
        rowDel[i] = 0;
    }
    for (j = 0; j < width; j++){
        colDel[j] = 0;
    }

    //入力（行ごと）
    for (i = 0; i < height; i++){
        for (j = 0; j < width; j++){
            scanf(" %c", &a[i][j]);
        }
    }

    //どの行が # を持たないのかをチェックする
    for (i = 0; i < height; i++){
        for (j = 0; j < width; j++){
            //最初の # 見つければ、残りを無視して次の行にチェックする
            if (a[i][j] == '#'){
                break;
            }
            //最後まで # を持たない場合 -> その行を消すか=true
            else if (a[i][j] == '.' && j == width - 1){
                rowDel[i] = 1;
            }
        }
    }
    //どの列が # を持たないのかをチェックする
    for (j = 0; j < width; j++){
        for (i = 0; i < height; i++){
            //最初の # 見つければ、残りを無視して次の列にチェックする
            if (a[i][j] == '#'){
                break;
            }
            //最後まで # を持たない場合 -> その列を消すか=true
            else if (a[i][j] == '.' && i == height - 1){
                colDel[j] = 1;
            }
        }
    }

    //出力(行ごと)
    for (i = 0; i < height; i++){
        //消さない行だけは出力される
        if (rowDel[i] == 0){
            for (j = 0; j < width; j++){
                //消さない列だけは出力される
                if (colDel[j] == 0){
                    printf("%c", a[i][j]);;
                }
            }
            printf("\n");
        }
    }
    return 0;
}

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

using namespace std;

const int INF = 1000;

int n;
int mn;
int sum;

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

	mn = INF;

	for(int i = 1 ; i <= n ; i++)
	{
		int v;
		scanf("%d",&v);

		sum += v;
		if( v%10 != 0 ) mn = min( mn , v );
	}

	if( sum%10 != 0 ) printf("%d\n",sum);
	else 
	{
		if( mn == INF ) printf("0\n");
		else printf("%d\n",sum - mn);
	}
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int w,h; scanf("%d%d",&w,&h);
	vector<lint> p(w),q(h);
	rep(i,w) scanf("%lld",&p[i]);
	rep(i,h) scanf("%lld",&q[i]);

	sort(p.begin(),p.end());
	sort(q.begin(),q.end());

	lint ans=0;
	int ip=0,iq=0;
	while(ip<w || iq<h){
		if(ip==w || (iq<h && p[ip]>=q[iq])){
			ans+=(w-ip+1)*q[iq++];
		}
		else{
			ans+=(h-iq+1)*p[ip++];
		}
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 1792
# writer解(c++)を写経した．answerのfor文のところ何やってるかさっぱりわかりませんが…
# https://atcoder.jp/contests/m-solutions2020/submissions/15122924
import sys
input = sys.stdin.readline
INF = 10**13


def main():
    N = int(input())
    X = []
    Y = []
    P = []
    for _ in range(N):
        a, b, c = (int(i) for i in input().split())
        X.append(a)
        Y.append(b)
        P.append(c)
    X_dist = [[0]*N for _ in range(1 << N)]
    Y_dist = [[0]*N for _ in range(1 << N)]

    # bitという道路群を建設したときの，各集落の評価距離
    # bit 001001 とかの1が立っている集落に道を作る
    for bit in range(1 << N):
        cur_x = [0]
        cur_y = [0]
        for i in range(N):
            if bit & (1 << i):
                cur_x.append(X[i])
                cur_y.append(Y[i])
        for i in range(N):
            X_dist[bit][i] = P[i]*min(abs(cx - X[i]) for cx in cur_x)
            Y_dist[bit][i] = P[i]*min(abs(cy - Y[i]) for cy in cur_y)

    # これはなに？
    answer = [INF] * (N+1)
    for i in range(1 << N):
        cnt = 0
        for j in range(N):
            if (i >> j) & 1:
                cnt += 1
        j = i
        while j >= 0:
            j &= i
            cost = 0
            for k in range(N):
                if not((i >> k) & 1):
                    cost += min(X_dist[j][k], Y_dist[i - j][k])
            answer[cnt] = min(answer[cnt], cost)
            j -= 1

    for ans in answer:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 88444
#include <stdio.h>

int main(void)
{
	int a, b, c, tmp;

	scanf("%d %d %d", &a, &b, &c);

	if (a > b) {
		tmp = a;
		a = b;
		b = tmp;
	}
	if (b > c) {
		tmp = b;
		b = c;
		c = tmp;
	}
	if (a > b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	printf("%d %d %d\n", a, b, c);

	return 0;
}

Measured memory_bytes: 596
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		int n=sc.nextInt();
		int[] a=new int[6];
		for(int i=0; i<n; i++){
			double d=sc.nextDouble();
			for(int k=0; k<6; k++){
				if(d+EPS<165+k*5||k==5){
					a[k]++;
					break;
				}
			}
		}
		for(int i=0; i<6; i++){
			print((i+1)+":");
			for(int k=0; k<a[i]; k++){
				print("*");
			}
			println("");
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
import copy
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
ma =max(a)
cn =0
for i in range(n):
  if a[i]==ma and cn<2:
    b=copy.deepcopy(a)
    del b[i]
    print(max(b))
    cn +=1
  else:
    print(ma)

Measured memory_bytes: 14684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template<typename T>
map<T, long long> factorize(T x) {
  map<T, long long> res;
  for (long long i = 2; i * i <= x; ++i) {
    while (x % i == 0) {
      x /= i;
      res[i] += 1;
    }
  }
  if (x != 1) res[x]++;
  return res;
}

long myPow(long x, long n, long m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long 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 main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  map<ll, ll> mp;
  for (int i = 0; i < n; ++i) {
    auto p = factorize(a[i]);
    for (auto itr : p) {
      chmax(mp[itr.first], itr.second);
    }
  }

  ll lc = 1;
  for (auto itr : mp) {
    lc *= myPow(itr.first, itr.second, mod);
    lc %= mod;
  }

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    auto m = modinv(a[i], mod);
    auto t = lc * m; 
    ans += t;
    ans %= mod;
  }

  cout << ans << endl;
}

Measured memory_bytes: 896
/**
 *    author:  khangtq1
 *    created: 22.06.2020 13:10:57 +07
**/

#include <bits/stdc++.h>

using namespace std;

const int INF = (int) 1e9 + 7;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);		
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for(int i = 0; i < n; i++) {
		cin >> h[i];
	}
	vector<int> dp(n, INF);
	dp[0] = 0;
	for(int i = 0; i < n; ++i) {
		for(int step = i + 1; step <= i + k; ++step) {
			if(step < n) {
				dp[step] = min(dp[step], dp[i] + abs(h[i] - h[step]));
			}
		}
	}
	cout << dp[n - 1];
	return 0;
}


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int count = 0;
  for (int i = 0; i <= A; ++i) {
    for (int j = 0; j <= B; ++j) {
      for (int k = 0; k <= C; ++k) {
        int total = 500*i + 100*j + 50*k;
        if (total == X) ++count; 
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

int main(){
    ll n;
    cin>>n;
    ll ans=0;
    ll sum=0;
    ll a;
    ll now=0;
    rep(i,n){
       cin>>a;
       if(now<a){
           now=a;
           sum=0;
        }else{
           now=a;
           sum++;
        }
       ans=max(ans,sum);
    }
    cout<<ans<<endl;
}


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

void optimize_cp_stdio() {
    std::ios::sync_with_stdio(false);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main() {
    optimize_cp_stdio();
    int n;
    std::string s;
    std::cin >> n >> s;
    std::vector<int> prefix(n), suffix(n);
    for (int i = 0; i < n; i++) {
        prefix[i] = s[i] == 'W';
        suffix[i] = s[i] == 'E';
    }
    std::partial_sum(prefix.begin(), prefix.end(), prefix.begin());
    std::partial_sum(suffix.rbegin(), suffix.rend(), suffix.rbegin());
    int ans = INT_MAX;
    for (int i = 0; i < n; i++) {
        int cost = (i == 0 ? 0 : prefix[i - 1]) + (i + 1 == n ? 0 : suffix[i + 1]);
        ans = std::min(ans, cost);
    }
    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2964
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_V=101010;
const int inf = 1LL << 60;
typedef pair<int,int> P;//firstは最短距離、secondは頂点の番号

class edge{
  public:
  int to,cost;
};

int V, E;
vector<edge> G1[MAX_V];
vector<edge> G2[MAX_V];
int d1[MAX_V];
int d2[MAX_V];

void dijkstra1(int s){
  priority_queue<P,vector<P>,greater<P> > que;
  fill(d1, d1 + V, inf);
  d1[s] = 0;
  que.push(P(0, s));

  while(!que.empty()){
    P p = que.top();que.pop();
    int v = p.second;
    if(d1[v] < p.first) continue;
    for(int i = 0;i < G1[v].size(); ++i){
      edge e = G1[v][i];
      if(d1[e.to] > d1[v]+e.cost){
        d1[e.to] = d1[v]+e.cost;
        que.push(P(d1[e.to], e.to));
      }
    }
  }
}
void dijkstra2(int s){
  priority_queue<P,vector<P>,greater<P> > que;
  fill(d2, d2 + V, inf);
  d2[s] = 0;
  que.push(P(0, s));

  while(!que.empty()){
    P p = que.top();que.pop();
    int v = p.second;
    if(d2[v] < p.first) continue;
    for(int i = 0;i < G2[v].size(); ++i){
      edge e = G2[v][i];
      if(d2[e.to] > d2[v]+e.cost){
        d2[e.to] = d2[v]+e.cost;
        que.push(P(d2[e.to], e.to));
      }
    }
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int s, t;
  cin >> V >> E >> s >> t; s--; t--;
  for (int i = 0; i < E; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--; b--;
    edge e; e.to = b; e.cost = c;
    G1[a].push_back(e);
    swap(a, e.to);
    G1[a].push_back(e);
    e.cost = d;
    G2[a].push_back(e);
    swap(a, e.to);
    G2[a].push_back(e);
  }
  dijkstra1(s);
  dijkstra2(t);
  stack<int> st;
  st.push(d1[V - 1] + d2[V - 1]);
  for (int i = V - 2; i >= 0; i--) {
    int p = d1[i] + d2[i];
    int q = st.top();
    st.push(min(p, q));
  }
  while (!st.empty()) {
    cout << 1000000000000000 - st.top() << endl;
    st.pop();
  }
}


Measured memory_bytes: 19100
using System;
using System.Collections.Generic;
using System.Text;

namespace AOJ
{
    class Program
    {
        static int compare(char lhs, char rhs)
        {
            if (lhs < rhs) return 1;
            if (lhs > rhs) return -1;
            return 0;
        }
        static int compare(string lhs, string rhs)
        {
            var l = lhs.ToCharArray();
            var r = rhs.ToCharArray();
            var length = Math.Min(l.Length, r.Length);

            for (int i = 0; i < length; ++i)
            {
                var balance = compare(l[i], r[i]);
                if (balance < 0)
                {
                    return -1;
                }
                if (balance > 0)
                {
                    return 1;
                }
            }

            if (l.Length < r.Length)
            {
                return 1;
            }
            if (l.Length > r.Length)
            {
                return -1;
            }
            return 0;
        }

        static void Main(string[] args)
        {
            var firstInput = Console.In.ReadLine();
            var count = int.Parse(firstInput);

            var taroPrise = new int[3] { 3, 1, 0 };
            var hanakoPrise = new int[3] { 0, 1, 3 };

            int taro = 0;
            int hanako = 0;

            for (int i = 0; i < count; ++i)
            {
                var input = Console.In.ReadLine();
                var inputs = input.Split(' ');
                var taroInput = inputs[0];
                var hanakoInput = inputs[1];
                var index = compare(taroInput, hanakoInput) + 1;
                taro += taroPrise[index];
                hanako += hanakoPrise[index];
            }

            Console.Out.WriteLine("{0} {1}", taro, hanako);
        }
    }
}



Measured memory_bytes: 17844
import std.container;
import std.range;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.stdio;
import std.container;

void main() {
	int d, t, s;

	readf("%s %s %s", &d, &t, &s);

	if (d <= s * t) {
		writeln("Yes");
	} else {
		writeln("No");
	}
}


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

int main(){
    string s;
    int n, k;
    cin >> n >> k;
    cin >> s;

    s[k-1] = s[k-1] - ('A' - 'a');
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    s = S()
    k = I()

    return re.sub(r'[^{}]'.format(s[k-1]), '*', s)


print(main())



Measured memory_bytes: 5080
#include <bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define fi first
#define sc second
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //printf(f,##__VA_ARGS__),fflush(stdout)

typedef long long ll;

const int N=2e5+50,oo=0x3f3f3f3f;

int n,fail,ans[N],sz1[N],sz2[N],qwq,rt1,rt2,ptr[N];
vector<int> g1[N],g2[N],g3[N];
typedef vector<int> G[N];
void add(int s,int d,G g){
	g[s].pb(d),g[d].pb(s);
}

void dfs1(int v,int p){
	sz1[v]=1;
	for(int d:g1[v])if(d!=p)dfs1(d,v),sz1[v]^=1;
	Pr("sz1[%d]=%d\n",v,sz1[v]);
}

void dfs2(int v,int p){
	sz2[v]=1;
	for(int d:g2[v])if(d!=p)dfs2(d,v),sz2[v]^=1;
	Pr("sz2[%d]=%d\n",v,sz2[v]);
}

typedef pair<int,int> P;
set<P> del;
bool chk(int x,int y){ 
	if(x>y)swap(x,y);
	P t=mp(x,y);
	if(del.count(t))return false;
	else {
		del.insert(t);
		return true;
	}
}

void dfs3(int v){
	for(;ptr[v]<g3[v].size();++ptr[v]){
		int d=g3[v][ptr[v]];
		if(chk(v,d)){
			Pr("from %d to %d\n",v,d); 
			if(v!=qwq&&d!=qwq){
				if(v<=n&&d>n)ans[v]=1;
				if(v>n&&d<=n)ans[v-n]=-1;
			}
			dfs3(d);
		}
	}
}

int main(int argc,char  *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	scanf("%d",&n);
	qwq=n+n+1;
	rep(i,1,n){
		int p; scanf("%d",&p);
		if(p!=-1)add(p,i,g1),add(p,i,g3);
		else rt1=i,add(i,qwq,g3);;
	}
	rep(i,1,n){
		int p; scanf("%d",&p);
		if(p!=-1)add(p,i,g2),add(n+p,n+i,g3);
		else rt2=i,add(n+i,qwq,g3);
	}
	dfs1(rt1,0);
	dfs2(rt2,0);
	rep(i,1,n){
		if(sz1[i]%2!=sz2[i]%2)fail=true;
		else if(sz1[i]%2==1){
			add(i,n+i,g3);
			Pr("Link %d,%d\n",i,n+i);
		}
	}
	dfs3(qwq);
	if(fail)puts("IMPOSSIBLE");
	else{
		puts("POSSIBLE"); 
		rep(i,1,n)printf("%d%c",ans[i]," \n"[i==n]);
	}
	return 0; 
}

Measured memory_bytes: 59504
#include <stdio.h>

int main(){
  int x;
  int y;
  int r;
  int tmp;
  scanf("%d%d",&x,&y);
  if(x<y){
    tmp=x;
    x=y;
    y=tmp;
  }
 
  while(y>0){
    r=x%y;
    x=y;
    y=r;
  }
  printf("%d\n",x);
  return 0;
}

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

struct bb {
    ll a;
    ll b;
    ll c;
};

int main() {
    ll n, m;
    cin >> n >> m;
    vector<bb> imp;
    ll result[n+1];
    result[1] = 0;
    for(ll i=2;i<=n;i++) {
        result[i] = -1;
    }
    for(ll i=0; i < m;i++){
        ll a, b, c;
        cin >> a >> b >> c;
        bb sg = {a, b,c};
        imp.push_back(sg);
    }
    sort(imp.begin(), imp.end(), [](const bb& x, const bb& y){return x.a < y.a ||( x.a == y.a && (x.b < y.b || ( x.b == y.b && x.c < y.c))) ;} );
    for(vector<bb>::const_iterator i = imp.begin(); i != imp.end(); i++) {
        if (result[i->a] == -1) {
            cout << -1 << endl;
            return 0;
        }
        ll sh = result[i->a] + i->c;
        if (result[i->b] != -1 && result[i->b] <= sh) {
            continue;
        }
        for(ll j = i->a; j <= i->b; j++) {
            if (result[j] == -1 || result[j] > sh) {
                result[j] = sh;
            }
        }
    }
    cout << result[n] << endl;
}

Measured memory_bytes: 5492
#include <iostream>
#include <string>
#include <vector>
#include <queue>

int dp[5010][5010];

int main(void){
  int n;
  std::string s;
  std::cin >> n >> s;

  s = "S"+s;
  for(int i=1; i<s.size(); i++){
    for(int j=1; j<s.size(); j++){
      int temp = dp[i-1][j-1];
      if(s[i] == s[j] && std::abs(i-j) >= temp+1) dp[i][j] = temp+1;
    }
  }

  int best = 0;
  for(int i=0; i<s.size(); i++){
    for(int j=0; j<s.size(); j++){
      best = best<dp[i][j] ? dp[i][j] : best;
    }
  }

  std::cout << best << std::endl;
  
  return 0;
}


Measured memory_bytes: 98176
#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[i];
  for(int i = 0;i < N;i++){
    if(A[i] % 2 == 0){
      if(A[i] % 3 != 0 && A[i] % 5 != 0){
        cout << "DENIED" <<endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" <<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int N;
	cin >> N;
	if (x1 > x2) {
		swap(x1, x2);
		swap(y1, y2);
	}
	vector<pair<int, int>> C;
	rep(i, N) {
		int x, y;
		cin >> x >> y;
		C.pb(mp(x, y));
	}
	sort(C.begin(), C.end());
	double d = 10 * (2 - acos(0));
	double kotae;

	if (x1 == x2) {
		int aru = 0;
		if (y1 > y2) swap(y1, y2);
		rep(i, N) {
			if (C[i].first == x1 && C[i].second > y1 && C[i].second < y2) aru = 1;
		}
		kotae = 100.0 * (y2 - y1);
		if (aru) kotae += 10 * (2 * acos(0) - 2);
	}
	else if (y1 == y2) {
		int aru = 0;
		if (x1 > x2) swap(x1, x2);
		rep(i, N) {
			if (C[i].second == y1 && C[i].first > x1 && C[i].first < x2) aru = 1;
		}
		kotae = 100.0 * (x2 - x1);
		if (aru) kotae += 10 * (2 * acos(0) - 2);
	}
	else if (y2 > y1) {
		vector<int> V;
		V.pb(1e9);
		int aru = 0;
		rep(i, C.size()) {
			int a = C[i].first;
			int b = C[i].second;
			if (a >= x1 && a <= x2 && b >= y1 && b <= y2) {
				aru = 1;
				int R = V.size() - 1;
				int L = 0;
				while (L < R) {
					int half = (L + R + 1) / 2;
					if (V[half] < b) L = half;
					else R = half - 1;
				}
				if (V[L] < b) {
					if (L == V.size() - 1) V.pb(b);
					else V[L + 1] = b;
				}
				else V[0] = b;
			}
		}
		int B = V.size();
		if (aru) {
			kotae = 100.0 * (y2 - y1 + x2 - x1) - B * d;
			if (B == 1 + min(x2 - x1, y2 - y1)) kotae += 10 * (2 * acos(0) - 2) + d;
		}
		else kotae = 100.0 * (y2 - y1 + x2 - x1);
	}
	else if (y2 < y1) {
		vector<int> V;
		V.pb(-1);
		int aru = 0;
		rep(i, C.size()) {
			int a = C[i].first;
			int b = C[i].second;
			if (a >= x1 && a <= x2 && b >= y2 && b <= y1) {
				aru = 1;
				int R = V.size() - 1;
				int L = 0;
				while (L < R) {
					int half = (L + R + 1) / 2;
					if (V[half] > b) L = half;
					else R = half - 1;
				}
				if (V[L] > b) {
					if (L == V.size() - 1) V.pb(b);
					else V[L + 1] = b;
				}
				else V[0] = b;
			}
		}
		int B = V.size();
		if (aru) {
			kotae = 100.0 * (y1 - y2 + x2 - x1) - B * d;
			if (B == 1 + min(x2 - x1, y1 - y2)) kotae += 10 * (2 * acos(0) - 2) + d;
		}
		else kotae = 100.0 * (y1 - y2 + x2 - x1);
	}
	cout << fixed << setprecision(15) << kotae << endl;

	Would you please return 0;
}

Measured memory_bytes: 3696
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.function.LongSupplier;

public class Main{ // 

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

	static LongSupplier now = new LongSupplier() {
		private long t = System.currentTimeMillis();

		@Override
		public long getAsLong() {
			long a = t;
			t = System.currentTimeMillis();
			long ans = t - a;
			return ans;
		}
	};

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	static int tr(Object... objects) {
		System.out.println("tr:" + Arrays.deepToString(objects));
		return 0;
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		int n = cin.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < a.length; i++)
			a[i] = cin.nextInt();

		now.getAsLong();

		long ans = solve(n, a);
		cout.println(ans);

		assert 0 == tr("elapsed", now.getAsLong());
	}

	private static long solve(int n, int[] a) {
		Arrays.sort(a);
		int ans = 0;
		int cnt = 1;
		for (int i = 1; i < n; i++) {
			if (a[i] != a[i - 1]) {
				if (cnt % 2 == 1)
					ans += 1;
				cnt = 1;
			} else {
				cnt += 1;
			}
		}
		if (cnt % 2 == 1)
			ans += 1;
		return ans;
	}

}


Measured memory_bytes: 35040
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,ac=0,wa=0,tle=0,re=0;
	cin>>N;
	string S;
	for(int i=0;i<N;i++)
	{
		cin>>S;
		if(S.compare("AC")==0)
			ac++;
		else if(S.compare("WA")==0)
			wa++;
		else if(S.compare("TLE")==0)
			tle++;
		else
			re++;

	}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re<<endl;
}


Measured memory_bytes: 3640
<?php
$n = trim(fgets(STDIN));
if($n <= 9){
echo $n;
}else{
$a = str_split($n);
$c = count($a);
if($a[$c-1] == 9){
echo array_sum($a);
}else{
echo $a[0] - 1 + ($c-1) * 9;
}
}

Measured memory_bytes: 3828
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

benefits = -1000000000

for t in range(1,1024):
  bits = list(bin(t))
  a = [0 for _ in range(n)]
  jk = 0
  while jk < 10:
    b = bits.pop()
    if b == "b":
      break
    elif b == "0":
      jk += 1
      continue
    else:
      for i in range(n):
        if f[i][jk]:
          a[i] += 1
      jk += 1
  
  s = 0
  for i in range(n):
    s += p[i][a[i]]
  else:
    benefits = max(s,benefits)
else:
  print(benefits)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define cast static_cast
#define vi vector<int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
typedef long long int ll;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int h,w;
	cin>>h>>w;
	v<v<char>> a(h,v<char>(w));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a[i][j];
		}
	}
	v<vi> dp(h,vi(w));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(i==0 && j==0){
				dp[i][j]=1;
				continue;
			}
			int h1,h2;
			if(a[i][j]=='#'){
				dp[i][j]=0;
				continue;
			}
			if(i!=0){
				h1=dp[i-1][j];
			}
			else{
				h1=0;
			}
			if(j!=0){
				h2=dp[i][j-1];
			}
			else{
				h2=0;
			}
			dp[i][j]=(h1+h2)%modF;
		}
	}
	cout<<dp[h-1][w-1]<<"\n";
}	

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


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

    # divisors.sort()
    return divisors

n = int(input())
ans = 20

for i in make_divisors(n):
    ans = min(max(len(str(i)),len(str(n//i))), ans)

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
  ll ans=0;
  ll cnt=0;
  ll n,m;
  cin >> n >> m;
  vector<pair<ll,ll>> v(n);
  for (ll i=0;i<n;i++){
    pair<ll,ll> tmp;
    cin >> tmp.first >> tmp.second;
    v.at(i)=tmp;
  }
  sort(v.begin(),v.end());
  //for(int i=0;i <n;i++){
    //cout << v.at(i).first << " " << v.at(i).second << endl;
  //}
  for (int j=0; j < n;j++){
    ans+=(v.at(j).first)*(v.at(j).second);
    cnt+=v.at(j).second;
    if (cnt > m){
      while (cnt != m){
        ans-=(v.at(j).first);
        cnt--;
      }
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
  
  
  

Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
/*
  int i;
  int x[10000];

  for (i = 0; i < 10000; i++) {
    scanf("%d", &x[i]);
    if (x[i] == 0) break;
  }

  for (i = 0; i < 10000; i++) {
    if (x[i] == 0) break;
    printf("Case %d: %d\n", i+1, x[i]);
  }
*/

  int i = 1;
  int x;

  while (1) {
    scanf("%d", &x);
    if (x == 0) {
      break;
    } else {
      printf("Case %d: %d\n", i, x);
      i++;
    }
  }

  return 0;
}

Measured memory_bytes: 600
n, k = map(int, input().split())
s = list(input())
 
if s[k-1] == 'A':
  s[k-1]='a'
elif s[k-1] == 'B':
  s[k-1]='b'
elif s[k-1] == 'C':
  s[k-1]='c'
 
print(''.join(s))

Measured memory_bytes: 38256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
	int a = 0;
    for (int i=0; i<=3; i++){
      if (s.substring(i,i+1).equals("+")) {
        a++;
      } else {
        a--;
      }
    }
    System.out.println(a);
  }
}

Measured memory_bytes: 21972
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████   
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
const double EPS = 1e-9;
#define INF (1LL<<60)
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int a,b,c;
  cin >> a >> b >> c;
  
  if(a > b) swap(a,b);

  if(range(c,a,b)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

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

int main() {
    int m, k;
    cin >> m >> k;
    if (m == 0) {
        if (k == 0) cout << "0 0" << endl;
        else cout << -1 << endl;
        return 0;
    }
    if (m == 1) {
        if (k == 0) cout << "0 0 1 1" << endl;
        else cout << -1 << endl;
        return 0;
    }

    if ((1 << m) <= k) {
        cout << -1 << endl;
        return 0;
    }

    for (int i = 0; i < (1 << m); i++) {
        if (i == k) continue;
        cout << i << " ";   
    }
    cout << k << " " << endl;
    for (int i = (1 << m) - 1; i >= 0; i--) {
        if (i == k) continue;
        cout << i << " ";
    }
    cout << k << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<vector>
//#include<queue>
//#include<sstream>
//#include<cmath>
//#include<set>
//#include<algorithm>
//#include<map>
#define mp make_pair
#define pii pair<int,int>
#pragma GCC optimize ("O3")
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-9;
const int maxn = 1e5+9;
const double pi=acos(-1.0);
const int inf = 1e9+9;
const int mod = 10007;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    cout<<(1000-n%1000)%1000;
    return 0;
}


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

public class Main {

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

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

		int q = sc.nextInt();
		int[] t = new int[q];
    	for (int i = 0; i < q; i++) {
    		t[i] = sc.nextInt();
    	}

    	Arrays.sort(s);
    	Arrays.sort(t);
    	
    	int count = 0;
    	for (int i = 0, key = 0; i < n && key < q;) {
    		if (s[i] < t[key]) {
    			i++;
    		} else if (s[i] == t[key]) {
    			count++;
    			i++;
    			key++;
//    			System.out.println(s[i]);
    		} else {
    			key++;
    		}
    	}
		
    	System.out.println(count);

    	sc.close();
	}
}

Measured memory_bytes: 32080
using System;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;


class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Enumerable.Repeat(0, n).Select(_ => int.Parse(Console.ReadLine())).OrderBy(x => x).ToArray();
        int middle = a[n / 2];
        int half = n / 2;
        long sum0 = 0;
        long sum1 = 0;
        for (int i = 0; i < half; i++) sum0 += a[i];
        for (int i = half + (n % 2); i < n; i++) sum1 += a[i];
        long res = (sum1 - sum0) * 2;
        if (n % 2 != 0)
        {
            res -= Min(a[n / 2 + 1] - middle, middle - a[n / 2 - 1]);
        }
        else
        {
            res -= a[n / 2] - a[n / 2 - 1];
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 20700
//last updated : 24.04.2020
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <ll,ll> pll;

#define mp              make_pair
#define pb              push_back
#define fi              first
#define se              second

#define endl            '\n'
#define init			ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define db(x)           cout << ">>>>>> " << #x << " -> " << x << endl

const ll inf = INT_MAX;
const ll MAX = 1e5+5;
const ll MOD = 1e9+7;
const double pi = acos(-1.0);
const double EPS = 1e-9;

ll n;
ll arr[255];

int main() {
	init;
    // freopen ("input.txt", "r", stdin);
	// freopen ("output.txt", "w", stdout);

	cin >> n;
	for (int i = 1; i <= n; i++) cin >> arr[i];
	for (int i = 1; i <= n; i++) {
		cout << "node " << i << ": key = " << arr[i] << ", ";
		if (i/2) cout << "parent key = " << arr[i/2] << ", ";
		if (i*2 <= n) cout << "left key = " << arr[i*2] << ", ";
		if (i*2+1 <= n) cout << "right key = " << arr[i*2+1] << ", ";
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3132
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

struct Node
{
  Node *parent;
  Node *left;
  Node *right;
  int key;
};

class BStree
{
public:
  Node *root;
  Node *nil;
  int solve();
  int print();
  int insert( Node *z );
  int preorder( Node *nd );
  int inorder( Node *nd );
  bool find( int k );
};

int BStree::solve()
{
  int n;
  cin >> n;
  
  string com;
  int d;
  Node *nd;
  
  for ( auto i = 0; i < n; ++i )
    {
      cin >> com;

      if ( com == "print" )
        print();
      else if ( com == "insert")
        {
          cin >> d;
          nd = new Node;
          nd->key = d;
          nd->parent = nil;
          nd->left = nil;
          nd->right = nil;
          insert( nd );
        }
      else
        {
          cin >> d;
          if ( find( d ) )
            cout << "yes" << endl;
          else
            cout << "no" << endl;
        }
    }
      
  return 0;
}

int BStree::print()
{
  inorder( root );
  cout << endl;
  preorder( root );
  cout << endl;
  return 0;
}

int BStree::insert( Node *z )
{
  Node *y = nil;
  Node *x = root;

  while ( x != nil )
    {
      y = x;
      if ( z->key < x->key )
        x = x->left;
      else
        x = x->right;
    }

  z->parent = y;

  if ( y == nil )
    root = z;
  else if ( z->key < y->key )
    y->left = z;
  else
    y->right = z;
  
  return 0;
}

bool BStree::find( int k )
{
  Node *x;
  x = root;
  
  while ( x != nil )
    {
      if ( x->key == k )
        return true;
      else if ( x->key > k )
        x = x->left;
      else
        x = x->right;
    }

  return false;
}

int BStree::preorder( Node *nd )
{
  if ( nd == nil )
    return 0;

  cout << " " << nd->key;
  preorder( nd->left );
  preorder( nd->right );
  
  return 0;
}

int BStree::inorder( Node *nd )
{
  if ( nd == nil )
    return 0;

  inorder( nd->left );
  cout << " " << nd->key;
  inorder( nd->right );
  
  return 0;
}

int main()
{

  BStree b;

  b.nil = new Node;
  b.nil->parent = b.nil;
  b.nil->left = b.nil;
  b.nil->right = b.nil;
  b.nil->key = -1;

  b.root = b.nil;
  
  b.solve();

  return 0;
}

Measured memory_bytes: 19968
def main():
    INF = float('inf')
    N, M = map(int, input().split())
    dist = [0] + [INF] * (N-1)
    abc = []
    
    for i in range(M):
        a, b, c = map(int, input().split())
        abc.append((a-1, b-1, -c))
            
    for a, b, c in abc:
        dist[b] = min(dist[b], dist[a]+c)
        
    ans = dist[-1]
    
    for a, b, c in abc:
        dist[b] = min(dist[b], dist[a]+c)
            
    if ans != dist[-1]:
        print('inf')
    else:
        print(-ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3388
<?php
fscanf(STDIN,"%d",$n);

$list = explode(" ", trim(fgets(STDIN)));
if($n == 2){
    echo max($list);
    exit;
}
$left[0] = $list[0];
for($i=1;$i<$n;$i++){
    $left[$i]=gcd($left[$i-1], $list[$i]);
}
$right[$n-1] = $list[$n-1];
for($i=$n-2;$i>=0;$i--){
    $right[$i]=gcd($right[$i+1], $list[$i]);
}
$ans = max($right[1], $left[$n-2]);
for($i=0;$i<$n-2;$i++){
    $ans = max($ans, gcd($left[$i], $right[$i+2]));
}
echo $ans;
function gcd($m, $n){
    if($n > $m) list($m, $n) = array($n, $m);

    while($n !== 0){
        $tmp_n = $n;
        $n = $m % $n;
        $m = $tmp_n;
    }
    return $m;
}


Measured memory_bytes: 23280
from itertools import accumulate


def main():
  n = int(input())
  As = map(int, input().split())
  Bs = map(int, input().split())

  diffs = [a - b for a, b in zip(As, Bs)]
  pos_acc = list(accumulate(sorted(filter(lambda x: x>0, diffs), reverse=True)))
  negatives = list(filter(lambda x: x<0, diffs))
  neg_sum = abs(sum(negatives))
  num_negs = len(negatives)
  if num_negs == 0:
    print(0)
    return
  for i, pa in enumerate(pos_acc):
    if neg_sum <= pa:
      print(num_negs + i + 1)
      return
  print(-1)


if __name__ == '__main__':
  main()


Measured memory_bytes: 22516
// vim:ts=4:sts=4:sw=4:et
// MOSCOW IPT JINOTEGA
// Table #14
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef long long i64;

const ll M = 3555;
typedef pair<ll, ll> pll;

ll n;

ll mabs(ll x) {
    return x < 0 ? -x : x;
}

ll gcd(ll x, ll y) {
    x = mabs(x), y = mabs(y);
    while (x) {
        y %= x;
        swap(x, y);
    }
    return y;
}

void read() {
    cin >> n;
}

pll sub(const pll &x, const pll &y) {
    ll nom = x.first * y.second - y.first * x.second;
    ll den = x.second * y.second;
    return {nom, den};
}

void norm(pll &x) {
    ll g = gcd(x.first, x.second);
    x.first /= g;
    x.second /= g;
}

void kill() {
    for (ll a = 1; a <= M; ++a)
        for (ll b = a; b <= M; ++b) {
           pll cur = {4, n}; 
           cur = sub(cur, {1, a});
           cur = sub(cur, {1, b});
           norm(cur);
           if (cur.first == 1) {
               cout << a << " " << b << " " << cur.second << endl;
               return;
           }
        }
}

int main() {
#ifdef LOCAL
    assert(freopen("c.in", "r", stdin));
#endif
    //ios_base::sync_with_stdio(false);

    read();
    kill();

    return 0;
}



Measured memory_bytes: 256
#coding:utf-8

class MakeTree():
    def __init__(self, key, p=None, l=None, r=None):
        self.key = key
        self.p = p
        self.l = l
        self.r = r

 
def Insert(root,value):
    y = None
    x = root
    z = MakeTree(value)

    while x != None:
        y = x
        if x.key > z.key:
            x = x.l
        else:
            x = x.r
    z.p = y

    if y == None:
        root = z
    elif z.key < y.key:
        y.l = z
    else:
        y.r = z
    return root


def Find(u, target):
    y = None
    x = u
    while x != None and target != x.key:
        y = x
        if x.key > target:
            x = x.l
        else:
            x = x.r
    return x


def Delete(u, z):
    if z.l == None or z.r == None:
        y = z
    else:
        y = getSuccessor(z)

    if y.l != None:
        x = y.l
    else:
        x = y.r

    if x != None:
        x.p = y.p
    if y.p == None:
        root = x
    elif y == y.p.l:
        y.p.l = x
    else:
        y.p.r = x

    if y != z:
        z.key = y.key


def getSuccessor(x):
    if x.r != None:
        return getMinimum(x.r)
    y = x.p
    while y != None and x == y.r:
        x = y
        y = y.p
    return y
        
def getMinimum(x):
    while x.l != None:
        x = x.l
    return x


def inParse(u):
    if u == None:
        return
    inParse(u.l)
    global inParseList
    inParseList.append(u.key)
    inParse(u.r)

def preParse(u):
    if u == None:
        return
    global preParseList
    preParseList.append(u.key)
    preParse(u.l)
    preParse(u.r)


root = None       
n = int(input())
inParseList = []
preParseList = []
for i in range(n):
    order = list(input().split())
    if order[0] == "insert":
        root = Insert(root, int(order[1]))
        
    elif order[0] == "print":
        inParse(root)
        preParse(root)
        print(" " + " ".join([str(i) for i in inParseList]))
        print(" " + " ".join([str(i) for i in preParseList]))
        preParseList = []
        inParseList = []
        
    elif order[0] == "find":
        x = Find(root, int(order[1]))
        if x == None:
            print("no")
        else:
            print("yes")
    else:
        x = Find(root, int(order[1]))
        Delete(root, x)






        



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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

#define MAX (50 * 50 + 50)
ll dp[51][MAX];
int main() {
  int N,A;
  cin >> N >> A;
  vector<int> x(N);
  rep(i,N) cin >> x[i];

  ll maxi = 0;
  dp[0][0] = 1;
  rep(i,N) {
    for(int l=N-1;l>=0;--l) {
      for(int j=MAX-1;j>=0;--j) {
	int k = j + x[i];
	if( k <= MAX ) {
	  dp[l+1][k] += dp[l][j];
	}
      }
    }
  }
  rep(i,N) {
    maxi += dp[i+1][(i+1)*A];
  }
  cout << maxi << endl;
  compute();
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d)puts("Left");
	else if (a + b < c + d)puts("Right");
	else puts("Balanced");
	return 0;
}

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

int ans = 0;
int N, M, Q;
vector<int> a, b, c, d;
void recurse(vector<int>& v, int i) {
    if (i == N) {
        int sum = 0;
        for (int j = 0; j < Q; j++) {
            if (v[b[j]]-v[a[j]] == c[j]) sum += d[j];
        }
        ans = max(ans,sum);
    }
    else {
        int prev = v.empty() ? 1 : v.back();
        for (int j = prev; j <= M; j++) {
            v.push_back(j);
            recurse(v,i+1);
            v.pop_back();
        }
    }
}

int main() 
{
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    for (int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];    
        --a[i]; --b[i];
    }
    vector<int> v;
    recurse(v,0);
    cout << ans << '\n';
}


Measured memory_bytes: 3604