akhauriyash/Code-Regression huggingface dataset:
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) ->
      if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  inorder (fun e -> print_string " "; print_int e) t;
  print_newline ();
  preorder (fun e -> print_string " "; print_int e) t;
  print_newline ()

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let t = ref (create ()) in
  for _ = 0 to m - 1 do
    match read_line () |> split_on_char ' ' with
    | ["insert"; n] -> t := insert (int_of_string n) !t
    | _ -> print !t
  done

Measured memory_bytes: 31844
N,M = map(int,input().split())
red_possible = [1] + [0]*(N-1)
balls = [1] * N
for i in range(M):
    x,y = map(lambda x:int(x)-1,input().split())
    if red_possible[x]:
        red_possible[y] = 1
        if balls[x] == 1:
            red_possible[x] = 0
    balls[x] -= 1
    balls[y] += 1
print(sum(red_possible))

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,i,sum=0,x,y,i1;
    cin>>n;
    ll a[n],b[n],p[n];
    for (i=0;i<n;i++){
        cin>>a[i];
        p[i]=i+1;
    }
    for (i=0;i<n;i++){
        cin>>b[i];
    }
    vector<vector<ll> >v;
    do {
        vector<ll>temp;
        for (i=0;i<n;i++){
            temp.push_back(p[i]);
        }
        v.push_back(temp);
    }
    while (next_permutation(p,p+n));
    sort(v.begin(),v.end());
    for (i=0;i<v.size();i++){
        bool same=true;
        for (i1=0;i1<n;i1++){
            if (a[i1]!=v[i][i1]){
                same=false;
                break;
            }
        }
        if (same)x=i;
        same=true;
        for (i1=0;i1<n;i1++){
            if (b[i1]!=v[i][i1]){
                same=false;
                break;
            }
        }
        if (same)y=i;
    }
    cout<<abs(x-y)<<'\n';
}

Measured memory_bytes: 4408
s = input()
len_s = len(s)
a = [i for i in s if i != "x"]
b = "".join(a)
if b != b[::-1]:
  print(-1)
  exit()
ans = 0
f,r = 0,len_s-1
while f < r:
  if s[f] == s[r]:
    f += 1
    r -= 1
  elif s[f] == "x":
    f += 1
    ans += 1
  elif s[r] == "x":
    r -= 1
    ans += 1
print(ans)

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  int n=s.size();
  while(n--){
    if(n%2==1)continue;
    if(s.substr(0,n/2)==s.substr(n/2,n/2)){
      cout<<n;
      return 0;
    }
  }   
}

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

int main() {
    int N;
    cin >> N;
    vector<double> v(N);
    rep(i, N) cin >> v.at(i);

    sort(v.begin(), v.end());
    double ans = (v.at(0) + v.at(1)) / 2;
    for (int i = 2; i < N; i++) {
        ans = (ans + v.at(i)) / 2;
    }
    cout << ans << endl;
}


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

Input_ar = list(map(int,input().split()))

er = 0

for i in range(N):
  if Input_ar[i]%2==0:
    if not((Input_ar[i]%3==0) or (Input_ar[i]%5==0)):
      er += 1
if er == 0:
  print("APPROVED")
else:
  print("DENIED")




Measured memory_bytes: 2940
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> score(n,0);
    vector<int> border(n,k);
    vector<string> mem(n,"No");

    for(int i=0;i<q;i++){
        int a;
        cin >> a;
        a--;
        score.at(a)++;
    }

    //for(int i=0;i<n;i++) cout << score.at(i) << endl;

    for(int i=0;i<n;i++){
        border.at(i)=k-q+score.at(i);
        if(border.at(i)>0) mem.at(i)="Yes";
    }

    for(int i=0;i<n;i++) cout << mem.at(i) << endl;
}

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

int main()
{
  int a, b; cin >> a >>  b;
  int A = 0;
  int B = 0;
  
  rep(i, b) {
    A += (a * pow(10,i));
  }

  rep(i, a) {
    B += (b * pow(10, i));
  }

  if (a < b)cout << A << endl;
  else if (a >= b)cout << B << endl;

}

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

int main(){
	int n, M[8], m[8], res;
	char str[8];
	
	scanf("%d", &n);
	
	for(int j = 0; j < n; j++){
		scanf("%s", str);
		
		//printf("n = %d : j = %d\n", n, j);
		
		for(int i = 0; i < 8; i++){
			m[i] = str[i] - 48;
		}
		
		sort(m, m + 8);
		
		for(int i = 0; i < 8; i++){
			M[i] = m[7 - i];
		}
		
		for(int i = 7; i >= 0; i--){
			M[i] -= m[i];
			if(M[i] < 0){
				M[i] += 10;
				M[i - 1]--;
			}
		}
		res = M[0] * 10000000
				+ M[1] * 1000000
				+ M[2] * 100000
				+ M[3] * 10000
				+ M[4] * 1000
				+ M[5] * 100
				+ M[6] * 10
				+ M[7];
		
		printf("%d\n", res);
	}
	
	return 0;
}

Measured memory_bytes: 1040
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String str = sc.nextLine();
            if ("-".equals(str)) {
                break;
            }
            int m = sc.nextInt();
            int sum = 0;
            for (int i = 0; i < m; i++) {
                sum += sc.nextInt();
            }
            int bi = sum % str.length();
            int ei = bi + str.length();
            String res = (str + str).substring(bi, ei);
            System.out.println(res);
            sc.nextLine();
        }
    }
}

Measured memory_bytes: 18120
namespace VainZero.Procon.FSharp

open System
open System.Collections.Generic

[<AutoOpen>]
module Operators =
  let read f = Console.ReadLine().Split([|' '|]) |> Array.map f

module Program =
  [<EntryPoint>]
  let main _ =
    let [|n; t|] = read int64
    let n = int n
    let ts = read int64

    ts
    |> Array.collect (fun s -> [|(s, 1); (s + t, -1)|])
    |> Array.sortBy fst
    |> Array.pairwise
    |> Array.fold
      (fun (depth, total) ((first, _), (last, diff)) ->
        (depth + diff, (total + (if depth > 0 then last - first else 0L)))
      ) (1, 0L)
    |> (fun (_, total) -> printfn "%d" total)

    0


Measured memory_bytes: 59824
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll x,y; cin >>x>>y;
  ll out;
  if(x<y){
    out = min(y-x, abs(abs(y)-abs(x)) + 1);
  } else {
    x*=-1;
    out = 1;
    out += min(abs(y-x), abs(abs(y)-abs(x)) + 1);
  }
  cout << out << endl;
  return 0;
}


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

int main() {
	long long N, count = 0;
	static long long A[100000], B[100000], C[100000];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}
	sort(A, A + N), sort(B, B + N), sort(C, C + N);
	for (int i = 0; i < N; i++) {
		long long As, Cs;
		long long lb = -1, ub = N;
		while (ub - lb > 1) {
			long long mid = (lb + ub) / 2;
			if (A[mid] < B[i]) {
				lb = mid;
			}
			else {
				ub = mid;
			}
			As = ub;
		}
		lb = -1, ub = N;
		while (ub - lb > 1) {
			long long mid = (lb + ub) / 2;
			if (C[mid] > B[i]) {
				ub = mid;
			}
			else {
				lb = mid;
			}
			Cs = N - ub;
		}
		count += As * Cs;
	}
	cout << count;
}

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

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int T=scan.nextInt();
		for(int roop=0;roop<T;roop++){
			int[] n = new int[9];
			int[][] card = new int[3][9];
			char[] c = new char[9];
			for(int i=0;i<9;i++){
				n[i]=scan.nextInt();
			}
			for(int i=0;i<9;i++){
				c[i]=scan.next().charAt(0);
			}
			for(int i=0;i<9;i++){
				switch(c[i]){
					case 'R':
						card[0][n[i]-1]+=1;
						break;
					case 'G':
						card[1][n[i]-1]+=1;
						break;
					case 'B':
						card[2][n[i]-1]+=1;
						break;
					default:
						break;
				}
			}
			int set=0;
			for(int i=0;i<3;i++){
				for(int j=0;j<9;j++){
					if(card[i][j]>2){
						card[i][j]-=3;
						set+=1;
					}
					while(j<7 && card[i][j]>0 && card[i][j+1]>0 && card[i][j+2]>0){
						for(int k=0;k<3;k++){
							card[i][j+k]-=1;
						}
						set+=1;
					}
				}
			}
			if(set>2){
				System.out.println(1);
			}
			else{
				System.out.println(0);
			}
		}
	}
}

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

using namespace std;
bool is_prime(int n) {
  if (n < 2) return false;
  if (n == 2) return true;
  if (n % 2 == 0) return false;

  int x = 3;
  while (x * x <= n) {
    if (n % x == 0) return false;
    x += 2;
  }

  return true;
}

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

  int n = X;
  while (!is_prime(n)) n++;
  cout << n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const long long MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

// Nの桁数
int calc_digit(long long N) {
    int res = 0;
    while (N) {
        ++res;
        N /= 10;
    }
    return res;
}

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
    return a / GCD(a, b) * b;
}

// ax + by = gcd(a, b) となるような (x, y) を求める
// 多くの場合 a と b は互いに素として ax + by = 1 となる (x, y) を求める
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    // 再帰的に解く (x, y を入れ替えておく)
    long long d = extGCD(b, a % b, y, x); 
    y -= a / b * x;
    return d;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    ll n,p;cin>>n>>p;
    const auto &pf = prime_factorize(p);
    ll ans=1;
    for (auto a : pf) {
        ans*=pow(a.first,a.second/n);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import deque
n=int(input())
d={}
for i in range(n-1):
    a,b=map(int,input().split())
    if a in d:
        d[a].append(b)
    else:
        d[a]=[b]
    if b in d:
        d[b].append(a)
    else:
        d[b]=[a]
f,s=set([1]),set([n])
e=deque([0,1])
u=deque([0,n])
x=0
while 1:
    if len(e)==len(u)==1: break

    if len(e)>0:
        while e[-1]!=0:
            tmp=e.pop()
            for i in d[tmp]:
                if i not in f and i not in s:
                    f.add(i)
                    e.appendleft(i)
        e.rotate()
    if len(u)>0:
        while u[-1]!=0:
            tmp=u.pop()
            for i in d[tmp]:
                if i not in f and i not in s:
                    s.add(i)
                    u.appendleft(i)
        u.rotate()

print(["Fennec","Snuke"][len(f)<=len(s)])

Measured memory_bytes: 75096
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<vector>
using namespace std;
int n,m,x,y,k[100009];
bool f[100009];
int main(void){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a;
		cin>>a;
		string s;
		cin>>s;
		if(f[a])
			continue;
		if(s=="AC"){
			x++;
			y+=k[a];
			f[a]=1;
		}
		else{
			k[a]++;
		}
	}
	cout<<x<<' '<<y;
	return 0;
}

Measured memory_bytes: 896
import java.util.Arrays;
import java.util.Scanner;


public class Main{


	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scanner=new Scanner(System.in);
		int n=scanner.nextInt();
		int mvalue=scanner.nextInt();
		int[] V=new int[n+1];
		int[] W=new int[n+1];
		
		int[][] dp=new int[n+1][mvalue+1];
		for(int i=0;i<=n;i++)
			Arrays.fill(dp[i], 0);
		//Arrays.fill(dp[0],0);
		for(int i=1;i<=n;i++){
			V[i]=scanner.nextInt();
			W[i]=scanner.nextInt();
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=mvalue;j++){
				if(j>=W[i])
					dp[i][j]=Math.max(dp[i-1][j], dp[i-1][j-W[i]]+V[i]);
				else dp[i][j]=dp[i-1][j];
			}
		}
//		for(int i=1;i<=n;i++){
//			for(int j=1;j<=mvalue;j++)
//				System.out.print(dp[i][j]+" ");
//			System.out.println();
//		}
//			
		System.out.println(dp[n][mvalue]);
		
	}

}



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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("d",&a,&b)
#define sfff(a,b,c)     scanf("d%d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int z=1 ; z<=t ; z++)
#define PRINT_CASE printf("Case %d: ",z)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)1e5+5;
const int inf = 1e9+2;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;

int v[110],w[110];
ll DP[110][maxn];
int n,cap;

ll cal(int pos, int val){

    if(val==0) return 0;
    if(pos==n || val<0) return inf;

    ll &res = DP[pos][val];

    if(res!=-1){
        return res;
    }

    res= cal(pos+1,val);
    res = min(res ,cal(pos+1, val-v[pos])+w[pos]);

    return res;

}


int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin>>n>>cap;

    f0(i,n) cin>>w[i]>>v[i];
    memset(DP , -1 , sizeof(DP));
    for(int i=n*1000 ; i>=0 ; i--){

        if(cal(0,i)<=cap){
            cout<<i<<endl;
            return 0;
        }
    }

    return 0;
}



Measured memory_bytes: 86272
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
const ll MOD = 1000000007;
int main() {
	int n;
	cin >> n;
	ll a[n];
	rep(i, n) cin >> a[i];
	vector<ll> v(60);
	rep(i, n) {
		rep(j, 60) {
			if (a[i] >> j & 1LL) v[j]++;
		}
	}
	ll ans = 0;
	rep(i, 60) {
		ll p = (1LL << i) % MOD;
		ans += v[i] * (n - v[i]) % MOD * p % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main () {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int cnt = 0;
    for (int i = 0; i < 1000; ++i) {
        int c[3] = {i / 100 , (i / 10) % 10, i % 10 };
        int f = 0;
        for (int j = 0; j < N; ++j) {
            if (S[j] - '0' == c[f]) f++;
            if (f == 3) break;
        }
        if (f == 3) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3264
<?php

fscanf(STDIN, "%d", $n);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
sort($A);

$flg = true;
$prod = 1;
for ($i = 0; $i < $n; ++$i) {
    $prod *= $A[$i];

    if ($prod > 1000000000000000000) {
        $flg = false;
        break;
    }
}

echo $flg ? $prod : -1;


Measured memory_bytes: 28744
#define _USE_MATH_DEFINES  // M_PI等のフラグ

#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

string replace_with_str(string str, string str_from, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(str_from, pos), pos != string::npos) {
        str.replace(pos, str_from.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(int argc, char const *argv[]){
    string N;
    cin >> N;
    int ans = 0;
    for(int i=0; i<N.size(); i++){
        if(N[i] == '2'){
            ans ++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define lli long long int
#define f first
#define s second
#define fw(i, start, end) for (lli i = start; i < end; ++i)
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    lli n;
    float m;
    cin >> n >> m;
    float a[n];
    float s = 0;
    fw(i, 0, n)
    {
        cin >> a[i];
        s += a[i];
    }
    float tmp = s / (float)(4 * m);

    lli cnt = 0;
    fw(i, 0, n)

    {
        if (a[i] >= tmp)
        {
            cnt++;
        }
    }
    if (cnt >= m)
        cout << "Yes\n";
    else if(cnt<m)
    {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;

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

    vi h(n);
    rep(i, n) cin >> h[i];

    vi ok(n,1);

    rep(i, m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        if(h[a]>h[b]) ok[b]=0;
        if(h[a]<h[b]) ok[a]=0;
        if(h[a]==h[b]){
            ok[a] = 0;
            ok[b] = 0;
        }
    }

    int ans=0;
    rep(i, n){
        if(ok[i]==1) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int output = 0;
  for(int i=0;i<N;i++){
    int l,r;
    cin >> l >> r;
    output += (r-l+1);
  }
  cout << output << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;


int main()
{
    int a;

    cin >> a;

    cout << a + a * a + a * a * a << endl;

    return 0;
}

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

AC = 0
WA = 0
TLE = 0
RE = 0

for i in range(N):
  s = input()
  if s == 'AC':
    AC += 1
  elif s == 'WA':
    WA += 1
  elif s == 'TLE':
    TLE += 1
  else:
    RE += 1
    
print("AC x {}".format(AC))
print("WA x {}".format(WA))
print("TLE x {}".format(TLE))
print("RE x {}".format(RE))

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long A; cin >> A;
    long V; cin >> V;
    long B; cin >> B;
    long W; cin >> W;
    long T; cin >> T;

    string ans = "NO";
    long tmpA = A;
    long tmpB = B;

    if(B > A){
        for(int i = 0; i < T; i++){
            tmpA += V;
            tmpB += W;
        }
        if(tmpA >= tmpB) ans = "YES";
    }

    if(A > B){
        for(int i = 0; i < T; i++){
            tmpA -= V;
            tmpB -= W;
        }
        if(tmpA <= tmpB) ans = "YES";
    }

    cout << ans << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    int X, Y;
    io.read(X, Y);
    string ans = "No";
    if(Y % 2 == 0 && Y / 2 - X >= 0 && 2 * X - Y / 2 >= 0) ans = "Yes";
    cout << ans;
    return 0;
}

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

const int MAXN = 100007;
int a[MAXN];
int b[MAXN];
int c[MAXN];

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

    for (int i = 0; i < N; i++) scanf("%d", &a[i]);
    for (int i = 0; i < N; i++) scanf("%d", &b[i]);
    for (int i = 0; i < N; i++) scanf("%d", &c[i]);

    sort(a, a+N);
    sort(c, c+N);

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll x = lower_bound(a, a+N, b[i]) - a;
        ll y = upper_bound(c, c+N, b[i]) - c;
        y = N - y;

        ans += x * y;
    }

    cout << ans << endl;
}

/*
3
1 2 3
2 4 6
5 7 8
*/




Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
	vector<int> X(5);
	int sum, min = 0;
	for(int i = 0; i < 5; i++){
		cin >> X.at(i);
		if(X.at(i)%10 <= X.at(min)%10 && X.at(i)%10)
			min = i;
	}
	for(int i = 0; i < 5; i++){
		if(i != min && X.at(i)%10)
			X.at(i) = X.at(i)-X.at(i)%10+10;
		sum += X.at(i);
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
function zeroPadding(str) {
  return ('000000' + str).slice(-6)
}


function Main(input) {
  const data = input.trim().split('\n')
  const temp = data[0].split(' ').map(s => parseInt(s))
  const N = temp[0] // 県
  const M = temp[1] // 市

  const rest = data.slice(1).map(s => {
    return s.split(' ').map(x => parseInt(x))
  })

  var ans = {}
  rest.forEach((d, index) => {
    if(!ans[d[0]]) ans[d[0]] = []
    ans[d[0]].push({index: index, p: d[0], t: d[1], s: '' })
  })

  // console.log(ans)


  for(var i in ans) {
    ans[i] = ans[i].sort((a, b) => a.t - b.t)
  }

  var res = Array(M)
  for(var i in ans) {
    for(var j = 0; j < ans[i].length; ++j) {
      var d = ans[i][j]
      var str = zeroPadding(d.p) + zeroPadding((j+1).toString())
      res[d.index] = str
    }
  }

  var output = res.reduce((p, c) => p + '\n' + c)

  console.log(output)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 88252
n=int(input())
t=list(map(int,input().split()))
m=int(input())
p=[]
x=[]
for i in range(m):
    p1,x1=map(int,input().split())
    p.append(p1)
    x.append(x1)
a=0
for i in range(n):
    a+=t[i]
for i in range(m):
    print(a-t[p[i]-1]+x[i])

Measured memory_bytes: 62748
N,W=map(int,input().split())
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(N):
  w,v=map(int,input().split())
  for j in range(W+1):
    if j>=w:
      dp[i+1][j]=max(dp[i][j-w]+v,dp[i][j])
    else:
      dp[i+1][j]=dp[i][j]
print(dp[N][W])

Measured memory_bytes: 119916
implicit none
integer :: n,k
integer,allocatable :: a(:),hist(:)
integer :: i

read *,n,k
allocate(a(n))
read *,a

allocate(hist(n))
hist(:) = 0
do i = 1, n
   hist(a(i)) = hist(a(i)) + 1
enddo

call cs11(n,hist)

print '(i0)',n-sum(hist(n-k+1:n))
stop

contains
subroutine cs11(Ncomb,a)
   integer, intent(in) :: Ncomb
   integer, intent(inout) :: a(Ncomb)
   integer :: icomb, jcomb,rswp
   logical :: flg_swp

   icomb = Ncomb
   flg_swp = .false.
   do while (icomb > 1 .or. flg_swp)
      icomb = (icomb * 10) / 13
      if (icomb < 1) then
         icomb = 1
      else if (icomb == 9 .or. icomb == 10) then 
         icomb = 11
      endif
      flg_swp = .false.
      do jcomb = 1, Ncomb-icomb
         if (a(jcomb) > a(jcomb+icomb)) then
            rswp = a(jcomb) 
            a(jcomb) = a(jcomb+icomb)
            a(jcomb+icomb) = rswp
            flg_swp = .true.
         endif
      enddo
   enddo
endsubroutine cs11
end

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

// aのn乗
ll modpow(ll a, ll n){
  ll r = 1;
  while (n) {
    r = r * ( (n%2)?a:1 ) %MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return r;
}

ll sum_inv[101010];

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  sum_inv[0]=0;
  for(int i=1;i<101000;i++){
    sum_inv[i]=sum_inv[i-1];
    (sum_inv[i]+=modpow(i+1,MOD-2))%=MOD;
  }
  int N; cin>>N;
  ll sum=0;
  rep(i,N){
    ll a; cin>>a;
    sum+=a*sum_inv[i]%MOD;
    sum+=a*sum_inv[N-1-i]%MOD;
    sum+=a;
    sum%=MOD;
  }
  rep(i,N) (sum*=(i+1))%=MOD;
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        
        if (str.length() < 4) {
            System.out.println("No");
            return;
        }

        if(str.substring(0, 4).contains("YAKI")) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    if (N == M) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
void input(){
    fast_io();
    cin >> N;
}

int solve(){
    if(N%2){
        vector<pii> edge;
        for (int i = 1; i <= N; i++)
        {
            for (int j = i+1; j <= N; j++)
            {
                if(j==i || j==N-i) continue;
                edge.emplace_back(i,j);
            }
        }
        cout << edge.size() << "\n";
        for (int i = 0; i < edge.size(); i++)
        {
            cout << edge[i].first << " " << edge[i].second << "\n";
        }
    }
    else{
        vector<pii> edge;
        for (int i = 1; i <= N; i++)
        {
            for (int j = i+1; j <= N; j++)
            {
                if(j==i || j==N+1-i) continue;
                edge.emplace_back(i,j);
            }
        }
        cout << edge.size() << "\n";
        for (int i = 0; i < edge.size(); i++)
        {
            cout << edge[i].first << " " << edge[i].second << "\n";
        }
    }
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3712
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
ll modpow(ll a, ll n, ll mod) {
  
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll factorial(ll x){
  if(x==0)return 1;
  return x*factorial(x-1)%MOD;
}
struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};
int main(){
  ll n,m;cin>>n>>m;
  vvl data(n);
  vl a(m),b(m);
  rep(i,m){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
  }
  ll ans=0;
  rep(i,m){
    UnionFind tree(n);
    rep(j,m){
      if(j==i)continue;
      tree.unite(a[j],b[j]);
    }
    if(!tree.same(a[i],b[i]))ans++;
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);

int maxs,minf;
  if(a<c) maxs=c;
  else maxs=a;
  
  if(b<d) minf=b;
else minf=d;
  
  
  if(maxs<minf) printf("%d",minf-maxs);
  else printf("0");
  
return 0;
}

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

int main() {
	int n; cin >> n;
	int a[100000];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long d = 0;
	{
		int s = 1;
		for (int i = 0; i < n; i++) {
			d += a[i] * s; s = -s;
		}
	}
	cout << d;
	for (int i = 1; i < n; i++) {
		d -= 2 * a[i - 1];
		d = -d;
		cout << " " << d;
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline char CH()
{
  static char buf[100000],*ptr1=buf,*ptr2=buf;
  return ptr1==ptr2&&(ptr2=(ptr1=buf)+fread(buf,1,100000,stdin),ptr1==ptr2)?EOF:*ptr1++;
}
static inline int IN(void)
{
  int x=0,f=0,c=CH();while(c<48||c>57){f^=c==45,c=CH();}
  while(c>47&&c<58){x=x*10+c-48,c=CH();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Radix32(int A[],const int sz)
{
  int temp[200001];const int bit=8;
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,sz)u[A[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)u[i+1]+=u[i];
    rep(i,sz){temp[--u[A[sz-1-i]>>bit*k&((1<<bit)-1)]]=A[sz-1-i];}k++;
    rep(i,sz)v[temp[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)v[i+1]+=v[i];
    rep(i,sz)A[--v[temp[sz-1-i]>>bit*k&((1<<bit)-1)]]=temp[sz-1-i];
  }
}
int main(void)
{
  int N,p=0,m=0,z=0,A[200000];
  long K,count=0,l=-2e18,r=-l,mid,x=scanf("%d %ld",&N,&K);
  rep(i,N){x=IN();if(x>0)A[m+p++]=x;else if(x<0)A[p+m++]=x;else z++;}
  Radix32(A,m+p);
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;
  if(K<=1l*m*p)r=1l;else l=-1l;x=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=x;if(count>=K){r=mid-1l;continue;}
      rep(i,p){while(i<plus&&1l*A[i]*A[plus]>mid){plus--;}if(i==plus){break;}count+=1l*plus-i;}if(count>=K){r=mid-1l;continue;}
      rep(i,m){while(i<minus&&1l*A[m+p-1-i]*A[m+p-1-minus]>mid){minus--;}if(i==minus){break;}count+=1l*minus-i;}
    }
    else{int low=0;rep(i,m){while(1l*A[low]*A[p+i]>mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K)r=mid-1l;else l=mid+1l;
  }
  return OUT(l),0;
}

Measured memory_bytes: 3176
def distance(a,b):
    ans = (a[0]-b[0])**2 + (a[1] - b[1])**2
    return ans**(0.5)
from itertools import permutations
from math import factorial
n = int(input())
xy = []
for i in range(n):
    xy.append(list(map(int,input().split())))
ans = 0
for d in permutations(range(n)):
    for i in range(n-1):
        ans += distance(xy[d[i]],xy[d[i+1]])
print(ans/factorial(n))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#include <set>
#include <map>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int tmp, cnt = 0;


int main()
{
    int n,q,a;
    vector<ll> s;
    ll t;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        s.push_back(a);
    }
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> t;
        if (binary_search(s.begin(), s.end(), t))
        {
            cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3808
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <queue>

using namespace std;
const int64_t INF=10000000000000000;
#include <vector>
#include<cstdint>
#include <iostream>
#include <vector>

template<class T>
void read_1d(std::vector<T>& a,int64_t num){
	a.reserve(num);
	for(int64_t i1=0;i1<num;i1++){
		T temp;
		std::cin>>temp;
		a.push_back(temp);
	}
}
template<class T>
void read_2d(std::vector<std::vector<T> >&a,int64_t x,int64_t y ){
	a.resize(x);
	for(int64_t i1=0;i1<x;i1++){
		a[i1].reserve(y);
		for(int64_t i2=0;i2<y;i2++){
			char temp;
			std::cin>>temp;
			if(temp=='0'){
				a[i1].push_back(0);
			}else{
				a[i1].push_back(1);
			}
		}
	}
}
template<class InputIterator>
void debug(InputIterator first,InputIterator last){
	for(auto i1=first;i1!=last;i1++){
		std::cout<<(*i1);
	}
}


int main(){
	int64_t n,k;
	cin>>n>>k;
	vector<int64_t> pos_negative;
	vector<int64_t> pos_positive;
	pos_negative.reserve(n);
	pos_positive.reserve(n);
	for(int64_t i1=0;i1<n;i1++){
		int64_t temp;
		cin>>temp;
		if(temp>=0){
			pos_positive.push_back(temp);
		}else{
			pos_negative.push_back(-temp);
		}
	}
	reverse(pos_negative.begin(),pos_negative.end());
	int64_t ans=INF;
	for(int64_t t=0;t<=k;t++){
		int64_t negative,positive;
		if(t==0){
			negative=0;
		}else{
			if(t<=pos_negative.size()){
				negative=pos_negative[t-1];
			}else{
				continue;
			}
		}
		if(t==k){
			positive=0;
		}else{
			if((k-t)<=pos_positive.size()){
				positive=pos_positive[k-t-1];
			}else{
				continue;
			}
		}
		int64_t temp=min(negative,positive)*2+max(negative,positive);
		if(temp<ans){
			ans=temp;
		}
	}
	cout<<ans<<endl;





}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
#include <cctype>
#include <bitset>
using namespace std;
int main()
{
    int N,i,MAX,a;
    cin >> N;
    int H[N];
    for(i = 0;i < N;i++) cin >> H[i];
    a = 1;
    MAX = H[0];
    for(i = 1;i < N;i++){
        if(MAX <= H[i]){
            MAX = H[i];
            a++;
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 3584
/* "The world is full of obvious things which nobody by any chance ever observes." */


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define mod 1000000007
#define pi  3.14159265358979323846
#define pb push_back
#define mk make_pair
#define popcnt(a) _Generic((a), int: __builtin_popcount(a), \  long long: __builtin_popcountll(a))  
#define precise(x) cout<<fixed<<setprecision(10)<<x
#define test cout<<"#";
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout) 

const ll inf = 1e18L + 2;

ll ans[1000001];

ll solve(vector<ll> &v, ll n, ll k)
{
    ans[1] = 0;
    for(ll x = 2; x <= n; x++)
    {
        ans[x] = inf;
        for(ll y = 1; y <= k; y++)
        {
            if(x-y>=1)
                ans[x] = min(ans[x], ans[x-y] + abs(v[x-1] - v[x-y-1]));
        }
    }
    return ans[n];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, k;
    cin>>n>>k;
    vector<ll> v(n);
    memset(ans, -1, sizeof(ans));
    for(ll x = 0; x < n; x++)
        cin>>v[x];
    cout<<solve(v, n, k);
}

Measured memory_bytes: 11912
#include<bits/stdc++.h>
using namespace std;
long long n, x,ans;
long long gcdgcd(long long x,long long n)
{
    if(n%x==0)
        return n*2-x;
    ans=n/x*x*2+gcdgcd(n%x, x);
    return ans;
}
int main()
{
    cin>>n>>x;
    cout<<gcdgcd(x, n-x)+n<<endl;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    ll N; cin >> N;
    vector<ll> A(N); REP(i,N) cin >> A[i];
    SORT(A);
    vector<pair<ll,ll>> v;
    v.emplace_back(A[0],1);
    REP(i,N-1){
        if(v.back().first == A[i+1]) v.back().second++;
        else v.emplace_back(A[i+1],1);
    }
    ll ans = 0;
    ll a=0,b=0;
    while(v.size()){
        if(v.back().second > 1){
            if(a > 0){
                b = v.back().first;
                break;
            }
            else a = v.back().first;
            v.back().second -= 2;
        }
        else v.pop_back();
    }
    ans = a*b;
    cout << ans << en;
    return 0;
}

Measured memory_bytes: 3188
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int n,q,t;
    int c = 0;
    cin >> n;
    int S[n] = {};
    for(int i=0;i<n;i++){
        scanf("%d",&S[i]);
    }
    cin >> q;
    int T[q] = {};
    for(int i=0;i<q;i++){
        scanf("%d",&T[i]);
    }
    
    for(int i=0;i<q;i++){
        t = T[i];
        int left = 0,right = n;
        while(left < right){
            int mid = (left + right)/2;
            if(S[mid] == t){
                c++;
                break;
            }
            else if(t < S[mid]){
                right = mid;
            }
            else{
                left = mid +1;
            }
        }
    }
    
    cout << c << endl;
}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main() {
    string u="Sunny";
    string x="Cloudy";
    string z="Rainy";
    string s;
    cin>>s;
    if(s[0]==u[0]){
        cout<<x;
    }
    else if(s[0]==x[0]){
        cout<<z;
    }
        else{
            cout<<u;
        }



    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
 int a,b,d,r;
 double f,p,m;
 cin>>a>>b;
 p=a;
 m=b;
 d=a/b;
 r=a%b;
 f=p/m;
 cout<<d<<" "<<r<<" ";
	printf("%6f",f);
	cout<<endl;
return 0;
}


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

int main()
{
    int n,t;
    std::cin>>n>>t;
    std::vector<int> p(n);
    for(int i=0;i<n;i++)std::cin>>p[i];
    long long time = 0;
    for(int i=0;i<n-1;i++){
        //次の人まで行くかtが全部でるか
        time += std::min(t,p[i+1] - p[i]);
    }
    time += t;
    std::cout<<time<<std::endl;

}

Measured memory_bytes: 1024
#!/usr/bin/python3
# Copyright (C) 2017 Sayutin Dmitry.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 3
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.

def main():
    s, c = map(int, input().split())

    lo, hi = 0, int(1e18)
    
    while hi - lo > 1:
        mi = lo + (hi - lo) // 2

        free = c - 2 * mi
        if free < 0 or s + free // 2 < mi:
            hi = mi
        else:
            lo = mi
    print(lo)

main()


Measured memory_bytes: 2940
n = int(input())
s = [input() for _ in range(n)]

cnt = []
for i in range(ord('a'), ord('z') + 1):
     cnt.append(min(v.count(chr(i)) for v in s))

ans = ''
for i, v in enumerate(cnt):
    ans += chr(97 + i) * v
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i > (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int n,k;
		cin>>n>>k;
		ll ma=0,mi=0,ans=0;
		FOR(i,0,k)
		{
			mi+=i;
			ma+=(n-i);
		}
		FOR(i,k,n+1)
		{
			ans+=(ma-mi+1);
//			cout<<ma<<' '<<mi<<' '<<ans<<'\n';
			ans%=mod;
			mi+=i;
			ma+=(n-i);
		}
		ans+=(ma-mi+1);
		ans%=mod;
		cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  string s;
  int num[26] = {};
  while (getline(cin, s))
    for (int i = 0; i < s.size(); ++i)
      if (isalpha(s[i]))
        num[tolower(s[i]) - 'a']++;

  for (int i = 0; i < 26; ++i)
    cout << (char)('a' + i) << " : " << num[i] << endl;

  return 0;
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    /* 入力受け取り */
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N){cin >> A[i];}

    int sum = 0;
    ll res = 0;
    int right = 0;
    rep(left, N){
        while (right < N && ((sum ^ A[right]) == (sum + A[right]))){
            sum += A[right];
            ++right;
        }
        res += (right - left);
        if (left == right) { // when left == right == 0
            ++right;
        } else {
            sum -= A[left];
        }
    }
    cout << res << endl;
}

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


Measured memory_bytes: 1024