akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>

using namespace std;
#define INF 2e9 + 9
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;

struct node {
    Int to;
    Int length;
};


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


vector<vector<int>> to;
vector<int> flag;
vector<int> c;

Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

vector<vector<Int>> a;
vector<vector<Int>> d;
Int w, h;

void dfs(int x, int y, int id) {
    if (d[y][x] != 0) return;
    d[y][x] = id;
    REP(8, i) {
        Int tox = x + dx8[i];
        Int toy = y + dy8[i];
        if (tox >= 0 && toy >= 0 && tox < w && toy < h && a[toy][tox] == 1) {
            a[toy][tox] = 0;
            dfs(tox, toy, id);
        }
    }
}


int main(void) {
    while (true) {
        cin >> w >> h;
        if (w == 0) break;
        d.assign(h, vector<Int>(w, 0));
        a.clear();
        REP(h, i) {
            vector<Int> z;
            REP(w, k) {
                Int tmp;
                cin >> tmp;
                z.push_back(tmp);
            }
            a.push_back(z);
        }
        Int cnt = 1;
        // a[y][x]

        REP(h, k) {
            REP(w, i) {
                if (a[k][i] == 1) dfs(i, k, cnt);
                /*for (auto z : a){
                cout << "Cnt : " << cnt << endl;
                    for (auto zz : z){
                        cout << zz << " ";
                    }
                    cout << endl;
                }*/
                cnt++;
            }
        }
        map<int, int> mp;
        REP(h, k) {
            REP(w, i) {
                if (d[k][i] != 0) mp[d[k][i]]++;
            }
        }
        cout << mp.size() << endl;
    }
}


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

using namespace std;

typedef long long ll;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n;

    cin >> n;

    vector<ll> a(n * 3);
    ll ans = 0;

    ll i, len = n * 3;

    for (i = 0; i < len; i++) cin >> a[i];

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

    len = n * 2;
    for (i = 1; i <= len; i += 2) ans += a[i];

    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int mod = 1e9 + 7;
const int N = 2e5;
int n, m;
ll ans = 1;
ll fac[N], inv[N];

ll power(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i < N; ++i) {
        fac[i] = fac[i - 1] * i % mod;
    }
    inv[N - 1] = power(fac[N - 1], mod - 2);
    for (int i = N - 2; i >= 0; --i) {
        inv[i] = inv[i + 1] * (i + 1) % mod;
    }
}

ll C(ll a, ll b) {
    return fac[a] * inv[b] % mod * inv[a - b] % mod;
}

int main() {
    init();
    cin >> n >> m;

    for (int i = 2; i * i <= m; ++i) {
        int cnt = 0;
        while (m % i == 0) {
            m /= i;
            ++cnt;
        }
        if (cnt) {
            ans = ans * C(cnt + n - 1, n - 1) % mod;
        }
    }
    if (m != 1)
        ans = ans * n % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6776
#include <bits/stdc++.h>
#define int long long

#define TASKNAME ""

using namespace std;
const int K = 300;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<bitset<K> > v;
    for (int i=0; i < n; i ++){
        string s;
        cin >> s;
        bitset<K> b;
        for (int j=0; j < m; j++){
            if (s[j] == '#') b[j] = 1;
        }
        v.push_back(b);
    }
    int ans = 0;
    bitset<K> a, b, c;
    for (int i=0; i < n; i++){
        for (int j=i; j < n; j++){
            for (int k=j; k < n; k++){
                if (i==k) continue;
                a = v[i], b = v[j], c = v[k];
                int d1 = j-i, d2 = k-j, s1, s2;
                if (d1 >= d2) s1 = d1, s2=2*d1-d2;
                else s1 = d1 + 2*(d2-d1), s2 = d2;
                //cout << i << " " << j << " " << k << " " << s1 << " " << s2 << endl;
                a <<= s1, c <<= s2;
                b &= a;
                b &= c;
                ans += b.count();
                if (d1==0 || d2==0) continue;
                a = v[i], b = v[j], c = v[k];
               // cout << a[1] << " " << s1 << endl;
                a >>= s1, c >>= s2;
                b &= a;
                b &= c;
                ans += b.count();
            }
        }
    }
    cout << ans;

}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (A, B, C, K) = readLine()!!.split(" ").map { it.toLong() }

//    fun calcElems(elemNums: List<Long>, amount: Long, calcResult: List<Long> = listOf(), index: Int = 1): List<Long> {
//        val targetNum = elemNums.first()
//        val (newAmount, newElemNum) = if (amount > targetNum) {
//            Pair(amount - targetNum, targetNum)
//        } else {
//            Pair(0L, amount)
//        }
//        val newResult = calcResult.plusElement(newElemNum)
//
//        return if (elemNums.size == index) newResult else calcElems(elemNums, newAmount, newResult, index + 1)
//    }
//    val (a, _, c) = calcElems(listOf(A, B, C), K)
    var amount = K
    val a = if (amount > A) {
        amount -= A
        A
    } else {
        val tmp = amount
        amount = 0
        tmp
    }
    
    val b = if (amount > B) {
        amount -= B
        B
    } else {
        val tmp = amount
        amount = 0
        tmp
    }
    
    val c = if (amount > C) {
        amount -= C
        C
    } else {
        amount
    }
    
    println(a - c)
}



Measured memory_bytes: 36436
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
bool h_[200], w_[200];
signed main() {
	int h, w; cin >> h >> w;
	char map[200][200];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> map[i][j];
			if (map[i][j] == '#') {
				h_[i] = 1;
				w_[j] = 1;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		bool p=0;
		for (int j = 0; j < w; j++) {
			if (h_[i] && w_[j]) {
				cout << map[i][j];
				p = 1;
			}
		}
		if (p)cout << endl;
	}
}

Measured memory_bytes: 384
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    FastScanner in;
    PrintWriter out;

    void solve() {
        int n = in.nextInt();
        long[] a = new long[n];
        long sumA = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
            sumA += a[i];
        }
        long sumB = 0;
        long diff = 0;
        long[] b = new long[n];
        for (int i = 0; i < n; i++) {
            b[i] = in.nextLong();
            sumB += b[i];
            if (b[i] < a[i]) {
                diff += a[i] - b[i];
            } else {
                if ((b[i] - a[i]) % 2 == 1) {
                    diff++;
                }
            }
        }
        long ops = sumB - sumA;
        if (ops < diff) {
            out.println("No");
        } else {
            out.println("Yes");
        }
    }

    void run() {
        try {
            in = new FastScanner(new File("MainT.in"));
            out = new PrintWriter(new File("MainT.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

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

Measured memory_bytes: 25684
#include <stdio.h>
#include <stack>
#include <utility>
using namespace std;
typedef pair<int,int> pi;
#define F first
#define S second
#define MP make_pair
const int N=15e2+10;
int main(){
    int n,m,a[N][N],now,ans,nx;
    pi temp;
    stack<pi> s;
    scanf("%d%d",&n,&m);
    ans=0;
    for(int i=0;i<n;i++){
        now=0;
        for(int j=0;j<m;j++){
            scanf("%d",&nx);
            if(nx==0)now++;
            else now=0;
            a[i][j]=now;
        }
    }
    for(int j=0;j<m;j++){
        while(!s.empty())s.pop();
        for(int i=0;i<n;i++){
            while(!s.empty()){
                if(s.top().F>a[i][j]){
                    temp=s.top();
                    s.pop();
                    if(s.empty())ans=max(ans,temp.F*i);
                    else ans=max(ans,temp.F*(i-1-s.top().S));
                }
                else break;
            }
            s.push(MP(a[i][j],i));
        }
        while(!s.empty()){
            temp=s.top();
            s.pop();
            if(s.empty())ans=max(ans,temp.F*n);
            else ans=max(ans,temp.F*(n-s.top().S-1));
            
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 11052
//Inbornhandsome
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define endl '\n'
#define int long long

const int N = 1e5 + 7;

int arr[N][3], ans[N][3], n;

int dp(int a, int b)
{

    if(a == n) return arr[n][b];

    if(ans[a][b] != 0) return ans[a][b];

    ans[a][b] = max(arr[a][b] + dp(a+1, (b+1) % 3), arr[a][b] + dp(a+1, (b+2) % 3));

    return ans[a][b];
    
}

int32_t main()
{
    IOS; //FIO;

    cin >> n;

    for(int i = 1; i <= n; i ++)
    cin >> arr[i][0] >> arr[i][1] >> arr[i][2];

    ans[0][0] = max(dp(1,0), max(dp(1,1), dp(1,2)));

    cout << ans[0][0];

    return 0;
}

Measured memory_bytes: 11136
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String blank = " ";
        String data[] = br.readLine().split(blank);
        int a = Integer.parseInt(data[0]);
        int b = Integer.parseInt(data[1]);
        int c = Integer.parseInt(data[2]);
        
        int i = 0;
        for (int l = 0; a + l <= b; l++){
            if(c % (a + l) == 0){
                i++;
            }
        }
        System.out.println(i);
    }
}

Measured memory_bytes: 24416
import java.util.*;

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

        int N = sc.nextInt();
        long ans = 1;

        for(int i=1; i<=N; i++){
            ans *= i;
            ans = (long)(ans%(Math.pow(10, 9) + 7));
        }
        System.out.println(ans);
    }
}

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int L; cin >> L;
	vector<LL> A(L);
	repp(i,0,L) cin >> A[i];
	vector<LL> dp(5,0);
	repp(i,0,L){
		vector<LL> nx(5,1e9+7);
		LL z = dp[0];
		nx[0] = z+A[i];
		z = min(z,dp[1]);
		nx[1] = z+(A[i]==0?2:(A[i]%2==0?0:1));
		z = min(z,dp[2]);
		nx[2] = z+(A[i]%2==1?0:1);
		z = min(z,dp[3]);
		nx[3] = z+(A[i]==0?2:(A[i]%2==0?0:1));
		z = min(z,dp[4]);
		nx[4] = z+A[i];
		swap(nx,dp);
	}
	repp(i,1,5) dp[0] = min(dp[0],dp[i]);
	cout << dp[0] << endl;
	return 0;
}


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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string a,b;
    int i,c=0;
    cin >> a >> b;
    for (i=0;i<a.length();i++)
    {
        if (a[i] != b[i]) c++;
    }
    cout << c;
    return 0;
}


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

//INSERT ABOVE HERE
const Int MAX = 510;
const Int MAX_A = 1e15;
Int A[MAX][MAX];
void check(Int n){
  set<Int> ss;
  for(Int i=1;i<=n;i++){
    for(Int j=1;j<=n;j++){
      ss.emplace(A[i][j]);
      assert(1<=A[i][j]);
      
      //if(!(A[i][j]<=MAX_A)) cout<<A[i][j]<<endl;
      assert(A[i][j]<=MAX_A);
      if(i>1) assert(max(A[i][j],A[i-1][j])%min(A[i][j],A[i-1][j])==1);
      if(j>1) assert(max(A[i][j],A[i][j-1])%min(A[i][j],A[i][j-1])==1);
    }
  }
  assert((Int)ss.size()==n*n);
}

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

const Int MAX_N=1e5;
Int th[MAX_N];

signed main(){
  Int n;
  cin>>n;

  if(n==2){
    cout<<"4 7"<<endl;
    cout<<"23 10"<<endl;
    return 0;
  }

  for(Int i=0;i<MAX;i++)
    for(Int j=0;j<MAX;j++)
      A[i][j]=1;

  memset(th,0,sizeof(th));
  for(Int i=2;i<MAX_N;i++)
    if(!th[i]) for(Int j=i+i;j<MAX_N;j+=i) th[j]=1;
  
  vector<Int> vs;
  for(Int i=3;i<MAX_N;i++)
    if(!th[i]) vs.emplace_back(i);
  
  Int cnt=0;
  auto nxt=[&](){return vs[cnt++];};
  
  for(Int i=2;i<=n;i+=2){
    Int k=nxt();
    for(Int j=0;i+j<=n;j++) A[i+j][j+1]*=k;
    k=nxt();
    for(Int j=0;i+j<=n;j++) A[j+1][i+j]*=k;
  }
  
  for(Int i=2;i<=n;i+=2){
    Int k=nxt();
    for(Int j=0;(~n&1)+i+j<=n;j++) A[(~n&1)+i+j][n-j]*=k;
    k=nxt();
    for(Int j=0;i-j>=1;j++) A[j+1][i-j]*=k;
  }
  
  Int di[]={0,0,1,-1};
  Int dj[]={1,-1,0,0};
  
  for(Int i=1;i<=n;i++){
    for(Int j=1;j<=n;j++){
      if((i+j)&1) continue;
      for(Int k=0;k<4;k++)
	A[i][j]=lcm(A[i][j],A[i+di[k]][j+dj[k]]);
      A[i][j]++;
    }
  }
  
  for(Int i=1;i<=n;i++){
    for(Int j=1;j<=n;j++){
      if(j>1) cout<<" ";
      cout<<A[i][j];
    }
    cout<<endl;
  }
  
  //check(n);
  return 0;
}


Measured memory_bytes: 6016
n = gets.to_i

ans = []
until n == 0 do
  n % 2 == 0 ? ans.unshift(0) : ans.unshift(1)
  ans.size.even? ? n += 1 : n -= 1 if ans[0] == 1
  n /= 2
end

puts ans.empty? ? 0 : ans.join


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

#define N 100010
#define MP make_pair
typedef long long LL;

int n, a[N];


int main()
{
	//freopen("in.txt", "r", stdin);
	
	LL ans = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		int x, y;
		cin >> x >> y;
		a[i] = -y - x;
		ans += x;
	}
	sort(a + 1, a + n + 1);
	int o = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (o) ans += a[i];
		o ^= 1;
	}
	cout << ans << endl;
	return 0;	
}

Measured memory_bytes: 640
a=int(input())
b=str(input())
sum=0

riron_sum=b.count('R')*b.count('G')*b.count('B')

for i in range(0,a):
    for n in range(1,a):
        j = i+n
        k = j+n
        #print(j)
        #print(k)
        if k>=a:
        	break

        if b[i]!=b[j] and b[j]!=b[k] and b[k]!=b[i]:
                riron_sum-=1

print(riron_sum)

Measured memory_bytes: 9200
N = int(input())
A=list(map(int, input().split()))
ans=1
if 0 in A:
    ans=0
    print(ans)
else:
    for i in range(N):
        if ans>10**18:
            break
        ans=ans*A[i]
    if ans>10**18:
        print(-1)
    else:
        print(ans)

Measured memory_bytes: 21788
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n;
int x[MAXN],y[MAXN];

pair<int,int> ox[MAXN];
pair<int,int> oy[MAXN];
int xind[MAXN],yind[MAXN];

bool done[MAXN];
ll d[MAXN];
priority_queue<pair<ll,int> > q;

ll solve() {
	REP(i,n) ox[i]=MP(x[i],i); sort(ox,ox+n); REP(i,n) xind[ox[i].second]=i;
	REP(i,n) oy[i]=MP(y[i],i); sort(oy,oy+n); REP(i,n) yind[oy[i].second]=i;
	REP(i,n) d[i]=LLONG_MAX,done[i]=false; q=priority_queue<pair<ll,int> >();
	d[0]=0,q.push(MP(-d[0],0));
	while(!q.empty()) {
		ll dat=-q.top().first; int at=q.top().second; q.pop();
		if(dat>d[at]) continue; else done[at]=true;
		for(int dx=-1;dx<=+1;dx+=2) {
			int idx=xind[at]+dx; if(idx<0||idx>=n) continue;
			int to=ox[idx].second;
			ll dto=min(abs(x[at]-x[to]),abs(y[at]-y[to]));
			if(!done[to]&&dto<d[to]) {
				//printf("%d->%d = %lld (x)\n",at,to,dto);
				d[to]=dto,q.push(MP(-d[to],to));
			}
		}
		for(int dy=-1;dy<=+1;dy+=2) {
			int idx=yind[at]+dy; if(idx<0||idx>=n) continue;
			int to=oy[idx].second;
			ll dto=min(abs(x[at]-x[to]),abs(y[at]-y[to]));
			if(!done[to]&&dto<d[to]) {
				//printf("%d->%d = %lld (y)\n",at,to,dto);
				d[to]=dto,q.push(MP(-d[to],to));
			}
		}
	}
	ll ret=0; REP(i,n) ret+=d[i]; return ret;
}

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d%d",&x[i],&y[i]);
	printf("%lld\n",solve());
}

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


Measured memory_bytes: 7412
def main():
    N=int(input())
    dic={"AC":0,"WA":0,"TLE":0,"RE":0}
    for _ in range(N):
        s=input()
        dic[s]+=1
        
    for i in dic:
        print("{0} x {1}".format(i,str(dic[i])))
        
    
    
main()

Measured memory_bytes: 9184
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define INF 1e9

static const int seed=702;
static const int D=365;
static const int ntype=26;
static int ans[D+1];
static int max_score=-INF;
static int t=120000;
class Contest{
public:
    Contest(){
        last=0;
    }
    int s[D+1];
    int c;
    int last;
};

static Contest contest[ntype+1];

void Input(){
    int d;
    cin>>d;
    for(int i=1;i<=ntype;++i){
        int t;
        cin>>t;
        contest[i].c=t;
    }
    for(int day=1;day<=D;++day){
        for(int type=1;type<=ntype;++type){
            int t;
            cin>>t;
            contest[type].s[day]=t;
        }
    }
}

int evaluate(){
    int sum=0;
    vector<int> l(ntype+1,0);
    for(int day=1;day<=D;++day){
        int type=ans[day];
        sum+=contest[type].s[day];
        l[type]=day;
        for(int t=1;t<=ntype;++t){
            sum-=contest[t].c*(day-l[t]);
        }
    }
    return sum;   
}

void Output(){
    for(int d=1;d<=D;++d) cout<<ans[d]<<endl;
}

void Init(){
    for(int d=1;d<=D;++d) ans[d]=rand()%ntype+1;
}

void Greedy(){
    vector<int> l(ntype+1,0);
    int score=0;
    for(int d=1;d<=D;++d){
        for(int i=1;i<=ntype;++i) score-=contest[i].c*(d-l[i]);
        int temp=score;
        int t=-1;
        for(int i=1;i<=ntype;++i){
            int k=contest[i].s[d]+contest[i].c*(d-l[i])+score;
            if(k>temp){
                temp=k;
                t=i;
            }
        }
        ans[d]=t;
        l[t]=d;
    }
}

void change(){
    int p=rand()%D+1;
    int temp=ans[p];
    ans[p]=rand()%ntype+1;
    int temp_score=evaluate();
    if(max_score<temp_score) max_score=temp_score;
    else ans[p]=temp;
}

void swap(){
    int p1=rand()%D+1;
    int p2=rand()%D+1;
    while(p1==p2) p2=rand()%D+1;
    int temp=ans[p1];
    ans[p1]=ans[p2];
    ans[p2]=temp;
    int temp_score=evaluate();
    if(max_score<temp_score) max_score=temp_score;
    else{
        ans[p2]=ans[p1];
        ans[p1]=temp;
    }
}

void solve(int times){
    max_score=evaluate();
    for(int i=0;i<times;++i){
        swap();
        change();
    }
}

int main(){
    srand(seed);
    Input();
    Greedy();
    solve(t);
    for(int i=0;i<2000;++i) change();
    Output();
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const int INF = 1001001001;

int main(){
    ll n;
    cin >> n;
    ll ans = n*2;
    for(ll i=1; i*i<=n; i++) {
        if (n%i == 0) if (ans*i > i*i+n) ans = i-2+n/i;
    }
    cout << ans << endl;
}

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

using ll = long long;
const int mod = 1e9 + 7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, A;
    cin >> H >> A;
    cout << (H + A - 1) / A << endl;
}

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

int main() {

  int N, l, r, sum;
  cin >> N;
  sum = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    sum += r - l + 1;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

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

    int time=0,xn=0,yn=0;
    int n;
    cin >> n;
    rep(i,n){
        int t,x,y;
        cin >> t >> x >> y;
        if(abs(x-xn)+abs(y-yn)>t-time){
            cout << "No" << endl;
            return 0;
        }
        else{
            if((t-time-abs(x-xn)-abs(y-yn))%2!=0){
                cout << "No";
                return 0;
            }
            else{
                time = t;
                xn = x;
                yn = y;
            }
        }
    }

    cout << "Yes";

    return 0;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    # 入力がスペース区切りかどうか
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    # 余白の有無
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

H, W = MAP()
grid = build_grid(H, W, '*', str, space=0, padding=1)

dp = list2d(H+2, W+2, INF)
if grid[1][1] == '.':
    dp[1][1] = 0
else:
    dp[1][1] = 1
for i in range(H+1):
    for j in range(W+1):
        if grid[i][j] == '.' and grid[i][j+1] == '#':
            dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1)
        else:
            dp[i][j+1] = min(dp[i][j+1], dp[i][j])  
        if grid[i][j] == '.' and grid[i+1][j] == '#':  
            dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1)
        else:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
ans = dp[H][W]
print(ans)


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

int main() {
	int r, c;
	cin >> r >> c;
	vector<vector<int>> table(r, vector<int>(c));
	vector<int> ctotal(c, 0);
	vector<int> rtotal(r, 0);
	int total = 0;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> table.at(i).at(j);
			ctotal.at(j) += table.at(i).at(j);
			rtotal.at(i) += table.at(i).at(j);
			total += table.at(i).at(j);
		}
	}
	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			if (j == c) {
				if (i == r) cout << total;
				else cout << rtotal.at(i);
			}
			else if (i == r) cout << ctotal.at(j) << " ";
			else cout << table.at(i).at(j) << " ";
		}
		cout << endl;
	}
}


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

int main(){
	string s; cin >> s;
	int x = s.length();
	int cnt = 0;
	for(int i = 0; i < x/2; i++){
		if(s[i] != s[x - i - 1])cnt++;
	}
	cout << cnt << endl;
}


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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
    puts("YES");
  } else {
    puts("NO");
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int min;
        int d;
        min = scan.nextInt();
    	int tmp = scan.nextInt();
    	d = tmp - min;
    	if(tmp < min){
    		min = tmp;
    	}
        //max = min;
        for(int i = 1; i < n-1; i++){
            int x = scan.nextInt();
            if(x < min){
                min = x;
            }else{
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            }
        }
        System.out.println(d);
    }
}


Measured memory_bytes: 98584
#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define vlint vector<lint>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
#define GEts(s) getline(cin,s);
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())

using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}
template<typename T>T lcm(T a, T b){return a * b / gcd(a, b);}
static const double pi = 3.141592653589793;
int modpow(int a,int n,int p){if (n==0)return 1%p; if(n==1)return a%p;if(n%2==1)return (a*modpow(a,n-1,p))%p;lint t=modpow(a,n/2,p);return (t*t)%p;}//a^n%p
lint MOD=pow(10,9)+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位


class unionfind{
public:
	vector<int> table;
	void init(int size){
		table.resize(size);
		rep(i,size)table[i]=i;
	};
	int root(int index){
		if(table[index]==index)return index;
		else{
			int hoge=root(table[index]);
			table[index]=hoge;
			return hoge;
		}
	};
	bool same(int x,int y){
		return(root(x)==root(y));
	};
	int marge(int x,int y){
		int yroot=root(y);
		int xroot=root(x);
		if(xroot==yroot)return 0;
		table[yroot]=xroot;
		return 0;
	}
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(19);
	string s="";
	int k;
	in(k);
	rep(i,k)s+="ACL";
	out(s);
	return 0;
}


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

int main() {
	int a, b;
	int num = 1;
	int c = 0;

	cin >> a >> b;
	while (num < b) {
		num += a - 1;
		c++;
	}
	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  string s;
  std::cin >> s;
  if((s[0]==s[1] && s[1]==s[2]) || (s[1]==s[2] && s[2]==s[3]))printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 256
/*
    BY - Darkworld1 ( Tanu kumar )
    college - AIT
    Problem - contest ( div 3 )
*/
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define rep(i,a,n) for( int i = a ; i < n ; i++ )
#define prep( i, a , n ) for ( int i = a ; i>= n ; i--)
#define   pr pair<int,int>
const int N = 13 , M=N,inf=(int)1e9;
const int mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
ll ans ;
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
void solve(){

       int t ;
       cin >> t ;
       if(t==1) cout << "Hello World";
       else {
        int a , b ;
        cin >> a >> b ;
        cout << a+b ;
       }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}
/*
    ---------------- lemmas-----------------------------------
   1)
   2)
   3)

*/


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

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

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

Node treeSearch(Node u, int k){

  while(u!=NIL && k != u->key){
    if(k < u->key)u = u->left;
    else u = u->right;
  }
  return u;
}

void inorder(Node u){
if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
 if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
      
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);

    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



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

int main(){
  int n,k;
  int sum =0;
  cin>> n >> k;
  for (int i = 0; i < n;i++){
    int x;
    cin>>x;
    if(x<=k-x){
      sum += 2*x;
    } else {
      sum += 2*(k-x);
    }
  }
  cout <<sum << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  for (int i=0; i<N; i++){
    cin >> P.at(i);
  }
  sort(P.begin(), P.end());
  int sum=0;
  for (int i=0; i<K; i++){
    sum+=P.at(i);
  }
  cout << sum << endl;
  return 0;
}

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

using namespace std;

#define li long long int
#define pb push_back

int main()
{
    li N,K;
    cin>>N>>K;
    vector<li> A(N);
    li i,j,k;
    for(i=0;i<N;i++)
    {
        cin>>A[i];
    }
    for(i=K;i<N;i++)
    {
        if(A[i] > A[i-K])
        cout<<"Yes\n";
        else
        cout<<"No\n";
    }
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

class DSU{
   public:
   vector <int> id , sz;
   DSU(int n){
      id.resize(n+1);
      sz.resize(n+1);
      for(int i=0 ; i<=n ; i++){
         id[i] = i;
         sz[i] = 1;
      }
   }

   int root(int i){
      while(i != id[i])   id[i] = id[id[i]] , i = id[i];
      return i;
   }

   void uni(int a, int b){
      int ra = root(a);
      int rb = root(b);
      if(ra == rb)   return;
      if(sz[ra] < sz[rb]) swap(ra,rb);
      id[rb] = ra , sz[ra] += sz[rb];
   }
};

int32_t main() {
    fast;
    int n,m;
    cin >> n >> m;

    DSU O(n);
    f(i,0,m){
        int u,v;
        cin >> u >> v;
        O.uni(u,v);
    }

    int ans = 0;
    f(i,1,n+1) ans = max(ans, O.sz[O.root(i)]);

    cout << ans << "\n";
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    int n;
    cin >> n;
    cout << n / 2 + (n % 2 == 0 ? 0 : 1);
    return 0;
}


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


int main(){

    int x,y,z;
    cin>>x>>y>>z;
    int res=0;
    int start=z;
    while ((x-start)>=(z+y)){
        ++res;
        start+=(z+y);
    }


    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
N, M = map(int,input().split())
A = list(map(int,input().split()))
L = [0]*(N+1)
for i in range(1,N+1):
    L[i] = (L[i-1] + A[i-1]) % M
L = Counter(L).values()
ans = 0
for i in L:
    ans += i * (i-1) // 2
print(ans)


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> vec(H);
  int i = 0;
  while(i < H) {
    cin >> vec.at(i);
    i++;
  }
  
  string a = "";
  int j = 0, x = W + 2;
  while(j < x) {
    a += "#";
    j++;
  }
  
  cout << a << endl;
  for(int k = 0; k < H; k++) {
    cout << "#" << vec.at(k) <<"#" << endl;
  }
  
  cout << a << endl;
}

Measured memory_bytes: 256
INF = 1 << 30

def min(a,b)
  a < b ? a : b
end

def dist(a,b)
  if a >= 0
    b
  elsif b <= 0
    -a
  else
    min(b - 2 * a, b * 2 - a)
  end
end

N,K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

puts (0 .. N - K).inject(INF){|s, i| min(s, dist(A[i], A[i + K- 1])) }



Measured memory_bytes: 8452
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let s: String = read!();
    let n = s.len();
    let mut a = Vec::with_capacity(n);
    let mut b = Vec::with_capacity(n);

    for i in 0..n {
        if i%2==0 {
            a.push('1');
            b.push('0');
        }else{
            a.push('0');
            b.push('1');
        }
    }

    let s = s.chars().collect_vec();

    let mut ans_a = 0;
    let mut ans_b = 0;

    for i in 0..n {
        if a[i] != s[i] {
            ans_a += 1;
        }
        if b[i] != s[i] {
            ans_b += 1;
        }
    }
    
    println!("{}", ans_a.min(ans_b));
}


Measured memory_bytes: 3568
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	ll a,b;
	cin >>a>>b;

	cout<<a*b/__gcd(a,b)<<endl;
	return 0;
}



Measured memory_bytes: 256
from bisect import *
import itertools
n = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for a,b in itertools.combinations(L,2):
    ans += max(0,bisect_left(L,a+b) - bisect_right(L,abs(a-b)))
    ans -= (2*a > b) + (2*b > a)
print(ans//3)


Measured memory_bytes: 48348
def main():
    s = input()
    q = int(input())
    bottom = ''
    top = ''
    swapped = 0
    for _ in range(q):
        query = input()
        if len(query) == 1:
            swapped = 1 - swapped
            continue
        _, f, c = query.split()
        if swapped:
            if f == '1':
                bottom += c
            else:
                top += c
        else:
            if f == '1':
                top += c
            else:
                bottom += c

    if swapped:
        print(bottom[::-1] + s[::-1] + top)
    else:
        print(top[::-1]+s+bottom)


if __name__ == '__main__':
    main()



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

int main(){
  string S; cin >> S;
  int k=S.size();
  for(int i=0;i<k;i++){
    if(i%2==0 && S[i]=='L'){
      cout << "No" << endl;
      return 0;
    }
    if(i%2==1 && S[i]=='R'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
    

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque, Counter

N = int(input())
X = [[] for i in range(N)]
L = [0]*N
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)
    L[x-1] += 1
    L[y-1] += 1

P = [-1] * N
Q = deque([0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

C = Counter(P)
##### Settings
unit = 0
merge = lambda a, b: a + b
adj_bu = lambda a, i: (a+1)/C[P[i]]
adj_td = lambda a, i, p: ((XX[p]*L[p]-XX[i]*C[p])/max(1,L[p]-1)+1)/max(1,C[i])
adj_fin = lambda a, i: a*max(1,C[i])/L[i]
#####

ME = [unit] * N
XX = [0] * N
TD = [unit] * N
for i in R[1:][::-1]:
    XX[i] = adj_bu(ME[i], i)
    p = P[i]
    ME[p] = merge(ME[p], XX[i])
XX[R[0]] = adj_fin(ME[R[0]], R[0])

for i in R:
    ac = unit
    for j in reversed(X[i]):
        TD[j] = adj_td(merge(TD[j], ac), j, i)
        ac = merge(ac, XX[j])
        XX[j] = adj_fin(merge(ME[j], TD[j]), j)

print(*XX, sep = "\n")

Measured memory_bytes: 122308
import math

n,d=map(int, input().split())
x=[list(map(int,list(input().split()))) for i in range(n)]
pot = 0
count = 0

for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            pot = pot + (x[i][k] - x[j][k])**2
        if ((math.sqrt(pot)).is_integer()):
            count = count + 1
        pot = 0
    

print(count)

Measured memory_bytes: 3064
using System;
using System.Linq;

namespace Aizu {
    public class OnlineJudge {
        static void Main() {
            Console.WriteLine(Console.ReadLine().Aggregate(0, (p, c) => (p + 1) | (char.IsDigit(c) ? 0x20 : 0) | (char.IsUpper(c) ? 0x40 : 0) | (char.IsLower(c) ? 0x80 : 0)) >= 0xe6 ? "VALID" : "INVALID");
        }
    }
}



Measured memory_bytes: 9392
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(q);
    for(;q--;){
      int3(c, a, n);
      int res = min(c, min(a, n));
      c -= res; a -= res; n -= res;
      if(c >= a * 2){
        res += a;
        c -= a * 2;
        pri(res + c / 3);
      }else{
        pri(res + c / 2);
      }
    }


/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3120
/*
    Created by Ezio112
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<ll> vll;
ll inf(1e18);
#define mod ll(1e9+7)
//#define mod ll(998244353)
#define ff first
#define ss second
ll power(ll a,ll b)
{
	if(!b)
		return 1;
	ll dp=power(a,b/2)%mod;
	
	if(b&1) return (((dp*dp)%mod)*a)%mod;
	
	return (dp*dp)%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll test=1;
    //cin>>test;

    while(test--)
    {
		ll x,y;
		cin>>x>>y;
		bool flag=false;
		
		for(ll i=0;i<=x;++i)
		if(2*x+2*i==y)
			flag=true;
		if(flag)
			cout<<"Yes";
		else cout<<"No";
	}
	return 0;
}


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

int main()
{
    char s[20];

    while(cin>>s)
    {
        for(int i=0; i<strlen(s); i++)
        {
            if(s[i] == ',') s[i] = ' ';
        }
        printf("%s\n", s);
    }

    return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc171/tasks/abc171_b
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	ll k;
	cin>>k;
	ll min=0;
	vector<ll> p;
	p.resize(n);
	ll i;
	for(i=0;i<n;i++)
	{
		cin>>p[i];
	}
	sort(p.begin(),p.end());
	for(i=0;i<k;i++)
	{
		min=min+p[i];
	}
	cout<<min<<"\n";
	return 0;
}

Measured memory_bytes: 3600
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn print_vec(v: &[usize]) {
    for (i, n) in v.iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", n);
    }
    println!();
}

fn main() {
    let (h, w) = scan!(usize, usize);
    let _ = scan!(i64);
    let vs = scan!(i64;;);

    let mut mass: Vec<Vec<_>> = (0..h).map(|_| vec![0; w]).collect();
    let (mut x, mut y) = (0usize, 0usize);
    for (i, &v) in vs.iter().enumerate() {
        for _ in 0..v {
            mass[x][y] = i + 1;
            y += 1;
            if y == w {
                x += 1;
                y = 0;
            }
        }
    }
    for (i, m) in mass.iter_mut().enumerate() {
        if i % 2 == 0 {
            print_vec(m)
        } else {
            m.reverse();
            print_vec(m)
        }
    }
}


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

using namespace std;

int main(){

    int a, b, c;
    cin >> a >> b >> c;

    if (a + b + c >= 22){
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    } 

    return 0;
}

Measured memory_bytes: 256