akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

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

class DisjointSet {
public:
	vector<ll> rank, p;

	DisjointSet() {}
	DisjointSet(ll size) {
		rank.resize(size, 0);
		p.resize(size, 0);
		for (ll i = 0; i < size; i++) makeSet(i);
	}

	void makeSet(ll x) {
		p[x] = x;
		rank[x] = 0;
	}

	bool same(ll x, ll y) {
		return findSet(x) == findSet(y);
	}

	void unite(ll x, ll y) {
		link(findSet(x), findSet(y));
	}

	void link(ll x, ll y) {
		if (rank[x] > rank[y]) {
			p[y] = x;
		}
		else {
			p[x] = y;
			if (rank[x] == rank[y]) {
				rank[y]++;
			}
		}
	}

	ll findSet(ll x) {
		if (x != p[x]) {
			p[x] = findSet(p[x]);
		}
		return p[x];
	}
};

int main() {
	ll n, k, l;

	cin >> n >> k >> l;
	DisjointSet ds1 = DisjointSet(n);
	DisjointSet ds2 = DisjointSet(n);

	for (ll i = 0; i < k; i++) {
		ll p, q;
		cin >> p >> q;
		p--; q--;
		ds1.unite(p,q);
	}
	for (ll i = 0; i < l; i++) {
		ll r, s;
		cin >> r >> s;
		r--; s--;
		ds2.unite(r,s);
	}

	map<pair<int,int>, int> m;
	for (int i = 0; i < n; i++) {
		int ar, br;
		ar = ds1.findSet(i);
		br = ds2.findSet(i);
		m[make_pair(ar,br)]++;
	}
	for (int i = 0; i < n; i++) {
		int ar, br;
		ar = ds1.findSet(i);
		br = ds2.findSet(i);
		cout << m[make_pair(ar,br)] <<" ";
	}
	cout << endl;
	
}


Measured memory_bytes: 18048
def preOrder(s):
	print(" " + str(s),end="")
	if main[s][1] != -1:
		preOrder(main[s][1])
	if main[s][2] != -1:
		preOrder(main[s][2])

def inOrder(s):
	if main[s][1] != -1:
		inOrder(main[s][1])
	print(" " + str(s),end="")
	if main[s][2] != -1:
		inOrder(main[s][2])

def postOrder(s):
	if main[s][1] != -1:
		postOrder(main[s][1])
	if main[s][2] != -1:
		postOrder(main[s][2])
	print(" " + str(s),end="")

n = int(input())
main = [[-1] * 1 for i in range(n+1)]
for i in range(n):
	a = input().split()
	for j in range(1,3):
		main[int(a[j])][0] = int(a[0])
		main[int(a[0])].append(int(a[j]))
	#print(main)

del a


for i in range(n):
	if main[i][0] == -1:
		print("Preorder")
		preOrder(int(i))
		print()
		print("Inorder")
		inOrder(int(i))
		print()
		print("Postorder")
		postOrder(int(i))
		break
print()

#print(main)





Measured memory_bytes: 5616
/*
    author: Salam_35
    Created at :

*/

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

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() int t;cin >> t;while(t--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}

typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
   int a,b,c;
   cin >> a >>b >> c;
   swap(a,b);
   swap(a,c);
   cout<<a<<' '<<b<<' '<<c<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repx(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int a[500][500];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    
    // 2. 集合を構築できるか確認.
    // ex.
    // N = 1
    // 1 1
    // 
    // N = 3
    // 1 1 2
    // 2 3 3
    // 
    // N = 6
    // 1 1 2 4
    // 2 3 3 5
    // 4 5 6 6
    // 
    // N = 10
    // 1 1 2  4  7
    // 2 3 3  5  8
    // 4 5 6  6  9
    // 7 8 9 10 10
    // ...
    int x = 0;
    repx(i, 1, N + 1){
        if((i + 1) * i / 2 == N){
            x = i;
            break;
        }
    }
    if(x == 0){
        puts("No");
        return 0;
    }
    
    // 3. 集合を構築.
    int k = x + 1, left = 1, right = 1;
    rep(i, x) rep(j, i + 1) a[i][j] = left++;
    repx(j, 1, k) rep(i, j) a[i][j] = right++;
    // rep(i, x){
    //     rep(j, k) printf("%d ", a[i][j]);
    //     puts("");
    // }
    
    // 4. 出力.
    puts("Yes");
    printf("%d\n", k);
    rep(j, k){
        printf("%d ", x);
        rep(i, x){
            printf("%d", a[i][j]);
            if(i < x - 1) printf(" ");
        }
        puts("");
    }
    return 0;
    
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
 
using namespace std;
 
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define x first
#define y second
 
typedef long long tint;
 
const int INF = 1e6;
const int MOD = 1e9+7;

vector<int> adj[201];
bool visited[201];
int match[201];

bool dfs(int node){
	if(visited[node]) return 0;
	visited[node] = 1;
	for(auto u : adj[node]){
		if(match[u] == -1 || dfs(match[u])){
			match[node] = u;
			match[u] = node;
			return 1;
		}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(NULL);
	int n; cin >>  n;
	vector<pair<int,int>> red (n);
	vector<pair<int,int>> blue (n);
	forn(i, n) cin >> red[i].x >> red[i].y;
	forn(i, n) cin >> blue[i].x >> blue[i].y;
	forn(i, n){
		forn(j, n){
			if(red[i].x < blue[j].x && red[i].y < blue[j].y){
				adj[i].push_back(100+j);
				adj[100+j].push_back(i);
			}
		}
	}
	forn(i, 202){
		match[i] = -1;
	}
	while(1){
		memset(visited, 0, sizeof visited);
		bool cont = 0;
		forn(i, n){
			if(match[i]==-1)cont|=dfs(i);
		}
		if(cont==0)break;
	}
	int ret = 0;
	forn(i, 100){
		if(match[i] != -1) ret++;
	}
	cout << ret << "\n";
}


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

public class Main {

    public static void main(String[] args) throws IOException {


       // BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int arr[] = new int[n];

        for(int i=0; i<n; i++){
            arr[i] = sc.nextInt();
        }

        int dp[] = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++) {
          for(int j=(i+1);j<=(i+k);j++) {
              if(j<n) {
                  dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[i]-arr[j]));
              }
          }
        }

        System.out.println(dp[n-1]);
    }
}

Measured memory_bytes: 59456
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	rep(i, 1000) {
		vector<int> res = { i % 10, i / 10 % 10, i / 10 / 10 % 10 };
		int cnt = 0;
		rep(j, n) {
			if (int(s[j] - '0') == res[cnt]) cnt++;
			if (cnt == 3) break;
		}
		if (cnt == 3) ans++;
	}

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


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


int main(int argc, char **argv)
{
	string str; cin >> str;
	int N = str.size();
	string sample1(N, '0');
	string sample2(N, '0');
	for (int i = 0; i < N; ++i)
	{
		if (i & 1)
			sample2[i] = '1';
		else
			sample1[i] = '1';
	}

	long long tmp1{0}, tmp2{0};
	for (int i = 0; i < N; ++i)
	{
		if (str[i] != sample1[i])
			++tmp1;
		if (str[i] != sample2[i])
			++tmp2;
	}
	std::cout << min(tmp1, tmp2) << std::endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int n;cin>>n;
	int a[110]={};
	fori(n){cin>>a[i];}
	bool c[8]={};int count=0;
	fori(n){
		if(a[i]<3200){
			c[a[i]/400]=true;
		}else{
			++count;
		}
	}
	int color=0;
	fori(8){color+=(c[i]?1:0);}
	cout<<color+((color==0&&count!=0)?1:0)<<" "<<color+count;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=20010;
char s[maxn],ch,ans[maxn],t[maxn];
bool cmp(char a[],char b[]) {
	int n=strlen(a+1),m=strlen(b+1);
	if (n!=m) return n<m;
	for (int i=1;i<=n;i++)
		if (a[i]!=b[i]) return a[i]<b[i];
	return 0;
}
int n,k;
bool solve() {
	int len=0;
	while (t[n-len]==ch&&len<n) len++;
	for (int i=2;i<=k&&len<n;i++) {
		for (int j=n+1;j<=n*2;j++) t[j]=t[n-(j-n)+1];
		if (i<k) for (int j=len+1;j<=n+len;j++) t[j-len]=t[j];
		else for (int j=n-len+1;j<=n*2-len;j++) t[j-n+len]=t[j];
		t[n+1]=0;
		len*=2;
	}
	t[n+1]=0;
	return 1;
}
int main() {
	read(n); read(k); scanf("%s",s+1);
	ch='z';
	for (int i=1;i<=n;i++) ch=min(ch,s[i]);
	if (k>=14) {
		for (int i=1;i<=n;i++) printf("%c",ch);
		printf("\n");
	} else {
		for (int i=n+1;i<=n*2;i++) s[i]=s[n-(i-n)+1];
		for (int i=1;i<=n*2+1;i++) ans[i]='z'+1;
		for (int i=1;i<=n+1;i++) {
			for (int j=i;j<=i+n-1;j++) t[j-i+1]=s[j];
			if (solve()&&cmp(t,ans)) {
				for (int j=1;j<=n;j++) ans[j]=t[j];
				ans[n+1]=0;
			}
		}
		printf("%s\n",ans+1);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  string S;
  cin>>S;
  
  if(
    (int)(S.length())!=A+B+1
    || S[A]!='-'
  ){
  	cout<<"No"<<endl;
    return 0;
  }
  
  bool isVaild=true;
  for(int i=0,l=A+B+1;i<l;++i){
    if(i==A)continue;
    if('0'<=S[i]&&S[i]<='9')continue;
    isVaild=false;
    break;
  }
  cout<<(isVaild?"Yes":"No")<<endl;
}

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

int main(void) {
    int N, A[100];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];
    int ans = 0;
    for (int i = 1; i < N; ++i) {
        if (A[i-1] == A[i]) {
            ++ans;
            ++i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c,i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d",&a,&b,&c);
		if(a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 2048
# https://atcoder.jp/contests/abs/tasks/abc087_b

a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0

n_500 = min(x // 500, a)
for i in range(n_500 + 1):
    remainder_500 = x - 500 * i    
    n_100 = min(remainder_500 // 100, b)
    for j in range(n_100 + 1):
        remainder_100 = remainder_500 - 100 * j
        # n_50 = min(remainder_100 // 50, c)
        if remainder_100 // 50 <= c:
            # print(i, j, remainder_100 / 5)
            ans += 1
        
print(ans)
    

Measured memory_bytes: 3060
[H,W]=[int(x) for x in raw_input().split()]
N=int(raw_input())
A=[int(x) for x in raw_input().split()]
B=[[0 for x in range(W)] for y in range(H)]
p=0
q=0
d=1
k=0
D=6
for i in range(1,N+1):
    for j in  range(A[i-1]):
        B[p][(q+k)*d]=i
        q+=1
        if q==W:
            p+=1
            q=0
            d*=-1
            k= not k
for i in range(H):
    print "".join([str(x).ljust(D) for x in B[i]])
        
        
    

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

using namespace std;

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

	string s;
	cin >> s;
	vector<int> v(26);
	for(int t=0;t<s.size();t++){
		v[int(s[t])-int('a')]++;
	}
	bool b=false;
	for(int i=0;i<26;i++){
		if(v[i]==0){
			cout << char(int('a')+i) << '\n';
			b=true;
			break;
		}
	}
	if(b==false)cout << "None\n";
}

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

using namespace std;

int main() {
    long long N,A,B;
    cin >> N >> A >> B;
    long long C = N / (A + B);
    long long D = N % (A + B);
    long long E = C * A;
    if (A < D) {
        E += A;
    } else {
        E += D;
    }
    cout << E << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define setp(n) fixed<<setprecision(n)
int main(){
    int n;
    cin>>n;
    if(n%100>0 && n%100<=12){
        if(n/100>0 && n/100<=12)
            cout<<"AMBIGUOUS"<<endl;
        else
            cout<<"YYMM"<<endl;
    }
    else{
        if(n/100>0 && n/100<=12)
            cout<<"MMYY"<<endl;
        else
            cout<<"NA"<<endl;
    }
    return 0;
}

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

int main(){
    long long A, B;
    cin >> A >> B;

    long long x = A * B;
    long long tmp;

    if(A < B){
        tmp = A;
        A = B;
        B = tmp;
    }
    
    long long r = A % B;
    
    while(r != 0){
        A = B;
        B = r;
        r = A % B;
    }
    
    cout << x / B << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
c = []
ans = 0
for i in range(N):
    tmp = list(map(int, input().split()))
    c.extend(tmp[1:])
cnt = [0 for i in range(M)]
for i in range(len(c)):
    tmp2 = c[i]-1
    cnt[tmp2] += 1

for i in range(M):
    if cnt[i] == N:
        ans += 1

print(ans)

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

int main() {
    vector<int> v(3);
    for (int i = 0; i < 3; i++) cin >> v[i];
    sort(v.begin(), v.end());
    int count = 0;
    for (int i = 0; i < 2; i++) count += v[i+1] - v[i];
    cout << count << endl;
}

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

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  char b; cin>>b;
  switch (b)
  {
  case 'A':
    cout << 'T' << endl;
    break;

  case 'C':
    cout << 'G' << endl;
    break;

  case 'G':
    cout << 'C' << endl;
    break;

  case 'T':
    cout << 'A' << endl;
    break;

  default:
    break;
  }
}

int main()
{
  solve();
  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 ll = long long;
using P = pair<int, int>;

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

	int n, a, b;
	cin >> n >> a >> b;
	int ans;
	ans = 0;
	rep(i, n + 1)
	{
		int sum;
		sum = i / 10000 + (i % 10000 / 1000) + (i % 1000 / 100) + (i % 100 / 10) + i % 10;

		if (sum >= a && sum <= b)
			ans += i;
	}
	cout << ans << endl;
}


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

struct xy{
  double x;
  double y;
};

void kock (int , struct xy ,struct xy);

int main(){
  struct xy a={0,0},b={100,0};
  int num;
  
  scanf("%d",&num);

  printf("%f %f\n",a.x,a.y);
  kock(num,a,b);
  printf("%f %f\n",b.x,b.y);
  


  return 0;

}


void kock(int n, struct xy p1,struct xy p2){

  struct xy s,t,u;
  
  if( n == 0)
    return;
  
  // p1, p2 から s, t, u を計算

  s.x = (2*p1.x + 1*p2.x)/3;
  s.y = (2*p1.y + 1*p2.y)/3;
  t.x = (1*p1.x + 2*p2.x)/3;
  t.y = (1*p1.y + 2*p2.y)/3;
  u.x = (t.x - s.x)/2 - (t.y - s.y) * sqrt(3)/2 + s.x;
  u.y = (t.x - s.x)*sqrt(3)/2 + (t.y - s.y) /2 + s.y;


  kock(n-1, p1, s);
  printf ("%f %f\n",s.x,s.y);
  kock(n-1, s, u);
  printf("%f %f\n", u.x,u.y);
  kock(n-1, u, t);
  printf("%f %f\n", t.x,t.y);
  kock(n-1, t, p2);

}



Measured memory_bytes: 2756
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<String> strs = new ArrayList<String>();
		long ans = 0;

		for(int i= 0 ; i < n ; i++){
			char[] tmp = (sc.next()).toCharArray();
			Arrays.sort(tmp);
			String tmpstr = String.valueOf(tmp);
			strs.add(tmpstr);
		}
		Collections.sort(strs);
		long cnt = 1;
		for(int i = 1 ; i < n ; i++){
			if((strs.get(i-1)).equals(strs.get(i))){
				cnt++;
			}else{
				if(cnt == 1){
				}else{
					ans += cnt*(cnt-1)/2;
				}
				cnt=1;
			}
		}

		if(cnt == 1){
		}else{
			ans += cnt*(cnt-1)/2;
		}
		cnt=1;

		System.out.println(ans);
	}

}

Measured memory_bytes: 52180
h=int(raw_input().split(' ')[0])
map=[]
for x in range(h):
 map.append(raw_input())
for row in range(h):
 for col in range(len(map[row])):
  count=0
  if map[row][col]=='.':
   for x in (-1,0,1):
    for y in (-1,0,1):
     if not (x==0 and y==0) and 0<=row+y<h and 0<=col+x<len(map[row]):
      if map[row+y][col+x]=='#':
       count+=1
   map[row]=map[row][:col]+str(count)+map[row][col+1:]
for row in map:
 print row

Measured memory_bytes: 2692
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

/*
n

n 10^5

10^9+7
 */
ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}

const ll MAX = pow(10,9) + 7;

ll f(int n){
  return n==0 ? 1 : n * f(n-1) % MAX;
}

int main(){
  int n;
  cin>>n;
  cout << f(n)%MAX << endl;

  return 0;
}


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

int64_t const MAX=pow(10,9)+7;

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> a(M);
  vector<int> b(N+1);
  for(int i=0;i<M;++i){
    cin>>a.at(i);
    b.at(a.at(i))=b.at(a.at(i))+1;
  }
  
  vector<int64_t> dp(N+1);
  for(int i=N;i>=0;--i){

    if(i==N){dp.at(N)=1;}

    else if(i==N-1){
      if(b.at(N-1)==1){dp.at(N-1)=0;}
      else{dp.at(N-1)=1;}
    }

    else{
      if(b.at(i)==1){dp.at(i)=0;}
      else{dp.at(i)=(dp.at(i+1)+dp.at(i+2))%MAX;}
    }
    
  }

  cout<<dp.at(0)<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,sum=0,p,x;
    int t[105];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>t[i];
        sum=sum+t[i];
    }
    int m;
    cin>>m;
    while(m--)
    {
        cin>>p>>x;
        cout<<sum+x-t[p-1]<<endl;
    }
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int D, E;
  while(cin>>D>>E,D){
	double ans = 1e9;
	for(int y=0;y<=D;++y){
	  int x = D - y;
	  mini(ans, abs(sqrt(y*y+x*x) - E));
	}
	cout << fixed << setprecision(9) << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3244
n = int(input())
a = []
for i in range(n):
	x, y = input().split()
	y = int(y)
	if x == "S":
		a.append(y)
	if x == "H":
		a.append(y + 13)
	if x == "C":
		a.append(y + 26)
	if x == "D":
		a.append(y + 39)
for i in range(1, 53):
	if not (i in a):
		if i <= 13:
			print("S {}".format(i - 0))
		elif i <= 26:
			print("H {}".format(i - 13))
		elif i <= 39:
			print("C {}".format(i - 26))
		else:
			print("D {}".format(i - 39))


Measured memory_bytes: 5596
N,K = list(map(int,input().split()))
s = input()
data = [int(a) for a in s]

#numsの偶数番目の要素が連続した1の個数,奇数番目の要素が連続した0の個数
#	data[1001110001] -> nums[1,2,3,3,1]
nums = []
if data[0]==0:
	nums.append(0)
i,j = 0,0
for i in range(len(data)):
	i,count = j,1
	for j in range(i+1,len(data)):
		if data[i]==data[j]:
			count+=1
		if data[i]!=data[j] or j==len(data)-1:
			nums.append(count)
			break

#累積和 nums[1,2,3,3,1] -> sums[0,1,3,6,9,10]
sums = [0]
for i in range(len(nums)):
	sums.append(sums[i] + nums[i])

#連続した0を1にする操作をK回行うと、2K+1個連続した1の要素が並ぶ 
ans = 1
for i in  range(0,len(sums),2):
	j = i + K*2+1
	if j>=len(sums):
		j = len(sums)-1
	ans = max(ans, sums[j]-sums[i])

print(ans)


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

template<typename T>
struct UnionFind
{
    vector<T> parents;
    vector<T> rank;
    UnionFind(T n):parents(n),rank(n,0){
        for (T i=0;i<n;i++){
            parents[i] = i;
        }
    }
    T root(T x){
        //再帰的に根をつけなおす//rootを返す
        return parents[x] == x ? x: parents[x] = root(parents[x]);
    }
    //mergeする　すでに一致してたらfalseを返す。
    bool unite(T x, T y){
        if (x==y) return false;
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        parents[y] = x;
        return true;
    }
    bool same(T x, T y){
        if (x==y) return true;
        return root(x) == root(y);
    }
};

void solve(long long N, long long K, long long L, std::vector<long long> p, std::vector<long long> q, std::vector<long long> r, std::vector<long long> s){
    UnionFind<long long> train(N);
    UnionFind<long long> road(N);
    for (ll i=0;i<K;i++){
        road.unite(p[i]-1,q[i]-1);
    }
    for (ll i=0;i<L;i++){
        train.unite(r[i]-1,s[i]-1);
    }
    map<pair<ll,ll>,ll> counts;
    for (ll i=0;i<N;i++){
        auto idx = make_pair(road.root(i),train.root(i));
        if (counts.count(idx)){
            counts[idx]+=1;
        }else{
            counts[idx] = 1;
        }
    }
    for (ll i=0;i<N;i++){
        auto idx = make_pair(road.root(i),train.root(i));
        printf("%lld",counts[idx]);
        if (i<N-1){
            printf(" ");
        }else{
            printf("\n");
        }
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long L;
    scanf("%lld",&L);
    std::vector<long long> p(K);
    std::vector<long long> q(K);
    for(int i = 0 ; i < K ; i++){
        scanf("%lld",&p[i]);
        scanf("%lld",&q[i]);
    }
    std::vector<long long> r(L);
    std::vector<long long> s(L);
    for(int i = 0 ; i < L ; i++){
        scanf("%lld",&r[i]);
        scanf("%lld",&s[i]);
    }
    solve(N, K, L, std::move(p), std::move(q), std::move(r), std::move(s));
    return 0;
}


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

int gcd_th(int a, int b, int c){
  return gcd(a, gcd(b, c));
}


int main(void){
  long long N;
  cin >> N;
  long long sum = 0;
  for(long long i = 1; i <= N; i++){
   if(i % 3 == 0) continue;
    if(i % 5 == 0) continue;
    else sum += i;    
  }
  cout << sum;
  
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
int n = 0 , x =  0 , t = 0 , t_x = 0;
	
int main(){
    std::cin>>n>>x>>t;
    t_x = n / x;
    if( n % x > 0){
    t_x++;
    }
    t_x *= t;
    std::cout<<t_x;    
}

Measured memory_bytes: 3584
#include<stdio.h>
int main()
{
  int n,i=0,j,g,cnt=0,k,h;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  cnt=0;
  int m=0;
  int G[10]={0};
  for(i=0;i<n;i++){
    if(i==0){G[0]=1; m++; continue;}
    g=(3*G[i-1]+1);
    if(g>n)break;
    G[i]=g;
    m++;
    }
  printf("%d\n",m);
  for(i=m-1;i>=0;i--){
  printf("%d",G[i]);
  if(i!=0)printf(" ");
  }
  for(h=m-1;h>=0;h--){
    for(i=G[h];i<n;i++){
      int v=a[i];
      j=i-G[h];
      while(j>=0 && a[j]>v){
        a[j+G[h]]=a[j];
        j=j-G[h];
        cnt++;
      }
      a[j+G[h]]=v;
    }
  }
  printf("\n");
  printf("%d\n",cnt);
  for(i=0;i<n;i++){
    printf("%d\n",a[i]);
  }
  return 0;
}


Measured memory_bytes: 5640
def key_func(n):
    return n[0]

n,m = map(int, input().split(" "))
a_b = []
for i in range(n):
    a_b.append(list(map(int,input().split(" "))))

a_b.sort(key=key_func)

money = 0

for item in a_b:
    i = min(m,item[1])
    money = money + item[0]*i
    m = m - i
    if m <= 0:
        break

print(money)

Measured memory_bytes: 29020
n=int(input())
a=list(map(int,input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

from functools import reduce
def lcm_multi(num_list):
    return reduce(lcm, num_list, 1)
k=lcm_multi(a)
answer=0
for i in range(n):
    answer+=k//a[i]
print(answer%(10**9+7))

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

using namespace std;

int main(){

    int a,b,c,d,left,right;

    cin >> a >> b;
    cin >> c >> d;
    left = a+b;
    right = c+d;

    if(left>right){
        cout << "Left" << endl;
    }
    else if(right>left){
        cout << "Right" << endl;
    }
    else{
        cout << "Balanced" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

int main(void)
{
	double N = 0;
	double K = 0;
	double prob = 0;
	cin >> N;
	cin >> K;

	for (int i = 1; i <= N; i++)
	{
		int val = i;
		int exp = 0;
		for (int j = 0; j <= ((int)log2(K) + 1); j++)
		{
			if (val >= K)
			{
				break;
			}
			else
			{
				val *= 2;
				exp++;
			}
		}
		prob += (1.0 / N) * pow(0.5, exp);
	}
	cout.precision(12);
	cout << fixed <<  prob;
}

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

typedef struct Card{
    char type;
    int num;
    int sl;
    bool operator < (const Card &x) const{ return num<x.num; }
};

void sort_bubble(Card card[], int n){
    for(int i = 0; i < n; i++){
        for(int j = n-1; j >= i+1; j--){
            if(card[j]<card[j-1]) swap(card[j], card[j-1]);
        }
    }
}

void sort_selection(Card card[], int n){
    for(int i = 0; i < n; ++i){
        int mini = i;
        for(int j = i; j < n; j++){
            if(card[j]<card[mini]) mini = j;
        }
        swap(card[i], card[mini]);
    }
}

void print_cards(Card card[], int n){
    for(int i = 0; i < n; ++i){
        if(i) cout << " ";
        cout << card[i].type << card[i].num;
    }
    cout << endl;
}

void check_stability(Card card[], int n){
    for(int i = 0; i < n-1; ++i){
        if(card[i].num<card[i+1].num)
            continue;
        if(card[i].sl>card[i+1].sl){
            cout << "Not stable" << endl;
            return;
        }
    }
    cout << "Stable" << endl;
    return;
}

int main(){
    //FILE *inp = freopen("in.txt", "r", stdin);
    int n;
    cin>>n;
    Card card1[n], card2[n];
    int val;
    char ch;
    for(int i = 0; i < n; ++i){
        cin>>ch>>val;
        card1[i].type = card2[i].type = ch;
        card1[i].num = card2[i].num = val;
        card1[i].sl = card2[i].sl = i;
    }
    sort_bubble(card1, n);
    sort_selection(card2, n);
    print_cards(card1, n);
    check_stability(card1, n);
    print_cards(card2, n);
    check_stability(card2, n);
    //fclose(inp);
    return 0;
}

Measured memory_bytes: 3104
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
A, B, C, D = map(int, input().split())
X = B//C - (A-1)//C
Y = B//D - (A-1)//D
E = (C*D)//gcd(C,D)
Z = B//E - (A-1)//E
print(B-A-X-Y+Z+1)

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	long n,a[10000];

	cin >> n;

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

	int p = 0;

	sort(a,a + n);

	for (long i = 0; i < n; i++)
	{
		for (long j = 0; j < n; j++)
		{
			if (i < j && (a[j] - a[i]) % (n - 1) == 0)
			{
				cout << a[i] << " " << a[j] << endl;
				p += 1;
				break;
			}
		}
		if (p != 0)
		{
			break;
		}
	}
}


Measured memory_bytes: 3156
n = gets.to_i
inputs = []
n.times do
  inputs << gets.to_i
end

min_value = inputs[0]
max_value = -100_000_000_000
inputs[1..-1].each do |num|
  max_value = [max_value, num - min_value].max
  min_value = [min_value, num].min
end

puts max_value

Measured memory_bytes: 11160
#include <stdio.h>

int main(){
  int w, h, x, y, r;

  scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);

  if(((x - r) < 0 || (x + r) > w) ||
     ((y - r) < 0 || (y + r) > h)){
    printf("No\n");
  } else {
    printf("Yes\n");
  }
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld ;
#define pb push_back
#define fi first
#define se second
const int N = 55;
const ll mod = 1e9+7;
int adj[N][N];
bool vis[N];
ll msk;
ll par;
int n;
void dfs(int a, int b){
    if(a==b){
        msk = par;
    }
    vis[a] = true;
    for(int i=1;i<=n;i++){
        if(adj[a][i]==0)continue;
        if(vis[i])continue;
        par|=(1ll<<(adj[a][i]-1));
        dfs(i,b);
        if(par&(1ll<<(adj[a][i]-1)))par^=(1ll<<(adj[a][i]-1));
    }
}
ll arr[55];
int popcnt(ll x){
    int ret = 0;
    while(x){
        ret+=x%2;
        x/=2;
    }
    return ret;
}
void solve(){
    cin>>n;
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        adj[x][y] = adj[y][x] = i;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        memset(vis,false,sizeof vis);
        par = 0;
        msk = 0;
        dfs(x,y);
        arr[i] = msk;
    }
    ll ans = (1ll<<(n-1));
    for(int i=1;i<(1<<m);i++){
        ll prd = 0;
        ll mask=0;
        for(int j=0;j<m;j++){
            if(i&(1<<j)){
                prd++;
                mask|=arr[j];
            }
        }

        ll pp = n-1-popcnt(mask);
        ll trt = (1ll<<pp);
        if(prd%2==1)trt*=-1;
        ans+=trt;
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//    preprocess();
    int t =1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string S, T, ans = "";
  cin >> S >> T;
  for (int i = 0; i < N; i++) {
    ans += S.at(i);
    ans += T.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def func(s, li):
    ans = 0
    for a in li:
        if s < 0 and s + a <= 0:
            ans += -(s + a) + 1
            s = 1
        elif s > 0 and s + a >= 0:
            ans += (s + a) + 1
            s = -1
        else:
            s = s + a
    return ans

n = list(map(int, input().split()))
li = list(map(int, input().split()))

ans0 = 0
s = li[0]
if s >= 0:
    ans0 += s + 1
    s = -1
ans0 += func(s, li[1:])
ans1 = 0
s = li[0]
if s <= 0:
    ans1 += -s + 1
    s = 1
ans1 += func(s, li[1:])

print(min(ans0, ans1))

Measured memory_bytes: 14468
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

const int MAXN=1E5+10;
vector<int> g[MAXN];

int main(){FIN;
	int n,m; cin>>n>>m;
	fore(i,0,m){
		int x,y; cin>>x>>y; x--; y--;
		g[x].pb(y); g[y].pb(x);
	}
	vector<int> ds(n,1e9),par(n,-1);
	queue<int> q; q.push(0); ds[0]=0;
	while(SZ(q)){
		int v=q.front(); q.pop();
		for(auto x:g[v]) if(ds[x]>ds[v]+1) ds[x]=ds[v]+1,par[x]=v,q.push(x);
	}
	fore(i,1,n) if(par[i]<0)cout<<"No\n",exit(0);
	cout<<"Yes\n";
	fore(i,1,n) cout<<par[i]+1<<"\n";
}

Measured memory_bytes: 10680
#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
#include <ext/pb_ds/detail/standard_policies.hpp>


/* 
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end() 
#define mod 1000000007
//#define maxx 200006
#define ll long long 
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long > 
#define listi vector< int> 
#define pii   pair<int , int> 
#define pll pair<long long , long long > 
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


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


// end of #define 

// define globals ...
const int maxx = 2e5+26;

//write function from here ...







int Main(){


ll n;
cin>>n;


ll arr[n+1];

for(int i= 1;  i<=  n ;i++){
	
	
	int a;
	cin>>a;
	
	arr[a]=i ;
	
}

for(int a= 1; a<=n;a++)
cout<<arr[a]<<" ";



return 0;

}






int main(){
 quick;
int t =1; 
//cin>>t;
while(t-- )
 Main();

 return 0;


}


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

using namespace std;

int keta(long long b){
    int ans = 0;
    
    while (b > 0){
        b /= 10;
        ans++;
    }
    return ans;
}

int main(void){
   long long n;
   cin >> n;
   
   int ans = 16;
   
   for (long long i = 1; i * i <= n; i++){
       if (n % i != 0) continue;
       long long b = n / i;
       
       int temp1 = keta(i);
       int temp2 = keta(b);
       
       int temp3 = max(temp1,temp2);
       ans = min(ans,temp3);
   }
   cout << ans << endl;
}


Measured memory_bytes: 3616
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

int a, b, k;

int main() {
  init_ios();
  cin >> a >> b >> k;
  for (int i = a; i >= 1; --i)
    if (a%i == 0 && b%i == 0) {
      --k;
      if (k == 0) {
        cout<<i<<"\n";
        return 0;
      }
    }
}

Measured memory_bytes: 256
import collections
s = input()


cnt = collections.Counter(s)
used = set(cnt.keys())
c = -1
if len(used) < 26:
    for i in range(26):
        if not chr(i+ord("a")) in used:
            c = chr(i+ord("a"))
            break
if c != -1:
    print(s+c)
else:
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print("-1")
        exit()
    i = 25
    while i > 1 and s[i-1] > s[i]:
        i -= 1
    lused = sorted(s[i-1:])
    print(s[:i-1]+lused[lused.index(s[i-1])+1])


Measured memory_bytes: 9384
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,n,x,a,t;
    scanf("%d%d%d",&n,&x,&t);
    a = (n/x)+1;
    if(n%x==0)
    {
        printf("%d\n",(n/x)*t);
    }

    else
    {
        printf("%d\n",a*t);
    }
    return 0;
}


Measured memory_bytes: 1736
def g(x):
    return (x, 1, x + 1, 0)[x % 4]


def f(a, b):
    return g(b) ^ g(a - 1)


def main():
    a, b = (int(z) for z in input().split())
    print(f(a, b))


if __name__ == "__main__":
    main()

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

int main() {
  int N;
  cin >> N;
  int i = 0;
  int j = 0;
  while (i < N){
    string S;
    cin >> S;
    if ( S == "Y" ){
      j ++;
    }
   i++;
  }
  
  if ( j > 0 ){
    cout << "Four" <<endl;
  }
  else {
    cout << "Three" << endl;
  }
}



Measured memory_bytes: 256
main :: IO ()
main = do
    [sx,sy,tx,ty] <- map read . words <$> getLine :: IO [Int]
    let x = tx - sx
        y = ty - sy
        a = [ (y,'U'), (x,'R'), (y,'D'), (x+1,'L')
            , (y+1,'U'), (x+1,'R'), (1,'D'), (1,'R')
            , (y+1,'D'), (x+1,'L'), (1,'U')]
    putStrLn $ concatMap (uncurry replicate) a

Measured memory_bytes: 1020
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int H,W;
    cin >> H >> W;
    char C[H][W];
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            cin >> C[i][j];

    for(int i = 0; i < 2 * H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            int k = i / 2;
            cout << C[k][j];
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
n = N
b_list = [int(b) for b in input().split()]

a_list = []
while(1):
    flag_i = -1
    for i in range(n):
        if i+1 == b_list[i]:
            a = b_list[i]
            flag_i = i
    if flag_i == -1:
        break
    a_list.append(a)
    b_list.pop(flag_i)
    n -= 1

if len(a_list) != N:
    print(-1)
else:
    for a in a_list[::-1]:
        print(a)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int(i)=0;i<(n);i++)
const ll INF = 9223372036854775807;
#define MAX_V 100001
#define MAX_E 100000

struct edge{
  ll to, cost;
};
typedef pair<int, int> P;

int V,E;
vector<edge> G[MAX_V];
ll d[MAX_V];

void input_graph(){
  int s,t,c;
  REP(i,E){
    cin>>s>>t>>c;s--;t--;
    G[s].push_back({t,c});
    G[t].push_back({s,c});
  }
}

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d+V, INF);
  d[s]=0;
  que.push(P(0,s));

  while(!que.empty()){
    P p=que.top();que.pop();
    int v=p.second;
    if(d[v]<p.first) continue;
    REP(i,G[v].size()){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main(){
  cin>>V;E=V-1;
  input_graph();
  
  int q,k;cin>>q>>k;k--;
  dijkstra(k);
  
  REP(i,q){
    int x,y;cin>>x>>y;x--;y--;
    cout<<d[x]+d[y]<<endl;
  }
}

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

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    ll n;
    cin >> n;
    if(n==1) {cout << 0 << endl; return 0;}
    if(is_prime(n)) {cout << 1 << endl; return 0;}
    const auto &res = prime_factorize(n);
    ll time = 0;
    for(auto p : res){
        if(p.second==0) continue;
        ll num = 1;
        while(1){
            p.second-=num;
            if(p.second<0) break;
            time++;
            num++;
        }
    }
    cout << time << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>

using namespace std;

#define mod 1000000007

int w, h;
int s[31][31];
int c[4];

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

int solve()
{
	int cost[31][31][4];
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			for(int k = 0; k < 4; k++){
				cost[i][j][k] = mod;
			}
		}
	}
	queue<pair<pair<int, int>, int> > qu;
	cost[0][0][0] = 0;
	qu.push(make_pair(make_pair(0, 0), 0));
	while(!qu.empty()){
		int x = ((qu.front()).first).first;
		int y = ((qu.front()).first).second;
		int d = (qu.front()).second;
		// (x, y)?????????????????????d (dx, dy??¨??????)
		qu.pop();
		// cout << x << " " << y << " " << d << ":" << endl;
		for(int i = 0; i < 4; i++){
			// i : ???????????????
			int nc = cost[x][y][d];
			int nd = (d + i) % 4;
			int nx = x + dx[nd];
			int ny = y + dy[nd];
			if(nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
			if(i != s[x][y]) nc += c[i];
			if(cost[nx][ny][nd] > nc){
				cost[nx][ny][nd] = nc;
				qu.push(make_pair(make_pair(nx, ny), nd));
				// cout << nx << " " << ny << " " << nd << " " << nc << endl;
			}
		}
	}
	int ans = mod;
	for(int i = 0; i < 4; i++){
		ans = min(ans, cost[h - 1][w - 1][i]);
	}
	return ans;
}

int main()
{
	while(1){
		cin >> w >> h;
		if(w == 0 && h == 0) break;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin >> s[i][j];
			}
		}
		for(int i = 0; i < 4; i++){
			cin >> c[i];
		}
		cout << solve() << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
i = list(map(int, input().split()))
def in_retangle(w,h,x,y,r):
    if r<=y and y<=h-r and r<=x and x<=w-r:
        print("Yes")
    else:
        print("No")
    
in_retangle(i[0],i[1],i[2],i[3],i[4])


Measured memory_bytes: 5600
int main()
{
     int a,b,c,d,s1,s2;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        s1=a*b;
        s2=c*d;
        if(s1>s2)
            printf("%d\n",s1);
        if(s1<s2)
            printf("%d\n",s2);
        if(s1==s2)
            printf("%d\n",s1);
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		while(!(a == 0 && b == 0)){
			int n = sc.nextInt();
			int [][] dis = new int[b+1][a+1];
			//初期値
			for(int i=0; i <= b; i++){
				int set = 0;
				if(i == 0){
					set = 0;
				}
				else {
					set = 1;
				}
				dis[i][0] = 0;
				for(int j = 1; j <= a; j++){
					dis[i][j] = set;
				}
			}
			
			for(int i=0; i  < n; i++){
				int x = sc.nextInt();
				int y = sc.nextInt();
				dis[y][x] = 0;
			}
			
			for(int i=1; i <= b; i++){
				for(int j =1; j <= a; j++){
					if(dis[i][j] == 0){
						continue;
					}
					int left = dis[i][j-1] ;
					int bottom = dis[i-1][j];
					if(i != 1 || j != 1){
						dis[i][j] = left + bottom;
					}
				}
			}
			System.out.println(dis[b][a]);
			
			a = sc.nextInt();
			b = sc.nextInt();
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

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

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

const long long INF = 1LL << 60;

int main(){
  char c;
  cin >> c;

  if('a' <= c && c <= 'z'){
    cout << 'a' << endl;
  }
  else{
    cout << 'A' << endl;
  }

  return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		scan.nextLine();
		String[] ary = scan.nextLine().split(" ");
		scan.close();
		int max = Integer.parseInt(ary[0]);
		int min = max;
		int value;
		for(int i=1; i<ary.length; i++) {
			value = Integer.parseInt(ary[i]);
			if(max < value) {
				max = value;
			}
			if(value < min) {
				min = value;
			}
		}
		System.out.println(max-min);
	}

}

Measured memory_bytes: 21844
#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;

int main(){
	string str;
	int m; 

	while(cin>>str){
		if(str=="-")break;
		cin>>m;
		for(int i=0; i<m; i++){
			int h;
			cin>>h;
			string cat=str.substr(0,h);
			str.erase(0,h);
			str=str+cat;
		}
		cout<<str<<endl;
	}

	return 0;

}


Measured memory_bytes: 3220
#include<stdio.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  int next=(tail+1)%LEN;

  Q[tail]=x;
  tail=next;
}

P dequeue(){
  P val;

  val=Q[head];
  head=(head+1)%LEN;
  return val;
}

int min(int q,int x){
  if(q<x) return q;
  else return x;
}

int main(){
  P ori; 
  int i,q,j,keika=0,t;

  scanf("%d%d",&n,&q);
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head=1;
  tail=n+1;

  while(head!=tail){
      ori=dequeue();
      t=min(q,ori.t);
      ori.t-=t;
      keika+=t;
      if(ori.t>0) enqueue(ori);
      else {
	printf("%s",ori.name);
	printf("%c",' ');
	printf("%d\n",keika);
      }
  }
  
  return 0;
}





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

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string ans, str; cin >> str;
	for(auto ch: str) {
		if(ch == 'B') {
			if(ans.size()) ans.pop_back();
		} else {
			ans.push_back(ch);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <bitset>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

struct Edge {
	int from, to, s;
};

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	int Max = max({ a,b,c }), Min = min({ a,b,c });

	cout << Max - Min << endl;

	return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(3 * n);
	for (int i = 0; i < 3 * n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += a[3 * n - i * 2];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408