akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
namespace DS
{
    class Program
    {
        static void Main(string[] args)
        {
           
           int n = Convert.ToInt32(Console.ReadLine());
            List<List<int>> task = new List<List<int>>();

            for (int i = 0; i < n; i++)
            {
                string[] tasksPerDay = Console.ReadLine().Split(' ');
                List<int> taskDayI = new List<int>();
                for(int j=0;j<3;j++)
                {
                    taskDayI.Add(Convert.ToInt32(tasksPerDay[j]));
                }
                task.Add(taskDayI);
            }
          int maxValue = 0;

            if(n==1)
            {
                maxValue = Math.Max(task[0][0], Math.Max(task[0][1], task[0][2]));
            }

            for(int i=1;i<n;i++)
            {
                for(int j=0;j<3;j++)
                {
                    int t = task[i][j];
                    for(int k=0;k<3;k++)
                    {
                        if (j != k)
                            task[i][j] = Math.Max(task[i][j], t + task[i - 1][k]);
                    }
                    if (i == n - 1)
                        maxValue = Math.Max(maxValue, task[i][j]);
                }
            }
            
            Console.WriteLine(maxValue);
        }
    }
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    int m = max({a, b, c});
    int temp = m;
    for (int i = 0; i < k; i++)
        temp *= 2;
    cout << a + b + c - m + temp << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  int64_t pp = 2;
  int64_t p = 1;
  int64_t cur = 3;
  
  for(int i = 2; i < n; i++) {
    int64_t tmp = pp;
    pp = p;
    p = cur;
    cur = pp + p;
  }
  
  if(n == 0) {
    cout << pp << endl;
  } else if(n == 1) {
    cout << p << endl;
  } else cout << cur << endl;
}

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

using namespace std;


int p[20005];
int A[20005];
int B[20005];
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int a;
        scanf("%d", &a);
        A[a] += i + 1;
        A[i + 1] += 25000 * (i + 1);
    }
    for (int i = 1; i <= n; ++i) B[i] =  25000 * (n - i + 1);

    for (int i = 1; i < n; ++i) printf("%d ", A[i]);
    printf("%d\n", A[n]);
    for (int i = 1; i < n; ++i) printf("%d ", B[i]);
    printf("%d\n", B[n]);


    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
#define ll long long

int main() {
	int s[200000], a[200000], b[200000];
	ll hoge, l, min, ac, bc;
	char hogehoge[200000];
	scanf("%s", hogehoge);
	l = strlen(hogehoge);
	for (int i = 0; i < l; i++) {
		if (hogehoge[i] == '1')s[i] = 1;
		else s[i] = 0;
	}
	for (int i = 0; i < l; i++) {
		if (i % 2 == 0) {
			a[i] = 0;
			b[i] = 1;
		}
		else {
			a[i] = 1;
			b[i] = 0;
		}
	}
	ac = 0;
	bc = 0;
	for (int i = 0; i < l; i++) {
		if (s[i] != a[i])ac++;
		if (s[i] != b[i])bc++;
	}
	if (ac < bc)cout << ac << endl;
	else cout << bc << endl;

}

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

int main(){
    string s;
    cin >> s;
    int w;
    cin >> w;
    string t;
    int c = 0;
    while(c < s.length()){
        t += s[c];
        c += w;
    }
    cout << t << endl;
    return 0;
} 

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

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

    if (D == 25)
    {
        cout << "Christmas\n";
    }
    else if (D == 24)
    {
        cout << "Christmas Eve\n";
    }
    else if (D == 23)
    {
        cout << "Christmas Eve Eve\n";
    }
    else if (D == 22)
    {
        cout << "Christmas Eve Eve Eve\n";
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int n,age[7],i,temp;
    while (scanf("%d",&n)!=EOF&&n!=0) {
        for (i=0; i<7; i++) age[i]=0;
        for (i=0; i<n; i++) {
            scanf("%d",&temp);
            temp/=10;
            if (temp>=7) temp=6;
            age[temp]++;
        }
        for (i=0; i<7; i++) printf("%d\n",age[i]);
    }
    return 0;
}

Measured memory_bytes: 600
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	vi arr(n);
	for(int &i:arr)cin>>i;
	sort(arr.rbegin(),arr.rend());
	ll ans=1;
	int cnt = 0;
	for(int i=0;i<n-1;i++) {
		if(arr[i]==arr[i+1])ans*=arr[i],i++,cnt++;
		if(cnt==2)break;
	}
	if(cnt!=2)cout<<0;
	else
	cout<<ans;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3672
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int i,N,X[200001],Y[200001];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&X[i]);
    Y[i] = X[i];
  }
  sort(X,X+N);
  for(i=0;i<N;i++){
    if(X[(N+1)/2] <= Y[i] ){
      printf("%d\n",X[N/2 -1]);
    }else
      printf("%d\n",X[N/2]);
  }

}


Measured memory_bytes: 3712
s = input()
t = input()

def LCS(X,Y):
    XL = len(X)
    YL = len(Y)
    dp = [[0 for j in range(YL+1)] for i in range(XL+1)]
    for i in range(XL):
        for j in range(YL):
            if X[i] == Y[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
    # 以下復元
    S = ''
    i,j = i+1,j+1
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            i,j = i-1,j-1
            S += X[i]
    S = S[::-1]
    return S

print(LCS(s,t))



Measured memory_bytes: 120028
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int (i)=(a);(i)<(b);++(i))
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cout<<#x<<"="<<(x)<<endl;
#define DBG(v) REP(i, LEN((v))) cout<<(v)[i]<<(i==LEN((v))-1 ? '\n' : ' ')
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<vector<int>> vii;
typedef vector<vector<lint>> vll;

class CAlchemist {
public:
    int N;
    priority_queue<double, vector<double>, greater<double>> pq;

    void input(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in>>N;
        REP(i, N){
            int a;
            in>>a;
            pq.push(a);
        }
    }

    void solve(std::istream& in, std::ostream& out) {
        input(in, out);
        while(1<LEN(pq)){
            double a, b;
            a = pq.top(); pq.pop();
            b = pq.top(); pq.pop();
            pq.push((a+b)/2);
        }
        out<<fixed<<setprecision(12)<<pq.top()<<'\n';
    }
};


int main() {
	CAlchemist solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,j,n,k;
    scanf("%d",&n);
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {
            k=i*j;
            if(k==n)
            {
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");
}


Measured memory_bytes: 1716
import datetime
while 1:
    y1,m1,d1,y2,m2,d2=map(int,input().split())
    if y1==-1:break
    d1 = datetime.date(y1, m1, d1)
    d2 = datetime.date(y2, m2, d2)
    print((d2-d1).days)


Measured memory_bytes: 6036
//
// Created by 10940 on 2020/7/25.
//

#include <bits/stdc++.h>

using namespace std;
typedef unsigned long long ULL;
const int MAX_N = 1e5;

int main() {
    ULL N, D;
    int ans = 0;
    cin >> N >> D;
    D *= D;
    while (N--) {
        int x, y;
        cin >> x >> y;
        ULL a = abs(x);
        ULL b = abs(y);
        ULL t = a * a + b * b;
        if (t <= D) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

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

    int n, ans = 0;
    string s;

    cin >> n >> s;
    for (int i = 0; i < n - 1; ++i) {
        vector<bool> cnt(27, false);
        for (int j = 0; j <= i; ++j) cnt[(int)(s[j] - 'a')] = true;

        int num = 0;
        for (int j = i + 1; j < n; ++j)
            if (cnt[(int)(s[j] - 'a')]) {
                ++num;
                cnt[(int)(s[j] - 'a')] = false;
            }
        ans = max(ans, num);
    }

    cout << ans << endl;

    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 h, w;
  while(1){
    cin >> h >> w;
    if(h+w==0) break;
    else{
      rep(i, h){
        rep(j, w){
          if((i+j)%2==0) cout << "#";
          else cout << ".";
        }
        cout << endl;
      }
    }
    cout << endl;
  }

}




Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main(){
    string str;
    cin >> str;
    int sz;
    sz = str.size();
    int ans;
    ans = str[sz-1]-'0';
    if(ans==2 || ans==4 || ans==5 || ans==7 || ans==9 ){
        cout << "hon" << endl;
    }else if(ans==0 || ans==1 || ans==6 || ans==8){
        cout << "pon" << endl;
    }else if(ans==3){
        cout << "bon" << endl;
    }
}




Measured memory_bytes: 3628
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include <math.h>
#include <string> 
using namespace std;

int main()
{
	int H,W,cut_h,cut_w,count=0;
	cin>>H>>W>>cut_h>>cut_w;
	count = (H-cut_h) * (W-cut_w);
	cout<<count;
}

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int n;
  i64 x;
  cin >> n >> x;
  vector<i64> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(all(a));

  int i = 0;
  while(x > 0 && i < n) {
    x -= a[i];
    ++i;
  }
  if(x < 0) --i;
  if(x > 0) --i;
  cout << i << endl;
}


Measured memory_bytes: 384
import sys

if __name__ == "__main__":
    line1 = sys.stdin.readline().strip()
    X = int(line1)

    A = 120
    while A >= -120:
        A -= 1

        B = 120

        isEnd = False
        while B >= -120:
            B -= 1

            if A ** 5 - B ** 5 == X:
                print("{0} {1}".format(A, B))
                isEnd = True
                break

        if isEnd:
            break



Measured memory_bytes: 9124
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s:String = read();
    let c:Vec<char> = s.chars().collect();
    let mut ans = "Yes";
    for i in 0..s.len() {
        match c[i] {
            'U' => (),
            'D' => (),
            'R' => {
                if (i+1) % 2 != 0 {()} else {ans = "No"}
            },
            'L' => {
                if (i+1) % 2 == 0 {()} else {ans = "No"}
            },
            _ => ()
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2160
#include <stdio.h>
#include <string.h>

int main(void){
        char s[11];
        int num;
        int i,j,k,count=0;

        scanf("%s",s);
        scanf("%d",&num);

        char ring[num][101];

        for(i=0; i<num; i++){
                scanf("%s",ring[i]);
        }
        for(i=0; i<num; i++){
                k=0;
                for(j=0; j<2*strlen(ring[i]); j++){
                        k=0;
                        if(ring[i][j]==s[k]){
                                if(strlen(s)==1){
                                        count++;
                                        i++;
                                        j=-1;
                                }
                                for(k=1; k<strlen(s); k++){
                                        if(s[k]==ring[i][(j+k)%strlen(ring[i])]){
                                                if(k+1==strlen(s)){
                                                        count++;
                                                        i++;
                                                        j=-1;
                                                }
                                        }else
                                                break;
                                }
                        }
                }
        }
                printf("%d\n",count);
                return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll h,w;cin>>h>>w;
    if(h%3==0||w%3==0){
        cout<<0<<endl;
        return 0;
    }
    ll res=min(h,w);
    rep1(i,h){
        ll a=w*i;
        ll b=w/2;
        b*=(h-i);
        ll c=h*w-a-b;
        ll maxi=max(a,max(b,c));
        ll mini=min(a,min(b,c));
        ll buf=maxi-mini;
        chmin(res,buf);
    }
    rep1(i,w){
        ll a=h*i;
        ll b=h/2;
        b*=(w-i);
        ll c=h*w-a-b;
        ll maxi=max(a,max(b,c));
        ll mini=min(a,min(b,c));
        ll buf=maxi-mini;
        chmin(res,buf);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t

bool loop(){
    int n,r;
    cin >> n >> r;
    vector<int> a;
    
    for(int i = 0 ; i < n ; i++ ){
        a.push_back(i+1);
    }
    if( n == 0 && r == 0 )return false;
    
    for(int i = 0 ; i < r; i++ ){
        int p,c;
        cin >> p >> c;
        p = n + 1 - (c+p);
        for(int j = 0 ; j < c ; j++ ){
            a.push_back(a[p]);
            a.erase(a.begin() + p);
        }
        /*
        for(int j = 0 ; j < n ; j ++ ){
            cout << a[j] << "\t";
        }
        cout << endl;*/
    }
    
    cout << a[n-1] << endl;
    
    return true;
}


int main(void){
    while(loop());
    return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
// Palindromic Numbers 回文数
int main() {
  int a, b, r = 0;
  cin >> a >> b;

  for (int i = a; i <= b; i++) {
    int s = i % 10, t = i / 10000 % 10;
    int u = i / 10 % 10, v = i / 1000 % 10;

    if (s == t && u == v) {
      r++;
    }
  }

  cout << r << endl;
}

Measured memory_bytes: 3596
from collections import Counter
N = int(raw_input())
A = map(int, raw_input().split())

B = list(set(A))
counter = Counter(A)
total = 0

for i in range((len(B))):
    n = counter[B[i]]
    total += n*(n-1)/2

for i in range((len(A))):
    n = counter[A[i]]
    ans = total -(n-1)
    print ans


Measured memory_bytes: 24168
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int n;
   cin>>n;
   vector<int>factors;
   for(int i=1;i<=sqrt(n);i++)
   {
       if(n%i==0)
       {
            if(i!=n/i)
            {
                 factors.emplace_back(i);
                 factors.emplace_back(n/i);
            }
            else
              factors.emplace_back(i);
       }
   }
   int res=0;
   for(auto x:factors)
   {
        if(x==1)
          continue;
        int m=x-1;
        if(n/m==n/x)
          res+=m;
   }
   cout<<res<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define pb push_back

int main(void)
{
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vec<int> c(n, 0);
  c[0] = 0;
  c[1] = 0;
  rep(i, n - 1) {
    if (s[i] == 'A' && s[i + 1] == 'C') c[i + 2] = c[i + 1] + 1;
    else c[i + 2] = c[i + 1];
  }
  rep(i, q) {
    int a, b;
    cin >> a >> b;
    cout << c[b] - c[a] << endl;
  }
  return 0;
}



Measured memory_bytes: 1408
#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;

int main(){
  int x,y,z;
  cin>>x>>y>>z;
  printf("%d %d %d\n",z,x,y);
  return 0;
}




Measured memory_bytes: 256
N_1, N_2, N_3, N_4 = map(int, input().split(' '))
set_1974 = {1, 9, 7, 4}
input_set = {N_1, N_2, N_3, N_4}

if len(set_1974 - input_set) == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 2940
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
      	String s = scn.next();
      	String[] list = s.split("");
      	int count = 0;
      	int min = n;
      	for(int i=1; i<n; i++){
      		if(list[i].equals("E")) count++;
    	}
    	min = Math.min(min, count);
    	for(int i=1; i<n; i++){
      		if(list[i-1].equals("W")) count++;
      		if(list[i].equals("E")) count--;
      		min = Math.min(min, count);
    	}
      	System.out.println(min);
	}
}


Measured memory_bytes: 68540
#include <bits/stdc++.h>
#define m_k make_pair
#define inf 0x3f3f3f3f
using namespace std;
const int N=110;
int n,m,dp[N][N],vi[N][N];
char mp[N][N];
void bfs()
{
	queue <pair<int,int> > q;
	q.push(m_k(2,1));
	q.push(m_k(1,2));
	vi[1][2]=vi[2][1]=1;
	while (!q.empty())
	{
		int x,y;
		x=q.front().first;
		y=q.front().second;
		q.pop();
		if (mp[x][y]=='.') dp[x][y]=min(dp[x-1][y],dp[x][y-1]);
		if (mp[x][y]=='#')
		{
			int a,b;
			a=dp[x-1][y];b=dp[x][y-1];
			if (mp[x-1][y]!='#') a++;
			if (mp[x][y-1]!='#') b++;
			dp[x][y]=min(a,b);
		}
		int dx,dy;
		dx=x+1;dy=y;
		if (dx<=n && !vi[dx][dy])
		{
			q.push(m_k(dx,dy));
			vi[dx][dy]=1;
		}
		dx=x;dy=y+1;
		if (dy<=m && !vi[dx][dy])
		{
			q.push(m_k(dx,dy));
			vi[dx][dy]=1;
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	  scanf("%s",mp[i]+1);
	memset(dp,0x3f,sizeof(dp));
	if (mp[1][1]=='#') dp[1][1]=1;
	else dp[1][1]=0;
	bfs();
//	for (int i=1;i<=n;i++)
//	{
//		for (int j=1;j<=m;j++)
//		  printf("%d ",dp[i][j]);
//		printf("\n");
//	}
	printf("%d\n",dp[n][m]);
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>

#define PI 3.14159265359

int main() {
	int a, b, c;
	double s, l, h;
	scanf("%d %d %d", &a, &b, &c);
	h = sin(((double)c/180) * PI) * (double)b;
	s = (h * (double)a) / 2;
	l = hypot(h, (double)a - cos(((double)c/180) * PI) * (double)b) + (double)a + (double)b;
	printf("%f\n%f\n%f\n", s, l, h);
	return 0;
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

char g[500][500];

int main() {
    lint h, w;
    cin >> h >> w;

    fill(&g[0][0], &g[500][0], '$');

    for(lint i=1; i<=h; i++)
    for(lint j=1; j<=w; j++) {
        cin >> g[i][j];
    }

    auto id = [&](lint i, lint j) {
        return i*w + j;
    };
    UnionFind uf(500*500);

    for(lint i=1; i<=h; i++)
    for(lint j=1; j<=w; j++) {
        if(g[i][j] == '#') {
            if(g[i+1][j] == '.')  uf.unite(id(i, j), id(i+1, j));
            if(g[i][j+1] == '.')  uf.unite(id(i, j), id(i, j+1));
            if(g[i-1][j] == '.')  uf.unite(id(i, j), id(i-1, j));
            if(g[i][j-1] == '.')  uf.unite(id(i, j), id(i, j-1));
        }

        if(g[i][j] == '.') {
            if(g[i+1][j] == '#')  uf.unite(id(i, j), id(i+1, j));
            if(g[i][j+1] == '#')  uf.unite(id(i, j), id(i, j+1));
            if(g[i-1][j] == '#')  uf.unite(id(i, j), id(i-1, j));
            if(g[i][j-1] == '#')  uf.unite(id(i, j), id(i, j-1));
        }
    }

    map<lint, lint> mp[2];
    for(lint i=1; i<=h; i++)
    for(lint j=1; j<=w; j++) {
        mp[g[i][j] == '#'][uf.find(id(i, j))]++;
    }

    set<lint> used;
    lint ans = 0;
    for(lint i=1; i<=h; i++)
    for(lint j=1; j<=w; j++) {
        if(used.count(uf.find(id(i, j))))  continue;
        ans += mp[0][uf.find(id(i, j))] * mp[1][uf.find(id(i, j))];
        used.insert(uf.find(id(i, j)));
    }

    cout << ans << endl;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  ll h[n];
  rep(i,n) cin >> h[i];

  sort(h,h+n);

  int p = n-k;
  ll ans =0;

  if(p <=0 ){
      cout << 0 << endl;
      return 0;
  }
  else{
   for(int i=0;i<p;i++){
    ans += h[i];
   }
   cout << ans << endl;
  }
}

 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int cnt(int a)
{
	int sum=0;
	while(a%2==0)
	{
		a/=2;
		sum++;
	}
	return sum;
}

int main()
{	
	int n,a,ans=1000000000;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		ans=min(ans,cnt(a));
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(void){
    string S;
    cin >> S;
    if(S == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<cstdio>
#include<cctype>
#include<vector>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<unordered_map>
#include<stack>
#include<map>
#include<bitset>
#include <cstdlib>
#include<cstring>
#define ll long long;
#define pb push_back
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
using namespace std;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);

	long long u;
	cin >> u;
	double x = 100;
	int ans = 0;
	for (;;)
	{
		x *= 1.01;
		x =floor(x);
		ans++;
		if (x >= u)
		{
			break;
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
const double EPS = 1e-10;
struct Vec2 {
  double x;
  double y;

  Vec2() : x(0.0),y(0.0){} 
  Vec2(double _x,double _y) :x(_x),y(_y){}  
  
  Vec2 operator+(const Vec2& other) const { return { x + other.x , y + other.y }; }
  Vec2 operator-(const Vec2& other) const { return { x - other.x , y - other.y }; }
  bool operator==(const Vec2& other) const { return (abs(x - other.x) < EPS && abs(y - other.y) < EPS ); }
  //  bool operator<(const Vec2& other) const { if(abs(x - other.x) < EPS) return y < other.y; else return x < other.x; }
  bool operator<(const Vec2& other) const { return x < other.x; }
  
  double dot(const Vec2& other) const { return x * other.x + y * other.y; }
  double cross(const Vec2& other) const { return x * other.y - y * other.x; }
  double length() const { return sqrt(x * x + y * y); }
};
// A とB のなす角θ cosθ, sinθ を返す
double Cos(const Vec2 A, const Vec2 B) { return A.dot(B) / (A.length()*B.length()); }
double Sin(const Vec2 A, const Vec2 B) { return A.cross(B) / (A.length()*B.length()); }

// 線分AB上に点Cがあるかどうかの判定
bool IsOnLine(const Vec2 A, const Vec2 B, const Vec2 C) {  return abs(Sin(A - C, B - C)) < EPS && Cos(A - C, B - C) < 0; }

// 線分の交差判定
bool CrossCheck(const Vec2 a, const Vec2 b, const Vec2 c, const Vec2 d) {
  if(a == c || a == d || b == c || b == d) return true; // 端点が等しい場合はtrue
  Vec2 AB = b - a, AC = c - a, AD = d - a;
  Vec2 CA = a - c, CB = b - c, CD = d - c;
  double s = AB.cross(AC) * AB.cross(AD);
  double t = CD.cross(CA) * CD.cross(CB);

  if(abs(Sin(AB, CD)) < EPS) { // 平行のとき
    if(abs(Sin(AB, AC)) < EPS) { // 同一直線上にあるか？
      return (CA.dot(CB) - EPS < 0 || (a - d).dot(b - d) - EPS < 0 || AC.dot(AD) - EPS < 0);
    }
    else return false;
  }
  else return s < EPS && t < EPS;
}

pair<Vec2,Vec2> pd;
// 最近点対
double ClosestPair(vector<Vec2> &v, int l, int r) {
  if(r - l <= 1) return 1e+15;
  int mid = (l + r) / 2;
  Vec2 O = v[mid];
  double d = min(ClosestPair(v, l, mid), ClosestPair(v, mid, r));
  sort(v.begin() + l, v.begin() + r, [](Vec2 a, Vec2 b) {
					return a.y < b.y;
				      });

  // 境界を跨ぐものをチェック
  vector<Vec2> w;
  for (int i = l; i < r; ++i) {
    if(abs(v[i].x - O.x) >= d) continue;
    for (int j = w.size() - 1; j >= 0; --j) {
      if(abs(v[i].y - w[j].y) >= d) break;
      chmin(d, (v[i] - w[j]).length());
    }
    w.push_back(v[i]);
  }
  return d;
}

int main()
{
  int n; cin >> n;
  vector<Vec2> v(n);
  rep(i,n) cin >> v[i].x >> v[i].y;

  sort(v.begin(), v.end());
  
  double res = ClosestPair(v, 0, n);
  printf("%.10f\n", res);
  return 0;
}



Measured memory_bytes: 7344
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<ll>;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
#define diup(a, b) (a % b == 0 ? a / b : a / b + 1)
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }

/*****/

void Main()
{
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
		cout << "vowel";
	else
		cout << "consonant";
}

/*****/

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

	std::cout << std::fixed << std::setprecision(10);


	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/


	Main();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <algorithm>
using namespace std;
int main(){
  stack<int> s;
  int a,b;
  string n;
  while(cin>>n){
    if(isdigit(n[0]))
      s.push(atoi(n.c_str()));
    else{
      a=s.top();
      s.pop();
      b=s.top();
      s.pop();
      if(n[0]=='+') b+=a;
      else if(n[0]=='-') b-=a;
      else if(n[0]=='*') b*=a;
      s.push(b);
    }
  }
  cout<<s.top()<<endl;
}

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

int main() {
    // 読み込み
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++) {
        if(s[i]=='?') s[i] = 'D';
    }
    cout << s << endl;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int mod=998244353;
const int N=1e6+5;
int n,m,ans,b[N];
char s[N],a[N];
//char buf[1<<21],*p1=buf,*p2=buf;
//inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=(n-1)/2;i++)a[++m]=s[i];
	for(int i=1;i<=m/2;i++)
		if(a[i]!=a[m-i+1])
		{
			puts("No");
			goto xjh;
		}
	m=0;
	for(int i=(n+3)/2;i<=n;i++)a[++m]=s[i];
	for(int i=1;i<=m/2;i++)
		if(a[i]!=a[m-i+1])
		{
			puts("No");
			goto xjh;
		}
	m=0;
	for(int i=1;i<=n;i++)a[++m]=s[i];
	for(int i=1;i<=m/2;i++)
		if(a[i]!=a[m-i+1])
		{
			puts("No");
			goto xjh;
		}			
	puts("Yes");
	xjh:;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby
a, b, n = STDIN.readline().strip().split(' ').map(&:to_i)
l = []
while line=gets do
  l << line.strip.split(' ').map(&:to_i)
end
r = [[0, a], [0, b]]
l.each do |x, y, a|
  case a
    when 1
    r[0][0] = x if r[0][0] < x
    when 2
    r[0][1] = x if r[0][1] > x
    when 3
    r[1][0] = y if r[1][0] < y
    when 4
    r[1][1] = y if r[1][1] > y
  end
end
s = [r[0][1] - r[0][0], 0].max * [r[1][1] - r[1][0], 0].max
puts s


Measured memory_bytes: 1788
from operator import mul
from functools import reduce
from collections import Counter
# from itertools import combinations as comb
# from itertools import permutations as perm
# from copy import copy
# 配列二分法アルゴリズム
# https://docs.python.jp/3/library/bisect.html
# import bisect
# 桁数指定
# print('{:.3f}'.format(X))
# from collections import defaultdict
# dic = defaultdict(lambda: ...)
# 値で辞書をソート
# sorted(dic.items(), key=lambda x:x[1])
# ヒープキュー
# https://docs.python.org/ja/3/library/heapq.html
# import heapq
# 正規表現(regular expression)のためのモジュール
# import re

import sys

sys.setrecursionlimit(2000)


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


# 重複組み合わせは nHr = (n + r - 1)Cn
def cmb(n, r):
    # combination
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def gcd(a, b):
    # greatest common divisor
    while b > 0:
        a, b = b, a % b

    return a


def lcm(a, b):
    # least common multiple
    return a * b // gcd(a, b)


S = input()

A = ['k', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', "SUN"]

print(A.index(S))


Measured memory_bytes: 3828
val primes = listOf(3, 5, 7, 11, 13)

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    var nums = mutableListOf<Int>()
    dfs(N, 0, 1, 1, nums)

    println(nums.size)
}

fun readInputLine(): String {
    return readLine()!!
}

fun dfs(N: Int, index: Int, cnt: Int, now: Int, nums: MutableList<Int>) {
    if (cnt > 8 || now > N) {
        return
    }
    if (cnt == 8) {
        nums.add(now)
        return
    }
    if (index >= 5) {
        return
    }

    if (index == 0) {
        dfs(N, 1, cnt * 4, now * 27, nums)
    }
    dfs(N, index + 1, cnt * 2, now * primes[index], nums)
    dfs(N, index + 1, cnt, now, nums)
}


Measured memory_bytes: 33960
n = int(input())
A = list(map(int, input().split()))

counter = 0
for i in range(n):
    minIdx = i
    for j in range(i,n):
        if A[j] < A[minIdx]:
            minIdx = j
    if minIdx != i:
        counter += 1
    A[i], A[minIdx] = A[minIdx], A[i]

for i in range(n):
    if i == n-1:
        print(A[i])
    else:
        print(A[i],end=' ')
print(counter)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pa;
int mod=1e9+7;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int k,x;
    for(int i=1;i<=5;i++){
        cin>>x;
        if(!x) k=i;
    }
    cout<<k;
    return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int         int64_t
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;
int inf = 4e18;
int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    int n; cin >> n;
    int res = 0;
    vi arr(n), arr2, ps(n), ps2;
    arr2.pb(0);
    vector<char> si(n);
    si[0] = '+';
    for(int i=0;i<n;i++){
        if(i) cin >> si[i];
        cin >> arr[i];
        if(i) ps[i] = ps[i-1] + arr[i] * (si[i] == '+' ? 1 : -1);
        else ps[0] = arr[0];
        if(si[i] == '+') arr2.back() += arr[i];
        else arr2.pb(arr[i]);
    }
    ps2.pb(arr2[0]);
    for(int i=1;i<arr2.size();i++) ps2.pb(ps2.back() + arr2[i]);
    res = ps.back();
    for(int i=1, ind = 0;i<n;i++){
        if(si[i] == '-'){
            ++ind;
            res = max(res, ps[i-1] - arr2[ind] + ps2.back() - ps2[ind]);
        }
    }
    cout << res<<endl;
    return 0;
}


Measured memory_bytes: 4212
#include<stdio.h>
#include<math.h>
int main(void)
{
  int n,d,x[10][10],i,j,f,a,k,c;
  double b;
  scanf("%d %d",&n,&d);
  for(i=0;i<n;i++){
    for(j=0;j<d;j++){
      scanf("%d",&x[i][j]);
    }
  }
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      a=0;
      for(k=0;k<d;k++){
	a=a+pow(x[i][k]-x[j][k],2);
      }
      b=sqrt(a);
      int c=b;
	if((double)c==b){
	f++;
      }
    }
  }
  printf("%d\n",f);
  return 0;
}

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

int main(){
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if(a1+a2+a3<22){
        cout << "win" << endl;
    }else{
        cout << "bust" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
n,m = map(int,input().split())
P = list(map(int,input().split()))

uf = {i:i for i in range(1,n+1)}

def get_parent(i):
  lst = []
  while uf[i] != i:
    lst.append(i)
    i = uf[i]
  for l in lst[:-1]:
    uf[l] = i
  return i

def unite(i,j):
  p = get_parent(i)
  uf[get_parent(j)] = p

def same(i,j):
  return get_parent(i) == get_parent(j)

for _ in range(m):
  x,y = map(int,input().split())
  unite(x,y)

ans = 0
for i in range(1,n+1):
  ans += same(P[i-1],uf[i])
print(ans)



Measured memory_bytes: 20704
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
  
using namespace std;
const int inf = 1e9 + 7;




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

 	cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;
    int res = n / 500 * 1000;
    n %= 500;
    res += n - n % 5;
    cout << res;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	static final long MOD = 1000000007;

	static int H, W, K;
	static long[][] dp = new long[110][10];
	static int ans = 0;
	static int n = 0;
	static long x = 0;
	static long[] X;
	static long[] P;




	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		n = sc.nextInt();
		x = sc.nextLong();

		X = new long[51];
		P = new long[51];
		X[0] = 1;
		P[0] = 1;
		for(int i = 1;i <= 50;i++){
			X[i] = 2*X[i-1] + 3;
			P[i] = 2*P[i-1] + 1;
		}
		long ans = sum(n, x);
		System.out.println(ans);






	}

	static long sum(int n,long l){				//lはバーガーのたべる位置
		
		if(n == 1){
			if(l == 1){
				return 0;
				
			}else if(l <= 4){
				return l -1;
			}else{
				return 3;
			}
			
			
		}
		
		if(l <= 1){
			return 0;
		}else  if(l <= 1 + X[n-1]){
			return sum(n-1, l-1);

		}
		else  if(l == 2 + X[n-1]){
			return P[n-1] + 1;
		}

		else  if( l <= 2 + 2*X[n-1]){
			return  P[n-1] + 1 + sum(n-1, l-(2+X[n-1]));
		}
		else {
			return 2*P[n-1] + 1;
		}
		

	}

}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}


Measured memory_bytes: 21972
fun main(args: Array<String>) {

    val (n, a, b) = readLine()!!.split(" ").map{ it.toLong() }

    modFactInit(n, a, b)

    var ans = modPow(2, n) - 1 + mod
    val minus = modAdd(nCr(n,a), nCr(n,b))

    ans = modSub(ans, minus)
    if (ans < 0L) ans += mod
    println(ans)

}

const val mod = 1000000007L
fun modAdd(a: Long, b:Long):Long = (a + b) % mod
fun modSub(a: Long, b:Long):Long = (a - b) % mod
fun modMul(a: Long, b:Long):Long = (a % mod) * (b % mod) % mod
fun modDiv(a: Long, b:Long):Long = modMul(a, modPow(b, mod - 2))
fun modPow(a: Long, b:Long):Long =
    when {
        b == 0L -> 1L
        b == 1L -> a
        b % 2L == 0L -> modPow(a, b / 2L).let { (it * it) % mod }
        else -> (a * modPow(a, b - 1)) % mod
    }
val factList = mutableListOf<Long>()
val factInvList = mutableListOf<Long>()
fun modFactInit(n: Long, a:Long, b:Long) {
    val limit = Math.max(Math.min(a, n-a), Math.min(b, n-b))
    var tmp = 1L
    var tmpInv = 1L
    for(i in 0 until limit) {
        tmp = modMul(tmp, n-i)
        tmpInv = modMul(tmpInv, i+1)
        factList.add(tmp)
        factInvList.add(tmpInv)
    }
}
fun nCr(n: Long, r: Long):Long {
    if (n == r) return 1L
    var ans = 1L
    var bunbo = 1L
    val limit = Math.min(r, n-r)
    for (i in 0 until limit) {
        ans = modMul(ans, n-i)
        bunbo = modMul(bunbo, i + 1)
    }
    return modDiv(factList[limit.toInt() -1], factInvList[limit.toInt() -1])
}


Measured memory_bytes: 51040
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> //required
//#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define lb long double
#define pb push_back
#define loop(i,start,n) for(ll i=start;i<n;i++)
#define rloop(i,n,start)for(ll i=n;i>=start;i--)
#define mod 1000000007
#define endl "\n"
#define INF     1e15
#define NEG_INF -1e15
#define pll pair<ll,ll>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
//using namespace __gnu_pbds;

int main(){
	IOS;
	ll n;
	cin >> n;
	map<ll, ll> mp;
	ll value, sum = 0;
	loop(i, 1, n + 1){
		cin >> value;
		mp[value]++;
		sum += value;
	}
	debug(sum);
	ll q;
	cin >> q;
	while(q--){
		ll b, c;
		cin >> b >> c;
		mp[c] += mp[b];
		sum += (c - b) * mp[b];
		mp.erase(b);

		cout << sum << endl;
	}
}

Measured memory_bytes: 7576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
int main()
{
    ios::sync_with_stdio(false);
    ll n ; cin >> n;
    ll ans = 0;
    for (int i = 1 ; i <= n ; i++){
        for (int j = 1 ; j <= n ; j++){
            for (int k = 1 ; k <= n ; k++)
                ans += __gcd(i , __gcd(j , k));
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3668
import math
def main():
  a,b,c = list(map(int,input().split()))
  k = int(input())
  if a<b:
    if b<c:
      print(a+b+c*pow(2,k))
    else:
      print(a+b*pow(2,k)+c)
  else:
    if a<c:
      print(a+b+c*pow(2,k))
    else:
      print(a*pow(2,k)+b+c)
main()


Measured memory_bytes: 8964
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#define INF 1 << 29
using namespace std;

typedef long long ll;

int main(){
    int x,n;
    //int dif = INT16_MAX;
    int buf = 0;
    int max_num = 0;
    int x_d = 0,x_u = 101;
    cin >> x >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
        max_num = max(max_num,p[i]);
    }
    //cout << max_num << endl;
    vector<bool> table(101,true);
    for(int i = 0; i < n; i++){
        table[p[i]] = false;
    }
    /*
    for(int i = 0; i <= max_num; i++){
        cout << table[i] << " ";

    }
    cout << endl;
    */
    for(int i = x; i >= 0; i--){
        if(table[i]){
            x_d = i;
            break;
        }
    }
    /*
    if(x_d == 0){
        x_d = INF;
    }
    */
    for(int i = x; i <= 100; i++){
        if(table[i]){
            x_u = i;
            break;
        }

    }
    /*
    if(x_u > 100){
        x_u == INF;
    }
    */
    //cout << x_d << " " << x_u << " " << abs(x_d - x) << " " << abs(x_u - x) << endl;
    if(abs(x_d - x) <= abs(x_u - x)){
        cout << x_d << endl;
    }else{
        cout << x_u << endl;
    }

    //cout << min(x_d,x_u) << endl;
    /*
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    int j = 0;
    sort(p.begin(),p.end());
    for(j = 0; j < n; j++){
        buf = abs(x-p[j]);
        if(buf < dif){
            dif = buf;
            x_d = p[j];
        }else break;
    }
    x_u = p[j+1];
    for(int i = x-1; i >= x_d; i--){
        if()
    }
    */




    return 0;
}

Measured memory_bytes: 3600
import sys
sys.setrecursionlimit(10000000)


def main():
    n = int(input())
    
    G=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v,w = map(int, input().split())
        G[u-1].append([v-1,w])
        G[v-1].append([u-1,w])
    ans=[-1]*n
    
    def sub(node,distance):
        for next_node, edge in G[node]:
            if ans[next_node]==-1:
                ans[next_node]=(distance+edge)%2
                sub(next_node,(distance+edge)%2)
    sub(0,0)
    
    for i in ans:
        print(i)
main()

Measured memory_bytes: 94576
#include <stdio.h> 
     
    int main(){
    	int a;
    	int b;
    	int c;
     
    	char buf[10];
    	fgets(buf,10,stdin);
    	sscanf(buf,"%d %d %d" ,&a,&b,&c);
     
    	if(b-a==c-b){
    	   printf("YES\n");
    	}else{
    	   printf("NO\n");
    	}
    	return 0;
    }
     
    	

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

int main() {
	
	int h, w;
	cin >> h >> w;
	vector<vector<char>> a(h, vector<char>(w));
	rep(i, h) rep(j, w){
		cin >> a[i][j];
	}
	
	//Rows
	rep(i, h){
		bool is_all_white = true;
		rep(j, w){
			if(a[i][j] == '#'){
				is_all_white = false;
			}
		}
		if(is_all_white){
			if(i < h - 1){
				for(int k = i; k < h - 1; k++){
					a[k] = a[k + 1];
				}
			}
			i--;
			h--;
		}
	}
	
	//Columms
	rep(j, w){
		bool is_all_white = true;
		rep(i, h){
			if(a[i][j] == '#'){
				is_all_white = false;
			}
		}
		if(is_all_white){
			if(j < w - 1){
				for(int k = j; k < w - 1; k++){
					rep(l, h){
						a[l][k] = a[l][k + 1];
					}
				}
			}
			j--;
			w--;
		}
	}
	
	rep(i, h){
		rep(j, w){
			cout << a[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
S_str = input()
Slen = len(S_str)
S = int(S_str)

S_3 = []
for i in range(2,Slen):
    S_3.append(abs(S//(10**(Slen-i-1))-753))
    S = S % (int(S_str[i-2])*(10**(Slen-i+1)))

print(min(S_3))


Measured memory_bytes: 9004
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  string S;
  cin >> S;
  constexpr int32_t kP = 2019;
  const int64_t L = static_cast<int64_t>(S.length());
  vector<int64_t> P(L, 0);
  P[L - 1] = 1;
  for (int32_t i = 1; i < L; ++i) {
    P[L - 1 - i] = (P[L - i] * 10) % kP;
  }
  vector<int64_t> A(L, 0);
  vector<int64_t> sum(L + 1, 0);
  vector<int64_t> hist(kP, 0);
  sum[0] = 0;
  hist[0]++;
  for (int64_t i = 0; i < L; ++i) {
    const int64_t n = static_cast<int64_t>(S.c_str()[i] - '0');
    A[i] = (n * P[i]) % kP;
    sum[i + 1] = (sum[i] + A[i]) % kP;
    hist[sum[i + 1]]++;
  }
  int64_t result = 0;
  for (int64_t i = 0; i < static_cast<int64_t>(hist.size()); ++i) {
    if (hist[i] >= 2) {
      result += hist[i] * (hist[i] - 1) / 2;
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 8388