akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{

    int e, y;

    scanf("%d %d", &e, &y);

    if(e == 0) {
        if(y >= 1868 && y <= 1911)
            printf("M%d\n", y - 1867);
        else if(y >= 1912 && y <= 1925)
            printf("T%d\n", y - 1911);
        else if(y >= 1926 && y <= 1988)
            printf("S%d\n", y - 1925);
        else if(y >= 1989 && y <= 2016)
            printf("H%d\n", y - 1988);
    }
    else if(e == 1)
        printf("%d\n", 1867 + y);
    else if(e == 2)
        printf("%d\n", 1911 + y);
    else if(e == 3)
        printf("%d\n", 1925 + y);
    else if(e == 4)
        printf("%d\n", 1988 + y);

    return 0;
}
    

Measured memory_bytes: 596
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

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

//逆元を求める関数
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;
}

void solve() {
	int n; cin >> n;
	vector<int> c(n - 1), s(n - 1), f(n - 1);
	for (int i = 0; i < (n - 1); ++i) {
		cin >> c[i] >> s[i] >> f[i];
	}
	for (int i = 0; i < n - 1; ++i) {
		//開通式後に最初の駅で乗車
		int require_t = s[i] + c[i];
		for (int j = i + 1; j < (n - 1); ++j) {
			//次の駅の開通式前に到着した場合は開通式終了まで待機
			if (require_t < s[j]) {
				require_t += (s[j] - require_t);
			} else {
				//次の駅の開通式後に到着した場合は電車の出発時間(fで割り切れる時間)まで待機
				if (require_t % f[j] != 0) {
					require_t += (f[j] - (require_t % f[j]));
				}
			}
			//次の駅に向かう時間を加算
			require_t += c[j];
		}
		cout << require_t << endl;
	}
	//最終駅は0を出力
	cout << 0 << endl;
    return;
}

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



Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#include<string>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define nax (int)1e6+3
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// look for  all edge cases
//search for a pattern
		



signed main(){
	int n;
	cin >> n;
	vector<int> v(n);
	
	int val = 0;
	
	for(int i = 0 ; i <n ;i++){
		cin >> v[i];
		val ^= v[i];
	}
	
	for(int i =0 ; i < n ;i++){
		cout<<(v[i]^val)<<" ";
	}
	
	
	return 0;
}

	



Measured memory_bytes: 4840
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
using namespace std;
//typedef std::pair<std::string,double> P;

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

typedef long long ll;
typedef vector<int> VI;

struct Less {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};
//グラフの隣接リスト
//VI g[200010];
//頂点の入次数を管理
int h[100010];

int g[101][101];

int v[110], w[110];
int dp[110][10100];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, W; cin >> N >> W;

	REP(i, N) cin >> v[i] >> w[i];

	for (int i = 0; i < 110; ++i) {
		for (int j = 0; j < 10100; ++j) {
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j <= W; ++j) {
			if (j - w[i] >= 0) dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			else dp[i + 1][j] = dp[i][j];
		}
	}

	cout << dp[N][W] << endl;
	return 0;
}


Measured memory_bytes: 7540
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N, K;
  cin >> N >> K;
  ll mod = N % K;
  ll ans = min(mod, abs(mod - K));

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


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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;
const ll mod = 1e9+7;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  int n;  cin >> n;
  ll a[n];
  for (int i = 0; i < n; ++i){
    cin >> a[i];
  }
  ll pref[n+1];
  pref[0] = 0;
  for (int i = 0; i < n; ++i){
    pref[i+1] = pref[i] + a[i];
    pref[i+1] %= mod;
  }
  ll ans = 0;
  for (int i = 1; i < n; ++i){
    ans += pref[i]*a[i]%mod;
    ans %= mod;
  }

  cout << ans%mod << endl;

  return 0;
}

Measured memory_bytes: 6772
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (0 until n).map {
        (0 until sc.next().toInt()).map {
            sc.next().toInt() - 1 to sc.next().toInt()
        }
    }
    println(problem147c(n, a))
}

fun problem147c(
    n: Int,
    a: List<List<Pair<Int, Int>>>
): Int {
    fun judge(bit: Int): Boolean {
        for (i in 0 until n) {
            if (bit and (1 shl i) == 0) continue
            for (xy in a[i]) {
                val (x, y) = xy
                if (y == 1 && bit and (1 shl x) == 0) return false
                if (y == 0 && bit and (1 shl x) != 0) return false
            }
        }
        return true
    }

    var res = 0
    var bit = 0
    while(bit < (1 shl n)) {
        if (judge(bit)) {
            var count = 0
            for (i in 0 until n) {
                if (bit and (1 shl i) != 0) count++
            }
            res = Math.max(res, count)
        }
        bit++
    }
    return res
}

Measured memory_bytes: 36436
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n;
ll x[225816],segtree[816225][2];
P v[225816];
bool delayed[816225];

void init(int i=0, int l=0, int r=n){
	if(r-l>1){
		init(i*2+1,l,(l+r)/2);
		init(i*2+2,(l+r)/2,r);
		segtree[i][0] = segtree[i*2+1][0] + segtree[i*2+2][0];
	}else{
		segtree[i][0] = v[l].second;
	}
}

void eval(int i, int l, int r){
	if(delayed[i]){
		segtree[i][0] += segtree[i][1]*(r-l);
		if(r-l>1){
			segtree[i*2+1][1] += segtree[i][1];
			segtree[i*2+2][1] += segtree[i][1];
			delayed[i*2+1] = true;
			delayed[i*2+2] = true;
		}
		segtree[i][1] = 0ll;
		delayed[i] = false;
	}
}

void update(int a, int b, ll v, int i=0, int l=0, int r=n){
	eval(i,l,r);
	if(b<=l || r<=a){
		return;
	}else if(a<=l && r<=b){
		segtree[i][1] += v;
		delayed[i] = true;
		eval(i,l,r);
	}else{
		update(a,b,v,i*2+1,l,(l+r)/2);
		update(a,b,v,i*2+2,(l+r)/2,r);
		segtree[i][0] = segtree[i*2+1][0] + segtree[i*2+2][0];
	}
}

ll query(int a, int b, int i=0, int l=0, int r=n){
	eval(i,l,r);
	if(b<=l || r<=a){
		return 0ll;
	}else if(a<=l && r<=b){
		return segtree[i][0];
	}else{
		return query(a,b,i*2+1,l,(l+r)/2)+query(a,b,i*2+2,(l+r)/2,r);
	}
}

int main(void){
	int i,d,j;
	ll h,ans=0ll,a,t;
	cin >> n >> d >> a;
	for(i=0; i<n; ++i){
		cin >> x[i] >> h;
		v[i] = P(x[i],h);
	}
	sort(x,x+n); sort(v,v+n);
	init();
	for(i=0; i<n; ++i){
		j = (int)(upper_bound(x,x+n,x[i]+d*2)-x);
		h = max(0ll,query(i,i+1));
		t = (h?((h-1)/a+1):0ll);
		ans += t;
		update(i,j,-a*t);
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

bool U[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    ll R, S, P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
    ll ans = 0;
    REP(i, N) {
        if (i >= K) {
            if (T[i] == T[i - K] && U[i - K])
                continue;
        }
        if (T[i] == 'r')
            ans += P;
        else if (T[i] == 's')
            ans += R;
        else
            ans += S;
        U[i] = true;

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

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

int main() {
  int x, n; cin >> x >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  
  sort(p.begin(), p.end());
  int l = 0;
  int ans;
  while (true) {
    bool is_ans = true;
    for (int i = 0; i < n; i++) {
      if (x - l == p[i]) is_ans = false;
    }
    if (is_ans) {
      ans = x - l;
      break;
    }
    
    is_ans = true;
    for (int i = 0; i < n; i++) {
      if (x + l == p[i]) is_ans = false;
    }
    if (is_ans) {
      ans = x + l;
      break;
    }
    l++;
  }
  cout << ans << endl;
}

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

int main(){
  int N, sum = 0, tmp;
  cin >> N;
  tmp = N;
  while(true){
    
    sum = sum + N % 10;
    N = N / 10;
    if(N == 0) break;
  }
  if(tmp % sum == 0){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    string s1,s2;
    int f=0;
    int n=s.length();
     for(int i=0,j=n-1;i<((n+1)/2 -1);i++,j--){
        if(s[i]==s[j])
            continue;
        else{
    
            f=1;
        }
    }

    for(int i=0,j=(n+1)/2 -2;i<((n+1)/2 -1)/2;i++,j--){
        if(s[i]==s[j])
            continue;
        else{
    
            f=1;
        }
    }
    for(int j=(n+3)/2 -1,i=n-1;j<((n+3)/2 -1)/2;j++,i--){
        if(s[i]==s[j])
            continue;
        else
            f=1;
    }
    if(f==1)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;

}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> l(Q), r(Q);
  REP(i, Q) {
    cin >> l[i] >> r[i]; --l[i]; --r[i];
  }

  vector<int> A(N, 0);
  REP(i, N - 1) {
    if((S[i] == 'A') && (S[i + 1] == 'C')) A[i] = 1;
  }
  vector<int> cum(N + 1, 0);
  REP(i, N) cum[i + 1] = cum[i] + A[i];

  REP(i, Q) {
    int ret = cum[r[i]] - cum[l[i]];
    cout << ret << endl;
  }
  return 0;
}



Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    veci prime(55560);
    for(int i = 2; i <= 55555; i++) {
        for(int j = i; j <= 55555; j += i) {
            prime[j]++;
        }
    }
    veci ans;
    for(int k = 1; 5*k-2 <= 55555; k++) {
        //if(prime[5*k-4] == 1) ans.push_back(5*k-4);
        if(prime[5*k-2] == 1) ans.push_back(5*k-2);
    }
    REP(i,N) cout << ans[i] << endl;
}

Measured memory_bytes: 3640
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long[] a = new long[N];
		long[] ans = new long[N-1];
		long total = 0,dis = 0;
		for( int i=0; i<N; i++ ){
			a[i] = sc.nextLong();
			total += a[i];
		}
		for( int i=0; i<N-1; i++ ){
			dis += a[i];
			total -= a[i];          
			ans[i] = Math.abs(total-dis);        
		}
		Arrays.sort(ans);
		System.out.println(ans[0]);
	}
}


Measured memory_bytes: 87736
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

string table[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int to(char c){
	if( c >= 'a' ) return 10 + c - 'a';
	return c - '0';
}

int main(){
	string s;
	while(cin >> s && s != "0"){
		int r = to(s[1])*16+to(s[2]);
		int g = to(s[3])*16+to(s[4]);
		int b = to(s[5])*16+to(s[6]);
		vector< pair<int,int> > answer;
		for(int i = 0 ; i < 8 ; i++){
			int R = (i>>2&1)*255;
			int G = (i>>1&1)*255;
			int B = (i&1)*255;
			int dist = (R-r)*(R-r) + (g-G)*(g-G) + (b-B)*(b-B);
			//cout << R <<" " << G << " " << B << " " <<  endl;
			answer.push_back( make_pair(dist,i) );
		}
		cout << table[(*min_element(answer.begin(),answer.end())).second] << endl;
	}
}

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

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second
 
Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    Int b[70][2] = {};
    for (Int i = 0; i < n; i++) {
        Int x = 0;
        for (Int j = 0; j < 61; j++) {
            b[j][a[i] % 2]++;
            a[i] /= 2;
        }
    }
    Int res = 0;
    for (Int i = 0; i < 61; i++) {
        Int add = b[i][0] * b[i][1] % mod;
        add = add * (((1LL)<<i) % mod) % mod;
        res += add;
        res %= mod;
    }
    dump(res % mod);
    return 0;
}

Measured memory_bytes: 2560
import numpy as np
n = int(input())

sg = []

for i in range(n):
    x, l = map(int, input().split())
    sg.append([max(x - l, 0), x + l])

sg.sort(key=lambda x: x[1])

prev = sg[0][1]

ans = 0
for i in range(1, n):
    if prev > sg[i][0]:
        ans += 1
    else:
        prev = sg[i][1]

print(n - ans)

Measured memory_bytes: 30324
L=['A','C','G','T']
s=input()
ans=[]
for i in range(len(s)):
    if s[i] in L:
        j=i
        while s[j] in L:
            j+=1
            if j==len(s):
                break
        ans.append(len(s[i:j]))
print(0 if len(ans)==0 else max(ans))

Measured memory_bytes: 9072
package main

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

func main() {
	defer writer.Flush()
	H, W, K := ReadInt(), ReadInt(), ReadInt()
	grid := make([]string, H)
	for i := 0; i < H; i++ {
		grid[i] = ReadString()
	}

	ans := make([][]int, H)
	cnt := 0
	for h := 0; h < H; h++ {
		pos := make([]int, 0) // この行のイチゴ位置
		for w := 0; w < W; w++ {
			if grid[h][w] == '#' {
				pos = append(pos, w)
			}
		}
		if len(pos) == 0 {
			// イチゴがなければ次の行へ
			continue
		}
		// イチゴがあれば、この行の左から右まで、番号を付ける。
		row := make([]int, W)
		left := 0
		for i, right := range pos {
			for w := left; w <= right; w++ {
				row[w] = cnt + i + 1
			}
			left = right + 1
		}
		for w := left; w < W; w++ {
			row[w] = cnt + len(pos)
		}
		cnt += len(pos)
		ans[h] = row

		// 上で未設定の行にも、同じ番号をつける
		for nh := h - 1; nh >= 0 && len(ans[nh]) == 0; nh-- {
			ans[nh] = row
		}
		if cnt == K {
			// イチゴが全部見つかったので下の行にも同じ番号をつけて終了
			for nh := h + 1; nh < H; nh++ {
				ans[nh] = row
			}
			break
		}
	}

	for h := 0; h < H; h++ {
		for w := 0; w < W; w++ {
			Printf("%d ", ans[h][w])
		}
		Println()
	}
}

var writer = bufio.NewWriter(os.Stdout)

func Printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }
func Println(a ...interface{})               { fmt.Fprintln(writer, a...) }

var scanner = bufio.NewScanner(os.Stdin)

func init() {
	scanner.Buffer(make([]byte, 256), 1e9)
	scanner.Split(bufio.ScanWords)
}
func ReadString() string { scanner.Scan(); return scanner.Text() }
func ReadInt() int {
	a, err := strconv.Atoi(ReadString())
	if err != nil {
		panic(err)
	}
	return a
}


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

int main() {
    
    int N;
    cin >> N;
    // map<int, vector<vector<int>> m;
    map<int, vector<vector<int>>> m;
    int u, v, w;
    for(int i=0;i<N-1;i++){
        cin >> u >> v >> w;
        if(m.count(u)==0){
            vector<vector<int>> vv;
            vector<int> h{v, w%2};
            vv.push_back(h);
            m.insert(make_pair(u, vv));
        }else{
            vector<int> h{v, w%2};
            m[u].push_back(h);
        }
        if(m.count(v)==0){
            vector<vector<int>> vv;
            vector<int> h{u, w%2};
            vv.push_back(h);
            m.insert(make_pair(v, vv));
        }else{
            vector<int> h{u, w%2};
            m[v].push_back(h);
        }
    }
    vector<int> colors(N);
    set<int> searched;

    // 最初は1
    auto ite=m.begin();
    colors.at(ite->first - 1) = 2;
    stack<int> search;
    search.push(ite->first);
    while(search.size() != 0){
        u = search.top();
        search.pop();
        if(searched.count(u)==0){
            // 探索がまだできていない
            searched.insert(u);
            for(int i=0;i<m[u].size();i++){
                int c = colors.at(u-1);
                if(m[u].at(i).at(1)==1){
                    c = 3 - c;
                }
                colors.at(m[u].at(i).at(0)-1) = c;
                search.push(m[u].at(i).at(0));
            }
        }
    }
    int co;
    for(int i=0;i<N;i++){
        if(colors.at(i)==1){
            co = 1;
        }else{
            co = 0;
        }
        cout << co << endl;
    }

    return 0;

}

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

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

  if (a == b && b == c) {
    cnt = 1;
  } else if ((a == b && b != c) || (a == c && a != b) || (b == c && b != a)) {
    cnt = 2;
  } else {
    cnt = 3;
  }

  cout << cnt << endl;

  return 0;
}

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


M = 998244353

def powmod(a, x, m = M):
    y = 1
    while 0 < x:
        if x % 2 == 1:
            y *= a
            y %= m
        x //= 2
        a = a ** 2
        a %= m

    return y


def solve(s):
    n = len(s)

    nb = nc = 0
    ch = s[0]
    if ch == 'b':
        nb += 1
    elif ch == 'c':
        nc += 1
    sf = True
    tf = True
    left = ch
    for ch in s[1:]:
        if ch == 'b':
            nb += 1
        elif ch == 'c':
            nc += 1
        if ch == left:
            sf = False
        else:
            tf = False
        left = ch


    if tf:
        return 1
    if n == 3:
        if (nb + nc * 2) % 3:
            return 7 if sf else 6
        else:
            return 3
    if n % 3:
        return (powmod(3, n - 1) + M - powmod(2, n - 1) + (1 if sf else 0)) % M
    else:
        if (nb + nc * 2) % 3:
            return (powmod(3, n - 1) + M - (powmod(2, n - 1) - powmod(2, n // 3 - 1)) + (1 if sf else 0)) % M
        else:
            return (powmod(3, n - 1) + M - (powmod(2, n // 3) + 4 * powmod(8, n // 3 - 1)) + (1 if sf else 0)) % M

def main():
    s = input()

    print(solve(s))


if __name__ == '__main__':
    main()



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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc =new Scanner(System.in);
		int A = sc.nextInt();
		int t = sc.nextInt();
		
		int result = A - t;
		if(result<0) {
			result = 0;
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 35816
/* Test Code */

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

struct edge
{
    int v,w,nxt;
}e[400050];

int head[100050],ecnt;

void adde(int u,int v,int w)
{
    e[++ecnt].v = v;
    e[ecnt].w = w;
    e[ecnt].nxt = head[u];
    head[u] = ecnt;
}

int N,M;
int l[200050],r[200050];
int d[200050];
long long dist[100005];
queue<int> que;
bool vis[100050],inq[100050];

bool spfa(int st)
{
    que.push(st);
    inq[st] = true;
    dist[st] = 0;
    long long curmax = 0,curmin = 0;
    while(!que.empty())
    {
        int u = que.front();
        que.pop();
        for(int i = head[u];i;i = e[i].nxt)
        {
            int v = e[i].v;
            if(dist[v] == 12345678987654321)
            {
                dist[v] = dist[u] + e[i].w;
                curmax = max(curmax,dist[v]);
                curmin = min(curmin,dist[v]);
                if(curmax - curmin > 1000000000)
                    return false;
                vis[v] = 1;
                if(!inq[v])
                    que.push(v);
            }
            else if(dist[v] != dist[u] + e[i].w)
                return false;
        }
        inq[u] = false;
    }
    return true;
}

int main()
{
    for(int i = 1;i <= 100000; ++ i)
        dist[i] = 12345678987654321;
    scanf("%d%d",&N,&M);
    for(int i = 1;i <= M; ++ i)
    {
        scanf("%d%d%d",&l[i],&r[i],&d[i]);
        adde(l[i],r[i],d[i]);
        adde(r[i],l[i],-d[i]);
    }
    for(int i = 1;i <= N; ++ i)
    {
        if(!vis[i])
        {
            vis[i] = 1;bool l = spfa(i);
            if(!l)
            {
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN=1E5+10;

int n,fa[MAXN];
set<int> S[MAXN];
map<ll,int> M;
queue<pair<int,int> > q;

int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}

ll get(int u,int v)
{
	if(u>v)
		swap(u,v);
	return 1ll*MAXN*u+v;
}

void Add_Edge(int u,int v)
{
	S[u].insert(v);
	S[v].insert(u);
	if(++M[get(u,v)]==2)
		q.emplace(u,v);
}

void Erase_Edge(int u,int v)
{
	S[u].erase(v);
	S[v].erase(u);
	M.erase(get(u,v));
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		fa[i]=i;
	for(int i=1,u,v;i<=2*n-2;i++)
	{
		scanf("%d%d",&u,&v);
		Add_Edge(u,v);
	}
	for(int i=1;i<n;i++)
	{
		if(q.empty())
			return puts("NO"),0;
		int x=find(q.front().first),y=find(q.front().second);
		q.pop();
		if(S[x].size()<S[y].size())
			swap(x,y);
		Erase_Edge(x,y);
		for(set<int>::iterator it=S[y].begin(),nxt;it!=S[y].end();it=nxt)
		{
			int v=*it;
			nxt=it;nxt++;
			Erase_Edge(y,v);
			Add_Edge(x,v);
		}
		fa[y]=x;
	}
	puts("YES");
}


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

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

const int INF = 1e9;

using namespace std;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
//    freopen("out.txt", "w", stdout);

    ll N, Q; cin >> N >> Q;
    
    set<ii> setx, sety;
    setx.insert({N, N});
    sety.insert({N, N});

    ll b = 0;

    for(int q = 0; q < Q; q++){
        int d; cin >> d;

        if(d == 1){
            int x; cin >> x;
            int y = (*sety.lower_bound({x, 0})).second;
            setx.insert({y, x});
            b += y-2;
        }
        if(d == 2){
            int y; cin >> y;
            int x = (*setx.lower_bound({y, 0})).second;
            sety.insert({x, y});
            b += x-2;
        }
    }
    cout << (N-2)*(N-2)-b;


    return 0;

}


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

int main(){
  int n, tmp;
  int p[2000001];

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> p[i];
  }
  
  sort(p, p+n);
  for(int i=0;i<n-1;i++){
    if(p[i]==p[i+1]){
      cout << "NO";
      return 0;
    }
  }
  
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 2688
N,M,X = map(int, input().split())
n = list(map(int, input().split()))
Ni = list(range(N,X,-1))
Nk = list(range(0,X))
Ni_set = set(Ni)
Nk_set = set(Nk)
n_set = set(n)
Ni_ten = list(Ni_set & n_set)
Nk_ten = list(Nk_set & n_set)
if len(Ni_ten)< len(Nk_ten):
 print(len(Ni_ten))
else:
  print(len(Nk_ten))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

const int N = 3e5 + 500;
const ll inf = 1e18;
const int mod = 1e9 + 7;
const int M = 3e6 + 500;


int n,a[N],b[N];

int main()
{
	speed;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
	}
	int ok = 0;
	for(int i = 1; i <= n-2; i++){
		int f = 1;
		for(int j = i; j <= i+2; j++){
			if(a[j] != b[j])f = 0;
		}
		if(f){
			ok = 1;
			break;
		}
	}
	cout << (ok ? "Yes" : "No");
}


Measured memory_bytes: 3656
#include <cstdio>
#include <map>

typedef long long LL;
const int Mod[2] = {999988679, 999988609};
const int B[2] = {370728, 370732};
const int iB[2] = {396903752, 462741403};
const int MN = 250005;

inline void Add(int &x, int y, int i) { x -= (x += y) >= Mod[i] ? Mod[i] : 0; }

int N;
char S[MN];
int A[2][MN], D[2][MN];
std::map<std::pair<int, int>, int> Buk;
LL Ans;

int main() {
	scanf("%d%s", &N, S + 1);
	for (int j = 0; j < 2; ++j) A[j][0] = 0, D[j][0] = 1;
	for (int i = 1, V[2] = {1, 1}; i <= N; ++i) {
		for (int j = 0; j < 2; ++j) {
			A[j][i] = A[j][i - 1];
			if (S[i] == '+') Add(A[j][i], V[j], j);
			if (S[i] == '-') Add(A[j][i], Mod[j] - V[j], j);
			if (S[i] == '>') V[j] = (LL)V[j] * B[j] % Mod[j];
			if (S[i] == '<') V[j] = (LL)V[j] * iB[j] % Mod[j];
			D[j][i] = V[j];
		}
	}
	for (int i = N; i >= 0; --i) {
		Ans += Buk[{
			(A[0][i] + (LL)A[0][N] * D[0][i]) % Mod[0],
			(A[1][i] + (LL)A[1][N] * D[1][i]) % Mod[1]
		}];
		++Buk[{A[0][i], A[1][i]}];
	}
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#include <boost/functional/hash.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n;
    cin >> n;

    string s;
    cin >> s;

    auto r = irange(0L, n / 2 + 1);
    auto it = partition_point(r.begin(), r.end(), [&](int64_t len) {
        if (len == 0) {
            return true;
        }

        unordered_map<string, int64_t, boost::hash<string>> m;
        for (auto p : irange(0L, n - len + 1)) {
            string sub = string(s.begin() + p, s.begin() + p + len);
            if (m.count(sub) > 0) {
                if (m[sub] + len <= p) {
                    cerr << sub << endl;
                    return true;
                }
            } else {
                m[sub] = p;
            }
        }

        return false;
    });

    cout << *it - 1 << endl;
}

Measured memory_bytes: 6768
#include <iostream>

using namespace std;

int main()
{
    int n;
    long long d;
    int cnt=0;
    cin>>n>>d;
    d=d*d;
    while(0<n--) {
        int x,y; cin>>x>>y;
        long long dx;
        dx=1ll*x*x+1ll*y*y;
        if(dx<=d) cnt++;
    }
    cout << cnt << '\n';
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int N = (int)S.size();
  int num[3];
  num[0] = num[1] = num[2] = 0;
  for (int i = 0; i < N; i ++) {
    num[(int)S[i] - (int)'a'] ++;
  }
  int mi = num[0];
  int ma = num[0];
  for (int i = 1; i < 3; i ++) {
    if (mi > num[i]) mi = num[i];
    if (ma < num[i]) ma = num[i];
  }
  cout << ((ma - mi < 2) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 3760
mod = 10**9 + 7
n = int(input())
l = list(map(int, input().split()))
 
d, ans = 0, 0
 
for i in range(1, n):
  f = 1 if i == 1 else f * (i-1) % mod
  d = (d * i + f) % mod
  ans = (ans * i + (l[i] - l[i-1]) * d) % mod
 
print(ans)

Measured memory_bytes: 62576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=2e5;
const int inf=1e9;
vector<int> g[51];
vector<int> color(50);
vector<int> visit(50);
bool dfs(int v){
	for(int u:g[v]){
		if(visit[u] == 0){
            visit[u] = 1;
			color[u] = color[v] ^ 1;
			if(!dfs(u)) return false;
		}else{
			if(color[v] == color[u]) return false;
		}
	}return true;
}
int main(){
	int N;cin>>N;
	int D[N];
	rep(i,0,N) cin>>D[i];
	sort(D, D+N);
	for(int s = D[0]; s >= 0; s--){
		rep(i,0,N){ g[i].clear(); visit[i] = 0; }
		rep(i,0,N)rep(j,0,i){
			if(abs(D[i] - D[j]) < s){
				g[i].push_back(j);
				g[j].push_back(i);
			}
		}
		bool flag = true;
		rep(i,0,N)if(visit[i] == 0){
			visit[i] = 1;
			color[i] = 0;
			flag &= dfs(i);
		}
		int a = 0,b = 0;
		rep(i,0,N){
			if(color[i]) a = max(a, D[i]);
			else b = max(b, D[i]);
		}
		if(flag && abs(24 - a - b) >= s){ cout<<s<<endl; return 0; }
	}
}

Measured memory_bytes: 256
n = int(input())
nums = list(map(int, input().split()))
count = 0
for i in range(n):
    for j in range(n-1, i, -1):
        if nums[j] < nums[j-1]:
            count += 1
            nums[j], nums[j-1] = nums[j-1], nums[j]
for i in range(n-1):
    print(nums[i], end = ' ')
print(nums[n-1])
print(count)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int k;
	string s="ACL";
	cin>>k;
	while(k--)
        cout<<s;
    cout<<endl;
	return 0;
}


Measured memory_bytes: 3504
def solve(N, A, X, Y):
    ret = 0
    for i in range(2 ** N):
        tmp = []
        for j in range(N):
            if i >> j & 1:
                tmp.append(j)
        if not tmp:
            continue

        is_valid = True
        for a_idx in tmp:
            for idx in range(A[a_idx]):
                if (Y[a_idx][idx] and X[a_idx][idx] - 1 not in tmp) \
                        or (not Y[a_idx][idx] and X[a_idx][idx] - 1 in tmp):
                    is_valid = False
                    break
        ret = max(ret, len(tmp)) if is_valid else ret
    return ret

if __name__ == "__main__":
    N = int(input())
    A = []
    X, Y = [], []
    for _ in range(N):
        A.append(int(input()))
        tmp_x, tmp_y = [], []
        for _ in range(A[-1]):
            x, y = map(int, input().split())
            tmp_x.append(x)
            tmp_y.append(y)
        X.append(tmp_x)
        Y.append(tmp_y)
    print(solve(N, A, X, Y))

Measured memory_bytes: 45676
let lower_bound (a : int array) first last v =
  let rec doit len first =
    if len = 0 then first
    else
      let half = len / 2 in
      let mid = first + half in
      if a.(mid) < v then doit (len - half - 1) (mid + 1)
      else doit half first in
  doit (last - first + 1) first

let () =
  let n = read_int () in
  let dp = Array.make (n + 1) max_int in
  for i = 0 to n - 1 do
    let a = read_int () in
    dp.(lower_bound dp 0 n a) <- a;
  done;
  lower_bound dp 0 n max_int |> Printf.printf "%d\n"

Measured memory_bytes: 5280
// https://atcoder.jp/contests/abc115/tasks/abc115_c

#[allow(unused)]
use std::cmp::{max, min};
#[allow(unused)]
use std::collections::{HashSet, VecDeque};
use std::io;
use std::io::{BufRead, Read, Write};
use std::str::FromStr;

#[allow(unused, non_snake_case)]
pub fn solve<R: BufRead, W: Write>(mut io: Io<R, W>) {
    let N: usize = io.next();
    let K: usize = io.next();
    let mut hs: Vec<usize> = io.nexts(N);

    hs.sort();

    let res = (0..N - K + 1).map(|i| hs[i + K - 1] - hs[i]).min().unwrap();

    io.println(res);
}

#[allow(dead_code)]
fn main() {
    let stdin = io::stdin();
    let stdin_lock = stdin.lock();
    let stdout = io::stdout();
    let stdout_lock = stdout.lock();

    let io = Io {
        reader: stdin_lock,
        writer: stdout_lock,
    };

    solve(io);
}

/* IO helpers */

pub struct Io<R, W>
where
    R: BufRead,
    W: Write,
{
    pub reader: R,
    pub writer: W,
}

#[allow(dead_code)]
impl<R, W> Io<R, W>
where
    R: BufRead,
    W: Write,
{
    fn println<T: std::fmt::Display>(&mut self, value: T) {
        writeln!(&mut self.writer, "{}", value).expect("Unable to write");
    }

    fn print<T: std::fmt::Display>(&mut self, value: T) {
        write!(&mut self.writer, "{}", value).expect("Unable to write");
    }

    fn debug<T: std::fmt::Debug>(&mut self, value: T) {
        writeln!(&mut self.writer, "{:?}", value).expect("Unable to write");
    }

    fn next<T: FromStr>(&mut self) -> 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>();
        token.parse::<T>().ok().expect("Unable to parse")
    }

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

/* Structure helpers */

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 998244353;

int main() {
	int X, Y;
	for (int i = 0;i < 5;i++) {
		cin >> X;
		if (X == 0)Y = i + 1;
	}
	cout << Y << endl;
}

Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <cmath>

using namespace std;

int main() {
    string s, t, u;
    size_t a, b;
    cin >> s >> t >> a >> b >> u;
    if (u == s)
        --a;
    else if (u == t)
        --b;
    cout << a << ' ' << b << endl;
    return 0;
}



Measured memory_bytes: 256
from collections import deque
s=deque(input())
q=int(input())
flg=True #正順
for i in range(q):
    p=list(map(str,input().split()))
    if p[0]=="1":flg=not(flg)
    else:
        z,f,c=p
        if f=="1":
            if flg:s.appendleft(c)
            else:s.append(c)
        else:
            if not(flg):s.appendleft(c)
            else:s.append(c)

s=list(s)
if flg:
    ans=s
else:
    ans=s[::-1]
print("".join(ans))



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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

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

const ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int x; cin >> x;
	cout << x*x << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 256
s = input()
l = len(s)
mod = 10**9 + 7
dp = [[0 for j in range(13)] for i in range(l + 1)]
dp[0][0] = 1
for i in range(l):
    if s[i] == '?':
        for j in range(10):
            for k in range(13):
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k] % mod
    else:
        for k in range(13):
            dp[i + 1][(k * 10 + int(s[i])) % 13] += dp[i][k] % mod
print(dp[-1][5] % mod)


Measured memory_bytes: 66268
#include <bits/stdc++.h>
#define int long long
#define dl long double
#define ff first
#define ss second
#define pb push_back
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAXN 500
using namespace std;
typedef pair<int,int> pii;

const int MOD = 998244353;


int32_t main(){
	fastio;
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	
	s[k-1] = s[k-1]-'A'+'a';
	cout<<s<<endl;
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
int main() {
    string S;

    cin >> S;
    if(S == "Sunny") {
        cout << "Cloudy" << endl;
    } else if(S == "Cloudy") {
        cout << "Rainy" << endl;
    } else if(S == "Rainy") {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var s = nextstr();
  var ans = 0, t = 0;
  for(var i = 0; i < 3; i++){
    if(s[i] === "R")t++;
    else ans = Math.max(ans,t), t = 0;
  }
  return Math.max(ans,t);
}

Measured memory_bytes: 29684
#define _DEBUG
#include "bits/stdc++.h"
#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;
  //内部は1-indexedだけどmainでは0-indxedで動く
  int sz;//size 葉がsz個、葉以外がsz-1個
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);//子を用いて親を更新
    }
  }

  void add(int k, const Monoid &x) {
	k += sz;
	seg[k] += x;
	while(k >>= 1) {
	  seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
	}
  }

  Monoid query(int a, int b) {//半開区間
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};
int main(){
	int N,K,A[300001];
	scan(N>>K);
	SegmentTree<int> seg(300003,[](int a, int b){return max(a,b);},0);
	rep(i,N){
		scan(A[i]);
		int num=seg.query(max(A[i]-K,0),min(A[i]+K+1,300002));
		seg.update(A[i],num+1);
	}
	prin(seg.query(0,300002));
	return 0;
}


Measured memory_bytes: 8576
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
ans = sum(A)
C = Counter(A)
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    if b in C:
        C[c] += C[b]
        ans += (c - b) * C[b]
        C[b] = 0
    print(ans)


Measured memory_bytes: 21320
#include <stdio.h>

int main()
{
	long long H, W, X;
	scanf("%lld %lld", &H, &W);
	X = (H * W + 1) / 2;
	if (H == 1 || W == 1) printf("1\n");
	else printf("%lld\n", X);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
import numpy as np

input_values = input().split(" ")

p1 = np.array([int(input_values[0]),int(input_values[1])])
p2 = np.array([int(input_values[2]),int(input_values[3])])

v1 = p2-p1
v2 = np.array([-v1[1],v1[0]])

p3 = p2+v2

v3 = np.array([-v2[1],v2[0]])
p4 = v3+p3

print(p3[0],p3[1],p4[0],p4[1])


Measured memory_bytes: 21540
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define prt(var)         cout << var << endl
#define prtd(n, var)     cout << fixed << setprecision(n) << var << endl
#define prt2(var1, var2) cout << var1 << " " << var2 << endl
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << endl

//----------------------------------------------------------------
ll gcd(ll x, ll y){
  if(x<y){return gcd(y,x);}
  if(y==0 || x==y) {return x;}
  else {return gcd(y, x%y);}
}



int main(void) {
  ll a, b;
  cin >> a >> b;

  ll g = gcd(a,b);

  if(g==1){
    prt(1); return 0;
  }

  double sq = sqrt(g);
  vecll div;
  for(int i=1; i<sq; i++){
    if(g%(i)==0){
      div.push_back(i);
      if((g/i)!=i){
        div.push_back(g/i);
      }
    }
  }

  sort(all(div));

  vector<bool> isOK;
  isOK.assign(div.size(), true);
  rep(i, div.size()){
    if(div[i]==1 || !isOK[i]){continue;}
    REP(j,i+1,div.size()){
      if(div[j]%div[i]==0){
        isOK[j]=false;
      }
    }
  }

  ll ans=0;
  rep(i,isOK.size()){
    if(isOK[i]){ans++;}
  }

  prt(ans);
}


Measured memory_bytes: 384
// M
#include<bits/stdc++.h>
using namespace std;
const int N = 303, Mod = 998244353;
int n, k, C[N], dp[N][N][N];
inline void Add(int &a, int b)
{
	a += b;
	if (a >= Mod)
		a -= Mod;
}
int main()
{
	string S;
	cin >> S >> k;
	S = "0" + S;
	for (int i = 0; i < (int)S.size();)
	{
		int r = i + 1;
		while (r < (int)S.size() && S[r] == '1')
			r ++;
		C[n ++] = r - i - 1;
		i = r;
	}
	k = min(k, (int)S.size());
	dp[n][0][0] = 1;
	int sm = 0;
	for (int i = n - 1; ~ i; sm += C[i], i --)
		for (int j = sm; j >= 0; j --)
		{
			for (int h = 0; h <= k; h ++)
				Add(dp[i][j][h], dp[i][j + 1][h]),
				Add(dp[i][j][h], dp[i + 1][j][h]);
			for (int h = 0; h <= k; h ++)
				for (int df = 1; df <= C[i]; df ++)
					Add(dp[i][j + df][h + df], dp[i + 1][j][h]);
		}
	int tot = 0;
	for (int h = 0; h <= k; h ++)
		Add(tot, dp[0][0][h]);
	return !printf("%d\n", tot);
}


Measured memory_bytes: 30492
import math
d, g = map(int, input().split())

p = [0] * d
a = [0] * d
for i in range(d):
    q, c = map(int, input().split())
    a[i] = q * (i + 1) * 100 + c
    p[i] = q

n = len(a)

min_val = sum(p)
for i in range(1 << n):
    score = 0
    val = 0
    k = -1
    for j in range(n):
        if i >> j & 1:
            score += a[j]
            val += p[j]
        else:
            k = j
    r = g - score
    if r > 0:
        if r >= a[k]:
            continue
        else:
            l = math.ceil(r / ((k + 1) * 100))
            if l >= p[k]:
                continue
            val += l
    min_val = min(min_val, val)
print(min_val)


Measured memory_bytes: 68696
h,w = map(int,input().split())
si = [input() for i in range(h)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1 for _ in range(n+1)]
 
    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
 
    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
 
    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
ki = UnionFind(h*w)

vx = [0,1,0,-1]
vy = [1,0,-1,0]

for i in range(h):
    for j in range(w):
        if si[i][j] == '#':
            for k in range(4):
                ny = i + vy[k]
                nx = j + vx[k]
                if ny >= 0 and ny < h and nx >= 0 and nx < w:
                    if si[ny][nx] == '.':
                        if ki.same_check(i*w+j,ny*w+nx) == True:
                            continue
                        ki.union(i*w+j,ny*w+nx)
ans = 0

li = [0]*(h*w+1)

for i in range(h):
    for j in range(w):
        if si[i][j] == '.':
            li[ki.find(i*w+j)] += 1

for i in range(h):
    for j in range(w):
        if si[i][j] == '#':
            ans += li[ki.find(i*w+j)]
            
print(ans)

Measured memory_bytes: 66824
N, M = gets.split.map(&:to_i)
AB = M.times.map{gets.split.map(&:to_i)}

class UFTree
  def initialize(n)
    @p = Array.new(n + 1, -1)
  end
  def find(x)
    @p[x] < 0 ? x : @p[x] = find(@p[x])
  end
  def unite(a, b)
    x = find(a)
    y = find(b)
    if x != y
      x, y = y, x if @p[y] < @p[x]
      @p[x] += @p[y]
      @p[y] = x
    end
  end
  def member(x)
    -@p[find(x)]
  end
end

nC2 = Hash.new {|h, n| h[n] = n * (n - 1) / 2}
tree = UFTree.new(N)
tot = nC2[N]
ans = [tot]
AB[1...M].reverse.each do |a, b|
  if tree.find(a) != tree.find(b)
    n1 = tree.member(a)
    n2 = tree.member(b)
    tot -= nC2[n1 + n2] - nC2[n1] - nC2[n2]
    tree.unite(a, b)
  end
  ans << tot
end 

puts ans.reverse

Measured memory_bytes: 20476