akhauriyash/Code-Regression huggingface dataset:
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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;
}

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16) << boolalpha;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int A, B, M;
  cin >> A >> B >> M;
  vi a(A), b(B);
  cin >> a >> b;

  int ans = INF;
  rep(i, M) {
    int x, y, c;
    cin >> x >> y >> c;
    chmin(ans, a[x - 1] + b[y - 1] - c);
  }
  sort(all(a));
  sort(all(b));
  chmin(ans, a[0] + b[0]);
  out(ans);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  unordered_map<ll, ll> mp;
  ll maxi = 0;
  rep(i, n) {
    ll num;
    cin >> num;
    mp[num]++;
    maxi += num;
  }
  //   cout << endl;
  //   for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
  //     cout << itr->first << " " << itr->second << endl;
  //   }

  int q;
  cin >> q;
  rep(i, q) {
    ll b, c;
    cin >> b >> c;
    maxi -= mp[b] * b;
    maxi += mp[b] * c;
    cout << maxi << endl;
    mp[c] += mp[b];
    mp[b] = 0;
  }
  return 0;
}

Measured memory_bytes: 6984
N, M = map(int, input().split())
A_list = []
for i in range(N):
    A = list(map(int, input().split()))
    A_list.append(A)
dic_A = {}
for A in A_list:
    for j in range(1, len(A)):
        if A[j] in dic_A:
            dic_A[A[j]] += 1
        else:
            dic_A[A[j]] = 1
cnt = 0
for i in range(1, M+1):
    if i in dic_A and dic_A[i] == N:
        cnt += 1
print(cnt)

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

S = 0
a = 0
while S+A[a]<=K:
  S+=A[a]
  a+=1

b = 0
ans = a

while a>=0:
  if S+B[b]<=K:
    S+=B[b]
    b+=1
  else:
    S-=A[a-1] 
    a-=1
  ans = max(ans, a+b)

print(ans)

Measured memory_bytes: 40136
a,b,c,d = map(int,input().split())

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def f(e):
   return e - (e//c + e//d - e//(c*d//gcd(c,d)))

print(f(b)-f(a-1))


Measured memory_bytes: 2940
H,W = map(int,input().split())
lists = [input() for i in range(H)]
x = 1
y = 1
check = True
for x in range(1,H-1):
    for y in range(1,W-1):
        if(lists[x][y] == "#"):
            if(x!=0 or y!=0 or x==W-1or y==H-1):
                if((lists[x+1][y] == ".") and (lists[x-1][y] == ".") and (lists[x][y-1] == ".") and (lists[x][y+1] == ".")):
                    check = False
if(lists[0][0] == "#"):
     if(lists[0][1] == "." and lists[1][0] == "."):
        check = False
if(lists[H-1][0] == "#"):
     if(lists[H-2][0] == "." and lists[H-1][1] == "."):
            check = False
if(lists[0][W-1] == "#"):
    if(lists[0][W-2] == "." and lists[1][W-1] == "."):
        check = False
if(lists[H-1][W-1] == "#"):
    if(lists[H-2][W-1] == "." and lists[H-1][W-2] == "."):
        check = False
if(check):
    print("Yes")
else :
    print("No")

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

int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    for(int i=0;i<n;i++){
        cin >> c[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    
    long long int kotae = 0;
    for(int i=0;i<n;i++){
        //aを求める
        auto p1 = lower_bound(a,a+n,b[i]);
        long long int dis1 = distance(a,p1);
        //bを求める
        auto p2 = upper_bound(c,c+n,b[i]);
        long long int index = distance(c,p2);
        long long int dis2 = n-index;
        
        kotae += dis1*dis2;
    }
    cout << kotae << endl;
}

Measured memory_bytes: 1408
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[4][13], p[10], s[5], t[5], z; char c; string s1 = "A23456789TJQK", s2 = "SCHD";
int judge() {
	vector<int> v; int w = 1, f = 1, g = 1, h = 1;
	for (int i = 1; i < 5; i++) {
		if (s[i - 1] != s[i]) v.push_back(w), w = 0;
		if (s[i - 1] + 1 != s[i]) g = 0;
		if (t[i - 1] != t[i]) f = 0;
		w++;
	}
	v.push_back(w);
	sort(v.begin(), v.end());
	if (v.size() == 2) return v.back() + 3;
	for (int i = 0; i < 5; i++) h &= (s[i] == (i ? (i + 8) % 13 : 0) ? 1 : 0);
	if (f) return h ? 9 : g ? 8 : 5;
	if (g | h) return 4;
	if (v.back() == 3) return 3;
	if (v.back() == 2) return 5 - v.size();
	return 0;
}
int main() {
	while (cin >> n) {
		if (z++) cout << endl;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 13; j++) cin >> a[i][j];
		}
		for (int i = 1; i < 10; i++) cin >> p[i];
		for (int i = 0; i < n; i++) {
			int cnt = 0;
			for (int j = 0; j < 5; j++) {
				cin >> c; s[j] = s1.find(c);
				cin >> c; t[j] = s2.find(c);
				cnt += a[t[j]][s[j]];
			}
			sort(s, s + 5);
			sort(t, t + 5);
			cout << cnt * p[judge()] << endl;
		}
	}
}

Measured memory_bytes: 3016
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2,max):
        fac[i] = fac[i-1]*i%mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod

def COM(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k]*finv[n-k]%mod)%mod

mod = 10**9+7

K = int(input())
S = input()
N = len(S)
max = N+K
fac = [0] * max
finv = [0] * max
inv = [0] * max
COMinit()

ans = 0
for i in range(K+1):
    x = COM(N+K-i-1,N-1)
    y = pow(26,i,mod)
    z = pow(25,K-i,mod)
    xyz = ((x*y%mod)*z)%mod
    ans = (ans+xyz)%mod
print(ans)


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

int main()
{
//    for (int z = 0; z < 100; z++) {
    int N, A, B, C, D;
//        N = 100; A = 10; B = 30; D = 50;
//        C = A + arc4random() % 80;
//        if ( C == A || C == B || C == D ) {
//            C++;
//        }
    
    cin >> N >> A >> B >> C >> D;
    string S;
//        S = "";
//        for (int i = 1; i <= N; i++) {
//            S.push_back((arc4random() % (6 + N % 5)) == 0 ? '#' : '.');
//        }
        cin >> S;
//        S[A-1] = 'A';
//        S[B-1] = 'B';
//        S[C-1] = 'C';
//        S[D-1] = 'D';
//        cout << S << endl;

    vector<int> passPoints;
    int Abegin = A, Bbegin = B, Aend = N, Bend = N;
    int blockLength = 0;
    bool isLastBlocked = false;
    for (int i = 1; i <= N; i++) {
        if (S[i-1] == '#') {
            blockLength += 1;
            isLastBlocked = true;
            
            if (Aend == N && blockLength == 2 && i > A) {
                Aend = i - 2;
            }
            if (Bend == N && blockLength == 2 && i > B) {
                Bend = i - 2;
            }
        } else {
            if (i <= A && blockLength >= 2) {
                Abegin = i;
            }
            if (i <= B && blockLength >= 2) {
                Bbegin = i;
            }
            isLastBlocked = false;
            blockLength = 0;
        }
    }
    bool OK = Abegin <= C && C <= Aend && Bbegin <= D && D <= Bend;
//    cout << Abegin << "<=" << C << "<=" << Aend << endl;
//    cout << Bbegin << "<=" << D << "<=" << Bend << endl;
    if (OK && D < C) {
        int safeLength = 0;
        bool isLastSafe = false;
        bool canPass = false;
        for (int i = Bbegin - 1; i <= Bend; i++) {
            if (S[i-1] != '#') {
                safeLength += 1;
                isLastSafe = true;
                
                if (safeLength == 3) {
                    canPass = true;
//                    cout << "can pass at " << i-2 << " to " << i << endl;
                    break;
                }
            } else {
                safeLength = 0;
                isLastSafe = false;
            }
            if (i > D) {
//                cout << "breaking at " << i << endl;
                break;
            }
        }
        OK = OK & canPass;
//        cout << "can pass: " << canPass << endl;
    }
    cout << (OK ? "Yes" : "No") << endl;
//    }
    return 0;
}


Measured memory_bytes: 576
n = int(input())
S = sorted([int(input()) for i in range(n)])

if sum(S) % 10 != 0:
    print(sum(S))
else:
    ans = []
    for s in S:
        if (sum(S)-s) % 10 == 0:
            ans.append(0)
        else:
            ans.append(sum(S)-s)
            break
    print(max(ans))


Measured memory_bytes: 2940
#include<stdio.h>

int main(void){
  int score[5]={},ave=0;

  for(int i=0;i<5;i++){
    scanf("%d",&score[i]);
    if(score[i]<40) score[i]=40;
    ave+=score[i];
  }
  printf("%d\n",ave/5);
  return 0;
}



Measured memory_bytes: 2136
#include<stdio.h>
int main(){
  int n,i;
  double sum =0;
  scanf("%d",&n);
  double x[n];
  char u[3][n];

  for(i=0;i<n;i++){
    scanf("%lf %c %c %c",&x[i],&u[0][i],&u[1][i],&u[2][i]);
    if(u[0][i]=='B'){
      x[i] = x[i]  * 380000.0;
    }
  }
  for(i=0;i<n;i++){
    sum += x[i];
  }
  printf("%f",sum);

  return 0;
}


Measured memory_bytes: 128
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    int x, n;
    cin >> x >> n;
    // if(n == 0){
    //     cout << x << endl;
    //     return 0;
    // }
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ma = 1e9;
    int ans = -1;
    for(int i = -1; i <= 101; i++){
        bool ok = true;
        rep(j, n){
            if(a[j] == i){
                ok = false;
                break;
            }
        }
        if(ok){
            if(ma > abs(x - i)){
                ans = i;
                ma = abs(x - i);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
import sys
input = sys.stdin.readline

a, b, c = map(int, input().split())
n_a, n_b, n_c = 0, 0, 0
ans = 0

if a == b == c and a % 2 == 0:
    print(-1)
    exit()

elif a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    for i in range(10 ** 5):
        n_a = b // 2 + c // 2
        n_b = a // 2 + c // 2
        n_c = a // 2 + b // 2

        if n_a % 2 == 0 and n_b % 2 == 0 and n_c % 2 == 0:
            ans += 1
        else:
            ans += 1
            break

        a = n_a
        b = n_b
        c = n_c

print(ans)


Measured memory_bytes: 3064
var lines = []; var result = "";
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var s = lines[0].split("");
    var K = Number(lines[1]);
    var len = s.length;

    var s_code = Array(len).fill(0)
    for (var i = 0; i < len; i++) {
        s_code[i] = s[i].charCodeAt(0);
    }

    for (var i = 0; i < len; i++) {
        if (i === len - 1) {
            K = K % 26;
            s_code[i] + K > "z".charCodeAt(0) ? s_code[i] = 97 + s_code[i] + K - "z".charCodeAt(0) - 1 : s_code[i] += K;
        }
        else {
            if ("z".charCodeAt(0) - s_code[i] + 1 <= K && s_code[i] !== "a".charCodeAt(0)) { K -= "z".charCodeAt(0) - s_code[i] + 1; s_code[i] = "a".charCodeAt(0); }
        }
        if (K <= 0) { break };
    }

    for (var i = 0; i < len; i++) {
        result += String.fromCharCode(s_code[i]);
    }
    console.log(result);
});

Measured memory_bytes: 15692
#include<iostream>
#include<iostream>
#include<string>
using namespace std;
string s;
long long k;

int main(){
        cin>>s>>k;
        bool f=0;
        int c=0;
        for(int i=0;i<s.size();i++){
                if(s[i]!='1')break;
                c++;
        }
        if(c>=k){
                cout<<1<<endl;
                return 0;
        }

        int ans=0;
        for(int i=0;i<s.size();i++){
                if(s[i]!='1'){
                        cout<<s[i]<<endl;
                        return 0;
                }
        }
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
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 main(){
    int n,W;cin>>n>>W;
    vl w(n),v(n);
    rep(i,n)cin>>w[i]>>v[i];
    vector<vl> dp(n+1,vl(W+1,0));
    rep(i,n){
        rep(j,W+1){
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            if(j+w[i]<=W)dp[i+1][j+w[i]]=max(dp[i+1][j+w[i]],dp[i][j]+v[i]);
        }
    }
    ll ans=0;
    rep(i,W+1)chmax(ans,dp[n][i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

const int INF = 1 << 29;
typedef pair<int, int> P;

int n, k;

int compress(vector<int>& vec1, vector<int>& vec2, vector<int>& tmp)
{
	for (int i = 0; i < n; i++)
	{
		tmp.push_back(vec1[i]);
		tmp.push_back(vec2[i]);
	}

	sort(tmp.begin(), tmp.end());
	tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());

	for (int i = 0; i < n; i++)
	{
		vec1[i] = find(tmp.begin(), tmp.end(), vec1[i]) - tmp.begin();
		vec2[i] = find(tmp.begin(), tmp.end(), vec2[i]) - tmp.begin();
	}

	return tmp.size();
}

int main(void)
{
	while(cin >> n >> k && n && k)
	{
		vector<int> x1, y1, d1, x2, y2, d2;
		x1.resize(n); y1.resize(n); d1.resize(n); x2.resize(n); y2.resize(n); d2.resize(n);
		for (int i = 0; i < n; i++)
		{
			cin >> x1[i] >> y1[i] >> d1[i] >> x2[i] >> y2[i] >> d2[i];
		}
		vector<int> cx; int w = compress(x1, x2, cx);
		vector<int> cy; int h = compress(y1, y2, cy);
		vector<int> cd; int d = compress(d1, d2, cd);

		long long ans = 0;
		for (int x = 0; x < w - 1; x++)
		{
			for (int y = 0; y < h - 1; y++)
			{
				for (int z = 0; z < d - 1; z++)
				{
					int count = 0;
					for (int i = 0; i < n; i++)
					{
						if(x1[i] <= x && x + 1 <= x2[i] && y1[i] <= y && y + 1 <= y2[i] && d1[i] <= z && z + 1 <= d2[i])
							count++;
					}
					if(count >= k)
						ans += (long long)(cx[x + 1] - cx[x]) * (long long)(cy[y + 1] - cy[y]) * (long long)(cd[z + 1] - cd[z]);
				}
			}
		}

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

Measured memory_bytes: 1220
function main(input) {
  const inputs = input.split('\n')
  const [N, K] = inputs[0].split(' ').map(BigInt)
  const r = N % K
  if (K < 2n * r) {
    console.log(String(K - r))
  } else {
    console.log(String(r))
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 29424
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let n=read::<u32>();
    let k=read::<u32>();
    println!("{}",k*(k-1).pow(n-1))
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};

//ll mod = 1000000009;

const int MAX = 510000;
const int 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 (int 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(int n, int 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() {
    int k, t; cin >> k >> t;
    vector<int> a(t),h(k);
    rep(i,t) cin >> a[i];
    sort(a.rbegin(),a.rend());

    int MAX = a[0], m;

    if(k%2!=0) m = k / 2 + 1;
    else m = k / 2;

    if(m>=MAX) cout << 0 << endl;
    else cout << 2 *((MAX - m) - 1) + 1 << endl;
}




Measured memory_bytes: 3564
s = str(input())
q = int(input())

for i in range(q):
	arr = list(map(str, input().split()))
	c = arr[0]
	n1 = int(arr[1])
	n2 = int(arr[2])

	if c == 'print':
		print(s[n1:n2 + 1])
	if c == 'replace':
		s = s[0:n1] + arr[3] + s[n2 + 1:len(s)]
	if c == 'reverse':
		l = n2 - n1 + 1
		reverse = ''
		for i in range(l):
			reverse += s[n2 - i]
		s = s[0:n1] + reverse + s[n2 + 1:len(s)]



Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int x;
    cin>>x;
    int c=1;
    int y[x+1];
    for (int i=1;i<=x;i++){
        cin>>y[i];
    }
    for (int i=1;i<=x;i++){
        if (y[i]==c)
            c++;
    }
    cout<<(c==1?-1:x-c+1)<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
        }
        int ans = (n + k - 3) / (k - 1);
        System.out.println(ans);
    }
}

Measured memory_bytes: 48476
# 2019/12/1

n=int(input())
s=list(input())

fst=[]
tmp=set()
for i in range(n):
    tmp.add(s[i])
    fst.append(list(tmp))

trd=[]
tmp=set()
for i in range(n):
    tmp.add(s[n-1-i])
    trd.append(list(tmp))
trd=trd[::-1]
cnt=set()
for i in range(1,n-1):
    for f in fst[i-1]:
        for t in trd[i+1]:
            cnt.add(f+s[i]+t)
print(len(cnt))

Measured memory_bytes: 16116
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009
#define MOD MOD7

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

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

int minV[100003], maxV[100003];

signed main() {
	int N;
	cin >> N;

	vector<int> T, A;
	inputVector(T, N);
	inputVector(A, N);

	T.insert(T.begin(), 0);
	T.push_back(0);
	A.insert(A.begin(), 0);
	A.push_back(0);

	for (int i = 1; i <= N; i++) {
		if (T[i] > T[i - 1]) {
			minV[i] = T[i];
			maxV[i] = T[i];
		} else {
			minV[i] = 1;
			maxV[i] = T[i];
		}
	}

	for (int i = N; i > 0; i--) {
		if (A[i] > A[i + 1]) {
			if (A[i] < minV[i] || A[i] > maxV[i]) {
				cout << 0 << endl;
				return 0;
			}
			minV[i] = A[i];
			maxV[i] = A[i];
		} else {
			if (minV[i] > A[i]) {
				cout << 0 << endl;
				return 0;
			}
			minV[i] = max(1LL, minV[i]);
			maxV[i] = min(A[i], maxV[i]);
		}
	}

	int ret = 1;
	for (int i = 1; i <= N; i++) {
		ret *= maxV[i] - minV[i] + 1;
		ret %= MOD;
	}

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3572
PROGRAM DAYDREAM
    IMPLICIT NONE
    CHARACTER(100000) S, SUBS
    INTEGER L
    READ(*, *) S
    L = LEN(TRIM(S))
    DO
        IF(L .EQ. 0) THEN
            WRITE(*, '(A)') 'YES'
            STOP
        ELSE IF(L .LT. 0) THEN
            WRITE(*, '(A)') 'NO'
            STOP
        ELSE IF(S(L - 4: L) == 'dream') THEN
            L = L - 5
        ELSE IF(S(L - 6: L) == 'dreamer') THEN
            L = L - 7
        ELSE IF(S(L - 4: L) == 'erase') THEN
            L = L - 5
        ELSE IF(S(L - 5: L) == 'eraser') THEN
            L = L - 6
        ELSE
            WRITE(*, '(A)') 'NO'
            STOP
        ENDIF
    ENDDO
    STOP
END PROGRAM DAYDREAM


Measured memory_bytes: 700
#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
int n, m, q, mod;
int gcd=0,a[N],b[N],c[N],fa[N];
inline int gf(int u){
	return fa[u]==u?u:fa[u]=gf(fa[u]);
}
inline void merge(int u,int v){
	u=gf(u), v=gf(v);
	if(u!=v)fa[u]=v;
}
inline int id(int x, int y, int z){
	return (x-1)*6+y*3+z;
}
bool vis[2][N];
int main(){
	scanf("%d%d%d%d",&n,&m,&q,&mod);
	for(int i=1; i<=m; ++i){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		gcd=__gcd(gcd,abs(c[i]-c[1]));
	}
	if(!gcd)gcd=mod; mod=__gcd(3*gcd,mod);
	int z=c[1]%gcd;
	for(int i=0;i<=6*n;++i)fa[i]=i;
	for(int i=1;i<=m;++i){
		int w=(c[i]-z)/gcd;
		for(int x=0;x<=1;++x)
			for(int y=0;y<=2;++y){
				merge(id(a[i],x,y),id(b[i],1-x,(2*y+w)%3));
				merge(id(b[i],x,y),id(a[i],1-x,(2*y+w)%3));
			}
	}
	for(int i=0,j=z; i<(mod<<1);++i,(j<<=1)%=mod)vis[i&1][j]=1;
	while(q--){
		int s,t,r; scanf("%d%d%d",&s,&t,&r);
		int res=0;
		for(int i=0;i<=1;++i)
			for(int j=0;j<=2;++j)
				if(gf(id(t,0,0))==gf(id(s,i,j)))
					res|=vis[i][(r+z+(3-j)*gcd)%mod];
		puts(res?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD=1000000007;

int main() {
    string S; cin>>S;
    ll ans=0;
    for(int bit=0;bit<(1<<S.size()-1);bit++){
        ll now=0;
        for(int i=0;i<S.size();i++){
            now=now*10+S[i]-'0';
            if(bit & (1<<(S.size()-2-i))){
                ans+=now;
                now=0;
            }
        }
        ans+=now;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool ask(int a,int b){
	cout <<"? "<<a <<' '<<b <<endl;
	char c;	cin >> c;
	return c == 'Y';
}
bool ans[4000];
main() {
	int A,B;
	cin >> A >> B;
	if (A <= B) {
		cout << "Impossible" << endl;
		return 0;
	}
	int n = A+B;
	stack<int> s;
	for (int i = 0; i < n; i++) {
		if (!s.size())  s.push(i);
		else {
			int v = s.top();
			if (ask(v,i)) 
				s.push(i);
			else s.pop();
		}
	}
	int cool = s.top();
	for (int i = 0; i < n; i++) {
		ans[i] = ask(cool,i);
	}
	cout <<"! ";
	for (int i = 0 ; i <  n; i++)
		cout << ans[i];
	cout <<endl;
	return 0;
}

Measured memory_bytes: 724
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
bool prime[MAX_N];
int S[MAX_N];

void solve() {
	fill(prime, prime + 100000, true);
	prime[1] = false;
	for(int i = 2; i <= 100000; i++) {
		if(!prime[i]) continue;
		for(int j = i * 2; j <= 100000; j += i) {
			prime[j] = false;
		}
	}
	for(int i = 3; i <= 100000; i += 2) {
		if(prime[i] && prime[(i + 1) / 2]) {
			S[i]++;
		}
	}
	for(int i = 3; i <= 100000; i++) {
		S[i] += S[i - 1];
	}
	int Q;
	cin >> Q;
	while(Q--) {
		int l, r;
		cin >> l >> r; l--;
		cout << S[r] - S[l] << "\n";
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    rep(i, 365) {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 3632
# r:グー　s:ちょき　p:パー
n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = input()
point = {"r":p, "s":r, "p":s}
d = {"r":"p", "s":"r", "p":"s"}

janken = []
score = 0
for i in range(n):
  if len(janken) < k or d[t[i]]!=janken[-k]:
    score += point[t[i]]
    janken.append(d[t[i]])
  else:
    janken.append("")
print(score)

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

int main()
{
    int H,W;
    cin>>H>>W;
    char arr[H][W];
    for(int i=0;i<H;i++)
    {
        for(int j=0;j<W;j++)
        {
            cin>>arr[i][j];
        }
    }
    long long int dp[H][W];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<W;i++)
    {
        if(arr[0][i]=='.')
        {
            dp[0][i]=1;
        }
        else
        {
            break;
        }
    }
     for(int i=0;i<H;i++)
    {
        if(arr[i][0]=='.')
        {
            dp[i][0]=1;
        }
        else
        {
            break;
        }
    }
    for(int i=1;i<H;i++)
    {
        for(int j=1;j<W;j++)
        {
            if(arr[i][j]=='.')
            {
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%(long long int)(1e9+7);
                dp[i][j]%=(long long int)(1e9+7);
            }
            else
            {
                dp[i][j]=0;
            }
        }
    }
    cout<<dp[H-1][W-1];
    return 0;
}

Measured memory_bytes: 12432
import java.util.Scanner;

public class Main
{
	private static class Node
	{
		public Node l, r;
		public Node(Node l_, Node r_) { l = l_; r = r_; }
	}
	
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		for(;sc.hasNext();)
		{
			char type = sc.next().charAt(0);
			String x = sc.next();
			String y = sc.next();
			
			pos = 0;
			Node nx = makeNode(x);
			
			pos = 0;
			Node ny = makeNode(y);
			
			System.out.println(toString(type == 'u' ? union(nx, ny) : intersect(nx, ny)));
		}
	}
	
	private static int pos;
	private static Node makeNode(String s)
	{
		Node node = new Node(null, null);
		
		if (s.charAt(pos) == '(') pos++;
		
		if (s.charAt(pos) == '(')
		{
			node.l = makeNode(s);
		}
		
		if (s.charAt(pos) == ',') pos++;
		
		if (s.charAt(pos) == '(')
		{
			node.r = makeNode(s);
		}
		
		if (s.charAt(pos) == ')') pos++;
		
		return node;
	}
	
	private static Node union(Node x, Node y)
	{
		if (x == null)
		{
			return y;
		}
		else if (y == null)
		{
			return x;
		}
		return new Node(union(x.l, y.l), union(x.r, y.r));
	}
	
	private static Node intersect(Node x, Node y)
	{
		if (x == null || y == null)
		{
			return null;
		}
		return new Node(intersect(x.l, y.l), intersect(x.r, y.r));
	}
	
	private static String toString(Node node)
	{
		return node == null ? "" : "(" + toString(node.l) + "," + toString(node.r) + ")";
	}
}

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//切り上げ除算
long long cutup(long long a,long long b){return (a+b-1)/b;}

//累乗
template<typename t>
constexpr t my_pow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
    }
    return x;
}
#define pow my_pow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,k;
    cin>>n>>k;
    vl h(n);
    rep(i,n)cin>>h[i];
    sort(all(h));
    ll res=INF;
    rep(i,n-k+1){
        chmin(res,h[i+k-1]-h[i]);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3964
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,D=map(int,input().split())
ans=0
for _ in range(N):
    x,y=map(int,input().split())
    if x**2+y**2<=D**2:
        ans+=1
print(ans)

Measured memory_bytes: 68664
/*  chuckie   */
#include <bits/stdc++.h>
//#define CHUCKIE

 
#define cint(d) scanf("%d", &d)
#define cint2(a, b) scanf("%d %d", &a, &b)
#define cint3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define cint4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
 
#define clong(d) scanf("%lld", &d)
#define clong2(a, b) scanf("%lld %lld", &a, &b)
#define clong3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define clong4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
 
const long long MOD = 1000000007;
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODR(d) ((d)>=MOD?(d)%MOD:(d))
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define MODADDSET(d) if ((d) >= MOD) d -= MOD;
#define MODADDWHILESET(d) while ((d) >= MOD) d -= MOD;
 
#define foreach(it,c) for(__typeof((c).begin()) it = (c).begin(); it!=(c).end(); it++) 
#define MAX 1000000
#define ll long long
#define mp make_pair
#define pb push_back
 
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;


int gcd(int a, int b)
{
    return (a%b == 0)? abs(b) : gcd(b,a%b);
}

int main()
{
	
	#ifdef CHUCKIE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a ,b,c;
	cin>>a>>b>>c;
	
	int x =a%b;

	
	
	if(x==0)
	{
		if(c==0)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		
		return 0;
	}
	
	int g=gcd(x,b);
	if((c+g)%g==0)
	{
		cout<<"YES"<<endl;
	}
	
	
	else
	{
		cout<<"NO"<<endl;
		
	}
	
	
	
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)

import itertools as its
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
def worstdata():
    a=0
    return a
#solution:
def comp(p):#期待値
    return ((p+1)/2)


#input
n,k=(pin())
S=list(pin())
debug(S)
s=([comp(S[_]) for _ in range(n)])
ans=0
#print(s)
x=list(its.accumulate(s))
#print(list(its.accumulate(s)))
#default
for a in range(k):
    ans=x[k-1]
#print("*",ans,0,k-1)
temp=0.0
for i in range(1,n-k+1):
    
    ans=max(ans,x[k+i-1]-x[i-1])
print(ans)
#print(["NO","YES"][1-cond])



Measured memory_bytes: 120524
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let a: i32 = sc.next();
    let b: i32 = sc.next();
    println!("{}", std::cmp::max(0, a - b * 2));
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn char(&mut self) -> char {
        self.next::<String>().chars().next().unwrap()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <utility>
#include <map>
using namespace std;

struct unionFind{
	vector<int> par;
	unionFind(int n) : par(n) {
		for(int i=0; i < n; i++){
			par[i] = i;
		}
	}
	int root(int x) {
		if(par[x] == x) return x;
		else return par[x] = root(par[x]);
	}
	bool isSame(int x, int y){
		return root(x) == root(y);
	}
	void merge(int x, int y){
		x = root(x);
		y = root(y);
		if(x == y) return;
		else{
			par[x] = y;
		}
	}
};

int main(){
	int n, k, l;
	cin >> n >> k >> l;
	unionFind road(n);
	unionFind rail(n);
	int a, b;
	for(int i=0; i<k; i++){
		cin >> a >> b;
		road.merge(--a, --b);
	}
	for(int i=0; i<l; i++){
		cin >> a >> b;
		rail.merge(--a, --b);
	}
	using pint = pair<int,int>;
	map<pint, int> m;
	for(int i=0; i<n; i++){
		pint p(road.root(i), rail.root(i));
		m[p]++;
	}
	for(int i=0; i<n; i++){
		pint p(road.root(i), rail.root(i));
		cout << m[p] << " ";
	}
	return 0;
}



Measured memory_bytes: 13568
#include<iostream>
using namespace std;
int main(){
	int ans[10];
	int sum=0;
	int other=0;
	int a=0;
	int i=0;
	int j=0;
	
	while(1){
		cin>>sum;
		if(sum==0)break;
		for(i=0;i<9;i++){
			cin>>a;
			other+=a;
		}
		ans[j]=sum-other;
		sum=0;
		other=0;
		a=0;
		j++;
	}
	
	for(i=0;i<j;i++){
		cout<<ans[i]<<endl;
	}
}
	



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

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int miniute = (h2-h1)*60 + (m2-m1);
    cout << miniute - k << endl;
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int r,c,vo[100][100],to,ko=0;
    cin>>r>>c;
    for(int i=0;i<r;i++){
        for(int o=0;o<c;o++){
            cin>>vo[i][o];
        }
    }
    for(int i=0;i<r;i++){
        to=0;
        for(int o=0;o<c;o++){
            to=to+vo[i][o];
            cout<<vo[i][o]<<" ";
        }
        ko=ko+to;
        cout<<to<<endl;
    }
    for(int i=0;i<c;i++){
        to=0;
        for(int o=0;o<r;o++){
            to=to+vo[o][i];
        }
        cout<<to<<" ";
    }
    cout<<ko<<endl;
    
}



Measured memory_bytes: 3088
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	k := intScanner()
	ans := make([]bool, n)
	for i := 0; i < k; i++ {
		d := intScanner()
		for j := 0; j < d; j++ {
			a := intScanner()
			ans[a-1] = true
		}
	}
	x := 0
	for _, b := range ans {
		if !b {
			x++
		}
	}
	fmt.Println(x)
}


Measured memory_bytes: 1776
#!/usr/bin/env python3
import sys
from itertools import chain

# from itertools import combinations as comb
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(X: int, Y: int):
    if Y % 2 == 1:
        return NO
    if Y > X * 4:
        return NO
    if Y < X * 2:
        return NO
    return YES


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    answer = solve(X, Y)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9160
def main():
    l = list(map(int,input().split(" ")))
    N = l[0]
    Y = l[1]
    c1 = N
    c2 = 0
    c3 = 0
    if Y>N*10000 or Y<N*1000:
        print(-1,-1,-1)
        exit()
    while c1>=0:
        tar1 = Y-c1*10000
        c2 = N-c1
        while c2>=0:
            tar2 = tar1-c2*5000
            c3 = N-c2-c1
            tar3 = tar2-c3*1000
            if tar3==0:
                print(c1,c2,c3)
                exit()
            c2-=1
        c1-=1
    print(-1,-1,-1)

if __name__=="__main__":
    main()

Measured memory_bytes: 3188
//Problem B
#include<bits/stdc++.h>
using namespace std;
const int N=400005;
int n,m,cnt,tot,dfn[N],low[N],st[N],tp,in[N];
char ch[N];
vector<int>e[N],E[N];
void tarjan(int v){
    dfn[v]=low[v]=++cnt;
    st[++tp]=v,in[v]=1;
    for(int i=0;i<(int)E[v].size();i++){
        int u=E[v][i];
        if(!dfn[u])tarjan(u),low[v]=min(low[v],low[u]);
        else if(in[u])low[v]=min(low[v],dfn[u]);
    }
    if(dfn[v]==low[v]){
        ++tot;int lust=0;
        while(lust!=v)lust=st[tp--],in[lust]=0;
    }
}
int main(){
    scanf("%d%d%s",&n,&m,ch+1);
    while(m--){
        int a,b;
        scanf("%d%d",&a,&b);
        e[a].push_back(b),e[b].push_back(a);
        if(ch[a]==ch[b])E[a].push_back(b+n),E[b].push_back(a+n);
        else E[a+n].push_back(b),E[b+n].push_back(a);
    }
    n<<=1;
    for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
    if(tot==n)printf("No");else printf("Yes");
    //for(int i=1;i<=n;i++)for(int j=0;j<2;j++)if(!vis[i][j]){printf("try %d %d\n",i,j);
    //    ++cnt;if(dfs(i,j)){printf("Yes");for(int i=1;i<=n;i++){for(int j=0;j<2;j++)printf("%d ",vis[i][j]);printf("\n");}return 0;}
    //}printf("No");
    return 0;
}

Measured memory_bytes: 49792
#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int A, B;

int main()
{
  scanf( "%d%d", &A, &B );

  printf( "%d\n", A>=13?B:A>=6&&A<=12?B/2:0 );

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a[4],b[4];
	int ad=0;
	for(int i=0;i<4;i++){
		cin>>a[i];
		ad+=a[i];
	}
	int bd=0;
	for(int j=0;j<4;j++){
		cin>>b[j];
		bd+=b[j];
	}
	if(ad>=bd)
		cout<<ad<<endl;
	else
		cout<<bd<<endl;
	return 0;
}

Measured memory_bytes: 1160
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	X := sc.nextInt()
	if X == 7 || X == 5 || X == 3 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

min_val = -1
for i in range(-1000, 1000):
    if i in P:
        continue
    if abs(min_val - X) > abs(X - i):
        min_val = i
if len(P) == 0:
    print(X)
else:
    print(min_val)


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

using namespace std;


void solve1() {
	int N;
	vector<int> L;
	cin >> N;
	for (int i = 0; i < N*2; i++)
	{
		int l;
		cin >> l;
		L.push_back(l);
	}

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

	int ans = 0;
	for (int i = 0; i < 2*N-1; i+=2)
	{
		ans += min(L[i], L[i + 1]);
	}
	cout << ans << endl;
}



int main() {
	solve1();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
char isprime[1024];
int prime[1024];
int counts[1024];
int mod = 1e9 + 7;
typedef long long ll;
//#define LOCAL
int main(int argc, char *argv[]) {
	int N;
	int index = 0;
	memset(isprime, 1, sizeof(isprime));
	
	for(int i = 2; i <= 1010; ++i) {
		if(isprime[i]) {
			prime[index++] = i;
			for(int j = i + i; j <= 1010; j += i)
				isprime[j] = 0;
			#ifdef LOCAL 
			cout << i << " ";
			#endif
		}
	}
	
	while(cin >> N) {
		memset(counts, 0, sizeof(counts));
		
		for(int i = 2; i <= N; ++i) {
			int m = i;
			for(int j = 0; m && j < index; j++) {
				while(m % prime[j] == 0) {
					counts[j] += 1;
					m = m / prime[j];

				}
			}
		}
		
		ll ans = 1;
		for(int i = 0; i < index; i++) {
			#ifdef LOCAL 
				cout << counts[i] << " ";
			#endif

			if(counts[i] > 0)
				ans = (ans * (counts[i] + 1)) % mod;
		}
		cout << ans << endl;
	}
}

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

int main(){
    int a;
    int b;
    int c;
    int x;
    int y;
    int z;

    cin >> x >> y >> z;

    a = z;
    b = x;
    c = y;

    cout << a << " " << b << " " << c << endl;

}

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

int main () 
{ 
int n;cin>>n;
  while(n>0){
    if(n%10==7){
    cout<<"Yes";return 0;
    }
    n=n/10;
  }
  cout<<"No";
	return 0; 
} 


Measured memory_bytes: 3596