akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
const ll MX = 1e18;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};

int main(){
  ll a;
  cin>>a;
  double b;
  cin>>b;
  ll j=b*100+0.5;
  COUT((a*j)/100);
}
  


Measured memory_bytes: 3720
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] p = new int[M];
            String[] S = new String[M];
            for (int i = 0; i < M; i++) {
                p[i] = in.nextInt();
                S[i] = in.next();
            }

            boolean[] ex = new boolean[N + 1];
            for (int i = 0; i < M; i++) {
                if (ex[p[i]]) {
                    S[i] = "WA";
                }
                if (S[i].equals("AC")) {
                    ex[p[i]] = true;
                }
            }
            boolean[] ac = new boolean[N + 1];
            int[] cnt = new int[2];
            for (int i = M - 1; i >= 0; i--) {
                if (S[i].equals("AC")) {
                    if (!ac[p[i]]) {
                        cnt[0]++;
                        ac[p[i]] = true;
                    }
                } else {
                    if (ac[p[i]]) {
                        cnt[1]++;
                    }
                }
            }
            out.printf("%d %d\n", cnt[0], cnt[1]);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 44864
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n string
	fmt.Scan(&n)

	nn := strings.Split(n, "")
	a := nn[0] + nn[1]
	b := nn[2] + nn[3]

	c, _ := strconv.Atoi(a)
	d, _ := strconv.Atoi(b)

	if 0 < c && c <= 12 {
		if 0 < d && d <= 12 {
			fmt.Println("AMBIGUOUS")
		} else {
			fmt.Println("MMYY")
		}
	} else {
		if 0 < d && d <= 12 {
			fmt.Println("YYMM")
		} else {
			fmt.Println("NA")
		}
	}

}


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

int main(void){
    int N,M;cin>>N>>M;
    vector<int>B(M,0);
    for(int i=0;i<N;i++){
        int K;
        cin>>K;
        for(int l=0;l<K;l++){
            int A;
            cin>> A;
            B[A-1]++;
        }
    }
    int ans=0;
    for(int i=0;i<M;i++){
        if(B[i]==N){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 100000

typedef long long ll;
typedef pair<int,int> P;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N;
    cin >> N;
    ll ans[90];
    ans[0] = 2;
    ans[1] = 1;
    for(int i = 2; i <= 86; i++){
        ans[i] = ans[i-1] + ans[i-2];
    }
    cout << ans[N];
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  vii A(N);
  rep(i,0,N-1){
    int a,b; cin>>a>>b;
    A[a-1].push_back(b-1);
    A[b-1].push_back(a-1);
  }
  vector<pii> C(N);
  queue<int> Q;
  Q.push(0);
  vector<bool> F(N,1),G(N,1);
  F[0]=0;
  int count=0;
  Q.push(-1);
  while(1){
    int K=Q.front();
    Q.pop();
    if(K==-1){
      count++;
      Q.push(-1);
    }
    else{
      rep(i,0,A[K].size()){
        if(F[A[K][i]]){
          F[A[K][i]]=0;
          Q.push(A[K][i]);
        }
      }
      C[K].first=count;
    }
    if(Q.size()==1)
      break;
  }
  Q.pop();
  Q.push(N-1);
  G[N-1]=0;
  count=0;
  Q.push(-1);
  while(1){
    int K=Q.front();
    Q.pop();
    if(K==-1){
      count++;
      Q.push(-1);
    }
    else{
      rep(i,0,A[K].size()){
        if(G[A[K][i]]){
          G[A[K][i]]=0;
          Q.push(A[K][i]);
        }
      }
      C[K].second=count;
    }
    if(Q.size()==1)
      break;
  }
  count=0;
  rep(i,0,N){
    if(C[i].first<=C[i].second)
      count++;
  }
  string ans="Snuke";
  if(count>N-count)
    ans="Fennec";
  cout<<ans<<endl;
  }



Measured memory_bytes: 7936
package main

import (
	"fmt"
)

func main() {
	var N int
	var buf int
	fmt.Scan(&N)
	cont := map[int]int{}
	for i := 0; i < N; i++ {
		fmt.Scan(&buf)
		if _, ok := cont[buf]; ok {
			delete(cont, buf)
		} else {
			cont[buf] = 1
		}
	}
	fmt.Println(len(cont))
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  int n, v_max;
  int d[10][10];

  while (cin >> n, n){
    memset(d, 1e9 + 9, sizeof(d));
    v_max = 0;
    REP(i, n){
      int a, b, c;
      cin >> a >> b >> c;
      v_max = max(v_max, max(a, b));
      d[a][b] = c;
      d[b][a] = c;
    }

    v_max++;
    REP(i, v_max) d[i][i] = 0;
    REP(k, v_max) REP(i, v_max) REP(j, v_max) {
      d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    pair<int, int> mini;
    mini.second = 1e9 + 9;
    REP(i, v_max) {
      int sum = 0;
      REP(j, v_max) {
        if (d[i][j] == 1e9 + 9) continue;
        sum += d[i][j];
      }
      if (mini.second > sum){
        mini.first = i;
        mini.second = sum;
      }
    }

    cout << mini.first << " " << mini.second << endl;
  }
}

Measured memory_bytes: 3040
#include<cstdio>

int main(){
    int x;
    int s = 0;
    for(int i = 0;; i++){
        scanf("%d\n",&x);
        if(x == 0){
            break;
        }
        s++;
        printf("Case %d: %d",s,x);
        printf("\n");
    }
    return 0;
}


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

int main(){
	
	string a;
	cin>>a;
	
	int len=a.size();
	bool flag1=false,flag2=false;
	int point1=0,point2=0;
	
	for(int i=0;i<len;i++){
		if(a[i]=='C'){
			point1=i;
			flag1=true;
		}
		if(a[i]=='F'){
			point2=i;
			flag2=true;
		}
	}
	
	if(flag1&&flag2&&point1<point2){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;
const ll MOD = 1e9 + 7;

using namespace std;
using P = pair<int,int>;

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


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

  ll p = 1;
  REP(i, 1, n+1) {
      p *= i;
      p = p%MOD;
  }
  cout << p << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
typedef pair<int, int> pii;
#define x first
#define y second
const int N = 1e5 + 10;
int n, a[N];
int main() {
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a + i);
	LL s = 0, tmp = 0, ans; int f = 1;
	rep(i,1,n) {
		s += a[i]; 
		if (f == 1 && s < f) tmp += f - s, s = f;
		else if (f == -1 && s > f) tmp += s - f, s = f;
		f = -f;
	}
	ans = tmp;
	f = -1; tmp = 0; s = 0;
	rep(i,1,n) {
		s += a[i];
		if (f == 1 && s < f) tmp += f - s, s = f;
		else if (f == -1 && s > f) tmp += s - f, s = f;
		f = -f;
	}
	ans = min(ans, tmp);
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(){
  int a,b,c,t;
  cin >> a >> b >> c;
  if(a>b){
    t=a;
    a=b;
    b=t;
  }
  if(a>c){
    t=a;
    a=c;
    c=t;
  }
  if(b>c){
    t=b;
    b=c;
    c=t;
  }
  cout << a << " " << b << " " <<c <<endl;
}


Measured memory_bytes: 3072
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <stdio.h>

using namespace std;

#define fo(i,n) for(int i=0; i<(int)n; i++)
#define rep(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
#define pii pair<int,int>

#define INF 100000000

int n;
map<pair<int,int>,int> dp;
map<pair<int,int>,bool> vis;
map<pair<int,int>,bool> now;
map<pair<int,int>,int> next;
char buf[25][25];
int dx[] = {-1,0,1,-1,1,-1,0,1};
int dy[] = {-1,-1,-1,0,0,1,1,1};
int ans;

int make(pair<int,int> p) {
	if (next.find(p)!=next.end()) return next[p];
	int mask = p.first;
	int pos = p.second;
	mask |= (1<<pos);
	int newmask = 0;
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			int k = i*n+j;
			int t = 0;
			if (j>0) {
				t += (mask&(1<<(k-1)))>0;
				if (i>0) t += (mask&(1<<(k-1-n)))>0;
				if (i<n-1) t += (mask&(1<<(k-1+n)))>0;
			}
			if (j<n-1) {
				t += (mask&(1<<(k+1)))>0;
				if (i>0) t += (mask&(1<<(k+1-n)))>0;
				if (i<n-1) t += (mask&(1<<(k+1+n)))>0;
			}
			if (i>0) t += (mask&(1<<(k-n)))>0;
			if (i<n-1) t += (mask&(1<<(k+n)))>0;
			if ((mask&(1<<k)) && k!=pos) {
				if (t==2 || t==3) {
					newmask |= (1<<k);
				}
			}
			else {
				if (t==3 && k!=pos) {
					newmask |= (1<<k);
				}
			}
		}
	}
	next[p] = newmask;
	return newmask;
}

void print(int m) {
	for (int i=0; i<n;  i++) {
		for (int j=0; j<n; j++) {
			int k = i*n+j;
			if (m&(1<<k)) cout<<'#';
			else cout<<'.';
		}
		cout<<endl;
	}
}

int solve(int x, int y, int mask) {
	//cout<<x<<" "<<y<<" "<<mask<<endl;
	//print(mask);
	//cout<<endl;
	
	if (mask==0) return 0;
	
	queue<pair<int,int> > q;
	q.push(make_pair(mask,x*n+y));
	q.push(make_pair(-1,-1));
	set<pair<int,int> > vis;
	vis.insert(make_pair(mask,x*n+y));
	int t = 1;
	
	while (q.size()>1) {
		mask = q.front().first;
		x = q.front().second/n;
		y = q.front().second%n;
		q.pop();
		if (mask==-1) {
			t++;
			q.push(make_pair(-1,-1));
		}
			
		for (int k=0; k<8; k++) {
			int u = x + dx[k];
			int v = y + dy[k];
			if (u<0 || u>=n) continue;
			if (v<0 || v>=n) continue;
			if (mask&(1<<(u*n+v))) continue;
		
			int m = make(make_pair(mask,u*n+v));
			
			if (m==0) {
				return t;
			}
			
			if (vis.insert(make_pair(m,u*n+v)).second) q.push(make_pair(m,u*n+v));
			
		}
	}
	return -1;
}

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

	while (scanf("%d",&n) && n!=0) {
		for (int i=0; i<n; i++) scanf("%s",buf+i);
		//for (int i=0; i<n; i++) cout<<buf[i]<<endl;
		int x,y;
		int mask = 0;
		for (int i=0; i<n; i++) for (int j=0; j<n; j++) {
			if (buf[i][j]=='#') mask |= (1<<(i*n+j));
			if (buf[i][j]=='@') {
				x = i;
				y = j;
			}
		}
		now.clear();
		vis.clear();
		dp.clear();
		ans = INF;
		ans = solve(x,y,mask);
		if (ans >= INF) printf("-1\n");
		else printf("%d\n",ans);
	}

    return 0;

}

Measured memory_bytes: 19436
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;


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

long long min=11111111111111111;
int index=10;
for(int i=0;i<5;i++){
  if(min >a[i]) {min =a[i]; index=i;}
}

cout<<(n+min-1)/min+4<<endl;
}


Measured memory_bytes: 256
var
  maxn1,maxn2,who1,who2,maxn3,maxn4:longint;
  i,j,m,n,k,p,len1,len2:longint;
  check1,check2:array[0..100005]of longint;
function max(x,y:longint):longint;
begin
  if x>y then exit(x)
  else exit(y);
end;
begin
  readln(n);
  for i:=1 to n do
    begin
      read(k);
      if i mod 2=1 then inc(check1[k])
      else inc(check2[k]);
    end;
  for i:=1 to 100000 do
    if check1[i]>maxn1 then
      begin
        maxn1:=check1[i]; who1:=i;
      end;

  for i:=1 to 100000 do
    if (i<>who1)and(check1[i]>maxn3) then
      maxn3:=check1[i];

  for i:=1 to 100000 do
    if check2[i]>maxn2 then
      begin
        maxn2:=check2[i]; who2:=i;
      end;

  for i:=1 to 100000 do
    if (i<>who2)and(check2[i]>maxn4) then
      maxn4:=check2[i];

  if who1<>who2 then
    writeln(n-maxn1-maxn2)
  else           
    writeln(n-max(maxn1+maxn4,maxn2+maxn3));
end.

Measured memory_bytes: 896
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

x=int(input())

flag=True
while flag:
    if is_prime(x):
        print(x)
        flag=False
    x+=1



Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  vector<int> sum(n+2,0);
  rep1(i,n){
    sum[i]=sum[i-1]+a[i-1];
  }
  int res=inf;
  sum[n+1]=inf;
  for(int i=2;i<n-1;++i){
    int f_sum=sum[i];
    int r_sum=sum[n]-sum[i];
    int f_half=f_sum/2;
    int r_half=r_sum/2;
    auto f_it=lower_bound(sum.begin(),sum.begin()+i+1,f_half);
    auto r_it=lower_bound(sum.begin()+i+1,sum.end(),r_half+f_sum);

    //printf("i = %lld, f_sum = %lld, f_it = %lld, r_sum = %lld, r_it = %lld\n",i,f_sum,*f_it,r_sum,*r_it);
    vector<int> buf(4);
    buf[0]=*f_it;buf[1]=*r_it-f_sum;buf[2]=f_sum-*f_it;buf[3]=r_sum-*r_it+f_sum;
    sort(buf.begin(),buf.end());
    res=min(res,buf[3]-buf[0]);
    --f_it;
    //printf("i = %lld, f_sum = %lld, f_it = %lld, r_sum = %lld, r_it = %lld\n",i,f_sum,*f_it,r_sum,*r_it);
    buf[0]=*f_it;buf[1]=*r_it-f_sum;buf[2]=f_sum-*f_it;buf[3]=r_sum-*r_it+f_sum;
    sort(buf.begin(),buf.end());
    res=min(res,buf[3]-buf[0]);
    --r_it;
    //printf("i = %lld, f_sum = %lld, f_it = %lld, r_sum = %lld, r_it = %lld\n",i,f_sum,*f_it,r_sum,*r_it);
    buf[0]=*f_it;buf[1]=*r_it-f_sum;buf[2]=f_sum-*f_it;buf[3]=r_sum-*r_it+f_sum;
    sort(buf.begin(),buf.end());
    res=min(res,buf[3]-buf[0]);
    ++f_it;
    //printf("i = %lld, f_sum = %lld, f_it = %lld, r_sum = %lld, r_it = %lld\n",i,f_sum,*f_it,r_sum,*r_it);
    buf[0]=*f_it;buf[1]=*r_it-f_sum;buf[2]=f_sum-*f_it;buf[3]=r_sum-*r_it+f_sum;
    sort(buf.begin(),buf.end());
    res=min(res,buf[3]-buf[0]);
  }
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 3328
#include <vector> 
#include <list> 
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <complex>
using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;

typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(t,c) for(typeof((c).begin()) t=(c).begin(); t!=(c).end(); ++t)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(t,a,b) for(int t=(a);t<(b);++t)
#define REP(t,n)  FOR(t,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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



const LL mod = 1000000007;

LL gcd(LL a, LL b) { if (a%b == 0) { return b; } else return gcd(b, a%b); }
LL lcm(LL a, LL b) { return a / gcd(a, b)*b; }

#define Yes_ cout<<"Yes"<<endl; return 0;
#define No_ cout<<"No"<<endl; return 0;


#define YES_ cout<<"YES"<<endl; return 0;
#define NO_ cout<<"NO"<<endl; return 0;

#define POSSIBLE cout<<"POSSIBLE"<<endl; return 0;
#define IMPOSSIBLE cout<<"IMPOSSIBLE"<<endl; return 0;




int main() {
	
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	int x = 0, y = 0;

	if (A + B < 2 * C) {
		cout << A * X + B * Y << endl;
	}
	else {
		int m = min(X, Y);
		int ans = 2*C * m;
		if (X - m > 0) {
			if (A < 2*C) {
				ans += A * (X - m);
			}
			else {
				ans += 2 * C*(X - m);
			}
		}
		else {
			if (B < 2 * C) {
				ans += B * (Y - m);
			}
			else {
				ans += 2 * C*(Y - m);

			}
		}
		cout << ans << endl;
	}


}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int parent[50*50+5];
int length[50*50+5];

void init(){
  for (int i=0; i<50*50+5; i++){
    parent[i] = i;
    length[i] = 1;
  }
  return;
}

int getroot(int n){
  if (parent[n]==n){
    return n;
  } else {
    return getroot(parent[n]);
  }
}

bool samegroup(int n, int m){
  int nroot = getroot(n);
  int mroot = getroot(m);
  if (nroot==mroot){
    return true;
  } else {
    return false;
  }
}

bool unite(int n, int m){
  if (samegroup(n, m)){
    return false;
  } else {
    int nroot = getroot(n);
    int mroot = getroot(m);
    if (length[nroot]==length[mroot]){
      parent[nroot] = mroot;
      length[mroot]++;
    } else if (length[nroot]>length[mroot]){
      parent[mroot] = nroot; 
    } else {
      parent[nroot] = mroot;
    }
    return true;
  }
}

int main(){
  int N;
  scanf("%d", &N);
  int M;
  scanf("%d", &M);
  std::vector<int > a(M), b(M);
  for (int i=0; i<M; i++){
    scanf("%d", &a[i]);
    scanf("%d", &b[i]);
  }
  int ans = 0;
  for (int i=0; i<M; i++){
    init();
    for (int j=0; j<M; j++){
      if (j==i) continue;
      unite(a[j],b[j]);
    }
    int parent = getroot(1);
    bool ok = true;
    for (int i=1; i<=N; i++){
      if (!samegroup(parent,i)){
        ok = false;
        break;
      }
    }
    if (!ok) ans++;
    //if (!ok) printf("i=%d OK\n", i);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=j;i<=k;++i)
#define Forr(i,j,k) for (int i=j;i>=k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T& a,T b) {return a<b?a=b,1:0;}
template<typename T>bool chkmin(T& a,T b) {return a>b?a=b,1:0;}

const int maxn=100000+100;
struct node {
	int to,next;
}e[maxn<<1];
int n,tot;
int head[maxn],cnt[maxn],dp[maxn];

inline void read(int &x) {
	x=0;
	int p=1;
	char c=getchar();
	while (!isdigit(c)) {if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) {x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	x*=p;
}

inline void file() {
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
}

inline void add(int from,int to) {
	tot++; e[tot].to=to; e[tot].next=head[from]; head[from]=tot;
}

void dfs(int u,int fa) {
	int flag=0;
	for (int i=head[u];i!=0;i=e[i].next) {
		int v=e[i].to;
		if (v==fa) continue;
		dfs(v,u);
		dp[u]+=dp[v];
		if (!dp[v]) {
			if (!flag) flag=1;
			else dp[u]++;
		}
	}
}

int main() {
//	file();
	read(n);
	For (i,1,n-1) {
		int x,y; read(x); read(y);
		add(x,y); add(y,x); cnt[x]++; cnt[y]++;
	}
	int root=-1;
	For (i,0,n-1) if (cnt[i]>=3) root=i;
	if (root==-1) printf("1");
	else {
		dfs(root,-1);
		printf("%d\n",dp[root]);
	}
	return 0;
}

Measured memory_bytes: 6528
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>

namespace n91 {

void main_() {
  const usize n = scan<usize>();
  const usize q = scan<usize>();
  auto t = md_vec(n, 0_z, usize());
  for (const auto i : rep(0_z, n - 1_z)) {
    const usize a = scan<usize>() - 1_z;
    const usize b = scan<usize>() - 1_z;
    t[a].push_back(b);
    t[b].push_back(a);
  }
  std::vector<u32> count(n, 0_z);
  for (const auto i : rep(0_z, q)) {
    const usize p = scan<usize>() - 1_z;
    const u32 x = scan<u32>();
    count[p] += x;
  }

  std::vector<u32> ans(n);

  const auto dfs = [&](const auto &dfs, const usize v, const usize p,
                       u32 c) -> void {
    c += count[v];
    ans[v] = c;
    for (const auto e : t[v]) {
      if (e != p) {
        dfs(dfs, e, v, c);
      }
    }
  };
  dfs(dfs, 0_z, n, static_cast<u32>(0));

  for (const auto e : ans) {
    std::cout << e << " ";
  }
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 23424
# -*- coding: utf-8 -*-

def swap(A, i, j):
    tmp  = A[i]
    A[i] = A[j]
    A[j] = tmp

def selectionSort(A, N):
    """N個の要素を含む0-オリジンの配列A"""
    nswap = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            swap(A, i, minj)  # A[i] と A[minj] を交換
            nswap += 1
    return nswap

N = int(input())
A = [int(t) for t in input().split()]
if len(A) != N: raise

nswap = selectionSort(A, N)
print(' '.join(map(str, A)))
print(nswap)



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

int main() {
  
	int N, M, cnt=0;
	cin >> N >> M;

	if(N >= 2) cnt += (N * (N - 1)) / 2;
	if(M >= 2) cnt += (M * (M - 1)) / 2;

	cout << cnt << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define M 1000000000
int main() {
	int n,R,mini,ans = -(M);
	scanf("%d", &n);
	scanf("%d", &R);
	mini = R;
	for (int i = 1; i < n; i++) {
		scanf("%d", &R);
		ans = std::max(ans, R - mini);
		mini = std::min(mini, R);
	}
	printf("%d\n", ans);
}

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

int main(){
  int64_t N,K;
  cin >> N >> K;
  while(true){
    if(N>K){
      N%=K;
    }else{
      int64_t diff=abs(N-K);
      if(diff>=N){
        break;
      }else{
        N=diff;
      }
    }
  }
  cout << N << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
q = int(input())

from collections import Counter
count = Counter(a)

s = sum(a)
for _ in range(q):
    b, c = map(int, input().split())
    s += (c-b)*count[b]
    count[c] += count[b]
    count[b] = 0
    print(s)

Measured memory_bytes: 23936
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
int main(){
	ll n, x, m, ans = 0, s = 0, l = 0, rep;
	cin >> n >> x >> m;
	bool b[m];
	fill(b, b + m, false);
	ll cur = x;
	for (int i = 0; i < m; i++){
		if (b[cur]) rep = cur;
		b[cur] = true;
		(cur *= cur) %= m;
	}
	cur = x;
	while (cur != rep){
		ans += cur;
		(cur *= cur) %= m, n--;
		if (n == 0) break;
	}
	do{
		s += cur;
		(cur *= cur) %= m, l++;
	}while (cur != rep);
	for (int i = 0; i < n % l; i++){
		ans += cur;
		(cur *= cur) %= m;
	}
	ans += s * (n / l);
	printf("%lld\n", ans);
}

Measured memory_bytes: 3768
S = input()
ans = len(S)
for c in set(S):
    maxi = count = 0
    for s in S:
        if s != c:
            count += 1
        else:
            maxi = max(maxi, count)
            count = 0
    maxi = max(maxi, count)
    ans = min(ans, maxi)
print(ans)

Measured memory_bytes: 2940
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n = 0;
  cin >> n;

  cout << LCM(2,n);



  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
using namespace std;
map <int, int>a;
map <int, int>b;
map <long, long>vis;
int main()
{
	int n,m;
	cin>>n;
	for(int i = 1; i <= n; i++) {
		cin>>a[i];
		vis[a[i]]++;
	}
	cin>>m;
	for(int i = 1; i <= m; i++){
		cin>>b[i];
		vis[b[i]]--;
	}
	if(m > n) cout<<"NO"<<endl;
	else{ for(int i = 1; i <= n; i++){
			if(vis[b[i]] < 0) {
				cout<<"NO"<<endl;
				return 0;
			}
		}
		cout<<"YES"<<endl;
	}
}

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

#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define t_times int t; cin >> t; while(t--)
#define _parr(a, n) for(int __i = 0; __i < (int )n; __i++) cout << a[__i] << ' '; cout << '\n'
#define fr(i, p, n) for(int i = (int )p; i < (int )n; i++)
#define frn(i, p, n) for(int i = (int )p; i <= (int )n; i++)
#define rev(i, n, p) for(int i = (int )n; i >= (int )p; i--)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).begin(), (c).end()
#define sci(n) scanf("%d", &n)
#define scl(n) scanf("%lld", &n)
#define prin(n) printf("%d\n", n)
#define prln(n) printf("%lld\n", n)
#define mp make_pair
#define F first
#define S second
#define pb push_back

typedef long long int LL;
typedef unsigned long long ULL;
typedef unsigned int uint;
typedef pair< int, int> ii;
typedef vector< int> vi;

const int mod = 1e9 + 7;
const LL INF = 9e18 + 2e17;
const int inf = 2e9;
const int N = 2e5 + 22;
const double eps = 1e-10;

int n, m;

void _solve() {
    int a, b;
    cin >> a >> b;
    if(b == 1) {
        cout << 0;
        return;
    }
    int ans = 1, i = 1;
    while(1) {
        ans += a - 1;
        if(ans >= b) {
            cout << i;
            return;
        }
        i++;
    }
}
int main() {
    fastio;
    //t_times
    _solve();
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  char S[200];
  scanf("%s",S);
  int leng;
  leng = strlen(S);
  int i,j;
  j=0;
  for(i=0;i<leng/2;i++){
    if(S[i]==S[leng-1-i])
      j++;
  }
  printf("%d",i-j);
  return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <stack>
#include <map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <string.h>

using namespace std;

// NG

int N;
int a[1000000];
int c[1000000];

long loss(long k) {
    long l;
    for (int i=1; i <= N; i++) {
        l += abs(c[i] - k);
    }
    return l;
}
int main(int argc, char** argv) {
    cin >> N;
    for (int i=1; i <= N; i++) cin >> a[i];
    for (int i=1; i <= N; i++) c[i] = a[i] - i;
    sort(&c[1], &c[1] + N);
    //for (int i=1; i <= N; i++) cout << c[i] << endl;;

    long i = N / 2 + 1;
    long ans = loss(c[i]);
    if (0 <= i - 1) ans = min(ans, loss(c[i - 1]));
    if (i + 1 <= N) ans = min(ans, loss(c[i + 1]));
    cout << ans << endl;
}

Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, K;
  std::cin >> N >> K;
  std::vector<int> A(N);
  for(int i=0;i<N;i++) std::cin >> A[i];
  std::vector<int> dp(K+1, -1);
  dp[0] = 0;
  for(int i=1;i<=K;i++){
    set<int> gr;
    for(int j=0;j<N;j++) if(i>=A[j] && gr.find(dp[i-A[j]])==gr.end()) gr.insert(dp[i-A[j]]);
    int now = 0;
    while(true){
      if(gr.find(now)!=gr.end()) now++;
      else break;
    }
    dp[i] = now;
  }
  std::cout << (dp[K]==0?"Second":"First") << '\n';
  return 0;
}


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

int main() {
    int n, m;
    int k[10];
    int s[10][10];
    int p[10];
    int patterns, bit;
    int status[10];
    int ans = 0;
    
    cin >> n >> m;
    
    for (int i = 0; i < m; i++) {
        cin >> k[i];
        
        for (int ii = 0; ii < k[i]; ii++) {
            cin >> s[i][ii];
        }
    }
    
    for (int i = 0; i < m; i++) {
        cin >> p[i];
    }
    
    patterns = (1 << n) - 1;
    
    for (int i = 0; i <= patterns; i++) {
        int flag = true;
        bit = 1;
        
        for (int ii = 0; ii < n; ii++) {
            if (i & bit) {
                status[ii] = 1;
            }
            else {
                status[ii] = 0;
            }
            
            bit = bit << 1;
        }
        
        for (int ii = 0; ii < m; ii++) {
            int count = 0;
            
            for (int iii = 0; iii < k[ii]; iii++) {
                count += status[s[ii][iii] - 1];
                //cout << "ii=" << ii << ", iii=" << iii << ", s[ii][iii]=" << s[ii][iii] << endl;
            }
            
            //cout << "count=" << count << ", p[ii]=" << p[ii] << endl;
            
            if ((count % 2) != p[ii]) {
                flag = false;
                break;
            }
        }
        
        if (flag) {
            ans++;
        }
        
        /*cout << "patterns=" << patterns << ", i=" << i;
        
        for (int ii = 0; ii < n; ii++) {
            cout << ", status[" << ii << "]=" << status[ii];
        }
        
        cout << ", flag=" << (flag ? "true" : "false") << endl;*/
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
namespace AtCoder
{
  class Program
  {
	static void Main(string[] args)
	{
  		var v = Console.ReadLine();
  		var IsCoffee = (v[2] == v[3] && v[4] == v[5]);
  		Console.WriteLine(IsCoffee ? "Yes" : "No");
	}
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();

#define MAXX 500005
#define PI 3.14159265358979323846264338327950
#define F first
#define S second
#define ll   long long int
#define mod  1000000007



int main()
{
	FAST;
	ll n;
	cin >> n;
	if(n == 1){
		cout << "Hello World";
		return 0;
	}
	ll a, b;
	cin >> a >> b;
	cout << a + b;
}

Measured memory_bytes: 3652
#include<stdio.h>

#define MAX_N 100000

int n;
int p[100000];

void swap( int a, int b )
{
	int tnp;
	tnp = p[a];
	p[a] = p[b];
	p[b] = tnp;
}

int main(void)
{
	int ans;
	int i;
	
	scanf( "%d", &n );
	
	for( i=0; i<n; i++ ) {
		scanf( "%d", &p[i] );
	}
	
	
	ans = 0;
	for( i=0; i<n; i++ ) {
		if ( p[i] == i + 1 ) {
			ans++;
			if ( i < n-1 && p[i+1] == i + 2 ) {
				swap(i, i+1);
			}
			else if ( i > 0 && p[i-1] == i ) {
				swap(i, i-1);
			}
			else if ( i < n-1 && p[i+1] != i+1 ) {
				swap(i, i+1);
			}
			else if ( i > 0 && p[i-1] != i+1 ) {
				swap(i, i-1);
			}
		}
	}
	
	printf( "%d\n", ans );
}

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

int main() {
  ll N = 0, x = 0, y = 0, A = 0, B = 0,ans = 0;
  cin >> N >> A >> B;
  x = N % (A + B);
  y = N / (A + B);
  if(A >= x){
    ans = A * y + x;
    cout << ans;
    return 0;
  }
  else{
    ans = A * (y + 1);
    cout << ans;
    return 0;
  }
}

Measured memory_bytes: 3620
#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
#        print(par)
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]


N, M = map(int, input().split())
A = [0 for _ in range(M)]
B = [0 for _ in range(M)]

#初期化
#根なら-size,子なら親の頂点
par = [-1]*N

for i in range(M):
    a, b = map(int, input().split())
    unite(a-1, b-1)
#    print(par)

#print()
group = set([])

for i in range(N):
    group.add(find(i))

#print(group)
    
ans = 0
for g in group:
#    print(size(g))
    ans = max(ans, size(g))
print(ans)

Measured memory_bytes: 28004
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int L=1e5+2;
char s[L];
vector<P> ret;
int main() {
	scanf("%s",s+1);
	int n=strlen(s+1);
	if(s[n]=='1'){
		puts("-1");
		return 0;
	}
	if(s[1]=='0'){
		puts("-1");
		return 0;
	}

	int cur=1;
	for(int i=1;i<n;i++){
		if(s[i]=='1'){
			if(s[n-i]=='0'){
				puts("-1");
				return 0;
			}
			while(cur<i){
				ret.push_back(P(cur,i));
				cur++;
			}
		}
	}
	ret.push_back(P(n-1,n));
	for(auto p:ret){
		printf("%d %d\n",p.first, p.second);
	}

	return 0;
}



Measured memory_bytes: 2420
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<string> s1(n), s2(n);
        vector<int> t1(n), t2(n);
        map<string, int> index;
        for(int i=0; i<n; ++i){
            cin >> s1[i] >> t1[i] >> s2[i] >> t2[i];
            index[s1[i]] = i;
        }

        vector<int> sup(n);
        vector<vector<int> > edges(n);
        for(int i=0; i<n; ++i){
            sup[i] = index[s2[i]];
            if(s1[i] != s2[i])
                edges[index[s2[i]]].push_back(i);
        }

        int ret = 0;
        vector<bool> make(n, false);
        for(int i=0; i<n; ++i){
            if(make[i])
                continue;

            int j = i;
            vector<bool> check(n, false);
            while(!check[j]){
                check[j] = true;
                j = sup[j];
            }

            check.assign(n, false);
            int k = j;
            while(!check[j]){
                if(t1[j] - t2[j] < t1[k] - t2[k])
                    k = j;
                check[j] = true;
                j = sup[j];
            }

            ret += t1[k] - t2[k];
            queue<int> q;
            q.push(k);
            while(!q.empty()){
                int a = q.front();
                q.pop();
                ret += t2[a];
                make[a] = true;

                for(unsigned l=0; l<edges[a].size(); ++l){
                    int b = edges[a][l];
                    if(!make[b])
                        q.push(b);
                }
            }
        }

        cout << ret << endl;
    }
}

Measured memory_bytes: 1488
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 10;
inline LL in()
{
    LL x = 0, flag = 1; char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-') flag = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * flag;
}
int n, m, ans, kind;
LL xsum, ori[MAXN], tar[MAXN], tot[MAXN];
int a[MAXN], b[MAXN], size[MAXN];
bool vis[MAXN];
int fa[MAXN];
int find(int x)
{
	if (fa[x] != x) fa[x] = find(fa[x]);
	return fa[x];
}
void unite(int x, int y)
{
    int fx = find(x), fy = find(y);
    if (fx == fy) return;
	fa[fy] = fx;
    size[fx] += size[fy];
}
bool judge()
{
	map <LL, int> cnt;
    for (int i = 1; i <= n+1; i ++)
        cnt[ori[i]] ++;
    for (int i = 1; i <= n; i ++)
    {
        if (cnt[tar[i]] > 0)
	        cnt[tar[i]] --;
	    else 
	        return false;
    }
    return true;
}
void init()
{
	map <LL, int> id; 
    sort(tot + 1, tot + n + 2);
    id[tot[1]] = kind = 1;
    for (int i = 2; i <= n + 1; i ++)
    {
        if (tot[i] != tot[i-1]) kind ++;
        id[tot[i]] = kind;
    }
    for (int i = 1; i <= n+1; i ++)
    {
        a[i] = id[ori[i]];
        b[i] = id[tar[i]];
    }
}
int main()
{
	n = in();
	for (int i = 1; i <= n; i ++) 
    {
        tot[i] = ori[i] = in();
        ori[n + 1] ^= ori[i];
    }
    tot[n + 1] = ori[n + 1];
	for (int i = 1; i <= n; i ++) 
	{
		tar[i] = in();
		tar[n + 1] ^= tar[i];	
	}
    if (judge() == false) 
    {
        printf("-1");
        return 0;
    }
    init();
    for (int i = 1; i <= kind; i ++) fa[i] = i;
	for (int i = 1; i <= n + 1; i ++)
	{
		if (a[i] != b[i]) 
		{
			ans ++;
            size[a[i]] ++;
		}
	}
	for (int i = 1; i <= n + 1; i ++)
	{
		if (find(a[i]) == find(b[i])) continue;
		unite(a[i], b[i]);
	}
    for (int i = 1; i <= n + 1; i ++)
    {
        if (fa[a[i]] == a[i] && a[i] != b[i] && !vis[a[i]]) 
		{
			vis[a[i]] = true;
			ans ++;
		}
    }
	if (a[n+1] != b[n+1]) ans --;
	if (size[fa[a[n+1]]] > 1) ans --;
    cout << ans << endl;
	return 0;
}

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

string S;
long long ans = 0;

int main() {
  cin >> S;

  int N = S.length();

  if(N%2 ==  0){
    printf("No\n");
    return 0;
  }

  for(int i=0;i<(N-1)/2;i++){
    if(S[i] != S[N-1-i]){
      printf("No\n");
      return 0;
    }
  }

  for(int i=0;i<(N-1)/4;i++){
    if(S[i] != S[((N-1)/2)-1-i]){
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");
}


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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i <= b; i++)


int main() {
	int N, K;
	cin >> N >> K;
	int sol = 0;
	int coord;
	for(int i = 0; i < N; i++){
		cin >> coord;
		if (coord < abs(coord - K)){
			sol += 2*coord;
		}
		else{
			sol += 2*abs(coord-K);
		}
	}
	cout << sol << "\n";
	
}


Measured memory_bytes: 256
#pragma region Include
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#pragma endregion

using namespace std;

#pragma region Macros
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define dump(x) \
  cout << "Line " << __LINE__ << " : " << #x << " = " << (x) << endl
template <class T>
using VV = vector<vector<T>>;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "[";
  rep(i, vec.size()) os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "]";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<vector<T>>& mat) {
  os << "[";
  rep(i, mat.size()) os << mat[i] << (i + 1 == mat.size() ? "" : ",\n ");
  os << "]";
  return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}

template <typename V, typename H>
void resize(vector<V>& vec, const H head) {
  vec.resize(head);
}

template <typename V, typename H, typename... T>
void resize(vector<V>& vec, const H& head, const T... tail) {
  vec.resize(head);
  for (auto& v : vec) resize(v, tail...);
}
constexpr double EPS = 1e-10;
const int INF = 0x3f3f3f3f;
#pragma endregion

int main() {
  int N;
  cin >> N;
  int num = (N + 1) / 2;
  double res = (double)num / (double)N;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import*
from bisect import*
p=[1]
for _ in range(30):p+=p[-1]*2,
n,*a=map(int,open(0).read().split())
d=Counter(a)
c=0
for i,b in enumerate(sorted(a)[::-1]):
  if d[b]<1:continue
  d[b]-=1
  x=p[bisect(p,b)]-b
  if d[x]:
    d[x]-=1
    c+=1
print(c)

Measured memory_bytes: 104860
#include <bits/stdc++.h>
#include<set>
#include <algorithm>
#define ll long long 
#include <string.h>
using namespace std;

int main()
{
	double n,a,b;
	cin>>a>>b>>n;
	double x=min(b-1,n);
	double ans= floor((a*x)/b)-a*floor(x/b);
	ll int d =ans ;
	cout<<d<<endl;
} 




Measured memory_bytes: 3720
from collections import deque
N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]
class UnionFind:
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
    def find(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            self.par[y] = x
    def is_same(self, x, y):
        return self.find(x) == self.find(y)
uf = UnionFind(N)
next_ = [[] for _ in range(N)]
for u, v, w in X:
    next_[u - 1].append((v - 1, w))
    next_[v - 1].append((u - 1, w))
    uf.union(u - 1, v - 1)
now = min(set(uf.par))
result = ["" for _ in range(N)]
result[now] = "0"
ver = deque([now])
while len(ver) > 0:
    now = ver.pop()
    color = result[now]
    for n, w in next_[now]:
        if result[n] != "":
            continue
        if w % 2 == 0:
            result[n] = color
        else:
            result[n] = "1" if color == "0" else "0"
        ver.append(n)
print("\n".join(result))


Measured memory_bytes: 62096