akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
const int N = 100010;
int parents[N];
int res[N];
int friends[N];
int n,m,k;

int find(int curr){
  if(parents[curr] != parents[parents[curr]]) parents[curr] = find(parents[curr]);
  return parents[curr];
}

int main(){
  cin >> n >> m >> k;
  for(int i = 1; i <= n; i ++){
    parents[i] = i;
    res[i] = 1;
  }
  while(m --){
    int a, b;
    cin >> a >> b;
    int pa = find(a);
    int pb = find(b);
    if(pa != pb){
      parents[pa] = pb;
      res[pb] += res[pa];
    }
    friends[a] ++;
    friends[b] ++;
  }
  for(int i = 1; i <= n; i ++){
    res[i] = res[find(i)];
  }
  while(k --){
    int a, b;
    cin >> a >> b;
    int pa = find(a);
    int pb = find(b);
    if(pa == pb){
      res[a] --;
      res[b] --;
    }
  }
  for(int i = 1; i <= n; i ++){
    //cout << parents[i] << endl;
    cout << res[i]-1 - friends[i] << " ";
  }
  cout << endl;
  return 0;
}


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

int main(){
  // 入力
  long int N, M;
  cin >> N >> M;
  vector<long int> A(M);
  long int sum = 0;
  for (long int i=0; i<M; i++) {
    cin >> A[i];
    sum += A[i];
  } 

  long int result = -1;
  if (N>=sum) {
    result = N - sum;
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3672
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int a = s.indexOf("A");
		int b = s.lastIndexOf("Z");
		int c = s.length();
		System.out.println(b-a+1);
	}
}

Measured memory_bytes: 24820
n = raw_input()

result =""

for var in n:
    if var == "0":
        result = result + var
    elif var == "1":
        result = result +var
    elif var == "B":
        tmp = ""
        for s in range(0,len(result)-1):
            tmp = tmp + result[s]
        result = tmp
print result


Measured memory_bytes: 2568
from time import time
start=time()
from copy import deepcopy
from random import randint

d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
    a=list(map(int,input().split()))
    s.append(a)

def score_calculator(l):
    score=0
    las=[0]*26
    for i in range(d):
        for j in range(26):
            las[j]+=1
        las[l[i]]=0
        for j in range(26):
            score-=las[j]*c[j]
        score+=s[i][l[i]]
    return score
    
highest_sum_score=-1000000000000

for i in range(1,13):
    last=[0]*26
    temp_ans_lst=[]
    for j in range(d):
        daily_highest_score=-10000000000000
        for k in range(26):
            temp_score=s[j][k]
            temp_last=deepcopy(last)
            for p in range(26):
                temp_last[p]+=1
            temp_last[k]=0
            for p in range(26):
                down=temp_last[p]
                for q in range(i):
                    qdown=down+i+1
                    down+=qdown
                temp_score-=down*c[p]
            if temp_score>daily_highest_score:
                daily_highest_score=temp_score
                daily_choice=k
        for k in range(26):
            last[k]+=1
        last[daily_choice]=0
        temp_ans_lst.append(daily_choice)
    if score_calculator(temp_ans_lst)>highest_sum_score:
        ans_lst=deepcopy(temp_ans_lst)
        highest_sum_score=score_calculator(temp_ans_lst)
        
while time()-start<1.9:
    a=randint(0,d-2)
    temp_ans_lst=deepcopy(ans_lst)
    temp_ans_lst[a],temp_ans_lst[a+1]=temp_ans_lst[a+1],temp_ans_lst[a]
    if score_calculator(temp_ans_lst)>highest_sum_score:
        ans_lst=deepcopy(temp_ans_lst)
        highest_sum_score=score_calculator(temp_ans_lst)

for i in ans_lst:
    print(i+1)

Measured memory_bytes: 90952
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;
#define int long long

namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const ll INF=LLONG_MAX;
/*
2
8
0
325125
65026
*/
vint dp(256,0);
void mainmain(){
	int n,m;
	while(cin>>n>>m,n||m){
		vint c(m),x(n);
		rep(i,m) cin>>c[i];
		rep(i,n) cin>>x[i];
		rep(i,256) dp[i]=INF;
		dp[128]=0;
		rep(i,n){
			vint tmp(256,INF);
			rep(j,m){
				rep(k,256){
					int t=k+c[j];
					if(t<0) tmp[0]=min(tmp[0],dp[k]);
					else if(t>255) tmp[255]=min(tmp[255],dp[k]);
					else tmp[t]=min(tmp[t],dp[k]);
				}
			}
			rep(j,256){
				if(tmp[j]==INF) continue;
				tmp[j]+=(j-x[i])*(j-x[i]);
			}
			dp=tmp;
			// rep(i,256) cout<<i<<" "<<dp[i]<<endl;
			// cout<<endl;
		}
		int ans=INF;
		rep(i,256){
			ans=min(ans,dp[i]);
		}
		cout<<ans<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

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

using namespace std;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<lli, lli> pi;


int main()
{

    {
        set<int> st;
        for(int i=0; i<3; i++){
            int x;
            cin >> x;
            st.insert(x);
        }
        if(st.size() == 2) printf("Yes\n");
        else printf("No\n");
    }

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a, b, c;
    int n = 0;
    scanf("%d%d%d", &a, &b, &c);
    for (int i = a; i <= b; i++)
    {
        if (c % i == 0)
        {
            n = n+1;
        }
    }
    printf("%d\n", n);

    return 0;
}


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

using namespace std;

int main(void)
{
	int n;
	
	std::cin >> n;
	
	std::vector<int> a(n);
	for(int i = 0; i < n; i++)
	{
		std::cin >> a[i];
	}
	
	std::reverse(a.begin(), a.end());
	
	for(int i = 0; i < n; i++)
	{
		if( i != n - 1 )
			std::cout << a[i] << " ";
		
		else 
			std::cout << a[i] << std::endl;
	}
	
	return 0;
}


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

int main() {
  string s,t;
  cin >> s;
  cin >> t;
  
  int c=0;
  for(int i=0;i<s.length();i++){
    if(s.at(i)==t.at(i))	continue;
    else	c++;
  }
  cout << c;
  return 0;
}

Measured memory_bytes: 3912
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, a; 
	cin >> n >> a;
	for(int i = 0; i <= 10000 / 500; i++){
		for(int j = 0; j <= a; j++){
			if(i * 500 + j == n){
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,x=0;
    cin>>a>>b>>c;
    for (int i=a;i<=b;i++){
        if (c%i==0){
            x=x+1;
        }
    }
    cout<<x<<endl;
}



Measured memory_bytes: 3096
#!/usr/bin/env python3

st = []
for _ in range(2):
    st.append(input())
S=st[0]
T=st[1]

ans=len(T)

for i in range(len(S)-len(T)+1):
    diff=0
    for j in range(len(T)):
        if S[i+j]!=T[j]:
            diff+=1
    ans=min(ans,diff)

print(ans)



Measured memory_bytes: 9120
object Main extends App {
  @scala.annotation.tailrec
  def loop(store: Seq[(Long, Long)], acc: Long, count: Long): Long = {
    if (count <= 0) acc else store match {
      case Seq() => acc
      case (price, number) :: xs => loop(xs, acc + price * count.min(number), count - number)
    }
  }

  val sc = new java.util.Scanner(System.in)
  val N, M = sc.nextInt()
  println(loop(List.fill(N)(sc.nextLong() -> sc.nextLong()).sortBy(_._1), 0L, M))
}


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

#ifdef DEBUG
#define watch(x) cout << "DEBUG: " << (#x) << " = " << (x) << endl
#else
#define watch(x) ;
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define endl "\n"
const int INF = 0x3f3f3f3f;

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - (((begin) > (end)) << 1))

#define fi first
#define se second
#define pb push_back
#define all(X) begin(X),end(X)

#define rd1(x) scanf("%d", &x)
#define rd2(x, y) scanf("%d%d", &x, &y)
#define rd3(x, y, z) scanf("%d%d%d", &x, &y, &z)

#define rdl1(x) scanf("%lld", &x)
#define rdl2(x, y) scanf("%lld%lld", &x, &y)
#define rdl3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)

#pragma GCC optimize ("Ofast")
#pragma GCC target("avx,avx2")


int main() {

#ifdef DEBUG
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	int n,m;
	cin >> n >> m;
	vi kk[n+1];
	bool p[m];

	rep(i,0,m) {
		int k;
		cin >> k;

		rep(j,0,k){
			int s;
			cin >> s;
			kk[s].pb(i+1);
		}
	}

	rep(i,0,m) {
		cin >> p[i];
	}

	int res = 0;
	bool pp[m];
	rep(i,0,1<<n){
		memset(pp,0,sizeof pp);

		for(int j = 0; (1 << j) <= i; j++)
			if((1<<j)&i)
				rep(k,0,(int) kk[j+1].size())
					pp[kk[j+1][k]-1] = !pp[kk[j+1][k]-1];

		rep(j,0,m)
			if(p[j] == pp[j]){
				if(j == m-1)
					res++;
			} else
				break;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	a,b = IN()
	is_a=lambda x:14 if x==1 else x
	a=is_a(a)
	b=is_a(b)
	if a==b:
		return 'Draw'
	ret='Alice' if a > b else 'Bob'
	return ret
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 38384
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Set<Character> set = new HashSet<>();
		String s = sc.next();
		for (char c : s.toCharArray()) {
			set.add(c);
		}
		
		System.out.println(set.size() == 3 ? "Yes" : "No");
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n + 2];
		int[] s1 = new int[n + 2];
		int[] s2 = new int[n + 2];
		
		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();
			s1[i] = s1[i - 1] + Math.abs(a[i] - a[i - 1]);
		}
		
		for (int i = n; i >= 0; i--) {
			s2[i] = s2[i + 1] + Math.abs(a[i] - a[i + 1]);
		}
		
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= n; i++) {
			int d = s1[i - 1] + Math.abs(a[i - 1] - a[i + 1]) + s2[i + 1];
			sb.append(d);
			sb.append('\n');
		}
		
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 61184
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
using namespace std;

int main() {
	string a, b;
	cin >> a; b = a;
	reverse(b.begin(), b.end());
	for (int i = 0; i < b.length(); i++) {
		if (b[i] == 'b')b[i] = 'd';
		else if (b[i] == 'd')b[i] = 'b';
		else if (b[i] == 'p')b[i] = 'q';
		else if (b[i] == 'q')b[i] = 'p';
	}
	if (a == b)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){
  int j,m,n,i;
  while(fscanf(stdin,"%d %d",&m,&n)!=EOF&&m>=0&&n>=0){
    for(i=1,j=m+n;;i++){
      j/=10;
      if(j==0) break;
    }
    printf("%d\n",i);
  }
  return 0;
}

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


//unionfind
//根にはグループの要素数（負）、それ以外には根の値
//初期値は―1
vector<int> uni(100000,-1);
//引数aの根を求める、なければaを根として返す
int root(int a){
    if(uni[a] < 0) return a;
    return uni[a] = root(uni[a]);  
}
//頂点aとbを繋ぐ
//元々同じグループであればfalse
bool unite(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;
    if(uni[a] > uni[b]){
        a ^= b;
        b ^= a;
        a ^= b;
    }
    uni[a] += uni[b];
    uni[b] = a;
    return true;
}
//頂点aとbが同じグループかを調べる
bool isconnected(int a, int b){
    return root(a) == root(b);
}
//頂点aを含むグループの頂点数を調べる
int unisize(int a){
    return -uni[root(a)];
}

//main
int main(){
    ll n,m; cin >> n >> m;
    vector<int> a(m),b(m); rep(i,m) cin >> a[i] >> b[i];
    vector<ll> ans(m);
    ans[m-1] = n*(n-1)/2;
    for(ll i = m-2; i >= 0; i--){
        if(!isconnected(a[i+1],b[i+1])) ans[i] = ans[i+1] - ll(unisize(a[i+1]))*ll(unisize(b[i+1]));
        else ans[i] = ans[i+1];
        unite(a[i+1],b[i+1]);
    }
    rep(i,m) cout << ans[i] << endl;
}

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

int main() {
    int N, K; cin >> N >> K;
    vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = K; i < N; i++) {
        if (A[i-K] < A[i]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

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

int ceil(int a, int b) {
    return (a % b == 0  ? a/b : a/b+1);    
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int A, B; cin >> A >> B;
    //1, 4, 7, 10
    int ans = ceil((B-1),(A-1));
    cout << ans << '\n';

}



Measured memory_bytes: 256
// READ & UNDERSTAND
// ll, int overflow, array bounds
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int a,b,k;
	cin >> a >> b >> k;
	int gcd = __gcd(a,b);
	vi fac;
	for(int i=1; i<=sqrt(gcd); i++){
		if(gcd%i==0){
			fac.pb(i);
			if(gcd/i!=i)fac.pb(gcd/i);
		}
	}
	sort(all(fac));
	cout << fac[fac.size()-k] << endl;
}	


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

int main() {
string S;
cin >> S;
if(S.at(6) != '5' && S.at(6) != '6' && S.at(6) != '7' &&S.at(6) != '8' &&S.at(6) != '9' && S.at(5) != '1' ){ 
cout << "Heisei" <<endl;
}
else{cout << "TBD" <<endl;}
} 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
using namespace std;

typedef long long ll;

ll NumCount(ll Count0, ll Count1, string &S, ll AC0, ll AC1){
    ll AllCount = 0;
                if(Count0 <= Count1){
                    AllCount += AC1;
                    AllCount += AC0-Count0;
                    }
                else{
                    AllCount += AC1-Count1;
                    AllCount += AC0;
                    }
    return AllCount;
    }
int main(){
    string S;
    cin >> S;
    ll Count0 = 0;
    ll ACount0 = 0;
    ll Count1 = 0;
    ll ACount1 = 0;
    ll AllCount = 0;
    if(S.size()==1){
        cout << 1;
        }
    else{
            if(S[0] == '<'){
                Count0++;
                ACount0 += Count0;
                }
            else{
                Count1++;
                ACount1 += Count1;
                }
    for(int i=1; i<S.size()-1; i++){
            if(S[i-1] == '<' && S[i] == '<'){
                Count0++;
                ACount0 += Count0;
                }
            else if(S[i-1] == '>' && S[i] == '<'){
                    AllCount += NumCount(Count0, Count1, S, ACount0, ACount1);
                    Count0 = 1;
                    ACount0 = Count0;
                    Count1 = 0;
                    ACount1=0;
                }
            else{
                Count1++;
                ACount1 += Count1;
                }
        }
            if(S[S.size()-2] == '>' && S[S.size()-1] == '<'){
                AllCount += NumCount(Count0, Count1, S, ACount0, ACount1);
                AllCount++;
                }
            else if(S[S.size()-1] == '>'){
                Count1++;
                ACount1+=Count1;
                AllCount += NumCount(Count0, Count1, S, ACount0, ACount1);
                }
            else{
                Count0++;
                ACount0+= Count0;
                AllCount += ACount0;
                }
        cout << AllCount;
    }
}

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

bool isMSPrime(int in) {
    for (int i = 1; ; i++) {
        int div = 7 * i - 1;
        if (2 * div > in) {
            break;
        }
        if (in % div == 0) {
            return false;
        }
        div += 2;
        if (2 * div > in) {
            break;
        }
        if (in % div == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 1) {
            break;
        }
        vector<int> output;
        for (int i = 1; ; i++) {
            int divide = 7 * i - 1;
            if (divide > n) {
                break;
            }
            if (n % divide == 0 && isMSPrime(divide)) {
                output.push_back(divide);
            }
            divide += 2;
            if (divide > n) {
                break;
            }
            if (n % divide == 0 && isMSPrime(divide)) {
                output.push_back(divide);
            }
        }
        cout << n << ":";
        for (vector<int>::iterator it = output.begin(); it != output.end(); it++) {
            cout << " " << *it;
        }
        cout << endl;
    }
}

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

int main() {
    string S;
    cin >> S;
    if (S == "RRR") {
        cout << 3 << endl;
    } else if (S[1] == 'R' && (S[0] == 'R' || S[2] == 'R')) {
        cout << 2 << endl;
    } else if (S == "SSS") {
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    double t,a;
    cin>>t>>a;
    double h[n];
    int m;
    double k=1000000;
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
        double val = t-(h[i]*0.006);
        if(abs(val-a)<k)
        {
            k=abs(val-a);
            m=i+1;
        }
    }
    cout<<m<<endl;
    return 0;
}


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

const ll Mod = 1e9+7; 
const int MAX = 1e5+5;
ll sec[MAX], tri[MAX];
int cnt[MAX];
int Li[MAX];
string L;
int n;

void init() {
  rep(i, n) Li[i] = L[i] - '0';
  sec[0] = tri[0] = 1;
  rep(i, n+1) sec[i+1] = sec[i]*2 % Mod;
  rep(i, n+1) tri[i+1] = tri[i]*3 % Mod;
  cnt[0] = Li[0];
  for (int i = 1; i < n; ++i) cnt[i] = cnt[i-1] + Li[i];
}

void solve() {
  init();
  ll ans = (tri[n-1] + sec[cnt[n-1]]) % Mod;
  for (int i = 1; i < n; ++i) {
    if (Li[i]) {
      ans = (ans + sec[cnt[i-1]]*tri[n-(i+1)]) % Mod;
    }
  }
  cout << ans << endl;
}


int main() {
  cin >> L;
  n = L.length();
  solve();
  return 0;
}

Measured memory_bytes: 2816
#include<iostream>

using namespace std;

int main()
{
	int N;
	cin >> N;
	char S[N], T[N];
	cin >> S >> T;

	for(int i = 0; i < N; i++)
	{
		cout << S[i] << T[i];		
	}
	cout << "\n";


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   long N = sc.nextLong();
   long A = sc.nextLong();
   long B = sc.nextLong();
   
   long tmp = N/(A+B);
   long ans = tmp * A;  
   long s = N%(A+B);
   
   if(s<=A) ans += s;
   else ans += A;
   System.out.print(ans);
 }
}

Measured memory_bytes: 23892
#include<cstdio>

int main(){
	int h,w;
	scanf("%d %d", &h, &w);
	while(h && h){
		for(int i = 0; i < h ; i++){
			for(int j = 0; j < w; j++){
				if((i + j) % 2)
				{
					printf(".");
				}else{
					printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
		scanf("%d %d", &h, &w);
	}
}

Measured memory_bytes: 1000
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?(テァツクツョテ・ツーツ湘ァツ可?

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

// テ、ツコツ古ゥツδィテ」ツδ榲」ツδε」ツδ?」ツδウテ」ツつー (テヲツ慊?・ツ、ツァテヲツオツ?」ツつ津、ツスツソテ」ツ?」テ」ツ?ヲティツァツ」テ」ツ??
// テ」ツδサテヲツ卍ョテゥツ?堙」ツ?ォティツセツコテ」ツつ津・ツシツオテ」ツつ凝、ツサツ姪」ツ?ォテ」ツ??ィツ?ェテ・ツ按?」ツ?ァテ・ツ按・テ」ツ?ォテゥツ?づァツつケテ」ツつ?2 テ」ツ?、テァツ板ィテヲツ?湘」ツ?凖」ツつ?

template <typename T>
struct Edge {
    int to; T cap, cost; int rev;
    Edge(int t, T c, int r) : to(t), cap(c), rev(r) {}
    Edge(int t, T ca, T co, int r) : to(t), cap(ca), cost(co), rev(r) {}
};

template <typename T>
using Graph = vector< vector< Edge<T> > >;

struct BipartiteMatching {
    int S, T, E, a, b;
    vector< vector< Edge<int> > > G;
    vector<int> used;
    BipartiteMatching(int x, int y, int z) : S(x), T(y), E(z) {
        G.resize(S+T+2);
        used.resize(S+T+2);
        a = S + T, b = a + 1;
    }
    void add_edge(int from, int to, int cap) {
        G[from].push_back(Edge<int>(to  , cap, G[to  ].size()    ));
        G[to  ].push_back(Edge<int>(from, 0  , G[from].size() - 1));
    }
    void readGraph() {
        for(int i=0; i<S; i++) add_edge(a  , i, 1);
        for(int i=0; i<T; i++) add_edge(i+S, b, 1);
    }
    int dfs(int v, int t, int f) {
        if(v == t) return f;
        used[v] = true;
        for(size_t i=0; i<G[v].size(); i++) {
            Edge<int> &e = G[v][i];
            if(!used[e.to] && e.cap > 0) {
                int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int solve() {
        int flow = 0;
        while(1) {
            fill(used.begin(), used.end(), 0);
            int f = dfs(a, b, INF);
            if(f == 0) return flow;
            flow += f;
        }
    }
};

int N, M;

signed main() {
    cin >> N >> M;
    BipartiteMatching fl(N, M, 0);
    rep(i,0,N) {
        int p; cin >> p;
        rep(j,0,p) {
            int d; cin >> d; d--;
            fl.add_edge(i, N+d, 1);
        }
    }
    fl.readGraph();
    cout << (fl.solve() == M ? "Bob" : "Alice") << endl;
    return 0;
}

Measured memory_bytes: 19132
import sys
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

N, M, K = map(int, input().split())
friends = {i: set() for i in range(N)}
blocks = {i: set() for i in range(N)}

for _ in range(M):
    a, b = map(int, input().split())
    friends[a-1].add(b-1)
    friends[b-1].add(a-1)

for _ in range(K):
    a, b = map(int, input().split())
    blocks[a-1].add(b-1)
    blocks[b-1].add(a-1)

counts = [0] * N
seen = [False] * N
def dfs(v):
    if seen[v] == True:
        return
    seen[v] = True
    for node in friends[v]:
        c.add(node)
        dfs(node)
 
for v in range(N):
    if seen[v] == True:
        continue
    c = set()
    dfs(v)
    l = len(c)
    for i in c:
        counts[i] = l - 1
        counts[i] -= len(c & friends[i])
        counts[i] -= len(c & blocks[i])
print(' '.join(map(str, counts)))

Measured memory_bytes: 106984
from sys import stdin
[N, K] = [int(x) for x in stdin.readline().rstrip().split()]

sunuke = [0 for _ in range(N)]
for i in range(K):
    d = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    for j in range(d):
        sunuke[As[j]-1] += 1

tot = 0    
for i in range(N):
    if sunuke[i] ==0:
        tot+=1

print(tot)

Measured memory_bytes: 67688
import copy
H,W,K = list(map(int,input().rstrip().split(' ')))
MASU = [list(input()) for _ in range(H)]
H2_li = []
W2_li = []
C_black = 0
for i in range(2**H):
    H2 = []
    for j in range(H):
        if ((i>>j)&1):H2.append(1)
        else:H2.append(0)
    H2_li.append(H2)
for i in range(2**W):
    W2 = []
    for j in range(W):
        if ((i>>j)&1):W2.append(1)
        else:W2.append(0)
    W2_li.append(W2)

for h2 in H2_li:
    for w2 in W2_li:
        masu = copy.deepcopy(MASU)
        for i,h in enumerate(h2):
            if h == 1:
                masu[i] = ['r']*W
        for i,w in enumerate(w2):
            if w == 1:
                for k in range(H):
                    masu[k][i] = 'r'
        count = 0
        for h in range(H):
            for w in range(W):
                if masu[h][w]=='#':count+=1
        if count == K:C_black+=1

print(C_black)

Measured memory_bytes: 9252
#include<bits/stdc++.h>
using namespace std;
int n,k;
int h[100005];
int dp[100005];
int main(){
	memset(dp,63,sizeof(dp));
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&h[i]);
	dp[1]=0;
	for(int i=2;i<=n;i++){
		for(int j=i-1;j>0&&j>=i-k;j--)dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 1e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//


signed main()
{
  ios();
  int N;
  int a[5];
  cin >>N;
  rep(i,5) cin >> a[i];
  sort(a,a+5);
  int ans = (N-1)/a[0]+5;
  
  cout << ans << endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;


bool[100000] prime;


void initPrime() {
    prime[0] = false;
    prime[1] = false;
    for (int i = 3; i < 100000; i++) {
        for (int j = 2; j * j <= i; j++) {
            if (i % j == 0) {
                prime[i] = false;
            }
        }
    }
}


void main() {
    prime[] = true;
    initPrime();
    int N = readln.chomp.to!(int);
    int[] ans;

    for (int i = 3; i <= 55555 && ans.length < N; i++) {
        if (prime[i] && i % 5 == 1) ans ~= i;
    }
    for (int i = 0; i < N; i++) {
        if (i != 0) write(" ");
        write(ans[i]);
    }
    writeln();
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	string S; cin >> S; int N = S.size(); 
	vector<int> B, C, E; 
	B.push_back(0); 
	for(int i = 0; i < N-1; i++){
		if(S.at(i) == 'R' && S.at(i+1) == 'L') C.push_back(i); 
		if(S.at(i) == 'L' && S.at(i+1) == 'R'){
			E.push_back(i); B.push_back(i+1); 
		}
	}
	E.push_back(N-1); 
	int A[100010] = {}; 
	for(int i = 0; i < B.size(); i++){
		int l = C.at(i) - B.at(i) + 1; 
		int r = E.at(i) - C.at(i); 
		A[C.at(i)] += (l+1) / 2; 
		A[C.at(i)+1] += l - (l+1) / 2; 
		A[C.at(i)+1] += (r+1) / 2;  
		A[C.at(i)] += r - (r+1) / 2; 
	}
	for(int i = 0; i < N; i++){
		cout << A[i] << " "; 
	}
	cout << endl; 
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto &ai: a) cin >> ai;
    int sum = accumulate(begin(a), end(a), 0);
    cout << sum - n << endl;
    return 0;
}


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

using namespace std;

string s;
int k;

int main() {   
/*#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif*/
  ios_base::sync_with_stdio(0);
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'a') continue;
    if ((26 - (s[i] - 'a')) <= k) {
      k -= (26 - (s[i] - 'a'));
      s[i] = 'a'; 
    }
  }                 
  s[s.size() - 1] = ('a' + ((s[s.size() - 1] - 'a') + k) % 26);
  cout << s << "\n";
  return 0;
} 


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<vector<int>> A(N, vector<int>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (A[i][j] > A[i][k] + A[k][j]) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      bool ok = false;
      for (int k = 0; k < N; k++) {
        if (k == i or k == j) continue;
        if (A[i][j] == A[i][k] + A[k][j]) {
          ok = true;
          break;
        }
      }
      if (!ok) {
        ans += A[i][j];
      }
    }
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 640
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//int.Parseは文字列を整数に変換。
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long[] memos = new long[n];
    long min = 0;
    long max = 0;

    for(long i = 0; i < n; i++)
    {
      memos[i] = nums[i];
    }

    Array.Sort(memos);
    min = memos[n/2 - 1];
    max = memos[n/2];
    
    for(long i = 0; i < n; i++)
    {
		Console.WriteLine((nums[i] <= min) ? max : min);
    }
	}
}

Measured memory_bytes: 36680
from collections import deque
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
field = ["#"*(W+2) for _ in range(H+2)] #indexed from 1
for i in range(1, H+1):
    field[i] = "#" + input() + "#"
    
idxs = []
dxdy = [(1,0), (-1,0), (0,1), (0,-1)]
for row in range(1, H+1):
    for col in range(1, W+1):
        if field[row][col] == ".":
            idxs.append((row, col))
graph = {idx: deque() for idx in idxs}
for idx in idxs:
    x = idx[0]
    y = idx[1]
    for dx, dy in dxdy:
        if field[x+dx][y+dy] == ".":
            graph[idx].append((x+dx, y+dy))

dist = [[-1] * (W+1) for _ in range(H+1)] #indexed from 1
seen = [[0] * (W+1) for _ in range(H+1)] #indexed from 1
queue = deque()
def bfs(u,v):
    seen[u][v] = 1
    dist[u][v] = 0
    queue.append((u,v))
    while queue:
        p, q = queue[0]
        if not graph[(p,q)]:
            queue.popleft()
            continue
        g,h = graph[(p,q)].popleft()
        if seen[g][h]:
            continue
        seen[g][h] = 1
        dist[g][h] = dist[p][q] + 1
        queue.append((g,h))

bfs(1, 1)
total_pattern = 0
goal = dist[H][W]
if goal == -1:
    print(-1)
else:
    empty_count = 0
    for row in range(1, H+1):
        empty_count += field[row].count(".")
    total_pattern = empty_count - goal - 1
    print(total_pattern)

Measured memory_bytes: 5740
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int main(){
    string s;
    cin >> s;
    ll ans = 0;
    for(int i=1;i<s.size();i++){
        if(s.at(i-1)!=s.at(i))ans++;
    }
    cout << ans << endl;

}



Measured memory_bytes: 512
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
 //    String[] nyu=sc.nextLine().split(" ");

     String nyu=sc.nextLine();
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);
//int D=Integer.parseInt(nyu);



//StringBuffer sb = new StringBuffer(nyu);
//		String dst = sb.reverse().toString();

//     String nyu2=sc.nextLine();
//int E=Integer.parseInt(nyu2);



//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);

switch(nyu){
case "H H":
System.out.println("H") ;
break;

case "D D":
System.out.println("H") ;
break;

case "H D":
System.out.println("D") ;
break;

case "D H":
System.out.println("D") ;
break;


default:
System.out.println("NO") ;

break;
}


//int res=Math.min((A*B),C);

//for(String tem:nyu){
//if(tem.equals("1"))res++;
//}
//int res=0;
//for(int i=0;i<300;i++){
//if(num[i]==1)res=i;
//}

//char[] c = nyu.toCharArray();


//System.out.println(nyu+"-"+line_r_2+"-"+nyu2+"-"+line_r_1);



//if(B-A==C-B){
//double res=Math.ceil((AB)/2);

//System.out.println("YES");
//}else if((C-B)<A){
//System.out.println("safe");

//}else{
//System.out.println((A+B)%24);

//}




	}
}

Measured memory_bytes: 21844
import heapq
import collections


def main():
    INF = 10 ** 15
    # Load data
    N, M, S = list(map(int, input().split()))
    SUM_A = 0
    A = [[INF for _ in range(N)] for _ in range(N)]  # fare
    B = [[INF for _ in range(N)] for _ in range(N)]  # time
    C = [0 for _ in range(N)]  # silver coins per 1 gold coin
    D = [0 for _ in range(N)]  # time per 1 gold coin
    ADJ = collections.defaultdict(list)
    for _ in range(M):
        u, v, a, b = list(map(int, input().split()))
        u -= 1
        v -= 1
        A[u][v] = a
        A[v][u] = a
        B[u][v] = b
        B[v][u] = b
        ADJ[u].append(v)
        ADJ[v].append(u)
        SUM_A += a
    S = min(SUM_A, S)  # SUM_A だけ銀貨があればどこへでも無条件で移動可能
    for n in range(N):
        c, d = list(map(int, input().split()))
        C[n] = c
        D[n] = d
    # 「都市 i で銀貨 s 枚所持」を1ノードと考え、
    # 初期状態 (0, S) からの最短距離（時間）をDijkstraで求める
    arr_dist = [[INF for _ in range(SUM_A + 1)] for _ in range(N)]
    arr_dist[0][S] = 0
    que = [(0, 0, S)]  # (距離, 都市, 銀貨)
    while len(que) > 0:
        dist, city, silver = heapq.heappop(que)
        # same city (next_city == city)
        next_silver, next_dist = silver + C[city], dist + D[city]
        if next_silver <= SUM_A and arr_dist[city][next_silver] > next_dist:
            arr_dist[city][next_silver] = next_dist
            heapq.heappush(que, (next_dist, city, next_silver))
        # other city
        for next_city in ADJ[city]:
            next_silver, next_dist = silver - A[city][next_city], dist + B[city][next_city]
            if 0 <= next_silver <= SUM_A and arr_dist[next_city][next_silver] > next_dist:
                arr_dist[next_city][next_silver] = next_dist
                heapq.heappush(que, (next_dist, next_city, next_silver))
    # 最後に都市 i に関連するノードを全部チェックし、最短距離（時間）を出す
    min_dist = [0 for _ in range(N)]
    for city in range(1, N):
        min_dist[city] = min(arr_dist[city])
    for ans in min_dist[1:]:
        print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 97204
#include<iostream>
#include<vector>
#include<string>
using namespace std;

char table[53]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
inline int access(int num,int div){ return (num+div)%div;}

int main(){
  int n;
  while(cin>>n,n){
    vector<int> key(n);
    for(int i=0;i<n;i++)
      cin>>key[i];
    string str;
    cin>>str;
    int data=0;
    for(int i=0;i<(int)str.size();i++){
      if('a'<= str[i] && str[i] <= 'z') data=int(str[i]-'a');
      else if('A' <= str[i] && str[i] <= 'Z') data=int(str[i]-'A'+26);
      str[i]=table[access(data-key[access(i,n)],52)];
    }
    cout<<str<<endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define O 0
#define I 1
#define T 3

int c=0;

void insertSort(int *,int,int);

int main(){
  int i,j,n,m=O,G[20];
  int *A;

  scanf("%d",&n);
  A = malloc(n*sizeof(int));
  for(i=O;i<n;i++){
    scanf("%d",&A[i]);
  }
  G[O]=O;
  while(I){
    if(n<T*G[m]+I){
      break;
    }
    G[m+I]=T*G[m]+I;
    m++;
 }
  for(i=m;i>O;i--){
    insertSort(A,n,G[i]);
  }
  printf("%d\n",m);
  for(i=m;i>=I;i--){
    printf("%d ",G[i]);
  }
  printf("\n");
  printf("%d\n",c);
  for(i=O;i<n;i++){
    printf("%d\n",A[i]);
  }
  return O;
}

void insertSort(int *A,int n,int g){
  int i,j,key;
  for(i=g;i<n;i++){
    j=i;
    key=A[i];
    while(O<=j-g){
      if(A[j-g]<=key){
	break;
      }
      A[j]=A[j-g];
      j-=g;
      c++;
    }
   A[j]=key;
 }
}




Measured memory_bytes: 5644
import math as m
from array import *
import sys
import datetime
import calendar


a= int(input())
b=int(input())

if a==1 and b==2:
    print(3)
if a==2 and b==3:
    print(1)
if a==2 and b==1:
    print(3)
if a==3 and b==2:
    print(1)
if a==1 and b==3:
    print(2)
if a==3 and b==1:
    print(2)


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

vector<int> g[N];
int n;
set<int> A,B,C;

void input(){
  int a,b,c;
 
  cin>>n>>a>>b>>c;
  for(int i=0,t;i<a;i++) cin>>t,A.insert(t-1);
  for(int i=0,t;i<b;i++) cin>>t,B.insert(t-1);
  for(int i=0,t;i<c;i++) cin>>t,C.insert(t-1);

  int par[N];
  for(int i=0;i<N;i++) par[i] = i;
  for(int v:A) par[v] = *A.begin();
  for(int v:B) par[v] = *B.begin();
  for(int v:C) par[v] = *C.begin();
  
  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    int u,v;
    cin>>u>>v; u--,v--;
    u = par[u], v = par[v];
    if(u == v) continue;
    g[u].push_back(v);
    g[v].push_back(u);
  }
}

typedef pair<int,int> P;
typedef pair<P,int> PP;
vector<P> dijkstra(int start){
  vector<P> D(N,P(INF,INF));
  priority_queue<PP,vector<PP>,greater<PP>> Q;

  Q.push(PP(P(0,start),start));
  D[start] = P(0,start);
  while(!Q.empty()){
    PP t = Q.top();Q.pop();
    P cost = t.first;
    int pos = t.second;
    if(D[pos] < cost)continue;

    for(int npos:g[pos]){
      P ncost = P(cost.first+1,min(cost.second,npos));
      if(D[npos] <= ncost) continue;
      Q.push(PP(ncost,npos));
      D[npos] = ncost;
    }
  }
  return D;
}

P calc(P a,P b,P c){
  int cost = a.first + b.first + c.first;
  int node = min(a.second,min(b.second,c.second));
  return P(cost,node);
}

signed main(){
  input();
  int a = *A.begin();
  int b = *B.begin();
  int c = *C.begin();
  vector<P> AD = dijkstra(a);
  vector<P> BD = dijkstra(b);
  vector<P> CD = dijkstra(c);
  
  P ans = P(INF,INF);
  for(int i=0;i<n;i++) Min(ans,calc(AD[i],BD[i],CD[i]));
  cout<<ans.first<<" "<<ans.second+1<<endl;
  return 0;
}

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

int main() {
	int x, y;
	cin >> x >> y;
	while (x > 0 || y > 0) {
		if (x <= y)
			cout << x << " " << y << endl;
		else
			cout << y << " " << x << endl;
		cin >> x >> y;
	}
	
	return 0;
}


Measured memory_bytes: 3068
#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() {
    string s,t;
    cin >> s>>t;
    int ans=0;
    REP(i,s.length()){
        if(s[i]==t[i]) continue;
        ans++;
    }
    cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3916
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

for i in range(1, N + 1):
    A[i] += A[i-1]
for i in range(1, M + 1):
    B[i] += B[i-1]

ans = 0
b_cnt = M
for a_cnt in range(N + 1):
    if A[a_cnt] > K:
        continue
    while A[a_cnt] + B[b_cnt] > K:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)

print(ans)

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

using namespace std;

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

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

#endif

void Main() {
    ll A, B; cin >> A >> B;
    cout << max(max(A + B, A - B), A * B) << endl;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
long long a[86];
using namespace std;
int main()
{
	int n;
	a[0]=2;
	a[1]=1;
	for(int i=2;i<=86;i++)
	{
		a[i]=a[i-1]+a[i-2];
	}
	cin>>n;
	cout<<a[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()

if n == 0:
    print(0)
    exit()

ans = deque()
i = 0
while n != 0:
    tmp = ( n % 2**(i+1) ) // 2**i
    ans.appendleft(tmp)
    n -= tmp * (-2)**i
    i += 1
print(*list(ans),sep="")

Measured memory_bytes: 10200
#include <stdio.h>
int main(){
	int a,b;
	int n;
	while(scanf("%d %d",&a,&b) != EOF){
		a = a + b;
		for(n = 0;;n++){
			a /= 10;
			if(a <= 0)break;
		}
		printf("%d\n",n+1);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h> 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vv = vector<vector<int>>;
using P = pair<int,int>;

int main(){
  vector<int> num(3);
  rep(i,3) cin >> num.at(i);
  sort(num.begin(),num.end());
  int ans=0;
  while( num.at(1) != num.at(2) ){
    num.at(0)++;
    num.at(1)++;
    ans++;
  }
  while( num.at(0) < num.at(1) ){
    num.at(0) += 2;
    ans++;
  }
  if( num.at(0) != num.at(1) ){
    num.at(1)++;
    num.at(2)++;
    ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 1000001

int linearSearch(int A[], int n, int key)
{
  int i;

  i = 0;
  A[n] = key;
  if(A[0] == key){
    return 1;
  }
  while(A[i] != key){
    i++;
  }
  if(i == n){
    return 0;    
  }
  return i;
}

int main(){

  int i, n, q, key, count=0;
  int A[N];
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }

  scanf("%d", &q);

  for(i=0; i<q; i++){
    scanf("%d", &key);
    if(linearSearch(A, n, key)){
	count++;
      }
  }

    printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 2852
<?php
$str1 = trim(fgets(STDIN));
$str2 = trim(fgets(STDIN));
$array = explode(" ", $str2);
$d2 = $array[1];


class SubmitAnswer {
    public static function println($answer = "") {
        echo $answer . PHP_EOL;
    }
}


if($d2 < 2){
  $answer = 1;
} else {
  $answer = 0;
}
 
SubmitAnswer::println("$answer");


Measured memory_bytes: 3576