akhauriyash/Code-Regression huggingface dataset:
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = sum(a)
d = {}
q = int(input())
for i in range(q):
    x, y = map(int, input().split())
    ans -= c[x] * x
    ans += c[x] * y
    c[y] = c[y] + c[x]
    c[x] = 0
    print(ans)

Measured memory_bytes: 24008
def choose(n, r, M):
    x = 1
    y = 1

    for i in range(r):
        x = x * (n - i) % M
        y = y * (i + 1) % M
    res = x * pow(y, M-2, M) % M
    return res

n, a, b = map(int, input().split())
M = 10 ** 9 + 7

print((pow(2, n, M) - 1 - choose(n, a, M) - choose(n, b, M)) % M)

Measured memory_bytes: 3064
// problem: "https://atcoder.jp/contests/abc140/tasks/abc140_d"

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,k;
    string s;

    cin>>n>>k;

    cin>>s;

    if(s.size() == 1)
        cout<<0;

    else
    {
        int i,j,p,l;
        i = 1;
        l = s.size();
        p = 0;

        if(s[0] == 'R')
        {
            for(j=0;j!=n;j++)
            {
                if(s[j] == 'L')
                    s[j] = 'R';
                else
                    s[j] = 'L';
            }
        }

        while(k && i < l)
        {
            if(s[i] == 'R')
            {
                j = i;
                while(j < l && s[j] == 'R')
                {
                    p++;
                    j++;
                }

                if(j == l)
                {
                    if(k)
                    {
                        k--;
                    }
                }
                else
                {
                    if(k)
                    {
                        k--;
                        p++;
                    }
                }

                i = j+1;
            }

            else
            {
                p++;
                i++;
            }
        }

        while(i < l)
        {
            if(s[i] == s[i-1])
                p++;

            i++;
        }

        cout<<p;
    }

    return 0;
}


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

using namespace std;

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

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

#endif

ll f(ll b, ll c, ll d) {
    return b - (b / c) - (b / d) + (b / ((c * d) / __gcd(d, c)));
}

void Main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << f(B, C, D) - f(A - 1, C, D) << '\n';
}

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


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<vector>
#include<fstream>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<cwctype>
#include<algorithm>
#include<math.h>

using namespace std;


int data[10];

bool searchB (int a){
	vector<int >sea;

	for(int i=0;i<10;i++){
		if(a>>i & 1)sea.push_back(data[i]);
	}
	if(sea.size()>1){
	for(int i=0;i<sea.size()-1;i++){
		if(sea[i]>sea[i+1])return false;
	}
	}
	return true;
}

int main(){

	int n=0;
	cin>>n;

	for(int i=0;i<n;i++){
		

	for(int j=0;j<10;j++){
		cin>>data[j];
	}
	bool suc=false;
	for(int i=0;i<2048;i++){
		if(searchB(i) && searchB(~i)){
			cout<<"YES"<<endl;
			suc=true;
			break;
		}
	}
	if(!suc)cout<<"NO"<<endl;
	}
	return 0;
}

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

int main(){
  vector<int> A(3);

  for(int i=0;i<3;i++){
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());

  cout << A.at(0)+A.at(1) << endl;
}

Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0: break
    record = {}
    for _ in range(n):
        num, m1, s1, m2, s2, m3, s3, m4, s4 = \
            map(int, input().split())
        record[num] = (m1*60+s1) + (m2*60+s2) + \
                        (m3*60+s3) + (m4*60+s4)
    record = sorted(record.items(), key=lambda x: x[1])
    result = record[:2]
    result.append(record[-2])
    for res in result:
        print(res[0])



Measured memory_bytes: 6436
#include<stdio.h>
 
struct tree{
 int back, left, right;
};
 
struct tree a[25];
 
void preorder(int id){
 if (id == -1){
 return;  
 }
 printf(" %d", id);
 preorder(a[id].left);
 preorder(a[id].right);
}
 
void inorder(int id){
 if (id == -1){
 return;  
 }
 inorder(a[id].left);
 printf(" %d", id);
 inorder(a[id].right);
}
 
void postorder(int id){
 if (id == -1){
 return;  
 }
 postorder(a[id].left);
 postorder(a[id].right);
 printf(" %d", id);
}
 
int main(){
 int num, i, Start, point, left, right;
  
 scanf("%d", &num);
 for(i = 0; i < num; i++){
   a[i].back = -1;
 }
 
 for(i = 0; i < num; i++){
   scanf("%d %d %d", &point ,&left, &right);
   a[point].left  = left;
   a[point].right = right;
   if(left != -1){
     a[left].back  = point;
   }
   if(right != -1){
     a[right].back = point;
   }
 }
  
 for(i = 0; i < num; i++){
    /* check
    printf("%d %d %d %d\n",i, a[i].back,a[i].left,a[i].right);
    */
   if(a[i].back == -1){
     Start = i;
   }
 }
 
 printf("Preorder\n");
 preorder(Start);
 printf("\n");
 
 printf("Inorder\n");
 inorder(Start);
 printf("\n");
 
 printf("Postorder\n");
 postorder(Start);
 printf("\n");
 
 return 0;
}

Measured memory_bytes: 1816
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int n, m, c, ans = 0, i, j, judeged = 0;
	int *b, a;

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

	judeged += c;

	b = (int *)malloc(sizeof(int) * m);

	for (i = 0; i < m; i++)
		scanf("%d", b + i);


	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			scanf("%d", &a);
			judeged += a * *(b + j);
		}

		if (judeged > 0)
			ans++;

		judeged = c;
	}

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

	return 0;
}


Measured memory_bytes: 128
//Jay Shree Krishna

#include"bits/stdc++.h"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long int
#define inf 1e18+5
#define sr string
#define M 1000000007
#define start int t;cin>>t;while(t--)
#define db(x) cout<<#x<<"="<<x<<"\n"
#define db2(a,b)cout<<#a<<": "<<a<<" , "<<#b<<": "<<b<< endl;
#define db3(a,b,c)cout<<#a<<": "<<a<<" , "<<#b<<": "<<b<<" , "<<#c<<": "<<c<<endl;
#define forr(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = 1; i <= n; i++)
#define rep(i,j,k) for(int i = j; i < k; i++)
#define rp(i,j,k) for(int i = j; i <=k; i++)
#define nn "\n"
#define en "\n"
#define vvi vector<vector<int>>
#define vi vector<int>
#define si set<int>
#define mlsi multiset<int>
#define vc vector<char>
#define vli vector<long long int>
#define vpii vector<pair<int,int>>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umsi unordered_map<string,int>
#define umci unordered_map<char,int>
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sortv(x) sort(x.begin(),x.end())
#define sorta(x,n) sort(x,x+n)
#define sorted(x) is_sorted(x.begin(),x,end())
#define print_all(x) for(auto t:x) cout<<t<<" ";cout<<en;
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define ub upper_bound
#define lb lower_bound
#define go(x) for(auto &[u,v]:x)
#define in(x) cin>>x
#define in2(x,y) cin>>x>>y
#define in3(x,y,z) cin>>x>>y>>z
#define in4(x,y,z,v) cin>>x>>y>>z>>v
#define oo(x) cout<<x<<endl
#define oo2(x,y) cout<<x<<" "<<y<<endl
#define oo3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl
#define ood(n,x) cout<<fixed<<setprecision(n)<<x<<"\n"
#define sz(x) x.size()
#define ff first
#define ss second
#define ooy cout<<"Yes\n"
#define oon cout<<"No\n" 
#define rr return
#define cc continue

using namespace std;

template<class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
void read(vli &a,int n){
    a.resize(n);
    forr(i,n) cin>>a[i];
}

bool fine=0;
vli a;
ll n,m;


void solve(){
    in(n);
    ll ans=0;
    fr(i,n-1){
        ll temp=n/i;
        if(n%i==0) temp--;
        ans+=temp;
    }
    oo(ans);


}

int main(){
   #ifndef ONLINE_JUDGE 
    freopen("input1.txt", "r", stdin); 
    freopen("error.txt", "w", stderr); 
    freopen("output1.txt", "w", stdout); 
    #endif
    fast;
   if(fine){
        start{
            solve();
        }
   }
   else solve();
    return 0;
}


Measured memory_bytes: 3628
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

ans_H = (T - A)/0.006
dif = 10**20
ans = 0
for i in range(len(H)):
	temp_dif = abs(ans_H - H[i])
	if (dif > temp_dif):
		dif = temp_dif
		ans = i + 1
	
print(ans)
		
	
		
	

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

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

  for (int i = 1; i <= 1000; i++) {
    int x = i * 0.08, y = i * 0.1;
    if (x == a && y == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
} 

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=ja
//0-1 Knapsack Problem
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in");
    //std::ifstream in("./input.txt");
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N,W; cin>>N>>W;
    vector<pair<ll,ll>> vwn(N+1);
    FOR(i,0,N){
        auto&& vw=vwn.at(i);
        cin>>vw.first>>vw.second;
    }

    vector<vector<ll>> dp(N+2,vector<ll>(W+1)); //数,weight
    FOR(i,0,N){
        FOR(w,0,W+1){
            const auto& vw=vwn.at(i);
            if (w-vw.second<0){
                dp[i+1][w]=dp[i][w];
            }else{
                dp[i+1][w]=max(dp[i][w], dp[i][w-vw.second]+vw.first); //いれる
            }
        }
    }
    ll ans=0;
    FOR(w,0,W+1){
        ans=max(ans,dp[N][w]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11068
#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;

int main(void){
	vector<char> ma;
	map<char, int> key_map;
	for(int i=0; i<26; i++){
		ma.push_back('a' + i);
		key_map['a' + i] = i;
	}
	for(int i=0; i<26; i++){
		ma.push_back('A' + i);
		key_map['A' + i] = 26 + i;
	}


	while(1){
		int n;
		vector<int> key;
		vector<char> ans;
		string list;
		cin >> n;
		if(n == 0) break;

		for(int i=0; i<n; i++){
			int t;
			cin >> t;
			key.push_back(t);
		}
		cin >> list;

		for(int i=0; i<list.size(); i++){
			int size = key.size();
			int key_i = i;
			if(i >= size) key_i = i % size;
			//cout << key_map[list[i]]  << endl;
			//cout << (key_map[list[i]] + 52 - key[key_i])%52  << endl;
			
			char ch = ma[(key_map[list[i]] + 52 - key[key_i] ) % 52];
			ans.push_back(ch);
		}

		for(int i=0; i<ans.size(); i++){
			cout << ans[i];
		}
		puts("");

	}


	return 0;
}

Measured memory_bytes: 1208
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int S=sc.nextInt();
      int W=sc.nextInt();
      if(W>=S){
         System.out.println("unsafe");
      }else{
         System.out.println("safe");
      }
   }
}
      


Measured memory_bytes: 35764
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        var s = Console.ReadLine();
        var t = Console.ReadLine();
        Console.WriteLine(s.Zip(t, (x, y) => x == y).Count(x => x));
    }

    static readonly TextReader In = Console.In;
    static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0;
            int next = In.Read();
            int rev = 1;
            while (45 > next || next > 57) next = In.Read();
            if (next == 45) { next = In.Read(); rev = -1; }
            while (48 <= next && next <= 57)
            {
                res = res * 10 + next - 48;
                next = In.Read();
            }
            return res * rev;
        }
    }
}


Measured memory_bytes: 11220
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    while (true) {
      int a = scan.nextInt();
      String op = scan.next();
      int b = scan.nextInt();

      if (op.equals("?")) {
        break;
      }

      switch (op) {

      case "+":
        System.out.println(a + b);
        break;

      case "-":
        System.out.println(a - b);
        break;

      case "*":
        System.out.println(a * b);
        break;

      case "/":
        System.out.println(a / b);
        break;
      }

    }

  }
}


Measured memory_bytes: 26344
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#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++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    double dou,butu;
    cin >> A >> dou;

    C = (ll)((A*(ll)(dou * 100+0.5))/100);

    cout<< C;


    
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
 
// cout<<fixed<<setprecision(10);
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

const int INF = 1e9;
const int NM = 100100;
int dp[NM];

int main() {
    int n; cin >> n;
    rep(i, NM) dp[i] = -1;
    dp[0] = 0;
    
    // bfs
    queue<int> que;
    que.push(0);

    while(!que.empty()) {
        int v = que.front(); que.pop();

        for(int pow6 = 1; v+pow6 <= n; pow6 *= 6) {
            if(dp[v+pow6] == -1) {
                dp[v+pow6] = dp[v] + 1;
                que.push(v+pow6);
            }
        }
        for(int pow9 = 1; v+pow9 <= n; pow9 *= 9) {
            if(dp[v+pow9] == -1) {
                dp[v+pow9] = dp[v] + 1;
                que.push(v+pow9);
            }
        }
    }
    cout << dp[n] << endl;


}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
 
using namespace std;
 
int main(){
int R,G;
  
  cin >> R >> G;
  
  cout << G - R + G << endl;
  
  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#define MAX_A 2333
#define MAX_L 15
#define int long long

using namespace std;

const char c[]="MARCH";

int n;
int f[MAX_A];
char s[MAX_L];

int cal()
{
	int ans=0;
	for(int i=0;i<5;i++)
	{
		for(int j=i+1;j<5;j++)
		{
			for(int k=j+1;k<5;k++)
			{
				ans+=f[c[i]]*f[c[j]]*f[c[k]];
			}
		}
	}
	return ans;
}

signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%s",s),f[s[0]]++;
	printf("%lld\n",cal());
}


Measured memory_bytes: 256
main :: IO ()
main = do
  n <- getLine
  if n == "0000"
    then return ()
    else do
      putStrLn $ solve n
      main

solve :: String -> String
solve s
  | all ((==) (head s)) s = "NA"
  | otherwise = count s 0
  where
    count :: String -> Int -> String
    count s counter
      | s == "6174" = show counter
      | otherwise = count (show' ((read sorted) - (read (reverse sorted)))) (counter + 1)
      where
        sorted = sort s
        sort :: String -> String
        sort [] = []
        sort (x:xs) = (sort higher) ++ [x] ++ (sort lower)
          where
            higher = filter (\y -> y >= x) xs
            lower = filter (\y -> y < x) xs

        show' :: Int -> String
        show' n = (replicate (4 - (length n')) '0') ++ n'
          where n' = show n

Measured memory_bytes: 4088
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

ll ans=0;

ll sum(vector<ll> v){
    ll res=0;
    rep(i,v.size())res+=v[i];
    return res;
}

vector<ll> StI(string &s){
    vector<ll> res;
    for(int i=0;i<s.length();i++){
        ll tmp=0;
        ll j=0;
        while(i+j<s.length()&&s[i+j]!='+'){
            tmp*=10;
            tmp+=s[i+j]-'0';
            j++;
        }
        i+=j;
        res.push_back(tmp);
    }
    return res;
}

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

    string s;
    cin>>s;

    for(int bit=0;bit<pow(2,s.length()-1);bit++){
        string t="";
        ll tmp=bit;
        while(tmp>0){
            t+=tmp%2+'0';
            tmp/=2;
        }
        while(s.size()>t.size()){
            t=t+'0';
        }
        reverse(t.begin(),t.end());
        
        string sti="";
        for(int i=0;i<s.length();i++){
            if(t[i]=='1'&&i!=0)sti+='+';
            sti+=s[i];
        }
        vector<ll> v=StI(sti);
        ans+=sum(v);
    }
    fin(ans);


//////////////////////////////////////////////////////
return 0;}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int R, G;
  cin >> R >> G;
  
  if(R < 0) {
    cout << "R(first input) must be greater than or equal to 0.";    
    return 0;
  }
  
  if(G > 4500) {
  	cout << "G(second input) must be smaller than or equal to 4500.";
    return 0;
  }

  cout << 2 * G - R << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, a, b = map(int, input().split())

    if (b - a) % 2 == 0:
        print("Alice")
    else:
        print("Borys")


if __name__ == '__main__':
    resolve()


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

char arr[1000000];

int main() {
    scanf("%s", arr);

    long long cb = 0, t = 0;
    for (char *p = arr; *p != '\0'; p++) {
        if (*p == 'W') t += cb;
        if (*p == 'B') cb++;
    }

    printf("%lld\n", t);
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  int n,i,j,count=0,ans=1000000000;
  cin >> n;
  for(i=0;i<n;i++){
    count = 0;
    cin >> j;
    while(j%2==0){
      if(j==0)break;
      j/=2;
      count++;
    }
    ans = min(ans,count);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int,vector<int>,greater<int>>
#define heap_max priority_queue<int>
#define printv(v) for(auto p : v) cout << p << " ";
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout << a[i] << " ";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
	int n,k;
	cin >> n >> k;
	int a[n];
	for(int i = 0 ; i < n ; i++){
		cin >> a[i];
	}
	int dp[k+1];
	memset(dp,0,sizeof(dp));
	for(int i = 0 ; i<=k ; i++){
		for(int val : a){
			if(i-val>=0 && dp[i-val]==0){
				dp[i] = 1;
				break;
			}
		}
	}
	if(dp[k]==1){
		cout << "First";
	}
	else{
		cout << "Second";
	}
}


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

int main() {
	// 코틀린 ,문자열 알고리즘 보기, 앳코더, (시간되면 코드포스까지)
	ios_base::sync_with_stdio(false); cin.tie(NULL); //9 90 900 
	ll x, y;  cin >> x >> y;
	ll sum = x + y;
	if (sum & 1) {
		cout << "IMPOSSIBLE" << '\n';
	}
	else {
		cout << sum / 2 << '\n';
	}





	
}

Measured memory_bytes: 256
from collections import deque

n = int(input())
graph_W = []
for _ in range(n):
    graph_W.append(list(map(int, input().split())))
    
num_root = [0]*n
work_queue = deque([])
visited = set()

work_queue.append(1)
visited.add(1)
cnt = 0
while work_queue:
    here = work_queue.popleft() - 1
    num_node = graph_W[here][1]
    cnt += 1
    if num_node == 0:
        continue
    for k in range(num_node):
        num_graph = graph_W[here][k+2]
        if num_graph not in visited:
            work_queue.append(num_graph)
            visited.add(num_graph)
            num_root[num_graph-1] = num_root[here] + 1


print(1,0)
for i in range(1,n):
    if num_root[i] != 0:
        print(i+1,num_root[i])
    else:
        print(i+1,-1)


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

int mat[105][105];

int main()
{
    int n;
    cin >> n;
    int m;
    cin >> m;
    int c;
    cin >> c;
    int a;
    cin >> a;
    int cnt = 1;
    for(int i = 0; i < n; ++i){
        if(i % 2 == 0) for(int j = 0; j < m; ++j){
                            if(a == 0){
                                cin >> a;
                                ++cnt;
                            }
                            mat[i][j] = cnt;
                            --a;
                       }
        else for(int j = m-1; j >= 0; --j){
                            if(a == 0){
                                cin >> a;
                                ++cnt;
                            }
                            mat[i][j] = cnt;
                            --a;
        }
    }

    for(int i = 0;i < n; ++i){
        for(int j = 0; j < m; ++j){
            cout << mat[i][j] << ' ';
        }

        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main { 
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  int n = sc.nextInt();
	  int[]a=new int[100];
	  for (int i=0 ;i<n ;i++) {
		  a[i]=sc.nextInt();
	  }
	  for (int i=n-1; i>0 ; i--) {
		  System.out.print(a[i]+" ");
	  }
	  
	
	  
	
	  System.out.println(a[0]);
	  
	  }
}



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

int main() {

    int a, b;
    cin >> a >> b;

    if (a%3 == 0 or b%3 == 0 or (a+b)%3 == 0) {
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e4+5;
ll n, h, a[A], c[A], memo[A];
ll dp(int curh)
{
	if (curh <= 0)
		return 0;
	if (~memo[curh])
		return memo[curh];
	ll val = 1e18;
	for (int i = 0; i < n; i++)
		val = min(val, c[i] + dp(curh - a[i]));
	return memo[curh] = val;
}
int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> h >> n;
	memset(memo, -1, sizeof memo);
	for (int i = 0; i < n; i++)
		cin >> a[i] >> c[i];
	cout << dp(h);
//	vector <pair<double , pair<ll, ll>>> v;
//	for (int i = 0; i < n; i++)
//	{
//		int a, c;
//		cin >> a >> c;
//		v.pb({a / (c*1.0), {a, c}});
//	}
//	sort(v.rbegin(), v.rend());
//	ll maxa = 1e9, minc = 1e9, ans = 0;
//	for (int i = 0; i < n; i++)
//	{
//		int ca = v[i].S.F, cc = v[i].S.S;
//		if (ca >= maxa)
//			continue;
//		else
//		{
//			ll eq = cc * (h / ca);
//			if (minc >= eq)
//			{
//				ans += cc * (h / ca), h = h % ca;
//				maxa = ca, minc = cc;
//			}
//		}
//	}
//	if (h)
//		ans += minc;
//	cout << ans;
	return 0;
}


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

int main(){
    int n, m, c; cin >> n >> m >> c;
    vector<int> b(m);
    for(int i = 0; i < m; i++)
        cin >> b[i];
    vector<vector<int>> a(n, vector<int>(m));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++)
            cin >> a[i][j];
    }

    int res = 0;
    for(int i = 0; i < n; i++){
        int sum = 0;
        for(int j = 0; j < m; j++)
            sum += a[i][j] * b[j];
        if(sum + c > 0)
            res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b=1;
string s;
signed main()
{
	cin>>a;
	while(1){
		if(b*b>a){
			cout<<(b-1)*(b-1);
			return 0;
		}
		b++;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
typedef complex<double> P;
typedef vector<P> L;
struct C{
    P p;
    double r;
};
const double INF = 1e10;
const double EPS = 1e-8;
int sign(double x) {
    if(x > EPS) return 1;
    if(x < -EPS) return -1;
    return 0;
}
vector<P> pCC(C a, C b) {
    vector<P> res;

    double d = abs(b.p - a.p);
    double l1 = abs(a.r - b.r);
    double l2 = a.r + b.r;
    if(sign(d) == 0 && sign(l1) == 0) assert(false);
    if(sign(d - l1) < 0 || sign(d - l2) > 0) return res;

    double th1 = arg(b.p - a.p);

    if(sign(d - l1) == 0 || sign(d - l2) == 0) {
        res = {a.p + polar(a.r, th1)};
    } else {
        double th2 = acos( (a.r * a.r - b.r * b.r + d * d) / (2 * a.r * d) );
        res.push_back( a.p + polar(a.r, th1 - th2) );
        res.push_back( a.p + polar(a.r, th1 + th2) );
    }
    return res;
}
double dot(P a, P b) {
    return real(conj(a) * b);
}
double cross(P a, P b) {
    return imag(conj(a) * b);
}
int ccw(P a, P b, P c) {
    b -= a;
    c -= a;
    return sign(cross(b, c)) ? : dot(b, c) < 0 ? 2 : norm(b) < norm(c) ? -2 : 0;
}

bool iSS(L s, L t) {
    auto ok = [](L a, L b) {
        return ccw(a[0], a[1], b[0]) * ccw(a[0], a[1], b[1]) <= 0; 
    };
    return ok(s, t) && ok(t, s);
}
int main() {
    int n;
    while(cin >> n && n) {
        vector<C> cs(n);
        REP(i, n) {
            double x, y, r;
            cin >> x >> y >> r;
            cs[i] = {{x, y}, r};
        }

        P cp[111][2] = {};
        cp[0][0] = cp[0][1] = cs[0].p;
        for(int i = 0; i + 1 < n; i++) {
            vector<P> v = pCC(cs[i], cs[i + 1]);
            REP(j, 2) {
                cp[i + 1][j] = v[j];
            }
        }
        cp[n][0] = cp[n][1] = cs[n - 1].p;

        double dp[111][2] = {};
        REP(i, n + 1) REP(j, 2) dp[i][j] = INF;
        dp[0][0] = dp[0][1] = 0;

        REP(i, n) REP(j, 2) if(dp[i][j] < INF) {
            P from = cp[i][j];
            for(int i2 = i + 1; i2 <= n; i2++) REP(k, 2) {
                P to = cp[i2][k];
                L path = {from, to};
                bool ok = true;
                for(int i3 = i + 1; i3 < i2; i3++) {
                    L hit = {cp[i3][0], cp[i3][1]};
                    if(!iSS(path, hit)) {
                        ok = false;
                    }
                }
                if(ok) {
                    dp[i2][k] = min(dp[i2][k], dp[i][j] + abs(from - to));
                }
            }
        }
        double ans = dp[n][0];
        printf("%.12f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1384
data class Double2D(val x: Double, val y: Double) {
  operator fun plus(o: Double2D): Double2D {
    return Double2D(x + o.x, y + o.y)
  }
  operator fun minus(o: Double2D): Double2D {
    return Double2D(x - o.x, y - o.y)
  }
  operator fun times(o: Double): Double2D {
    return Double2D(x * o, y * o)
  }
  fun norm2(): Double {
    return x * x + y * y
  }
  fun norm(): Double {
    return Math.sqrt(x * x + y * y)
  }
}

fun cross(v1: Double2D, v2: Double2D): Double {
  return v1.x * v2.y - v1.y * v2.x
}

fun dot(v1: Double2D, v2: Double2D): Double {
  return v1.x * v2.x + v1.y * v2.y
}

fun ccw(p: Double2D, q: Double2D, r: Double2D): Int {
  val vq = q - p
  val vr = r - p
  if (cross(vq, vr) > 0)   return +1     // counter clockwise
  if (cross(vq, vr) < 0)   return -1     // clockwise
  if (dot(vq, vr) < 0)     return +2     // r-p-q on line
  if (vq.norm2() < vr.norm2()) return -2 // p-q-r on line
  return 0
}

fun compareDouble2D(p1: Double2D, p2: Double2D): Int {
  if (p1.x != p2.x) {
    return java.lang.Double.compare(p1.x, p2.x)
  }
  return java.lang.Double.compare(p1.y, p2.y)
}

fun convexHull(inputPs: List<Double2D>): List<Double2D> {
  val ps = inputPs.sortedWith(java.util.Comparator { p1, p2 -> compareDouble2D(p1, p2) })
  val n = ps.size
  val qs = mutableListOf<Double2D>()
  for (i in 0 until n) {
    while (qs.size >= 2 &&
        // Use "<= 0" here to exclude a point on an edge.
        ccw(qs[qs.size - 2], qs[qs.size - 1], ps[i]) == -1) {
      qs.removeAt(qs.size - 1)
    }
    qs.add(ps[i])
  }
  val lowerHullSize = qs.size
  for (i in n - 2 downTo 0) {
    while (qs.size >= lowerHullSize &&
        // Use "<= 0" here to exclude a point on an edge.
        ccw(qs[qs.size - 2], qs[qs.size - 1], ps[i]) == -1) {
      qs.removeAt(qs.size - 1)
    }
    qs.add(ps[i])
  }
  qs.removeAt(qs.size - 1)
  return qs
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  // No List(n, {}) constructor for Kotlin 1.0.
  val ps = Array(n, {
    val (x, y) = readLine()!!.split(" ").map(String::toInt)
    Double2D(x.toDouble(), y.toDouble()) })
      .asList()
  val qs = convexHull(ps)
  val m = qs.size
  val args = mutableMapOf<Double2D, Double>()
  for (i in 0 until m) {
    val qm = qs[i]
    val qp = qs[(i + (m - 1)) % m]
    val qn = qs[(i + 1) % m]
    val v1 = qn - qm
    val v2 = qp - qm
    val cos_theta = dot(v1, v2) / v1.norm() / v2.norm()
    val theta = Math.acos(cos_theta)
    args[qs[i]] = Math.PI - theta
  }
  for (p in ps) {
    if (args.containsKey(p)) {
      val arg = args[p]!!
      println(String.format("%.9f", arg / (2.0 * Math.PI)))
    } else {
      println(0.0)
    }
  }
}

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

        String str = scanner.next();
        int q = scanner.nextInt();

        int a, b;
        String op, p;
        StringBuffer sb;
        for(int i = 0; i < q; i++){
            op = scanner.next();
            a = scanner.nextInt();
            b = scanner.nextInt();

            if(op.equals("replace")){
                p = scanner.next();
                sb = new StringBuffer(str);
                sb = sb.replace(a, b+1, p);
                str = sb.toString();
            }
            else if(op.equals("reverse")){
                sb = new StringBuffer(str.substring(a, b+1));
                sb = sb.reverse();
                p = sb.toString();
                sb = new StringBuffer(str);
                sb = sb.replace(a, b+1, p);
                str = sb.toString();

            }

            else if(op.equals("print")){
                System.out.println(str.substring(a, b+1));
            }
        }

    }
}



Measured memory_bytes: 29444
#include <bits/stdc++.h>
using namespace std; 
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define ld long double
#define fi first 
#define se second 
#define mp make_pair
#define pb push_back
#define ull unsigned long long int
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define mo 1000000007
ll gcd(ll a ,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll poww(ll a,ll n){if(n==0)return 1;ll p=poww(a,n/2);p=(p*p)%mo;if(n%2)p=(a*p)%mo;return p;}
////////////////////////////////////////////////////

void solve()
{  int k ; cin>>k; 
  queue<pair<ll,int> > q; 
  for(int i = 1; i<=9; i++)
  q.push(mp(i,i)); 
  int cur = 9; 
  while(true)
  {
  	ll x = q.front().fi;
  	int y = q.front().se;
  //	cout<<x<<" "<<y<<endl; 
  	if(y==k)
  	{
  		cout<<x<<endl;return; 
	  }
	  q.pop(); 
	  ll rem = x%10; 
	  
	  x = x*10; 
	  if(rem!=0)
	  { 
	  	cur++; 
	  	//if(cur==35||cur==36)
	  	//cout<<x<<"*"<<cur<<" "<<rem<<endl;
	  	q.push(mp(x+rem-1,cur));
	  }
	  
	  cur++; 
	// if(cur==35||cur==36)
	  	//cout<<x<<"&"<<cur<<endl;
	  q.push(mp(x+rem,cur));
	  if(rem!=9)
	  { 
	  
	  	cur++;
	  	// if(cur==35||cur==36)
	  	//cout<<x<<"^"<<cur<<endl;
	  	q.push(mp(x+rem+1,cur));
	  }
  }
  
}

int main()
{ ios; 

 int t; t=1;
 while(t--)
	solve(); 
	return 0 ; 
}

Measured memory_bytes: 3456
import java.util.*;

public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int p = sc.nextInt();
        int ans = 0;
        
        ans = (a*3 + p) / 2;
       
        System.out.println(ans);
        
     
       
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int dy[] = {1, 1, 0, -1, -1, 0};
    int dx[] = {1, 0, -1, -1, 0, 1};

    for(;;){
        int t, n;
        cin >> t >> n;
        if(t == 0)
            return 0;

        vector<int> y(n), x(n);
        for(int i=0; i<n; ++i)
            cin >> x[i] >> y[i];

        int y0, x0;
        cin >> x0 >> y0;
        vector<vector<bool> > check(2*t+1, vector<bool>(2*t+1, false));
        for(int i=0; i<n; ++i){
            int y1 = y[i] - y0 + t;
            int x1 = x[i] - x0 + t;
            if(0 <= y1 && y1 < 2*t+1 && 0 <= x1 && x1 < 2*t+1)
                check[y1][x1] = true;
        }

        queue<pair<int, int> > q;
        q.push(make_pair(t, t));
        check[t][t] = true;
        int ret = 1;
        while(--t >= 0){
            queue<pair<int, int> > q2;
            while(!q.empty()){
                int y, x;
                y = q.front().first;
                x = q.front().second;
                q.pop();
                for(int i=0; i<6; ++i){
                    int y1 = y + dy[i];
                    int x1 = x + dx[i];
                    if(!check[y1][x1]){
                        check[y1][x1] = true;
                        q2.push(make_pair(y1, x1));
                        ++ ret;
                    }
                }
            }
            q = q2;
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 940
#include <stdio.h>


void merge(int *,int,int,int);
void mergeSort(int *,int,int);

int count;
int main(){
  int n;
  int i;
  
  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  mergeSort(S,0,n);

  for(i=0;i<n-1;i++){
    printf("%d ",S[i]);
  }

  printf("%d\n%d\n",S[n-1],count);
  return 0;

}


void mergeSort(int *A,int left,int right){
  int mid;
  if(left+1 < right){
    mid = (left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }

}

void merge(int *A,int left,int mid,int right){
  int i,k,j;
  int n1=mid-left;
  int n2=right-mid;
  int L[n1+1];
  int R[n2+1];
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }


  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
 
  }


  L[n1]=1000000000;
  R[n2]=1000000000;
  i=0;
  j=0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      count++;
      i=i+1;
    }
    else{
      A[k]=R[j];
      j=j+1;
      count++;
    }

  }
}

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

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define FORR(i,a,b) for(int i=(int)(b)-1; i>=(int)(a); i--)

using pii = pair<int,int>;
using pid = pair<int,double>;

double po(set<pid> S, int x){
  double ans = 0;
  for(pid P : S){
    int i = P.first;
    double y = P.second;
    for(pid Q : S){
      int j = Q.first;
      if(i != j){
        y *= 1.0 * (j-x) / (j-i);
      }
    }
    ans += y;
  }
  return ans;
}

int main(){
  while(true){
    int n;
    scanf("%d", &n);
    if(n==0)break;
    vector<pid> vv;
    set<pid> S;
    REP(i,n+3){
      double v;
      scanf("%lf", &v);
      vv.push_back(pid(i,v));
      S.insert(pid(i,v));
    }
    REP(i,n+3){
      pid er = vv[i];
      S.erase(er);
      pid P = *S.begin(); S.erase(P);
      double ch = po(S,P.first);
      if(abs(ch - P.second) < 1e-2){
        // found
        printf("%d\n", i);
        break;
      }else{
        // printf("i=%d -> (%d,%.5f) vs %.5f\n", i, P.first, P.second, ch);
        S.insert(er);
        S.insert(P);
      }
    }
  }
  return 0;
}




Measured memory_bytes: 3160
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

vector<int> vertexs[200000];
int back[200000];
void dfs(int now) {
    for (auto x : vertexs[now]) {
        back[x] = now;
        dfs(x);
    }
}
int color[200000];
int union_tree[200000];
int union_find(int a) {
    if (union_tree[a] == a) return a;
    return union_tree[a] = union_find(union_tree[a]);
}
void solve(){
    while (true) {
        int n, query;
        cin >> n >> query;
        if (n == 0) return;
        REP(i, n + 1) {
            vertexs[i].clear();
            color[i] = 1e9;
        }
        REP(i, n - 1) {
            int a;
            cin >> a;
            a--;
            vertexs[a].push_back(i + 1);
        }
        dfs(0);
        vector<pair<int, int>>inputs;
        REP(i, query) {
            string a;
            int b;
            cin >> a >> b;
            b--;
            if (a == "Q") {
                inputs.push_back(mp(0, b));
            }
            else {
                color[b] = min(color[b], i);
                inputs.push_back(mp(1, b));
            }
        }
        REP(i, n) {
            union_tree[i] = i;
            if (color[i] == 1e9) {
                union_tree[i] = back[i];
            }
        }
        int ans = 0;
        for (int q = query - 1; q >= 0; --q) {
            if (inputs[q].first == 1) {
                if (color[inputs[q].second] == q) {
                    color[inputs[q].second] = 1e9;
                    union_tree[inputs[q].second] = back[inputs[q].second];
                }
            }
            else {
                ans += union_find(inputs[q].second) + 1;
            }
        }
        cout << ans << endl;
    }
}

#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 21564
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n, m; cin >> n >> m;
    vector<vector<int>> adj(n + 10);
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
    }
    vector<int> ans;
    for (int i = 1; i <= n; i++) {
        vector<int> pa(n + 10, 0);
        queue<int> q;
        for (int v : adj[i]) {
            q.push(v);
            pa[v] = i;
        }
        while (!q.empty()) {
            int v = q.front(); q.pop();
            if (v == i) {
                vector<int> all;
                all.push_back(i);
                v = pa[i];
                while (v != i) {
                    all.push_back(v);
                    v = pa[v];
                }
                if (ans.empty() || SZ(ans) > SZ(all)) {
                    ans = all;
                }
            }
            for (int u : adj[v]) {
                if (!pa[u]) {
                    pa[u] = v;
                    q.push(u);
                }
            }
        }
    }
    if (ans.empty()) {
        cout << "-1\n";
        exit(0);
    }
    cout << SZ(ans) << "\n";
    for (int x : ans) {
        cout << x << "\n";
    }
}


Measured memory_bytes: 512
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}


int main() {
	ll a, b;
	cin >> a >> b >> h >> m;
	double res = 0;
	double ho = h * 30 + m * 0.5;
	double mo = m * 6;
	double p = max(ho, mo);
	double q = min(ho, mo);
	double ra = p - q;
	if (ra > 180) {
		ra = 360 - ra;
	}
	//cout << ra << endl;
	res = sqrt(a * a + b * b - 2 * a * b * cos((ra/180)*3.1415926535));
	cout << setprecision(15) << res << endl;
}

Measured memory_bytes: 4152
n,t=map(int,input().split())
a=list(map(int,input().split()))
ma=[0]*n
ma[n-1]=a[n-1]
for i in range(n-2,-1,-1):
  ma[i]=max(ma[i+1],a[i])
plus=[0]*n
for j in range(n):
  plus[j]=ma[j]-a[j]
plusm=max(plus)
print(plus.count(plusm))

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

main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
long long i,j,k,l,m,n,p,q;
char s1[100],s2[1000];
while(cin>>m>>n>>p>>q){
    i=0;
    if(m<=q){
        i+=m;
        q-=m;
    }
    else {i+=q; q=0;}
    if(q>0){
        if(q>=n)q-=n;
        else q=0;
    }
    if(q>0){
        if(q>=p)i+=(-1*p);
        else i+=(-1*q);
    }
    cout<<i<<endl;
}
return 0;
}


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

int main() {
    int h, w, n, nokori, paint, count = 0;
    cin >> h >> w >> n;
    nokori = n;
    paint = max(h, w);
    while(nokori > 0){
        nokori -= paint;
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
all=int(0)
for i in range(n):
    all+=A[i]

m=int(input())
for i in range(m):
    p,x=map(int,input().split())
    all-=A[p-1]
    all+=x
    print(all)
    all-=x
    all+=A[p-1]

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll x;
    cin >> x;
    ll k = 100;
    int count = 0;
    while(k < x)
    {
        k *= 1.01;
        count++;
    }
    cout << count << endl;
}



Measured memory_bytes: 3632
#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;
static const int INF (1<<30);

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

  ll ans = (b / x) - (a / x);
  if (a % x == 0LL) ans++;
  //if (ans == 0LL && a % x == 0LL) ans++;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256