akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
multiset<ll> s;
multiset<ll>::iterator it;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;ll a;
    cin>>n;
    deque<ll> dq;
    for (int i=0;i<n;i++) {
        cin>>a;
        s.insert(a);
    }
    it = s.end(); it--;
    dq.push_front(*it);
    s.erase(it);
    for (int i=0;s.size()>1;i=1-i) {
        if (i==1) {
            it = s.end(); it--;
            dq.push_front(*it);
            s.erase(it);
            if (s.size()>1) {
                it = s.end(); it--;
                dq.push_back(*it);
                s.erase(it);
            }
        }
        else {
            it = s.begin();
            dq.push_front(*it);
            s.erase(it);
            if (s.size()>1) {
                it = s.begin();
                dq.push_back(*it);
                s.erase(it);
            }
        }
    }
    it = s.begin();
    if (abs(dq.back()-(*it))>(abs(dq.front()-(*it)))) dq.push_back(*it);
    else dq.push_front(*it);
    ll sum=0,p=dq.front();
    dq.pop_front();
    while (!dq.empty()) {
        ll q = dq.front();
        dq.pop_front();
        sum += (ll)abs(p-q);
        p = q;
    }
    cout<<sum;
}


Measured memory_bytes: 5504
def main(A, B, C, D):
    start = min(A, C)
    end = max(B, D)
    alice_list = [1 if A <= i < B else 0 for i in range(start, end)]
    bob_list = [1 if C <= i < D else 0 for i in range(start, end)]

    print(sum([all(t) for t in zip(alice_list, bob_list)]))
    

if __name__ == "__main__":
    A, B, C, D = [int(x) for x in input().split()]

    main(A, B, C, D)

def test1(capsys):
    inputs = [0, 75, 25, 100]
    out = 50
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

def test3(capsys):
    inputs = [0, 33, 66, 99]
    out = 0
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

def test4(capsys):
    inputs = [10, 90, 20, 80]
    out = 60
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

def test5(capsys):
    inputs = [10, 50, 50, 90]
    out = 0
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define M 998244353
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define Zero(dp) memset(dp,0,sizeof(dp))
#define pb emplace_back
using namespace std;
int32_t main(){
ios
int t=1;
//cin>>t;
while(t--)
{
	int n;cin>>n;
	cout<<n/2+n%2;
}
}


Measured memory_bytes: 256
def knapsack(N,W,weight,value):
    inf=float("inf")
    V=sum(value)
    dp=[[inf for i in range(V+1)] for j in range(N+1)]
    dp[0][0]=0
    # dp[i][j]:i番目までの品物から価値がj以上になるよう選んだときの重さの総和の最小値
    for i in range(N):
        for j in range(V+1):
            if j-value[i]>=0: # i+1番目を選ぶ場合
                dp[i+1][j]=min(dp[i][j-value[i]]+weight[i], dp[i+1][j])
            # i+1番目を選ばない場合
            dp[i+1][j]=min(dp[i][j],dp[i+1][j])

    # dp[N][j]がW以下であるようなjの最大値が答えになる
    ans=0
    for i in range(V+1):
        if dp[N][i]<=W:
            ans=i
    return ans

n,w=map(int,input().split())
weight=[0]*n
value=[0]*n
for i in range(n):
    weight[i],value[i]=map(int,input().split())
print(knapsack(n,w,weight,value))

Measured memory_bytes: 315828
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	string S1;
	cin >> S1;

	string S2 = S1;
	reverse(S2.begin(), S2.end());

	if (S1 == S2)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

	return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

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

int card[2][5000];
int a, b;

int main() {
	cin >> a >> b;
	
	REP(i, a) scanf("%d", &card[0][i]);
	REP(i, b) scanf("%d", &card[1][i]);
	
	int ans = 0;
	REP(i, b) {
		int pos = i, cnt = 0;
		REP(j, a) {
			if (pos >= b) break;
			if (card[0][j] != card[1][pos]) continue;
			pos++;
		}
		ans = max(ans, pos - i);
	}

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

Measured memory_bytes: 1288
#include<iostream>
#include<vector>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    int city[n + 1];
    for (int i = 1; i <= n; ++i) {
        city[i] = 0;
    }
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        city[a]++; city[b]++;
    }
    for (int i = 1; i <= n; ++i) {
        cout << city[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int N, M, C, cnt = 0;
    cin >> N >> M >> C;

    int B[M];

    REP(i, M)
    cin >> B[i];

    REP(i, N)
    {
        int A[M], s = 0;
        REP(j, M)
        {
            cin >> A[j];
            s += A[j] * B[j];
        }
        s += C;
        if (s > 0)
            cnt += 1;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
// include
// ----------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>

// repetition
// ----------------------------------------------------------------------------
#define FOR(i, a, b) for (i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// memory clear
// ----------------------------------------------------------------------------
#define CLRNUM(a) memset((a), 0, sizeof(a))
#define CLRBOOL(a, flag) memset((a), flag, sizeof(a))
#define CLRCHAR(a) memset((a), '\0', sizeof(a))

// debug
// ----------------------------------------------------------------------------
#define DEBUGINT(x) printf("%d\n", x);
#define DEBUGFLOAT(x) printf("%f\n", x);
#define DEBUGCHAR(x) printf("%c\n", x);
#define DEBUGSTR(x) printf("%s\n", x);
#define DEBUGFORINT(i, a, b, x) FOR(i, a, b){ printf("%d ", x[i]); }
#define DEBUGFORFLOAT(i, a, b,x ) FOR(i, a, b){ printf("%f ", x[i]); }
#define DEBUGFORCHAR(i, a, b, x) FOR(i, a, b){ printf("%c ", x[i]); }
#define DEBUGREPINT(i, n, x) REP(i, n){ printf("%d ", x[i]); }
#define DEBUGREPFLOAT(i, n, x) REP(i, n){ printf("%f ", x[i]); }
#define DEBUGREPCHAR(i, n, x) REP(i, n){ printf("%c ", x[i]); }

// other
// ----------------------------------------------------------------------------
#define PUTNL printf("\n")

// constant
// ----------------------------------------------------------------------------
#define INF 1000000000

int main(void)
{
    long long int input;
    int num[10];
    int i, j;

    while (scanf("%lld", &input) != EOF){
        for (i = 9; i >= 0; --i){
            num[i] = (input % 10);
            input /= 10;
        }

        for (i = 8; i >= 0; --i){
            for (j = 0; j <= i; j++){
                num[j] = (num[j] + num[j + 1]) % 10;
            }
        }

        printf("%d\n", num[0]);
            
   
    }

    return 0;        
}

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

int main() {
  int K,N,ask=0;
  cin>>K>>N;
  vector<int>umi(N);
  rep(i,N) cin>>umi[i];
  for(int i=0;i<N;i++){
    if(i==N-1){
      ask=max(ask,umi[0]+(K-umi[N-1]));
    }
    else{
      ask=max(ask,umi[i+1]-umi[i]);
    }
  }
  cout<<K-ask;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i=0; i<N; i++) {
    cin >> p.at(i);
  }
  vector<int> q(N);
  for (int j=0; j<N; j++) {
    q.at(j)=j+1;
  }
  int S=0;
  for (int k=0; k<N; k++) {
    if (p.at(k)!=q.at(k)) {
      S=S+1;
    }
  }
  if (S<=2) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3580
#include<stdio.h>
#define N 200000
int main(){
    int i;
    int n,maxv=-2000000000,minv;
    int R[N];
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&R[i]);
    
    minv = R[0];
    
    for(i=1;i<n;i++){
        maxv = maxv > R[i] - minv ? maxv : R[i] - minv;
        minv = minv < R[i] ? minv : R[i]; 
    }
    printf("%d\n",maxv);
    return 0;
}


Measured memory_bytes: 2636
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
#define ull unsigned long long
#define IO(x,y) freopen(x,"r",stdin);freopen(y,"w",stdout)
#define fo(x) while(x-->0)
#define nl '\n'
#define pb push_back

vector<vector<int> > v;
vector<int> dp(1, -1);

int f(int cur){
	if(dp[cur]!=-1)
		return dp[cur];
	if(v[cur].size()){
		int max=0;
		for(int i=0; i<v[cur].size(); i++){
			int temp=f(v[cur][i]);
			if(temp>max)
				max=temp;
		}
		dp[cur]=1+max;
		return 1+max;
	}
	return 0;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	// IO("in.txt", "out.txt");
	int n, m;
	cin >> n >> m;
	v.resize(n);
	dp.resize(n, -1);
	int i, in1, in2;
	for(i=0; i<m; i++){
		cin >> in1 >> in2;
		in1--; in2--;
		v[in1].pb(in2);
	}
	int max=0;
	for(i=0; i<n; i++){
		int temp=f(i);
		if(temp>max)
			max=temp;
	}
	cout << max;
}


Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n, k;
		cin >> n >> k;
		vector<int> x(n);
		vector<int> a;
		for (int j = 0; j < n; j++) {
			cin >> x[j];
		}
		for (int j = 1; j < n; j++) {
			a.push_back(x[j]-x[j-1]);
		}
		sort(a.begin(), a.end(), greater<int>());
		int sum = 0;
		for (int i = k-1; i < a.size(); i++) {
			sum += a[i];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 2392
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		assert solve(4, 6, new int[][] { { 2, 1 }, { 3, 4 }, { 4, 10 }, { 3, 4 } }) == 11;
		assert solve(4, 10, new int[][] { { 1, 100 }, { 1, 100 }, { 1, 100 }, { 1, 100 } }) == 400;
		assert solve(4, 1, new int[][] { { 10, 100 }, { 10, 100 }, { 10, 100 }, { 10, 100 } }) == 0;
		int N = cin.nextInt();
		int W = cin.nextInt();
		int[][] wv = new int[N][];
		for (int i = 0; i < N; i++)
			wv[i] = new int[] { cin.nextInt(), cin.nextInt() };
		long ans = solve(N, W, wv);
		cout.println(ans);
	}

	private static long solve(long N, long W, int[][] wv) {
		// Q.メモリ使用量／計算量が爆発しないか？
		// A. w[1]<=w[i]<=w[1]+3, for i=2..N
		HashMap<Integer, Long> valueByWeight = new HashMap<>();
		valueByWeight.put(0, 0L);
		HashMap<Integer, Long> temp = new HashMap<>();
		for (int[] z : wv) {
			int w = z[0];
			int v = z[1];
			temp.clear();
			temp.putAll(valueByWeight);
			for (Map.Entry<Integer, Long> entry : valueByWeight.entrySet()) {
				int nw = entry.getKey() + w;
				long nv = entry.getValue() + v;
				if (nw > W)
					continue;
				if (temp.containsKey(nw) && temp.get(nw) > nv)
					continue;
				temp.put(nw, nv);
			}
			HashMap<Integer, Long> sw = temp;
			temp = valueByWeight;
			valueByWeight = sw;
			// System.out.println(sw);
		}
		long ans = valueByWeight.values().stream().mapToLong(x -> x).max().getAsLong();
		return ans;
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

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

}


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

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

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

string K;
int D;

vector<vector<vector<ll>>> dp(10100, vector<vector<ll>>(110, vector<ll>(2, 0)));

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

    cin >> K;
    cin >> D;

    int N = K.length();

    dp.at(0).at(0).at(0) = 1;

    REP(digit, N) REP(d, D) REP(isless, 2) {
        int c = K.at(digit) - '0';
        REP(next, 10) {
            if (next < c) {
                dp.at(digit + 1).at((d + next) % D).at(1) += dp.at(digit).at(d).at(isless);
                dp.at(digit + 1).at((d + next) % D).at(1) %= mod; 
            } else if (next == c) {
                dp.at(digit + 1).at((d + next) % D).at(isless) += dp.at(digit).at(d).at(isless);
                dp.at(digit + 1).at((d + next) % D).at(isless) %= mod;
            } else {
                if (isless) {
                    dp.at(digit + 1).at((d + next) % D).at(isless) += dp.at(digit).at(d).at(isless);
                    dp.at(digit + 1).at((d + next) % D).at(isless) %= mod;
                }
            }

        }

    }

    cout << (dp.at(N).at(0).at(0) + dp.at(N).at(0).at(1) - 1 + mod) % mod << endl;
    
    return 0;
}

Measured memory_bytes: 61568
#include <bits/stdc++.h>	
#define pb push_back
#define N 100005
typedef long long ll;
using namespace std;

int A[1001];

int main(){
	int n,d,x,ans=0,aux;
	scanf("%d%d%d",&n,&d,&x);

	for (int i = 0; i < n; ++i){
		scanf("%d",&aux);
		ans+=(d-1)/aux;
	}


	return !printf("%d",ans+x+n);
}



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

int main(){
	int n, x, i, j, k, cnt;
	cin>>n>>x;
	while(n!=0 || x!=0){
		cnt=0;
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				for(k=1;k<=n;k++){
					if(i!=j && j!=k && i!=k){
						if(i+j+k==x){
							cnt++;
						}
					}
				}
			}
		}
		cnt /= 6;
		cout << cnt << endl;
		cin>>n>>x;
	}
	return 0;
}

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

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

    for (int j = n - 1; j >= 0; j--) {
        cout << a[j];
        if (j != 0) {
            cout << " ";
        } 
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3076
import java.io.*
import java.util.*

fun solve(n: String){
    println(n.map{ if(it=='9') '1' else '9'}.joinToString(separator="").toInt())
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val n = sc.next()
    solve(n)
}



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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairInt;
typedef tuple<int, int, int> tuple3Int;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[])
{
  int N, Q;
  vector<ll> a;

  scanf("%d%d", &N, &Q);
  a.resize(N);

  FOR(i, N) scanf("%lld", &a[i]);

  FOR(i, Q) {
    ll x;
    scanf("%lld", &x);

    int l(0), r(0);
    ll ans(0), sum(0);
    while(r < N) {
      while(r < N && sum <= x) sum += a[r++];
      while(sum > x) {
        ans += r - l - 1;
        sum -= a[l++];
      }
    }
    ans += (ll)(N - l) * (N - l + 1) / 2;

    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e18+7
#define lim (lld)1e9+7
#define MAX2 (lld)2e5+9
#define ff first
#define ss second
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

const lld mod=lim;

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


lld extend_gcd(lld a, lld b, lld& x, lld& y) {
    if (b == 0) { x = 1;y = 0;return a;}
    lld x1, y1;
    lld d = extend_gcd(b, a % b, x1, y1);
    x = y1; y = x1 - y1 * (a / b);return d;	}

lld rowNum[]={-1,0,0,1};
lld colNum[]={0,-1,1,0};

int main()
{
	fastio
	lld m,n,k,ans=0;
	cin>>m>>n>>k;

	std::vector<lld> first(m+1);
	std::vector<lld> second(n+1);

	for(lld i=1;i<=m;i++)
		cin>>first[i];

	for(lld j=1;j<=n;j++)
		cin>>second[j];

	for(lld i=2;i<=m;i++)
		first[i]+=first[i-1];

	for(lld i=2;i<=n;i++)
		second[i]+=second[i-1];

	lld j=n;
	for(lld i=0;i<=m;i++)
	{
		if(first[i]>k)
			break;

		while(first[i]+second[j]>k)
			j--;

		ans=max(ans,i+j);
	}
	

	cout<<ans<<endl;
}

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

int main(){
    string s;
    cin >> s;
    int debag = 0;

    bool flag = true;

    if(s[0] != 'A'){
        flag = false;
        if(debag) cout << "first" << endl;
    } 


    int count_C = 0;
    for(int i = 2; i <= s.length()-2; i++){
        if(s[i] == 'C') count_C ++;
    }
    if(count_C != 1 ){
        flag = false;
        if(debag) cout << "second" << endl;
    } 

    for(int i = 0; i < s.length(); i++){
        if(s[i] != 'A' && s[i] != 'C'){
            if(s[i] < 'a' || s[i] > 'z'){
                flag = false;
                if(debag) cout << "third" << endl;
            }
        }
    }
 
    if(flag) cout << "AC" << endl;
    else cout << "WA" << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    ld A,B;
    cin >> A >> B;

    // ready
    bool ok = false;
    int ans = -1;
    for (int i=0; i<=2000; i++) {
        if ((int)(i*0.08) == A && (int)(i*0.1) == B) {
            ans = i;
            break;
        }
    }

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S;
  cin >> S;

  for (uint i = 0; i < S.size(); i++) {
    S[i] += N;
    if ('Z' < S[i]) S[i] -= ('Z' - 'A' + 1);
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,l,t; cin>>n>>l>>t;
    vector<ll> loc(n);
    ll counter=0;
    rep(i,n){
        ll x,w; cin>>x>>w;
        if(w==1)loc[i]=(x+t)%l;
        else loc[i]=((x-t)%l+l)%l;
        if(w==1){
            counter-=(t+x)/l;
        }else{
            counter+=(t+l-x-1)/l;
        }
    }
  	counter=(counter%n+n)%n;
    sort(loc.begin(),loc.end());
    vector<ll> ans(n);
    rep(i,n) ans[(i+counter)%n]=loc[i];
    rep(i,n) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 2816
k=int(input())
ans=[1,2,3,4,5,6,7,8,9]
p=[1,2,3,4,5,6,7,8,9]
c=9
while c<k:
    t=[]
    for i in p:
        j=i%10
        if j==0:
            t.append(i*10)
            t.append(i*10+1)
            c+=2
        elif j==9:
            t.append(i*10+8)
            t.append(i*10+9)
            c+=2
        else:
            t.append(i*10+j-1)
            t.append(i*10+j)
            t.append(i*10+j+1)
            c+=3
    ans.extend(t)
    p=t[::]
print(ans[k-1])

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

struct BIT {
  vector<ll> bit;
  int n;
  BIT(int n_) : n(n_ + 1), bit(n_ + 1) {}
  void add(int a, ll w) {
    for(int x = a; x <= n; x += x & -x) bit[x] += w;
  }
  ll sum(int a) {
    ll ret = 0;
    for(int x = a; x > 0; x -= x & -x) ret += bit[x];
    return ret;
  }
};

ll f(vector<ll> &A, ll c) {
  int N = A.size();
  vector<ll> acc(N + 1);
  for(int i = 0; i < N; i++) { 
    acc[i + 1] = acc[i] + (A[i] >= c ? 1 : -1);
  }
  vector<ll> acc_s = acc;
  sort(all(acc_s));
  ll ret = 0;
  BIT bit(N + 2);
  for(int i = 0; i < N + 1; i++) {
    int k = lower_bound(all(acc_s), acc[i]) - acc_s.begin();
    
    ret += i - bit.sum(k + 1);
    bit.add(k + 1, 1);
  }
  return ret;
}

void solve() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  ll M = (N + 1) * N / 2;
  ll ok = 1e9 + 10, ng = 0;
  while(ok - ng > 1) {
    ll c = (ok + ng) / 2;
    if (f(A, c) >= M / 2 + 1) {
      ok = c;
    } else {
      ng = c;
    }
  }
  cout << ng << endl;
  
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;
import java.util.Stack;

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        for (int i = 0; i < N; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        long min = Long.MAX_VALUE;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int k = 0; k < N; k++) {
                    for (int l = 0; l < N; l++) {
                        int contain = 0;
                        for (int m = 0; m < N; m++) {
                            if (x[i] <= x[m] && x[j] >= x[m] && y[k] <= y[m] && y[l] >= y[m]) {
                                contain++;
                            }
                            if (contain >= K) {
                                min = Math.min(min, (long)(x[j] - x[i]) * (y[l] - y[k]));
                            }
                        }
                    }
                }
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 22612
from collections import Counter

def replace(a, bc):
    hist = Counter(a)
    tot = sum(v * c for v, c in hist.items())

    for b, c in bc:
        if b not in hist or b == c:
            delta = 0
        else:
            bct = hist[b]
            delta = (c - b) * bct 
            del hist[b]
            if c not in hist:
                hist[c] = bct 
            else:
                hist[c] += bct
        tot += delta
        print(tot)

def main():
    N = int(input())
    a = [int(i) for i in input().split()]
    Q = int(input())

    bc = []
    for i in range(Q):
        bc.append((int(i) for i in input().split()))

    replace(a, bc)


main()


Measured memory_bytes: 108784
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        //aとbの値を代入する
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        //aとbの値を比較する
        if(a < b){
            System.out.println("a < b");
        }
        else if(a > b){
            System.out.println("a > b");
        }
        else{
            System.out.println("a == b");
        }

        
    }
}



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

int main(){
	int n, m, s[300];
	
	while(1){
		int sum1 = 0, sum2 = 0, ans[4] = {}, count = 0;
		cin>>n>>m;
		
		if(n == 0 && m == 0) break;
		
		for(int i = 0; i < n; i++){
			cin>>s[i];
			sum1 += s[i];
		}
		for(int j = 0; j < m; j++){
			cin>>s[n+j];
			sum2 += s[n+j];
		}
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				if(sum1-s[i]+s[n+j] == sum2-s[n+j]+s[i]){
					if(count == 0){
						ans[0] = s[i];
						ans[1] = s[n+j];
					}else{
						if(ans[0]+ans[1] > s[i]+s[n+j]){
							ans[0] = s[i];
							ans[1] = s[n+j];
						}
					}
					count++;
				}
			}
		}
		
		if(count == 0)cout<<-1<<endl;
		else cout<<ans[0]<<" "<<ans[1]<<endl;
	}
	return 0;
}


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

using namespace std;

#define int long long

const int mod = 1e9+7;
int n,a,b,c,d;
int f[1001][1001];
int fact[1001];
int re_fact[1001];

int p(int a,int b)
{
	if (b == 0)
		return 1;
	int tmp = p(a,b/2);
	if (b%2 == 0) return (tmp * tmp)%mod;
	return ((tmp * tmp)%mod * a)%mod;	
}

int comb(int n,int k)
{
	int tmp = ((fact[n] * re_fact[k])%mod * re_fact[n-k])%mod;
	return tmp;
}

int dp(int rem,int cur)
{
	if (rem == 0)
		return 1;
	if (cur > b)
		return 0;
	if (f[rem][cur] != -1)
		return f[rem][cur];
	int ans = dp(rem,cur + 1);
	for (int j=c;j<=d;j++)
	{
		if (rem - j*cur < 0)
			break;
		ans = (((((dp(rem - j*cur,cur + 1)*fact[j*cur])%mod*p(p(fact[cur],j),mod-2))%mod*re_fact[j])%mod*comb(rem,j*cur))%mod + ans)%mod;						
	}
	return f[rem][cur] = ans;
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	                 
	fact[0] = 1;
	for (int i=1;i<=1000;i++)
		fact[i] = (fact[i-1] * i)%mod;
	re_fact[1000] = p(fact[1000],mod-2);
	for (int i=1000;i>=1;i--)
		re_fact[i-1] = (re_fact[i] * i)%mod;	
	cin >> n >> a >> b >> c >> d;
	for (int i=0;i<=1000;i++)
		for (int j=0;j<=1000;j++)
			f[i][j] = -1;
	cout << dp(n,a);
}

Measured memory_bytes: 11540
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> A(2, vector<int>(N+1));
    for(int i=0; i<2; i++)
        for(int j=1; j<=N; j++)
            cin >> A[i][j];

    vector<int> sm1(N+2, 0), sm2(N+2, 0);
    for(int i=1; i<=N; i++) sm1[i] = sm1[i-1] + A[0][i];
    for(int i=N; i>=1; i--) sm2[i] = sm2[i+1] + A[1][i];
    int ans = 0;
    for(int i=1; i<=N; i++)
        ans = max(ans, sm1[i] + sm2[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
a,b=(int(x) for x in input().split())
lista=[]
listb=[]
for numa in range(a+1):
  lista.append(numa*2)
for numb in range(a+1):
  listb.append(numb*4)
listb.reverse()
count=0
combined1 = [x+y for (x, y) in zip(lista, listb)]
for num in combined1:
  if num==b:
    count+=1
if count>0:
  print("Yes")
else: 
  print("No")


Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, n) for (int i = 1; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 500005;
const int MOD = 998244353 ;




void solve(){
    string s;
    cin>>s;
    int n = s.length(), cnt = 0;
    f(i,n/2)if(s[i] != s[n - 1 - i])cnt++;
    cout<<cnt;
}


int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;

const ll inf = 1LL<<59;


struct SegmentTree{
private:
    int n; // セグ木の葉の数, つまり２冪になっており,　全体の要素数は2*n-1
    vector<ll> node;

public:
    SegmentTree(vector<ll> v){
        int sz = (int)v.size();
        n = 1; while(n < sz) n*= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; ++i) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; --i) node[i] = max(node[2*i+1], node[2*i+2]);
    }

    // k番目(0-indexed)をvalに変更
    void update(int x, ll val){
        x += (n-1);
        node[x] = val;
        while(x > 0){
            x = (x-1)/2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }

    // [a,b)の最小値を求める
    // kは接点の番号、l、rはその接点が[l, r)に対応していることを表す
    // 外からはgetmin(a, b, 0, 0, n)と呼ぶ
    ll getmax(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        // [a, b)と[l, r)が交差していなければinfを返す
        if(r <= a || b <= l) return 0;
        // [a,b) ⊃ [l, r)ならば、この接点の値
        if(a <= l && r <= b) return node[k];
        // そうでなければ二つの子の最小値
        ll vl = getmax(a, b, k*2+1, l, (l+r)/2);
        ll vr = getmax(a, b, k*2+2, (l+r)/2, r);
        return max(vl, vr);
    }
};


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

    int n; cin >> n;
    vector<ll> h(n), a(n);
    for(int i=0; i<n; ++i) cin >> h[i];
    for(int i=0; i<n; ++i) cin >> a[i];

    SegmentTree seg(vector<ll>(n+1, 0));
    for(int i=0; i<n; ++i){
        ll maxv = seg.getmax(0, h[i]);
        seg.update(h[i], maxv+a[i]);
    }

    ll ans = seg.getmax(0, n+1);
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ins(a,b,c) a.insert(a.begin()+b,c)
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
signed main(){
  int a;
  cin>>a;
  vector<int> b(a),c;
  fo(i,a)
    cin>>b[i];
  for(int i=b.size()-1;i>=0;i-=2)
    c.push_back(b[i]);
  if(a%2==0){
  for(int i=0;i<b.size();i+=2)
    c.push_back(b[i]);
  }
  else{
    for(int i=1;i<b.size();i+=2)
    c.push_back(b[i]);
  }
  fo(i,a){
    cout<<c[i];
    if(i==a-1)
      cout<<endl;
    else
      cout<<' ';
  }
}

Measured memory_bytes: 5488
<?php

fscanf(STDIN, "%s", $str);

$array = str_split($str);

$size = count($array);
$win = 0;
foreach($array as $letter){
    if($letter == "o"){
        $win++;
    }
}
$residue = 15 -$size;

if($win + $residue < 8){
    echo "NO";
}else{
    echo "YES";
}

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

int main(){
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> l(N);
  for (int i=0; i<N; i++) cin >> l[i];
  int ans = 1e9;
  for (int i=0; i<(1<<(N*2)); i++){
    int tmp = i;
    int a=0, b=0, c=0, cost=0;
    int lnum=0;
    while(lnum<8){
      int hoge = tmp&3;
      if (hoge==1){
        if (a!=0)cost+=10;
        a+=l[lnum];
      }
      else if (hoge==2){
        if (b!=0)cost+=10;
        b+=l[lnum];
      }
      else if (hoge==3){
        if (c!=0)cost+=10;
        c+=l[lnum];
      }
      lnum++;
      tmp >>= 2;
    }
    if (a==0||b==0||c==0) continue;
    cost += abs(a-A) + abs(b-B) + abs(c-C);
    ans = min(ans, cost);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
A = [int(i) for i in input().split()]

ans = 1e9
for i in range(0, 3):
    for j in range(0, 3):
        for k in range(0, 3):
            if(i == j or i == k or j == k):
                continue
            cost = abs(A[i] - A[j]) + abs(A[j] - A[k]);
            ans = min(ans, cost)

print (ans)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin >> a;
  cin >> b;
  cin >> c;
  if(a<b){
    if(b<c)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }else
    cout << "No" << endl;
}


Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

    int n; cin  >> n;
    int d[100010] = {};
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
    }

    ll res = 0;
    for (int i = 0; i < n; i++)
    {
      for (int j = i+1; j < n; j++)
      {
          res += d[i] * d[j];
      }
        
    }
    cout << res << "\n";
    
}

Measured memory_bytes: 640
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>

using namespace std;



long pow(long a, long e, long m) {
    long r = 1;
    long t1, t2;
    while(e != 0) {
        if(e%2 == 1) r = (r*a)%m;
        //if(e%2 == 1) r = mulmod(r,a,m);
        e /= 2;
        a = (a*a)%m;
        //a = mulmod(a,a,m);
    }
    return r;
}

void euclid(long a, long b, long *s, long *t) {
    if(a==0) {
        *s = 0;
        *t = 1;
        return;
    }
    if(b==0) {
        *s = 1;
        *t = 0;
        return;
    }
    if(a>b) {
        euclid(a%b, b, s, t);
        *t -= a/b*(*s);
        return;
    }
    euclid(a, b%a, s, t);
    *s -= b/a*(*t);
    return;
}


long inv(long n, long m) {
    long s,t;
    euclid(n, m, &s, &t);
    return s%m;
}


int main(void){

    

    long k;
    string str;
    cin >>k>>str;
    long s = str.length();
    long m = 1000000007;

    long sum = 0;
    long t;
    long bin = 1;
    for(int i = 0; i <= k; i++) {
        t = pow(26,k-i,m)*pow(25,i,m);
        t = t%m;
        sum += bin*t;
        sum = sum%m;
        bin = bin*(s+i);
        bin = bin%m;
        bin = bin*inv(i+1,m);
        bin = bin%m;
    }

    cout<<(sum+m)%m;



    


    return 0;
}

Measured memory_bytes: 5336
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, ans = -1;
  cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  for (int i=0; i<N; i++) cin >> s[i] >> t[i];
  string X;
  cin >> X;
  for (int i=0; i<N; i++) {
    if (s[i]==X) ans = accumulate(t.begin()+i+1, t.end(), 0);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int count = 1;
        for(int i = 0; i < n; i++){
        	int num = sc.nextInt();
            if(num % 2 == 0){
            	count = count * 2;
            }
        }
        System.out.println((int)Math.pow(3, n) - count);
    }
} 

Measured memory_bytes: 35816
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(n)-1,i##_len=(int)(s);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 2019

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}
int isOK(ll num, ll s) {
	if (num >= s) return 1;
	else return 0;
}

ll binary_search(ll start,ll s) {
	ll left = -1;
	ll right = start;

	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(mid*mid,s)) right = mid;
		else left = mid;
	}

	return right;
}

ll binary_search2(ll start, ll s) {
	ll left = -1;
	ll right = start;

	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(mid*start, s)) right = mid;
		else left = mid;
	}

	return right;
}


int main() {
	ll s;
	scanf("%lld", &s);
	ll x1 = 0, y1 = 0;
	ll x2 = binary_search(Minl(1e9,s),s);
	ll y3 = binary_search2(x2, s);
	ll diff = x2*y3 - s;
	ll y2, x3;
	REPS(i, x2) {
		if (diff%i == 0 && diff / i <= x2) {
			y2 = i;
			x3 = diff / i;
			break;
		}
	}
	printf("%lld %lld %lld %lld %lld %lld\n", x1, y1, x2, y2, x3, y3);
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
  long long N,M;
  cin >> N >> M;
  if(N == 1 && M == 1) cout << 1 << endl;
  else if(N==1) cout << M - 2 << endl;
  else if(M == 1) cout << N - 2 << endl;
  else{
    cout << (N-2)*(M-2) << endl;
  }
  return 0;

}


Measured memory_bytes: 256
#ABC129A-Airplane.py

#import list
from sys import stdin

input = stdin.readline

#constant
#N = int(input())
P, Q, R = list(map(int,input().split()))

#variable

#function

#class

#main function
def main():
    print(min([P+Q,Q+R,P+R]))

if __name__ == "__main__":
    main()


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B;
    cin >> A >> B;
    cout << max({A + B, A - B, A * B}) << endl;
    return 0;
}


Measured memory_bytes: 3576
n = int(input())
AC, WA, TLE, RE = 0, 0, 0, 0
for _ in range(n):
    s = input()
    if s == "AC":
        AC += 1
    elif s == "TLE":
        TLE += 1
    elif s == "WA":
        WA += 1
    elif s == "RE":
        RE += 1
print(f"AC x {AC}")
print(f"WA x {WA}")
print(f"TLE x {TLE}")
print(f"RE x {RE}")

Measured memory_bytes: 69852
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int a;
  cin>>a;
  cout<<((a+1)*a+1)*a<<endl;
  return 0;
}


Measured memory_bytes: 3632
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

const int N = (int) 1e6 + 6, mod = (int) 0;
vector<int> g[N];
int dfs(int v) {
    vector<int> p;
    for (int u : g[v])
        p.push_back(dfs(u));
    int res = 0;
    sort(p.begin(), p.end());
    for (int x : p)
        res = max(x + 1, res + 1);
    return res;
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for (int j = 1; j < n; ++j) {
        int x;
        cin >> x;
        --x;
        g[x].push_back(j);
    }
    cout << dfs(0) << endl;
}


Measured memory_bytes: 34688
from collections import Counter
N = int(input())
Alist = list(map(int, input().split()))
Ac = Counter(Alist)
kaz_d = {}
for k, v in Ac.items():
    kaz_d[k] = (v * (v-1))//2
s = sum(kaz_d.values())
for a in Alist:
    v = Ac[a]
    print(s - ((v*(v-1)//2)) + (((v-1)*(v-2))//2))


Measured memory_bytes: 30776
from heapq import heappop, heappush

N, M = map(int, input().split())
X = list(map(int, input().split()))

pq = []
for v in X:
    heappush(pq, -v)

for _ in range(M):
    u = heappop(pq)
    heappush(pq, -(-u // 2))

print(-sum(pq))


Measured memory_bytes: 84884
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String st=br.readLine();
		int N=Integer.valueOf(st);
		String[] cmd=br.readLine().split(" ");
		int[] arr=new int[N];
		for(int i=0;i<N;i++)
		{
			arr[i]=Integer.valueOf(cmd[i]);
		}
		int[] minCost=new int[N];
		minCost[0]=0;
		minCost[1]=Math.abs(arr[1]-arr[0]);
		for(int i=2;i<N;i++)
		{
			minCost[i]=Math.min(minCost[i-1]+Math.abs(arr[i]-arr[i-1]),minCost[i-2]+Math.abs(arr[i]-arr[i-2]));
		}
		System.out.println(minCost[N-1]);
	}

	/*private static int minCost(int[] arr, int i, int j) {
		// TODO Auto-generated method stub
		if(j==0)
			return 0;
		if(j==1)
			return Math.abs(arr[1]-arr[0]);
		return Math.min(Math.abs(arr[j]-arr[j-1])+minCost(arr,i,j-1), Math.abs(arr[j]-arr[j-2])+minCost(arr,i,j-2));
	}*/
}


Measured memory_bytes: 35852
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,t,ans=1000000;
  cin >> n >> t;
  for(long i=0;i<n;i++) {
    long a,b;
    cin >> a >> b;
    if(b<=t) ans=min(ans,a);
  }
  if(ans==1000000) cout << "TLE" << endl;
  else cout << ans << endl;
}

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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return list(set(a))

a = prime_factorize(N)
count, j = 0, 0
for i in a:
    j = 0
    while N % pow(i, j+1) == 0:
        N /= pow(i, j+1)
        j += 1
    count += j
        
print(count)
        


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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;

struct UnionFind{
  vector<int> par;
  vector<int> siz;

  UnionFind(int N){
    par.resize(N);siz.resize(N);
    for(int i=0;i<N;i++) par[i]=i;
    for(int i=0;i<N;i++) siz[i]=1;
  }

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

  bool unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if (rx == ry) return false;
    if(siz[rx] < siz[ry]) swap(rx,ry);
    siz[rx] += siz[ry];
    par[ry] = rx;
    return true;
  }

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

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

int main(){
  int n,m;
  cin>>n>>m;
  UnionFind uf(n);
  for(int i(0);i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    uf.unite(a,b);
  }
  set<int> s;
  for(int i(0);i<n;i++){
    s.insert(uf.root(i));
  }
  cout << s.size() -1 << endl;
  return 0;
}



Measured memory_bytes: 7816