akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);

const double PI  = acos(-1.0);
using namespace std;
//typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 100000 + 9;
int n,m,mem[3009][3009];
string s,t;

int dp(int i, int j)
{
    if(i==n || j== m) return 0;
    if(mem[i][j] != -1) return mem[i][j];

    if(s[i] == t[j]) return mem[i][j] = 1 + dp(i+1, j+1);
    int c1 = dp(i+1, j);
    int c2 = dp(i, j+1);
    return mem[i][j] = max(c1,c2);
}

void build(int i, int j)
{
    if(i==n || j== m) return ;

    if(s[i] == t[j])
    {
        cout<<s[i];
        build(i+1, j+1);
    }
    else
    {
        int c1 = dp(i+1, j);
        int c2 = dp(i, j+1);

        if(dp(i, j) == c1) build(i+1, j);
        else build(i, j+1);
    }
}

 int main()
{
//freopen("calc.in","r",stdin);
//freopen("calc.out","w",stdout);
//__builtin_popcount()
input
        cin>>s>>t;
        n = s.size();
        m = t.size();

        memset(mem,-1,sizeof mem);
        dp(0, 0);

        build(0, 0);





return 0;
}


Measured memory_bytes: 39280
#include<iostream>
#define MOD 1000000007
using namespace std;
long long int A(long long int a){
	long long int ans=1;
	for(long long int i=a;i>=1;i--){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int main(){
	long long int m,n;
	cin>>m>>n;
	if(n>m){
		int temp=n;
		n=m;
		m=temp;
	}
	if((m-n)>=2){
		cout<<0<<endl;
	}else if((m-n)==1){
		cout<<(A(m)*A(n))%MOD<<endl;
	}else{
		long long int ans=(A(m)*A(n))%MOD;
		ans*=2;
		cout<<ans%MOD<<endl;
	}
	return 0;
}

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

ll XOR_cum(ll X){
    ll res = X;
    if(X % 4 == 0)res = X;
    if(X % 4 == 1)res = 1;
    if(X % 4 == 2)res = X + 1;
    if(X % 4 == 3)res = 0;
    return res;
}
    
int main() {
    ll A,B;
    cin>>A>>B;
    ll ans = XOR_cum(B)^XOR_cum(max(0LL,A-1));
    cout<<ans<<endl;
}


Measured memory_bytes: 256
while True:
    w = int(input())
    if w == -1:
        break
    ans = 1150
    w = max(w-10,0)
    ans += min(w,10)*125
    w = max(w-10,0)
    ans += min(w,10)*140
    w = max(w-10,0)
    ans += w*160
    print(4280-ans)



Measured memory_bytes: 5588
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        var x = vars[0];
        var n = vars[1];
        if (n == 0)
        {
            System.Console.ReadLine();
            Console.WriteLine(x);
            return;
        }
        var p = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        
        var ans = Enumerable.Range(1, 100).Where(v => !p.Contains(v)).ToList();
        ans.Add(0);
        ans.Add(101);
        ans = ans.OrderByDescending(v => v).ToList();


        var sa = int.MaxValue;
        var kotae = -1;
        foreach(var v in ans)
        {
            if(Math.Abs(v - x) <= sa)
            {
                kotae = v;
                sa = (int)Math.Abs(v - x);
            }
        }

        Console.WriteLine(kotae);

    }
}

Measured memory_bytes: 28404
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
int r;
//int m,n;
//int i,j,k,l;
//int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
//char a[101],b[101],s[101],t[101],u[101];
int main(void){
    scanf("%d",&r);
    printf("%f",2*r*M_PI);
    return 0;
}

Measured memory_bytes: 1748
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var l = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var h = l[0]; var w = l[1];
        var pxl = new List<List<Char>>();
        var fpx = new List<Char>();
        for (var j = 0; w + 2 > j; j++)
        {
            fpx.Add('#');
        }
        pxl.Add(fpx);

        for (var i = 0; h > i; i++)
        {
            var px = Console.ReadLine().ToCharArray().ToList();
            px.Add('#');
            px.Insert(0, '#');
            pxl.Add(px);
        }
        pxl.Add(fpx);

        for (var i = 0; h + 2 > i; i++)
        {
            Console.WriteLine(new String(pxl[i].ToArray()));
        }
    }
}

Measured memory_bytes: 13396
n = int(input())
red = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:-x[1])
blue = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for b in blue:
    for i, r in enumerate(red):
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            del red[i]
            break
print(ans)


Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var a = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
        var n = (int)nk[0];
        var k = nk[1];
        int[] count = Enumerable.Repeat(-1, n).ToArray();
        int cur = 0;
        count[cur] = 0;
        while (true)
        {
            if (count[a[cur]] != -1)
            {
                var period = (count[cur] + 1) - count[a[cur]];
                k = (k - count[a[cur]]) % period + count[a[cur]];
                Console.WriteLine(count.TakeWhile(x => x != k).Count() + 1);
                return;
            }
            count[a[cur]] = count[cur] + 1;
            cur = a[cur];
            if (count[cur] == k)
            {
                Console.WriteLine(cur + 1);
                return;
            }
        }
    }
}


Measured memory_bytes: 43712
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n;
    cin >> n;
    cout << pow(n, 3) << endl;
}

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

int main()
{
    string x,y;
    cin>>x>>y;
    ll n=x.size(),m=y.size();
    ll dp[n+1][m+1];
    string s;
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=m;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
                continue;
            }
            if(x[i-1]==y[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    ll k=dp[n][m];
    ll i=n,j=m;
    while(i>0 && j>0 && k>0)
    {
        if(x[i-1]==y[j-1])
        {
            s.push_back(x[i-1]);
            i--;
            j--;
            k--;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
                i--;
            else
                j--;
        }
    }
    reverse(s.begin(),s.end());
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 70656
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            int sum[] = { 0, 0 };
            while (n-- > 0) {
                int a = sc.nextInt();
                int b = sc.nextInt();
                if (a == b) {
                    sum[0] += a;
                    sum[1] += b;
                } else {
                    sum[a > b ? 0 : 1] += a + b;
                }
            }
            System.out.println(sum[0] + " " + sum[1]);
        }
    }
}



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

int main() {
	int X, Y;
	long long int recy = 0;
	long long int recx = 0;
	cin >> X >> Y;
	int ans = 0;
	if ((2 * X - Y) % 3 == 0 && (2 * Y - X) % 3 == 0 && 2 * Y - X >= 0 && 2 * X - Y >= 0) {
		recx = (2 * X - Y) / 3;
		recy = (2 * Y - X) / 3;
		long long int mod = 1000000007;
		long long int bunshi = 1;
		for (int i = recx + 1; i <= (recx + recy); i++) {
			bunshi = bunshi * i % mod;
		}
		long long int bunbo = 1;
		for (int i = 1; i <= recy; i++) {
			bunbo = bunbo * i % mod;
		}
		long long int  gen = 1;
		long long int n = mod - 2;
		while (n > 0) {
			if (n & 1) gen = gen * bunbo % mod;
			bunbo = bunbo * bunbo % mod;
			n >>= 1;
		}
		ans = gen * bunshi % mod;
	}
	cout << ans << endl;

	return 0;
}

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

int mm[100004];
signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif    

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

    if((n-cnt)%2==0)
    {           
        cout<<cnt;
    }
    else
    {
        cout<<cnt-1;
    }
    
}

Measured memory_bytes: 5148
import scala.io.{StdIn => in}

object Main extends App {
  val Array(r, d, x) = in.readLine.split(" ").map(_.toLong)

  val ans = (1 to 10).scanLeft(x) { (pre, _) =>
    r * pre - d
  }.tail
  println(ans.mkString("\n"))
}

Measured memory_bytes: 25556
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

vector<ll> enum_div(ll n){
    vector<ll> ret;
    for(ll i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

int main(void) {
    ll n;
    cin>>n;
    vll v=enum_div(n);
    ll ans=INF;
    rep(i,v.size()){
        ll a=floor(log10(v[i]))+1;
        ll b=floor(log10(n/v[i]))+1;
        // cout<<v[i]<<' '<<a<<" "<<b<<endl;
        ans=min(ans,max(a,b));
    }
    fin(ans);
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int N, M;
long long ans;
vector<vector<int>> G;
void dfs(int s, vector<bool> &isVisited, int cnt){
    if(cnt == N){
        ans++;
        return;
    }
    isVisited[s] = true;
    for(auto t : G[s]){
        if(isVisited[t]) continue;
        isVisited[t] = true;
        dfs(t, isVisited, cnt + 1);
        isVisited[t] = false;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    G.resize(N);
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<bool> isVisited(N);
    isVisited[0] = true;
    dfs(0, isVisited, 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def warshallFloyd():
	for k in range(n):
		for i in range(n):
			if A[i][k] == INF:
				continue
			for j in range(n):
				if A[k][j] == INF:
					continue
				A[i][j] = min(A[i][j], A[i][k] + A[k][j])

INF = 2 * 10**9 + 89

if __name__ == "__main__":
	n, m = map(int, input().split())
	A = [[INF for _ in range(n)] for _ in range(n)]
	for i in range(n):
		A[i][i] = 0
	
	for _ in range(m):
		s, t, d = map(int, input().split())
		A[s][t] = d

	warshallFloyd()

	negative = False
	for i in range(n):
		if A[i][i] < 0:
			negative = True

	if negative:
		print("NEGATIVE CYCLE")
	else:
		for i in range(n):
			for j in range(n):
				if A[i][j] == INF:
					A[i][j] = "INF"
		for i in range(n):
			print(*A[i])


Measured memory_bytes: 6284
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

constexpr int INF = 1e9;

struct edge {
    int to, cost, num;
};

using edges = vector<edge>;
using graph = vector<edges>;

struct state {
    int v, rest, num;
    bool operator>(state const& other) const {
        return num > other.num;
    }
};

int main() {
    int N, M, L;
    while(cin >> N >> M >> L, N) {
        graph g(N);
        vector<vector<int>> res(N, vector<int>(L+1, INF));
        for(int i=0; i<M; ++i) {
            int a, b, d, e;
            cin >> a >> b >> d >> e;
            a--; b--;
            g[a].push_back((edge){b, d, e});
            g[b].push_back((edge){a, d, e});
        }
        priority_queue<state, vector<state>, greater<state>> que;
        que.push(state{0, L, 0});
        res[0][L] = 0;
        while(!que.empty()) {
            state s = que.top(); que.pop();
            int v = s.v;
            int rest = s.rest;
            if(res[v][rest] < s.num) {
                continue;
            }
            for(auto& e : g[v]) {
                if(rest - e.cost >= 0 && res[e.to][rest - e.cost] > res[v][rest]) {
                    res[e.to][rest - e.cost] = res[v][rest];
                    que.push(state{e.to, rest-e.cost, res[e.to][rest-e.cost]});
                }
                if(res[e.to][rest] > res[v][rest] + e.num) {
                    res[e.to][rest] = res[v][rest] + e.num;
                    que.push(state{e.to, rest, res[e.to][rest]});
                }
            }
        }
        cout << *min_element(res[N-1].begin(), res[N-1].end()) << endl;
    }
}


Measured memory_bytes: 3420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
}


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

int main() {
  ll n,k,ans;
  cin >> n >> k;
  ans = k;
  rep(i,n-1) ans *= k-1;
  cout << ans << endl;
}

Measured memory_bytes: 256
N=input()
h=list(map(int,input().split()))
ans=0
def solve(ar):
    global ans
    if(sum(ar)==0):
        return
    if(0 in ar):
        i=ar.index(0)
        if(i-1>=0):
            solve(ar[:i])
        solve(ar[i+1:])
        return 
    s=True
    while(s):
        ans+=1
        for i in range(len(ar)):
            ar[i]=ar[i]-1
            if(ar[i]<=0):
                s=False
    solve(ar)

solve(h)
print(ans)

Measured memory_bytes: 3064
#include<string>
#include<iostream>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
int M;
cin>>M;
int res=24-M+24;
cout<<res;
system ("pause");
return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
	int num, i, a, ans = 1;
	cin >> num;
	vector<int> d(num + 1);
	for (i = 1; i <= num; i++) {
		scanf("%d", &a);
		d[a] = i;
	}
	for (a = 1, i = 1; i < num; i++) {
		if (d[i] < d[i + 1]) {
			a++;
			ans = max(a, ans);
		}
		else
			a = 1;
	}
	cout << num - ans << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 2010
#define MOD 1000000007
 
long long bin[MAX][MAX] = {0};
 
void pascal_trianlge() {
	bin[0][0] = 1;
	for (int i = 1; i < MAX; ++i) {
		bin[i][0] = bin[i][i] = 1;
		for (int j = 1; j < i; ++j) {
			bin[i][j] = (bin[i-1][j] + bin[i-1][j-1]) % MOD;
		}
	}
}
 
int main() {
	int n, k;
	cin >> n >> k;
	pascal_trianlge();
 
	for (int i = 1; i < k + 1; ++i) {
			cout << (bin[n - k + 1][i] * bin[k - 1][k - i]) % MOD  << endl;
	}
 
	return 0;
}

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

void solve(long long X){
    vi n5(0);
    for (ll i = 0; i <= 1000; i++)
    {
        n5.push_back(i * i * i * i * i);
    }

    for (int i = 0; i <= 1000; i++)
    {
        for (int j = 0; j <= 1000; j++) {
            if (n5[i] + n5[j] == X) {
                cout << i << " -" << j << endl;
                return;
            }
            if (n5[i] - n5[j] == X) {
                cout << i << " " << j << endl;
                return;
            }
            if (-n5[i] + n5[j] == X) {
                cout << "-" << i << " -" << j << endl;
                return;
            }
            if (-n5[j] - n5[i] == X) {
                cout << "-" << i << " " << j << endl;
                return;
            }
        }
    }

}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3672
let cnt = ref 0

let print_array a =
  Array.iteri (fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n) a;
  print_newline ()

let selection_sort a n =
  let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
  let rec select j minj =
    if j >= n then minj
    else select (j + 1) (if a.(j) < a.(minj) then j else minj)
  in
  let rec doit i =
    if i >= n then ()
    else begin
      let minj = select i i in
      if minj <> i then (swap i minj; incr cnt);
      doit (i + 1)
    end
  in
  doit 0

let () =
  let n = read_int () in
  let a = Array.of_list (List.map int_of_string (Str.split (Str.regexp " ") (read_line ()))) in
  selection_sort a n;
  print_array a;
  Printf.printf "%d\n" !cnt

Measured memory_bytes: 2368
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();

        if (line.length() == 2) {
            System.out.println(line);
        } else {
            for (int i = 2; i >= 0; i--) {
                System.out.print(line.charAt(i));
            }
            System.out.print("\n");
        }
    }
}


Measured memory_bytes: 24276
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int a, b, c, d;
   cin >> a >> b >> c >> d;
   while(1) {
       c -= b;
       if(c<=0) {
           cout << "Yes" << endl;
           return 0;
       }
       a-=d;
       if(a<=0) {
           cout << "No" << endl;
           return 0;
       }
   }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

string A,B,C;
cin >> A >> B >> C;

reverse(all(A));
reverse(all(B));
reverse(all(C));
char now = 'a';
while(true) {
    if(now == 'a') {
        if(A.empty()) {
            cout << 'A' << endl;
            return 0;
        }
        else {
            now = A.back();
            A.pop_back();
        }
    }
    if(now == 'b') {
        if(B.empty()) {
            cout << 'B' << endl;
            return 0;
        }
        else {
            now = B.back();
            B.pop_back();
        }
    }
    if(now == 'c') {
        if(C.empty()) {
            cout << 'C' << endl;
            return 0;
        }
        else {
            now = C.back();
            C.pop_back();
        }
    }
}

}

Measured memory_bytes: 256
#include <iostream> 
#include <algorithm> 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <cmath> 
#include <iomanip>
 using  namespace std;
 int a, b, c, x, d;
 //purvikaurraina
int main ()
{
    cin >> a >> b >> c >> x;
     for ( int i = 0 ; i <= a; i ++ )
    {
        for ( int j = 0 ; j <= b; j ++ )
        {
            for ( int k = 0 ; k <= c; k ++ )
                 if (i * 500 + j * 100 + k * 50 == x) d ++ ;
        }
    }
    cout << d << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
  if(min(b,d)-max(a,c)<0){
    cout<<0<<endl;
  }else{
    cout<<min(b,d)-max(a,c)<<endl;
  }
  }



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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ElapsedTime{
	chrono::system_clock::time_point m_start;
public:
	ElapsedTime(){
		m_start = chrono::system_clock::now();
	}
	~ElapsedTime(){
		const auto end = chrono::system_clock::now();
		const auto elapsed = chrono::duration_cast<std::chrono::milliseconds >(end - m_start).count();
		out(elapsed,"ms");
	}
};

vector<ll> enum_prime(ll N){
	deque<bool> is_prime(N+1,true);
	vector<ll> P;
	for(ll i=2;i<=N;i++){
		if(is_prime[i]){
			for(ll j=i*i;j<=N;j+=i){
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}

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

	map<int,int> M;
	auto P=enum_prime(50000);
	for(int i=0,ei=P.size();i<ei;i++){
		for(int j=i;j<ei;j++){
			M[P[i]+P[j]]++;
		}
	}

	while(true){
		int N=in();
		if(!N) break;
		out(M[N]);
	}
	return 0;
}


Measured memory_bytes: 5952
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
a = LIST()
q = INT()
arr = [0 for _ in range(10 ** 5 + 100)]
for i in a:
    arr[i] += 1
ans = sum(a)
for _ in range(q):
    b, c = MAP()
    arr[c] += arr[b]
    ans += (c - b) * arr[b]
    arr[b] = 0
    print(ans)

Measured memory_bytes: 89524
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
string intToA(int n,int radix)
{
	string ans="";
	do{
		int t=n%radix;
		if(t>=0&&t<=9) ans+=t+'0';
		else ans+=t-10+'a';
		n/=radix;
	}while(n!=0);
	reverse(ans.begin(),ans.end());
	return ans;
}
int main()
{
	int n,k;
	cin>>n>>k;
	cout<<(intToA(n,k)).size();
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

int a[1000];
int b[10000];

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

	int K, T;
	cin >> K >> T;
	for(int i = 0; i < T; i++) {
		cin >> a[i];
	}
	sort(a, a + T);
	reverse(a, a + T);

	if(a[0] <= (K + 1) / 2) {
		cout << 0 << endl;
		return 0;
	}

	int r1 = a[0], r2 = K - r1;
	for(int i = 0; i < K; i++) {
		if(i % 2 == 0) {
			b[i] = 0;
			r1--;
		}
		else {
			if(r2) {
				b[i] = 1;
				r2--;
			}
			else {
				b[i] = 0;
				r1--;
			}
		}
	}

	int ans = 0;
	for(int i = 0; i < K - 1; i++) {
		if(b[i] == b[i + 1]) ans++;
	}
	cout << ans << endl;
}

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

using namespace std;
int a[100005],b[100005],c[100005],n;
long long ans,f[100005];
void go(int a[])
{
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
}
int main()
{
	scanf("%d",&n);
	go(a); go(b); go(c);
	for (int i=1,j=0;i<=n;++i)
	{
		while (j<n&&a[j+1]<b[i]) ++j;
		f[i]=j+f[i-1];
	}
	for (int i=1,j=0;i<=n;++i)
	{
		while (j<n&&b[j+1]<c[i]) ++j;
		ans+=f[j];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long n;
   cin>>n;
    int ww;
    cin>>ww;
    long long w[n];
    long long v[n];
    for(int i=0;i<n;i++){cin>>v[i]>>w[i];}
    long long dp[n+1][ww+1];
    long long x,y;
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=ww;j++){
             x=dp[i-1][j];
            if(j>=v[i-1])
             y=dp[i-1][j-v[i-1]]+w[i-1];
            else y=0;

          
            dp[i][j]=max(x,y);
        }
    }
 

    cout<<dp[n][ww];


    return 0;
}

Measured memory_bytes: 79232
#include <iostream>
#include<utility>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<cfloat>
#include<functional>
#include<string>
#include<numeric>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<cctype>
#include<iterator>
#include <stdio.h>
#include <string.h>
#include <sstream>
//#include<conio.h>
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define MEGA_MIND ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define M_PI 3.14159265358979323846
#define mod 1000000007
#define endl "\n"
using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;


const int N = 5e6 + 5, inf = 2e9;


int n,x=0,y=0,c=0;
vector<int> v1, v2, v3;
int main()
{
	MEGA_MIND
		cin >> n;
	for (int i = 0; i < n; i++)
		v1.push_back(i + 1);
	for (int i = 0; i < n; i++)
	{
		int q; cin >> q;
		v2.push_back(q);
	}
	for (int i = 0; i < n; i++)
	{
		int q; cin >> q;
		v3.push_back(q);
	}


	do
	{
		if (v1 == v2)
			x = c;
		if (v1 == v3)
			y = c;
		c++;
	} while (next_permutation(v1.begin(),v1.end()));
	cout << abs(y - x) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	string s;
	cin>>n>>s;
	map<pair<string,string>,ll> ma;
	ll ans=0;
	REP(bit,(1<<n)) {
		bitset<18> bi(bit);
		string a="",b="";
		REP(i,n) {
			if(bi[i]) {
				a+=s[i];
			} else {
				b=s[i]+b;
			}
		}
		ma[make_pair(a,b)]++;
	}
	REP(bit,(1<<n)) {
		bitset<18> bi(bit);
		string a="",b="";
		REP(i,n) {
			if(bi[i]) {
				a+=s[n+i];
			} else {
				b=s[n+i]+b;
			}
		}
		ans+=ma[make_pair(b,a)];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 87040
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long multipleC = b / c - (a - 1) / c; // cの倍数の数
        long multipleD = b / d - (a - 1) / d; // dの倍数の数
        long lcm = getLcm(c, d);
        long commonMultiple = b / lcm - (a - 1) / lcm; // cdの公倍数の数

        long result = b - (a - 1) - multipleC - multipleD + commonMultiple;
        System.out.println(result);
    }

    static long getLcm(long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return c / b;
    }
}


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

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

    int ans = 0;
    for (int i = 0; i < n; ) {
        if (i != 0) i--;
        i += k;
        ans++;
    }

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

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

deque<int> height[250][250];//それぞれの高さと最上部のダイスのインデックス
int sokumen[][4]={{-1,-1,-1,-1},{2,3,5,4},{1,4,6,3},{1,2,6,5},{1,5,6,2},{1,3,6,4},{2,4,5,3}};//topが決まっているときの側面のパターン（反時計回り）
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

class dice
{
	public:
	int top;
	int frontid;//frontの面のindex
	int x,y;//座標
	dice(int t,int f)
	{
		top=t;
		for(int i=0;i<4;i++)
		{
			if(sokumen[top][i]==f)
				frontid=i;
		}
		x=125;
		y=125;
	}

	//転がったときにダイスがどうなるか
	//frontから反時計回り
	int rotate(int muki)
	{
		int rotid=(frontid+muki+4)%4;//転がる方向の面（転がった後に下に来るやつ）
		int front=sokumen[top][frontid];
		if(sokumen[top][rotid]<4)
			return -1;//転がることができない
		if(muki==0)
			front=top;
		else if(muki==2)
			front=7-top;
		top=7-sokumen[top][rotid];//topは転がる方向の裏

		//frontidを求める
		for(int i=0;i<4;i++)
		{
			if(sokumen[top][i]==front)
				frontid=i;
		}
		x+=dx[muki];
		y+=dy[muki];
		return top;
	}
};
vector<dice> d;

//(125,125)の最上部にあるサイコロを転がせる限界まで転がす
void korokoro(int di)
{
	int x=125;
	int y=125;
	bool f[4];//方向を調べる
	while(1)
	{
		//cerr<<height[x][y].size()<<endl;
		//高さ条件を見る
		fill(f,f+4,false);
		for(int i=0;i<4;i++)
		{
			if((int)height[x][y].size()-(int)height[x+dx[i]][y+dy[i]].size()>=2)
				f[i]=true;
			else
				f[i]=false;
		}
		int muki=-1;
		int me=-1;
		//高さ条件が合致している中で最大のダイスの目を見る
		for(int i=0;i<4;i++)
		{
			if(f[i] && me<sokumen[d[di].top][(d[di].frontid+i+4)%4])
			{
				me=sokumen[d[di].top][(d[di].frontid+i+4)%4];
				muki=i;
			}
		}
		//目が3以下なら終わり
		//cerr<<d[di].top<<" "<<me<<" "<<muki<<endl;
		if(me<=3)
			break;
		//それ以外なら転がす
		d[di].rotate(muki);
		height[x][y].pop_front();
		x=d[di].x;
		y=d[di].y;
		height[x][y].push_front(di);
	}
}

int main()
{
	while(1)
	{
		int n;
		int ans[6];
		fill(ans,ans+6,0);
		cin>>n;
		if(n==0)
			break;
		for(int i=0;i<250;i++)
		{
			for(int j=0;j<250;j++)
				height[i][j].clear();
		}
		d.clear();
		//(100,100が原点)
		for(int i=0;i<n;i++)
		{
			int t,f;
			cin>>t>>f;
			d.push_back(dice(t,f));
			height[125][125].push_front(i);
			korokoro(height[125][125][0]);

		}
		
		//すべてのマスについて見る
		for(int i=0;i<250;i++)
		{
			for(int j=0;j<250;j++)
			{
				if(!height[i][j].empty())
				{
					//cerr<<i<<" "<<j<<" "<<height[i][j].size()<<" "<<d[height[i][j][0]].top<<endl;
					ans[d[height[i][j][0]].top-1]++;
				}
			}
		}

		for(int i=0;i<6;i++)
		{
			cout<<ans[i];
			if(i!=5)
				cout<<" ";
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 44640
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;

const int MAXN = 200005;
vector<int> adjList[MAXN];
int cnt[MAXN];


void dfs(int u, int par) {
    for (int v : adjList[u]) {
        if (v == par)
            continue;
        cnt[v] += cnt[u];
        dfs(v, u);
    }
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n, q;
    cin >> n >> q;
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        adjList[u].push_back(v);
        adjList[v].push_back(u);
    }

    for (int i = 0; i < q; ++i) {
        int p, x;
        cin >> p >> x;
        cnt[p] += x;
    }

    dfs(1, -1);

    for (int i = 1; i <= n; ++i)
        cout << cnt[i] << ' ';

    cout << '\n';

    return 0;
}

Measured memory_bytes: 23552
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

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

typedef vector<int> vec;
typedef vector<vec> mat;

int main(){
    int d, t, s;
    cin >> d >> t >> s;
    if(d <= s * t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
#S = str(input())

i = 1
minNum = sys.maxsize
while i <= N**0.5 :
  if N % i == 0 :
    minNum = min(minNum, max(len(str(i)), len(str(N//i))))
  i += 1
print (minNum)





Measured memory_bytes: 3436
#include <stdio.h>
int main(void){
	int sx,sy,tx,ty;
	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
	int i,j,dx=tx-sx,dy=ty-sy;
	for(i=1;i<=4;i++){
		if(i==3){dx++;dy++;}
		if(i>2){printf(i%2==0?"R":"L");}
		for(j=0;j<dy;j++){printf(i%2==0?"D":"U");}
		for(j=0;j<dx;j++){printf(i%2==0?"L":"R");}
		if(i>2){printf(i%2==0?"U":"D");}
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2] << endl;
}

Measured memory_bytes: 3608
import math
import heapq
n, m = map(int, input().split())
a = [int(i) * (-1) for i in input().split()]
heapq.heapify(a)
i = 0
while i < m:
    max_a = - heapq.heappop(a)
    max_a /= 2
    heapq.heappush(a, -max_a)
    i += 1
total = 0
for k in a:
    total += math.floor(-k)
print(total)

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

int N, M, p, d[10010];

int dst(int a, int b) {
	return b + (b < a ? N : 0) - a;
}

int main() {
	cin >> N >> M >> p;
	
	for(int i=0;i<M;++i) cin >> d[i];
	
	sort(d, d+M);
	
	int pp = lower_bound(d, d+M, p) - d;
	
	int ans = N;
	
	for(int i=0;i<M;++i) {
		int di = d[(pp + i) % M], di_ = d[(pp - i - 1 + M) % M];
		
		if (i == M-1) {
			ans = min(ans, dst(p, di));
			ans = min(ans, dst(di_, p));
		} else {
			int dii = d[(pp + i + 1) % M], dii_ = d[(pp - i - 2 + M) % M];
			ans = min(ans, 2 * dst(p, di) + dst(dii, p));
			ans = min(ans, 2 * dst(di_, p) + dst(p, dii_));
		}
	}
	
	cout << ans * 100 << endl;
}

Measured memory_bytes: 1216
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := readInt()
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		a := readInt()
		m[a]++
	}

	ans := 0
	for a, c := range m {
		if c >= a {
			ans += c - a
		} else {
			ans += c
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7040
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

char img[57][57], temp[57][57];
int main(){
	Lancer();
	ll w, a, b, res,arr[4];
	cin >> w >> a >> b;
	if (a > b)
		res = max(a-(b+w), (ll)0);
	else
		res = max(b-(a+w), (ll)0);
	cout << res;
	cout << endl;
	return 0;
}


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

int main() {
    int n,c,k;
    cin >> n >> c >> k;
    int t[n];
    for(int i=0;i<n;i++) cin >> t[i];

    sort(t, t+n);
    int res = 0;
    for(int i=0;i<n;){
        int start = i;
        while(i < n && t[i] - t[start] <= k && i - start < c){
            i++;
        }
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int num = a*b;
    if(num%2==0){
      System.out.println("Even");
    }else{
      System.out.println("Odd");
    }
  }
}

Measured memory_bytes: 21716
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

//vector<ll> a;

int main()
{
	ll h,a;
	cin >> h >> a;
	
	cout << ceil((double)h / (double)a) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, s[3], t[3], id[3], mx;
const int N = 2e5;
int ai[N], lst[N], res;
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i)
        scanf("%d", &ai[i]), mx = max(mx, ai[i]);

    for (int p = 1; p <= 2; ++ p)
    {
        for (int i = p; i <= n; i += 2)
            lst[ai[i]] ++;
        for (int i = 1; i <= mx; ++ i)
        {
            if (lst[i] > s[p])
                t[p] = s[p], s[p] = lst[i], id[p] = i;
            else if (lst[i] > t[p])
                t[p] = lst[i];
            lst[i] = 0;
        }
    }
    if (id[1] != id[2]) res = n - s[1] - s[2];
    else res = min(n - s[1] - t[2], n - s[2] - t[1]);
    printf("%d\n", res);
}


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

int main(){
  int n, sum = 0, ans = 0;
  cin >> n;
  vector<vector<long>> a(n,vector<long> (2));
  for (long i = 0; i < n; ++i){
    for (int j = 0; j < 2; ++j) cin >> a[i][j];
  }
  
  sort(&a[0], &a[n], [](auto& x, auto& y){return x[1] < y[1];});
  rep(i, n, 0){
    sum += a[i][0];
    if(sum > a[i][1]){
      ans = 1;
      break;
    }
  }
  
  if(ans) cout << "No" << endl;
  else cout << "Yes" << endl;
}

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

typedef long long ll;

int main()
{
    string s;
    cin >> s;
    int i,j;
    int n = s.size();
    vector<pair<char,int>> rl;
    char temp_c;
    int temp_n = 0;
    temp_c = s.at(0);
    ++temp_n;
    for(i = 1;i < n;++i){
        if(s.at(i) != temp_c){
            rl.emplace_back(temp_c,temp_n);
            temp_c = s.at(i);
            temp_n = 1;
        }else{
            ++temp_n;
        }
    }
    rl.emplace_back(temp_c,temp_n);
    vector<int> ans(n,0);
    int temp = 0;
    for(i = 0;i < rl.size();++i){
        if(rl.at(i).first == 'R'){
            temp += rl.at(i).second;
            if(rl.at(i).second%2 == 0){
                ans.at(temp) += rl.at(i).second/2;
                ans.at(temp-1) += rl.at(i).second/2;
            }else{
                ans.at(temp-1) += (rl.at(i).second+1)/2;
                ans.at(temp) += (rl.at(i).second-1)/2;
            }
        }else{
            if(rl.at(i).second%2 == 0){
                ans.at(temp) += rl.at(i).second/2;
                ans.at(temp-1) += rl.at(i).second/2;
            }else{
                ans.at(temp) += (rl.at(i).second+1)/2;
                ans.at(temp-1) += (rl.at(i).second-1)/2;
            }
            temp += rl.at(i).second;
        }
    }
    for(i = 0;i < n;++i){
        cout << ans.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 1780
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<vector<int> > a(n);
    int i,j,k;
    for(i=0; i<n; i++) {
        for(j=0; j<n-1; j++) {
            int tmp;
            scanf("%d", &tmp);
            a[i].push_back(tmp-1);
        }
    }

    vector<int> curr(n);
    
    set<pair<int,int> > z;
    for(i=0; i<n; i++) {
        int tmp=a[i][0];
        if(tmp>i && a[tmp][0]==i) {
            z.insert(make_pair(i,tmp));
        }
    }

    int ans=0;
    while(1) {
        if(z.empty()) {
            break;
        }
        ans++;

        set<pair<int,int> > z0;
        auto it=z.begin();
        for(; it!=z.end(); ++it) {
            int tmp0=it->first;
            int tmp1=it->second;
            curr[tmp0]++;
            curr[tmp1]++;
        }

        it=z.begin();
        for(; it!=z.end(); ++it) {
            int tmp0=it->first;
            int tmp1=it->second;

            if(curr[tmp0]<n-1) {
                int tmp=a[tmp0][curr[tmp0]];
                if(curr[tmp]<n-1) {
                    if(a[tmp][curr[tmp]]==tmp0) {
                        z0.insert(make_pair(MIN(tmp0,tmp),MAX(tmp0,tmp)));
                    }
                }
            }
            
            if(curr[tmp1]<n-1) {
                int tmp=a[tmp1][curr[tmp1]];
                if(curr[tmp]<n-1) {
                    if(a[tmp][curr[tmp]]==tmp1) {
                        z0.insert(make_pair(MIN(tmp1,tmp),MAX(tmp1,tmp))).second;
                    }
                }
            }
        }
        z.swap(z0);
    }

    for(i=0; i<n; i++) {
        if(curr[i]!=n-1) {
            printf("-1\n"); return 0;
        }
    }
    printf("%d\n", ans);

    return 0;
}


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

int main() {
	int a,b,c,n;
  cin>>n;
  b=0;
  
  
  
  for(int i=1;i<=n;i+=2){
  	a=0;
    for(int j=1;j<=i;j++){
    	if(i%j==0)
          a++;
    }
    if(a==8){
      b++;
     // cout<<i<<endl;
    }
  
  }
  
  cout<<b<<endl;
  
return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
  int n1,n2;
  cin>>n1>>n2;
  while(n1!=0){
  if(n1<n2){
    int temp=n2;
    n2=n1;
    n1=temp;
  }
    n1=n1%n2;
  }
  cout<<n2<<endl;
   
  return 0;
}


Measured memory_bytes: 3080
#include <iostream>
using namespace std;
int prime[1000000];
int main(){
  fill(prime,prime + 1000000,1);
  prime[0] = prime[1] = 0;
  for(int i = 2 ; i*i < 1000000 ; i++ ){
    if(prime[i])for(int j = i*2 ; j < 1000000 ;j+=i )prime[j] = 0;
  }

  int p = 0;
  int n;
  while( cin >> n,n ){
    int cnt =0;
    for(int i = 0 ; i <= n/2 ; i++){
      if(prime[i] == 1 && prime[n-i] == 1)cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

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

using namespace std;

#define rep(i,n) for(int (i)=1;(i)<=(n);(i)++)

int main(){
  int H,W,h,w;
  cin >> H >> W >> h >> w;
  int gyou = H - h;
  int retu = W - w;
  cout << gyou*retu << endl;
}


Measured memory_bytes: 256
n, l = gets.split.map(&:to_i)
absmin = 9999999999
for i in 0..(n-1)
  pt = l + i
  absmin = pt if pt.abs < absmin.abs
end
sum = 0
for i in 0..(n-1)
  sum += l + i
end
puts sum - absmin

Measured memory_bytes: 1788
defmodule Main do
    def main do
        k = IO.read(:line)
        |> String.trim
        |> String.to_integer

        x = for c<- (for a <- 1..k, b <- 1..k, do: Integer.gcd(a, b)), d <- 1..k, do: Integer.gcd(c, d)
        IO.puts Enum.sum(x)
    end
end

Measured memory_bytes: 824564
#include <bits/stdc++.h>
#define RANGE(i,n) for(int i=0;i<n;i++)
typedef long long ll;
struct P{
    ll var1;
    ll var2;
};
bool operator< ( const P &one, const P &two){
    return one.var1 < two.var1;
};
bool operator> ( const P &one, const P &two){
    return one.var1 > two.var1;
};

using namespace std;

signed main() {
    int X, N;
    cin >> X >> N;
    vector<int> p;
    RANGE(i, N){
        int x;
        cin >> x;
        p.push_back(x);
    }
    vector<int> plus_vec;
    vector<int> minus_vec;
    for(int s : p){
        if(s - X >= 0){
            int sa = s - X;
            plus_vec.push_back(sa);
        }else{
            int sa = X - s;
            minus_vec.push_back(sa);
        }
    }
    if(!plus_vec.empty()) sort(plus_vec.begin(), plus_vec.end(), greater<int>());
    if(!minus_vec.empty()) sort(minus_vec.begin(), minus_vec.end(), greater<int>());
    if(plus_vec.empty() || plus_vec.back() != 0){
        cout << X << endl;
    }else{
        plus_vec.pop_back();
        RANGE(i, 100){
            if(minus_vec.empty() || minus_vec.back() != i+1){
                cout << X - (i + 1);
                break;
            }else if(plus_vec.empty() || plus_vec.back() != i+1){
                cout << X + (i + 1);
                break;
            }
            minus_vec.pop_back();
            plus_vec.pop_back();
        }
        cout << "" << endl;
    }
}


Measured memory_bytes: 3628