akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define debug(n) cerr << #n << ':' << n << endl;
using namespace std;

using ll = long long;

int main(){
  string s; cin >> s;
  ll n = s.size();
  ll k; cin >> k;
  char f = s[0], e = s[n-1];
  char bef = 'A';
  ll cnt=0,now=0;
  bool one = true;
  for(int i = 0; i < n; ++i){
    if(f != s[i])one = false;
    if(bef == s[i]){
      now++;
    } else {
      bef = s[i];
      cnt+=now/2;
      now=1;
    }
  }
  if(one){cout << n*k/2 << endl; return 0;}
  cnt+=now/2;
  // debug(cnt);
  if(f != e){
    cout << cnt*k << endl;
  } else {
    int cf = 0;
    int idx=0;
    while(idx<n&&s[idx++]==f)cf++;
    int ce = 0;
    idx = n-1;
    while(idx>=0&&s[idx--]==e)ce++;
    ll cnt2 = cnt-cf/2-ce/2;
    ll ans = cnt2*k+((ce+cf)/2)*(k-1) + ce/2 + cf/2;
    // debug(cnt2);
    // debug(cf);
    // debug(ce);
    cout << ans << endl;
  }
  return 0;
  
}


Measured memory_bytes: 384
N, M = map(int, input().split())
A, B = [0]*M, [0]*M

to = {i: [] for i in range(N)}

for i in range(M):
    a, b = map(lambda x:int(x)-1, input().split())
    to[a].append(b)
    to[b].append(a)

q = []
dist = [-1]*N
dist[0] = 0
pre = [-1]*N
q.append(0)
while len(q)>0:
    v = q.pop(0)
    for u in to[v]:
        if dist[u]==-1:
            dist[u] = dist[v]+1
            pre[u] = v
            q.append(u)
print("Yes")
print(*map(lambda x:x+1, pre[1:]), sep="\n")


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

int main(){
  long int A,B,C,Q,x,y;
  cin >> Q;
  for(int i=0;i<Q;i++){
  cin >> A >> B;
  x=min(A,B);y=max(A,B);
  if(x==y || x+1==y) cout << 2*x-2<<endl;
  else{
    if(ceil(sqrt(A*B))==floor(sqrt(A*B)))C=sqrt(A*B)-1;
    else C=sqrt(A*B);
    if(C*(C+1)>=A*B)cout << 2*C-2 << endl;
    else cout << 2*C-1 << endl;
  }
    
  }  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

void prime_factorize(long long N, map<ll, ll> &ma) {
    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
        ma[a] = max(ma[a], ex);
    }

    // 最後に残った数について
    if (N != 1)
        ma[N] = max(ma[N], (ll)1);

    return;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    ll MOD = pow(10, 9) + 7;
    rep(i, N) { cin >> A[i]; }

    map<ll, ll> ma;
    rep(i, N) { prime_factorize(A[i], ma); }

    ll lcm = 1;
    for (auto m : ma) {
        lcm *= modpow(m.first, m.second, MOD);
        lcm %= MOD;
    }

    ll ans = 0;
    rep(i, N) {
        ans += lcm * modpow(A[i], MOD - 2, MOD) % MOD;
        ans %= MOD;
    }

    if (ans < 0) {
        while (ans < 0) {
            ans += MOD;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4084
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)

//変数
int N;
vector<int> a;

//解法
void solve() {

	vector<ll> front_sum(N + 1), back_sum(N + 1);

	priority_queue<int> back;
	priority_queue<int, vector<int>, greater<int>> front;

	ll sum = 0;

	rep(i, N) {
		front.push(a[i]);
		sum += a[i];
	}
	front_sum[0] = sum;
	for (int i = 1; i < N + 1; i++) {
		front.push(a[N - 1 + i]);
		sum = sum + a[N - 1 + i] - front.top();
		front.pop();
		front_sum[i] = sum;
	}

	sum = 0;
	rep(i, N) {
		back.push(a[3 * N - 1 - i]);
		sum += a[3 * N - 1 - i];
	}
	back_sum[N] = sum;
	for (int i = N - 1; i >= 0; i--) {
		back.push(a[N + i]);
		sum = sum + a[N + i] - back.top();
		back.pop();
		back_sum[i] = sum;
	}

	ll ans = LLONG_MIN;
	rep(i, N + 1) {
		if (front_sum[i] - back_sum[i] > ans) ans = front_sum[i] - back_sum[i];
	}

	cout << ans;
	return;
}

int main() {
	//入力
	cin >> N;
	a.resize(3 * N);
	rep(i, 3 * N) cin >> a[i];
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 4088
#include <algorithm>
#include <array>
#include <bitset>
#include <cstdint>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <memory>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#include <vector>

// constexpr std::int64_t INF = 1ull << 50;
constexpr int INF = 1 << 20;

auto main() -> int {
  int N, M;
  std::cin >> N >> M;

  int s = -1, t = INF;
  for (auto i = 0; i < M; ++i) {
    int Li, Ri;
    std::cin >> Li >> Ri;
    s = std::max(Li, s);
    t = std::min(Ri, t);
  }

  if (t - s < 0) {
    std::cout << 0 << std::endl;
  } else {
    std::cout << (t - s + 1) << std::endl;
  }
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.stream.Collectors;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class DGridColoring {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int h = in.ints(), w = in.ints();
            int n = in.ints();
            int[] a = in.ints(n);
            int[][] c = new int[h][w];
            int offset = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < a[i]; j++) {
                    int index = offset + j;
                    //System.out.println(index);
                    int y = index / w;
                    if (y % 2 == 0) {
                        c[y][index % w] = i + 1;
                    } else {
                        c[y][w - (index % w) - 1] = i + 1;
                    }
                }
                offset += a[i];
            }
            Arrays.stream(c)
                    .map(x -> IntStream.of(x).mapToObj(Integer::toString).collect(Collectors.joining(" ")))
                    .forEach(out::println);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

        public int[] ints(int length) {
            return IntStream.range(0, length).map(x -> ints()).toArray();
        }

    }
}



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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int n=s.size();
	int ans=100000,cnt=0;
	rep(i,n){
		int cur=0;
		rep(j,n){
			if(s.at(i)==s.at(j)){
				cur=max(cur,cnt);
				cnt=0;
			}
			else cnt++;
		}
		cur=max(cur,cnt);
		cnt=0;
		ans=min(ans,cur);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  char b = 'A',c1,c2;


  while(scanf("%c,%c",&c1,&c2)!=EOF){
    if(c1==b)
      b = c2;
    else if(c2==b)
      b = c1;
   }
  printf("%c\n",b);
  return 0;
}

Measured memory_bytes: 540
while True:
    try:
        L = [map(int,raw_input().split()) for _ in xrange(input())]
        L += [map(int,raw_input().split()) for _ in xrange(input())]
    except EOFError:
        break
    L.sort(key = lambda (h,r):r*r*h)
    DP = [1]*len(L)
    for i,(h,r) in enumerate(L):
        for j,(H,R) in enumerate(L):
            if j > i and (H>h and R>r):
                DP[j] = max(DP[j],DP[i]+1)
    print max(DP)

Measured memory_bytes: 4252
N = int(input())
P = list(map(int, input().split()))

i = 0
count = 0
while i < N:
    if P[i] == i + 1:
        # P[i], P[i + 1] = P[i + 1], P[i]
        i += 2
        count += 1
    else:
        i += 1

print(count)


Measured memory_bytes: 14008
#include <stdio.h>

int main(int argc, char *args[])
{
	int n,m;

	int a[101][101];
	int b[101];
	int c;
	int l1,l2;
	int l3,l4;

	for( l1=0; l1<101; l1++ ) {
		for( l2=0; l2<101; l2++ ) {
			a[l1][l2] = 0;
		}
		b[l1] = 0;
	}

	scanf("%d %d", &n, &m);

	for( l3=1; l3<=n; l3++ ) {
		for( l4=1; l4<=m; l4++ ) {
			scanf("%d", &a[l3][l4] );
		}
	}

	for( l4=1; l4<=m; l4++ ) {
		scanf("%d", &b[l4] );
	}

	for( l3=1; l3<=n; l3++ ) {
		c = 0;
		for( l4=1; l4<=m; l4++ ) {
			c += a[l3][l4] * b[l4];
		}

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

	}

	return 0;

}

Measured memory_bytes: 640
n=gets.to_i
a=gets.split.map(&:to_i).sort
if n%3==0
  m=n/3
  x,y,z=a[0],a[m],a[2*m]
  if a[m-1]==x && a[2*m-1]==y && a[3*m-1]==z && x ^ y == z
    puts "Yes"
  else
    puts "No"
  end
else
  if a[0]==a[-1] && a[0]==0
puts "Yes"
  else
    puts "No"
  end
end

Measured memory_bytes: 9972
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> array = new ArrayList<>();
		for(int counter = 0; counter < 4; counter++)
			array.add(sc.nextInt());
		List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(4);
        list.add(7);
        list.add(9);
		System.out.println(array.containsAll(list) ? "YES" : "NO");
			
	}
}


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

int main(){
	int n,h=0,ans,a,b;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		if(a>h){
			h=a;
			ans=a+b;
		}
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 256
H,W=map(int,input().split())

matrix=[]
for i in range(H):
    matrix.append(list(input()))
for h in range(1,H-1):
    for w in range(1,W-1):
        if(matrix[h][w]=="#"):
           if(matrix[h-1][w]=="." and matrix[h][w-1]=="."
              and matrix[h+1][w]=="." and matrix[h][w+1]=="."):
               print("No")
               exit()
print("Yes")

Measured memory_bytes: 3064
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
int a[N],b[N],p[N],n;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&p[i]),a[p[i]]+=i,b[p[i]]+=i;
	fp(i,1,n)a[i]+=a[i-1];fd(i,n,1)b[i]+=b[i+1];
	fp(i,1,n)printf("%d%c",a[i]+i," \n"[i==n]);
	fp(i,1,n)printf("%d%c",b[i]+n-i+1," \n"[i==n]);
	return 0;
} 

Measured memory_bytes: 896
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;

const long MAX = 9999999;
const long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long COM(long n, long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    long X,Y;
    cin>>X>>Y;
    if((X+Y)%3!=0){
        cout<<0<<endl;
        return 0;
    }
    long N = (X+Y)/3;
    long n = X-N;
    COMinit();
    cout<<COM(N,n)<<endl;

}

Measured memory_bytes: 234624
#include<stdio.h>

int main(void){
    
    int a,b,c;
    int temp;
    
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    
    if(a > b){
        temp = a;
        a = b;
        b = temp;
    }
    
    if(b > c){
        temp = b;
        b = c;
        c = temp;
    }
    
    if(a > b){
        temp = a;
        a = b;
        b = temp;
    }
    
    printf("%d %d %d\n", a, b, c);
    
    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define endl "\n"
#define nl cout<<endl
#define pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define txti freopen("input.txt", "r", stdin);
#define txto freopen("output.txt", "w", stdout);
//#define mod 100000007

#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 

bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.second > b.second )
        return true;
    if( a.second==b.second && a.first > b.second )
       return true;
 
    return false;
 }
//me
ll const mod = 1e9+7;//998244353;
ll const inf = 1e3+1;

void solve()
{   
    ll n; cin >> n;
    ll a[n]; 
    f(i,0,n) cin >> a[i];

    ll suf[n+1]={0}; suf[n-1]=a[n-1];

    for(ll i = n-2; i>=0; i--)
        suf[i] = (a[i] + suf[i+1])%mod;
    ll ans = 0;
    f(i,0,n){

        ans = (ans + (a[i] * suf[i+1])%mod  )%mod;
        //cout << suf[2] << endl;
    }
    cout << ans << endl;
} 

int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
        
        ll t;
        /**/t=1;
        /*/cin>>t;/**/
        f(testcases,0,t){
            solve();
        }
 
 
    return 0;
}


Measured memory_bytes: 6780
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}


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

    rep(i,1000000000){
        if(abs(A-i) == abs(B-i)){
            cout << i << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;


}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main() 
{
    long a, b, c, d, tmp;
    while (std::cin >> a >> b) {
    	d = a * b;
		if(a < b) {
            tmp = a;
            a = b;
            b = tmp;
        }
 
    c = a % b;
    while(c != 0) {
        a = b;
        b = c;
        c = a % b;
    }
    cout << b << " " << d / b << endl;
    }
       return 0;
}


Measured memory_bytes: 3012
#include<iostream>

using namespace std;

int main(){
    int x;
    cin >> x;
    for (int a = -118; a < 120; a++)
    {
        for (int b = -119; b < 119; b++)
        {
            if (a * a * a * a * a - b * b * b * b * b == x)
            {
                cout << a << " " << b << endl;
                return 0;
            }
        }
        
    }
    return 0;
}

Measured memory_bytes: 3628
//Heaplax
#include<bits/stdc++.h>
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
bitset<2005> l[2005],r[2005],a[2005];//r[i]表示i作为右端点时那些左端点可行
int n;
char s[2005];
int main()
{
	re(n);
	for(int i=2;i<=n;++i)
	{
		scanf("%s",s+1);
		for(int j=1;j<i;++j)
		{
			if(s[j]=='1')a[i][j]=1;
			else a[j][i]=1;
		}
	}
	for(int i=1;i<=n;++i)l[i][i]=r[i][i]=1;
	for(int len=1;len<n;++len)
		for(int i=1;i<=n;++i)
		{
			if(i+len<=n && (r[i+len]&l[i+1]&a[i]).count())r[i+len][i]=1;
			if(i-len>=1 && (l[i-len]&r[i-1]&a[i]).count())l[i-len][i]=1;
		}
	printf("%d\n",(l[1]&r[n]).count());
}


Measured memory_bytes: 1792
# encoding: utf-8
N = gets.chomp.to_i
trans = []
5.times do
  x = gets.chomp.to_i
  trans << x
end
pass = [N,0,0,0,0,0]
# p N
# p trans
# # p pass
# i = 0
# while true do
# # for i in 1..N do
#   if pass[5] >= N then
#     break
#   end
#   (0..4).reverse_each do |j|
#     if pass[j] > 0 then
#       t = (pass[j] < trans[j]) ? pass[j] : trans[j]
#       pass[j+1], pass[j] = (pass[j+1] + t), (pass[j] - t)
#     end
#   end
#   # p i
#   # p pass
#   i = i + 1
# end
# puts i
m = trans.min
if (N % m) == 0 then
  t = N / m
else
  t = N / m + 1 
end
puts t + 4

Measured memory_bytes: 1788
#include <iostream>
#include <cstdlib>
#include <vector>

using namespace std;

struct UnionFind
{
    vector<int> data;
    UnionFind() {}

    // initialize
    UnionFind(int size) : data(size, -1) {}

    void unite_set(int x, int y){
        x = root(x);
        y = root(y);
        bool is_unite = (x != y);
        
        if (is_unite){
            if (data[y] < data[x]){
                swap(x, y);
            }
            data[x] += data[y];
            data[y] = x;
        }
    }

    bool is_same(int x, int y){
        return root(x) == root(y);
    }

    int root(int x){
        return (data[x] < 0) ? x : data[x] = root(data[x]);
    }

    int size(int x){
        return -data[root(x)];
    }
};

int main()
{
    int n, q;
    int c, a, b;
    cin >> n >> q;
    struct UnionFind d(n);
    vector<int> data;
    data.resize(n);
    
    for (int i=0; i<n; ++i){
        data[i] = i;
    }
    // query
    for (int i=0; i<q; ++i){
        cin >> c >> a >> b;
        // same
        if(c == 1){
            cout << d.is_same(a, b) << endl;
        }
        // unite
        else {
            d.unite_set(a, b);
        }
    }
}



Measured memory_bytes: 3148
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int K = in.nextInt();
            int S = in.nextInt();
            int count = 0;
            for (int X = 0; X <= K; X++) {
                for (int Y = 0; Y <= K; Y++) {
                    int Z = S - (X + Y);
                    if (!(Z >= 0 && Z <= K)) {
                        continue;
                    }
                    count++;
                }
            }
            System.out.println(count);
        }
    }
}


Measured memory_bytes: 23764
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <iostream>
#include <algorithm>
#include <list>
using namespace std;


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

	char s[50][50];

	for (int i=0; i<h; ++i){
		for(int j=0; j<w; ++j){
			cin >> s[i][j];
		}
	}

	for (int i=0; i<h; ++i){
		for(int j=0; j<w; ++j){
			if (s[i][j] == '#'){
				if ((s[i-1][j] == '#') || (s[i+1][j] == '#') || (s[i][j+1] == '#') || (s[i][j-1] == '#')){
					continue;
				}
				else{
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
//containing t test cases
#include<bits/stdc++.h>
#define pb push_back
#define mod 1000000007
#define mkp make_pair
#define fi first
#define se second
#define ll long long
#define scan(n) ll a[n]; for(ll i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(ll i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define pi 3.1415926535897932384626433832795028841971
#define mem(a,b) memset(a , b , sizeof a ) ;
//#define int long long
using namespace std;
//typedef vector<int>vi ;
typedef vector<ll>vi ;
typedef vector<vector<ll> >vvl ; 
typedef pair<ll,ll> pll ;
typedef vector<pair<ll,ll> > vpll;
//cout<<fixed<<setprecision(15);
/*vi adj[200005];
ll vis[200005];
ll parent[200005];
ll level[200005];
ll arr[200005];
ll size[200005];*/
//endl mut bhool!!
void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	map<ll,ll> mp;
	ll sum=0;
	rep(i,0,n){
		cin>>a[i];
		mp[a[i]]++;
		sum+=a[i];
	}
	ll q;
	cin>>q;
	for(ll i=0;i<q;i++)
	{
		ll x,y;
		cin>>x>>y;
		if(mp[x]==0)
		{
			cout<<sum<<endl;
			continue;
		
		}
		sum-=mp[x]*x;
		sum+=mp[x]*y;
		mp[y]+=mp[x];
		mp[x]=0;
		cout<<sum<<endl;
	}
	
}
int main()
{
	fast;
	ll test=1;
	//cin>>test;
	while(test--)
	{
		solve();
	}
	return 0;
}
/*
cout<<"YES"<<endl;
cout<<"NO"<<endl;
*/




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

using namespace std;

int main(void)
{
	int k, s;
	cin >> k >> s;
	int ans = 0;
	int t;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			t = s - i - j;
			if (t >= 0 && t <= k) {
				ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
using ll = long long;
using ii = pair<int,int>;
constexpr int MAXN = 5 + 200000;

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int h,w,n; cin >> h >> w >> n;
  if (h < w) swap(h,w);
  int ans = 0, tot = 0;
  while (tot < n) {
    tot += h;
    ans++;
  }
  cout << ans << '\n';
  return 0;
}


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



signed main(){
    int n;
    cin >>n;
    vector<int> a(n);
    cin >> a[0];
    int t;
    for(int i=1;i<n;i++){
        cin >> t;
    a[i]= t+a[i-1];
    }
    int p=0,q=2,ans=-1;
    for(int i=1;i<n-2;i++){
       while(abs(a[i]-2*a[p])>abs(a[i]-2*a[p+1]))p++;
       while(abs(a[n-1]+a[i]-2*a[q])>abs(a[n-1]+a[i]-2*a[q+1]))q++;
        if(ans<0||ans>max(max(a[p],a[i]-a[p]),max(a[q]-a[i],a[n-1]-a[q]))-min(min(a[p],a[i]-a[p]),min(a[q]-a[i],a[n-1]-a[q])))ans=max(max(a[p],a[i]-a[p]),max(a[q]-a[i],a[n-1]-a[q]))-min(min(a[p],a[i]-a[p]),min(a[q]-a[i],a[n-1]-a[q]));

        cerr << ans<< ' '<<p <<' '<<q<<endl;
        
    }

    
    cout << ans;
    return 0;
}

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

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

//--------------------------------------------

int main(){
  string S;
  int t = 0;
  int s = 0;

  cin >> S;

  REP (i, int(S.size())) {
    if (S.at(i) == 'S') s++;
    else {
      if (s > 0) s--;
      else t++;
    }
  }
  printf("%d\n",s + t);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 3e3 + 5;
const ll LINF = 1e18 + 5;
char s[N], t[N];
int dp[N][N];
pii pre[N][N];
void print(int x, int y)
{
	if(!x || !y) return;
	print(pre[x][y].first, pre[x][y].second);
	if(x!=pre[x][y].first && y!=pre[x][y].second) cout << s[x];
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> (s+1) >> (t+1);
 	int n = strlen(s+1), m = strlen(t+1);
 	for(int i=1; i<=n; i++)
 		for(int j=1; j<=m; j++)
 		{
 			if(s[i]!=t[j]) 
 			{
 				if(dp[i-1][j]>dp[i][j-1]) dp[i][j] = dp[i-1][j], pre[i][j] = mp(i-1, j);
 				else dp[i][j] = dp[i][j-1], pre[i][j] = mp(i, j-1);
 			}
 			else 
 			{
 				dp[i][j] = dp[i-1][j-1]+1;
 				pre[i][j] = mp(i-1, j-1);
 			}
 		}
 	int ans = 0, x = 0, y = 0;
 	for(int i=1; i<=n; i++)
 		for(int j=1; j<=m; j++)
 			if(dp[i][j]>ans) ans = dp[i][j], x = i, y = j;
 	//debug(ans);
 	print(x, y);
	return 0;
}


Measured memory_bytes: 106240
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<cstdlib>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int maxn=1e5+5;
const int mod=1e9+7;

inline ll quick(ll a,ll b,ll p)	//(a^b) mod p 
{
	ll ans=1;
	for( ;b;b>>=1)
	{
		if(b&1) ans=ans*a%p;
		a=a*a%p;
	}
	return ans%p;	//如果b=0,p=1,不加%p会错 
}

int main()
{
    ll n;
    cin>>n;
    ll t=(quick(10,n,mod)+quick(8,n,mod)-2*quick(9,n,mod)+2*mod)%mod;
    cout<<t<<endl;
	system("pause");
    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){
      lint n;
      cin>>n;
      lint a[n];
      lint money=1000;
      lint kabu=0;
      lint mn,mx;
      rep(i,n)cin>>a[i];
      rep(i,n-1){
        kabu=0;
         if(a[i]<a[i+1])kabu=money/a[i];
         money+=(a[i+1]-a[i])*kabu;
      }
      cout<<money<<endl;
    }
      
    
  

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

int bubsort(int, int, int);

int main(void)
{
	int num[3];
  cin >> num[0] >> num[1] >> num[2];

	int count = 0;
	int a, b, i, j;/*変数宣言*/
	for (j = 0; j < 2; j++) {
		for ( i = 0; i < 2 - j; i++) {/*隣同士の比較を繰り返す。順を追う毎に回数が1ずつ小さくなるので、その実装に'j'を使用*/
		if (num[i] < num[i+1]) {
			swap(num[i], num[i+1]);
		}
	}
}

//while (num[0] != num[1] || num[1] != num[2]) {
	if (num[1] - num[2] >= 2) {
		a = (num[1] - num[2]) / 2;
		num[2] = num[2] + (2*a);
		count = count + a;
	}
	if (num[1] - num[2] == 1) {
		num[0]++;
		num[2]++;
		count++;
	}
	if (num[1] - num[2] == 0) {
		b = num[0] - num[1];
		num[1] = num[1] + b;
		num[2] = num[2] + b;
		count = count + b;
	}
//}

cout << count << '\n';

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;

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

int main() {
    ll n, y;
    cin >> n >> y;
    ll a, b, c;
    a = -1;
    b = -1;
    c = -1;

    // 10000a+5000b+1000c=y
    // a+b+c=n
    // 9000a+4000b=y-1000n, a=[0..n], b=[0..n-a]
    ll t = y - 1000 * n;
    for (ll i = 0; i <= n; i++) {
        for (ll j = 0; j <= n - a; j++) {
            ll total = 9000 * i + 4000 * j;
            if (total == t) {
                c = n - i - j;
                if (c >= 0 && 10000 * i + 5000 * j + 1000 * c == y) {
                    a = i;
                    b = j;
                    break;
                }
            }
        }
    }
    if (a >= 0) {
        c = n - a - b;
    } else {
        a = b = c = -1LL;
    }
    printf("%lld %lld %lld\n", a, b, c);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
 
   int A, B;
   cin >> A >> B;
   if(B%A){
   	cout << B-A <<endl;
   }else{
   	cout << A+B <<endl;
   }
   

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
#define LINEY "YES\n"
#define Liney "Yes\n"
#define LINEN "NO\n"
#define Linen "No\n"

int main(){
  string s; cin >> s;
  int s_size = s.size();
  if(s_size==3){
    reverse(ALL(s));
  }
  cout << s << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000
struct node{
  int key;
  int cost;
  struct node *next;
};
 
typedef struct node *adj;
adj G[MAX];
adj SuperNode(int key,int cost,adj Node){
  adj n;
  n=(adj)malloc(sizeof(struct node));
  n->key=key;
  n->cost=cost;
  n->next=Node;
  return n;
}
 
adj Insert(int a,int b,int c){
  adj H;
  H=SuperNode(b,c,G[a]->next);
  G[a]->next=H;
}
 
int main(){
  int i,j,n,count=0,v,c,c1,v1;
  int color[MAX],D[MAX],pi[MAX],nx,min;
  adj H;
 
  scanf("%d",&n);
  for(i = 0;i < n;i++)G[i]=SuperNode(0,0,NULL);
  for(i = 0;i < n;i++){
    scanf("%d%d",&v,&c);
 
    for(j = 0;j <c;j++){
      scanf("%d %d",&v1,&c1);
    Insert(i,v1,c1);
  }
}
 
for(i=0;i<n;i++){
  color[i]=0;
  pi[i]=-1;
  D[i]=10000000;
 }
 D[0]=0;
 
while(1){
  min=10000000;
  for(i=0;i<n;i++){
    if(color[i] != 2 && D[i] < min){
      min=D[i];
      nx=i;
    }
  }
 
  if(min==10000000)break;
  color[nx]=2;
 
  for(H=G[nx];H!=NULL;H=H->next){
    if(color[H->key] !=2 && (H->cost+D[nx]) < D[H->key]){
        pi[H->key]=nx;
        D[H->key]=H->cost+D[nx];
        color[H->key]=1;
    }
 
  }
 }
 for(i=0;i<n;i++)printf("%d %d\n",i,D[i]);
return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
#define double long double
const int INF = 1e18, MOD = 1e9 + 7;

signed main() {
    int k, t;
    cin>>k>>t;
    int a;
    int mx = -INF;
    for (int i = 0; i < t; i++) {
        cin>>a;
        mx = max(mx, a);
    }
    cout<<max(0ll, mx - 1 - k + mx)<<endl;
}


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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

ll get(ll a, ll b) {
  ll res = 1ll;
  while(b) {
    if(b & 1) res = (res * a) % MOD;
    b >>= 1ll;
    a = (a * a) % MOD;
  }
  return res;
}

int main() {
  int n; cin >> n;
  vector <ll> a(n);
  for(auto &x : a) cin >> x;
  ll sum = accumulate(a.begin(), a.end(), 0ll);
  ll cur = 0;
  ll ans = 1e16;
  for(int i = 0; i < n - 1; i++) {
    cur += a[i];
    ans = min(ans, abs(cur + cur - sum));
  }
  print(ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> n;
	y=0;
	ll ans=0;
	for(i=0;i<n;i++)
	{
		cin >> x;
		y=max(y,x);
		ans+=(y-x);
	}
	cout<<ans<<endl;
}

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

int main() {
	int n,k,l,c=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
	    int a;
	    cin>>a;
	    if(a==1){
	        l=i+1;
	        i=n;
	        c=(l+k-3)/(k-1);
	        l=n-c*(k-1)-1;
	        if(l>0){
	            c+=(l+k-2)/(k-1);
	        }
	    }
	}
	cout<<c<<endl;
}

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

int main()
{
	int N, K;
	vector<int64_t> vec;
	cin >> N >> K;

	for (int i = 0; i < N; ++i)
	{
		int64_t h;
		cin >> h;
		vec.push_back(h);
	}

	sort(vec.begin(), vec.end());

	int64_t min_dif = static_cast<int64_t>(1) << 60;
	for (int i = 0; i + K - 1 < N; ++i)
	{
		min_dif = min(min_dif, vec[i + K - 1] - vec[i]);
	}

	cout << min_dif << endl;

	return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>

int N;
int A[114514];

int pos_cnt = 0;
int pos[114514];
int neg_cnt = 0;
int neg[114514];
int zero_cnt = 0;

int ptr = 0;
int kotae_list[114514][2];

int main(void) {
	int i;
	int kotae;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
		if (A[i] > 0) pos[pos_cnt++] = A[i];
		else if (A[i] < 0) neg[neg_cnt++] = A[i];
		else zero_cnt++;
	}

	if (zero_cnt > 0) {
		if (neg_cnt == 0) {
			neg_cnt = zero_cnt;
			for (i = 0; i < zero_cnt; i++) neg[i] = 0;
		} else {
			for (i = 0; i < zero_cnt; i++) pos[pos_cnt++] = 0;
		}
	}

	if (neg_cnt == 0) {
		int best = 0;
		int first = 0;
		int first_valid = 0;
		for (i = 1; i < pos_cnt; i++) {
			if (pos[i] < pos[best]) best = i;
		}
		kotae = pos[best];
		for (i = 0; i < pos_cnt; i++) {
			if (i == best) continue;
			if (!first_valid) {
				first = pos[i];
				first_valid = 1;
			} else {
				kotae_list[ptr][0] = kotae;
				kotae_list[ptr][1] = pos[i];
				kotae = kotae - pos[i];
				ptr++;
			}
		}
		kotae_list[ptr][0] = first;
		kotae_list[ptr][1] = kotae;
		kotae = first - kotae;
		ptr++;
	} else if (pos_cnt == 0) {
		int best = 0;
		for (i = 1; i < neg_cnt; i++) {
			if (neg[i] > neg[best]) best = i;
		}
		kotae = neg[best];
		for(i = 0; i < neg_cnt; i++) {
			if (i == best) continue;
			kotae_list[ptr][0] = kotae;
			kotae_list[ptr][1] = neg[i];
			kotae = kotae - neg[i];
			ptr++;
		}
	} else {
		kotae = neg[0];
		for (i = 1; i < pos_cnt; i++) {
			kotae_list[ptr][0] = kotae;
			kotae_list[ptr][1] = pos[i];
			kotae = kotae - pos[i];
			ptr++;
		}
		kotae_list[ptr][0] = pos[0];
		kotae_list[ptr][1] = kotae;
		kotae = pos[0] - kotae;
		ptr++;
		for (i = 1; i < neg_cnt; i++) {
			kotae_list[ptr][0] = kotae;
			kotae_list[ptr][1] = neg[i];
			kotae = kotae - neg[i];
			ptr++;
		}
	}

	printf("%d\n", kotae);
	for (i = 0; i < ptr; i++) {
		printf("%d %d\n", kotae_list[i][0], kotae_list[i][1]);
	}
	return 0;
}

/*

((((x- (((a-b)-c)-d) )-y)-z)-w)

y, z, w : 負の数
x       : 正の数
a       : 負の数
b, c, d : 正の数

負の数しかない場合

(((x-y)-z)-w)

xに一番絶対値が小さい数を持ってくる

正の数しかない場合

(x- (((a-b)-c)-d) )

aに一番絶対値が小さい数を持ってくる

*/


Measured memory_bytes: 3564
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#define LL long long int
const int N = 100005;
using namespace std;
LL n,A,B;
LL a[N];

bool judge(LL x)
{
    LL temp=x*B;
    LL sub=A-B;
    LL sum=0;
    for(LL i=n; i>=1; i--)
    {
        if(a[i]>temp)
        {
            if((a[i]-temp)%sub)
                sum+=(a[i]-temp)/sub+1;
            else
            sum+=(a[i]-temp)/sub;
        }
    }
    if(sum<=x)
        return true;
    return false;

}

int main()
{

    cin>>n>>A>>B;
    LL right=0;
    for(LL i=1; i<=n; i++)
    {
        cin>>a[i];
        right+=a[i]/B+1;
    }

    sort(a+1,a+1+n);
    LL left=1;
    while(left<right)
    {
        LL mid=(left+right)/2;
        if(judge(mid))
            right=mid;
        else
            left=mid+1;
    }
    cout<<left<<endl;
    return 0;

}



Measured memory_bytes: 1024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
long long int comb(long long int n,long long int r){
    vector<vector<long long int> > v(n+1,vector<long long int>(n+1,0));
    long long int i,j;
    rep(i,0,n+1){
        v.at(i).at(0)=1;
        v.at(i).at(i)=1;
    }
    rep(i,0,n+1){
        rep(j,0,i)v.at(i).at(j)=v.at(i-1).at(j-1)+v.at(i-1).at(j);
    }
    return v.at(n).at(r);
}
int main(void){
    string S,T,U;
    int A,B;
    cin>>S>>T;
    cin>>A>>B;
    cin>>U;
    if(S==U)cout<<A-1<<" "<<B<<endl;
    else cout<<A<<" "<<B-1<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val s = sc.nextLine()
    val count = mutableMapOf<Char, Int>()
    for (c in s) {
        count[c] = (count[c] ?: 0) + 1
    }
    var ans = 1L
    for (v in count.values) {
        ans *= v + 1
        ans %= 1000000007
    }
    ans--
    println(ans)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 34432
#include <iostream>
#include <sstream>  // istringstream
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;


int main()
{   
    long long N, K;
    cin >> N >> K;
    long long A[N+1];
    for(int i=1; i<N+1; ++i){
        cin >> A[i];
    }

    // 10^5回以内に必ずループする
    long long memo[2*100000+10] = {0};
    long long now = 1;
    memo[now] = 1;
    long long idx_s = 0; // ループが始まる視点
    long long loop_s = 0; // ループが始まる視点までの回数
    long long loop_n = 0; // ループの周期
    for(int i=2; i<N+10; ++i){
        now = A[now];
        if(memo[now] != 0){ // すでにきたことがある場合
            idx_s = now;
            loop_s = memo[now] - 1;
            loop_n = i - memo[now];
            break;
        }
        memo[now] = i;
    }

    if(K-loop_s >= loop_n){
        long long search_n = (K-loop_s)%loop_n;
        now = idx_s;
        for(int i=0; i<search_n; ++i){
            now = A[now];
        }
    }
    else{
        now = 1;
        for(int i=0; i<K; ++i){
            now = A[now];
        }
    }


    cout << now << endl;

    return 0;
}

Measured memory_bytes: 6708
l=list(input())
n=2**3
for i in range(n):
    sum=int(l[0])
    buf=l[0]
    for j in range(3):
        if i>>j & 1:
            buf+='+'+l[j+1]
            sum+=int(l[j+1])
        else:
            buf+='-'+l[j+1]
            sum-=int(l[j+1])
    if sum==7:
        print(buf+'=7')
        exit()


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

const int maxn=2e5+5;

int n,x;
int niz[maxn];
int used[maxn];

int main()
{
    cin>>n>>x;
    if(x==1 || x==(2*n-1))
    {
        cout<<"No";
		}
		else
		{
				if(x!=2)
				{
						niz[(2*n-1)/2]=x;
						niz[(2*n-1)/2-1]=x-1;
						niz[(2*n-1)/2+1]=x+1;
						niz[(2*n-1)/2+2]=x-2;
						used[x]=used[x-1]=used[x+1]=used[x-2]=1;
						int k=1;
						for(int i=0;i<2*n-1;i++)
						{
								if(niz[i]!=0)
										continue;
								else
										while(used[k]!=0)
												k++;
										niz[i]=k;
								k++;
						}
				}
				else
				{
						niz[(2*n-1)/2]=2;
						niz[(2*n-1)/2-1]=3;
						niz[(2*n-1)/2+1]=1;
						niz[(2*n-1)/2+2]=4;
						int k=5;
						for(int i=0;i<2*n-1;i++)
						{
								if(i<(2*n-1)/2+3 && i>(2*n-1)/2-2)
										continue;
								niz[i]=k;
								k++;
						}
				}
				cout<<"Yes"<<endl;
				for(int i=0;i<2*n-1;i++)
				{
						cout<<niz[i]<<endl;
				}
		}
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>

using namespace std;

const int MAXN = 3000 + 10;

int N;
char str[MAXN << 1];
int apos[MAXN]= {0}, bpos[MAXN]= {0};
int an = 0, bn = 0;

string f[MAXN], g[MAXN];
// f[i]: 强制选第i对a、b，对i...n对a、b的最大串
// g[i]: max (f[i], f[i + 1], ..., f[n])

int main () {
	scanf ("%d%s", & N, str + 1);
	for (int i = 1; i <= N << 1; i ++) {
		if (str[i] == 'a') apos[++ an] = i;
		if (str[i] == 'b') bpos[++ bn] = i;
	}
	for (int i = N; i >= 1; i --) {
		if (apos[i] < bpos[i]) {
			int j = i;
			while (j <= N && apos[j] < bpos[i]) j ++;
			f[i] = "ab" + g[j];
		}
		else {
			int j = i;
			while (j <= N && bpos[j] < apos[i]) j ++;
			for (int k = 1; k <= j - i; k ++) f[i] += 'b';
			f[i] += 'a' + (i + 1 == j ? g[i + 1] : f[i + 1]).substr(j - i - 1, string::npos);
		}
		g[i] = max (f[i], g[i + 1]);
	}
	cout << g[1] << endl;

	return 0;
}

/*
3
aababb
*/

/*
9
abbbaababaababbaba
*/

Measured memory_bytes: 20060
import java.util.*;

@SuppressWarnings("unused")
public class Main {

  private static void solve() {
    long a = nl();
    long b = nl();
    long c = nl();
    long d = nl();

    long x = Math.max(a * c, b * d);
    long y = Math.max(a * d, b * c);
    System.out.println(Math.max(x, y));
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  set<int> colors;
  rep(i, 3) {
    int a;
    std::cin >> a;
    colors.insert(a);
  }
  std::cout << colors.size() << "\n";
}


Measured memory_bytes: 256
package main

import (
	"fmt"
//	"strconv"
//	"sort"
//	"math"
//	"regexp"
)


var a,b,c int

func main(){
	fmt.Scan(&a,&b,&c)
	m := make(map[int]int)	

	m[a]++
	m[b]++
	m[c]++

	if m[7] ==1 && m[5]==2{
		fmt.Println("YES")
	}else{
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512