akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep1(i,n) for(long long i=1; i<(int)n; i++)
#define repa(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}

int N, M, K, H, W, L, R, X;
//string S, T;
signed main(){
  cin >> N;
  map<int,int> mp;
  int ans = 0;
  rep(i,N){ int a; cin >> a; mp[a]++; ans += a;}
  int Q; cin >> Q;
  rep(i,Q){
    int B, C; cin >> B >> C;
    ans = ans + C*mp[B] - B*mp[B];
    mp[C] += mp[B];
    mp[B] = 0;
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 9276
#include<iostream>
#include<math.h>
#include<algorithm>
#include<unordered_map>
using namespace std;

int main()
{
    int n, MXN=1e6+5;
    cin>>n;
    int a[n], ans=n;
    bool pres[MXN]={0};
    unordered_map<int,int> cnt;
    for(int i=0;i<n;i++){
        cin>>a[i];
        cnt[a[i]]++;
    }

    if(n==1 || cnt[1]==1){
        cout << '1' << '\n';
        return 0;
    }
    if(cnt[1]>1){
        cout << '0' << '\n';
        return 0;
    }

    sort(a,a+n);
    
    for(int i=0;i<n;)
    {
        if(cnt[a[i]]>1)
            ans-=cnt[a[i]];
        else if(pres[a[i]])
        {
            ans--;
            i++;
            continue;
        }
        for(int j=a[i]; j<MXN; j+=a[i])
            pres[j]=true;
        i+=cnt[a[i]];
    }
    cout<< ans <<'\n';
}


Measured memory_bytes: 13112
use std::io;

fn read() -> Vec<i32> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let t = read();
    for i in 0..t[0] {
        let nk = read();
        let n = nk[0] as usize;
        let k = nk[1] as usize;
        let mut X = read();
        X.sort();

        let mut distance: Vec<i32> = Vec::new();
        for j in 0..n - 1 {
            distance.push(X[j + 1] - X[j]);
        }

        distance.sort();
        for j in 0..k - 1 {
            distance.pop();
        }

        if distance.len() == 0 {
            distance.push(0);
        }
        //println!("{:?}", distance);
        let sum = distance.into_iter().fold(0, |mut sum, x| {
            sum = sum + x;
            sum
        });

        println!("{}", sum);
    }
}



Measured memory_bytes: 6968
from collections import deque

def main():
    n, m = map(int, input().split())
    INF = 10**20
    mapX = {INF, -INF}
    mapY = {INF, -INF}
    dx = [-1, 0, 1, 0]
    dy = [0, -1, 0, 1]
    lh = [None]*n
    lv = [None]*m
    for i in range(n):
        a, b, c = map(int, input().split())
        mapX.add(a)
        mapX.add(b)
        mapY.add(c)
        lh[i] = [a, b, c]
    for i in range(m):
        d, e, f = map(int, input().split())
        mapX.add(d)
        mapY.add(e)
        mapY.add(f)
        lv[i] = [d, e, f]
        
    x_len = len(mapX)*2 - 1
    y_len = len(mapY)*2 - 1
    mapX, mapY = sorted(list(mapX)), sorted(list(mapY))
    mapXi, mapYi = {val:i for i, val in enumerate(mapX)}, {val:i for i, val in enumerate(mapY)}
    grid = [[0]*y_len for _ in range(x_len)]
    
    x_range = [0] * x_len
    y_range = [0] * y_len
    x_range[0] = x_range[-1] = INF
    y_range[0] = y_range[-1] = INF
    
    for i, (x1, x2) in enumerate(zip(mapX, mapX[1:])):
        x_range[i*2 + 1] = x2 - x1
        if x1 <= 0 <= x2:
            sx = i*2 + 1
    
    for i, (y1, y2) in enumerate(zip(mapY, mapY[1:])):
        y_range[i*2 + 1] = y2 - y1
        if y1 <= 0 <= y2:
            sy = i*2 + 1
    
    for a, b, c in lh:
        y = mapYi[c]*2
        for x in range(mapXi[a]*2+1, mapXi[b]*2+1, 2):
            grid[x][y] = 1
    for a, b, c in lv:
        x = mapXi[a]*2
        for y in range(mapYi[b]*2+1, mapYi[c]*2+1, 2):
            grid[x][y] = 1
    q = deque()
    grid[sx][sy] = 1
    q.appendleft([sx, sy])
    ans = x_range[sx] * y_range[sy]
    while q:
        x, y = q.pop()
        for i in range(4):
            nx, ny = x+dx[i], y+dy[i]
            if grid[nx][ny]:
                continue
            nx += dx[i]
            ny += dy[i]
            if grid[nx][ny]:
                continue
            grid[nx][ny] = 1
            q.appendleft([nx, ny])
            ans += x_range[nx]*y_range[ny]
            if ans >= INF:
                print("INF")
                return
    print(ans)
        
            
if __name__ == "__main__":
    main()

Measured memory_bytes: 427524
def main():
    N, K = map(int, input().split())
    D = list(str(x) for x in input().split())

    while True:
        strN = str(N)
        flg = 0
        for i in strN:
            if i in D:
                flg = 1
        if flg == 0:
            print(N)
            break
        else:
            N += 1
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X= sc.nextInt();
		int Y = sc.nextInt();
		if (X>=10||Y>=10) {
			System.out.println(-1);
			return ;
		}

		System.out.println(X*Y);
	}
}

Measured memory_bytes: 23636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder1
{
    class Program
    {
        static void Main(string[] args)
        {
            int  times = int.Parse(Console.ReadLine());
            string[] Gachas = new string[times];

            for(int i = 0; i < times; i++)
            {
                Gachas[i] = Console.ReadLine();
            }

            var Gachas2 = Gachas.Distinct();
            Console.WriteLine(Gachas2.Count());
        }
    }
}

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

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i,n) cin >> A[i];
    const int m = 1000000007;
    ll ans=0;
    ll x=0;
    rep(i,n){
        ans = (ans + A[i]*x)%m;
        x = (x+A[i])%m;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  long long H, W, result;
  cin >> H >> W;
  if (H == 1 || W == 1) {
    result = 1;
  } else if (H % 2 == 0) {
    result = (H / 2) * W;
  } else {
    result = ((H / 2) * W) + ((W - 1) / 2) + 1;
  }

  cout << result << endl;
}

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

int main(){
  int t;
  cin >> t;
  for(int j = 0; j < t; j++){
    int n,k;
    cin >> n >> k;
    vector<int> x(n);
    vector<int> sa(n-1);
    for(auto &p: x){
      cin >> p;
    }

    for(int i = 0; i < n-1; i++)
      sa[i] = x[i+1] - x[i];

    // ??????????????????????????§
    long long ans = x[n-1] - x[0];

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

    int cnt = min(n-1, k-1);

    for(int i = 0; i < k-1; i++){
      if(!sa.empty()){
        ans -= sa.back();
        sa.pop_back();
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3588
import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        Integer x = Integer.parseInt(scanner.next());

        Integer[] l = new Integer[n];
        Integer[] d = new Integer[n + 1];

        for(int i = 0; i < n; i++) {
            l[i] = Integer.parseInt(scanner.next());
        }

        d[0] = 0;
        for(int i = 0; i < l.length; i++) {
            d[i+1] = d[i] + l[i];
        }

        int count = 0;
        for(int i = 0; i < d.length; i++) {
            if(d[i] <= x) count++;
        }

        System.out.println(count);
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];

  int ans = 1001001001;
  for(int i=1;i<=100;i++){
    int l = 0;
    rep(j,n){
      l += (i-x[j])*(i-x[j]);
    }
    ans = min(ans,l);
  }
  cout << ans << endl;
}

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

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

template<class T>bool ch1000000(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }





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

  vector<int> A(N);
  rep(i, 0, N){
    cin >> A[i];
  }

  sort(all(A), greater<int>());

  ll score = A[0];
  int cnt = 2;
  if(N == 2){
    cout << score << endl;
    return 0;
  }
  rep(i, 1, N){
    if(cnt == N){
      break;
    }
    score += A[i];
    cnt++;
    if(cnt == N){
      break;
    }
    score += A[i];
    cnt++;
  }

  cout << score << endl;

  // cout << setprecision(8) << ans << endl;  // For double
}



Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f(ll x){if(x==0) return 0;else return x%10+f(x/10);}
int main(){
    std::ios::sync_with_stdio(false);
    int k;cin>>k;
    int num=0;ll ans=1;ll p=1;
    while(num<k){
        cout<<ans<<endl;
        ll ans1=ans+p;
        ll ans2=ans+p*10;
        if(ans1*f(ans2)<=ans2*f(ans1)){ans=ans1;}
        else{ans=ans2;p*=10;}
        num++;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

#define PI 3.14159265358979323846

using namespace std;

int main(){
	double a, b, h, m;
	scanf("%lf %lf %lf %lf", &a, &b, &h, &m);
	double theta_1 = (h + m / 60) * PI / 6;
	double theta_2 = (m * PI) / 30;
	double x1 = a * cos(theta_1), y1 = a * sin(theta_1);
	double x2 = b * cos(theta_2), y2 = b * sin(theta_2);
	double dis = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	printf("%.14lf", dis);
	return 0;
}


Measured memory_bytes: 2472
H,W = map(int,input().split())
src = [list(input().split()) for i in range(H)]

for i in range(H):
    row = src[i]
    if 'snuke' in row:
        j = row.index('snuke')
        print(chr(ord('A') + j) + str(i+1))
        exit()

Measured memory_bytes: 3060
n, a, b = map(int, input().split())
c = a + b
d = n // c
if d == 0:
    if n<a:
        print(n)
    else:
        print(a)
else:
    if n - (c*d) <= a:
        print((a*d)+(n-(c*d)))
    else:
        print((a*d)+a)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s == "a" || s == "i" || s == "u" || s == "e" || s == "o") {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
}

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


def prime_factorize(N: int) -> list:
    res = []
    pn = 2
    while N != 1:
        exp = 0
        while N % pn == 0:
            N /= pn
            exp += 1
        if exp:
            res.append([pn, exp])
        pn += 1
    return res


pn = []
for i in range(2, N+1):
    for j in prime_factorize(i):
        flg = 0
        if pn:
            idx = 0
            for k in pn:
                if k[0] == j[0]:
                    pn[idx][1] += j[1]
                    flg = 1
                    break
                idx += 1
        if not flg:
            pn.append(j)

ans = 1
for i in pn:
    tmp = (i[1] + 1) % (10**9 + 7)
    ans *= tmp
    ans %= (10**9 + 7)

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>

int main() {
    int n;
    long long T = 1, A = 1, t, a;
    
    std::cin >> n;
    
    for(int i = 0; i < n; ++i) {
        std::cin >> t >> a;
        
        if(T * a == t * A)
            continue;
        
        auto minT = T;
        if(T % t != 0) {
            minT = (T / t + 1) * t;
        }
        
        auto minA = A;
        if(A % a != 0) {
            minA = (A / a + 1) * a;
        }
        
        if(minA / a == minT / t) {
            T = minT, A = minA;
        }else if(minA / a > minT / t) {
            A = minA, T = minA / a * t;
        }else
            T = minT, A = minT / t * a;
        
    }
    
    std::cout << T + A << std::endl;
}

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

int main(void)
{
	int i;
	int a1, a2, a3, a4;
	string s;
	cin >> a1 >> a2;
	cin >> s;
	for (i = 0; i < a1 + a2 + 1; i++)
	{
		if (i == a1)
		{
			if (s[i] != '-')
			{
				cout << "No";
				return 0;
			}
		}
		else
		{
			if(s[i]-'0'>9||s[i]-'0'<0)
			{
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

vector<int> adj[MAXN];
int dp[MAXN][4];

int dfs(int s, int curr, int p){
	int ans = 1;
	int cnt = 0;
	if(dp[s][curr] != -1) return dp[s][curr];
	for(auto it: adj[s]){
		if(it == p){
			continue;
		}
		cnt++;
		if(curr == 1){
			ans *= (dfs(it, 0, s)%MOD);
			ans %= MOD;
		} else {
			ans *= ((dfs(it, 0, s)%MOD + dfs(it, 1, s)%MOD))%MOD;
			ans %= MOD;
		}
	}
	if(cnt == 0){
		return 1;
	}
  	ans %= MOD;
	return dp[s][curr] = ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n; cin>>n;
    for(int i = 0;i<n-1;i++){
    	int t1, t2;
    	cin>>t1>>t2;
    	adj[t1].pb(t2);
    	adj[t2].pb(t1);
    }
    memset(dp, -1, sizeof(dp));
    cout<<(dfs(1, 1, -1) + dfs(1, 2, -1))%MOD<<endl;
    return 0;
}





Measured memory_bytes: 20536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    map<string, int> m;
    rep(i, n)
    {
        string s;
        cin >> s;
        m[s]++;
    }
    vector<string> keys = {"AC", "WA", "TLE", "RE"};
    rep(i, 4)
    {
        printf("%s x %d\n", keys[i].c_str(), m[keys[i]]);
    }

    return 0;
}

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


#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;

vvi g;
vi ans;
vi d;
vi x;

void dfs(int s){ // sを根としてdfs
  stack<int> st;
  d[s] = 1;
  st.push(s);
  
  while(!st.empty()){
    int next = st.top();
    st.pop();
    ans[next] += x[next];
    
    rep(i, g[next].size()){
      int c = g[next][i];
      
      if(d[c] == 0){
	d[c] = 1;
	ans[c] = ans[next];
	st.push(c);
      }
    }
  }
}

signed main(){
  int n, q; cin >> n >> q;
  g.resize(n);
  rep(i,n-1){
    int a, b; cin >> a >> b; a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  x.resize(n);
  rep(i,q){
    int a, b; cin >> a >> b; a--;
    x[a] += b;
  }

  ans.resize(n);
  d.resize(n);
  dfs(0);

  cout << ans[0];
  FOR(i,1,n) cout << " " << ans[i];
  cout << endl;
}

Measured memory_bytes: 20976
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int N,M,X,A[100],count1=0,count2=0;
 cin>>N>>M>>X;
 for(int i=0;i<M;i++)
 {
 	cin>>A[i];
 }
 sort(A,A+M);
 for(int i=X+1;i<N;i++)
 {
 	for(int j=0;j<M;j++)
 	{
 		if(A[j]==i)
 		{
 			count1++;
 		}
 	}
 }
  for(int i=X-1;i>0;i--)
 {
 	for(int j=0;j<M;j++)
 	{
 		if(A[j]==i)
 		{
 			count2++;
 		}
 	}
 }
 int r = min(count1,count2);
 cout<<r<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long 
#include<vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int mod=1e9+7;
int main(){
	IOS;

	set<int> s;
	int n;
	cin>>n;
	for(int i=0,x;i<n;i++)
	{
		cin>>x;
		s.insert(x);
	}
	if(s.size()==n)
	cout<<"YES";
	else
	cout<<"NO";
	
	}

Measured memory_bytes: 12928
def ipt(N=0,switch=0):
    if N == 0:
        return list(map(int,input().split()))
    else:
        if switch==0:
            return [list(map(int,input().split())) for _ in range(N)]
        else:
            return [int(input()) for _ in range(N)]

N=int(input())
LR=ipt(N)
ans=0
for i in range(N):
    ans += LR[i][1] - LR[i][0] + 1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
const int INF=100100100100100;

const int po=1000000000;
signed main(){
  int n,k,s;cin>>n>>k>>s;
  rep(i,n){
    if(i<k)cout<<s<<" ";
    else{
      if(s<po)cout<<s+1<<" ";
      else cout<<1<<" ";
    }
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1280
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    for x in range(N, 1000):
        if len(set(str(x))) == 1:
            print(x)
            return

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9088
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	string a,b;
	cin >> n;
	while(n--) {
		cin >> a >> b;
		string ret = "";
		reverse(a.begin(),a.end()),reverse(b.begin(),b.end());
		int a_len = a.size(),b_len = b.size();
		int num = max(a_len,b_len),c = 0;
		for(int i = 0; i < num; i++) {
			if(a_len <= i || b_len <= i) c += (b_len <= i ? a[i] : b[i]) - '0';
			else c += a[i] + b[i] - '0' * 2;
			ret += c % 10 + '0';
			c /= 10;
		}
		if(c) ret += c + '0';
		reverse(ret.begin(),ret.end());
		cout << (ret.size() > 80 ? "overflow" : ret) << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;


void ABC118B()
{
	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	for (int i = 0; i < N; ++i)
	{
		int K;
		cin >> K;
		for (int i = 0; i < K; ++i)
		{
			int x;
			cin >> x;
			++A[x - 1];
		}
	}

	int ct = 0;
	for (int i = 0; i < M; ++i)
	{
		if (A[i] == N)
			++ct;
	}
	cout << ct << endl;
}
int main()
{
	ABC118B();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

int N;
int A[210];

int main(){
    std::cin>>N;
    for (int i =0; i<N; ++i){
        std::cin>>A[i];
    }
    int res = 0;
    while(true){
        bool exist_odd = false; 
        for(int i = 0; i<N;++i){
            if(A[i]%2 !=0){
                exist_odd = true;
            }else{
                A[i] /=2;
            }
        }
        if(exist_odd) break;
        ++res;
    }
    std::cout<<res<<std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

ll po[2020];


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

ll Com(ll n,ll k){
  if(n==0){
    if(k==0) return 1;
    else return 0;
  }
  if(k>n) return 0;
  ll a=po[n];
  a*=modinv(po[k]);
  a%=Mod;
  a*=modinv(po[n-k]);
  return a%Mod;
}

int main(){
  ll i,j;
  ll n,k;
  cin>>n>>k;
  if(n==k){
    for(i=1;i<=k;i++){
      if(i==1) cout<<1<<endl;
      else cout<<0<<endl;
    }
    return 0;
  }
  po[1]=1;
  po[0]=1;
  for(i=2;i<2020;i++) {
    po[i]=i*po[i-1];
    po[i]%=Mod;
  }

  for(i=1;i<=k;i++){
    ll ans=Com(n-k-1,i);
    ans+=2*Com(n-k-1,i-1);
    ans+=Com(n-k-1,i-2);
    ans%=Mod;
    ans*=Com(k-1,i-1);
    ans%=Mod;
    cout<<ans<<endl;  
  }


  
  return 0;  
}

Measured memory_bytes: 256
n = int(input())
li = []
for i in range(n):
  a = list(map(int, input().split()))
  li.append(a)
dp = []
for i in range(n):
  dp.append([0 for j in range(3)])
dp[0][0] = li[0][0]
dp[0][1] = li[0][1]
dp[0][2] = li[0][2]
for i in range(1, n):
  dp[i][0] = li[i][0] + max(dp[i-1][1], dp[i-1][2])
  dp[i][1] = li[i][1] + max(dp[i-1][0], dp[i-1][2])
  dp[i][2] = li[i][2] + max(dp[i-1][0], dp[i-1][1])
print(max(dp[n-1][0], dp[n-1][1], dp[n-1][2]))


Measured memory_bytes: 76632
///
// File:  grl_5_a.cpp
// Author: ymiyamoto
//
// Created on Fri Oct 20 01:48:10 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;
#define SIZE 100000

struct route_t {
  uint64_t to;
  uint64_t dist;
};

static vector<route_t> tree[SIZE];
static vector<uint64_t> distances(SIZE, UINT32_MAX);
static vector<bool> visited(SIZE, false);

uint64_t distant(uint64_t n)
{
  uint64_t dist = 0;
  for (uint64_t i = 0; i < n; i++) {
    if (distances[dist] < distances[i]) {
      dist = i;
    }
  }
  return dist;
}

void dfs(uint32_t from)
{
  visited[from] = true;
  for (uint32_t i = 0; i < tree[from].size(); i++) {
    route_t r = tree[from][i];
    if (!visited[r.to]) {
      distances[r.to] = min(distances[r.to], distances[from] + r.dist);
      dfs(r.to);
    }
  }
}

int32_t main()
{
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n - 1; i++) {
    uint64_t s, t, w;
    cin >> s >> t >> w;
    tree[s].push_back({t, w});
    tree[t].push_back({s, w});
  }

  distances[0] = 0;
  dfs(0);

  uint64_t dist = distant(n);

  for (uint32_t i = 0; i < n; i++) {
    distances[i] = UINT32_MAX;
    visited[i] = false;
  }

  distances[dist] = 0;
  dfs(dist);

  cout << distances[distant(n)] << endl;

  return 0;
}

Measured memory_bytes: 15240
#include <stdio.h>
int main(void){
    
    int a, b;
    char op;
    
    while(1){
        scanf("%d %c %d", &a, &op, &b);
        if(op == '?'){
          break;
         }
         
        switch(op){
            case '+':
                printf("%d\n", a + b);
                break;
            case '-':
                printf("%d\n", a - b);
                break;
            case '*':
                printf("%d\n", a * b);
                break;
            case '/':
                printf("%d\n", a / b);
                break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;
/*
ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) a=a*a%MOD;
		else res=res*a%MOD;
		b>>=1;
	}
	res=res*a%mod;
	return res;
}
*/
vector<int> v;
ll f(ll n){
	ll ret=0;
	while(n){
		ret+=n%10;
		n/=10;
	}
	return ret;
}
int main()
{
	//IOS;
	ll n;
	cin>>n;
	while(n){
		v.pb(n%10);
		n/=10;
	}
	reverse(ALL(v));

	ll ans=0;
	REP(i,SZ(v)) ans+=v[i];
	ll cur=0;
	for(int i=0;i<v.size();i++){
		ans=max(ans,cur+v[i]-1+9*(SZ(v)-i-1));
		cur+=v[i];
	}
	cout<<ans;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>


int main(){
  ll int n;
  cin>>n;
  vi a(n);
  ll int memo[3*100000]={0};
  ll int s=0;
  rep(i,n){
    int tmp;
    cin>>tmp;
    memo[tmp]++;
    a[i]=tmp;
  }
  rep(i,3*100000){
    s+=(memo[i]*(memo[i]-1))/2;
  }
  ll int ans=0;
  rep(i,n){
    ans=s-(memo[a[i]]*(memo[a[i]]-1))/2 + ((memo[a[i]]-1)*(memo[a[i]]-2))/2;
    cout<<ans<<endl;
    ans=0;
  }


}

Measured memory_bytes: 5760
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    vector<string>s(2);
    int n;
    cin >> n;
    cin >> s[0] >> s[1];
    ll answer = 1;
    string tate="tate",yoko="yoko";
    string prev;
    REP(i,n){
        if(s[0][i]==s[1][i]){
            if(prev == tate){
                answer=answer*2%MOD;
            }else if(prev == yoko){
                //answer=answer*1%MOD;
            }else{
                answer=answer*3%MOD;
            }
            prev = tate;
        }else{
            if(prev == tate){
                answer=answer*2%MOD;
            }else if(prev == yoko){
                answer=answer*3%MOD;
            }else{
                answer=answer*6%MOD;
            }
            i++;
            prev = yoko;
        }
    }
    cout<< answer << endl;
    return 0;
}

Measured memory_bytes: 3604
num = int(input())
A = list(map(int, input().split()))
F = sum(A)
H = F / 2
S = 0
for i in range(num):
  S += A[i]
  if abs(H - (S + A[i+1])) > abs(H - S):
    print(abs(2 * S - F))
    break
    


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];

int Solve(){
	int x=0, y=0;
	for (int i=1; i<=n; i++){
		if (A[i]&1) y++;
		else x++;
	}
	if (x&1) return 1;
	if (y>=2) return 2;
	int g=0;
	for (int i=1; i<=n; i++){
		if (A[i]&1){
			if (A[i]==1) return 2;
			A[i]--;
		}
		g=__gcd(g, A[i]);
	}
	for (int i=1; i<=n; i++) A[i]/=g;
	return 3-Solve();
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i];
	if (n>1 && Solve()==1) cout<<"First\n";
	else cout<<"Second\n";
	
	return 0;
}


Measured memory_bytes: 4032
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=200003;

int main(){
  ll res=LONG_MAX;
  int n;
  cin>>n;
  ll a[maxn];
  a[0]=0LL;
  for(int i=0;i<n;i++){
    ll tmp;
    cin>>a[i+1];
    a[i+1]+=a[i];

  }
  for(int i=1;i<=n-1;i++){
    res=min(abs(a[i]-(a[n]-a[i])),res);
    
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 1792
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))
def plis(a): return " ".join(list(map(str, a)))

a, b, c, d = rli()
print(max(0, b-c-max(0, a-c) - max(0, b-d)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin>>s;
  if(s[2]==s[3]&&s[4]==s[5]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#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 endl "\n"
#define pb push_back
#define mp make_pair
#define ld long double
#define ii pair<ll,ll>;
#define vi vector<int>;
#define ll long long int
#define ook order_of_key
#define fbo find_by_order
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = a; i < b; i++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int main(){
    IOS
    //io_set();
    ll n, i, ans = INT_MIN, x;
    cin >> n;
    ll a[n];
    for(i = 0; i < n; i++){
        cin >> a[i];
    }
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    sort(a,a+n);
    for(i=0;i<n;i++){
        x = (upper_bound(a,a+n,a[i]+2)-(a+i));
        ans = max(x,ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n;
char a[11];
vector <long long> w;
long long rez;
int main(){
    cin >> n;
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1; j <= 10 ; j++){
            cin >> a[j];
        }
        sort(a+1,a+11);
        long long r = 0 , t = 1;
        for(int j = 1 ; j <= 10 ; j++){
            r += (a[j]-'a')*t;
            t*= 26;
        }
        w.pb(r);
    }
    sort(w.begin(),w.end());
    int p = 0;
    while(p < n){
        long long q = w[p];
        int pos = upper_bound(w.begin(),w.end(),q) - w.begin();
        rez += ((long long)(pos - p)*(pos-p-1))/2;
        p = pos;
    }
    cout << rez;
    return 0;
}


Measured memory_bytes: 1400
// AOJ 1080: Everything Starts With Your Vote
// 2018.2.4 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define HASHSIZ		262144	// 2^18
#define HASHMOD		262143
typedef struct { char *s; int id; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;			// Hash table

void insert(char *s, int id)
{
	long long i;
	char *p;
	HASH *tp;
	int inc;

	i = 0, p = s; while (*p) i = (i << 5) + (*p++ & 0x1f); i &= HASHMOD;
	tp = hash + (int)i, inc = *s + (*(s + 1) << 1);
	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return;
		tp += inc; if (tp >= hashend) tp -= HASHSIZ;
	}
	tp->s = s, tp->id = id;
}

int lookup(char *s)
{
	long long i;
	char *p;
	HASH *tp;
	int inc;

	i = 0, p = s; while (*p) i = (i << 5) + (*p++ & 0x1f); i &= HASHMOD;
	tp = hash + (int)i, inc = *s + (*(s + 1) << 1);
	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		tp += inc; if (tp >= hashend) tp -= HASHSIZ;
	}
	return -1;
}

typedef struct { char *nm; int x; char fav; } T;
T tbl[100002], *fav;
char name[100002][22];
int N, M, K, L;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int cmp(T *a, T *b)
{
	if (a->fav - b->fav) return a->fav - b->fav;
	if (b->x - a->x) return b->x - a->x;
	return strcmp(a->nm, b->nm);
}

int check(int m)
{
	int i, f, x, base, sum;
	char *nm;

	base = K-m;
	if (base < 0) return 0;
	if (base >= N) return 1;
	sum = 0, nm = tbl[base].nm, base = tbl[base].x;
	for (i = 0; i < m; i++) {
		x = base - fav[i].x;
		if (x < 0) continue;
		f = (strcmp(fav[i].nm, nm) <= 0);
		if (!x && f) continue;
		sum += x; if (!f) sum++;
		if (sum > L) return 0;
	}
	return sum <= L;
}

int main()
{
	int i, lo, hi, mi;
	char buf[12], *p;

	while (N = in()) {
		M = in(), K = in(), L = in();
		memset(hash, 0, sizeof(hash));

		for (i = 0; i < N; i++) {
			fgets(name[i], 22, stdin);
			tbl[i].nm = p = name[i];
			while (*p > ' ') p++; *p = 0;
			insert(name[i], i);
			tbl[i].x = atoi(p+1), tbl[i].fav = 0;
		}
		for (i = 0; i < M; i++) {
			fgets(p=buf, 12, stdin);
			while (*p > ' ') p++; *p = 0;
			tbl[lookup(buf)].fav = 1;
		}
		qsort(tbl, N, sizeof(T), cmp);
		fav = tbl + N - M, N -= M;

		lo = 0;
		hi = M; if (hi > K) hi = K; hi++;
		while (hi-lo > 1) {
			mi = (lo + hi) >> 1;
			if (check(mi)) lo = mi; else hi = mi;
		}
		printf("%d\n", lo);
	}
	return 0;
}


Measured memory_bytes: 11320
#include<iostream>
using namespace std;
int main(void) {
    while(1) {
        // ???????????????
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        // ??????
        int count = 0;
        for (int i = 1; i <= n-2; i++) {
            for (int j = i+1; j <= n-1; j++) {
                for (int k = j+1; k <= n; k++) {
                    if (i + j + k == x)
                        count++;
                }
            }
        }
        // ??¢???????????????
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
<?php
  fscanf(STDIN,"%d%d",$n,$m);
if($n*2<=$m){
	$count = $n;
  	$m -= $n*2;	
}elseif($n==0 || $n==1 || $m==0){
  echo "0";
  exit;
}else{
  echo (int)($m/2);
  exit;
}

$count += (int)($m/4);
echo $count;
  

Measured memory_bytes: 4604
#include <stdio.h>

static long cnt=0;

void insertionSort(long* A, long n, long g){
  int i;
  for (i=g;i<n;i++) {
    int k=A[i];
    int j=i-g;
    while((j>=0)&&(A[j]>k)) {
      A[j+g]=A[j];
      j-=g;
      cnt++;
      A[j+g]=k;
    }
  }
}

void shellSort(long *A, long n){
  long G[100];
  long m,i;
  G[0]=1;
  for(m=1; m<100; m++){
    long g=G[m-1]*3+1;
    if(g<=n)
      G[m]=g;
    else
      break;
  }
  cnt=0;
  for(i=m-1;i>=0;i--)
    insertionSort(A,n,G[i]);
  printf("%ld\n",m);
  for(i=m-1; i>0; i--)
    printf("%ld ", G[i]);
  printf("%ld\n",G[0]);
  printf("%ld\n",cnt);
}

int main(void){
  long N,n;
  long A[1000000];
  scanf("%ld\n",&N);
  for(n=0;n<N;n++)
    scanf("%ld\n",&A[n]);
  shellSort(A,n);
  for(n=0;n<N;n++)
    printf("%ld\n",A[n]);
  return 0;
}

Measured memory_bytes: 8412
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


#define PRINT(s) cout << (s);
#define PRINTLN(s) cout << (s) << endl;

typedef long long int ll;

using namespace std;

// #define REP(i,N) for(int i = 0; i < N; i++)

int main(){
    int n;
    int a[100];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int min_num = 114514;
    int max_num = -8101919;
    for(int i = 0; i < n; i++){
        min_num = min(min_num,a[i]);
        max_num = max(max_num,a[i]);
    }
    cout << max_num - min_num << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a, b;
	while(true)
	{
		cin >> a >> b;
		if(a == 0 && b == 0)
			break;
		for(int i = 0;i < a;i++)
		{
			for(int j = 0;j < b;j++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3076
#include<algorithm>
#include<cstdio>
#include<vector>
#include<iostream>

using namespace std;

int main(){
    int len_array,num_query;
    int b,e,t;
    scanf("%d",&len_array);
    vector<int> int_array(len_array,0);
    
    for(int i = 0;i < len_array;i++){
        cin >> int_array[i];
    }
    
    scanf("%d",&num_query);
    for(int i = 0;i < num_query;i++){
        scanf("%d %d %d",&b,&e,&t);
        for(int k = 0; k < e-b;k ++ ){
            swap(int_array[b+k],int_array[t+k]);
        }
    }
    
    for(int i = 0;i < len_array;i++){
        cout << int_array[i];
        if(i!=len_array-1) cout << " ";
        else cout << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define qwq(x) cerr<<" #"<<#x<<" = "<<x<<endl;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=200005,T=30000;
int a[N],b[N],p[N],n;

int main(){
	read(n);
	rep(i,1,n){
		read(p[i]);
		a[i]=i*T;
		b[i]=(n+1-i)*T;
	}
	rep(i,1,n)a[p[i]]-=n-i;
	rep(i,1,n)printf("%d ",a[i]);puts("");
	rep(i,1,n)printf("%d ",b[i]);puts("");
	return 0;
}


Measured memory_bytes: 896
import Control.Monad
import Data.Array.Unboxed
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B

readInts :: IO [Int]
readInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

main :: IO ()
main = do
  [a, b, m] <- readInts
  as <- listArray (1, a) <$> readInts
  bs <- listArray (1, b) <$> readInts
  xycs <- replicateM m $ readInts
  print $ solve as bs xycs

solve :: UArray Int Int -> UArray Int Int -> [[Int]] -> Int
solve as bs xycs = (a0 + b0) `min` (minimum [ (as ! x) + (bs ! y) - c | [x, y, c] <- xycs ])
  where
    a0 = foldr1 min $ elems as
    b0 = foldr1 min $ elems bs

Measured memory_bytes: 39292
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n, m;
    cin >> n;
    set<int>st;
    while(n--){
        cin >> m;
        st.insert(m);
    }
    cout << st.size() << endl;
    
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod = 1e9+7;
#define MAXN 21
int n;
int a[MAXN][MAXN];
lli dp[MAXN][1<<MAXN];
lli solve(int pos, int msk){
	if(pos == n){
		if(msk == (1 << n)-1)
			return 1ll;
		return 0ll;
	}
	//mujeres eligen j
	//mascara para hombres i
	if(dp[pos][msk] != -1) return dp[pos][msk];
	lli ans = 0ll;
	for(int i=0; i < n; i++){
		if(a[i][pos] == 1 && (msk & (1<<i)) == 0){
			ans = (ans + solve(pos+1, (msk | (1<<i))) % mod )%mod;
		}
	}
	return dp[pos][msk] = ans % mod;
}

int main(){__
	cin >> n;
	for(int i=0; i < n; i++){
		for(int j=0; j <n; j++){
			cin >> a[i][j];
		}
	}
	memset(dp,-1,sizeof(dp));
	cout << solve(0,0)% mod << endl;
	return 0;
}


Measured memory_bytes: 344320
#include<bits/stdc++.h>
#define N 1000010
#define hd q[h]
#define tl q[t]
using namespace std;
char s1[N],s2[N];
int n,i,tot,ans,len,h,t,lx,ly,x,y;
struct data{int x,y;}a[N],q[N<<1];
int main(){
	cin>>n;
	scanf("%s%s",s1+1,s2+1);
	for (i=1;i<=n;i++) if (s1[i]!=s2[i]) break;
	if (i>n) return puts("0"),0;
	for (x=y=n;y;--x,--y){
		while (s2[y]==s2[y-1]) --y;
		for (x=min(x,y);s1[x]!=s2[y]&&x;) --x;
		if (!x) return puts("-1"),0;
		a[++tot]=(data){x,y};
	}
	for (i=1;i+i<=tot;i++) swap(a[i],a[tot-i+1]);
	while (a[tot].x==a[tot].y&&tot) --tot;
	if (!tot) return puts("1"),0;
	len=1,lx=a[tot].x,ly=a[tot].y,--tot;
	q[h=t=N]=(data){1,ly-lx};
	while (ans=max(ans,len),tot){
		x=a[tot].x,y=a[tot].y,--tot;
		while (t>=h&&ly-tl.y>y) len-=tl.x,ly-=tl.y,--t;
		if (t>=h) tl.y-=ly-y-1;
		if (t<h) x==y?0:(hd=(data){len=1,y-x},++t); else
		++len,x<lx-1?(q[--h]=(data){1,lx-1-x},0):++hd.x;
		lx=x,ly=y;
	}
	cout<<ans+1<<"\n";
	return 0;
}

Measured memory_bytes: 15360
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;


int main() {
	ll L, N; cin >> L >> N;
	vector<ll> x(N + 2), acl(N + 2), acr(N + 2);
	for (int i = 1; i <= N; i++) cin >> x[i];
	for (int i = 1; i <= N; i++) acr[i] = acr[i - 1] + 2*x[i];
	for (int i = 1; i <= N; i++) acl[i] = acl[i - 1] + 2 * (L - x[N - i + 1]);
	ll ans = max(x[N], L - x[1]);
	for (int i = 0; i < N; i++) {
		int piv = (N + i) / 2;
		ll w = 2 * x[i];
		w += acr[piv] - acr[i];
		w += acl[N - piv];
		w -= (N - i) & 1 ? L - x[piv + 1] : x[piv];
		ans = max(ans, w);
	}
	x[N + 1] = L;
	for (int i = 0; i < N; i++) {
		int piv = (N + 1- i) / 2;
		ll w = 2 * (L - x[N + 1 - i]);
		w += acr[piv];
		w += acl[N - piv] - acl[i];
		w -= (N - i) & 1 ? x[piv] : L - x[piv + 1];
		ans = max(ans, w);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	
	public static final int MAX = 30000;
	public static final int SQRT = (int)(Math.ceil(Math.sqrt(MAX)));
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		boolean[] is_prime = new boolean[MAX + 1];
		Arrays.fill(is_prime, 2, MAX + 1, true);
		for(int i = 2; i <= SQRT; i++){
			if(is_prime[i]){
				for(int j = i * 2; j <= MAX; j += i){
					is_prime[j] = false;
				}			
			}
		}
		
		long[] count = new long[MAX + 1];
		for(int fst = MAX; fst >= 2; fst--){
			if(!is_prime[fst]){ continue; }
			
			for(int snd = fst; snd >= 2; snd--){
				if(!is_prime[snd]){ continue; }
				else if(fst + snd > MAX){ continue; }
				
				for(int thd = snd; thd >= 2; thd--){
					if(!is_prime[thd]){ continue; }
					else if(fst + snd + thd > MAX){ continue; }
					else if(fst >= snd + thd) { break; }
					
					count[fst + snd + thd]++;
				}
			}
		}
		
		while (true) {

			final int T = sc.nextInt();
			
			if(T == 0){ break; }
			
			System.out.println(count[T]);
			
		}

	}
}

Measured memory_bytes: 21432
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		
		int p = sc.nextInt();
		int q = sc.nextInt();
		int r = sc.nextInt();
		
		if (q <= p && r <= p )
			System.out.println(q + r);
		else if (p < q && r <= q)
			System.out.println(p +r);
		else if(p <= r && q < r)
			System.out.println(p + q);

		
		}
	
	}


Measured memory_bytes: 21844
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  ll start = 100;
  int n;
  cin >> n;
  rep(i, n){
    start = start * 105;
    start = (start + 99) / 100;
  }
  cout << start << "000" << endl;
	return 0;
}



Measured memory_bytes: 3060