akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <functional>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 3000000;

long long fac[MAX], finv[MAX], inv[MAX];


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


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
} 


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

    vector<pair<ll, ll>> v;

    for(ll i = 0; i < n; i++) {
        ll r, c;
        cin >> r >> c;
        v.push_back(make_pair(r,c));
    }

    vector<vector<ll>> dp(n+1, vector<ll>(n+1, 999999999999999999));
    for(ll i = 0; i < n; i++) {
        dp[i][i+1] = 0;
    }
    for(ll i = 0; i < n-1; i++) {
        dp[i][i+2] = v[i].first * v[i].second * v[i+1].second;
    }

    for(ll diff = 3; diff <= n; diff++) {
        //cout << diff << endl;
        for(ll i = 0; i + diff <= n; i++) {
            //cout << "*** [" << i <<", " << i+diff << ")" << endl;
            for(ll after = i+1; after <= i+diff-1; after++) {
                // cout << "-> [" << i << ", " << after << ") + [" << after << ", " << i+diff << ")" << endl;
                // cout <<  dp[i][after] + dp[after][i+diff] + v[i].first * v[after-1].second * v[i+diff-1].second << endl;
                dp[i][i+diff] = min(dp[i][i+diff], dp[i][after] + dp[after][i+diff] + v[i].first * v[after-1].second * v[i+diff-1].second);
                //cout << "dp[" << i << "][" << i+diff << "] = " << dp[i][i+diff] << endl;
            }
        }
    }

    cout << dp[0][n] << endl;

    return 0;    
}





Measured memory_bytes: 3168
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, A[222222], a[222222], m1, m2;

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> A[i];

  memcpy(a, A, sizeof(A));

  std::sort(a, a + N);

  m1 = a[N / 2 - 1];
  m2 = a[N / 2];

  for (int i = 0; i < N; i ++)
    std::cout << (A[i] < m2 ? m2 : m1) << std::endl;
  
  return 0;
}


Measured memory_bytes: 3840
#include <stdio.h>

int main() {
	char S[10], T[10], U[10];
	int A, B, i, ans=0;
	scanf("%s %s", &S, &T);
	scanf("%d %d", &A, &B);
	scanf("%s", &U);
	for (i = 0; i < 10; i++) {
		if (S[i] != U[i]) 
			ans = 1;
			break;
	}

	if (ans == 0) {
		printf("%d %d", A - 1, B);
	}
	else {
		printf("%d %d", A, B - 1);
	}

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
	int a, b, c, d, e;
	scanf("%d %d %d", &a, &b, &c);
	d = a;
	e = b;

	if (b <= a) {
		d = b;
		e = a;
	}

	if (c <= d) {
		printf("%d %d %d\n", c, d, e);
	}
	else if (d <= c && c <= e) {
		printf("%d %d %d\n", d, c, e);
	}
	else if (e <= c) {
		printf("%d %d %d\n", d, e, c);
	}

	return 0;
}

/*

/*
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 && c<= 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: 2760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll inf = (1LL<<60);

int main(){
    int N, Ma, Mb; cin >> N >> Ma >> Mb;
    vector<int> a(N), b(N), c(N);
    for(int i=0; i<N; i++) cin >> a[i] >> b[i] >> c[i];

    vector<vector<vector<ll>>> dp(N+1, vector<vector<ll>>(405, vector<ll>(405, inf)));

    dp[0][0][0] = 0;
    dp[0][a[0]][b[0]] = c[0];

    for(int i=1; i<N; i++){
        for(int j=0; j<405; j++){
            for(int k=0; k<405; k++){
                if(dp[i-1][j][k] == inf) continue;

                chmin(dp[i][j][k], dp[i-1][j][k]);
                chmin(dp[i][j+a[i]][k+b[i]], dp[i-1][j][k]+c[i]);
            }
        }
    }

    ll ans = inf;
    for(int a=1; a<405; a++) for(int b=1; b<405; b++){
        if(dp[N-1][a][b] == inf) continue;
        if(a*Mb == b*Ma) chmin(ans, dp[N-1][a][b]);
    }

    if(ans == inf) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 54656
#include <bits/stdc++.h>
#define int long long
using namespace std;

int x,y,A,B,C,now,sum;
priority_queue< int,vector<int>,greater<int> >q1;
priority_queue< int,vector<int>,greater<int> >q2;
signed main(){
	scanf("%d%d%d%d%d",&x,&y,&A,&B,&C);
	for (register int i=1; i<=A; ++i)
	{
		scanf("%lld",&now);
		if (q1.size()<x) q1.push(now),sum+=now;
		else if (q1.top()<now) sum-=q1.top(),q1.pop(),q1.push(now),sum+=now; 
	}
	while (q1.size()<x) q1.push(0);
	
	for (register int i=1; i<=B; ++i)
	{
		scanf("%lld",&now);
		if (q2.size()<y) q2.push(now),sum+=now;
		else if (q2.top()<now) sum-=q2.top(),q2.pop(),q2.push(now),sum+=now; 
	}
	while (q2.size()<y) q2.push(0);
	
	for (register int i=1; i<=C; ++i) 
	{
		int add1,add2;
		scanf("%lld",&now);
		add1=now-q1.top();
		add2=now-q2.top();
		if (max(add1,add2)<=0) continue;
		if (add1>add2) q1.pop(),q1.push(now),sum+=add1;
		else q2.pop(),q2.push(now),sum+=add2;
	}
	
	printf("%lld\n",sum); 
return 0;
}

Measured memory_bytes: 2420
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[a[0]]
for i in range(1,n):b+=[b[-1]+a[i]]
j=0
while a[-1-j]<=b[-2-j]*2:
  j+=1
  if j+1==n:break
print(j+1)

Measured memory_bytes: 14320
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] d = new int[N];
		int answer = 0;

		for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();

		}

		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				answer += d[i] * d[j];
			}
		}

		System.out.println(answer);
	}
}


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



int main(){
    string S;
    cin >> S;
    if(S[0] == S[1] && S[0] == S[2] && S[2] == S[3]) cout << "No" << endl;
    else if(S[0] == S[1] && S[2] == S[3]) cout << "Yes" << endl;
    else if(S[0] == S[2] && S[1] == S[3]) cout << "Yes" << endl;
    else if(S[0] == S[3] && S[1] == S[2]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

int n, m;
int ans = 0;
int dir[4]{-1, 1, 0, 0};

void dfs(vector<vector<int> >& grid, pair<int, int> cur, int depth) {
    grid[cur.first][cur.second] = 0;
    ans = max(ans, depth);
    for (int i = 0; i < 4; i++) {
        int nr = cur.first + dir[i];
        int nc = cur.second + dir[3 - i];
        if (nr < 0 || m <= nr) continue;
        if (nc < 0 || n <= nc) continue;
        if (grid[nr][nc] == 0) continue;
        dfs(grid, make_pair(nr, nc), depth + 1);
    }
    // cout << cur.first << " " << cur.second << endl;
    grid[cur.first][cur.second] = 1;
}

int main() {
    while(cin){    
        cin >> n >> m;
        if (n == 0 && m == 0) break;
        vector<vector<int> > grid(m, vector<int>(n, 0));
        rep(i, m) rep(j, n) cin >> grid[i][j];

        rep(i, m) rep(j, n) if (grid[i][j] == 1) dfs(grid, make_pair(i, j), 1);
        cout << ans << endl;
        ans = 0;
    }
}


Measured memory_bytes: 3188
N, M = gets.split.map(&:to_i)

C = []
D = Hash.new {|h, i| h[i] = {}}
M.times do |i|
  tmp = gets.split.map(&:to_i)
  C << tmp
  D[tmp[0]][tmp[1]] = nil
end 

D.each do |k, v|
  v.keys.sort.each.with_index(1) do |x, i|
    v[x] = i   
  end
end

C.each do |px, y|
  puts "%012d" % (px * 1000000 + D[px][y])
end

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

int main() {
  string str;
  while (cin >> str && str != "-") {
    int m; cin >> m;
    for (int i = 0; i < m; i++){
      int h; cin >> h;
      str = str.substr(h) + str.substr(0, h);
    }
    cout << str << endl;
  }
  return 0;
}



Measured memory_bytes: 3184
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CSwitches solver = new CSwitches();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSwitches {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            long ans = 0;
            ArrayList<Integer> a[] = new ArrayList[m];
            for (int i = 0; i < m; i++) a[i] = new ArrayList<Integer>();
            int p[] = new int[m];
            for (int i = 0; i < m; i++) {
                int k = in.nextInt();
                for (int j = 0; j < k; j++) a[i].add(in.nextInt() - 1);
            }
            for (int i = 0; i < m; i++) p[i] = in.nextInt();
            int x = (int) Math.pow(2, n);
            for (int i = 0; i < x; i++) {
                int l = 0;
                for (int j = 0; j < m; j++) {
                    int count = 0;
                    for (int k = 0; k < a[j].size(); k++) {
                        if ((i & (1 << a[j].get(k))) > 0) count++;
                    }
                    if (count % 2 == p[j]) l++;
                }
                if (l == m) {
                    ans++;
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 23508
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;

int main()
{
	int N, m6, m9;
	cin >> N;

	int ans = N;

	vector<int> v6, v9;

	v6.push_back(1);
	v9.push_back(1);

	int count = 6;
	while (count <= N) {
		v6.push_back(count);
		count *= 6;
	}

	count = 9;
	while (count <= N) {
		v9.push_back(count);
		count *= 9;
	}

	/*
	int  n = N;
	for (int i = v.size()-1; i >= 0; i--) {
		while (v[i] <= n) {
			n -= v[i];
			ans++;
		}
	}
	
	for (int i = 0; i < v.size(); i++) {
		cout << v[i] << endl;
	}*/

	for (int i = 0; i <= N/9; i++) {
		int count = 0;

		int res = 9*i;
		while(res != 0) {
			count += res%9;
			res = res/9;
		}

		res = N - 9*i;
		while (res != 0) {
			count += res % 6;
			res = res / 6;
		}
/*
		if (m6+m9>11) {
			count -= 10;
		}
		else if (m6 + m9>5) {
			count -= 5;
		}
*/
		if (ans > count) ans = count;
	}

	cout << ans;

	char qq;
	cin >> qq;
	return 0;
}

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

int main() {
	int r, c, sum, acc;
	int table[100 + 1][100 + 1] = {};
    cin >> r >> c;

    acc = 0;
	for (int i = 0; i < r; i++) {
		sum = 0;
		for (int j = 0; j < c; j++) {
            cin >> table[i][j];
			sum += table[i][j];
			table[r][j] += table[i][j];
		}
		table[i][c] = sum;
		acc += sum;
	}
	table[r][c] = acc;

	for (int i = 0; i < r + 1; i++) {
		for (int j = 0; j < c; j++) {
			cout << table[i][j] << " ";
		}
		cout << table[i][c] << endl;
	}

    return 0;
}


Measured memory_bytes: 3108
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>
#include <numeric>

using namespace std;
typedef long long ll;

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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> balls(N, 1);
	set<int> s;
	s.insert(0);
	rep(i, M) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		balls[x]--;
		balls[y]++;
		if (s.find(x) != s.end()) {
			if (balls[x] <= 0)
				s.erase(x);
			s.insert(y);
		}
	}
	auto ans = s.size();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5376
N, M, X, Y = map(int, input().split())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))

is_war = True

import numpy as np

for Z in range(X+1, Y+1):
    if np.all(np.array(x_list) < Z) and np.all(np.array(y_list) >= Z):
        is_war = False
        break
    
if is_war:
    print("War")
else:
    print("No War")

Measured memory_bytes: 27216
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
 
const int MOD = 1000000007;
using bigint = boost::multiprecision::cpp_int;
 
int main(){
    int N; cin >> N;
    bigint ablcm = 1;
    bigint b = 0;
    for(int i=0; i<N; i++){
        int a; cin >> a;
        auto t = __gcd(boost::multiprecision::integer_modulus(ablcm, a), a);
        (b *= (a/t)) += ablcm /= t;
        ablcm *= a;
    }
    b =  boost::multiprecision::integer_modulus(b, MOD);
    cout << b << endl;
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        init();
        String s = next();
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            ans.append("x");
        }
        System.out.println(ans.toString());
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 200000

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX];
    fget_array(arr, num);

    static int deque[NUM_MAX*2];
    int start = NUM_MAX;
    int end = NUM_MAX;

    int i;
    int dir = 1;
    for(i = 0; i < num; i++) {
        int val = arr[i];
        if(i%2==0) {
            deque[end++] = val;
        } else {
            deque[--start] = val;
        }
        dir = -dir;
    }

    if(dir==1) {
        // str is [start, end)
        for(i = start; i < end; i++) {
            printf("%d%c", deque[i], i == end-1 ? '\n' : ' ');
        }
    } else {
        for(i = end-1; i >= start; i--) {
            printf("%d%c", deque[i], i == start ? '\n' : ' ');
        }
    }
    return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>
int main(void){
  int N=0,X=0,T=0;
  int sum1=0,sum2=0,sum3=0;
  int T2=0;
  scanf("%d%d%d", &N, &X, &T);
  if((1<=N && N<=1000) && (1<=T && T<=1000) && (1<=X && X<=1000)){
    sum1=N/X;
    if(N%X!=0){
      sum2=sum1+1;
      printf("%d\n",T*sum2);
    }
    else{
    printf("%d\n",T*sum1);
    }
  }
  return 0;
}
  

Measured memory_bytes: 1732
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>

using namespace std;

#define fto(i,a,b) for (int i = (a); i <= b; i++)
#define fdw(i,a,b) for (int i = (a); i >= b; i--)
#define rep(i,a) for(int i = 0; i < a; i++) 
#define read(a) cin >> a
#define read2(a, b) cin >> a >> b
#define read3(a, b, c) cin >> a >> b >> c
#define read4(a, b, c, d) cin >> a >> b >> c >> d
#define write(a, b) cout << a << b
#define writeln(a) cout << a << "\n"

#define PI 3.14159265
#define oo 1000000000
#define ooLL 100000000000000000
#define log(a) cerr << #a << " = " << a << endl

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define next thongdeptrai
#define prev thongbachuthegioi
#define y1 thongsieucapvutru
#define y0 thongnotgay

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

#define maxn 100005

using namespace std;

int a[maxn], n;
int cnt[maxn];

int main() {

    // checking input file is not available with atCoder
 //   freopen("in.inp", "r", stdin);
    
    read(n);
    for(int i = 1; i <= n; i++) {
        read(a[i]);
        a[i]++;
    }

    for(int i = 1; i <= n; i++) 
        cnt[a[i] + 1]++, cnt[a[i] - 1]++, cnt[a[i]]++;

    int pos = 0;
    for(int i = 0; i <= 100002; i++) 
        if (cnt[pos] <= cnt[i]) pos = i;

    int res = 0;
    for(int i = n; i >= 1; i--) 
        if (a[i] + 1 == pos || a[i] - 1 == pos || a[i] == pos) res++;

    cout << res;
    

    #ifndef ONLINE_JUDGE
        cout << endl;
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    string w;
    cin >> w;
    for (int i = 0; i < 12; ++i) {
        cout << w[i];
        if (i == 3) cout << ' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
int a[MAXN],b[MAXN],c[MAXN],d[MAXN];
int n,sum;
int fa[MAXN],flag[MAXN];
int get_fa(int x){
	if(fa[x]==0)
		return x;
	fa[x]=get_fa(fa[x]);
	return fa[x];	
}
void merge(int x,int y){
	x=get_fa(x),y=get_fa(y);
	if(x!=y)
		fa[x]=y;
}
int main(){
	SF("%d",&n);
	for(int i=1;i<=n;i++){
		SF("%d",&a[i]);
		sum^=a[i];
	}
	a[n+1]=sum;
	sum=0;
	for(int i=1;i<=n;i++){
		SF("%d",&b[i]);
		sum^=b[i];
	}
	b[++n]=sum;
	for(int i=1;i<=n;i++){
		c[i]=a[i];
		d[i]=b[i];
	}
	sort(c+1,c+1+n);
	sort(d+1,d+1+n);
	for(int i=1;i<=n;i++)
		if(c[i]!=d[i]){
			PF("-1");	
			return 0;
		}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(a[i]!=b[i]||i==n){
			if(i!=n)
				ans++;
			int x=lower_bound(c+1,c+1+n,a[i])-c;
			int y=lower_bound(c+1,c+1+n,b[i])-c;
			flag[x]=flag[y]=1;
			merge(x,y);
		}
	if(ans==0){
		PF("0");
		return 0;	
	}
	for(int i=1;i<=n;i++)
		if(flag[i]&&fa[i]==0)
			ans++;
	PF("%d",ans-1);
}

Measured memory_bytes: 4096
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> L >> R;
		if (M < L) {
			M = L;
			K = R;
		}
	}
	cout << K + M << endl;
	return 0;
}


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

template<class T>
struct GraphNode {
    GraphNode(T data):
        neighbors(),
        data(data) 
    { }

    std::vector<GraphNode *> neighbors;
    T data;
};

template<class T>
class Graph {
public:
    enum CONTINUE_SEARCH {
        CONTINUE, END
    };

    Graph(const uint64_t num_nodes, T data):
        nodes(num_nodes, GraphNode<T>(data))
    { }

    GraphNode<T> &get_node(uint64_t n) {
        return nodes[n];
    }

    void add_bidirectional_edge(const uint64_t a, const uint64_t b) {
        nodes[a].neighbors.push_back(&nodes[b]);
        nodes[b].neighbors.push_back(&nodes[a]);
    }

    void depth_first_search(const uint64_t start_node, std::function<CONTINUE_SEARCH(GraphNode<T> &, uint64_t)> func) {
        auto searched_nodes = std::set<GraphNode<T> *>();
        depth_first_search_impl(nodes[start_node], func, searched_nodes, 0);
    }

private:
    void depth_first_search_impl(GraphNode<T> &node, std::function<CONTINUE_SEARCH(GraphNode<T> &, uint64_t)> func, std::set<GraphNode<T> *> &searched_nodes, uint64_t depth) {
        if(searched_nodes.find(&node) == searched_nodes.end()) {
            searched_nodes.insert(&node);
            if(func(node, depth) == CONTINUE_SEARCH::CONTINUE) {
                for(auto neighbor: node.neighbors) {
                    depth_first_search_impl(*neighbor, func, searched_nodes, depth + 1);
                }
            }
        }
    }

    std::vector<GraphNode<T> > nodes;
};

struct Data {
    uint64_t chaser_depth = 0;
    uint64_t runner_depth = 0;
};

GraphNode<Data> *node = nullptr;

uint64_t solve(Graph<Data> &g, uint64_t runner, uint64_t chaser) {
    g.depth_first_search(chaser, [](GraphNode<Data> &node, uint64_t depth) {
        node.data.chaser_depth = depth;
        return Graph<Data>::CONTINUE;
    });
    g.depth_first_search(runner, [](GraphNode<Data> &n, uint64_t depth) {
        if(n.data.chaser_depth <= depth) {
            return Graph<Data>::END;
        }
        n.data.runner_depth = depth;
        if(node == nullptr || node->data.chaser_depth < n.data.chaser_depth) {
            node = &n;
        }
        return Graph<Data>::CONTINUE;
    });
    return node->data.chaser_depth - 1;
}

int main() {
    uint64_t n, runner, chaser;
    std::cin >> n >> runner >> chaser;
    auto g = Graph<Data>(n, Data());
    for(int i = 0; i < n - 1; ++i) {
        uint64_t a, b;
        std::cin >> a >> b;
        g.add_bidirectional_edge(a - 1, b - 1);
    }

    std::cout << solve(g, runner - 1, chaser - 1);

    return 0;
}


Measured memory_bytes: 18944
# util functions
class UnionFind
  def initialize(n) # n: number of elements in the forest
    @par  = []
    @rank = []
    @vs   = []
    n.times do |i|
      @par[i] = i
      @rank[i] = 0
      @vs[i] = 1
    end
  end
  attr_accessor :par, :rank, :vs

  def find(x)
    raise "x = #{x} is out of range 0..#{@par.size - 1}" unless @par[x]
    if @par[x] == x
      return x
    else
      return find( @par[x] )
    end
  end

  def unite( x, y )
    xrt = find(x)
    yrt = find(y)
    return if xrt == yrt

    if @rank[xrt] > @rank[yrt]
      @par[yrt] = xrt
      @vs[xrt] += @vs[yrt]
    else
      @par[xrt] = yrt
      @vs[yrt] += @vs[xrt]
      @rank[yrt] += 1 if @rank[xrt] == @rank[yrt]
    end
  end

  def same( x, y ) # returns true/false
    return find( x ) == find( y )
  end

end # UnionFind

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

nn = inputs[0][0]
$lst = inputs[1]

# body
if $debugFlag
end

uf = UnionFind.new(nn)

for i in 2..inputs.size-1
  uf.unite($lst[inputs[i][0]-1]-1, $lst[inputs[i][1]-1]-1);
end

ans = 0;
for j in 0..nn-1
  ans += 1 if uf.same(j, $lst[j] - 1) or j == $lst[j]-1
end

puts ans


Measured memory_bytes: 14604
#include <stdio.h>
#define MAX 101

int main(void) {
  int a[MAX];
  int n;
  int i, j;
  int t;
  int count;

  while(scanf("%d", &n) != EOF) {
    if(!n)
      break;

    for(i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }

    count = 0;
    for(i -= 1; i >= 0; i--) {
      for(j = 1; j <= i; j++) {
	if(a[j-1] > a[j]) {
	  t = a[j-1];
	  a[j-1] = a[j];
	  a[j] = t;
	  count++;
	}
      }
    }
    printf("%d\n", count);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     998244353
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
ll pows(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD){if(m == 1)return 0;ll m0=m,y=0,x=1;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0) x+=m0;return x;}
int main()
{
ll n,m,i,j,k,x,y,z,e,f,p,q,g,l,r,w,h,count1=0,prod=1,a,b,c,d,index,x1,x2,diff,ans=0,sum=0,sum1=0,sum2=0,flag=0,flag1=0,flag2=0;
string s,s1,s2;
cin>>n;
p=n/500;
p*=1000;
sum+=p;
p=n%500;
p=p/5;
p*=5;
sum+=p;
cout<<sum;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
#define MAXN 400
#define MAXM 160000
#define LL long long
#define Pr pair<int,int>
#define X first
#define Y second
LL read(){
    LL x=0,F=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*F;
}
int n,m,tot;
int a[MAXM+5],vis[MAXM+5],tmp[MAXM+5];
int match[MAXM+5],ans[MAXN+5][MAXN+5],tp[MAXN+5][MAXN+5];
vector<int> P[MAXN+5][MAXN+5];
vector<int> G[MAXM+5];
int dfs(int x)
{
	if(vis[x])return 0;
	vis[x]=1;
    for(int i=0;i<G[x].size();i++){
        int xnt=G[x][i];
        if(match[xnt]==-1||dfs(match[xnt])){
            match[xnt]=x;
            return 1;
        }
    }return 0;
}
int main()
{
	//freopen("sort.in","r",stdin);
	//freopen("sort.out","w",stdout);
	n=read(),m=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			int x=read();
			a[x]=i;//在第i行
			P[i][(x-1)/m+1].push_back(x);
		}
	for(int t=1;t<=m;t++){//m次最大匹配O(n^4) 
		for(int i=1;i<=n;i++)
		G[i].clear(),match[i]=-1;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++)
			if(!P[i][j].empty())G[i].push_back(j);
		}
		for(int i=1;i<=n;i++){
			memset(vis,0,sizeof(vis));
			dfs(i);
		}
		for(int i=1;i<=n;i++){
			ans[match[i]][t]=P[match[i]][i].back();
			P[match[i]][i].pop_back();
		}
	}
	for(int i=1;i<=n;i++,puts(""))
		for(int j=1;j<=m;j++)
			printf("%d ",ans[i][j]);
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++)
		tmp[j]=ans[j][i];
		sort(tmp+1,tmp+n+1);
		for(int j=1;j<=n;j++)
		tp[j][i]=tmp[j];
	}
	for(int i=1;i<=n;i++,puts(""))
		for(int j=1;j<=m;j++)
			printf("%d ",tp[i][j]);
}

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

using ll = long long;
const ll mod = 1e9 + 7;

void mkay(ll& a){
	if(a >= mod)
		a -= mod;
}


ll ps[200001];
int arr[200001];
int n;

int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> arr[i];
		mkay(ps[i] = ps[i - 1] + arr[i]);
	}
	ll ans = 0;

	for(int i = 1; i <= n; i++){
		ll temp;
		temp = (arr[i] * ps[i - 1]) % mod;
		mkay(ans += temp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5960
def caesar(s, n):
    d = {}
    for c in (65, 97):
        for i in range(26):
            d[chr(i+c)] = chr((i+n) % 26 + c)

    return "".join([d.get(c, c) for c in s])

n = int(input())
s = input()

print(caesar(s, n))



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;

int main() {
  ll N; cin>>N;
  vi a(N); REP(i,N) cin>>a[i];
  vi b(3);
  REP(i,N) if(a[i]%4==0) b[0]+=1; else if(a[i]%4==2) b[1]+=1; else b[2]+=1;
  vi c(N);
  REP(i,3) if(b[2-i]) {c[0]=2-i; b[2-i]-=1; break;}
  FOR(i,1,N) for(ll j=2-c[i-1];j>=0;j--) if(b[j]) {c[i]=j; b[j]-=1; break;} else if(j==0) {cout<<"No"<<endl; return 0;}
  cout<<"Yes"<<endl;

}


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto& x : a){
        cin >> x;
        --x;
    }
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(a[i] > i && a[a[i]] == i)
            ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;

void solve(){
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	/*vector<int> r;
	r.push_back(a[0]);
	rep(i, n) {
		if (i + 1 < n&&a[i] < a[i + 1]) {
			r.push_back(a[i + 1]);
		}
		else {
			r.push_back(a[i] + 1);
		}
	}
	a = r; n++;*/
	//rep(i, n)cout << r[i] << endl;
	string ans = "First";
	rep1(i, n) {
		if (a[n - i] >= i) {
			if (n - i - 1 < 0 || a[n - i - 1] < i) {
				int r = a[n - i] - i;
				if (r % 2 == 0) {
					ans = "Second";
				}
				break;
			}
			else {
				if (a[n - i] > i&&a[n-i-1]==i) {
					ans = "Second";
					int tmp = 0;
					int cur = n - i - 1;
					while (cur >= 0 && a[cur] == i) {
						tmp ^= 1; cur--;
					}
					if (tmp % 2)ans = "First";
					int r = a[n - i] - i;
					if (r % 2)ans = "First";

					break;
				}
			}
		}
		if (a[n - i] == i) {
			int tmp = 1;
			int cur = n - i - 1;
			while (cur >= 0 && a[cur] == i) {
				tmp ^= 1; cur--;
			}
			if (tmp % 2)ans = "Second";
			break;
		}
	}
	cout << ans << endl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//init();
	solve();

	//cout << "finish" << endl;
	//stop
	return 0;
}

Measured memory_bytes: 640
N,M=map(int,input().split())
#N=3
#M=7

MEMO=[[0]*(2) for i in range(N+1)]
MEMO[0][0]=1
MEMO[0][1]=1

for i in range (1,N+1):
    MEMO[i][0]=MEMO[i-1][0]*2+3
    MEMO[i][1]=MEMO[i-1][1]*2+1
t=1
s=0
n=N-1
f=0
while(True):
        if(t==M):break
        if(t+MEMO[n][0]<M):
            if f==0:
                t=t+MEMO[n][0]+1
                s+=MEMO[n][1]+1
                f+=1
            else:
                s+=MEMO[n][1]
                break
        elif(t+MEMO[n][0]>M):
            t+=1
            n-=1
            f=0
        else:
            s+=MEMO[n][1]
            break
print(s)

Measured memory_bytes: 38256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>

using namespace std;


int main(){
    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> foods;
    vector<vector<int>> dp(N+1, vector<int>(T+2, 0));
    for(int i=0;i<N;i++){
        int a, b;
        cin >> a >> b;
        foods.push_back(pair<int ,int>{a, b});//timecost, value
    }
    sort(foods.begin(), foods.end());
//    for(auto f:foods){cout << f.first <<"-" << f.second << endl;}
    for(int j=foods[0].first;j<=T;j++)
        dp[1][j] = foods[0].second;
    int maxEat=foods[0].second;
    for(int f=2;f<=N;f++){
        for(int w=0;w<=T;w++){
            if(w-foods[f-1].first >= 0)
                dp[f][w] = max(dp[f-1][w], dp[f-1][w-foods[f-1].first] + foods[f-1].second);
            else
            {
                dp[f][w] = dp[f-1][w];
            }
        }
        dp[f][T+1] = dp[f-1][T-1]+foods[f-1].second;
        maxEat = max(maxEat, dp[f][T+1]);
    }
/*
    for(auto p:dp){
        for(auto c:p){
            cout << c << " ";
        }
        cout << endl;
    }*/

    cout << maxEat;
    return 0;
}


Measured memory_bytes: 35712
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;

int main() {
  int N; cin >>N;
  vector<P> v(N);
  REP(i, N) cin >>v[i].first >>v[i].second;
  sort(v.begin(), v.end(), [](const P &a, const P &b) -> bool { return (a.second != b.second ? a.second > b.second : a.first < b.first); });
  cout <<v[0].first <<" " <<v[0].second <<endl;
  return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
#define N 36

  typedef struct{
  char kind;
  
  int number;}
  Trump;
  
  int main(void){
  int n, i, j, a, min;
  Trump x[N], y[N], t;
  
  scanf("%d",&n);
  
  for(i = 0 ; i < n ; i++){
    scanf("%c%c%d",&x[i].kind, 
                 &x[i].kind,
                 &x[i].number);
    y[i] = x[i];
  }
    
  for(i = 0 ; i < n ; i++){
    for(j = n-1 ; j >= i+1 ; j--){
      if(x[j].number < x[j-1].number){
        t = x[j];
        x[j] = x[j-1];
        x[j-1] = t;
      }
    }
  }    
      
    
  for(i = 0 ; i < n ; i++){
    min = i;
    for(j = i ; j < n ;j++)
      if(y[j].number < y[min].number)
        min = j;
      t = y[i];
      y[i] = y[min];
      y[min] = t;     
  }
  
  
  
  
  for( i = 0; i < n-1; i++){
    printf("%c%d ", x[i].kind, x[i].number);
  }
  printf("%c%d\n", x[n-1].kind, x[n-1].number);
  printf("Stable\n");
   
  for( i = 0; i < n-1; i++){
    printf("%c%d ", y[i].kind, y[i].number);
  }
  printf("%c%d\n", y[n-1].kind, y[n-1].number);
  
  a = 1;
  
  for(i = 0; i < n; i++)
    if(x[i].kind != y[i].kind)
      a = 0;
  
  if(a == 1)
    printf("Stable\n");
  else
    printf("Not stable\n");
   
  return 0;
}



Measured memory_bytes: 1992
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);

#define dbg1(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    for (auto it = v.begin(); it != v.end(); ++it) {
        if ( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    for (auto it = v.begin(); it != v.end(); ++it) {
        if ( it != v.begin()) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    for (auto it = v.begin(); it != v.end(); ++it) {
        if ( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
    for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
    cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less 
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

/**___________________________________________________**/



int main()
{
    FASTIO
    /*
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    string s, t;
    cin >> s;
    t = s;
    reverse(s.begin(), s.end());
    int cnt = 0;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        if (s[i] != t[i])cnt++;
    }
    cout << (cnt + 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

constexpr int MAX_N = 100, INF = 1<<30;

using P = std::pair<int, int>;
using State = std::pair<int, P>;

int W, H, N;
int x[MAX_N], y[MAX_N];
int d[MAX_N][1010];
std::priority_queue<State, std::vector<State>, std::greater<State> > pque;
int ans = INF;

int main()
{
  scanf( "%d%d%d", &W, &H, &N );
  rep( i, N )
    scanf( "%d%d", x+i, y+i ), --x[i], --y[i];

  std::fill( (int*)d, (int*)(d+N), INF );

  rep( i, N )
  {
    int cost = x[i]+y[i];
    d[i][cost] = cost;
    pque.push( State( d[i][cost], P( i, cost ) ) );
  }

  while( !pque.empty() )
  {
    State st = pque.top(); pque.pop();
    int dist = st.first, v = st.second.first, cost = st.second.second;

    if( d[v][cost] < dist )
      continue;

    rep( i, N )
    {
      int ncost = std::max( 0, abs(x[i]-x[v])+abs(y[i]-y[v])-cost-1 );

      if( d[i][ncost] > d[v][cost]+ncost )
      {
        d[i][ncost] = d[v][cost]+ncost;
        pque.push( State( d[i][ncost], P( i, ncost ) ) );
      }
    }
  }

  rep( i, N ) rep( j, W+H+1 )
    ans = std::min( ans, d[i][j]+std::max(0,abs(W-1-x[i])+abs(H-1-y[i])-j) );

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


Measured memory_bytes: 3720
#include<bits/stdc++.h>
using  namespace std;
#define ll long long
#define pb push_back
#define sc second
#define fr first
#define mp make_pair
const int  MOD = 1e9 + 7, OO = 1e9;
const int  N = 2e5 + 10;
int a[30][30], calc[30];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int  n, d;
	cin >> n >> d;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= d; ++j) {
			cin >> a[i][j];
			calc[i] += a[i][j];
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			int sum = 0;
			for (int k = 1; k <= d; ++k) {
				sum += (a[i][k] - a[j][k])*(a[i][k] - a[j][k]);
			}
			int sq = sqrt(sum);
			if (sq*sq == sum)
				++ans;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		// セル数の合計
		int N_num = int.Parse(Console.ReadLine());
		int cell_sum = N_num*N_num;
		// 塗りつぶすセル数
		int A_Math = int.Parse(Console.ReadLine());
		// 解答マス数
		int answer = cell_sum - A_Math;
		//出力
		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 13140
/*
ID: mm.khan1
PROG: beads
LANG: C++14
*/
#include <bits/stdc++.h>

using namespace std;

//#pragma GCC target ("sse4.2")
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE_IO ifstream cin ("beads.in"); ofstream cout ("beads.out");
#define pii pair<int, int>
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const int MAX_I = 1e5*3;
const int N = 1e6;
const ll mud = 1e9 + 7;
ll a[N];

int main(){
	FAST_IO;
	//FILE_IO;	
	
	ll n;
	cin >> n;
	for (ll i=0;i<n;i++) cin>>a[i];

	bool ans=1;
	for (ll i=n-2;i>=0;i--){
		if (a[i]<max(0LL, a[i+1]-1) || a[i]>i){
			ans=0;
			break;
		}
	}
	if (!ans || a[0]){
		cout << "-1\n";
		return 0;
	}

	ll cnt=0, cur=0;
	for (ll i=n-1;i>=0;i--){
		if (cur<a[i]){
			cur=a[i];
			cnt+=a[i];
		}
		cur = max(0LL, cur-1);
	}

	cout << cnt << '\n';

	return 0;
}



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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int n;
ll x[105];
void solve() {
    cin >> n;
    rep(i, n) cin >> x[i];

    ll ans = inf;
    reps(p, 100) {
        ll res = 0;
        rep(i, n) res += pow2(x[i] - p);
        mins(ans, res);
    }

    cout << ans << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int S;
    int s,m,h;
    scanf("%d", &S);
    for(h=0; S >= 3600; h++){
        S -= 3600;
    }
    for(m=0; S >= 60; m++){
        S -= 60;
    }
    s = S;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}



Measured memory_bytes: 2112