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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db; 
typedef string str;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
 
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define endl '\n'
 
const ll MOD = 1000000007;

int main() {
   int n; scanf("%d", &n);
   vector<int> a(n);
   vector<int> b(n);
   for (int i = 0; i < n; i++)
      scanf("%d%d", &a[i], &b[i]);
   sort(all(a));
   sort(all(b));
   if (n % 2 == 0) {
      printf("%d", b[(n - 1) / 2] + b[(n + 1) / 2] - 
         a[(n - 1) / 2] - a[(n + 1) / 2] + 1);
   } else {
      printf("%d", b[(n - 1) / 2] - a[(n - 1) / 2] + 1);
   }
   return 0;
}

Measured memory_bytes: 4824
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt(), ms = sc.nextInt();
        String[] name = new String[c];
        int[] time = new int[c];
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < c; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            queue.add(i);
        }
        int total = 0;
        while (!queue.isEmpty()) {
            int i = queue.remove();
            if (time[i] > ms) {
                time[i] -= ms;
                total += ms;
                queue.add(i);
            } else {
                total += time[i];
                System.out.println(name[i] + " " + total);
            }
        }
    }
}

Measured memory_bytes: 76536
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		boolean[][] road = new boolean[H][W];
		for (int i = 0; i < H; i++) {
         String line = sc.next();
         for (int j = 0; j < W; j++) {
            if (line.charAt(j) == '.') {
               road[i][j] = true;
            } else {
               road[i][j] = false;
            }
         }
      }
      int[][] step = new int[H][W];
      init(step, H, W);
      int max = 0;
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            if (road[i][j]) {
               update(0, road, step, i, j, H, W);
               max = Math.max(max, max(step, H, W));
               init(step, H, W);
            }
         }
      }
		System.out.println(max);
	}
   
   public static void update(int value, boolean[][] road, int[][] step, int i, int j, int H, int W) {
      if (i >= 0 && i < H && j >= 0 && j < W && road[i][j]) {
         if (step[i][j] == -1 || step[i][j] > value) {
            step[i][j] = value;
            update(value + 1, road, step, i - 1, j, H, W);
            update(value + 1, road, step, i + 1, j, H, W);
            update(value + 1, road, step, i, j - 1, H, W);
            update(value + 1, road, step, i, j + 1, H, W);
         }
      }
   }
   
   public static int max(int[][] step, int H, int W) {
      int max = 0;
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            max = Math.max(max, step[i][j]);
         }
      }
      return max;
   }
   
   public static void init(int[][] step, int H, int W) {
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            step[i][j] = -1;
         }
      }
   }
}

Measured memory_bytes: 23276
#include <stdio.h>

int main()
{
	int N, K;
	char S[100001];
	scanf("%d %d", &N, &K);
	scanf("%s", S);
	
	int i, j, k, l[50001] = {}, r[50001] = {};
	for (i = 0, k = 0; i < N; ) {
		for (; S[i] == '0'; i++);
		l[++k] = i;
		for (; S[i] == '1'; i++);
		r[k] = i;
	}
	
	if (k <= K) {
		printf("%d\n", N);
		fflush(stdout);
		return 0;
	}

	int max = 0;
	for (i = 0; i <= k - K; i++) if (r[i+K] - l[i] > max) max = r[i+K] - l[i];
	printf("%d\n", max);
	fflush(stdout);
	return 0;
}

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

const int MAX_M = 10001;
const int MAX_N = 1001;
struct LOG{
	int m;
	int in;
	int out;
};

bool comp(LOG l1, LOG l2){
	return l1.in < l2.in;
}

int main(){
	int N, M;
	while(cin >> N >> M){
		if(N == 0 && M == 0) break;
		vector<LOG> vl[MAX_M];
		stack<LOG> sl[MAX_N];
		int r, q;
		cin >> r;
		for(int i = 0; i <r; i++){
			int t, n, m, s;
			cin >> t >> n >> m >> s;
			LOG l;
			if(s){
				l.in = t;
				sl[n].push(l);
			}else{
				l = sl[n].top();
				sl[n].pop();
				l.out = t;
				vl[m].push_back(l);
			}
		}
		cin >> q;
		for(int i = 0; i < q; i++){
			int ts, te, m;
			cin >> ts >> te >> m;
			int time = 0;
			sort(vl[m].begin(), vl[m].end(), comp);
			for(vector<LOG>::iterator iter = vl[m].begin();
				iter != vl[m].end(); iter++)
			{
				int ti = (*iter).in;
				int to = (*iter).out;
				if(ti >= te) break;
				if(ts >= to) continue;
				if(ts >= ti && te <= to){
					time += te - ts;
					break;
				}else if(ts >= ti && te >= to){
					time += to - ts;
					ts = to;
				}else if(ts <= ti && te <= to){
					time += te - ti;
					break;
				}else{
					time += to - ti;
					ts = to;
				}
				if(ts >= te) break;
			}
			cout << time << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a<b?a=b,true:false);}
template<class T>bool chmin(T &a, const T &b){return(a>b?a=b,true:false);}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

 

signed main() {

    int n, m;

    cin >> n >> m;

    vector<int> a(m), b(m), c(m);

    for(int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i];
        c[i] = -c[i];
    }

    vector<long long> dist(n+1, LINF);
    dist[1] = 0;

    for(int _ = 0; _ < n-1; _++) {
        for(int i = 0; i < m; i++) {
            if(dist[a[i]] == LINF) continue;
            chmin(dist[b[i]], dist[a[i]] + c[i]);
        }
    }

    long long  ans = dist[n];

    vector<bool> neg(n+1, false);

    for(int _ = 0; _ < n; _++) {
        for(int i = 0; i < m; i++) {
            if(dist[a[i]] == LINF) continue;
            if(chmin(dist[b[i]], dist[a[i]] + c[i]) or neg[a[i]])
                neg[b[i]] = true;
        }
    }

    if(neg[n]) cout << "inf\n";
    else cout << -ans << endl;
            

  
    return 0;
}



Measured memory_bytes: 384
import java.util.*;

class Main {
  public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int X = sc.nextInt();
    int Y = sc.nextInt();
    
    int[] ans = new int[N-1];
    int min = 10000;
    for(int i =1;i<N;i++){
      for (int j = i+1;j<N+1;j++){
        min = Math.min((Math.abs(j-i)),(Math.abs(X-i)+1+Math.abs(Y-j)));
        min = Math.min(min,Math.abs(Y-i)+1+Math.abs(X-j));
        ans[min-1]++;
      }
    }
    for(int k:ans){
      System.out.println(k);
    }
    
    
  }    
}



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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
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)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N,M = inputIL()
n = inputSLs(N)
m = inputSLs(M)

for i in range(N-M+1):
  for j in range(N-M+1):
    if m == [ n[k][i:i+M] for k in range(j,j+M)]:
      Yes()
      exit()
No()
    

Measured memory_bytes: 39152
#include <bits/stdc++.h>
//#include <atcoder/all>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void B();

int main()
{
	B();
	fflush(stdout);
	return 0;
}

static void B()
{
	LLONG a, b, c, d;
	get(a, b);
	get(c, d);

	LLONG ans = (a * c);
	ans = std::max((a * d), ans);
	ans = std::max((b * c), ans);
	ans = std::max((b * d), ans);
	printf("%lld\n", ans);
}


Measured memory_bytes: 3760
#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
    const int N=(int)4e5+100;
    const int inf=(int)1e9+100;
#define filename ""

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n,i,m;
    cin>>n>>m;
    vector<ll> a(n);
    fo(i,n)
    {
        cin>>a[i];
    }
    make_unique(a);
    n=a.size();
    ll c=a.back();
    ll d=c/2;
    while(1)
    {
        if (d>m) break;
        bool f=0;
        fo(i,n)
        {
            if ((d-a[i]/2)%a[i]!=0)
            {
                f=1;
            }
        }
        if (f)
        {
            d+=c;
            continue;
        }
        break;
    }
    if (d>m)
    {
        cout<<0;
        re 0;
    }
    ll nok=1;
    fo(i,n)
    {
        ll c=__gcd(a[i],nok);
        a[i]/=c;
        if (nok*a[i]>m)
        {
            cout<<1;
            re 0;
        }
        nok*=a[i];
    }
    cout<<(m-d)/nok+1;
}


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

using namespace std;
#define sz(a) int(a.size())
#define ll  long long
#define ull unsigned long long
//#define mod int(1e9+7)
#define endl '\n'
#define Engz ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);cin.tie(0) , cout.tie(0) ;
#define pi double(acos(-1))
#define S second
#define F first

//  freopen("input.txt","r",stdin);

//------------------- BESH ----------------------//
long long mod ;
long long p(long long a ,long long b)
{
    if(b==0)
        return 1;

    long long z=p(a,b/2);


    if(b%2==0)return ((z%mod)*(z%mod))%mod; else return (((z*z)%mod)*a)%mod;
}

long long g(long long a, long long b)
{
    if(a==0)
        return b;
    else return g(b%a , a);
}

//-----------sieve --------------------//

bool prime[1000001];

void sieve()
{
memset(prime , true , sizeof prime);
prime[0]=prime[1]=0;

for(int i=2 ; i*i<=1000000; i++)
{
    if(prime[i]==true)
    for(int j=i*i ; j<=100000 ; j+=i)
    prime[j]=false;
}
}

ll lcm(ll a, ll b)
{
    return (a*b)/__gcd(a,b);
}

long double a[3005];
long double ans[3005][3005];
int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n ; i++) cin>>a[i];

    ans[1][0]=1.0-a[1];
    ans[1][1]=a[1];


    for(int i=2 ;i<=n ; i++)
    {

        for(int j=0; j<=n ; j++)
        {
            if(j<=i)
            {
                ans[i][j]=ans[i-1][j]*(1-a[i]);
                if(j)  ans[i][j]+=ans[i-1][j-1]*a[i];
            }

            else ans[i][j]=0;
        }
    }

    long double res=0;
    for(int i=ceil((long double)n/2 ); i<=n ; i++)
    res+=ans[n][i];

        cout<<setprecision(12)<<fixed<<res;
	return 0;
}


Measured memory_bytes: 141440
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.NoSuchElementException;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		long[] A = new long[n];
		for (int i = 0; i < n; ++i) {
			A[i] = sc.nextLong();
		}
		Arrays.sort(A);
		HashMap<Long, Integer> map = new HashMap<>();
		for (int i = 0; i < n; ++i) {
			if (map.containsKey(A[i])) {
				map.put(A[i], map.get(A[i]) + 1);
			} else {
				map.put(A[i], 1);
			}
		}
		int ans = 0;
		for (int i = n - 1; i >= 0; --i) {
			if (!map.containsKey(A[i]))
				continue;
			long target = 1;
			while (target <= A[i])
				target *= 2;
			if (target - A[i] == A[i] && map.get(A[i]) == 1)
				continue;
			if (map.containsKey(target - A[i])) {
				++ans;
				;
				if (map.get(target - A[i]) == 1) {
					map.remove(target - A[i]);
				} else {
					map.put(target - A[i], map.get(target - A[i]) - 1);
				}
				if (map.get(A[i]) == 1) {
					map.remove(A[i]);
				} else {
					map.put(A[i], map.get(A[i]) - 1);
				}
			}
		}
		System.out.println(ans);
	}

	void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

}

class Scanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

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


Measured memory_bytes: 59004
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll area_sum = 0;
    while (i < N && A[i] != 0) {
      area_sum += A[i];
      i++;
    }
    ans += area_sum / 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4028
N, K = map(int,input().split())
ans1 = 0
ans2 = 0
if K % 2 == 0:
    for i in range(1,N+1):
        if i % K == 0:
            ans1 += 1
        if i % K == K//2:
            ans2 += 1
else:
    for i in range(1,N+1):
        if i % K == 0:
            ans1 += 1

print(ans1**3 + ans2**3)

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

int main() {
  int N, K;
  cin >> N >> K;
  int distance = 0;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    
    if (K >= (2 * x)) {
      distance += 2 * x;
    }
    
    else if (K > x && K < (2 * x)) {
      distance += 2 * (K - x);
    }
    
    else {
      distance += 2 * (x - K);
    }
  }
  
  cout << distance << endl;
}
      


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int INF = 2e9;
signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, m, s; cin >> n >> m >> s;
  struct edge { int to, cost; };
  vector< vector<edge> > adj(n);
  for (int i = 0; i < m; i++) {
    int a, b, c; cin >> a >> b >> c;
    adj[a].push_back(edge{b, c});
  }
  vector<int> d(n, INF);
  priority_queue<P, vector<P>, greater<P> > pq;
  d[s] = 0;
  pq.push(P(0, s));
  while (not pq.empty()) {
    P p = pq.top(); pq.pop();
    int v = p.second;
    for (auto&& i : adj[v]) {
      if (d[i.to] <= d[v] + i.cost) continue;
      d[i.to] = d[v] + i.cost;
      pq.push(P(d[i.to], i.to));
    }
  }
  for (int i = 0; i < n; i++) {
    cout << (d[i] == INF ? "INF" : to_string(d[i])) << '\n';
  }
  return 0;
}


Measured memory_bytes: 12944
import std.algorithm,
       std.string,
       std.range,
       std.array,
       std.stdio,
       std.conv;

struct Stack(T) {
  T[] stack;

  @property T pop() {
    T t = stack[$ - 1];
    stack.length--;
    return t;
  }
  
  @property size_t length() {
    return stack.length;
  }

  @property void push(T value) {
    stack ~= value;
  }

  @property bool empty() {
    return stack.empty;
  }

  @property T front() {
    return pop;
  }

  @property void popFront() {}

  @property void popAll() {
    foreach (_; this) {}
  }
}

void main() {
  ulong n = readln.chomp.to!ulong;
  ulong[] a = readln.chomp.split.to!(ulong[]);

  ulong[] odds,
          evens;

  Stack!ulong sodds,
              sevens;

  foreach (idx, elem; a) {
    if (idx % 2 == 0) {
      if (n % 2) {
        sevens.push(elem);
      } else {
        evens ~= elem;
      }
    } else {
      if (n % 2) {
        odds ~= elem;
      } else {
        sodds.push(elem);
      }
    }
  }


  if (n % 2 != 0) {
    foreach (elem; sevens) { writef("%d ", elem); }
    foreach (elem; odds)   { writef("%d ", elem); }
  } else {
    foreach (elem; sodds)  { writef("%d ", elem); }
    foreach (elem; evens) { writef("%d ", elem); }
  }
  writeln;
}


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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
vector<pii> L[N];
vector<pii> R[N];

int x[N];
int y[N];
bool lf[N];
bool rf[N];

void dfs(int u, int part){
  if(part == 0){
    lf[u]=true;
    for(auto p : L[u]){
      if(!rf[p.fi]){
        y[p.fi] = p.se - x[u];
        dfs(p.fi, 1);
      }
    }
  }
  else{
    rf[u]=true;
    for(auto p : R[u]){
      if(!lf[p.fi]){
        x[p.fi] = p.se - y[u];
        dfs(p.fi,0);
      }
    }
  }
}

int li, ri;

void dfs1(int node, int part){  
  if(part == 0){
    li = min(x[node], li);
    lf[node]=true;
    for(auto x : L[node]){
      if(!rf[x.fi]){
        dfs1(x.fi,1);
      }
    }
  }
  else{
    ri = min(y[node], ri);
    rf[node]=true;
    for(auto x : R[node]){
      if(!lf[x.fi]){
        dfs1(x.fi,0);
      }
    }
  }
}

int main(){
  fastIO;
  int n, m, q;
  cin >> n >> m >> q;
  int r[q], c[q], a[q];
  for(int i = 0 ; i < q; i ++ ){
    cin >> r[i] >> c[i] >> a[i];
    L[r[i]].push_back(mp(c[i],a[i]));
    R[c[i]].push_back(mp(r[i],a[i]));
  }
  dfs(1,0);
  for(int i = 1; i <= n; i ++ )
    if(!lf[i]) dfs(i,0);
  for(int i = 1; i <= m ; i ++ )
    if(!rf[i]) dfs(i,1);
  for(int i = 0 ; i < q; i ++ ){
    if(x[r[i]] + y[c[i]] != a[i]){
      cout << "No\n";
      return 0;
    }
  }
  for(int i = 1; i <= n; i ++ ){
    lf[i] = false;
  }
  for(int i = 1; i <= m ; i ++ )
    rf[i] = false;
  for(int i = 1; i <= n; i ++ ){
    if(lf[i]) continue;
    li = (int)2e9;
    ri = (int)2e9;
    dfs1(i,0);
    if(min((ll)li + ri,0ll) < 0ll){
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 13312
# include <iostream>
# include <vector>
# include <string>
# include <stack>

using namespace std;

string w;
int a[11];

bool ok(int n) {
    while(n > 0) {
        if(a[n % 10]) {
            return false;
        }
        n /= 10;
    }
    return true;
}

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

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

    while(!ok(n)) {
        n++;
    }

    cout << n;

    return 0;
}

Measured memory_bytes: 256
n, t = [int(_) for _ in input().split()]
l = [[int(i) for i in input().split()] for j in range(n)]

ans = float('inf')
for i in range(n):
    if l[i][1] <= t:
        ans = min(ans, l[i][0])

if ans == float('inf'):
    print("TLE")
else:
    print(ans)

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    ll N, M; cin >> N >> M;
    if(N == 2 || M == 2){
        cout << 0 << endl;
    }else if(N == 1 && M == 1){
        cout << 1 << endl;
    }else if(N == 1 || M == 1){
        cout << N*M - 2 << endl;
    }else{
        cout << (N-2)*(M-2) << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

itn H, W;
string S[202];
int a[202][202];


void solve() {
    FOR(h, 0, H + 1)
    a[h][0] = INF;
    FOR(w, 0, W + 1)
    a[0][w] = INF;
    FOR(h, 1, H + 1) {
        FOR(w, 1, W + 1) {
            if (h >= 2 && w >= 2) {
                a[h][w] = min(a[h - 1][w] + (S[h - 1][w - 1] != S[h - 2][w - 1]),
                    a[h][w - 1] + (S[h - 1][w - 1] != S[h - 1][w - 2]));
            } else if (h >= 2) {
                a[h][w] = a[h - 1][w] + (S[h - 1][w - 1] != S[h - 2][w - 1]);
            } else if (w >= 2) {
                a[h][w] = a[h][w - 1] + (S[h - 1][w - 1] != S[h - 1][w - 2]);
            }
            a[1][1] = !S[0][0];
        }
    }
    cout << (a[H][W] + 1) / 2 << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    FOR(H)
    cin >> S[i];
    FOR(H) {
        FOR(j, W) {
            if (S[i][j] == '#')
                S[i][j] = 0;
            else
                S[i][j] = 1;
        }
    }


    solve();
    return 0;
}


Measured memory_bytes: 384
//
// Created by 今村秀明 on 2016/09/05.
//
#include <stdio.h>
#include <vector>

using namespace std;

int N;
int K;
int a[100000];
vector<int> g[100000];
int ans = 0;

int dfs(int v) {
    int size = g[v].size();
    int steps = 0;
    for (int j = 0; j < size; j++) {
        int u = g[v][j];
        int h = dfs(u);
        steps = max(steps, h + 1);
    }
    if (steps == K - 1 && a[v] != 0) {
        a[v] = 0;
        steps = -1;
        ans++;
    }
    return steps;
}

int main() {
    scanf("%d %d", &N, &K);
    for (int i = 0; i < N; i++) {
        scanf("%d", a + i);
        a[i]--;
    }

    if (a[0] != 0) {
        a[0] = 0;
        ans++;
    }

    for (int i = 1; i < N; i++) {
        g[a[i]].push_back(i);
    }
    dfs(0);
    printf("%d\n", ans);

    return 0;
}

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

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputLine = Console.In.ReadLine();
            var inputs = inputLine.Split(new char[] { ' ', '\t', '　' });
            if (inputs.Length != 3)
            {
                return;
            }

            var integers = new List<int>();
            foreach (var s in inputs)
            {
                integers.Add(int.Parse(s));
            }

            Func<int, bool> check = (int i) =>
            {
                if (i < 1) return false;
                if (i > 10000) return false;
                return true;
            };
            foreach (var i in integers)
            {
                if (check(i) == false)
                {
                    return;
                }
            }

            integers.Sort();
            var output = string.Join(" ", integers);

            Console.WriteLine(output);
        }
    }
}


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

using namespace std;

int n;
long double d,x,ans;

int main()
{
	cin>>n>>d>>x;
	for(int i=n;i;i--)
	{
		ans+=d+(i*2-1)*x/2;
		d=(d*(i*2+2)+x*5)/(i*2);
		x=(i*2+4)*x/(i*2);
	}
	printf("%.10lf\n",(double)ans); 
} 

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

int main(void)
{
    ll N, P;
    cin >> N >> P;
    vector<int> A(N);
    vector<ll> Ps(2,0);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        Ps[A[i] % 2]++;
    }

    if(Ps[1] == 0){
        if(P == 0) cout << ((ll)1 << N) << endl;
        else cout << 0 << endl;
    } else{
        cout << ((ll)1 << N-1) << endl;
    }
  	return 0;
}

Measured memory_bytes: 3636
# coding: utf-8

import math
import re
import numpy as np
import copy

#読み込む
S = input().split(' ')
A = int(S[0])
B = int(S[1])
C = int(S[2])

K = int(input())

for i in range(K):
    if A >= B:
        B *= 2
    else:
        C *= 2

ans = "No"

#print(A,B,C)

if A < B and B < C:
    ans = "Yes"

print(ans)



Measured memory_bytes: 27180
#include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  cin>>n;
  vector<int> a(n),b(n);
  for(auto& i:a)cin>>i;
  for(int i=0;i<n;++i)b[i]=i;
  sort(b.begin(),b.end(),[&](int p,int q){return a[p]<a[q];});
  for(int i=0;i<n;++i)cout<<(i?" ":"")<<b[i]+1;
}

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

int main() {
    long n;
    cin >> n;
    long P[10];
    for (long i = 0; i < n; i++) {
        cin >> P[i];
    }

    sort(P, P + n);
    long sum = 0;
    for (long i = 0; i < n - 1; i++) {
        sum += P[i];
    }
    sum += P[n - 1] / 2;

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
x = int(input())

if x==2:
    print(2)
elif x==3:
    print(3)
else:
    while True:
        if x%2==0 or x%3==0:
            x += 1
            continue
        else:
            tmp = 0
            divisor_lst = [1, x]
            for i in range(1,x+1):
                if x%i==0 and i not in divisor_lst:
                    tmp = 1
                    x += 1
                    break
            if tmp==0:
                break
            elif tmp==1:
                continue
    print(x)

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

int main()
{
    string S;
    cin >> S;
    int count = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == '1') {
            count += 1;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MAXN 1009
int dp[MAXN][MAXN], h, w;
char adj[MAXN][MAXN];

const int mod = 1e9 + 7;

int calc(int i, int j){
    if (dp[i][j] != -1) return dp[i][j];
    if (i == h && j == w)   return dp[i][j] = 1;
    int res = 0;
    if (i < h && adj[i + 1][j] != '#')
        res = (res + calc(i + 1, j)) % mod;
    if (j < w && adj[i][j + 1] != '#')
        res =( res + calc(i, j+ 1) ) % mod;
    
    return dp[i][j] = res;
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    memset(dp, -1, sizeof dp);
    cin >> h >> w;
    rep(i, 1, h +1)    rep(j, 1, w + 1){
        cin >> adj[i][j];
    }
    cout << calc(1, 1) << '\n';
    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	ll dp[100][4][4][4][4];
	memset(dp, 0, sizeof(dp));

	set<string> s;
	s.insert("AGC");
	s.insert("ACG");
	s.insert("GAC");
	s.insert("AGGC");
	s.insert("AGTC");
	s.insert("ATGC");

	char chars[] = { 'A', 'G', 'C', 'T' };
	auto mod = (ll)1e9 + 7;

	for (auto i = 0; i < N; ++i)
	{
		for (auto j = 0; j < 4; ++j)
		{
			if (i == 0)
			{
				dp[i][j][0][0][0] = 1;
				continue;
			}

			for (auto k = 0; k < 4; ++k)
			{
				if (i == 1)
				{
					dp[i][j][k][0][0] = 1;
					continue;
				}

				for (auto l = 0; l < 4; ++l)
				{
					string temp;
					temp += chars[l];
					temp += chars[k];
					temp += chars[j];
					if (s.find(temp) != s.end())
					{
						continue;
					}

					if (i == 2)
					{
						dp[i][j][k][l][0] = 1;
						continue;
					}

					for (auto m = 0; m < 4; ++m)
					{
						string temp;
						temp += chars[m];
						temp += chars[l];
						temp += chars[k];
						temp += chars[j];
						if (s.find(temp) != s.end())
						{
							continue;
						}

						for (auto n = 0; n < 4; ++n)
						{
							dp[i][j][k][l][m] =
								(dp[i][j][k][l][m] + dp[i - 1][k][l][m][n]) % mod;
						}
					}
				}
			}
		}
	}

	auto ans = 0ll;
	for (auto j = 0; j < 4; ++j)
	{
		for (auto k = 0; k < 4; ++k)
		{
			for (auto l = 0; l < 4; ++l)
			{
				for (auto m = 0; m < 4; ++m)
				{
					ans = (ans + dp[N - 1][j][k][l][m]) % mod;
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    int N;
    char A[111], B[111], C[111];
    scanf("%d %s %s %s", &N, A, B, C);
    
    // 2. 操作回数を保存.
    int ans = 0;
    rep(i, N){
        set<char> s;
        s.insert(A[i]);
        s.insert(B[i]);
        s.insert(C[i]);
        ans += s.size() - 1;
    }
    
    // 3. 出力.
    printf("%d\n", ans);
    return 0;
    
}

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

int main()
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    long R[a], G[b], C[c], D[x+y];
    for(int i = 0; i < a; i++)
        cin >> R[i];
    for(int i = 0; i < b; i++)
        cin >> G[i];
    for(int i = 0; i < c; i++)
        cin >> C[i];

    sort(R, R+a);
    sort(G, G+b);
    sort(C, C+c);

    int p = 0;
    long long sum = 0;
    for(int i = 1; i <= x; i++)
        D[p++] = R[a-i];
    for(int i = 1; i <= y; i++)
        D[p++] = G[b-i];
    sort(D, D+x+y);
    p = 0;
    c--;
    while(c>=0)
    {
        if(D[p] > C[c])
            break;
        if(C[c] >= D[p])
        {
            D[p] = C[c];
            p++;
            c--;
        }
    }
    for(int i = 0; i < y+x; i++)
        sum += D[i];
    cout << sum;

}

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

int a[1<<19][2];

void update(int*a,int d){
	if(d<=a[1])return;
	if(d>a[0]){
		a[1]=a[0];a[0]=d;return;
	}
	a[1]=d;
}
int main(){
	int n;scanf("%d",&n);
	rep(i,1<<n){
		scanf("%d",&a[i][0]);
	}
	rep(i,n)rep(j,1<<n){
		if(!(j>>i&1)){
			update(a[j|1<<i],a[j][0]);
			update(a[j|1<<i],a[j][1]);
		}
	}
	int Max=0;
	for(int i=1;i<(1<<n);i++){
		Max=max(Max,a[i][0]+a[i][1]);
		printf("%d\n",Max);
	}
}

Measured memory_bytes: 7168
import sys
sys.setrecursionlimit(10**9)
from collections import Counter
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict
input = sys.stdin.readline
    
icase=0
if icase==0:
    n,m=map(int,input().split())
    a=[0]*m
    b=[0]*m
    for i in range(m):
        ai,bi=map(int,input().split())
        a[i]=ai-1
        b[i]=bi-1
elif icase==1:
    n,m=4,5
    a=[0, 2, 0, 1, 0]
    b=[1, 3, 2, 2, 3]
elif icase==2:
    n,m=6,5
    a=[1, 0, 4, 2, 3]
    b=[2, 1, 5, 3, 4]
elif icase==3:
    n,m=26,25
    a=[13, 13, 7, 1, 20, 0, 2, 3, 5, 13, 0, 0, 16, 3, 1, 15, 13, 13, 16, 9, 13, 8, 12, 6, 8]
    b=[14, 18, 25, 20, 24, 19, 13, 13, 21, 22, 14, 4, 23, 25, 10, 17, 17, 20, 20, 14, 21, 9, 22, 9, 11]
elif icase==4:
    f=open(r"C:\Users\nishi\999atcoder\q100\q087\testcase_01_in.dat")
    ll=f.readline()
    n,m=map(int,ll.split())
    a=[0]*m
    b=[0]*m
    for i in range(m):
        ll=f.readline()
        ai,bi=map(int,ll.split())
        a[i]=ai-1
        b[i]=bi-1
    f.close()

pair=[i for i in range(n)]

def root(x):
    if x==pair[x]:
        return x
    else:
        tmp=root(pair[x])
        pair[x]=tmp
        return tmp

def unite(x,y):
    x=root(x)
    y=root(y)
    if x==y:
        return
    elif x>y:
        pair[x]=y
    else:
        pair[y]=x

def q087():
    cc=[]
    c1=[1]*n
    c2=defaultdict(int)
    c2[1]=n
    c=n    
#    pair=[i for i in range(n)]
    for i in range(m-1):
#------------------------
        rta=root(a[m-i-1])
        rtb=root(b[m-i-1])
        if c1[rta]>=n or c1[rtb]>=n:
            cc.append(0)
            continue
        if rta<rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rta]+=c1[rtb]
            c1[rtb]=0
            d1=c1[rta]
#        pair[rtb]=rta
            unite(a[m-i-1],b[m-i-1])
        elif rta>rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rtb]+=c1[rta]
            c1[rta]=0
            d1=c1[rtb]
#        pair[rta]=rtb
            unite(a[m-i-1],b[m-i-1])
        else:
            cc.append(c)
            continue

        c2[d1]+=1    
        if c2[d2]>0:
            c2[d2]-=1
#    if c2[d2]==0:
#        del c2[d2]
        if c2[d3]>0:
            c2[d3]-=1
#    if c2[d3]==0:
#        del c2[d3]
#    print(c1)        
#    print(c2)     
        q=[]
        for c2k,c2v in c2.items():
            if c2v==0:
                q.append(c2k)
        while q:
            del c2[q.pop()]            
#    print(c2)     
        c3=[]
        for c2k,c2v in c2.items():
            c3.append((c2k,c2k*c2v))

        c=0
#    for i in range(len(c3)):
        for i,c3i in enumerate(c3):
            c+=c3i[1]*(c3i[1]-c3i[0])//2
#        for j in range(i+1,len(c3)):
            for j,c3j in enumerate(c3[0:i]):
                c+=c3i[1]*c3j[1]
        cc.append(c)

    for i in range(m-2,-1,-1):
        print(cc[i])
    print(n*(n-1)//2)
#-------------------------------
q087()
#-------------------------------



Measured memory_bytes: 92512
#include <stdio.h>
#define MAX 100000

int n,k;
long long T[MAX];

int check(long long p){
  int i=0,j;
  long long s;
 
  for(j=0;j<k;j++){
    s = 0;
    while(s + T[i] <= p){
      s += T[i];
      i++;
      if(i == n) return n;
    }
  }
  return 1;
}

int solve(){
  int v;
  long long left=0;
  long long right=MAX*10000;
  long long mid;
  while(right-left>1){
    mid = (right+left)/2;
    v = check(mid);
    if(v >= n) right = mid;
    else left = mid;
  }
  return right;
}

int main(){
  int i;
  long long ans;
  scanf("%d %d",&n,&k);;
  for(i=0;i<n;i++) scanf("%ld",&T[i]);
  ans = solve();
  printf("%ld\n",ans);
  return 0;
}

Measured memory_bytes: 1376
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n), sums(n+1);
    ll sum = 0;
    rep(i, n) cin >> a[i];
    rep(i, n) {
        sum += a[i];
        sums[i+1] += a[i] + sums[i];
        //cout << sums[i+1] << " : ";
    }


    ll ans = 1e18;
    for(int i = 1; i < n; i++) {
        ll b = sum - sums[i];
        ans = min(ans, abs(b - sums[i]));
    }

    cout << ans << endl;
}

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

#define PI 3.1415926535

double circumference(double r)
{
    double cir = 2*PI*r;
    return cir;
}
int main()
{
  double r;
  cin >> r;
  cout << fixed;
  cout << setprecision(4) << circumference(r);
  return 0;
}


Measured memory_bytes: 3784
int main(){
    int n,k,i,j,count=0;
    int a[10000];
    int b[10000];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
     scanf("%d",&k);
    for(i=0;i<k;i++){
        scanf("%d",&b[i]);
    }
    for(i=0;i<k;i++){
        for(j=0;j<n;j++){
            if(a[j]==b[i]){
                count++;
                break;
            }
        }
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2048
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
#https://note.nkmk.me/python-union-find/

    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n
    
        def find(self, x):
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]
    
        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)
    
            if x == y:
                return
    
            if self.parents[x] > self.parents[y]:
                x, y = y, x
    
            self.parents[x] += self.parents[y]
            self.parents[y] = x
    
        def size(self, x):
            return -self.parents[self.find(x)]
    
        def same(self, x, y):
            return self.find(x) == self.find(y)
    
        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]
    
        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]
    
        def group_count(self):
            return len(self.roots())
    
        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}
    
        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    n=I()
    lisx=[]
    lisy=[]
    edge=[]
    for i in range(n):
        x,y=MI()
        lisx.append([x,i])
        lisy.append([y,i])
    lisx.sort(key=lambda x:x[0])
    lisy.sort(key=lambda x:x[0])
    for i in range(n-1):
        edge.append([lisx[i][1],lisx[i+1][1],lisx[i+1][0]-lisx[i][0]])
        edge.append([lisy[i][1],lisy[i+1][1],lisy[i+1][0]-lisy[i][0]])
    edge.sort(key=lambda x:x[2])
    #print(edge)
    ans=0
    uf=UnionFind(n)
    for x,y,z in edge:
        if uf.same(x,y):
            continue
        else:
            uf.union(x,y)
            ans+=z
    print(ans)
        
        
    
if __name__=="__main__":
    main()


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

int main() {
  int n;
  cin >> n;
  string ans = "AB";

  if(n/1000 < 1){
    ans = ans + "C";
  }else{
    ans = ans + "D";
  }

  cout << ans << endl;

  return 0;
}

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

int main(void){
    int n,k;
    cin>>n>>k;
    int l[n];
    for(int i=0;i<n;i++) cin>>l[i];
    sort(l, l + n, greater<int>());
    int sum=0;
    for(int i=0;i<k;i++) sum += l[i];
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int issame(string a,string b)
{int c=a.size();
int p=b.size();
if(c!=p)
	return 0;
else{
	int d[c],e[c];
	for (int i = 0; i < c; ++i)
	{d[i]=a[i]-'0';
	}
	sort(d,d+c);
	for (int i = 0; i < c; ++i)
	{e[i]=b[i]-'0';
	}
	sort(e,e+c);
	for (int i = 0; i < c; ++i)
	{if(d[i]!=e[i])
		{
			return 0;}
	}

return 1;}
}		

int main()
{int n;
cin>>n;
int h[n+1],a[n+1];
for (int i = 1; i <=n; ++i)
{cin>>h[i];
}
h[0]=0;
a[0]=0;
a[1]=0;
a[2]=abs(h[2]-h[1]);
for (int i =3; i <=n; ++i)
{a[i]=min(a[i-1]+abs(h[i]-h[i-1]),a[i-2]+abs(h[i]-h[i-2]));
}
cout<<a[n]<<endl;


return 0;}






Measured memory_bytes: 4408
#include <stdio.h>

int main(){
  int a[3],i,f=0;
  for(i=0;i<3;i++) scanf("%d",&a[i]);
  
  if(a[0]==a[1]+a[2])f=1;
  else if(a[1]==a[0]+a[2])f=1;
  else if(a[2]==a[0]+a[1])f=1;
  
  if(f==1)printf("Yes");
  else printf("No");
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
    int a,b,ab;
    scanf("%d %d",&a,&b);
    ab=a+b;
    if(a%3==0||b%3==0||ab%3==0){
        printf("Possible\n");
    }else{
        printf("Impossible\n");
    }
    return 0;
}



Measured memory_bytes: 128