akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

//ソートされたA[left~mid]とA[mid+1~right]をくっつける関数
void merge(int* A, int left, int mid, int right, int* B){
    int i,j,k;
    int tmp;

    //kは一時的な配列Bの現在の添字、iは前半A[left~mid]、jは後半A[mid+1~right]を指す添字
    k=left; i=left; j=mid+1;
    while(k<=right){
        if(j>right) tmp=A[i++]; //前半のみにデータがある
        else if(i>mid) tmp=A[j++]; //後半のみにデータがある
        else if(A[i]<=A[j]) tmp=A[i++]; //前半の方が小さい
        else tmp=A[j++]; //後半の方が小さい

        B[k++]=tmp;
    }
    for(i=left;i<=right;i++) A[i]=B[i]; //元の配列に戻す
}

//A[left]~A[right]までの配列を昇順にマージソートする関数
void merge_sort(int* A, int left, int right, int*B){
    int mid;

    if(left<right){
        mid=(left+right)/2;
        merge_sort(A,left,mid,B); //A[left]~A[mid]までを再帰的にソート
        merge_sort(A,mid+1,right,B); //A[mid+1]~A[right]までを再帰的にソート
        merge(A,left,mid,right,B); //分割した二つをくっつける
    }
}

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

    //d[0]~d[N-1]に格納する
    int* d;
    NEW(d,N);
    for(int i=0;i<N;i++){
        scanf("%d",&d[i]);
    }

    //dをマージソートで昇順にする(dkariはマージソート用の仮メモリ)
    int* dkari;
    NEW(dkari,N);
    merge_sort(d,0,N-1,dkari);
    free(dkari);

    //d[0]~d[N/2-1]がABC用、d[N/2]~d[N-1]がARC用
    int ans;
    if(d[N/2-1]==d[N/2]) ans=0;
    else ans=d[N/2]-d[N/2-1];
    
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 896
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = a; i >= (b); --i)
#define repdl(i, a, b) for(ll i = a; i >= (b); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void writef(T ...tail) { write(tail...); cout << flush; }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  if (v.size()) {
    rep(i, 0, sz(v) - 1)
      out << v[i] << " ";
    out << v.back();
  }
  return out;
}
#endif
#include <atcoder/convolution>
#include <atcoder/dsu>
#include <atcoder/fenwicktree>
#include <atcoder/lazysegtree>
#include <atcoder/math>
#include <atcoder/maxflow>
#include <atcoder/mincostflow>
#include <atcoder/modint>
#include <atcoder/scc>
#include <atcoder/segtree>
#include <atcoder/string>
#include <atcoder/twosat>
using namespace std;
using namespace atcoder;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int n, q; read(n, q);
  fenwick_tree<ll> tree(n);

  rep(i, 0, n) {
    int t; read(t);
    tree.add(i, t);
  }

  rep(i, 0, q) {
    int t, u, v; read(t, u, v);
    if (t == 0)
      tree.add(u, v);
    else
      write(tree.sum(u, v));
  }
}



Measured memory_bytes: 8256
n,m,*X=map(int,open(0).read().split())
E=[0]*(max(X)+1)
P=[0]*m
M=[0]*m
for x in X:E[x]+=1;M[x%m]+=1
for i,e in enumerate(E):P[i%m]+=e//2
ans=0
for i in range(m//2+1):
	if i==0 or i*2==m:
		ans+=M[i]//2
	else:
		l=min(M[i],M[(m-i)%m])
		ans+=l+min((M[i]-l)//2,P[i])+min((M[(m-i)%m]-l)//2,P[(m-i)%m])
print(ans)

Measured memory_bytes: 14324
import heapq as h
I=lambda:list(map(int,input().split()))
n,k=I()
q=[]
v=i=T=A=0
l=[0]*-~n
for a,b in sorted([I()for _ in[0]*n],key=lambda x:-x[1]):
 if i<k:
  if l[a]:h.heappush(q,b)
  else:T+=v*2+1;v+=1
  T+=b
 elif l[a]^1and q:T+=b+v*2+1-h.heappop(q);v+=1
 A=max(A,T);i+=1;l[a]=1
print(A)

Measured memory_bytes: 33780
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int dist[111111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++) dist[i]=10000;
	dist[1]=1;
	deque<int> q;
	q.pb(1);
	while(!q.empty())
	{
		int u=q.front(); q.pop_front();
		if(dist[(u*10)%n]>dist[u])
		{
			dist[(u*10)%n]=dist[u]; q.push_front((u*10)%n);
		}
		if(dist[(u+1)%n]>dist[u]+1)
		{
			dist[(u+1)%n]=dist[u]+1; q.pb((u+1)%n);
		}
	}
	cout<<dist[0]<<'\n';
}	


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

int main(void){
    int n;
    string s,t;
    cin >> n >> s >> t;
    rep(i,n){
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
hlsit=list(map(int,input().split()))
ans=[0 for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    if hlsit[a-1]>hlsit[b-1]:
        ans[b-1]+=1
    elif hlsit[a-1]<hlsit[b-1]:
        ans[a-1]+=1
    else:
        ans[a - 1] += 1
        ans[b-1]+=1
#print(ans)
anscount=0
for i in ans:
    if i==0:
        anscount+=1
print(anscount)

Measured memory_bytes: 91576
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string card[40],cpcard[40];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>card[i];
        cpcard[i]=card[i];
    }
    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
            int a=card[j][1]-'0',b=card[j-1][1]-'0';
            if(a<b) swap(card[j],card[j-1]);
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<2;j++){
            cout<<card[i][j];
        }
        if(i!=n-1) cout<<" ";
    }
    cout<<endl;
    cout<<"Stable"<<endl;
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            int a=cpcard[j][1]-'0',b=cpcard[minj][1]-'0';
            if(a<b) minj=j;
        }
        swap(cpcard[i],cpcard[minj]);
    }
    for(int i=0;i<n;i++){
        cout<<cpcard[i];
        if(i!=n-1) cout<<" ";
    }
    cout<<endl;
    bool flag=true;
    for(int i=0;i<n;i++){
        if(card[i]!=cpcard[i]) flag=false;
    }
    if(flag) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
    return 0;
}



Measured memory_bytes: 3188
S = input()
a = int(S[:2])
b = int(S[2:])
if a== 0 and b >= 13:
    print("NA")
elif b== 0 and a >= 13:
    print("NA")
elif a==0 and b==0:
    print("NA")
elif a==0 and b <= 12:
    print("YYMM")
elif a<=12 and b == 0:
    print("MMYY")
elif a >= 13 and b <= 12:
    print("YYMM")
elif b >= 13 and a <= 12:
    print("MMYY")
elif a<= 12 and b<= 12:
    print("AMBIGUOUS")
else:
    print("NA")

Measured memory_bytes: 3064
s=input()

for i in range(2**3):
  chk=""
  for j in range(3):
    chk+=s[j]
    if (i>>j)&1==1:
      chk+='+'
    else:
      chk+='-'
  chk+=s[3] 
  if eval(chk)==7:
    break
print(f"{chk}=7")

Measured memory_bytes: 9000
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define MODD 1000000007
#define ll long long
using namespace std;

int A[111111];
int main() {
    int N,x;
    cin>>N>>x;
    for(int i=1;i<=N;i++) {
        cin>>A[i];
    }
    
    ll ans = 0;
    for(int i=1;i<=N-1;i++) {
        if (A[i]+A[i+1] > x) {
            ll c = min(A[i+1], A[i]+A[i+1]-x);
            A[i+1] -= c;
            ans += c;
        }
        
        if (A[i]+A[i+1] > x) {
            ll c = min(A[i], A[i]+A[i+1]-x);
            A[i] -= c;
            ans += c;
        }
        
        
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 640
/**
 * Combinatorial - Coin Changing Problem
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.String;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line.substring(0, line.indexOf(' ')));
			int m = parseInt(line.substring(line.indexOf(' ') + 1));

			int[] ns = new int[n + 1];
			int[] cs = new int[m];

			for (int i = 1; i < ns.length; i++) ns[i] = Integer.MAX_VALUE;

			StringTokenizer st = new StringTokenizer(br.readLine());
			for (int i = 0; i < m; i++) cs[i] = parseInt(st.nextToken());

			//solve
			for (int i = 0; i < cs.length; i++) {
				for (int j = cs[i]; j < ns.length; j++) {
					ns[j] = Math.min(ns[j], ns[j - cs[i]] + 1);
				}
			}
			System.out.println(ns[n]);
		}//end while
	}//end main
}

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

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

    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    priority_queue<pii> que;
    for (int i = 0; i < A; ++i) {
        int p;
        cin >> p;
        que.push({p, 0});
    }
    for (int i = 0; i < B; ++i) {
        int q;
        cin >> q;
        que.push({q, 1});
    }
    for (int i = 0; i < C; ++i) {
        int r;
        cin >> r;
        que.push({r, 2});
    }

    int rcnt = 0;
    ll ans = 0;
    while (X + Y - rcnt > 0) {
        auto p = que.top();
        que.pop();
        int cost = p.first;
        int num = p.second;
        if (num == 0 && X <= 0)
            continue;
        if (num == 1 && Y <= 0)
            continue;
        ans += cost;
        if (num == 0)
            X--;
        if (num == 1)
            Y--;
        if (num == 2)
            rcnt++;
    }

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


Measured memory_bytes: 6512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;

int main(){
    int a[3];
    lol(i,3)cin>>a[i];
    sort(a,a+3);
    int ans=0;
    int cnt=0,tnt=0;
    lol(i,2){
	ans+=(a[2]-a[i])/2;
	if((a[2]-a[i])%2==0)cnt++;
	else{
	    tnt++;
	    ans+=2;
	}
    }//cout<<ans<<endl;
    if(tnt*2>cnt)ans+=cnt-tnt*2+1;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	set<int> st;
	rep(i, 3) {
		int a;
		cin >> a;
		st.insert(a);
	}
	cout << st.size() << endl;
	return 0;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
           int n = sc.nextInt();
           if(n == 0) break;
           int[] x = new int[n];
           int[] y = new int[n];
           x[0] = 0;
           y[0] = 0;
           for(int i = 1; i < n; i++){
               int a = sc.nextInt();
               int b = sc.nextInt();
               //System.out.println(a + " " + b);
               switch(b){
               case 0:
                   x[i] = x[a] - 1;
                   y[i] = y[a];
                   break;
               case 1:
                   x[i] = x[a];
                   y[i] = y[a] - 1;
                   break;
               case 2:
                   x[i] = x[a] + 1;
                   y[i] = y[a];
                   break;
               case 3:
                   x[i] = x[a];
                   y[i] = y[a] + 1;
                   break;
               }
           }
        //   for(int i = 0; i < n; i++){
        //       System.out.println(x[i] + " " + y[i]);
        //   }
           int xmax = -300;
           int ymax = -300;
           int xmin = 300;
           int ymin = 300;
           for(int i = 0; i < n; i++){
               xmax = Math.max(x[i], xmax);
               xmin = Math.min(x[i], xmin);
               ymax = Math.max(y[i], ymax);
               ymin = Math.min(y[i], ymin);
           }
           //System.out.println(xmax + " " + xmin + " " + ymax + " " + ymin);
           int xans = xmax - xmin + 1;
           int yans = ymax - ymin + 1;
           System.out.println(xans + " " + yans);
       }
    }
}



Measured memory_bytes: 41088
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include <string.h>
using namespace std;
int main(){
	int N,L,ans=0,temp=0,a;
	vector<int> data;
	cin>>N>>L;
	for(int i=0;i<N;i++){
		cin>>a;
		data.push_back(L-a);
	}
	int dir=-1;
	if(data[0]<data[1])dir=1;
	temp+=data[0];
	for(int i=1;i<data.size();i++){
		if((dir==1&&data[i-1]<data[i])||(dir==-1&&data[i-1]>data[i])){
			temp+=data[i];
		}else{
			dir=-dir;
			ans=max(temp,ans);
			//cout<<ans<<endl;
			temp=data[i]+data[i-1];
		}
	}
	ans=max(ans,temp);
	cout<<ans<<endl;
	
}

Measured memory_bytes: 1676
fun main (args:Array<String>){
    val stlist = readLine()!!.split(" ")
    var (a, b) = readLine()!!.split(" ").map(String::toInt)
    val u : String = readLine()!!
    if(u == stlist[0]){
        a--
    }
    if(u == stlist[1]){
        b--
    }
    print(a)
    print(" ")
    print(b)
    return
}


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

constexpr int D[]={
    0b0111111,
    0b0000110,
    0b1011011,
    0b1001111,
    0b1100110,
    0b1101101,
    0b1111101,
    0b0100111,
    0b1111111,
    0b1101111
};

bool solve(){
    int n;
    cin >> n;
    if(n == -1) return false;
    int S = 0;
    for(int i=0;i<n;i++){
        int d;
        cin >> d;
        cout << bitset<7>(S^D[d]) << endl;
        S = D[d]; 
    }
    return true;
}

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



Measured memory_bytes: 2996
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

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

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

map<string, int> memo;


int main() {
	//sort(a.begin(),a.end());
	int x;
	cin >> x;
	int p = x;
	while (!is_prime(p)) {
		p++;
	}
	cout << p;
	return 0;
}









Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,i,a,b,c,ans=0;
  scanf("%d",&n);
  char str[3][n];
  for(i=0;i<3;i++) scanf("%s",str[i]);
  for(i=0;i<n;i++){
    a=b=c=0;
    if(str[0][i]==str[1][i]) a=1;
    if(str[0][i]==str[2][i]) b=1;
    if(str[1][i]==str[2][i]) c=1;
    if(a==1&&b==1) ans+=0;
    else if(a==0&&c==0&&b==0)ans+=2;
    else ans+=1;
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 128
while 1:
    a,op,b=input().split()
    a,b=int(a),int(b)
    if op=="?":
        break
    elif op=="+":
        print(a+b)
    elif op=="-":
        print(a-b)
    elif op=="*":
        print(a*b)
    elif op=="/":
        print(a//b)


Measured memory_bytes: 5600
import std.algorithm;
import std.stdio;

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		auto b = new bool [n];
		b[0] = true;
		auto c = new int [n];
		c[] = 1;
		foreach (j; 0..m)
		{
			int u, v;
			readf (" %s %s", &u, &v);
			u--;
			v--;
			if (b[u])
			{
				b[v] = true;
			}
			c[u]--;
			c[v]++;
			if (c[u] == 0)
			{
				b[u] = false;
			}
		}
		writeln (sum (b));
	}
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef long double LD;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()

const double eps=1e-5;
const LL INF=(LL)1e9*(LL)1e9;


int main()
{
    LL n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    a=abs(b-a);
    
    bool can;
    if(d*(n-1)<a)
    {
        can=false;
    }
    else if(c*(n-1)<=a)//a<=d*(n-1)
    {
        can=true;
    }
    else
    {
        can=false;
        REP(i,n)
        {
            if((i*d-(n-1-i)*d<= a && a<=i*d-(n-1-i)*c)
            || (i*d-(n-1-i)*d<= -a && -a<=i*d-(n-1-i)*c))
            {
                can=true;
                break;
            }
        }
    }
    if(can)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


Measured memory_bytes: 256
n = int(raw_input())
A = map(int, raw_input().split())

q = int(raw_input())
M = map(int, raw_input().split())

result = []
for i in range(q):
    result.append('no')

def adder(axis = 0, nums = [0], M = [0], q = 0):
    for i in range(q):
        if M[i] == axis:
            result[i] = 'yes'
    length = len(nums)
    if length != 0:
        for i in range(length):
            sum_n = axis + nums[i]
            adder(sum_n, nums[i+1:], M, q)

for i in range(n):
    adder(A[i], A[i+1:], M, q)

for i in result:
    print(i)

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

int main()
{
	int n[4];

	cin >> n[0] >> n[1] >> n[2] >> n[3];
	sort(n, n + 4);

	if (n[0] * 1000 + n[3] * 100 + n[2] * 10 + n[1] == 1974)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a1,a2,a3] <- getIntList
    print . sum . take 2 . sort $ map abs [a1-a2,a2-a3,a3-a1]

Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int A[105];

int main()
{
	int N, D, X;
	cin >> N >> D >> X;
	REP(i, N)
	{
		cin >> A[i];
	}

	ll ans = 0;
	FOR(i, D + 1, 1)
	{
		REP(j, N)
		{
			if ((i - 1) % A[j] == 0)
			{
				ans++;
			}
		}
	}
	cout << ans + X << endl;
	return 0;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    char grid[h][w];
    rep(i, h) {
        rep(j, w) {
            cin >> grid[i][j];
        }
    }
    rep(i, h) {
        rep(j, w) {
            if (grid[i][j] == '#') continue;
            int cnt = 0;
            for(int dx = -1; dx <= 1; dx++) {
                for (int dy = -1; dy <= 1; dy++) {
                    int x = i + dx;
                    int y = j + dy;
                    if (0 <= x and x < h and 0 <= y and y < w) {
                        if (grid[x][y] == '#') cnt++;
                    }
                }
            }
            grid[i][j] = '0' + cnt;
        }
    }
    rep(i, h) {
        rep(j, w) {
            cout << grid[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 3608
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000;
typedef long long ll;
ll n,m,P,d[2500],d1[2500],d2[2500];
struct edge{ll a;ll b;ll c;};
vector<edge>v;
queue<ll>q;
vector<ll>ch1[2500],ch2[2500];

int main(void){
    cin>>n>>m>>P;
    
    for(int i=1;i<n;i++)d[i]=INF;
    for(int i=0;i<m;i++){
        struct edge add;
        cin>>add.a>>add.b>>add.c;
        add.a--,add.b--,add.c=P-add.c;
        ch1[add.a].push_back(add.b);
        ch2[add.b].push_back(add.a);
        v.push_back(add);
    }
    
    d1[0]=1;
    for(auto x:ch1[0]){
        q.push(x);
    }
    while(!q.empty()){
        ll p=q.front();
        q.pop();
        if(d1[p]==0){
            for(auto x:ch1[p])q.push(x);
            d1[p]=1;
        }
    }
    
    d2[n-1]=1;
    for(auto x:ch2[n-1]){
        q.push(x);
    }
    while(!q.empty()){
        ll p=q.front();
        q.pop();
        if(d2[p]==0&&d1[p]==1){
            for(auto x:ch2[p])q.push(x);
            d2[p]=1;
        }
    }
    
    
    
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            struct edge e=v[j];
            if(d2[e.a]==1&&d2[e.b]==1&&d[e.a]+e.c<d[e.b]){
                d[e.b]=d[e.a]+e.c;
                if(i==n-1){
                    cout<<-1<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<max(0LL,-d[n-1])<<endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const ll MOD = pow(10, 9) + 7;

ll powmod(ll a, ll p, ll MOD) {
	ll ans = 1;
	ll mul = a;
	for (; p > 0; p >>= 1, mul = (mul * mul) % MOD) {
		if ((p & 1) == 1)ans = (ans * mul) % MOD;
	}
	return ans;
}

ll combmod(ll n, ll r, ll MOD){
  vector<ll> ff(n+1), vff(n+1);
  // 1! ~ n!
  ff[0] = 1;
  for(ll i = 1; i < n + 1; i++) {
    ff[i] = ff[i - 1] * i % MOD;
  }
  // n!^(MOD-2) (= n!^(-1))
  ll inv = powmod(ff[n], MOD - 2, MOD);

  // n!^(-1) ~ 1!^(-1)
  vff[n] = inv;
  for(ll i = n - 1; i >= 0; i--) {
    vff[i] = vff[i + 1] * (i + 1) % MOD;
  }

  // n combination r
  ll comb = (((ff[n] * vff[r]) % MOD) * vff[n - r]) % MOD;

  return comb;
}

int main() {

  ll n, m;
  cin >> n >> m;

  ll tmp = m;


  ll count = 0;
  ll iter = 2;

  ll ans0, ans1, ans2;
  ll ans = 1;

  //ans1 = fact(n-1);
  while(tmp != 1){
    if (tmp % iter != 0) {
      iter++;
      if (count != 0){
        ans *= combmod(n - 1 + count, n - 1, MOD) % MOD;
        ans %= MOD;
      }
      count = 0;
    } else {
      count++;
      tmp /= iter;
    }
  }

  if (count != 0) {
    //ans0 = fact(n+count-1);
    //ans2 = fact(count);
    // ans0 = fact_m(count + n - 1, count);
    // ans *= ans0/ans1 % aa;
    // ans = ans % aa;
    ans *= combmod(n - 1 + count, n - 1, MOD) % MOD;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1860
#include <stdio.h>

int main() {
  int in;
  float v=0;
  scanf("%d",&in);
  for (int i = 0; i < in; i++) {
    int a;
    scanf("%d\n",&a);
    v += 1.0/a;
  }
  printf("%.5f\n", 1/v);
  return 0;
}


Measured memory_bytes: 128
n = gets.to_i
t = 0
x = 0
y = 0

n.times do
  ti, xi, yi = gets.split.map(&:to_i)

  distance = (xi - x).abs + (yi - y).abs
  time = ti - t

  if distance > time || (time - distance).odd?
    puts 'No'
    exit
  end
  ti = t
  xi = x
  yi = y
end
puts 'Yes'

Measured memory_bytes: 1788
// sandeep_007  
#include <bits/stdc++.h>
 
using namespace std; 
 
#define PI acos(-1)
#define mod 1000000007
#define ll long long
#define nitro std::ios_base::sync_with_stdio (false); cin.tie(NULL)
#define pb push_back
#define mp make_pair
#define vi vector < int >
#define mod 1000000007
#define md 998244353
#define rep(i,a,b) for(int i=a;i<b;i++)
#define FF first
#define SS second
#define all(a) (a).begin(),(a).end()

ll power(ll x,ll y,ll p){
    ll res = 1;   
    x = x % p;    
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
 
        y = y>>1; 
        x = (x*x) % p; 
    }
    return res;
}

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

int32_t main () {
    nitro;
 
    #ifdef DBG
        freopen("in","r",stdin);
    #endif
    int n; cin >> n;
    vector<int> a(n);
    rep(i,0,n) cin >> a[i];	
    ll ans = a[0];
    rep(i,1,n) ans = gcd(ans,a[i]);
    cout << ans << endl;
	return 0;
}   

Measured memory_bytes: 640
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 4003
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>power;
int main()
{
    vector<char>vc;
    cin>>n;
    FOR(i,n)
    {
        cin>>a;
        v.p_b(a);
    }
    ll ans=0;
    FOR(i,n)
    {
        for(ll j=i+1;j<n;j++) ans+=(v[i]*v[j]);
    }
    cout<<ans<<endl;
}
/*
5
4
3
2
3
4
4
3
3
4
2
3
*/


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

using namespace std;

int main() {

    int n, m;
    cin >> n >> m;
    priority_queue<int> a;
    for(int i=0; i<n; i++) {
        int temp;
        cin >> temp;
        a.push(temp);
    }

    for(int i=0; i<m; i++) {
        int top = a.top();
        a.pop();
        top /= 2;
        a.push(top);
    }

    unsigned long long sum = 0;
    while(!a.empty()) {
        sum += a.top();
        a.pop();
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 892
import sys
import bisect
input = sys.stdin.readline
n = int(input().strip())
q = [-int(input().strip())]
qapp = q.append
bis_r = bisect.bisect_right
for i in range(n-1):
  a = -int(input().strip())
  if q[-1] <= a:
    qapp(a)
  else:
    b = bis_r(q,a)
    q[b] = a
print(len(q))

Measured memory_bytes: 7068
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
	ll n, k, p = 0, cnt = 0;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n){
		cin >> a[i];
		a[i]--;
	}
	vector<bool> v(n, true);
	while(v[p]){
		v[p] = false;
		p = a[p];
		cnt++;
	}
	if(k <= cnt){
		int now = 0, j = 0;
		rep(i, k){
			j = a[j];
		}
		cout << j+1 << endl;
	}else{
		int now = 0;
		vector<bool> ok(n, true);
		vector<int> b;
		while(ok[p]){
			ok[p] = false;
			b.push_back(p+1);
			p = a[p];
			now++;
		}
		k -= cnt - now;
		cout << b[k % now];
	}
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

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

LL f(LL n) {
    LL res = 0;
    while(n > 0){
        n/=10;
        res++;
    }
    return res;
}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    LL n;cin >> n;
    LL ans = 1000000;
    for(LL i=1;i*i <= n;i++){
        if(n%i != 0) continue;
        ans = min(ans, max(f(i), f(n/i)));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
  while(true){
    int rem=100;
    int b,r,g,c,s,t;
    scanf("%d%d%d%d%d%d", &b, &r, &g, &c, &s, &t);
    if(b==0&&r==0&&g==0&&c==0&&s==0&&t==0)break;
    int bonus = 5*b + 3*r;
    rem -= 3*(t-s-5*b-3*r);
    rem += 13*bonus;
    rem += 7*g+2*c;
    rem += 15*b+15*r;

    printf("%d\n", rem);
  }
  return 0;
}

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin, (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  string S;
  bool flag = true;
  cin >> S;
  rep(i, S.size()-1) {
    if (S[i] == S[i+1]) {
      flag = false;
      puts("Bad");
      break;
    }
  }
  if (flag)
    puts("Good");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>
#include <cstdint>
#include <cstring>

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int main()
{
	int A,B,C;
	cin >> A >> B >> C;

	if (C - (A - B) < 0){
		cout << 0 << endl;
		return 0;
	}

	cout << C - (A - B) << endl;

	//system("pause");

	return 0;
	
	//int p[255];
	//int c[255];

	//int N;
	//cin >> N;
	//
	//int p[255];
	//int c[255];

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

	//memcpy(c, p, 255);
	//sort(p, p + N);

	//int counter = 0;

	//for (int i = 0; i < N; i++){
	//	//cout << c[i] << "," << p[i] << endl;
	//	if (c[i] != p[i]){
	//		++counter;
	//	}
	//}

	//if (counter <= 2){
	//			cout << "YES" << endl;
	//			
	//}
	//else{
	//	cout << "NO" << endl;
	//}

	////system("pause");
	//return 0;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         998244353
#define mode        1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323



void solve()
{
       ll n,q;
       string s;
       cin>>n>>q>>s;
       ll c[n];
       memset(c,0,sizeof c);
       rep(i,1,n)
       {
              c[i]=c[i-1];
              if(s[i]=='C' && s[i-1]=='A') c[i]++;
       }
       while(q--)
       {
              ll l,r;
              cin>>l>>r;
              l--,r--;
              cout<<c[r]-c[l]<<endl;
       }
}

int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 1872
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i = ((int)(x) - 1); i >= 0; i--)
#define rreps(i,x) for(int i = ((int)(x)); i > 0; i--)

#define all(x) (x).begin(), (x).end()

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

int gcd(int a, int b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

using ll = long long;


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

    ll ansi = -1;
    ll ansj = -1;
    ll ansk = -1;
    for(ll i = 0; i <= N; i++){
        for(ll j = 0; j <= N; j++){
            if(N-(i+j) < 0) continue;

            if((i * 10000 + j * 5000 + (N-(i+j)) * 1000) == Y){
                ansi = i;
                ansj = j;
                ansk = N-(i+j);
            } 
        }
    }

    cout << ansi << " " << ansj << " " << ansk << endl;
    return 0;
}



Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
x = [None] * N
for _ in range(M):
    s, c = lr()
    s -= 1
    if s == 0 and c == 0 and N > 1:
        print(-1); exit()
    if x[s] and x[s] != c:
        print(-1); exit()
    x[s] = c

if N == 1:
    if x[0] == 0 or x[0] == None:
        print(0); exit()
for i in range(N):
    if x[i] == None:
        if i == 0:
            x[i] = 1
        else:
            x[i] = 0

# x が0の場合
print(''.join(str(y) for y in x))


Measured memory_bytes: 3064
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a, a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cerr << a[k] << " ";} cout << "\n"; }
#define PI 3.14159265358979323846
ll fac[111111];
ll mod = 1000000007;
ll cnk(ll n, ll k) { return (fac[n] * (modInverse((fac[k] * fac[n - k]) % mod, mod))) % mod;}
ld inf = 1e15;

int main(){
	FASTIO;
	ll n, m; cin >> n >> m;
	vector<ll> g[n];
	for (int k = 0; k < m; k++) {
	    ll x, y; cin >> x >> y;
	    --x; --y;
	    g[x].pb(y);
	    g[y].pb(x);
	}
	bool vis[n]; memset(vis, 0, sizeof vis);
	vis[0] = 1;
	queue<ll> q; q.push(0);
	ll ans[n]; memset(ans, -1, sizeof ans);
	while (!q.empty()){
	    ll u = q.front();
	    q.pop();
	    for (ll e: g[u]) {
	        if (!vis[e]) {
	            q.push(e), vis[e] = true;
	            ans[e] = u;
	        }
	    }
	}
	bool ok = true;
	for (int k = 1; k < n; k++) {
	    if (ans[k] == -1)
	        ok = false;
	}
	if (!ok)
	    return cout << "No\n", 0;
	cout << "Yes\n";
	for (int k = 1; k < n; k++)
	    cout << ans[k] + 1 << "\n";
	cout << endl;
	return 0;
}

Measured memory_bytes: 13120
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  string S;
  std::cin >> S;
  ll ans = 1;
  std::vector<int> count(26, 0);
  range(i, N) count[S[i] - 'a']++;
  range(i, 26) ans = (ans * (count[i] + 1))%MODs;
  std::cout << ans - 1 << '\n';
  return 0;
}


Measured memory_bytes: 760
k,a,b=map(int,input().split())
if b-a<=2:
    print(k+1)
    quit()
if (k-a+1)%2==0:
    print((k-a+1)//2*(b-a)+a)
else:
    print((k-a+1)//2*(b-a)+a+1)

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

#define fi first
#define se second
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;

const int N = 15 + 2;
const int M = 14348907 + 5;
const int K = (1 << 15) + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

ll x[N], y[N], p[N];
int n;

ll mnDisX[K][N], mnDisY[K][N];
ll f[M];
int cnt[M]; // cnt of f

int a[N];

void DFS(int dep, int x, int _cnt) {
	if (dep == n) {
		int s = 0, t = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] == 1) s |= (1 << i);
			if (a[i] == 2) t |= (1 << i);
		}
		for (int i = 0; i < n; i++)
			f[x] += min(mnDisX[s][i], mnDisY[t][i]);
		cnt[x] = _cnt;
		return;
	}
	for (int i = 0; i < 3; i++) {
		a[dep] = i;
		DFS(dep + 1, x * 3 + a[dep], _cnt + (i > 0));
	}
}

int main() {
	ios::sync_with_stdio(0);

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i] >> y[i] >> p[i];

	for (int s = 0; s < (1 << n); s++) {
		for (int i = 0; i < n; i++) {
			ll tmp = abs(x[i] * p[i]);
			for (int j = 0; j < n; j++)
				if ((s >> j) & 1)
					tmp = min(tmp, abs(x[i] - x[j]) * p[i]);
			mnDisX[s][i] = tmp;
		}
	}

	for (int s = 0; s < (1 << n); s++) {
		for (int i = 0; i < n; i++) {
			ll tmp = abs(y[i] * p[i]);
			for (int j = 0; j < n; j++)
				if ((s >> j) & 1)
					tmp = min(tmp, abs(y[i] - y[j]) * p[i]);
			mnDisY[s][i] = tmp;
		}
	}

	DFS(0, 0, 0);

	static ll ans[K];
	memset(ans, 0x3f, sizeof(ans));
	int upp = pow(3, n);

	for (int i = 0; i < upp; i++) {
		ans[cnt[i]] = min(ans[cnt[i]], f[i]);
		// cout << f[i] << endl;
	}
	for (int i = 0; i <= n; i++)
		cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 181144
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
 
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define MAX_N 256
#define INF INT_MAX

int nlist[MAX_N];
int plist[MAX_N];
int N,M,x;
 
int sq(int n){
	return n*n;
}

int main() {
	while(cin >> N >> M, N|M){
		fill_n(nlist, MAX_N, INF);
		vi C(M);
		REP(i, M){
			cin >> C[i];
		}
		nlist[128]=0;
		int res=INF;
		REP(i, N){
			fill_n(plist, MAX_N, INF);
			cin >> x;
			REP(j, MAX_N){
				if(nlist[j]!=INF){
					REP(k, M){
						int l=max(0,min(j+C[k],MAX_N-1));
						plist[l]=min(plist[l],nlist[j]+sq(x-l));
					}
				}
			}
			memcpy(nlist, plist, sizeof(plist[0])*MAX_N);
		}
		sort(nlist, nlist+MAX_N);
		cout << nlist[0] << endl;
	}
}

Measured memory_bytes: 1212
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main() {
	string s;
	int max,ans=-1;
	cin >> max >> s;
	static int acnt[27], bcnt[27];
	rep(i, max) 
		bcnt[s[i]-'a']++;

	rep(i, max) {
		int tmp = 0;
		acnt[s[i] - 'a']++;
		bcnt[s[i] - 'a']--;
		rep(j, 27) {
			tmp += acnt[j]>0 && bcnt[j]>0;
			ans = ans > tmp ? ans : tmp;
		}
	}
	cout << ans;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin>>s;

  int w;
  cin>>w;

  int n = s.size();
  for(int i=0;i<n;i++){
    if(i % w == 0) cout<<s[i];
  }
  cout<<endl;
		     
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int n,x,t;
  cin>>n>>x>>t;
  cout<<(n+x-1)/x*t<<endl;
  return 0;
}


Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
N = int(input())

s = str(N)
sum = 0
for i in range(len(s)) :
  sum += int(s[i])

if N%sum == 0 :
  print ("Yes")
else :
  print ("No")
  


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define M 100005
vector<int>edge[M];
int Get_sg(int x,int pre){
	int res=0;
	for(int i=0;i<edge[x].size();i++)
		if(edge[x][i]!=pre)res^=(Get_sg(edge[x][i],x)+1);
	return res;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	if(Get_sg(1,-1))puts("Alice");
	else puts("Bob");  
	return 0;
}  

Measured memory_bytes: 11904
#include<stdio.h>

int main(void){
  int i,j;
  int n,h[6];
  double height;

  scanf("%d",&n);
  for(i=0;i<6;i++){
    h[i]=0;
  }
  for(i=0;i<n;i++){
    scanf("%lf",&height);
    if(height<165.0)
      h[0]++;
    else if(height<170.0)
      h[1]++;
    else if(height<175.0)
      h[2]++;
    else if(height<180.0)
      h[3]++;
    else if(height<185.0)
      h[4]++;
    else
      h[5]++;
  }
  for(i=0;i<6;i++){
    printf("%d:",i+1);
    for(j=0;j<h[i];j++){
      printf("*");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 0
X,Y=map(int,input().split())
count=0
if X==3:
  count = count+100000
elif X==2:
  count = count+200000
elif X==1:
  count = count+300000
else:
  count = count

if Y==3:
  count = count+100000
elif Y==2:
  count = count+200000
elif Y==1:
  count = count+300000
else:
  count = count
  
if X==1 and Y==1:
  count = count+400000
  
print(count)

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



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

    double r; cin >> r;
    cout << 2.0*r*M_PI << endl;
}

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

int main(){
    string S;
    cin >> S;

    int ans2 = 0,ans1 = 0;
    int N = S.size();

    char F = '0';
    for(int i = 0; i < N; i++){
        if(S.at(i) == F){
            ans1++;
        }
        if(F == '0'){
            F = '1';
        }else{
        F = '0';
        }
    }
    F = '1';
    for(int i = 0; i < N; i++){
        if(S.at(i) == F){
            ans2++;
        }
        if(F == '0'){
            F = '1';
        }else{
        F = '0';
        }
    }
    cout << min(ans1,ans2) << endl;
}

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

using namespace std;

const int N = 2e5 + 123;
int n, a[N], s[N], ans;

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i++){
		s[a[i]] = s[a[i] - 1] + 1; 
		ans = max(ans, s[a[i]]);
	}
	cout << n - ans;
}

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

using namespace std;

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

int main() {
    int w, d, h;
    map<int, int> m;
	while(cin>>w>>d, w+d) {
	    m.clear();
	    int ans = 0;
	    rep(i, w) {cin >> h; m[h]++; ans+=h;}
	    rep(j, d) {cin >> h; if(m[h]) m[h]--; else ans+=h;};
	    cout << ans << endl;
	}
}



Measured memory_bytes: 3092