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

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

vector<ll> find_all(const string str, const string subStr) {
    vector<ll> result;

    int subStrSize = subStr.size();
    int pos = str.find(subStr);

    while (pos != std::string::npos) {
        result.push_back(pos);
        pos = str.find(subStr, pos + subStrSize);
    }

    return result;
}

int main() {
    INIT;

    ll N;
    cin >> N;
    vector<string> s(N);
    rep(i, N) cin >> s[i];

    ll ans = 0;
    vector<ll> find_vec;
    rep(i, N) {
        find_vec = find_all(s[i], "AB");
        ans += SZ(find_vec);
        find_vec.clear();
    }

    // cout << ans << endl;
    // pair<ll, ll> cnt_f, cnt_l;
    ll c1 = 0, c2 = 0, c3 = 0;
    rep(i, N) {
        ll len = SZ(s[i]);
        if (s[i][0] == 'B' && s[i][len - 1] == 'A') {
            c1++;
        } else if (s[i][0] == 'B') {
            c2++;
        } else if (s[i][len - 1] == 'A') {
            c3++;
        }
    }

    // cout << cnt_f.first << ", " <<cnt_f.second << endl;
    // cout << cnt_l.first << ", " << cnt_l.second << endl;
    if (c1 == 0) {
        ans += min(c2, c3);
    } else {
        if (c2 + c3 == 0) {
            ans += c1 - 1;
        } else {
            ans += c1 + min(c2, c3);
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define x first 
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;
template <typename T> inline int Chkmin (T &a, T b) {return a > b ? a = b, 1 : 0; }
template <typename T> inline int Chkmax (T &a, T b) {return a < b ? a = b, 1 : 0; }
inline int read ()
{
	int sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

const int Maxn = 100000 + 100;

int N, A[Maxn], B[Maxn], A1[Maxn], B1[Maxn];
int e, Begin[Maxn], To[Maxn << 1], Next[Maxn << 1];

inline void add_edge (int x, int y) { To[++e] = y; Next[e] = Begin[x]; Begin[x] = e; }

inline void Input ()
{
	N = read();
	int sum = 0;
	for (int i = 1; i <= N; ++i) A[i] = read(), sum ^= A[i];
	A[N + 1] = sum, sum = 0;
	for (int i = 1; i <= N; ++i) B[i] = read(), sum ^= B[i];
	B[++N] = sum;
}

int sum, Vis[Maxn], Viss[Maxn];

inline void dfs (int x)
{
	++sum;
	Vis[x] = 1;
	for (int i = Begin[x]; i; i = Next[i])
	{
		int y = To[i];
		if (!Vis[y]) dfs(y);
	}
}

inline void Solve ()
{
	for (int i = 1; i <= N; ++i) A1[i] = A[i], B1[i] = B[i];
	sort(A1 + 1, A1 + N + 1);
	sort(B1 + 1, B1 + N + 1);
	for (int i = 1; i <= N; ++i) if (A1[i] != B1[i]) { cout<<-1<<endl; return ; }
	int len = unique (A1 + 1, A1 + N + 1) - A1 - 1;
	for (int i = 1; i <= N; ++i) A[i] = lower_bound (A1 + 1, A1 + len + 1, A[i]) - A1;
	for (int i = 1; i <= N; ++i) B[i] = lower_bound (A1 + 1, A1 + len + 1, B[i]) - A1;

	int ans = 0;
	for (int i = 1; i <= N; ++i)
	{
		if (A[i] != B[i] || i == N)
		{
			if (i != N) ++ans;
			add_edge (A[i], B[i]), add_edge (B[i], A[i]);
			Viss[A[i]] = Viss[B[i]] = 1;
		}
	}
	for (int i = 1; i <= N; ++i)
		if (!Vis[i] && Viss[i])
		{
			dfs(i);
			++ans;
		}

	cout<<ans - 1<<endl;
}

int main()
{
	Input();
	Solve();
	return 0;
}

Measured memory_bytes: 5632
#include <stdio.h>

int isPrime(int x)
{
    int i;
    if (x < 2)
        return 0;
    else if (x == 2)
        return 1;
    if (x % 2 == 0)
        return 0;
    for (i = 3; i * i <= x; i += 2)
    {
        if (x % i == 0)
            return 0;
    }
    return 1;
}
int main()
{
    int n, x, i;
    int cnt = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &x);
        if (isPrime(x))
            cnt++;
    }
    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 2104
if __name__ == '__main__':
    n = int(input())
    lst = list(map(int, input().split()))

    ans = (50*101)*(50*101)
    for i in range(-100,101):
        mn = 0
        for c in lst:
            mn += (i-c)*(i-c)
        ans = min(ans,mn)

    print(ans)


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

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

int main()
{
    int n, m, k, t; cin >> n >> m >> k;
    vector<ll> sa(n+1), sb(m+1);
    sa[0] = sb[0] = 0;
    rep(i, n){
        cin >> t;
        sa[i+1] = sa[i] + t; 
    }
    rep(i, m){
        cin >> t;
        sb[i+1] = sb[i] + t;
    }

    int al = 0, ar = n+1;
    while(ar - al > 1){
        int am = (al + ar)/2;
        if(sa[am] <= k) al = am;
        else ar = am;
    }

    int ans = 0, cnt;
    for(int a = al; a >= 0; a--){
        cnt = a;
        int b_time = k - sa[a];

        int bl = 0, br = m+1;
        while(br - bl > 1){
            int bm = (bl + br)/2;
            if(sb[bm] <= b_time) bl = bm;
            else br = bm;
        }

        cnt += bl;
        ans = max(ans, cnt);
    }

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

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

const int INF = 10000000;
vector<int> map_table[100005];

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    // convert a and b to zero-origin
    a--;
    b--;
    map_table[a].push_back(b);
    map_table[b].push_back(a);
  }

  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  dist[0] = 0;
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int u : map_table[v]) {
      if (dist[u] != INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }
  cout << "Yes" << endl;
  rep(i, n) {
    if (i == 0) continue;
    int ans = pre[i] + 1;
    cout << ans << endl;
  }

  return 0;
}


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

using namespace std;

using int64 = long long;

string S;
int64 dp[18][2];

int64 rec(int idx, bool lim) {
  if(idx == S.size()) return 0;
  if(~dp[idx][lim]) return dp[idx][lim];
  int64 ret = 0;
  for(int i = lim ? 9 : S[idx] - '0'; i >= 0; i--) {
    ret = max(ret, rec(idx + 1, lim | (S[idx] - '0' != i)) + i);
  }
  return dp[idx][lim] = ret;
}

int main() {
  memset(dp, -1, sizeof(dp));
  cin >> S;
  cout << rec(0, 0) << endl;
}


Measured memory_bytes: 256
use std::collections::HashMap;
#[derive(Default)]
//NOTE
//declare variables to reduce the number of parameters for dp and dfs etc.
struct Solver {}

impl Solver {
    fn solve(&mut self) {
        let stdin = std::io::stdin();
        let mut scn = Scanner {
            stdin: stdin.lock(),
        };
        let n: usize = scn.read();
        let mut f = vec![1_usize; n + 1];
        for p in 2..=n {
            let mut x = 1;
            while p * x <= n {
                f[p * x] += 1;
                x += 1;
            }
        }
        let result = {
            let mut tmp = 0;
            for x in f.iter().enumerate() {
                tmp += x.0 * x.1
            }
            tmp
        };

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

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| {
            let mut solver = Solver::default();
            solver.solve()
        })
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 79268
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
vector<P>edge[100005];
int cnt[100005];
int num[16],ret;
int dp[(1<<16)];
bool ok[(1<<16)];
int main(){
	cin>>n;
	rep(i,n-1){
		int a,b,c;cin>>a>>b>>c;
		edge[a].pb(mp(b,c));
		edge[b].pb(mp(a,c));
	}
	rep(i,n){
		rep(j,edge[i].size()){
			cnt[i] ^= edge[i][j].sc;
		}
		if(cnt[i]){
			num[cnt[i]]++;
			ret++;
		}
	}
	int mask = 0;
	for(int i=1;i<16;i++){
		ret -= num[i]/2;
		num[i]%=2;
		if(num[i] == 1) mask |= (1<<i);
	}
	dp[0] = 0;
	rep(i,(1<<16)){
		int v = 0;
		rep(j,16) if(((i>>j)&1)) v ^= j;
		if(!v) ok[i] = 1;
	}
	for(int i=1;i<(1<<16);i++){
		int x = i;
		do{
			x = (x-1)&i;
			if(ok[x]){
				dp[i] = max(dp[i],dp[x]+dp[i-x]);
			}
		}while(x);
		dp[i] = max(dp[i],1);
	}
	ret -= dp[mask];
	cout << ret << endl;
}

Measured memory_bytes: 7156
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

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

  ll ans = a;
  if (k < a)
  {
      ans = k;
  }
  if (a+b < k)
  {
      /* code */
      ans -= (k - a - b);
  }
  
//   if (k-a-b >= 0 && c != 0) ans -= (k-a-b); //ans -= (k - a - b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] l = new int[n];
        int sum = 0, cnt = 1;

        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
            sum += l[i];
            if (sum <= x) {
                cnt++;
            }
        }

        System.out.println(cnt);

		sc.close();
	}
}


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

int a,b,c;
vector<int> v;

int main() {
	// your code goes here
	cin>>a>>b>>c;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(),v.end());
	cout<<v[0]+v[1]<<endl;
	return 0;
}

Measured memory_bytes: 256
/*
 * Author: FreePascal
 * Created Time:  2011-8-24 13:03:51
 * File Name: b.cpp
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

const int maxn = 25 + 10;
int n,total;
bool visit[maxn],flag;
struct node{
    int num,w;
}a[maxn];

void dfs(int k,int sum){
    if (flag) return;
    if (sum == total) {
        flag = true;
        return;
    }
    for (int i = 1; i <= n; i++)
        if (!visit[i] && sum + a[i].num <= a[i].w){
            visit[i] = true;
            dfs(i,sum + a[i].num);
            visit[i] = false;
        }
}
bool cmp(node a,node b){
    //return a.num < b.num || a.num == b.num && a.w - a.num < b.w - b.num;
    return a.w < b.w || a.w == b.w && a.num < b.num;
}

int main() {
    while (scanf("%d",&n) != EOF){
        if (n == 0) break;
        for (int i = 1; i <= n; i++) scanf("%d%d",&a[i].num,&a[i].w);
        sort(a + 1,a + n + 1,cmp);
        flag = true;
        for (int i = 1; i <= n; i++)
            if (a[i].num > a[i].w) flag = false;
        /*
        memset(visit,0,sizeof(visit));
        if (flag){
            total = 0;
            for (int i = 1; i <= n; i++) total += a[i].num;
            flag = false;
            dfs(0,0);
        }
        */
        if (flag){
            int sum = 0;
            //flag = true;
            for (int i = 1; i <= n; i++)
                if (sum + a[i].num <= a[i].w) sum += a[i].num;
                else {flag = false; break;}
        }
        if (flag) puts("Yes");
        else puts("No");
    }
    return 0;
}

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

void rev_string(char s[], char t[]){
  //char j[101];
  int i;
  int sum;
  for(i = 0; s[i] != '\0'; i++){
    t[i] = s[i];
    sum++;
  }
  for(i = 0; i <sum; i++){
    s[i] = t[sum - i -1];
  }
}
int main(){
  char s[101];
  char t[101];
  int i , sum= 0;
  scanf("%s", s);
  
  rev_string(s, t);
  for(i = 0; s[i] != '\0'; i++){
    if(s[i] != t[i]){
      sum++;
    }
  }
  printf("%d", sum/2);
  return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
string S,T;
deque<char> d,d2;

signed main(){
	cin>>N>>S>>T;
	REP(i,N){
		d.push_back(S[i]);
		d2.push_back(T[i]);
	}
	int ans=0;
	while(d.size()){
		if(d==d2){
			ans+=d.size();
			break;
		}
		else{
			d.pop_front();
			d2.pop_back();
			ans+=2;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define allr(v)	     ((v).rbegin()), ((v).rend())
#define sz(v) ((int)(v).size())
#define clr(v, d)        memset(v, d, sizeof(v))
#define JSE ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MP(i,j) make_pair(int i,int j);
typedef long long ll;
typedef unsigned long long ull;
typedef  double ld;
const ll OO = (ll)1e18;
const ll mod = (1e9) + 7;
const double PI = acos(-1.0);
int dx[]{ 0,0,1,-1 ,-1,-1,1,1};
int dy[]{ -1, 1,0,0,-1,1,1,-1};
ld dis(pair<ld, ld>a, pair<ld, ld>b) { return sqrt(pow(a.first - b.first, 2) + pow(a.second - b.second, 2)); }
ll pd(ll x) { if (x == 0)	return 1; if (x == 1) return 1; ull ans = 1; for (int i = 2; i <= x; i++) ans *= i; return ans; }
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);  
#endif
}
template<class Int>
Int gcd(Int a, Int b)
{
	return (b == 0 ? abs(a) : gcd(b, a%b));
}
template<class Int>
Int lcm(Int a, Int b)
{
	return abs(a / gcd(a, b)*b);
}
int main()
{
	//cout << setprecision(20) << fixed;
	JSE
		//file();
		//	freopen("friday.in", "r", stdin);
		///////////
		ll n;
	cin >> n;
	cout << lcm(n, 2LL) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;
bool comp(pair<lpair, ll> p1, pair<lpair, ll> p2){
    if(p1.first.first == p2.first.first){
        return (p1.first.second < p2.first.second);
    }
    return p1.first.first < p2.first.first;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    ll P[100010], Y[100010];
    cin >> N >> M;
    rep(i,0,M){
        cin >> P[i] >> Y[i];
    }
    vector< pair<lpair, ll> > lp;
    rep(i,0,M){
        lp.push_back(make_pair(make_pair(P[i], Y[i]), i));
    }
    sort(lp.begin(), lp.end(), comp);
    vector< pair<string, string> > ans(100010);
    ll rank = 0;
    ll prev_pref = lp[0].first.first;
    rep(i,0,M){
        ll n = lp[i].second;
        ll pre_num = lp[i].first.first;
        if(pre_num == prev_pref){
            rank++;
        }else{
            rank = 1;
        }
        prev_pref = pre_num;
        ll keta = to_string(pre_num).size();
        ll zero_num = 6 - keta;
        ans[n].first = string(zero_num, '0') + to_string(pre_num);
        ll keta2 = to_string(rank).size();
        ll zero_num2 = 6 - keta2;
        ans[n].second = string(zero_num2, '0') + to_string(rank);
    }
    rep(i,0,M){
        cout << ans[i].first << ans[i].second << endl;
    }
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
char a[605][605];

int solve(int ii, int jj) {
    int res = 0;
    int cnt = 0;
    for (int i = ii, j = jj; i < n && j < n; ++i, ++j) {
        if (i == ii) {
            forn(p, n) forn(q, n) {
                cnt += a[i + p][j + q] == a[i + q][j + p];
            }
        } else {
            int p = n - 1;
            ++cnt;
            forn(q, n - 1) {
                cnt += 2 * (a[i + p][j + q] == a[i + q][j + p]);
            }
        }

        if (cnt == n * n) {
            ++res;
        }

        --cnt;
        int p = 0;
        for (int q = 1; q < n; ++q) {
            cnt -= 2 * (a[i + p][j + q] == a[i + q][j + p]);
        }
    }
    return res;
}

int main() {
    scanf("%d", &n);
    forn(i, n) {
        scanf("%s", a[i]);
        forn(j, n) {
            a[i + n][j] = a[i][j];
            a[i][j + n] = a[i][j];
            a[i + n][j + n] = a[i][j];
        }
    }
    int ans = 0;
    forn(i, n) {
        ans += solve(0, i);
    }
    for (int i = 1; i < n; ++i) {
        ans += solve(i, 0);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
class Node:
    def __init__(self, node, left, right):
        self.node = node
        self.left = left
        self.right = right
        self.parent = -1
        self.sibling = -1
        self.degree = 0
        self.depth = 0
        self.height = 0
        self.type = ""

    def __str__(self):
        if self.parent == -1:
            self.type = "root"
        elif self.degree == 0:
            self.type = "leaf"
        else:
            self.type = "internal node"
        return "node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(
            self.node, self.parent, self.sibling, self.degree, self.depth, self.height, self.type)


def dfs(tree, v, p, d, s):
    tree[v].parent = p
    tree[v].depth = d
    tree[v].sibling = s
    if tree[v].left == tree[v].right:
        tree[v].height = 0
        return 0
    maxheight = 0
    if tree[v].left != -1:
        tree[v].degree += 1
        maxheight = max(
            maxheight, dfs(
                tree, tree[v].left, v, d + 1, tree[v].right))
    if tree[v].right != -1:
        tree[v].degree += 1
        maxheight = max(
            maxheight, dfs(
                tree, tree[v].right, v, d + 1, tree[v].left))
    tree[v].height = maxheight + 1
    return tree[v].height


def resolve():
    n = int(input())
    tree = [None for i in range(n)]
    V = [list(map(int, input().split())) for _ in range(n)]
    hasChild = set()
    childrens = set()
    for a, left, right in V:
        tree[a] = Node(a, left, right)
        if left != right:
            hasChild.add(a)
            childrens.add(left)
            childrens.add(right)
    root = hasChild - childrens
    if len(root) > 0:
        dfs(tree, root.pop(), -1, 0, -1)
    print(*tree, sep="\n")


resolve()



Measured memory_bytes: 5624
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int i = 0;
                while (true) {
                        int N = sc.nextInt();
                        if (N == 0) {
                                break;
                        }
                        System.out.println("Case "+ ++i + ": " + N);
                }
        }
}

Measured memory_bytes: 44692
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll a,b,c;cin>>a>>b>>c;
    map<int,int>m;
    m[a]++;
    m[b]++;
    m[c]++;
    if(m[a]==1)
        cout<<a;
    else if(m[b]==1)
        cout<<b;
    else
        cout<<c;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






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

int main()
{
	long long a,b,c,d;
  	cin>>a>>b>>c>>d;
  	while(a>0 && c>0)
    {
      	c-=b;
      	if(c<=0)
        {
          cout<<"Yes\n";
          return 0;
        }
 		a-=d;
      	if(a<=0)
        {
          cout<<"No\n";
          return 0;
        }
    }  
return 0;  
}  


Measured memory_bytes: 3584
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char a[100][100];
int b[100][100];
void my(int i,int j)
{
    if(b[i][j]==-1)
        return ;
    b[i][j]++;
}
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        memset(b,0,sizeof(b));
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            cin>>a[i][j];
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            {
                if(a[i][j]=='#')
                {
                    b[i][j]=-1;
                    my(i-1,j);
                    my(i+1,j);
                    my(i,j-1);
                    my(i,j+1);
                    my(i-1,j-1);
                    my(i-1,j+1);
                    my(i+1,j-1);
                    my(i+1,j+1);
                }
            }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(b[i][j]==-1)
                cout<<'#';
                else
                cout<<b[i][j];
            }
            cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i;
    cin >> n;
    vll a(n + 1), b(n + 1, 0), c;
    for(i = 1; i <= n; i++)
        cin >> a[i];
    for(i = n; i >= 1; i--)
    {
        ll sum = 0;
        for(ll j = 2 * i; j <= n; j += i)
            sum += b[j];
        if(sum % 2 != a[i])
            c.pb(i), b[i] = 1;
    }
    cout << c.size() << endl;
    for(auto x : c)
        cout << x << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 5108
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			int x=Integer.parseInt(in.next()),y=Integer.parseInt(in.next());
			if(x==0 && y==0)break;
			
			if(x<y)out.printf("%d %d\n",x,y);
			else out.printf("%d %d\n", y,x);
		}
		out.flush();
	}

}



Measured memory_bytes: 39132
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
template <class T1, class T2>
void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long N, long long M, std::vector<long long> A)
{
  int cnt = 0;
  lli sum = 0;
  rep(i, N) sum += A[i];
  rep(i, N)
  {
    if (A[i] * 4 * M >= sum)
      cnt++;
  }
  YesNo(cnt >= M);
}

signed main()
{
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &A[i]);
  }
  solve(N, M, std::move(A));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2>
void vadd(vector<T1> &v, T2 x)
{
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 256
s = list(input())
N = len(s)
s.append("x")

L = []
i = 0
l = []
while i < N:
	if s[i] == "A":
		l.append("a")
		i += 1
	elif s[i] == "B" and s[i + 1] == "C":
		l.append("b")
		i += 2
	else:
		if l != []:
			L.append(l)
		l = []
		i += 1

if l != []:
	L.append(l)

n = len(L)
ans = 0

for i in range(n):
	bcnt = 0
	bshift = 0
	nn = len(L[i])
	for j in range(nn):
		if L[i][j] == "b":
			bcnt += 1
			bshift += j
	ans += bshift - int(bcnt * (bcnt - 1) // 2)

print(ans)

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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int l=a+b;
    int r=c+d;
    if(l==r)
        cout<<"Balanced"<<endl;
    else if(l>r)
        cout<<"Left\n";
    else if(l<r)
        cout<<"Right\n";
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    cin >> n;
    vi v(n);
    REP(i,n) {
        cin >> v[i];
    }
    reverse(ALL(v));
    ll ma = 2, mi = 2;
    for (auto x:v){
        mi = (mi + x - 1) / x * x;
        ma = ma / x * x;
        if(mi>ma){
            cout << -1 << endl;
            return 0;
        }
        ma = ma + x - 1;
    }
    cout << mi << " " << ma << endl;
}

Measured memory_bytes: 1024
def modpow(a, n, m)
  return 1 if n == 0

  tmp = modpow(a, n / 2, m)
  n % 2 == 0 ? tmp * tmp % m : tmp * tmp * a % m
end

def modinv(a, m)
  modpow(a, m - 2, m)
end

M = (1e9+7).to_i

n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

h = {}
y = nil
(0..n).each do |i|
  if h[a[i]]
    y = i - h[a[i]] - 1
    break
  else
    h[a[i]] = i
  end
end

fa = (1..(n + 1)).inject([1]) { |acc, i| acc << acc[-1] * i % M; acc }
fi = fa.map { |f| modinv(f, M) }

(1..(n + 1)).each do |k|
  answer = fa[n + 1] * fi[k] * fi[n + 1 - k] % M
  if n + 1 - y >= k
    answer -= fa[n + 1 - y] * fi[k] * fi[n + 1 - y - k] % M
  end
  if n - 1 - y >= k
    answer += fa[n - 1 - y] * fi[k] * fi[n - 1 - y - k] % M
  end
  if n - 1 - y >= k - 1
    answer += fa[n - 1 - y] * fi[k - 1] * fi[n - y - k] % M
  end
  if n - 1 - y >= k - 2 && k >= 2
    answer += fa[n - 1 - y] * fi[k - 2] * fi[n + 1 - y - k] % M
  end
  puts answer % M
end


Measured memory_bytes: 25876
N, M = map(int, input().split())
a = [int(input()) for i in range(M)]
ans = 1
pos = 0


def fibonacci(N):
    prev = []
    for i in range(1, N+1):
        if i == 1 or i == 2:
            prev.append(1)
        else:
            prev.append(prev[-2] + prev[-1])
    return(prev[-1])


a.append(N + 1)

for i in range(M+1):
    dis = a[i] - pos
    if dis == 0:
        ans = 0
        break
    ans *= fibonacci(dis)
    pos = a[i]+1
print(ans % ((10**9)+7))


Measured memory_bytes: 460020
#include<stdio.h>
char c[5];
int main(){
  int n,m,a;
  char b;

  scanf("%d%d",&n,&m);
  for (int i = 0; i < m; i++)
  {
    scanf("%d %c", &a,&b);

    if(n != 1 && a == 1 && b=='0' ){
      printf("-1\n");
      return 0;
    }
    if(c[a-1] == 0 )
      c[a-1]=b;
    else if( c[a-1] != b ){
      printf("-1\n");
      return 0;
    }
  }
  for (int i = 0; i < n; i++){
    if (i==0 && c[0]== 0 && n>1)
      c[0]='1';
    else if (c[i]==0)
      c[i]='0';
    }

  printf("%s\n", c);
  return 0;
}


Measured memory_bytes: 128
from itertools import combinations
import math

n = int(input())

towns = []

for _ in range(n):
    array = list(map(int, input().split()))
    towns.append(array)


distances = [[0 for _ in range(n)] for _ in range(n)]

town_num = list(range(n))

for i, j in combinations(town_num, 2):
    distance = ((towns[j][0] - towns[i][0])**2 + (towns[j][1] - towns[i][1])**2)**(0.5)
    distances[i][j] = distance
    distances[j][i] = distance

total_way = math.factorial(n)

total = 0

for i in range(n):
    for j in range(n):
        total += distances[i][j] * math.factorial(n-1)

print(total/total_way)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int read()
{
    int f=1,x=0;
    char ss=getchar();
    while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
    while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
    return f*x;
}
int main()
{
   int a=read(),b=read(),c=read();
   if(a==b&&a==c&&b==c)
   {cout<<"1"<<endl;return 0;}
   if(a==b||a==c||b==c){cout<<"2"<<endl;return 0;}
   else cout<<"3"<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    string str;
    cin >> str;
    int q;
    cin >> q;
    
    for(int i=0;i<q;i++){
        string word;
        cin >> word;
        int a,b,plen;
        cin >> a >> b;
        plen = b-a+1;

        if(word == "print"){
            cout << str.substr(a,plen) << endl;
            //cout << "str[" << str << "] print[" << str.substr(a,plen) << "]" << endl;
        }else if(word == "reverse"){
            string buf = str;
            for(int j=0;j<plen;j++){
                str[a+j]=buf[b-j];
            }
            //cout << "str[" << str << "] reversefrom[" << buf << "]" << endl;
        }else if (word == "replace"){
            string p;
            cin >> p;
            for(int j=0;j<plen;j++){
                str[a+j]=p[j];
            }
            //cout << "str[" << str << "] replaceword[" << p << "]" << endl;
        }
    }
}

Measured memory_bytes: 1220
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

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

	//b棟f階のr番目の部屋にv人が追加で入居した
	vector< vector< vector<int> > > building(4,vector< vector<int> >(3,vector<int>(10)));
	
	for (int i = 0; i < n; i++)
	{
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		b--; f--; r--;
		building[b][f][r] += v;
	}

	for (int i = 0; i < 4; i++)//棟
	{
		for (int j = 0; j < 3; j++)//階
		{
			for (int k = 0; k < 10; k++)//部屋番号
			{
				printf(" %d", building[i][j][k]);
			}
			printf("\n");
		}
		if (i < 3)
		{
			printf("####################\n");
		}
	}

	return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int>A(N + 2);
	A[0] = 0;
	A[N + 1] = 0;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		A[i + 1] = a;
	}
	int ans = 0;
	for (int i = 0; i < N + 1; ++i) {
		ans += abs(A[i + 1] - A[i]);
	}
	for (int i = 0; i < N; ++i) {
		cout << ans + abs(A[i + 2] - A[i]) - abs(A[i + 1] - A[i]) - abs(A[i + 2] - A[i + 1]) << endl;
	}
	return 0;
}


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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//printfを使うときは上を削除
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	


ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}
//宣言だけしとく
int N,M,H,W,K,A,B;
string S;
//ここから書き始める

int main()
{
	cout << setprecision(10);
		
	int h , w , k;
	cin >> h >> w >> k;
	rep(i,h+1){//h行、w列
		rep(j,w+1){
			//まず、h行のうち一個も押さない（i = 0)
			int black = 0 ;
			black += (w-j) * i ;
			black += (h-i) * j ;
			if(black == k ){
				coY();
				return 0;
			}
		}
	}
	coN();
	
}


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

int main()
{
	int H = 0, W = 0, count = 0, a[10000] = { 0 };
	while (1){
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		a[count] = H, a[++count] = W;
		count++;
	}
	int i = 0;
	while (i < count){
		for (int j = 0; j < a[i]; j++){
			for (int k = 0; k < a[i + 1]; k++){
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
		i += 2;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
#include <ostream>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cmath>
#include <cstring>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using ll = long long;

template <typename T, typename U>
std::ostream &operator<<(std::ostream &out, std::pair<T, U> p)
{
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T>
std::ostream &operator<<(std::ostream &out, std::vector<T> v)
{
  out << "[";
  for (int i = 0; i < v.size(); ++i)
  {
    out << v[i] << (i == (v.size() - 1) ? "" : ", ");
  }
  out << "]";
  return out;
}

int n;
std::vector<int> a;
ll f_gcd[100001], b_gcd[100001];

ll gcd(ll x, ll y)
{
  if (y > x)
  {
    std::swap(x, y);
  }

  ll tmp = 0;
  while (y != 0)
  {
    tmp = x % y;
    x = y;
    y = tmp;
  }

  return x;
}

int main()
{
  cin >> n;
  a.resize(n);

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

  f_gcd[0] = a[0];
  b_gcd[n - 1] = a[n - 1];

  for (int i = 1; i < n; ++i)
  {
    f_gcd[i] = gcd(f_gcd[i - 1], a[i]);
  }
  for (int i = n - 2; i >= 0; i--)
  {
    b_gcd[i] = gcd(b_gcd[i + 1], a[i]);
  }

  ll ans = -int(1e9);

  for (int i = 0; i < n; ++i)
  {
    if (i == 0)
    {
      ans = std::max(ans, b_gcd[i + 1]);
    }
    else if (i == n - 1)
    {
      ans = std::max(ans, f_gcd[i - 1]);
    }
    else
    {
      ans = std::max(ans, gcd(f_gcd[i - 1], b_gcd[i + 1]));
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
using namespace std;

long double maxim[3]={-1,-1,-1},flame[3];
long double dist(long double x,long double y){
	return sqrt(x*x+y*y);
}
int main(){
	int N;
	cin >> N;
	int t[100];
	long double f[100],a[100],x[100],y[100];
	cin >> f[0] >> a[0] >> t[0] >> x[0] >> y[0];
	FOR(i,1,N){
		cin >> f[i] >> a[i] >> t[i] >> x[i] >> y[i];
		if(t[i]==t[i-1] && a[i]!=a[i-1]){
			if(maxim[t[i]]<dist(x[i]-x[i-1],y[i]-y[i-1]) || (maxim[t[i]]==dist(x[i]-x[i-1],y[i]-y[i-1]) && f[i]-f[i-1]<flame[t[i]] )){
				maxim[t[i]]=dist(x[i]-x[i-1],y[i]-y[i-1]);
				flame[t[i]]=f[i]-f[i-1];
			}
		}
	}
	REP(i,2)
		if(maxim[i]==-1)
			cout << -1 << " " << -1 << endl;
		else
		printf("%llf %llf\n",maxim[i],flame[i]/60.0);
}

Measured memory_bytes: 1296
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>


#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

vector<int> graph[100010];

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int a,b;
    
    rep(i,m){
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

int ans = 0;
bool f = false;

    rep(i,n){
        f = false;
        rep(j,graph[i].size()){
            if(h[i] <= h[graph[i][j]]){
                f = true;
                break;
            }
        }
        if(!f){
            ans++;
        }
    }    
    cout << ans << endl;

    return 0;
}

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

#define FOR(i, s, e)   for(int i = (s); i < (e); i++)
#define FOR64(i, s, e) for(ll  i = (s); i < (e); i++)
#define ALL(x)         (x).begin(), (x).end()
#define SORT(b, e)     sort((b), (e))
#define REV(b, e)      reverse((b), (e))
#define VSORT(v)       sort((v).begin(), (v).end())
#define VREV(v)        reverse((v).begin(), (v).end())
#define pb(a)          push_back(a)
#define INF            999999999

typedef long long ll;

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

	int T, A;
	cin >> T >> A;

	vector<int> H(N);
	for(int &h : H) cin >> h;

	auto it = min_element(ALL(H), [A, T](int x, int y){
		return abs((T - 0.006 * x) - A) < abs((T - 0.006 * y) - A);
	});

	int n = (it - H.begin()) + 1;

	cout << n << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, m;
  cin >> n >> m;
  vll a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  sort(all(a));
  reverse(all(a));
  ll sum = 0;
  for (ll i = 0; i < n; i++) sum += a[i];
  for (ll i = 0; i < m; i++) {
    if (a[i] < sum / (4.0 * m)) {
      No();
      return 0;
    }
  }
  Yes();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll k, l, r, ans;
ll a[200010], f[200010];
bool cmp(int x, int y) {
	return x > y;
}
bool check(ll x) {
	ll kk = k;
	for(int i = 1; i <= n; i ++) {
		ll res = x / f[i];
		if(a[i] >= res) kk -= a[i] - res;
	}
	return kk >= 0;
}
int main() {
	scanf("%d%lld", &n, &k);
	for(int i = 1; i <= n; i ++) scanf("%d", &a[i]);
	for(int i = 1; i <= n; i ++) scanf("%d", &f[i]);
	sort(a + 1, a + n + 1), sort(f + 1, f + n + 1, cmp);
	for(int i = 1; i <= n; i ++) {
		r = max(r, a[i] * f[i]);
	}
	l = 0;
	while(l <= r) {
		ll mid = l + r >> 1;
		if(check(mid)) {
			ans = mid, r = mid - 1;
		} else l = mid + 1;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m,now=0;
	string ic[257]={""},out,log[3]={"Opened by ","Closed by ","Unknown "};
	for(cin>>n;n>0;n--)cin>>ic[n];
	for(cin>>m;m>0;m--){
		bool kawa=0;
		cin>>out;
		for(int j=255;j>0&&!kawa;j--)if(ic[j]==out)kawa=1;
		if(kawa)cout<<log[now]+out<<endl;
		else cout<<log[2]+out<<endl;
		now=(now+kawa)%2;
	}
}

Measured memory_bytes: 1224
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n;
	cin >> n;
	map<int, int> mp;
	REP(i, n)
	{
		int a;
		cin >> a;
		if (mp.count(a) < 0)
			mp[a]++;
		else if (mp[a] < 1)
			mp[a]++;
		else
			mp[a]--;
	}
	int ans = 0;
	REPIT(mp)
	{
		if ((*it).second > 0)
			ans++;
	}
	print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 4992