akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

int dp[100000] = {};
long long cnt(int n) {
    if (n == 0 || n == 1) return dp[n] = 1;
    if (dp[n] != 0) return dp[n];
    else return dp[n]=(cnt(n - 1) + cnt(n - 2))%1000000007;
}

int main() {
    long long  n, m; long long a[100010] = {};
    cin >> n >> m;
    a[0] = -1; a[m+1] = n+1;
    for (long long i = 1;i <= m;i++) {
        cin >> a[i];
    }
    long long ans=1;
    long long f=1;
    for (long long i = 0; i <= m; i++) {
        if (a[i + 1] - a[i] == 1) f = 0;
        else ans = (ans * cnt(a[i + 1] - a[i]-2)) % 1000000007;
    }
    cout << ans*f<< endl;
  
}

Measured memory_bytes: 4480
a,b = (int(i) for i in input().split()) 
if a==1 or b ==1:
	if a==1 and b==1:
		print('Draw')
	elif a==1 and b != 1:
		print('Alice')
	elif a!=1 and b==1:
		print('Bob')
else:
	if a > b:
		print('Alice')
	elif b > a:
		print('Bob')
	elif a == b:
		print('Draw')
	else:
		pass

Measured memory_bytes: 3060
#include <cstdio>

int A,B,C;

int main(){
	
	scanf("%d%d%d",&A,&B,&C);
	
	if(A==B){
		printf("%d",C);
	}else if(A==C){
		printf("%d",B);
	}else{
		printf("%d",A);
	}
}


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

int mygcd(int a,int b, int c){
    if(0 == b%a && 0 == c%a){
        return a;
    }
    
    
    for(int i=a/2; i>=1; i--){
        if(0 == a%i && 0 == b%i && 0 == c%i){
            return i;
        }
    }
}

int main(void){
    // Your code here!"
    int sum=0,k;
    cin >> k;
    for(int a=1; a<=k; a++){
        for(int b=1; b<=k; b++){
            for(int c=1; c<=k; c++){
                sum += mygcd(a,b,c);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){ 
  long long n,ans=0;
  cin >> n;
  long long a[n]={},b;
  for(int i=0;i<n;i++){
    cin >> b;
    if(b>n){
      ans++;
    }else{
      a[b-1]++;
    }
  }
  for(int i=0;i<n;i++){
    if(a[i]>i+1){
      ans+=a[i]-i-1;
    }else if(a[i]<i+1){
      ans+=a[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 5e5 + 5;
const int logn = log2(maxn) + 1;
const int mod = 1e9 + 7;
int n , a[maxn];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(taskname".INP", "r")) {
        freopen(taskname".INP", "r", stdin);
        freopen(taskname".OUT", "w", stdout);
    }
    int res = 1e9;
    cin >> n;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i];
    }
    for(int i = -100 ; i <= 100 ; ++i){
        int ans = 0;
        for(int j = 1 ; j <= n ; ++j)ans += (a[j] - i) * (a[j] - i);
        res = min(ans , res);
    }
    cout << res;
}


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

using namespace std;
string result[8] = {"AAA", "AA", "A", "B", "C", "D", "E", "NA"};

void solve()
{
	double time1, time2;
	while(cin >> time1 >> time2)
	{
		int result1 = 0;
		int result2 = 0;
		if(time1 < 35.5)
		{
			result1 = 0;
		}
		else if(time1 < 37.5)
		{
			result1 = 1;
		}
		else if(time1 < 40.0)
		{
			result1 = 2;
		}
		else if(time1 < 43.0)
		{
			result1 = 3;
		}
		else if(time1 < 50.0)
		{
			result1 = 4;
		}
		else if(time1 < 55.0)
		{
			result1 = 5;
		}
		else if(time1 < 70.0)
		{
			result1 = 6;
		}
		else if(time1 >= 70.0)
		{
			result1 = 7;
		}

		if(time2 < 71.0)
		{
			result2 = 0;
		}
		else if(time2 < 77.0)
		{
			result2 = 1;
		}
		else if(time2 < 83.0)
		{
			result2 = 2;
		}
		else if(time2 < 89.0)
		{
			result2 = 3;
		}
		else if(time2 < 105.0)
		{
			result2 = 4;
		}
		else if(time2 < 116.0)
		{
			result2 = 5;
		}
		else if(time2 < 148.0)
		{
			result2 = 6;
		}
		else if(time2 >= 148.0)
		{
			result2 = 7;
		}
		if(result1 >= result2)
		{
			cout << result[result1] << endl;
		}
		else
		{
			cout << result[result2] << endl;
		}
	}
}

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

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
void print() {
    cout << endl;
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define zrep(i, a, b, c) for (int i = int(a); i < int(b); i+=int(c))

int main() {
    int L;
    cin >> L;
    printf("%.10lf\n", (double)L*L*L/27.0);
}

Measured memory_bytes: 3716
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <stdio.h>
#include <math.h>

#define LL long long
using namespace std;
int main(int argc, const char * argv[]) {
   int N;
   LL ans=1;
   cin>>N;
   LL mode=1;
   for (int i=0;i<9;i++) mode*=10;
   mode+=7;
   LL x[N],y[N];
   int ml=0,mr=N-1;
   for (int i=0;i<N;i++){
       cin>>x[i];
   }
   for (int i=0;i<N;i++){
       cin>>y[i];
   }
   for (int i=N-1;i>=1;i--){
       if (x[i]>x[i-1]){
          ml=i;
          break;
       }
   }
   for (int i=0;i<N-1;i++){
       if (y[i]>y[i+1]){
         mr=i;
         break;
       }
   }
   for (int i=1;i<N;i++){
     if (x[i]<x[i-1]) {
        cout<<"0"<<endl;
        return 0;
     }
   }
   for (int i=N-2;i>=0;i--){
      if (y[i]<y[i+1]){
          cout<<"0"<<endl;
          return 0;
      }
   }
   if (ml>mr) {
        cout<<"0"<<endl;
        return 0;
   }
   bool err=false;
   for (int i=0;i<ml;i++){
      if (x[i]>x[i+1] || y[i]<x[i]){
         err=true;
         break;
      }
   }
   if (err){
      cout<<"0"<<endl;
      return 0;
   }
   for (int i=N-2;i>mr;i--){
      if (y[i]<y[i+1] || x[i]<y[i]){
        err=true;
        break;
      }
   }
   if (err){
      cout<<"0"<<endl;
      return 0;
   }
   for (int i=ml;i<=mr;i++){
      if (x[i]!=y[i]){
         cout<<"0"<<endl;
         return 0;
      }
   }
   
   for (int i=1;i<ml;i++){
      if (x[i]!=x[i-1]){
          continue;
      }
      ans=(ans*x[i])%mode;
   }
   LL t=x[ml];
   for (int i=ml+1;i<=mr-1;i++){
        ans=(ans*t)%mode;
   }
   for (int i=N-2;i>mr;i--){
       if (y[i]!=y[i+1]){
          continue;
       }
       ans=(ans*y[i])%mode;
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 1920
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: i64,
    }
    let v = 1000000000;
    let x = (v - s % v) % v;
    let y = (s + x) / v;
    println!("0 0 {} 1 {} {}", v, x, y);

}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H(vector<int>&a){
    int ret=0,f=1;
    for(int i=a.size()-1;i>=0;i--){
        int cnt=0;
        for(int j=i;j<a.size();j++)if(a[i]>a[j])cnt++;
        ret+=f*cnt;
        f*=a.size()-i;
    }
    return ret;
}

void bfs(vint A,vint &cost){
    fill(all(cost),1001001001);
    cost[H(A)]=0;
    queue<vint>que;
    que.push(A);
    while(que.size()){
        vint a=que.front();
        que.pop();
        int h0=H(a);
        if(cost[h0]==4)break;
        for(int i=0;i<a.size();i++){
            for(int j=i+1;j<=a.size();j++){
                reverse(a.begin()+i,a.begin()+j);
                int h=H(a);
                if(cost[h]==1001001001){
                    cost[h]=cost[h0]+1;
                    que.push(a);
                }
                reverse(a.begin()+i,a.begin()+j);
            }
        }
    }
}

signed main(){
    int N;cin>>N;
    vector<int>A(N);
    rep(i,N)cin>>A[i];

    vector<int>B(N);
    rep(i,N)B[i]=i+1;

    vector<int>costA(3628800),costB(3628800);
    bfs(A,costA);bfs(B,costB);

    int ans=9;
    rep(i,3628800)chmin(ans,costA[i]+costB[i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 86612
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!long;
  foreach (h; 1L..3501L)
    foreach (m; h..3501L) {
      auto a = 4*h*m-n*(h+m);
      auto b = n*h*m;
      if (a > 0 && b % a == 0) {
        writeln(h, " ", m, " ", b/a);
        return;
      }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin >> x;
  vector<int> c(x);
  for(int i = 0;i < x;i++){
    int g;
    cin >> g;
    c.at(g-1) = i+1;
  }
  for(int i = 0;i < x;i++){
  cout << c.at(i);
    if(i==x-1)break;
    cout << " ";
  }
  cout << endl;    
  
}

Measured memory_bytes: 1152
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect
from itertools import accumulate

n,x=nii()
a=lnii()
a.sort()

b=list(accumulate(a))

if b[-1]<x:
  print(n-1)
else:
  inx=bisect(b,x)
  print(inx)

Measured memory_bytes: 9124
k = int(input())
ans = 'OK'
a, b = map(int, input().split())
if b-a+1 >= k:
    ans = 'OK'
else:
    for i in range(a, b+1):
        if i%k == 0:
            ans = 'OK'
            break
        else:
            ans = 'NG'
print(ans)

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

using namespace std;

const int N = 105;
                           
char a[N][N], b[2 * N][N];

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) { 
	  string str;
	  cin >> str;
	  for (int j = 1; j <= m; j++) {
	    a[i][j] = str[j - 1];
	  }
	}
	for (int i = 1; i <= 2 * n; i++) {
	  for (int j = 1; j <= m; j++) {
	    b[i][j] = a[(i + 1) / 2][j];
    }
  }
  for (int i = 1; i <= 2 * n; i++) {
    for (int j = 1; j <= m; j++) {
      putchar(b[i][j]);
    }
    putchar('\n');
  }
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            pass
        else:
            print("DENIED")
            break
else:
    print("APPROVED")

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

int main(){
    int n; cin >> n;
    vector<double> a(n);
    for(int i = 0; i < n; i++){
        int mid; cin >> mid;
        a[i] = mid;
    } 
    sort(a.begin(), a.end());
    double b = (a[0] + a[1]) / 2;
    for(int i = 2; i < n; i++){
        b = (b + a[i]) / 2;
    }
    cout << b << endl;
}

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

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] H = new int[N];
		for (int i = 0; i < N; i++) {
			H[i] = sc.nextInt();
		}
		int[] dp = new int[N];
		Arrays.fill(dp, (int)2e9);
		dp[0] = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 1; j <= K && i + j < N; j++) {
				if (dp[i] + Math.abs(H[i] - H[i + j]) < dp[i + j]) {
					dp[i + j] = dp[i] + Math.abs(H[i] - H[i + j]);
				}
			}
		}
		System.out.println(dp[N - 1]);
	}

}


Measured memory_bytes: 51128
#include<stdio.h>
int main()
{
    int A,B,max;
    input:
    scanf("%d%d",&A,&B);

    if(-100<=A&&100>=A&&-100<=B&&100>=B){
    if((A+B)>(A-B)){
        if((A+B)>(A*B))
            max=A+B;
        else
            max=A*B;
    }
    else{
        if((A-B)>(A*B))
            max=A-B;
        else
            max=A*B;
    }
    printf("%d",max);
    }
    else
        goto input;

    return 0;
}

Measured memory_bytes: 128
open System

// prelude
let readStr () = stdin.ReadLine()

let read f () = readStr() |> f
let reads f () = readStr().Split() |> Array.map f

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let readPair f g () =
  let (a,b) = readStr().Split() |> pair
  (f a, g b)

let readTriple f g h () =
  let (a,b,c) = readStr().Split() |> triple
  (f a, g b, h c)

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let (N,K) = readPair int int64 ()
let A = reads int () |> Array.map dec

let cnt =
  let rec greedy i k =
    if k=0L then i else greedy A.[i] (k-1L)
  let rec inner map i k =
    if k=0L then i
    elif Map.containsKey i map then
      let d = (Map.find i map) - k
      greedy i (k%d)
    else
      let map' =
        map
        |> Map.add i k
      inner map' A.[i] (k-1L)
  fun i k -> inner Map.empty i k

cnt 0 K |> inc |> printfn "%d"

Measured memory_bytes: 65348
import numpy as np
a,b = map(int, input().split())
mod = 2019
min_score = 2019

for i in range(a, b+1):
    for j in range(a, b+1):
        if i != j:
            temp = (i%mod)*(j%mod) %mod
            if min_score > temp:
                min_score = temp
            if min_score == 0:
                print(min_score)
                exit()

print(min_score)

Measured memory_bytes: 14436
x = int(input())
a = 1
flag = True
while flag:
  upper = a**5-x
  b = a
  while True:
    if b**5 == upper:
      flag = False
      a -= 1
      break
    if b**5<upper:
      break
    b -= 1
  a += 1
print(a,b)

Measured memory_bytes: 63712
#include <stdio.h>

#define Mod 1000000007

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long combination(long long n, long long k)
{
	long long i, x, y;
	for (i = n, x = 1; i >= n - k + 1; i--) x = x * i % Mod;
	for (i = 2, y = 1; i <= k; i++) y = y * i % Mod;
	return div_mod(x, y, Mod);
}

int factorize(int n, int p[], int m[])
{
	int i, k;
	for (i = 2, k = 0; i * i <= n; i++) {
		if (n % i != 0) continue;
		p[k] = i;
		for (m[k] = 0; n % p[k] == 0; m[k]++, n /= p[k]);
		k++;
	}
	if (n > 1) {
		p[k] = n;
		m[k++] = 1;
	}
	return k;
}

int main()
{	
	int N, M;
	scanf("%d %d", &N, &M);
	if (N == 1 || M == 1) {
		printf("1\n");
		fflush(stdout);
		return 0;
	}

	int i, k, p[100], m[100];
	long long ans = 1;
	k = factorize(M, p, m);
	for (i = 0; i < k; i++) ans = ans * combination(N + m[i] - 1, m[i]) % Mod;
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1732
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

char S[300050];

int main() {
  scanf("%s", S);
  const int n = strlen(S);

  Int res = 0;
  int blk = 0;
  for (int i = 0; i < n; ++i) {
    if (S[i] == 'B') {
      ++blk;
    } else {
      res += blk;
    }
  }
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  int cnt=0;
  int a,b,c;
  cin >> x;
  a=x/100;
  b=(x%100)/10;
  c=((x%100)%10);
  if(a*1!=0)cnt++;
  if(b*1!=0)cnt++;
  if(c*1!=0)cnt++;
  cout << cnt <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define N 200010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}

string s,rs;
int n;

signed main(){
  cin>>rs; s = rs;
  n = s.size();
  int ans =1+ n * (n-1)/2;
  int cnt[26] = {};
  for(char i:s) cnt[i-'a']++;
  for(int i=0;i<26;i++) ans -= cnt[i] * (cnt[i]-1) / 2;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 772
#include <cassert>
#include <cstdint>
#include <utility>
#include <vector>
 
class UnionFind {
 
public:
  using size_type = std::uint_fast32_t;
 
private:
  std::vector<std::pair<bool, size_type>> tree;
 
public:
  UnionFind(const size_type size) : tree(size, std::make_pair(1, 1)) {}
  size_type find(const size_type x) {
    assert(x < size());
    if (tree[x].first)
      return x;
    return tree[x].second = find(tree[x].second);
  }
  bool unite(size_type x, size_type y) {
    assert(x < size());
    assert(y < size());
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (tree[x].second < tree[y].second)
      std::swap(x, y);
    tree[x].second += tree[y].second;
    tree[y] = std::make_pair(0, x);
    return true;
  }
  bool same(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return find(x) == find(y);
  }
  size_type size(const size_type x) {
    assert(x < size());
    return tree[find(x)].second;
  }
  size_type size()const noexcept {
    return tree.size();
  }
};
 
#include<iostream>
int main(void) {
	int n, q;
	std::cin >> n >> q;
	UnionFind T(n);
	while (q--) {
		int p, a, b;
		std::cin >> p >> a >> b;
		if (p) {
			std::cout << (T.same(a, b) ? 1 : 0) << std::endl;
		}
		else {
			T.unite(a, b);
		}
	}
	return 0;
}


Measured memory_bytes: 3196
#include<iostream>
using namespace std;
int main(){
int n,m;
scanf("%d %d",&n,&m);
char arr[n][n];
char arr1[m][m];
for(int i=0;i<n;i++)
scanf("%s",arr[i]);
for(int i=0;i<m;i++)
scanf("%s",arr1[i]);
for(int i=0;i<n ;i++){
	for(int j=0 ;j<n;j++){
		int cnt=0;
		for(int a=0;a<m ;a++){
			for(int b=0;b<m;b++){
				if(arr1[a][b]==arr[i+a][j+b])
				cnt++;
			}
		}
		if(cnt==(m*m)){
		return( cout<<"Yes" ,      0);
			
		}
		
	}
}
printf("No\n");
return 0;
}

Measured memory_bytes: 256
[a,b,c]=[int(inp) for inp in input().split()]
#if a*a+b*b+c*c -2*(a*b+b*c+c*a) > 0:
if c - a - b < 0 or a*(a-2*b)+b*(b-2*c)+c*(c-2*a)<=0:
    print("No")
else:
    print("Yes")

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

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int j[4]={};
	if(a==b) j[0]=j[1]=1;
	if(a==c) j[0]=j[2]=1;
	if(a==d) j[0]=j[3]=1;
	if(b==c) j[1]=j[2]=1;
	if(b==d) j[1]=j[3]=1;
	if(c==d) j[2]=j[3]=1;
	if(j[0]==1&&j[1]==1&&j[2]==1&&j[3]==1) cout<<"yes"<<endl;
	else cout<<"no"<<endl;
	return 0;
}


Measured memory_bytes: 3096
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

from statistics import median

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

n = int(input())
AB = []
for _ in range(n):
    AB.append(get_nums_l())
A = [ ab[0] for ab in AB ]
B = [ ab[1] for ab in AB ]

if n%2 == 1:
    min_of_med = median(A)
    max_of_med = median(B)
    print(max_of_med - min_of_med + 1)

else:
    A.sort()
    B.sort()
    min_of_med = A[n//2 - 1] + A[n//2]
    max_of_med = B[n//2 - 1] + B[n//2]
    print(max_of_med - min_of_med + 1)


Measured memory_bytes: 137512
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static int[] S ;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		String[] Ws = W.split(" ");

		long a = Long.parseLong(Ws[0]);
		long b = Long.parseLong(Ws[1]);

		String A = "";
		String B = "";
		for(int i=0;i<b;i++){
			A+=String.valueOf(a);
		}

		for(int i=0;i<a;i++){
			B+=String.valueOf(b);
		}

		System.out.println(A.compareTo(B)<=0?A:B);
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
signed main()
{
	int n,k;
	cin>>n>>k;
	vector<int>v;int gab;
	for (int i=0;i<k;i++){
		cin>>gab;
		v.pb(gab);
	}
	for (int i=0;;i++){
		if (find(all(v),n-i)==v.end()){
			cout<<n-i;
			re 0;
		}
		if (find(all(v),n+i)==v.end()){
			cout<<n+i;
			re 0;
		}
	}
	re 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

vector<int> plist;
bool IsPrimeFromPlist(ll x){
  for(auto e:plist){
    if(e*e>x)break;
    if(x%e==0)return false;
  }
  return true;
}
void Mkplist(){
  plist.push_back(2);
  for(int i = 3; i <= 65000; ++i){
    if(IsPrimeFromPlist(i))plist.push_back(i);
  }
}

int main(){
  Mkplist();
  int n; cin >> n;
  vector<int> v;
  for(auto e:plist){
    if(e%5==1)v.push_back(e);
  }
  for(int i = 0; i < n; ++i){
    if(i)cout << ' ';
    cout << v[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
/**
 *   author:  prakhar17252
 *   created: 27.04.2019 18:24:10
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
#define int ll

#define pb emplace_back
#define push emplace
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define len(a) (int) a.size()
#define reset(a, val) memset(a, val, sizeof(a))
#define endl '\n'
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

const ll mod = (int) 1e9 + 7;
const ll inf = (ll) 2e18;
const ll ninf = (ll) -2e18;

ll power(ll x, ll y, ll mod = inf) {
    if (y == 0) return 1LL;
    if (y % 2) return ((x % mod) * power(x, y - 1, mod)) % mod;
    return power((x * x) % mod, y / 2, mod);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    time_t t1, t2;
    t1 = clock();

    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    //     freopen("error.txt", "w", stderr);
    // #endif

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

    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > 0) {
            ans += a[i];
        }
    }

    cout << ans << '\n';

    t2 = clock();
    #ifndef ONLINE_JUDGE
        cerr << endl << "time taken: " << (ld) (t2 - t1) / CLOCKS_PER_SEC << endl;
    #endif // ONLINE_JUDGE

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> C(N-1), S(N-1), F(N-1);
  for (int i = 0; i < N-1; i++) {
    cin >> C[i] >> S[i] >> F[i];
  }
  for (int i = 0; i < N; i++) {
    int t = 0;
    for (int j = i; j < N-1; j++) {
      if (t < S[j]) t += S[j] - t;
      else t += t % F[j] == 0 ? 0 : F[j] - t % F[j];
      t += C[j];
    }
    cout << t << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int main()
{
	LL a,b,c,x,y,ans=0;
	scan(a,b),scan(c);
	scan(x,y);
	c=min(c+c,a+b);
	
	if(x<y)
		swap(x,y),swap(a,b);
	ans+=y*c;
	x-=y;
	ans+=x*min(a,c);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int n,d,i,max=-1000000,min=1000000;
long sum=0;
scanf("%d",&i);
for(n=0;n<i;n++){
scanf("%d ",&d);
if(d>max){max=d;}
if(min>d){min=d;}
sum+=d;
}
printf("%d %d %ld\n",min,max,sum);
return 0;
}

Measured memory_bytes: 604
#include<stdio.h>

int main(){
  int i,n;
  while(scanf("%d",&n)){
    if (n==0)
      break;
    int cnt=0,fac=1;
    while (n>=5){
      cnt+=n/5;
      n=n/5;
      }
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
int n, h, w;
struct NODE{
	LL a;
	int r, c;
	inline bool operator < (const NODE &tmp) const
	{
		return a > tmp.a;
	}
}t[100010];
int fa[200010];
LL val[200010];

int find(int x)
{
	if(x == fa[x]) return x;
	return fa[x] = find(fa[x]);
}


int main()
{
	scanf("%d%d%d", &n, &h, &w);
	for (register int i = 1;i <= n;i ++) scanf("%d%d%lld", &t[i].r, &t[i].c, &t[i].a);
	sort(t + 1, t + n + 1);
	for (register int i = 1;i <= h + w;i ++)
	{
		fa[i] = i;
		val[i] = 1;
	}
	LL ans = 0;
	for (register int i = 1;i <= n;i ++)
	{
		int xx = find(t[i].r), yy = find(t[i].c + h);
//		printf("xx = %d, yy = %d\n", xx, yy);
		if(xx == yy)
		{
			if(val[xx])
			{
				val[xx] --;
				ans += t[i].a;
			}
		}
		else
		{
			if(val[xx] + val[yy])
			{
				val[xx] += val[yy];
				val[xx] --;
				fa[yy] = xx;
				ans += t[i].a;
			}
		}
//		printf("ans = %lld, val[xx] = %lld, val[yy] = %lld\n", ans, val[xx], val[yy]);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 9380
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <iomanip>

using namespace std;

double dp[301][301][301];

double expect(int N, int one, int two, int three){

    if(one == 0 && two == 0 && three == 0){
        return 0.0;
    }

    double temp = dp[one][two][three];
    if(temp >= 0.0){
        return temp;
    }

    int rest = one + two + three;
    double ret = (double)N / rest;

    if(one > 0){
        ret += expect(N, one - 1, two, three) * one / rest;
    }
    if(two > 0){
        ret += expect(N, one + 1, two - 1, three) * two / rest;
    }
    if(three > 0){
        ret += expect(N, one, two + 1, three - 1) * three / rest;
    }

    dp[one][two][three] = ret;
    return ret;
}

int main(){

    int N;
    cin >> N;
    int one, two, three;
    one = 0;
    two = 0;
    three = 0;

    int a;
    for(int i = 0; i < N; i++){
        cin >> a;
        if(a == 1){
            one++;
        }
        else if(a == 2){
            two++;
        }
        else{   // a == 3
            three++;
        }
    }

    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            for(int k = 0; k <= N; k++){
                dp[i][j][k] = -1.0;
            }
        }
    }

    double ans = expect(N, one, two, three);

    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 213376
/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MAX = 1024;

int main(void) {
	// in = fopen("A.in", "rt");
	
	int n, w, h;
	fscanf(in, "%d %d %d", &n, &w, &h);
	fprintf(out, "%d\n", (n - w + 1) * (n - h + 1));
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stack>
using namespace std;
 
int main() {
  int n;
  stack<int> st;
  while (cin>>n) {
    if (n == 0) {
      cout << st.top() << endl;
      st.pop();
    } else {
      st.push(n);
    }
  }
  return 0;
}

Measured memory_bytes: 3028
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
//#include "h.h"
using namespace std;

#define MOD 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first), (second) pb(mp(first), (second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	ll N;
	cin >> N;
	vector<ll> A(N);
	for(ll i = 0; i < N; i ++){
		cin >> A[i];
	}
	ll b;
	for(ll i = 0; i < N; i ++){
		cin >> b;
		A[i] -= b;
	}
	ll plusNum = 0, minusNum = 0;
	for(ll i = 0; i < N; i ++){
		if(A[i] <= 0){
			plusNum += (-A[i]) / 2;
		}
		else minusNum += A[i];
	}
	if(plusNum < minusNum)cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(){
	int n,x;
	scanf("%d %d", &n, &x);
	int i;
	int ans=1;
	int loc=0;
	int move;
	for(i=0; i<n; i++){
		scanf("%d", &move);
		loc+=move;
		if(loc<=x){
			ans++;
		}
	}
	printf("%d", ans);
	
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner input = new Scanner (System.in);
        int H,W,i,j;
        while(true){
            H = input.nextInt();
            W = input.nextInt();
            if(H == 0 && W == 0)break;
                for(i=0;i<H;i++){
                  for(j=0;j<W;j++){
                    System.out.print("#");
                  }
                System.out.println();
                }
            System.out.println();
        }
        
    }
}


Measured memory_bytes: 35464
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(int argc, const char *argv[])
{
  long long a, b, c;
  cin >> a >> b >> c;

  if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
    cout << 0 << '\n';
    return 0;
  }

  if (a == b && b == c) {
    cout << -1 << '\n';
    return 0;
  }

  long long ans = 0;
  while (a % 2 != 1 && b % 2 != 1 && c % 2 != 1) {
    long long tmp1 = a, tmp2 = b, tmp3 = c;
    a = (tmp2 + tmp3) / 2;
    b = (tmp1 + tmp3) / 2;
    c = (tmp1 + tmp2) / 2;
    ans++;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;
        
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        
        int count = 0;

        while (true) {
            if (a < b) {
                break;
            }
            b = b * 2;
            count++;
        }
        while (true) {
            if (b < c) {
                break;
            }
            c = c * 2;
            count++;
        }
        if (k < count) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 35616
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(int arg_a,int arg_b){
		a = arg_a;
		b = arg_b;
	}
	int a,b;
};

int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	vector<Info> info;

	ll tmp = (M+1)/2;

	for(int i = 0; i < tmp; i++){

		info.push_back(Info(tmp-(i+1),tmp+i));
	}

	int tmp2 = M-tmp;
	for(int i = 0; i < tmp2; i++){

		info.push_back(Info(2*tmp+tmp2-(i+1),2*tmp+tmp2+(i+1)));
	}

	for(int i = 0; i < info.size(); i++){

		printf("%d %d\n",info[i].a+1,info[i].b+1);
	}

	return 0;
}


Measured memory_bytes: 4344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int h, w;
    cin >> h >> w;
    int black = 0;
    char maze[h][w];
    int dis[h][w];
    rep(i,h) fill(dis[i], dis[i]+w, inf);
    rep(i,h)rep(j,w){
        cin >> maze[i][j];
        if(maze[i][j]=='#') black++;
    }
    queue<P> q;
    q.push(P(0,0));
    dis[0][0] = 1;
    while(!q.empty()){
        P p = q.front();
        q.pop();
        int x = p.first;
        int y = p.second;

        rep(i,4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx>=0&&nx<h&&ny>=0&&ny<w&&maze[nx][ny]=='.'&&dis[nx][ny]==inf){
                dis[nx][ny] = dis[x][y] + 1;
                q.push(P(nx, ny));
            } 
        }
    }
    if(dis[h-1][w-1]==inf) cout << -1 << endl;
    else cout << h*w-black-dis[h-1][w-1];
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		
		int H=sc.nextInt();
		int W=sc.nextInt();
		String P[]=new String[H];
		//输入
		for(int i=0;i<H;i++) {
		
			P[i]=sc.next();
		}
		for(int i=0;i<H;i++) {
			System.out.println(P[i]);
			System.out.println(P[i]);
		}
	}

}

Measured memory_bytes: 23288
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	ll N;
	cin >> N;
	ll i = 1;
	ll a = 0;
	ll b = 0;
	while(i*i<=N) {
		if(N%i==0) {
			a = i;
			b = N/i;
		}
		i++;
	}

	cout << a + b -2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long
ll gcd(ll a,ll b){
    ll s=1,c;
    while(a&&b){
        if((~a&1)&&(~b&1))
            a>>=1,b>>=1,s<<=1;
        else if(~a&1)a>>=1;
        else if(~b&1)b>>=1;
        else if(a>b)a=a-b;
        else c=b-a,b=a,a=c;
    }
    if(!a)return b*s;
    if(!b)return a*s;
}
using namespace std;
int main(){
	ll ans=0;
	int s[100001]={0};
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		s[a[i]]++;
	}
	int m;
	cin>>m;
	int b[m],c[m];
	for(int i=0;i<m;i++){
		cin>>b[i]>>c[i];
	}
	for(int i=1;i<=100000;i++){
		ans+=s[i]*i;
	}
	for(int i=0;i<m;i++){
		ans+=s[b[i]]*(c[i]-b[i]);
		s[c[i]]+=s[b[i]];
		s[b[i]]=0;
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 5148
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N);
	ll cnt=0;
	ll sm = 0;
	ll mini = 100000000;
	rep(i,0,N){
		cin >> A[i];
		if(A[i] < 0){
			cnt++;
		}
	}
	if(cnt%2 == 0){
		rep(i,0,N){
			sm += abs(A[i]);
		}
		cout << sm << endl;
	}else{
		rep(i,0,N){
			sm += abs(A[i]);
		}
		rep(i,0,N){
			mini = min(mini,abs(A[i]));
		}
		sm -= (ll)mini*2;
		cout << sm << endl;
	}

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <fstream>
#include <stdlib.h>
#include <ctime>
using namespace std;
typedef long long ll;
int n=0;
int a[300000];
int last[300000];
ll dp[300000];
ll p=1e9+7;
int main(){
    //ios_base::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int k=0;k<300000;k++){
        last[k]=-1;
    }
    dp[0]=1;
    last[a[0]]=0;
    for(int i=1;i<n;i++){
        if(last[a[i]]==-1||last[a[i]]==i-1){
            dp[i]=dp[i-1];
        }
        else{
            dp[i]=dp[i-1]+dp[last[a[i]]];
            dp[i]%=p;
        }
       // cout<<dp[i]<<" ";
        last[a[i]]=i;
    }
    //cout<<endl;
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n;
  string s;
  cin >> n >> s;
  string ln,rn;
  int l = 0,r = 0;
  rep(i,n){
    if(s.at(i) == '(') l++;
    else{
      if(l == 0){
        ln.push_back('(');
      }else l--;
    }
  }
  for(int i=n-1;i>=0;i--){
    if(s.at(i) == ')') r++;
    else{
      if(r == 0){
        rn.push_back(')');
      }else r--;
    }
  }
  cout << ln + s + rn << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	string str;
	cin>>N>>str;
	map<pair<string,string>,int> dicN;
	pair<string,string> dat;
	for(int s=0;s<(1<<N);++s){
		string A="";
		string B="";
		for(int i=0;i<N;++i){
			if( s&(1<<i) ){
				B = str[i] + B;
			}else{
				A+= str[i];
			}
		}
		dat.first = A;
		dat.second = B;
		dicN[dat]++;
	}
	LL ans = 0;
	
	for(int s=0;s<(1<<N);++s){
		string A="";
		string B="";
		for(int i=0;i<N;++i){
			if( s&(1<<i) ){
				B = str[N*2-1-i] + B;
			}else{
				A+= str[N*2-1-i];
			}
		}
		dat.first = A;
		dat.second = B;
		LL res = dicN[dat];
		ans += res;
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 87040
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int find(int a) {

}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n, q;
        string s;
        cin >> n >> q;
        cin >> s;
        char t[q], d[q];
        rep(i, q) cin >> t[i] >> d[i];

        ll is = -1;
        ll ie = n;
        WHILE:
        while (ie - is > 1) {
            ll m = (is + ie) / 2;
            ll tmp = m;
            char now = s[tmp];
            rep(i, q) {
                if (t[i] == now) {
                    if (d[i] == 'L') now = s[--tmp];
                    else now = s[++tmp];
                }
                if (tmp == -1) {
                    is = m;
                    goto WHILE;
                } else if (tmp == n) {
                    ie = m;
                    goto WHILE;
                }
            }
            ie = m;
        }
        ll ans = n;
        ans -= is;
        is = -1;
        ie = n;
        WHILE2:
        while (ie - is > 1) {
            ll m = (is + ie) / 2;
            ll tmp = m;
            char now = s[tmp];
            rep(i, q) {
                if (t[i] == now) {
                    if (d[i] == 'L') now = s[--tmp];
                    else now = s[++tmp];
                }
                if (tmp == -1) {
                    is = m;
                    goto WHILE2;
                } else if (tmp == n) {
                    ie = m;
                    goto WHILE2;
                }
            }
            is = m;
        }
        ans -= (n + 1 - ie);
        cout << ans << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 900
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def count_v(last_d, C, S, t, d):
    ret = S[t - 1]
    last_d[t - 1] = d
    for i in range(len(last_d)):
        ret -= C[i] * (d - last_d[i])
    return ret


def count_v_virtual(last_d, C, S, t, d):
    ret = S[t]
    tmp = last_d[t]
    last_d[t] = d
    for i in range(len(last_d)):
        ret -= C[i] * (d - last_d[i])
    last_d[t] = tmp
    return ret


def main():
    D = int(input())
    C = inpl()
    Ss = [inpl() for _ in range(D)]
    T = [int(input()) for _ in range(D)]
    M = int(input())
    DQ = [inpl() for _ in range(M)]
    last_d = [-1] * len(C)
    Contest = 26

    v = 0
    for d in range(D):
        tmp = count_v(last_d, C, Ss[d], T[d], d)
        v += tmp
        # print(v)

    for d, q in DQ:
        diff = 0
        original_t = T[d - 1]
        last_d_q = 0
        last_d_ori = 0
        for i in range(d):
            if T[i] == q:
                last_d_q = i + 1
            if T[i] == original_t and i < d - 1:
                last_d_ori = i + 1
        # print(d, q, original_t, last_d_q, last_d_ori)
        for i in range(d - 1, D):
            if T[i] == q:
                break
            diff += C[q - 1] * (d - last_d_q)
        # print(diff, C[q - 1])
        T[d - 1] = q
        for i in range(d - 1, D):
            if T[i] == original_t:
                break
            diff -= C[original_t - 1] * (d - last_d_ori)
        # print(C[original_t - 1], diff)
        v += diff + Ss[d - 1][q - 1] - Ss[d - 1][original_t - 1]
        print(v)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 85140