akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>
int main(void){
    std::string S;
    std::cin >> S;
    long children[100000]={};
    long start=0,end=0;
    for(long i=0;i<S.length()-1;i++){
        if(S[i]=='R' && S[i+1]=='L'){
            int R_index=i;
            int L_index=i+1;
            while(S[i+1]=='L'){
                end=i+1;
                if(i<S.length()-1){i++;}else{
                    break;
                }
            }
            long children_num=end-start+1;
            if((R_index-start+1)%2==0){
                children[R_index]=children_num/2;
                children[L_index]=children_num-children_num/2;
            }else{
                children[R_index]=children_num-children_num/2;
                children[L_index]=children_num/2;                
            }
            start=i+1;
        }
    }
    for(long i=0; i<S.length();i++){
        std::cout << children[i];
        if(i!=S.length()-1){
            std::cout << " ";
        }else{
            std::cout << std::endl;
        }
    }
    return 0;
}

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

int findSum(int n) {
  int sum;
  for (int i = 1; i <= n; i++) {
    sum += i;
  }
  return sum;
}

int main() {
  int N, answer;
  cin >> N;
  answer = findSum(N);
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> v(n), u(n+1);
    rep(i, n) cin >> v[i];

    int cnt = 0;
    rep(i, n-1){
        if(v[i]>=v[i+1]) cnt++;
        else cnt = 0;
        u[i+1] = cnt;
    }

    int ans = *max_element(all(u));
    cout << ans << endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  ll left = A[0];
  ll right = 0; for(int i = 1; i < N; ++i) right += A[i];
  ll res = pow(10, 17);
  for(int i = 1; i < N; ++i) {
    ll tmp = abs(left - right);
    if(res > tmp) res = tmp;
    left += A[i];
    right -= A[i];
  }
  cout << res << endl;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long a = long.Parse(Console.ReadLine());

            var result = (long)(a + Math.Pow(a, 2) + Math.Pow(a, 3));

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27840
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
  int N, K;
  string S, ans;
  cin >> N >> S >> K;
  ans = S;
  for(int i=0; i<N; i++){
    if(S[K-1]!=ans[i])ans[i]='*';
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
while true
  h,w = gets.split.map{ |e| e.to_i}
  break if (h == 0 && w == 0)
  even_line = ""
  odd_line = ""
  for i in 0..w-1
    if i.even?
      even_line += "#"
      odd_line += "."
    else
      even_line += "."
      odd_line += "#"
    end
  end
  
  
  h.times { |i|
    if (i.even?)
      puts even_line
    else
      puts odd_line
    end
  }
  puts ""
end

Measured memory_bytes: 6116
n = int(input())
def decomp(a):
    factors = []
    sqrt = round(n ** 0.5 + 0.5)
    for i in range(2, sqrt + 1):
        if not a % i:
            count = 0
            while a % i == 0:
                count += 1
                a //= i
            factors.append((i, count))
    if a != 1:
        factors.append((a, 1))
    return factors
total = 0
for i, j in decomp(n):
    temp = 1
    while j >= temp:
        total += 1
        j -= temp
        temp += 1
print(total)

Measured memory_bytes: 9440
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for A - Task Scheduling Problem
	A := make([]int, 3)
	fmt.Scanf("%d %d %d", &A[0], &A[1], &A[2])

	fmt.Println(math.Max(math.Max(math.Abs(float64(A[1])-float64(A[0])), math.Abs(float64(A[2])-float64(A[0]))), math.Abs(float64(A[1])-float64(A[2]))))

}


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

long long int right_acc[100005]={0}, left_acc[100005]={0};

int main(){
    long long int n, c;
    cin >> n >> c;
    vector<pair<long long int, long long int>> v;
    for(int i=0;i<n;++i){
        long long int x, y;
        cin >> x >> y;
        v.emplace_back(x, y);
    }

    long long int acc = 0, x = 0;
    for(int i=0;i<n;++i){
        acc -= (v[i].first - x);
        acc += v[i].second;
        x = v[i].first;
        right_acc[i+1] = max(acc, right_acc[i]);
    }

    acc = 0, x = c;
    for(int i=0;i<n;++i){
        acc -= (x - v[v.size()-1-i].first);
        acc += v[v.size()-1-i].second;
        x = v[v.size()-1-i].first;
        left_acc[i+1] = max(acc, left_acc[i]);
    }

    long long int ans = max(right_acc[n], left_acc[n]);
    for(int i=1;i<=n;++i){
        if(right_acc[i] != right_acc[i-1]){
            ans = max(ans, right_acc[i] + left_acc[n-i] - v[i-1].first);
        }
        if(left_acc[i] != left_acc[i-1]){
            ans = max(ans, left_acc[i] + right_acc[n-i] - (c-v[v.size()-i].first));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vi vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    ll ans=0;
    ll r=-1;
    int a;
    int b;
    REP(l,n){
        if(r<l){
            r=l;
            a=vec[l];
            b=vec[l];
        }
        while(r+1<n){
            int p=a+vec[r+1];
            int q=b^vec[r+1];
            if(p!=q){
                break;
            }else{
                a=p;
                b=q;
                r++;
            }
        }
        ans+=r-l+1;
        a-=vec[l];
        b^=vec[l];
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main(){
    int s_x, t_x, s_y, t_y;
    cin >> s_x >> s_y >> t_x >> t_y;
    
    int dx = t_x - s_x;
    int dy = t_y - s_y;
    
    for(int i = 0; i < dy; i++){
        cout << "U";
    }
    for(int i = 0; i < dx; i++){
        cout << "R";
    }
    
    for(int i = 0; i < dy; i++){
        cout << "D";
    }
    for(int i = 0; i < dx; i++){
        cout << "L";
    }
    
    cout << "L";
    for(int i = 0; i < dy + 1; i++){
        cout << "U";
    }
    for(int i = 0; i < dx + 1; i++){
        cout << "R";
    }
    cout << "D";
    
    cout << "R";
    for(int i = 0; i < dy + 1; i++){
        cout << "D";
    }
    for(int i = 0; i < dx + 1; i++){
        cout << "L";
    }
    cout << "U\n";
}

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

using namespace std;

const int N = 2e5 + 123;

int n;

int a[N], was[N], ans = N;

int main () {
    cin >> n;
    for (int i = 1;i <= n;i ++) {
        cin >> a[i];
    }was[0] = true;
    for (int i = 1;i <= n;i ++) {
        if (was[a[i] - 1]) {
            was[a[i]] = true;
            ans = min (ans, n - a[i]);
        }
    }
    if (ans == N) {
        cout << -1;
        exit (0);
    }
    cout << ans;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    char S[4];

    scanf("%s", S);

    int t = 0;

    if(strcmp(S, "abc") == 0){
        t = 1;
    }
    if(strcmp(S, "acb") == 0){
        t = 1;
    }
    if(strcmp(S, "bac") == 0){
        t = 1;
    }
    if(strcmp(S, "bca") == 0){
        t = 1;
    }
    if(strcmp(S, "cab") == 0){
        t = 1;
    }
    if(strcmp(S, "cba") == 0){
        t = 1;
    }

    if(t == 1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1624
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long d = sc.nextLong();
    int count = 0;
    for (int i = 0; i < n; i++) {
      long x = sc.nextLong();
      long y = sc.nextLong();
      if (x * x + y * y <= d * d) {
        count++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 59952
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll a,b,c,H,W,h,ans=10000000000;cin>>H>>W;
  a=H/3*W;h=H-H/3;
  b=(h/2)*W;c=(h-h/2)*W;
  ans=min(ans,max({a,b,c})-min({a,b,c}));
  b=h*(W/2);c=h*(W-W/2);
  ans=min(ans,max({a,b,c})-min({a,b,c}));
  a=(H/3+1)*W;h--;
  b=(h/2)*W;c=(h-h/2)*W;
  ans=min(ans,max({a,b,c})-min({a,b,c}));
  b=h*(W/2);c=h*(W-W/2);
  ans=min(ans,max({a,b,c})-min({a,b,c}));
  swap(H,W);
  a=H/3*W;h=H-H/3;
  b=(h/2)*W;c=(h-h/2)*W;
  ans=min(ans,max({a,b,c})-min({a,b,c}));
  b=h*(W/2);c=h*(W-W/2);
  ans=min(ans,max({a,b,c})-min({a,b,c}));
  a=(H/3+1)*W;h--;
  b=(h/2)*W;c=(h-h/2)*W;
  ans=min(ans,max({a,b,c})-min({a,b,c}));
  b=h*(W/2);c=h*(W-W/2);
  ans=min(ans,max({a,b,c})-min({a,b,c}));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main(void)
{
        int n,i,P=0,W=0,Y=0,G=0,s;
        char c;

        scanf("%d",&n);

        for(i=0;i<n;i++){
                scanf("%c",&c);
                if(c=='P') P=1;
                else if(c=='W') W=1;
                else if(c=='Y') Y=1;
                else if(c=='G') G=1;
        }

        if(Y==0) printf("Three\n");
        else     printf("Four\n");
        return 0;
}


Measured memory_bytes: 128
while True:
    n,r = map(int,input().split())
    if n == 0:
        break
    card = []
    for i in range(n):
        card.append(n - i)
    for i in range(r):
        p,c = map(int,input().split())
        card = card[p - 1:p + c - 1] + card[0:p - 1] + card[p + c - 1:n]
    print(card[0])



Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+7;
const ll mod = 1e9 + 7;
#define afdafafafdafaf y1;
int ar[maxn], n, m, k;


int main()
{
    int a,b,ans = -1;
    cin>>a>>b;
    if(a >= 1 && a <= 9 && b >= 1 && b <= 9)ans = a * b;
    cout<<ans<<"\n";
 
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod*mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

int max_n;
const int mn = 100000;
struct edge {
	int to, cap, cost, rev;
};
vector<edge> G[mn];
int par[mn];
int dist[mn];
void add_edge(int from, int to, int cap, int cost) {
	G[from].push_back({ to,cap,cost,(int)G[to].size() });
	G[to].push_back({ from,0,-cost,(int)G[from].size() - 1 });
	max_n = max({ max_n, from + 1, to + 1 });
}
int minimum_road(int s, int t) {
	fill(par, par + max_n, -1);
	fill(dist, dist + max_n, mod);
	dist[s] = 0;
	priority_queue<P, vector<P>, greater<P>> q; q.push({ 0,s });
	while (!q.empty()) {
		P p = q.top(); q.pop();
		int id = p.second;
		if (id == t)continue;
		rep(j, G[id].size()) {
			if (G[id][j].cap > 0) {
				int to = G[id][j].to;
				int nd = p.first + G[id][j].cost;
				if (nd < dist[to]) {
					dist[to] = nd;
					par[to] = id;
					q.push({ dist[to],to });
				}
			}
		}
	}
	int cur = t;
	while (cur != s) {
		int p = par[cur];
		if (p < 0)return -1;
		rep(j, G[p].size()) {
			if (G[p][j].cap > 0 && G[p][j].to == cur && dist[p] + G[p][j].cost == dist[cur]) {
				G[p][j].cap--;
				G[cur][G[p][j].rev].cap++;
				break;
			}
		}
		cur = p;
	}
	return dist[t];
}
int u;
int minimum_cost_flow(int s, int t) {
	int ret = 0;
	while(true) {
		int z = minimum_road(s, t);
		if (z < 0)return ret;
		ret += z; u++;
	}
	return ret;
}
const int m_n = 1000001;
void solve() {
	int n;
	while (cin >> n, n) {
		u = 0;
		rep(i, 2*n + 2)G[i].clear();
		vector<vector<int>> v(n);
		int sum = 0;
		rep(i, n) {
			v[i].resize(3);
			rep(j, 3)cin >> v[i][j];
			sum += v[i][0] * v[i][1] * v[i][2];
			sort(v[i].begin(), v[i].end());
		}
		int s = 2*n, t = 2*n + 1;
		rep(i, n) {
			add_edge(s, i, 1,0);
			add_edge(n+i, t, 1,0);
		}
		rep(i, n) {
			rep(j, n) {
				if (i == j)continue;
				bool f = true;
				rep(k, 3) {
					if (v[i][k] >= v[j][k])f = false;
				}
				if (f) {
					add_edge(i, n+j, 1,m_n-v[i][0]*v[i][1]*v[i][2]);
				}
			}
		}
		int z = minimum_cost_flow(s, t);
		z = u * m_n - z;
		cout << sum-z << endl;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
		return 0;
}


Measured memory_bytes: 5720
S = input()

ans = False

if S[:7] == "keyence":
    ans = True

if S.find("k") != -1:
    if S.find("keyenc")== 0and S[-1] == "e":
        ans = True
    if S.find("keyen")== 0 and S[-2:] == "ce":
        ans = True
    if S.find("keye")== 0 and S[-3:] == "nce":
        ans = True
    if S.find("key")== 0and S[-4:] == "ence":
        ans = True
    if S.find("ke")== 0 and S[-5:] == "yence":
        ans = True
    if S.find("k")== 0 and S[-6:] == "eyence":
        ans = True

else:
    if S[-7:] == "keyence":
        ans = True

if ans:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <map>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;

int main()
{
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	if (N <= K)
	{
		co(X*N);
	}
	else
	{
		co(X*K + Y * (N - K));
	}
	return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]

ans = [[0]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            li = []
            for k in range(-1,2):
                li.append((i-1, j+k))
            li.append((i, j-1))
            li.append((i, j+1))
            for k in range(-1, 2):
                li.append((i+1, j+k))
            for k in li:
                if 0 <= k[0] < h and 0 <= k[1] < w:
                    ans[k[0]][k[1]] += 1

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            ans[i][j] = '#'

for i in range(h):
    for j in range(w):
        print(ans[i][j], end = '')
    print()


Measured memory_bytes: 3572
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
using namespace std;

const long long mod = 1e9 + 7;

long long r1, r2, c1, c2;

long long power(long long m, long long k) {
	m %= mod;
	int res = 1;
	while (k) {
		if (k & 1) res = res * m % mod;
		m = m * m % mod;
		k >>= 1;
	}
	return res;
}

long long check(long long n, long long m) {
	if (n < m)
		return 0;

	long long res = 1;
	for (int i = 1; i <= m; i++)
		res = res * (n - i + 1) % mod * power(i, mod - 2) % mod;
	return res;
}

int main() {
	cin >> r1 >> c1 >> r2 >> c2;

	r2++, c2++;
	cout << (((check(r2 + c2, c2) - check(r1 + c2, c2) - check(r2 + c1, c1) + check(r1 + c1, c1)) % mod + mod) % mod) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,b,c;
	
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	
	if(a < b && b < c)
		printf("Yes\n");
	else
		printf("No\n");
	
	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b;
  cin >> a >> b;
  if (a % 2 != b % 2) cout << "IMPOSSIBLE" << "\n";
  else cout << (a + b) / 2 << "\n";
  return 0;
}

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

using ll = long long;
using P = pair<int, int>;

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  string s;
  cin >> s;

  if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
//---------------------------------------------------------------------------------------------------
typedef pair<int,int> P;

int main(void){
    // Your code here!
    int n; cin >> n;
    vector<int> a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];
    vector<P> p(n);
    rep(i,n) {
        p[i] = {b[i],a[i]};
    }
    sort(all(p));
    cout << MAX(a) - MIN(a)+1 + p[n-1].second - 1 + p[0].first << endl;
}


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

int main(int argc, char* argv[])
{
  int x;
  cin >> x;
  if (x == 7 || x == 5 || x == 3) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  cout << endl;

  return 0;
}


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

int main()
{
    int N;
    std::cin >> N;
    std::vector<int> odds;
    for (int i = 1; i <= N; i++)
    {
        if (i % 2 != 0) { odds.push_back(i); }
    }
    int resultCount = 0;
    for (int num : odds)
    {
        int count = 0;
        for (int i = 1; i <= num; i++)
        {
            if (num % i == 0) { count++; }
        }
        if (count == 8) { resultCount++; }
    }
    std::cout << resultCount << std::endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define R register
#define div why_abs_so_strong
using namespace std;
const int mod=998244353;
const int MAXN=2100;
int jc[MAXN*4];

int add(int x,int y)
{return (x+y)%mod;}
int mul(int x,int y)
{return 1LL*x*y%mod;}
int fpow(int x,int y)
{
	int ans=1;
	while(y)
	{
		if(y&1)ans=mul(ans,x);
		x=mul(x,x),y>>=1;
	}
	return ans;
}
int inv(int x)
{return fpow(x,mod-2);}
int div(int x,int y)
{return mul(x,inv(y));}
int comb(int x,int y)
{
	if(x<y)return 0;
	return div(jc[x],mul(jc[y],jc[x-y]));
}

int main()
{
	int k,n;
	scanf("%d%d",&k,&n);
	int m=k+k,n2=n>>1;
	jc[0]=1;
	for(R int i=1;i<=8000;++i)jc[i]=mul(jc[i-1],i);
	for(R int i=2;i<=m;++i)
	{
		int t1=k-i+1;
		if(t1<0)t1=-t1;
		int t2=k-t1,ans=0;
		int p=t2>>1,t3=k-t2;
		if(i%2==0)
		{
			for(R int q=0;q<=p;++q)
		    {
		    	ans=add(ans,mul(mul(comb(p,q),fpow(2,q)),comb(n+t3-1,q+t3-1)));
				ans=add(ans,mul(mul(comb(p,q),fpow(2,q)),comb(n+t3-2,q+t3-1)));
			}
		}
		else for(R int q=0;q<=p;++q)
		  ans=add(ans,mul(mul(comb(p,q),fpow(2,q)),comb(n+t3-1,q+t3-1)));
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    std::string s;
    std::cin >> s;
    int t = (s.length()-1)/2;
    bool flag = true;
    for(int i = 0; i < t/2; i++){
        flag &= (s[i] == s[t-i-1]);
    }
    for(int i = 0; i < t; i++){
        flag &= (s[i] == s[i+t+1]);
    }
    std::cout << (flag ? "Yes" : "No") << std::endl;
    return 0;
}


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

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------


int main() {
 ll n,ans=0;
 cin>>n;
 vll l(n);
 rep(i,n)cin>>l.at(i);
 
 rep(i,n-2){
     rep2(j,i+1,n-1){
         rep2(k,j+1,n){
             if(l.at(i)!=l.at(j)&&l.at(i)!=l.at(k)&&l.at(j)!=l.at(k)){
                 if(l.at(i)<l.at(j)+l.at(k)&&l.at(j)<l.at(i)+l.at(k)&&l.at(k)<l.at(j)+l.at(i))ans++;
             }
         }
     }
 }
 cout<<ans<<endl;
 
}



Measured memory_bytes: 3628
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var n int
	var w, r string
	fmt.Scan(&n)
	m := map[string]int{}
	fmt.Scan(&w)
	for _, v := range w {
		m[string(v)]++
	}
	for i := 0; i < n-1; i++ {
		fmt.Scan(&w)
		wm := map[string]int{}
		for _, v := range w {
			wm[string(v)]++
		}
		m = check(m, wm)
	}
	var ra []string
	for k, v := range m {
		ra = append(ra, strings.Repeat(k, v))
	}
	sort.Sort(sort.StringSlice(ra))
	for i := 0; i < len(ra); i++ {
		r += ra[i]
	}
	fmt.Println(r)
}
func check(b map[string]int, w map[string]int) map[string]int {
	r := map[string]int{}
	for k, v := range b {
		if w[k] > 0 && v > w[k] {
			r[k] = w[k]
			continue
		}
		if w[k] >= v {
			r[k] = v
			continue
		}
	}
	return r
}

Measured memory_bytes: 768
//C
//#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>


#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Hang in there!

using namespace std;


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



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// AtCoder_B
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		long L[] = new long[N];
		for(int i=0; i<N; i++) {
			L[i] = sc.nextLong();
		}

		int ans = 0;

		for(int i=0; i<N; i++) {
			for(int j=i+1; j<N; j++) {
				if(L[i] == L[j]) {
					continue;
				}
				for(int k=j+1; k<N; k++) {
					if(L[i] == L[k] || L[j] == L[k]) {
						continue;
					}
					if(L[i]+L[j]>L[k] && L[j]+L[k]>L[i] &&L [k]+L[i]>L[j]) {
						ans++;
					}
				}
			}
		}
		// 出力
		System.out.println(ans);
	    // Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}


Measured memory_bytes: 36384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long cnt;
int l;
int A[100000000];
int n;

vector <int> G;

void insertion(int *A,int n,int g)
{
	for (int i=g;i<n;i++)
	{
		int v=A[i];
		int j=i-g;
		while (j>=0&&A[j]>v)
		{
			A[j+g]=A[j];
			j-=g;
			cnt++; 
		}
		A[j+g]=v;
	}
} 

void shell(int A[],int n)
{
	for (int h=1;;)
	{
		if (h>n) break;
		G.push_back(h);
		h=3*h+1;
	}
	for (int i=G.size()-1;i>=0;i--)
	{
		insertion(A,n,G[i]);
	}
}

int main ()
{
	cin>>n;
	for (int i=0;i<n;i++) scanf("%d",&A[i]);
	cnt=0;
	shell(A,n);
	
	cout<<G.size()<<endl;
	for (int i=G.size()-1;i>=0;i--)
	{
		printf ("%d",G[i]);
		if (i) printf (" ");
	}
	
	printf ("\n");
	printf ("%d\n",cnt);
	
	for (int i=0;i<n;i++) printf ("%d\n",A[i]);
	
	return 0;
}


Measured memory_bytes: 7096
#include<stdio.h>
int main(){
    int a, b;
    int d, r;
    double f;
    scanf("%d %d", &a, &b);
    d = a / b;
    r = a % b;
    f = (double)a / (double)b;
    printf("%d %d %.5f\n", d, r, f);
}

Measured memory_bytes: 2752
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

const int MAX = 1111111;

int dpall[MAX];
int dpodd[MAX];
vi tri, all, odd;

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);

	tri.push_back(1);
	FOR(i, 2, MAX)
	{
		int t = tri.back() + i;
		if (t >= MAX) break;
		tri.push_back(t);
	}

	all.push_back(1);
	odd.push_back(1);
	FOR(i, 2, MAX)
	{
		int t = all.back() + tri[i-1];
		if (t >= MAX) break;
		all.push_back(t);
		if (t % 2 == 1) odd.push_back(t);
	}

	REP(i, MAX)
	{
		dpall[i] = dpodd[i] = MAX;
	}

	for (auto i : all) dpall[i] = 1;
	for (auto i : odd) dpodd[i] = 1;

	FOR(i, 1, MAX)for (auto j : all)
	{
		int t = i + j;
		if (t >= MAX) break;
		chmin(dpall[t], dpall[i] + 1);
	}
	FOR(i, 1, MAX)for (auto j : odd)
	{
		int t = i + j;
		if (t >= MAX) break;
		chmin(dpodd[t], dpodd[i] + 1);
	}
	int n;
	while (cin >> n, n)
	{
		cout << dpall[n] << " " << dpodd[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 11812
import java.util.*;
import java.io.*;

public class Main {
	public static String repeat(String one, int num){
		if (num<=0) return "";
		else return one + repeat(one,num-1);
	}
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();
        int N = sc.nextInt();
        
        if(N==100) N++;
        System.out.println(N + repeat("00",D));
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define lb(x) ((x)&(-(x)))
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 200010
using namespace std;
typedef long long ll;
inline void upd(int& a,int b){a=a+b>=dalao?a+b-dalao:a+b;}
int mem[N<<4],mcnt;
inline void mlc(int a,int* &t){mcnt+=a+1,t=&mem[mcnt],mcnt++;}
struct edge{int n,t;}e[N];
int n,head[N],ecnt,d[N],cnt[N],pw[N],*f[N][3],t[3];
inline void add(int a,int b){e[++ecnt]=(edge){head[a],b},head[a]=ecnt;}
inline void dfs1(int x,int D){cnt[D]++;for(int i=head[x];i;i=e[i].n)dfs1(e[i].t,D+1),d[x]=max(d[x],d[e[i].t]+1);}
inline void dfs(int x,int dep){
	int mx=-1,p=-1;
	for(int i=head[x];i;i=e[i].n)if(mx<d[e[i].t])mx=d[p=e[i].t];
	if(mx==-1){mlc(dep,f[x][0]),mlc(dep,f[x][1]),mlc(dep,f[x][2]),f[x][0][0]=f[x][1][0]=1;return;}
	dfs(p,dep+1);
	for(int i=head[x];i;i=e[i].n)if(e[i].t^p)dfs(e[i].t,0);
	for(int i=0;i<3;i++)f[x][i]=f[p][i]-1;
	f[x][0][0]=f[x][1][0]=1,mx=-1;
	for(int i=head[x],y;i;i=e[i].n)if(e[i].t^p){
		y=e[i].t,mx=max(mx,d[y]);
		for(int j=0;j<=d[y];j++){
			mset(t,0);
			upd(t[0],1ll*f[x][0][j+1]*f[y][0][j]%dalao);
			upd(t[1],1ll*f[x][1][j+1]*f[y][0][j]%dalao);
			upd(t[1],1ll*f[x][0][j+1]*f[y][1][j]%dalao);
			upd(t[2],1ll*f[x][1][j+1]*f[y][1][j]%dalao);
			upd(t[2],1ll*f[x][2][j+1]*f[y][0][j]%dalao);
			upd(t[2],1ll*f[x][2][j+1]*f[y][1][j]%dalao);
			f[x][0][j+1]=t[0],f[x][1][j+1]=t[1],f[x][2][j+1]=t[2];
		}
	}
	for(int i=1;i<=mx+1;i++)upd(f[x][0][i],f[x][2][i]),f[x][2][i]=0;
}
int main(){
	scanf("%d",&n);
	for(int i=1,p;i<=n;i++)scanf("%d",&p),add(p,i);
	dfs1(0,0),dfs(0,0);
	int ans=0;pw[0]=1;
	for(int i=1;i<=n;i++)pw[i]=(pw[i-1]<<1)%dalao;
	for(int i=0;i<=d[0];i++)upd(ans,1ll*pw[n-cnt[i]+1]*f[0][1][i]%dalao);
	printf("%d",ans);
	return 0;
}

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

int main()
{
	char s[111];
	while(scanf("%s", s) !=EOF ){
		int i, l, c=0, f=0;
		l=strlen(s);
		for(i=0; i<l; i++){
			if(s[i]=='C')
				c++;
			if(s[i]=='F'&&c!=0)
				f++;
		}
		if(c>0&&f>0)
			printf("Yes\n");
		else 
			printf("No\n");
	}
	return 0;
}

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

using namespace std;

#define ll long long
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int maxN = 3e3+5;
const int mod = 1e9+7;
double P[maxN],dp[maxN][maxN];
int n;

void solve(){
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>P[i];
    dp[0][0] = (1-P[0]);
    dp[0][1] = P[0];
    for(int i=1;i<n;i++){
        dp[i][0] = (1-P[i])*dp[i-1][0];
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<=i+1;j++){
            dp[i][j] = P[i]*dp[i-1][j-1]+(1-P[i])*dp[i-1][j];
        }
    }
    double ans = 0;
    for(int i=n/2+1;i<=n;i++){
        ans += dp[n-1][i];
    }
    cout<<setprecision(11)<<ans<<endl;
}

int main()
{
    FASTIO
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}






Measured memory_bytes: 49900
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  int a, b;
  cin >> a >> b;
  bool f = (1 <= a && a <= 9) && (1 <= b && b <= 9);
  cout << (f ? a * b : -1) << endl;
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;

struct tnode
{
    int x, y;
}a[MAXN];

bool cmp (tnode a, tnode b)
{
    return a.y > b.y;
}

int main ()
{
    int n, m;
    scanf ("%d%d", &n, &m);
    int xmax = 0;
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%d%d", &a[i].x, &a[i].y);
        if (a[i].x > xmax)
        {
            xmax = a[i].x;
        }
    }
    int ans = 0;
    sort (a + 1, a + n + 1, cmp);
    for (int i = 1; i <= n; i ++)
    {
        if (a[i].y > xmax)
        {
            m -= a[i].y;
            ans ++;
            if (m <= 0)
            {
                break;
            }
        }
        else
        {
            break;
        }
    }
    if (m > 0)
    {
        int tmp = m / xmax;
        if (m % xmax)
        {
            tmp ++;
        }
        ans += tmp;
    }
    printf ("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1152
import Control.Applicative ((<$>))
import Control.Monad (foldM)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Bool (bool)

main :: IO ()
main = do
  B.getLine
  B.lines <$> B.getContents >>= solve

solve :: [ByteString] -> IO ()
solve bs = foldM f Leaf bs >> return ()
  where f :: BSTree Int -> ByteString -> IO (BSTree Int)
        f tr bs = case B.words bs of
                   [com, bn] | com == sfind -> do
                     putStrLn $ bool "no" "yes" $ bstFind (readi B.readInt bn) tr
                     return tr
                   [_, bn] -> return (bstInsert (readi B.readInt bn) tr)
                   _ -> do
                     printList $ inOrder tr
                     printList $ preOrder tr
                     return tr
        sfind = B.pack "find"
data BSTree a = Leaf | Node a (BSTree a) (BSTree a) deriving Show

bstInsert :: (Ord a) => a -> BSTree a -> BSTree a
bstInsert x (Node y lt rt) | x > y = Node y lt (bstInsert x rt)
                           | x < y = Node y (bstInsert x lt) rt
                           | otherwise = Node y lt rt
bstInsert x Leaf = Node x Leaf Leaf

bstFind :: (Ord a) => a -> BSTree a -> Bool
bstFind _ Leaf = False
bstFind x (Node y lt rt) | x == y = True
                         | x > y = bstFind x rt
                         | otherwise = bstFind x lt

foldPre :: (a -> b -> b) -> b -> BSTree a -> b
foldPre f z Leaf = z
foldPre f z (Node x l r) = f x y2
  where y1 = foldPre f z r
        y2 = foldPre f y1 l

foldIn :: (a -> b -> b) -> b -> BSTree a -> b
foldIn f z Leaf = z
foldIn f z (Node x l r) = foldIn f y2 l
  where y1 = foldIn f z r
        y2 = f x y1

preOrder :: BSTree a -> [a]
preOrder = foldPre (:) []

inOrder :: BSTree a -> [a]
inOrder = foldIn (:) []

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . (' ':) . unwords . map show

readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n



Measured memory_bytes: 107656
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//素因数分解
vector<ll> decom;

void decompositPrime(ll n)
{
    ll a = 2;
    while (n >= a * a)
    {
        if (n % a == 0)
        {
            decom.push_back(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }
    decom.push_back(n);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    int N; cin >> N;
    vector<int> cnt(100010,0);
    ll ans=0;
    REP(i,N){
        int a; cin >> a;
        ans += a;
        cnt[a]++;
    }
    
    int Q; cin >> Q;
    while(Q--){
        int B,C; cin >> B >> C;
        cnt[C] += cnt[B];
        ans += (C-B) * cnt[B];
        cout << ans << "\n";
        cnt[B] = 0;
    }

    return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll n, m;
    cin >> n >> m;

    cout << (n-1) * (m-1) << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

VI dijkstra(map<int, vector<int>> &g, int n, int start)
{
    VI ret(n, IINF);
    priority_queue<PII, vector<PII>, greater<PII>> que;
    que.push({0, start});
    while (!que.empty())
    {
        int cost = que.top().first;
        int cur = que.top().second;
        que.pop();
        if (cost < ret[cur])
        {
            ret[cur] = cost;
            for (auto &&x : g[cur])
            {
                que.push({cost + 1, x});
            }
        }
    }
    return ret;
}

int main()
{
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--;
    t--;
    map<int, vector<int>> g;
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    auto ds = dijkstra(g, n, s);
    auto dt = dijkstra(g, n, t);
    ll dist = ds[t];
    map<int, int> mps, mpt;
    rep(i, n)
    {
        mps[ds[i]]++;
        mpt[dt[i]]++;
    }

    ll ans = 0;
    dist--;
    rep(i, n)
    {
        ll cur = ds[i];
        ans += mpt[dist - cur - 1];
        //  ans += mpt[dist - 2 - cur];
    }
    cout << ans << endl;
}


Measured memory_bytes: 18980
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}


void func(void)
{
//DEBUG_OUT("----\n");
    int N;
    cin >> N;
    int evenCnt = 0;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        if(a%2 == 0){ evenCnt++; }
    }

    int n = pow(3, N);
    int ans = n - pow(2, evenCnt);

    cout << ans << endl;
    
    return;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    long long n,k; cin>>n>>k;
    long long x[n]; rep(i,n) cin>>x[i];
    long long ans=1e15;
    for(long long left=0;left+k-1<n;left++){
        long long right=left+k-1;
        if(x[left]<0&&x[right]<0){
            ans=min(ans,abs(x[left]));
        }else if(x[left]>=0&&x[right]>=0){
            ans=min(ans,abs(x[right]));
        }else{
            ans=min({ans,abs(x[left]*2)+x[right],abs(x[left])+2*x[right]});
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=n-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    string s;
    cin>>s;
    int n=s.length();

    vvi dp(n,vi(2));
    dp[0][0]=1;
    if(s[0]!=s[1])dp[1][0]=2;
    else dp[1][0]=1;
    dp[1][1]=1;

    repa(i,2,n){
        dp[i][0]=dp[i-1][1]+1;
        if(s[i]!=s[i-1])cmax(dp[i][0],dp[i-1][0]+1);

        dp[i][1]=max(dp[i-2][1],dp[i-2][0])+1;
    }

    cout<<max(dp[n-1][0],dp[n-1][1])<<"\n";

    return 0;

}

Measured memory_bytes: 11396
strs = gets.chomp
s1 = []
s2 = []
curr_i = 0
strs.chars do |c|
  curr_i += 1
  if c == "\\"
    s1.push(curr_i)
  elsif c == '/'
    down_i = s1.pop
    next if down_i.nil?

    area = curr_i - down_i
    while s2.last && s2.last[0] > down_i
      area += (s2.pop)[1]
    end
    s2.push([down_i, area])
  end
end

puts s2.sum{|s| s[1]}
puts "#{s2.length} #{s2.map{|s| s[1]}.join(' ')}".strip


Measured memory_bytes: 8912
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string str;
    int K;
    cin >> str >> K;
    vector<string> dic(0);
    int index = 0;
    for(int i=0;i<str.length();i++){
        for(int j=1;j<=K && i+j <= str.length();j++){
            dic.push_back(str.substr(i,j));
        }
    }
    sort(dic.begin(),dic.end());
    unique(dic.begin(),dic.end());
    cout << dic[K-1] << endl;
    return 0;
}

Measured memory_bytes: 1660
from collections import defaultdict

def main():
    k = int(input())
    dic = defaultdict(bool)
    sev = 7
    i = 1
    while(True):
        sev = sev%k
        if sev == 0:
            print(i)
            return
        if(dic[sev]):
            print(-1)
            return
        dic[sev] = True
        sev = (sev + 7*pow(10,i,k))%k
        i += 1

if __name__ == "__main__":
    main()

Measured memory_bytes: 158580
X,Y = map(int,input().split())

mod = 10**9 + 7 

if (X+Y)%3 != 0:
    print(0)
    exit(0)

a = (2*X-Y)//3
b = (2*Y-X)//3

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
# mod = 10**9+7 #出力の制限
N = 10**6+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
 
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

print(cmb(a+b,a,mod))

Measured memory_bytes: 122044