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

public class Main {
    public static void main (String[] args){
        solve2149();
    }

    public static void solve2149() {
        Scanner sc = new Scanner(System.in);
        while(true) {
            // ??????????????\???
            int N = sc.nextInt();
            int A = sc.nextInt();
            int B = sc.nextInt();
            int C = sc.nextInt();
            int X = sc.nextInt();
            if(N == 0 && A == 0 && B == 0 && C == 0 && X == 0){
                break;
            }
            int nextX = X;
            int frame = 0;
            int Yi = -1;
            for(int i = 0; i < N; i++){
                int nextYi = sc.nextInt();
                if(Yi == nextYi){
                    frame++;
                    nextX = (A * nextX + B) % C;
                }
                while(frame <= 10000 && nextYi != nextX){
                    frame++;
                    nextX = (A * nextX + B) % C;
                }
                Yi = nextYi;
            }
            System.out.println(frame <= 10000 ? frame : -1);
        }
    }
}

Measured memory_bytes: 41116
n, x, y = map(int, input().split())
a = [0 for i in range(n-1)]
for ii in range(n):
	for jj in range(ii+1,n):
		i = ii+1
		j = jj+1
		if i < x and j < x:
			b = j-i
		elif i < x and j >= x and j <= y:
			b = min(j-i, y-j+1+x-i)
		elif i < x and j > y:
			b = j-i-(y-x)+1
		elif i >= x and i <= y and j >= x and j <= y:
			b = min(j-i,i-x+y-j+1)
		elif i >= x and i <= y and j > y:
			b = min(j-i,i-x+1+j-y)
		else:
			b = j-i
		#print (i,j,b)
		a[b-1] += 1
for i in a:
	print (i)


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    map<pair<int, int>, int> M;
    for (int i = 1; i <= n; ++i) {
        int tmp = i;
        vector<int> d;
        while (tmp) {
            d.push_back(tmp % 10);
            tmp /= 10;
        }
        int first = d.back(), last = d[0];
        ++M[make_pair(first, last)];
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        int tmp = i;
        vector<int> d;
        while (tmp) {
            d.push_back(tmp % 10);
            tmp /= 10;
        }
        int first = d.back(), last = d[0];
        ans = ans + M[make_pair(last, first)];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M=1e5+5;
ll a[M],m[M],val[M];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<=n;i++)
		cin>>a[i];
	m[0]=1;
	if(a[0]>1)
	{
		cout<<"-1\n";
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		m[i]=(m[i-1]-a[i-1])*2;
		if(m[i]>1e18)
			m[i]=1e18;
		if(a[i]>m[i])
		{
			cout<<"-1\n";
			return 0;
		}
	}
	ll ans=a[n];
	val[n] = a[n];
	for(int i=n;i>=1;i--)
	{
		ll req = (val[i]+1)/2;
		if(req+a[i-1]>m[i-1])
		{
			cout<<"-1\n";
			return 0;
		}
		val[i-1]=min(m[i-1],a[i-1]+val[i]);
		ans += val[i-1];
	}
	cout<<ans<<"\n";
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // start
    int n, a;
    cin >> n >> a;
    cout << n * n - a << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
import math
import numpy as np

i=list(map(int,input().split()))
a=i[0]
b=i[1]
h=i[2]
m=i[3]

m_arg=math.radians((360/60)*m)
h_arg=math.radians((360/12)*h+(360/12/60)*m)
h_v=a*np.array([math.cos(h_arg),math.sin(h_arg)])
m_v=b*np.array([math.cos(m_arg),math.sin(m_arg)])

print(np.linalg.norm(h_v-m_v))




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

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

  sort(a.begin(), a.end());
  int res = 0;
  rep(i,n) {
    if ( (x >= a[i] && i < n-1 ) || (i == n-1 && x == a[i])) x -= a[i], res++;  
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int M=sc.nextInt();
        int X=sc.nextInt();
        int Y=sc.nextInt();
        int[] x=new int[N];
        int[] y=new int[M];
        for(int i=0;i<N;i++){
            x[i]=sc.nextInt();
        }
        for(int i=0;i<M;i++){
            y[i]=sc.nextInt();
        }
        Arrays.sort(x);
        Arrays.sort(y);
        for(int i=x[N-1]+1;i<=y[0];i++){
            if(X<i&&i<=Y){
                System.out.println("No War");
                return ;
            }
        }
        System.out.println("War");
    }
}

Measured memory_bytes: 23124
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node{
    int p,l,r;
};

Node T[MAX];
int n,D[MAX];

void print(int u){
    int i,c;
    cout<<"node "<<u<<": ";
    cout<<"parent = "<<T[u].p<<", ";
    cout<<"depth = "<<D[u]<<", ";

    if(T[u].p==NIL) cout<<"root, ";
    else if(T[u].l==NIL) cout<<"leaf, ";
    else cout<<"internal node, ";

    cout<<"[";

    for(i=0, c=T[u].l; c!=NIL; i++,c=T[c].r){
        if(i) cout << ", ";
        cout<<c;
    }
    cout<<"]"<<endl;
}

//递归地求深度
int rec(int u,int p){
    D[u] = p;
    if (T[u].r!=NIL) rec(T[u].r,p);//右侧深度设置为相同深度
    if (T[u].l!=NIL) rec(T[u].l,p+1);//最左侧子节点的深度设置为自己的深度+1
}


int main(){
    int i,j,d,v,c,l,r;
    cin>>n;

    for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r =NIL;

    for(i=0; i<n; i++){
        cin>>v>>d;
        for(j=0; j<d; j++){
            cin>>c;
            if(j==0) T[v].l=c;
            else T[l].r=c;
            l=c;
            T[c].p = v;
        }
    }

    for(i=0; i<n; i++){
        if(T[i].p==NIL) r=i;
    }
    rec(r,0);

    for(i=0; i<n; i++) print(i);

    return 0;
}
















Measured memory_bytes: 7796
n,x = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
a.sort()
if sum(a) < x:
    print(n-1)
elif sum(a) == x:
    print(n)
else:
    for i in a:
        if x >= i:
            cnt += 1
            x -= i
    print(cnt)


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 1000 * 100 + 47;

int A[MAX];
int B[MAX];

int A1[MAX];
int B1[MAX];
int L[MAX * 2];
int sz;
vector<int> g[MAX];
int IN[MAX];
int OUT[MAX];
int U[MAX];

int val = 0;
void dfs(int v)
{
	if (U[v]) return;
	U[v] = 1;

	if (OUT[v] > IN[v]) val += OUT[v] - IN[v];
	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		dfs(to);
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, n) cin >> A[i];
	FOR(i, 0, n) cin >> B[i];
	

	int y = 0;
	int x = 0;
	FOR(i, 0, n)
	{
		x ^= A[i];
		y ^= B[i];
		A1[i] = A[i];
		B1[i] = B[i];
	}

	A1[n] = x;
	B1[n] = y;
	sort(A1, A1 + n + 1);
	sort(B1, B1 + n + 1);
	bool ok = true;
	FOR(i, 0, n + 1)
	{
		if (A1[i] != B1[i])
		{
			ok = false;
			break;
		}
	}

	if (!ok)
	{
		cout << -1 << endl;
		return 0;
	}

	int ans = 0;
	FOR(i, 0, n)
	{
		if (A[i] != B[i]) ans++;
		L[sz++] = A[i];
		L[sz++] = B[i];
	}

	L[sz++] = x;
	sort(L, L + sz);
	sz = unique(L, L + sz) - L;
	
	FOR(i, 0, n)
	{
		A[i] = lower_bound(L, L + sz, A[i]) - L;
		B[i] = lower_bound(L, L + sz, B[i]) - L;
	}

	x = lower_bound(L, L + sz, x) - L;
	FOR(i, 0, n)
	{
		int a = A[i];
		int b = B[i];
		if (a == b) continue;
		g[a].push_back(b);
		g[b].push_back(a);

		OUT[b]++;
		IN[a]++;
	}

	val = 0;
	dfs(x);
	if (val != 0 && OUT[x] > IN[x]) val--;
	ans += val;

	FOR(i, 0, n)
	{
		//cout << SZ(g[i]) << endl;
		if (U[i] || SZ(g[i]) == 0) continue;

		val = 0;
		dfs(i);
		if (val == 0) val++;
		//cout << i << ": " << val << endl;
		ans += val;
	}

	cout << ans << endl;
}

Measured memory_bytes: 16640
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
#include <ctype.h>
using namespace std;

#define PI acos(-1.0)
#define EPS 1e-8
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int>> vvi;

struct Matrix {
    vvi data;
    int r, c;
    Matrix(int row, int col, bool identity = false) : r(row), c(col) {
        data.assign(row, vector<int>(col, 0));
        if (identity) {
            for (int i = 0; i < r; ++i) {
                data[i][i] = 1;
            }
        }
    }
    Matrix operator * (Matrix& other) {
        int m = r, n = c, p = other.c;
        Matrix res(m, p);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < p; ++j) {
                for (int k = 0; k < n; ++k) {
                    res.data[i][j] += data[i][k] * other.data[k][j];
                }
            }
        }
        return res;
    }
};

// 扩展欧几里得算法 res[1] * a + res[2] * b = res[0] = gcd(a, b)
vector<int> extendGcd(int a, int b) {
    if (b == 0) {
        return {a, 1, 0};
    } else {
        vector<int> tmp = extendGcd(b, a % b);
        return {tmp[0], tmp[2], tmp[1] - (a / b) * tmp[2]};
    }
}

// 矩阵快速幂
Matrix matrix_power(Matrix base, ll exp) {
    int n = base.r;
    Matrix res(n, n, true);
    while (exp) {
        if (exp & 1) {
            res = res * base;
        }
        base = base * base;
        exp >>= 1;
    }
    return res;
}

// 带模快速幂
template <typename T>
T power_mod(T base, int exp, int mod = MOD) {
    T res = 1;
    while (exp) {
        if (exp & 1) res = res * base % mod;
        base = base * base % mod;
        exp >>= 1;
    }
    return res;
}

// 快速幂
template <typename T>
T power(T base, int exp) {
    T res = 1;
    while (exp) {
        if (exp & 1) res *= base;
        base *= base;
        exp >>= 1;
    }
    return res;
}

// 求逆元
ll inv(ll a) {
    return power_mod(a, MOD - 2);
}

/******************************** template ********************************/
#define MAXN 55
int n, k;

int main() {
    cin >> n >> k;
    int res = 1;
    for (int i = 0; i < n; ++i) {
        res = min(res << 1, res + k);
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    private static FastScanner sc = new FastScanner();
    private static boolean DEBUG_FLG = false;

    public static void main(String[] args) {
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int C = sc.nextInt();
    	if(A==B && B==C) {
    		System.out.println("Yes");
    	} else {
    		System.out.println("No");
    	}
    }

    static void debug(long... args) {
    	if(!DEBUG_FLG) return;
    	boolean flg = false;
    	for(long s : args) {
    		if(flg) System.out.print(" ");
    		flg = true;
    		System.out.print(s);
    	}
    	System.out.println();
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 22484
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

int N, M;
vector<int> Graph[10];
int ans;

bool visited[10];

void dfs(int cur) {
  bool finish = true;
  visited[cur] = true;
  for (auto e : Graph[cur]) {
    if (visited[e]) continue;

    dfs(e);
    finish = false;
  }

  if (finish) {
    bool allfinished = true;
    repe(i, 1, N) {
      if (!visited[i]) {
        allfinished = false;
      }
    }
    if (allfinished) ++ans;
  }

  visited[cur] = false;
}

int main() {
  cin >> N >> M;
  rep(i, 0, M) {
    int a, b;
    cin >> a >> b;
    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }

  dfs(1);

  cout << ans << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define P pair<int,int>
#define MAX_N 51
using namespace std;

bool G[MAX_N][MAX_N];
bool visited[MAX_N];
int n,m;

void dfs(int u){
    visited[u] = true;
    for(int v = 0; v < n; v++){
        if( !G[u][v] ) continue;
        if( visited[v] )continue;
        dfs(v);
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    int b1[m];
    int b2[m];
    for(int i = 0;i<m;i++){
        cin>> b1[i] >>b2[i];
        b1[i]--;b2[i]--;
        G[b1[i]][b2[i]] = G[b2[i]][b1[i]] = true;
        
    }
    ll ans = 0;
    for(int i = 0; i<m;i++){
        G[b1[i]] [b2[i]] = G[b2[i]] [b1[i]] = false;
        for(int i=0; i<n;++i) visited[i] = false;

        dfs(0);

        bool can = true;
        for(int j =0; j<n; ++j){
            if( !visited[j] ) {
                can = false;
                break;
            }
        }
        if( !can ) ans++;
        G[b1[i]] [b2[i]] = G[b2[i]] [b1[i]] =true;
    }
    cout<< ans <<endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String[] args) throws java.lang.NumberFormatException{
    Scanner scan=new Scanner(System.in);
    StringBuilder input=new StringBuilder();
    do{
      input.append(scan.nextLine());
    }while(scan.hasNext());

    for(char i='a';i<='z';i++){
      int count=0;
      for(int j=0;j<input.length();j++){
        if(input.toString().charAt(j)==i || Character.toUpperCase(input.toString().charAt(j))==Character.toUpperCase(i)){
          count++;
        }
      }
      System.out.println(i+" : "+count);
    }
  }
}


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

using namespace std;

using ll = long long;
const ll INF = 1e18 + 5;

int main(int argc, char** argv){
    ll N = 0, W = 0;

    cin >> N >> W;
    vector<ll> weights(N);
    vector<ll> values(N);


    for(int i = 0; i < N; ++i){
       cin >> weights[i] >> values[i]; 
    }
    vector<ll> dp(1000000, INF);

    dp[0] = 0;
    for(int item = 0; item < N; ++item){
        for(ll value = dp.size() - 1; value >= 0; --value){
            if(value + values[item] < dp.size()){
                dp[value+values[item]] =
                    min(dp[value] + weights[item], dp[value+values[item]]);
            }
        }
    }
    ll m = 0;
    for(ll i = 0; i  < dp.size(); ++i){
        if(dp[i] <= W && i > m){
            m = i;
        }
    }
    cout << m << "\n";
    return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>

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

  if((A % 3 == 0) || (B % 3 == 0) || ((A+B) % 3 == 0)){
    printf("Possible\n");
  }else{
    printf("Impossible\n");
  }
  return 0;
}


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

#define endl '\n'
#define rep(n)      for (int i = 0 ; i < n ; i++)
#define all(a)      a.begin(),a.end()
#define NumofDigits(n)    ((long long)log10(n)+1)
#define Unique(n)         (n).erase(unique(all(n)), (n).end())

void quick ()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}

void readFromText ()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE
}

const double Pi = acos(-1.0);

int main()
{
    quick();
//    readFromText();
    int n , m ; cin >> n >> m ; vector<pair<int,vector<int>>> v (n);
    for (int i = 0 ; i < n ; i++){
        cin >> v[i].first;
    }
    for (int i = 0 ; i < m ; i++){
        int a , b ; cin >> a >> b ; a-- , b-- ;
        v[a].second.push_back(v[b].first);
        v[b].second.push_back(v[a].first);
    }
    int counter = 0 ;
    for (int i = 0 ; i < n ; i++){
        bool add = true ;
//        if (i==2){
//            cout << v[i].first << " " ;
//            for (int j = 0 ; j < v[i].second.size() ; j++){
//                cout << v[i].second[j] << " " ;
//            }
//        }
//        cout << endl ;
        for (int j = 0 ; j < v[i].second.size() ; j++){
            if (v[i].first <= v[i].second[j]){
                add = false;
//                cout << "WHILE I = " << i << " v[i].first = " << v[i].first << endl ;
                break;
            }
        }
        if (add)counter++;
    }
    cout << counter ;
    return 0;
}

unsigned long long pow(long long base, long long power){
    if(power==0)
        return 1;
    if(power==1)
        return base;
    unsigned long long ans = pow(base, power/2);
    ans *= ans;

    if(power&1)
        return ans*base;
    return ans;
}


Measured memory_bytes: 9248
'use strict'

function main(input) {
  input = input
    .trim()
    .split(/\n|\s/)
    .map(Number)
  const n = input[0]
  let nums = input.slice(1)
  let count = 0
  while (true) {
    for (let i = 0; i < n; i++) {
      if (nums[i] % 2 > 0) {
        console.log(count)
        return
      }
    }
    nums = nums.map(v => v / 2)
    count++
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

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

    string s;
    cin >> s;
    vector<int> a;
    int n = s.size();
    if (s[n - 1] == '1' || s[0] == '0') {
        cout << -1 << endl;
        return 0;
    }
    rep(i, 0, n) {
        if (i > n - 2 - i) break;
        if (s[i] != s[n - 2 - i]) {
            cout << -1 << endl;
            return 0;
        }
        if (s[i] == '1') {
            a.emplace_back(i + 1);
        }
    }
    int cnt = 1;
    rep(i, 0, a.size() - 1) {
        cout << cnt << ' ' << cnt + 1 << endl;
        cnt++;
    }
    cout << cnt << ' ' << n << endl;
    cnt++;
    rep(i, 1, a.size()) {
        rep(j, 0, a[i] - a[i - 1] - 1) {
            cout << i + 1 << ' ' << cnt << endl;
            cnt++;
        }
    }
    rep(i, cnt, n) {
        cout << i << ' ' << n << endl;
    }

    return 0;
}

Measured memory_bytes: 1868
#include<stdio.h>
#include<string.h>
char s[10];
int main()
{
	int A,B,C,D,i;
	A=getchar()-'0';
	B=getchar()-'0';
	C=getchar()-'0';
	D=getchar()-'0';
	if(A+B+C+D==7) { s[1]=1;s[2]=1;s[3]=1; }
	if(A+B+C-D==7) { s[1]=1;s[2]=1;s[3]=0; }
	if(A+B-C+D==7) { s[1]=1;s[2]=0;s[3]=1; }
	if(A-B+C+D==7) { s[1]=0;s[2]=1;s[3]=1; }
	if(A+B-C-D==7) { s[1]=1;s[2]=0;s[3]=0; }
	if(A-B-C+D==7) { s[1]=0;s[2]=0;s[3]=1; }
	if(A-B+C-D==7) { s[1]=0;s[2]=1;s[3]=0; }
	if(A-B-C-D==7) { s[1]=0;s[2]=0;s[3]=0; }
	for(i=1;i<=3;i++)
	{
		if(s[i]==1) s[i]='+';
		else s[i]='-';
	}
	printf("%d%c%d%c%d%c%d=7",A,s[1],B,s[2],C,s[3],D);
	return 0;
}

Measured memory_bytes: 128
s = input()
cnt = 0
ans = 0
for i in range(len(s)):
    if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
        cnt += 1
        if ans < cnt:
            ans = cnt
    else:
        cnt = 0
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void)
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a <= b && b <= c)
{
printf("%d %d %d\n",a,b,c);
}else if(a <= c && c <= b){
printf("%d %d %d\n",a,c,b);
}else if(b <= a && a <= c)
{
printf("%d %d %d\n",b,a,c);
}else if(b <= c && c <= a)
{
printf("%d %d %d\n",b,c,a);
}else if(c <= a && a <= b)
{
printf("%d %d %d\n",c,a,b);
}else if(c <= b && b <= a)
{
printf("%d %d %d\n",c,b,a);
}
 return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
const int MAX_N=1e5;
int N;

string march="MARCH";

ll cnt['Z'-'A'+1];

int main(){
	cin>>N;
	REP(i,N){
		string s;
		cin>>s;
		cnt[s[0]-'A']++;
	}
	ll ans=0;
	REP(bit,1<<5){
		int c=0;
		ll a=1;
		REP(i,5){
			if (bit&(1<<i)){
				c++;
				a*=cnt[march[i]-'A'];
			}
		}
		if (c==3){
			ans+=a;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char a[10],b[10],c[10],x;
    gets(a);
    x=a[0];
    int i,j=0,k=0;
    for(i=0;a[i]!='\0';i++)
    {
        if(a[i]==x)
            b[j++]=a[i];
        else
            c[k++]=a[i];
    }
    i=0;
    if(b[i]==b[i+1] && c[i]==c[i+1])
        printf("Yes");
    else
        printf("No");
}

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

using namespace std;
using ll = long long int;
using lc = complex<double>;

#include<atcoder/all>
using namespace atcoder;

constexpr ll MOD = 998244353;

using mint = modint998244353;

vector<mint> pows;

struct S {
    mint a;
    mint size;
};

struct F {
    bool ch;
    mint a;
};

const mint inv9 = mint(1) / 9;

S op(S l, S r) { return S{pows[r.size.val()]*l.a + r.a, l.size + r.size}; }

S e() { return S{0, 0}; }

S mapping(F l, S r) { return (l.ch ? S{l.a * (pows[r.size.val()]-1)*inv9, r.size} : r); }

F composition(F l, F r) { return (l.ch ? l : r); }

F id() { return F{false, 0}; }

int main(void) {
    pows = vector<mint>(300000, 1);
    for(ll i=0; i<300000; i++)
        pows[i+1] = pows[i] * 10;

    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n, q;
    cin >> n >> q;

    vector<S> a(n, S{1,1});
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);

    while(q--) {
        ll l, r, d;
        cin >> l >> r >> d;
        l--, r--;

        seg.apply(l, r+1, F{true, d});
        cout << seg.all_prod().a.val() << endl;
    }


}

Measured memory_bytes: 12160
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll N;
vector<ll> a;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  a.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  int num = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] == num + 1) {
      num++;
    }
  }

  if (num == 0) {
    cout << -1 << endl;
  } else {
    cout << N - num << endl;
  }
  return 0;
}

Measured memory_bytes: 1792
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000;
#define mod (int)1000000007
#pragma endregion
struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

int main(void) {
	int n, m; cin >> n >> m;
	vector<pair<int, int>> d;
	lint ans = 0;
	for (int i = 0; i < m; i++) {
		int x, y; cin >> x >> y;
		d.push_back({ x,y });
	}
	for (int i = 0; i < m; i++) {
		UnionFind s(n);
		for (int j = 0; j < m; j++) {
			if (j == i) continue;
			s.unite(d[j].first - 1, d[j].second - 1);
		}

		for (int j = 1; j < n; j++) {
			if (!s.same(0, j)) break;
			if (j == n - 1) ans--;
		}
		ans++;
	}
	cout << ans << endl;

	return 0;
}

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

int read(){
	int a = 0; char c = getchar(); while(!isdigit(c)) c = getchar();
	while(isdigit(c)){a = a * 10 + c - 48; c = getchar();} return a;
}

const int _ = 2e5 + 7 , MOD = 998244353 , iv2 = (MOD + 1) / 2;
struct Edge{int end , upEd;}Ed[_ << 1];
int dp[_][3][3] , N , cntEd , head[_];
void addEd(int a , int b){Ed[++cntEd] = (Edge){b , head[a]}; head[a] = cntEd;}

int mx , id , pre[_];
void dfs1(int x , int p , int l){
	pre[x] = p; if(l > mx){mx = l; id = x;}
	for(int i = head[x] ; i ; i = Ed[i].upEd)
		if(Ed[i].end != p) dfs1(Ed[i].end , x , l + 1);
}

int mxdep[_];
void dfs2(int x , int p){
	for(int i = head[x] ; i ; i = Ed[i].upEd)
		if(Ed[i].end != p){dfs2(Ed[i].end , x); mxdep[x] = max(mxdep[x] , mxdep[Ed[i].end] + 1);}
}

void DP(int x , int p){
	dp[x][0][0] = 1; bool flg = 0;
	for(int i = head[x] ; i ; i = Ed[i].upEd)
		if(Ed[i].end != p){
			flg = 1; DP(Ed[i].end , x); static int tmp[3][3]; memset(tmp , 0 , sizeof(tmp));
			for(int j = 0 ; j < 3 ; ++j)
				for(int k = 0 ; k < 3 ; ++k)
					for(int p = 0 ; p < 3 ; ++p)
						for(int q = 0 ; q < 3 ; ++q){
							int coef = 3;
							if(mxdep[Ed[i].end] + 1 == mxdep[x]){
								tmp[min(j + p , 2)][k] = (tmp[min(j + p , 2)][k] + 1ll * dp[x][j][k] * dp[Ed[i].end][p][q]) % MOD;
								tmp[j][min(k + q , 2)] = (tmp[j][min(k + q , 2)] + 1ll * dp[x][j][k] * dp[Ed[i].end][p][q]) % MOD;
								coef -= 2;
							}
							tmp[j][k] = (tmp[j][k] + 1ll * coef * dp[x][j][k] * dp[Ed[i].end][p][q]) % MOD;
						}
			memcpy(dp[x] , tmp , sizeof(tmp));
		}
	if(!flg){dp[x][0][0] = 0; dp[x][1][1] = 1;}
}

int main(){
	N = read(); for(int i = 1 ; i < N ; ++i){int x = read() , y = read(); addEd(x , y); addEd(y , x);}
	dfs1(1 , 0 , 0); mx = 0; int t = id; dfs1(t , 0 , 0);
	for(int i = 0 ; i < mx / 2 ; ++i) id = pre[id];
	if(mx & 1){
		dfs2(id , pre[id]); DP(id , pre[id]); dfs2(pre[id] , id); DP(pre[id] , id); int sum = 0;
		for(int i = 0 ; i < 3 ; ++i)
			for(int j = 0 ; j < 3 ; ++j)
				for(int k = 0 ; k < 3 ; ++k)
					for(int l = 0 ; l < 3 ; ++l){
						if(i == 1 && l == 1) sum = (sum + 1ll * dp[id][i][j] * dp[pre[id]][k][l]) % MOD;
						if(j == 1 && k == 1) sum = (sum + 1ll * dp[id][i][j] * dp[pre[id]][k][l]) % MOD;
					}
		printf("%lld\n" , 1ll * sum * iv2 % MOD);
	}else{dfs2(id , 0); DP(id , 0); printf("%lld\n" , 1ll * iv2 * dp[id][1][1] % MOD);}
	return 0;
}


Measured memory_bytes: 21376
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] tem = sc.nextLine().split(" ");
        
        int H = Integer.parseInt(tem[0]);
        int W = Integer.parseInt(tem[1]);
        int M = Integer.parseInt(tem[2]);
        
        int[] Harray = new int[H];
        int[] Warray = new int[W];
        
        HashSet<String> Set= new HashSet<String>();
        
        String HW;
        for(int i = 0; i < M; ++i) {
            HW = sc.nextLine();
            Set.add(HW);
            tem = HW.split(" ");
            ++Harray[Integer.parseInt(tem[0]) - 1];
            ++Warray[Integer.parseInt(tem[1]) - 1];
        }
        
        int Hmax = 0;
        int HmaxCount = 1;
        for(int i = 0; i < Harray.length; ++i) {
            if(Harray[i] > Hmax) {
                Hmax = Harray[i];
                HmaxCount = 1;
            } else if(Harray[i] == Hmax) {
                ++HmaxCount;
            }
        }
        
        int Wmax = 0;
        int WmaxCount = 1;
        for(int i = 0; i < Warray.length; ++i) {
            if(Warray[i] > Wmax) {
                Wmax = Warray[i];
                WmaxCount = 1;
            } else if(Warray[i] == Wmax) {
                ++WmaxCount;
            }
        }
        
        int posicount = 0;
        int[] HmaxPosi = new int[HmaxCount];
        for(int i = 0; i < Harray.length; ++i) {
            if(Harray[i] == Hmax) {
                HmaxPosi[posicount] = i;
                ++posicount;
            }
        }
            
        posicount = 0;
        int[] WmaxPosi = new int[WmaxCount];
        for(int i = 0; i < Warray.length; ++i) {
            if(Warray[i] == Wmax) {
                WmaxPosi[posicount] = i;
                ++posicount;
            }
        }
        
        int max = Hmax + Wmax - 1;
        Check:
        for(int i = 0; i < HmaxPosi.length; ++i) {
            for(int j = 0; j < WmaxPosi.length; ++j) {
                if(!Set.contains((HmaxPosi[i] + 1) + " " + (WmaxPosi[j] + 1))) {
                    ++max;
                    break Check;
                }
            }
        }
        
        System.out.println(max);
    }
}

Measured memory_bytes: 96924
import java.util.*;
  public class Main{
	public static void main(String[] agrs) {
	    Scanner sc = new Scanner(System.in);
	        for(;;){
	            int n = sc.nextInt();
	            int r = sc.nextInt();	             
	            if( n==0 && r==0) {
	                break;
	            }	             
	            int[] input = new int[n];
	            for(int i = 0; i < n ; i++){
	                input[i] = n - i;
	            }	             
	            for(int i = 0; i < r ; i++){
	                int p = sc.nextInt()-1;
	                int c = sc.nextInt();                 
	                int[] deck = input.clone();	                 
	                for(int j = 0 ; j < c ; j++){
	                    deck[j] = input[j+p];
	                }
	                for(int j = 0; j < p ; j ++){
	                    deck[j+c] = input[j];
	                }
	                input = deck;
	            }
	            System.out.println(input[0]);
	        }
	}
    }


Measured memory_bytes: 37204
#include<iostream>
#include<map>
#include<string>
#include<cctype>
using namespace std;

#define f first
#define s second
#define mp make_pair
#define OVERFLOW mp(INF,INF)
typedef pair<int,int> P;
static const int INF = (1 << 29);

string s;
int pos;
P expression();
P term();
P factor();

bool check(P v){
   return (-10000 <= v.f && v.f <= 10000) && (-10000 <= v.s && v.s <= 10000);
}

P expression(){
   P val = term();
   if(!check(val))return OVERFLOW;
   
   while(s[pos]=='+' || s[pos]=='-'){
      if(s[pos]=='+'){
	 pos++;
	 P tmp = term();
	 if(!check(tmp))return OVERFLOW;
	 val.f += tmp.f;
	 val.s += tmp.s;
	 if(!check(val))return OVERFLOW;
      }
      else{
	 pos++;
	 P tmp = term();
	 if(!check(tmp))return OVERFLOW;
	 val.f -= tmp.f;
	 val.s -= tmp.s;
	 if(!check(val))return OVERFLOW;
      } 
   }
   //cout << "exp " << val.f << " " << val.s << endl;
   return val;
}

P term(){
   P val = factor();
   
   if(!check(val))return OVERFLOW;

   while(s[pos]=='*'){
      pos++;
      P tmp1 = val;
      val.f = val.s = 0;
      P tmp2 = factor();
      if(!check(tmp2))return OVERFLOW; 
      val.f += tmp1.f*tmp2.f - tmp1.s*tmp2.s;
      val.s += tmp1.f*tmp2.s + tmp1.s*tmp2.f;
      if(!check(val))return OVERFLOW;
   }
   //cout << "ter " << val.f << " " << val.s << endl;
   return val;
}

P factor(){
   P val = mp(0,0);
   
   if(s[pos]=='('){
      pos++;
      val = expression();
      if(!check(val))return OVERFLOW;
      pos++;
   }
   else{
      int tmp = 0;
      while(isdigit(s[pos])){
	 tmp = tmp*10 + (int)(s[pos] - '0');
	 if(tmp < -10000 || 10000 < tmp)return OVERFLOW; 
	 pos++;
      }
      
      if(pos==s.size())val.f = tmp;
      else if(s[pos]=='i'){
 	 val.s = (tmp==0) ? 1 : tmp;
	 pos++;
      }
      else val.f = tmp;
   }
   //cout << "fac " << val.f << " " << val.s << endl;
   return val;
}

int main(){
   while(cin >> s){
      pos = 0;
      P ans = expression();
      
      if(ans.f==INF && ans.s==INF){
	 cout << "overflow" << endl;
      }
      else if(ans.f==0 && ans.s==0){
	 cout << "0" << endl;
      }
      else if(ans.f==0){
	 cout << ans.s << "i" << endl;
      }
      else if(ans.s==0){
	 cout << ans.f << endl;
      }
      else{
	 cout << ans.f << (ans.s > 0 ? "+" : "") << ans.s << "i" << endl;
      } 
   }
   return 0;
}

Measured memory_bytes: 0
n, k = map(int, input().split())
a = list(map(int, input().split()))

mrk = [0] * n
plc = a[0] - 1
rp = 0 #ループに入った場所
rpc = -1#ループに入ってから
prc = 0#ループに入る前
for i in range(1, k + 1):
#    logging.debug(i)
    if rpc >= 0:
        rpc += 1
        if plc == rp:
#            logging.debug("prc{},rpc{}".format(prc,rpc))
            k = (k - prc) % rpc
#            logging.debug("k{},plc{}".format(k,plc))
            for i in range(k):
                plc = a[plc] - 1
#                logging.debug(plc)
            print(plc + 1)
            exit()
    if rpc == -1:
        prc += 1
    if mrk[plc] == 1 and rpc == -1:
        rp = plc
        rpc = 0
    mrk[plc] += 1
    if i < k:
        plc = a[plc] - 1
#    logging.debug("{},next{},{},roop{}".format(mrk,plc,prc,rpc))

print(plc + 1)

Measured memory_bytes: 32376
#include <bits/stdc++.h>
using namespace std;
//    std::sort(a.begin(), a.end(), std::greater<int>() );
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = min(b, d) - max(a, c);
    cout << (ans < 0 ? 0 : ans) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
	ptr = i
	for j in range(i + 1, N):
		if A[ptr] > A[j]:
			ptr = j
	if i != ptr:
		x = A[i]
		A[i] = A[ptr]
		A[ptr] = x
		ans += 1
s = str(A[0])
for i in range(1, N):
	s += " " + str(A[i])
print(s)
print(ans)


Measured memory_bytes: 5596
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main
{
    static long[] dp;
    static int N,M;
    static final int MOD = 1000000007;
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st = new StringTokenizer(br.readLine());
        N = Integer.parseInt(st.nextToken());
        M = Integer.parseInt(st.nextToken());
        dp = new long[N+1];
        Arrays.fill(dp,-1);
        dp[0] = 1; dp[1] = 1;
        for(int i=0;i<M;++i)
        {
            dp[Integer.parseInt(br.readLine())] = 0;
        }
        for(int i=0;i<=N;++i)
        {
            if(dp[i]!=-1) continue;
            dp[i] = (dp[i-1]+dp[i-2])%MOD;
        }
        bw.write(dp[N]+"");
        bw.close();
    }

}


Measured memory_bytes: 30312
memo = dict()


def calc(n):
    if n == 0:
        return 0
    if n == 1:
        return d
    if n in memo:
        return memo[n]

    ret = min(n * d,
              a + calc(n//2) + (n % 2) * d,
              a + calc((n+1)//2) + ((2 - (n % 2)) % 2) * d,
              b + calc(n//3) + (n % 3) * d,
              b + calc((n+2)//3) + ((3 - (n % 3)) % 3) * d,
              c + calc(n//5) + (n % 5) * d,
              c + calc((n+4)//5) + ((5 - (n % 5)) % 5) * d)

    memo[n] = ret
    return ret


t = int(input())
for i in range(t):
    n, a, b, c, d = map(int, input().split())
    print(calc(n))
    memo = dict()


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
//#define ll __int128
//#define int ll
//#define int ll
//#define char ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1>
inline istream & operator >> (istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();



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

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(4) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

int cnt(int n) {
    int ret = 0;
    while (n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

void smain() {
    int n;
    cin >> n;
    int ans = 1e9 + 10;
    for (int i = 1; i < n; ++i) {
        int j = n - i;
        inmin(ans, cnt(i) + cnt(j));

    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;

int n , a[N];
vector<int> e[N];

LL dfs(int x , int fa) {
    if (e[x].size() == 1) {
        return a[x];
    }
    LL sum = 0 , mx = 0;
    for (auto &y : e[x]) {
         if (y != fa) {
            LL w = dfs(y , x);
            sum += w;
            mx = max(mx , w);
        }
    }
    LL cnt = sum - a[x];
    if (cnt < 0) {
        puts("NO");
        exit(0);
    }
    if (mx > sum - mx && cnt > sum - mx) {
        puts("NO");
        exit(0);
    }
    if (mx <= sum - mx && cnt > sum / 2) {
        puts("NO");
        exit(0);
    }
    return sum - cnt - cnt;
}

int main() {
    scanf("%d" , &n);
    for (int i = 1 ; i <= n ; ++ i) {
        scanf("%d" , &a[i]);
    }
    for (int i = 1 ; i < n ; ++ i) {
        int x , y;
        scanf("%d%d" , &x , &y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    if (n == 2) {
        puts(a[1] == a[2] ? "YES" : "NO");
        return 0;
    }
    int root = -1;
    for (int i = 1 ; i <= n ; ++ i) {
        if (e[i].size() > 1) {
            root = i;
            break;
        }
    }
    puts(!dfs(root , 0) ? "YES" : "NO");
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,a[200010],b[200010];
int main()
{
	cin>>n;int i;for(i=1;i<=n;i++) cin>>a[i];sort(a+1,a+n+1);
	if(n&1)
	{
		ll ans=0;int mid=n/2+1,f=0,l=2,r=n;b[mid]=a[1];
		for(i=1;i<=n/2;i++)
		{
			if(f) b[mid+i]=a[l++],b[mid-i]=a[l++];
			else b[mid+i]=a[r--],b[mid-i]=a[r--];
			f^=1;
		}
		for(i=1;i<n;i++) ans+=abs(b[i+1]-b[i]);
		ll tmp=0;l=1;r=n-1;f=1;b[mid]=a[n];
		for(i=1;i<=n/2;i++)
		{
			if(f) b[mid+i]=a[l++],b[mid-i]=a[l++];
			else b[mid+i]=a[r--],b[mid-i]=a[r--];
			f^=1;
		}
		for(i=1;i<n;i++) tmp+=abs(b[i+1]-b[i]);cout<<max(ans,tmp);
	}
	else
	{
		ll ans=0;int mid,f,l,r;mid=n/2,f=1,l=2,r=n-1;b[mid]=a[1];b[mid+1]=a[n];
		for(i=1;i<n/2;i++)
		{
			if(f) b[mid+i+1]=a[l++],b[mid-i]=a[r--];
			else b[mid+i+1]=a[r--],b[mid-i]=a[l++];
			f^=1;
		}
		for(i=1;i<n;i++) ans+=abs(b[i+1]-b[i]);cout<<ans<<endl;
	}
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
    int H,W,i,j;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0){
            break;
        }
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                if((i+j)%2==0){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
            }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include<vector>
#include<map>

using namespace std;

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

	map<int, int> b;
	vector<int> a(n);
	for (int &x : a) {
		cin >> x;
		b[x] += 1;
	}

	if (n == b.size()) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 10368
use proconio::input;

fn main() {
    input! {
        x: usize,
    }
    let (mut money, mut year) = (100f64, 0);
    loop {
        if x <= money as usize {
            break;
        }
        money = (money * 1.01).floor();
        year += 1;
    }
    println!("{}", year);
}


Measured memory_bytes: 2600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> P;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<P> sushis(n);
    for (int i = 0; i < n; ++i) {
        cin >> sushis[i].second >> sushis[i].first;
    }
    sort(sushis.begin(), sushis.end(), greater<P>());
    ll ans = 0;
    set<ll> st;
    stack<P> sk;
    for (int i = 0; i < k; ++i) {
        if (st.count(sushis[i].second)) {
            sk.push(sushis[i]);
        }
        st.insert(sushis[i].second);
        ans += sushis[i].first;
    }
    ll curr = ans;
    ans += st.size() * st.size();
    for (int i = k; i < n; ++i) {
        if (sk.empty()) break;
        if (st.count(sushis[i].second)) continue;
        curr -= sk.top().first;
        sk.pop();
        curr += sushis[i].first;
        st.insert(sushis[i].second);
        ans = max(ans, (ll) (curr + st.size() * st.size()));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5248
import std.stdio;
import std.string;
import std.conv;

int main()
{
	int line = readln.chomp.to!int;
	int n = readln.chomp.to!int;

	int[31] values;
	foreach(int i;0..line)
	{
		values[i] = i+1;
	}

	foreach(int i;0..n)
	{
		auto input = readln.chomp.split(",");
		int a = to!int(input[0]);
		int b = to!int(input[1]);

		int value = values[a-1];
		values[a-1] = values[b-1];
		values[b-1] = value;
	}

	foreach(int i;0..line)
	{
		writeln(values[i]);
	}

	return 0;
}

Measured memory_bytes: 1068
#include <stdio.h>

int main(void)
{
	int i,j;
	char a[10];
	while(scanf("%s",a)!=EOF){
		if(a[0]==a[1]&&a[1]==a[2]&&(a[0]=='o'||a[0]=='x')){
			printf("%c\n",a[0]);
		}else if(a[3]==a[4]&&a[4]==a[5]&&(a[3]=='o'||a[3]=='x')){
			printf("%c\n",a[3]);
		}else if(a[6]==a[7]&&a[7]==a[8]&&(a[6]=='o'||a[6]=='x')){
			printf("%c\n",a[6]);
		}else if(a[0]==a[3]&&a[3]==a[6]&&(a[0]=='o'||a[0]=='x')){
			printf("%c\n",a[0]);
		}else if(a[1]==a[4]&&a[4]==a[7]&&(a[1]=='o'||a[1]=='x')){
			printf("%c\n",a[1]);
		}else if(a[2]==a[5]&&a[5]==a[8]&&(a[2]=='o'||a[2]=='x')){
			printf("%c\n",a[2]);
		}else if(a[0]==a[4]&&a[4]==a[8]&&(a[0]=='o'||a[0]=='x')){
			printf("%c\n",a[0]);
		}else if(a[2]==a[4]&&a[4]==a[6]&&(a[2]=='o'||a[2]=='x')){
			printf("%c\n",a[2]);
		}else {
			printf("d\n");
		}
	}
	return 0;
}

Measured memory_bytes: 552