akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        t: f64,
        x: f64,
    }
    println!("{}", t / x);
}


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

def main():
    S=set(input())
    YesNo(len(S)%2==0 and (('N' in S and 'S' in S) or ('W' in S and 'E' in S)))

if __name__ == '__main__':
    main()


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, K;
	cin >> N >> K;
	vector<int64> A(N);
	REP(i, N) cin >> A[i];

	int64 l = 0, r = INF+1, m;
	while (r - l > 1) {
	  m = (l + r) >> 1;
	  int64 cnt = 0;
	  REP(i, N) {
	    cnt += (A[i] - 1) / m;
	  }
	  if (cnt <= K) r = m;
	  else l = m;
	}
	cout << r << endl;
}


Measured memory_bytes: 4784
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int a = scn.nextInt();
        int b= scn.nextInt();
        int answer = a+b;
        answer = Math.max(answer, a*b);
        answer = Math.max(answer,a-b);
        System.out.println(answer);
    }
}


Measured memory_bytes: 21844
import math
N = int(input())
S = []
for i in range(N):
    s = input()
    s = sorted(s)
    S.append(''.join(s))
S = sorted(S)
cnt = 0
ans = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        if cnt > 0:
            ans += math.factorial(cnt+1) // (math.factorial(cnt + 1 - 2) * math.factorial(2))
        cnt = 0
if cnt > 0:
    ans += math.factorial(cnt+1) // (math.factorial(cnt + 1 - 2) * math.factorial(2))
print(ans)


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n, k;
    string s;
    cin >> n >> k >> s;

    int cnt = 0;
    rep(i, 1, n) {
        if (s[i - 1] != s[i]) { ++cnt; }
    }
    cout << n - max(0, cnt - 2 * k) - 1 << endl;

    return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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 ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ll x=n/i;
        ans+=i*x*(x+1)/2;
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3648
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;

void solver_main()
{
	int n, q;
	double sum = 0;
	cin >> n >> q;
	vector<vector<int>> v(n + 1);
	vector<int> cnt(n + 1,0);
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		v[a].push_back(b);
	}

	for (int i = 0; i < q; i++) {
		int p, x;
		cin >> p >> x;
		cnt[p] += x;
	}

	int vx = 1;
	queue<int> fs;
	fs.push(1);
	while (!fs.empty()) {
		vx = fs.front();
		fs.pop();
		for (int i = 0; i < v[vx].size(); i++) {
			fs.push(v[vx][i]);
			cnt[v[vx][i]] += cnt[vx];
		}
	}

	for (int i = 1; i < cnt.size() - 1; i++) {
		cout << cnt[i] << " ";
	}
	cout << cnt[cnt.size() - 1] << endl;

}

int main(void)
{
	solver_main();
	return 0;
}

Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll s ;
ll r,c;
int main(){		
	cin >> r >> c;
	if(r==1 || c==1) {
		s=1;
	} 
	
	else if(r%2==0) {
		s = r/2 * c;
	}else {
		s = r/2 *c + (c+1)/2;
	}
	cout << s;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;

int main(){
    int N;
    cin >> N;
    int h[N+1];
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }
    h[N] = 0;
    //
    int count = 0;
    int done = 0;
    while(done != 1){
        int start = 0;
        int pcount = count;
        for(int i = 0; i < N; i++){
            if(h[i] >= 1){
                if(start == 0){
                    start = 1;
                    count++;
                }
                h[i]--;
            }else{
                start = 0;
            }
        }
        if(pcount == count){
            cout << count << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)


def recursion_g(eges, length, f):
    if length[f] != -1:
        return length[f]
    if not eges[f]:
        length[f] = 0
        return 0
    memo = []
    for t in eges[f]:
        memo.append(recursion_g(eges, length, t) + 1)
    length[f] = max(memo)
    return length[f]


def p_g():
    N, M = map(int, input().split())
    edges = [[] for _ in range(N)]
    length = [-1] * N
    for _ in range(M):
        x, y = map(int, input().split())
        edges[x - 1].append(y - 1)

    for i in range(N):
        recursion_g(edges, length, i)
    print(max(length))


if __name__ == '__main__':
    p_g()


Measured memory_bytes: 64688
#include <iostream>

#include <string>


using namespace std;

int N;

int main()
{
	cin >> N;


	int ac = 0;
	int wa = 0;
	int tle = 0;
	int re = 0;


	for (int i = 0;i<N;i++) {
		string s;

		cin >> s;

		if (s == "AC") {
			ac++;
		}
		else if (s == "WA") {
			wa++;
		}
		else if (s == "TLE") {
			tle++;
		}
		else {
			re++;
		}

	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;


	return 0;
}



Measured memory_bytes: 3232
#include <iostream>
#include <string>
using namespace std;
int main(){
    bool flag = true;
    int n;
    string S;
    cin >> S;
    n = S.size();
    for (int i=0; i<n/2; i++){
        if (S[i]!=S[n-1-i]) flag=false;
    }
    int right=0;
    int left=(n-1)/2 - 1;
    while (true){
        if(right>=left) break;
        if(S[right]!=S[left]) flag=false;
        right++;
        left--;
    }
    right=(n+3)/2-1;
    left=n-1;
    while (true){
        if(right>=left) break;
        if(S[right]!=S[left]) flag=false;
        right++;
        left--;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int a,b,c,d,takahashiAttack,aokiAttack;

int main(){
	cin>>a>>b>>c>>d;
	if(c % b == 0){
	takahashiAttack = c / b;
	}
	else{
		takahashiAttack = c / b + 1;
	}
	if(a % d == 0){
		aokiAttack = a / d;
	}
	else{
		aokiAttack = a / d + 1;
	}
	if(takahashiAttack > aokiAttack){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
	}
}


Measured memory_bytes: 3596
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

void dfsao(int pos, int dist);
void dfsta(int pos, int dist);

vector< int > tree[SIZE];
int di[SIZE];
bool vis[SIZE];
int mxdi, mxpos;

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

    int n;
    cin >> n;
    int ta, ao;
    cin >> ta >> ao;
    for( int i = 0; i < n - 1; ++i ) {
        int a, b;
        cin >> a >> b;
        tree[a].pb(b);
        tree[b].pb(a);

    }
    for( int i = 0; i < SIZE; ++i ) di[i] = INF;
    mxpos = ta;
    dfsao(ao, 0);
    for( int i = 0; i < SIZE; ++i ) vis[i] = false;
    mxdi = di[ta];
    dfsta(ta, 0);
    
    /*
    for( int i = 1; i <= n; ++i ) {
        cout << i << " " << di[i] << endl;
    }
    */

    cout << di[mxpos] - 1 << endl;
    return 0;
}

void dfsao(int pos, int dist) {
    if( vis[pos] ) return;
    vis[pos] = true;
    if( di[pos] <= dist ) return;
    di[pos] = dist;
    for( int i = 0; i < tree[pos].size(); ++i ) {
        if( di[tree[pos][i]] <= dist + 1 ) continue;
        dfsao(tree[pos][i], dist + 1);

    }
    return;

}

void dfsta(int pos, int dist) {
    if( vis[pos] ) return;
    vis[pos] = true;
    if( di[pos] <= dist ) return;
    if( mxdi < di[pos] ) {
        mxdi = di[pos];
        mxpos = pos;

    }

    for( int i = 0; i < tree[pos].size(); ++i ) {
        dfsta(tree[pos][i], dist + 1);

    }
    return;

}



Measured memory_bytes: 10112
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	String code(int t){
		int h = t/(60*60);
		t%=(60*60);
		int m = t/60;
		int s = t%60;
		
		String ret = "";
		if(h < 10){
			ret += "0";
		}
		ret += h;
		ret += ":";
		if(m < 10){
			ret += "0";
		}
		ret += m;
		ret += ":";
		if(s < 10){
			ret += "0";
		}
		ret += s;
		return ret;
		
	}
	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}

			int d[][] = new int[n][3];
			boolean z[][] = new boolean[n][60 * 60 * 12];

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < 3; j++) {
					d[i][j] = sc.nextInt();
				}
			}

			int t = 0;
			for (int h = 0; h < 12; h++) {
				for (int m = 0; m < 60; m++) {
					for (int s = 0; s < 60; s++) {
						int hd = h * 5 + m / 12;

						int hh[] = { 0, 0, 1, 1, 2, 2 };
						int mm[] = { 1, 2, 2, 0, 1, 0 };
						int ss[] = { 2, 1, 0, 2, 0, 1 };
						for (int i = 0; i < n; i++) {
							boolean ok = false;
							for (int j = 0; j < 6; j++) {
								if ((d[i][mm[j]] - d[i][hh[j]] + hd - m) % 60 == 0) {
									if ((d[i][ss[j]] - d[i][hh[j]] + hd - s) % 60 == 0) {
										ok = true;
									}
								}
							}
							if(ok){
//								System.out.println(i+" "+t);
								z[i][t] = true;
							}
						}
						t++;
					}
				}
			}

			int length = Integer.MAX_VALUE;
			
			int start = 0;
			int end = 0;
			
			int ansStart = 0;
			
			int count[] = new int[n];
			
			
			for(;end <= 60*60*12;){
				boolean ok = true;
				for(int i = 0; i < n ; i++){
					if( count[i] == 0){
						ok = false;
					}
				}
				if(ok){
					if(length > end - start -1 ){
						length = end - start-1;
						ansStart = start;
					}
				}
				
				if(ok){
					for(int i = 0; i < n ; i++){
						if(z[i][start]){
							count[i]--;
						}
					}
					start++;
					
					
				}else{
					if(end >= 60*60*12){
						break;
					}
					for(int i = 0; i < n ; i++){
						if(z[i][end]){
//							System.out.println(i+":"+end+"here");
							count[i]++;
						}
					}
					end++;
				}
			}
			
			System.out.println(code(ansStart )+" "+ code(ansStart+length));
		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

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

def main():
    s=input()
    K=int(input())
    l=[]
    for i in range(len(s)):
        for j in range(1,K+1):
            if i+j>len(s):
                continue
            l.append(s[i:i+j])
    l=list(set(l))
    l.sort()
    print(l[K-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 40944
from math import *

n,m=map(int,input().split(" "))

l=[0]*n
r=[0]*n

for i in range(m):
	s=input().split(" ")
	l[int(s[0])-1]+=1
	r[int(s[1])-1]+=1



i=0

c=0
tmp=0

while(i<n):
	tmp+=l[i]
	if(tmp>=m):
		c+=1
	tmp-=r[i]
	i+=1

print(c)

Measured memory_bytes: 4596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector< vector<int> > num(26, vector<int>(n));
    for(int i=0; i<n; i++) {
        string S;
        cin >> S;
        for(int j=0; j<S.size(); j++) {
            num[S[j]-'a'][i]++;
        }
    }

    char c = 'a';
    for(auto e: num) {
        int m = *min_element(e.begin(), e.end());
        while(m--) {
            cout << c;
        }
        ++c;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int S = s.nextInt();
        int h = S/3600;
        S %= 3600;
        int m = S/60;
        S %= 60;
        System.out.println(h+":"+m+":"+S);
    }
}


Measured memory_bytes: 26356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M  =2e5+23;
char v[M];
int T,n;
ll dp[103][M];
int a[M], w[M];
ll go (int i ,int W) {
    if (i==n || W==0) return 0;
    ll &ret = dp[i][W];
        if (ret+1)return ret;
    ret = -1;
    if (W - w[i]  >= 0 )
        ret = go(i+1,W-w[i])+a[i];
    ret = max( go(i+1,W),ret );
    return ret;
}
int s;
int main () {
    memset(dp,-1,sizeof dp);
    scanf("%d %d",&n,&s);
    for (int i=0;i<n;i++)
        scanf("%d %d",w+i,a+i);
    cout <<go (0,s);
}


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

using namespace std;

int N,K;

int main(){
  cin >> N >> K;
  vector<long long> h(N);
  for(int i = 0; i<N; i++){
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  long long ans = INT_MAX;
  for(int i = 0; i <= N - K; i++){
    ans = min(ans, h[i+K-1] - h[i]);
  }
  cout << ans;
}

Measured memory_bytes: 1024
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
if n == 1:
	print(0)
	exit()
l = factorization(n)

ans = 0
for i in range(len(l)):
	num = l[i][1]
	tmp = 1
	count = 0
	while True:
		if num < 0:
			ans += count - 1
			break
		num -= tmp
		tmp += 1
		count += 1
print(ans)


Measured memory_bytes: 9440
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9+5;

void solve(){
    int n,k;
    cin>>n>>k;
    vector<int>a(n),dp(n,INF);
    for(int i=0;i<n;i++){
        cin>>a[i];        
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=(i+k);j++){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}

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

Measured memory_bytes: 1024
declare var require: (x: string) => any;

function Main(input: string[]) {
  const r = parseInt(input[0]);

  console.log((r < 1200) ? 'ABC' : (r < 2800) ? 'ARC' : 'AGC');
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'));


Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
int main(void){
    ll n;
    cin >> n;
    vector<vector<ll>> g(n+1);
    map<p, ll> I{};
    for(ll i = 0; i < n-1; i++){
        ll a, b, c;
        cin >> a >> b >> c;
        I[p(a, b)] = c;
        g[a].push_back(b);
        g[b].push_back(a);
        I[p(a,b)] = I[p(b,a)] = c;
    }
    vector<ll> use(n+1, -1);
    vector<ll> ans(n+1, 0);
    use[1] = 0;
    ans[1] = 0;
    queue<ll> que;
    que.push(1);
    ll MAX = 0;
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(ll nv : g[v]){
            if(use[nv]!=-1) continue;
            if(I[p(v,nv)]%2!=0) ans[nv] = ans[v]+1;
            else ans[nv]=ans[v];
            que.push(nv);
            use[nv] = 1;
            MAX = max(MAX, ans[nv]);
        }
    }
    if(MAX%2==0){
        for(ll i = 1; i <= n; i++){
            if(ans[i]%2==0) cout << '1' << endl;
            else cout << '0' << endl;
        }
    }
    if(MAX%2!=0){
        for(ll i = 1; i <= n; i++){
            if(ans[i]%2==0) cout << '0' << endl;
            else cout << '1' << endl;
        }
    }
    return 0;
}


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

using namespace std;

int main()
{
    long long int n,m,sum=0,count=0;
    float c;
    cin>>n>>m;
    long long int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
    }
    c=(1/(4.0*m))*sum;
    for(int i=0;i<n;i++)
    {
        if(a[i]>=c)
            count=count+1;

    }
    if(count>=m)
        cout<<"Yes";
    else
        cout<<"No";


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const ll maxS = 1e6 + 5;
 
int main(){
    ll prime[maxS];
    memset(prime , -1 , sizeof(prime));
    
    for(ll i = 2; i*i <= maxS; i++){
        if(prime[i] == -1){
            for(ll j = 2*i; j < maxS; j += i){
                prime[j] = i;
            }
        }
    }
    
    ll n;
    cin>>n;
    ll a[n];
    for(int i = 0; i < n; i++){
        cin>>a[i];
    } 
    
    map<ll , ll>m;
    ll allGcd = a[0] , flag = 0;
    
    for(int i = 0; i < n; i++){
        ll temp = a[i];
        while(temp != 1){
            ll no;
            if(prime[temp] == -1){
                no = temp;
            }
            else{
                no = prime[temp];
            }
            if(m.find(no) != m.end()){
                flag = 1;
                break;
            }
            // cout<<temp<<" "<<no<<" ";
            m[no]++;
            while(temp % no == 0){
                temp /= no;
            }
            
        }
        if(flag == 1){
            break;
        }
    }
    for(int i = 0; i< n; i++){
        allGcd = __gcd(allGcd ,  a[i]);
    }
    if(flag){
        if(allGcd == 1){
            cout<<"setwise coprime\n";
        }
        else{
            cout<<"not coprime\n";
        }
    }
    else{
        cout<<"pairwise coprime\n";
    }
}
        

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

typedef long long int64;
const int MOD = 1e9 + 7;
const int MAX = 3e5 + 5;
int n, a, b;
int64 f[MAX];

int64 exp(int64 a, int64 n) {
	int64 ans = 1;
	while(n > 0) {
		if(n % 2LL == 1LL)
			ans = ans * a % MOD;
			
		a = a * a % MOD;
		n /= 2LL;
	}
	
	return ans;
}

int64 comb(int n, int k) {
	int64 ans = 1;
	for(int i = 0; i < k; i++)
		ans = 1LL * ans * (n - i) % MOD;

	ans = 1LL * ans * exp(f[k], MOD - 2) % MOD;
	return ans;
}

int main() {
	scanf("%d%d%d", &n, &a, &b);

	f[0] = 1;
	for(int i = 1; i <= 2e5; i++)
		f[i] = 1LL * f[i - 1] * i % MOD;

	int64 ans = (exp(2, n) - 1 + MOD) % MOD;

	ans = (ans - comb(n, a) + MOD) % MOD;
	ans = (ans - comb(n, b) + MOD) % MOD;

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
N = list(map(int, str(input())))
K = int(input())

flag = 1
i = -1

while (flag == 1) : 
    i += 1
    
    if N[i] == 1 : 
        if K > 1 : 
           K = K -1
        else : 
            print(1)
            flag = 0
    else : 
        print(N[i])
        flag = 0

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    static List<int[]>[] to;
    static long[] dist;
    static int n;
    
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        
        // to: 隣接リスト(無向)
        to = new List[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<int[]>();
        }
        for (int i = 0; i < n - 1; i++) {
            int p = sc.nextInt() - 1;
            int q = sc.nextInt() - 1;
            int dis = sc.nextInt();
            to[p].add(new int[]{q, dis});
            to[q].add(new int[]{p, dis});
        }
        
        // dist: kから各点への最短距離
        int query = sc.nextInt();
        int k = sc.nextInt() - 1;
        long[] distK = calcDist(k);
        
        // p→k→qの最短距離を出力
        while (query-- > 0) {
            int p = sc.nextInt() - 1;
            int q = sc.nextInt() - 1;
            
            System.out.println(distK[p] + distK[q]);
        }
    }
    
    public static long[] calcDist(int p) {
        dist = new long[n];
        dfs(p, 0, -1);
        return dist;
    }
    
    // 子qに、「pまでの距離+qへの距離」を配る
    public static void dfs(int p, long d, int par) {
        
        for (int[] qData : to[p]) {
            int q = qData[0];
            int PtoQ = qData[1];
            if (q == par) continue;
            dist[q] = d+PtoQ;
            
            dfs(q, d + PtoQ, p);
        }
    }
}


Measured memory_bytes: 181292
#include<stdio.h>
#include<string.h>
char ch[101];
int a[101];
int main()
{
	scanf("%s",ch);
	int len=strlen(ch);
	for(int i=0;i<len;i++)
	{
		a[ch[i]-'a']++;
	 } 
	 int i;
	 for( i=0;i<30;i++)
	 {
	 	if(a[i]>1)
	 	break;
	 }
	 if(i>26)
	 printf("yes\n");
	 else
	 printf("no\n");
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace contest_Csharp
{

    class Program
    {
        public static (long m, long s)[,] dp;
        public static long mod;
        
        public static List<int> getprimes(int n)
        {
            var result = new List<int>();
            result.Add(2);
            int i = 3;
            while (result.Last() <= n)
            {
                var flg = true;
                foreach(var p in result)
                {
                    if (i % p == 0)
                    {
                        flg = false;
                    } 
                }
                if (flg)
                    result.Add(i);
                i = i + 2;
            }
            return result;
        }
        static void Main(string[] args)
        {
            checked
            {
                var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
                Console.SetOut(sw);

                var vals = Console.ReadLine().Split(' ').
                    Select(x => int.Parse(x)).ToList();


                var N = vals[0];



                var ans = (1 - N);
                
                Console.WriteLine(ans);

                Console.Out.Flush();
            }//cheked




        }
        static long gcd(long a, long b)
        {
            long large = Math.Max(a, b);
            long small = Math.Min(a, b);
            while (large % small != 0)
            {
                var S = small;
                small = large % small;
                large = S;
            }
            return small;
        }
    }

}




Measured memory_bytes: 28304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200003,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,N;cin>>H>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    ll sum=0;
    
    for(int i=0;i<N;i++) sum+=A[i];
    
    if(sum>=H) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}




Measured memory_bytes: 640
#include<bits/stdc++.h>                                                                                                                                                                                     
using namespace std;
int main(){
  int N,i,alice_score=0,bob_score=0,max=0,judge=0;
  cin >> N;
  vector<int> a(N);
  for(i=0; i<N; i++)
    cin >> a.at(i);
  while(1){
    for(i=0; i<N; i++){
      if(max<a.at(i))
        max=a.at(i);
    }
    alice_score+=max;
    for(i=0; i<N; i++){
      if(max==a.at(i)){
        a.at(i)=0;
        break;
      }
    }
    max=0;
    for(i=0; i<N; i++){
      if(max<a.at(i))
        max=a.at(i);
    }
    bob_score+=max;
    for(i=0; i<N; i++){
      if(max==a.at(i)){
        a.at(i)=0;
        break;
      }
    }
    max=0;
    for(i=0; i<N; i++)
      judge+=a.at(i);
    if(judge==0)
      break;
    else
      judge=0;
  }
  cout << alice_score-bob_score << endl;
}

Measured memory_bytes: 256
#include<vector>
#include<list>
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int dfs(int v,vector<int>& seen,vector<int>& prt,
	const vector<vector<int>>& adj){
  seen.at(v)=1;
  for(const int& x: adj.at(v)){
    if(df)printf("serach %d->%d(%d)\n",v,x,seen.at(x));
    if(seen.at(x)==-1)continue;
    prt.at(x)=v;
    if(seen.at(x)==1) return x;
    int flag=dfs(x,seen,prt,adj);
    if(flag!=-1)return flag;
  }
  seen.at(v)=-1;
  return -1;
}

int main(){
  if(df) printf("*debug mode*\n");
  int n,m; cin >>n >>m;
  vector<vector<int>> adj(n);
  rep(i,m){
    int u,v; cin >>u >>v; u--;v--;
    adj.at(u).push_back(v);
  }
  if(df){
    rep(i,n){
      printf("%d:",i);
      for(const int& x:adj.at(i)){
	printf(" %d",x);
      }
      printf("\n");
    }
  }
  vector<int> seen(n,0),prt(n,-1);
  int flag=-1,cnt=0;
  while(flag==-1){
    int x=0;
    while(x<n and seen.at(x))x++;
    if(x==n){
      printf("-1");
      return 0;
    }
    flag=dfs(x,seen,prt,adj);
    if(df)printf("%d:%d\n",x,flag);
  }
  
  if(df){
    for(int x: prt){
      printf("%d ",x);
    }
    printf(":prt\n");
  }
  vector<int> able(n,0);
  int x=flag;
  do{
    if(df)printf("%d ",x);
    able.at(x)=1;
    x=prt.at(x);
  }while(x!=flag);
  if(df)printf(":cycle\n");

  seen=vector<int>(n,0);

  x=flag;
  do{
    for(int v: adj.at(x)){
      if(able.at(v)==0)continue;
      if(prt.at(v)==x)continue;
      int temp=prt.at(v);
      flag=x;
      while(temp!=x){
	able.at(temp)=0;
	temp=prt.at(temp);
      }
      prt.at(v)=x;
    }
    x=prt.at(x);
  }while(x!=flag);


  int c=0;
  x=flag;
  do{
    c++;
    x=prt.at(x);
  }while(x!=flag);
  printf("%d\n",c);
  do{
    printf("%d\n",x+1);
    x=prt.at(x);
  }while(x!=flag);
  
}

/// confirm df==0 ///


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   /// https://ideone.com/Fd5s8n
  int k;
  cin>>k;
  ll ans =0;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
        for(int g=1;g<=k;g++){
            ans+=__gcd(i,(__gcd(j,g)));
            ///cout << i << " " << j << " " << g << endl;
        }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <map>

using namespace std;
#define ll long long
#define pb push_back

int main() {
  int n, m,j=0;
  string a;
  cin >> n;
  map<string, int> bc;
  for(int i = 0; i < n; i++){
      cin >> a;
      bc[a]++;
  }
  cin >> m;
  vector<string> rc(m);
  for(int i = 0; i < m; i++){
      cin >> a;
      bc[a]--;
  }
  int maxnum= 0;

  for (auto i : bc) {
		maxnum = max(maxnum,i.second);
	}

  cout << maxnum << endl;

}


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

using namespace std;

int main(){

    string s;
    cin >> s;

    int bw = 0, wb = 0;
    for(int i=0;i<s.length();i++){
        if(i%2==0){
            if(s[i]=='0')wb++;
            else bw++;
        }else{
            if(s[i]=='0')bw++;
            else wb++;
        }
    }
    cout << min(wb,bw) << endl;;
}


Measured memory_bytes: 512
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    lint n;
    cin >> n;
    vec a(5);
    rep(i, 5) cin >> a[i];

    lint res = 5;

    lint mx = -1;
    rep(i, 5) mx = max(mx, (n-1)/a[i]);
    res += mx;

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<vector<ll>> num(10, vector<ll>(10));
	for (auto i = 1; i <= N; ++i)
	{
		auto e = i % 10;
		auto temp = i;
		while (temp / 10 > 0)
		{
			temp /= 10;
		}
		auto s = temp;
		++num[s][e];
	}

	auto ans = 0ll;
	for (auto i = 0; i < 10; ++i)
	{
		for (auto j = 0; j < 10; ++j)
		{
			ans += num[i][j] * num[j][i];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;

int n,k;
vector<int>g[maxn];
queue<pii>q;
int vis[maxn],depth[maxn];
ll ans = 1;

void dfs(int u, int dep){
    depth[dep]++;
    for(int i = 0; i < g[u].size(); i++){
      if(!vis[g[u][i]]){
        vis[g[u][i]] = 1;
        dfs(g[u][i],dep + 1);
      }
    }
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
   cin >> n >> k;
   int a,b;
   for(int i = 0; i < n - 1; i++){
      cin >> a >> b;
      //if(a > b) swap(a,b);
      g[a].push_back(b);
      g[b].push_back(a);
   }
   dfs(1,0);
   //cout << 1 << endl;
   q.push({1,0});
   ans = (ans * k) % MOD;
   memset(vis,0,sizeof(vis));
   while(!q.empty()){
      int fa = q.front().first, dep = q.front().second + 1;
      q.pop();
      vis[fa] = 1;
      int cnt = 0;
      for(int i = 0; i < g[fa].size();i++){
          int v = g[fa][i];
          if(vis[v])continue;
          else {
          if(dep == 1){
               ans = ans * (k - (cnt++) - 1 ) % MOD; 
          }
          else ans = ans * (k - (cnt++) - 2 ) % MOD;
          q.push({v,dep});
          //cout << ans << endl;
        }
      }
   }
   cout << ans << endl;
   return 0;
}

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


int main(void)
{
	int n, m;
	cin >> n >> m;
	int hotel[100005] = {};
	
	hotel[0] = 0;
	for (int i = 1; i < n; i++){
		cin >> hotel[i];
	}
	for (int i = 0; i < n; i++){
		hotel[i + 1] += hotel[i];
	}
	
	int now = 0, move;
	long long res = 0;
	for (int i = 0; i < m; i++){
		cin >> move;
		res += abs(hotel[now] - hotel[now + move]);
		now += move;
//		cout << now << " " << abs(hotel[now] - hotel[now + move]) << endl;
	}
	
	cout << res % 100000 << endl;
	
	return 0;
}

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

#define ll long long int
#define endl '\n'

void testCase()
{
    //ll t; cin>>t; while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        
        cout<<max({a*c,a*d,b*c,b*d});
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    testCase();
    return 0;
}

Measured memory_bytes: 3664
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int dp[320][320][320];
int main()
{
	string x;
	cin >> x;
	int gen;
	scanf("%d", &gen);
	for (int i = 0; i < x.size(); i++)
	{
		for (int j = 0; j < x.size() - i; j++)
		{
			int s = j, t = j + i;
			for (int k = 0; k <= gen; k++)
			{
				if (s == t)dp[s][t][k] = 1;
				else
				{
					dp[s][t][k] = max(dp[s][t][k], dp[s + 1][t][k]);
					dp[s][t][k] = max(dp[s][t][k], dp[s][t - 1][k]);
					dp[s][t][k + (x[s] != x[t])] = max(dp[s][t][k + (x[s] != x[t])], dp[s + 1][t - 1][k] + 2);
				}
			}
		}
	}
	printf("%d\n", dp[0][x.size() - 1][gen]);
}


Measured memory_bytes: 120960
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include<cstdio>
using namespace std;
int main() {
	int n, m, j, suu;
	while ((cin >> m >> n)&&m!=0||n!=0) {
		int check[1001] = { 0 };
		for (int i = 1; i <= m; i++)check[i] = i;
		j = 1;
		suu = m;
		for (int i = 1; i <=n; i++) {
			string str;
			
			cin >> str;
			if (suu > 1) {
				if (i % 15 == 0 ) {
					if (str != "FizzBuzz") {
						//cout << "1.." << j << endl;
						check[j] = 0;
						suu--;
					}
				}
				else if (i % 3 == 0){ 
					if (str != "Fizz") {
						//cout << "2.." << j << endl;
						check[j] = 0;
						suu--;
					}
				}
				else if (i % 5 == 0 ) {
					if (str != "Buzz") {
						//cout << "3.." << j << endl;
						check[j] = 0;
						suu--;
					}
				}
				else {
					char buf[10] = { NULL }; //buf2[10] = { NULL };
					sprintf(buf,"%d", i);
					//cout << "str?????????" << str << endl;
					//cout <<"buf?????????"<< buf << endl;
					//snprintf(buf, 10, "%s", str);
					if (str!=buf) {
						//cout << "kita";
						check[j] = 0;
						suu--;
					}
				}
				j++;
				int x;
				if(suu>1)
				for ( x = j; check[x] == 0;) {
					x++;
					if (x > m)x = 1;
				}
				j = x;
			}
		}
		int las;
		for (int i = m; i > 0; i--) if (check[i] != 0) {
			las = i; break;
		}
		//cout << "las?????????" << las << endl;
		for (int i = 1; i<=m; i++)
		{
			if (check[i] != 0)
			{
				cout << i;
				if (i<las)
					cout << " ";
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 3308
n = STDIN.gets
S = STDIN.gets.split(' ')
q = STDIN.gets
T = STDIN.gets.split(' ')

found_count=0
T.each do |t|
  S.each do |s|
    if t == s
      found_count += 1
      break
    end
  end
end

print "#{found_count}\n"

Measured memory_bytes: 9000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
  char T[1001];
  char P[1001];
  int i, j, cnt, len;
  scanf("%s", T); 
  scanf("%s", P); 
  
  len = strlen(P);
  for (i = 0; T[i] != '\0'; i++) {
    if (T[i] == P[0]) {
      cnt = 1;
      for (j = 1; (T[i + j] == P[j]) && (P[j] != '\0'); j++) {
        cnt++;
      }   
      if (cnt == len) {
        printf("%d\n", i); 
      }   
    }   
  }
  return 0;
}

Measured memory_bytes: 540
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define all(a) a.begin(),a.end()
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(auto c:v) cout<<" "<<c; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
void solve(){
	int k,n;
	cin>>n>>k;
	ll a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	ll ans=0;
	for(int i=0;i<n-k;i++)
		ans+=a[i];
	cout<<ans<<endl;
}
int main(){ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int T=1;
//	cin>>T;
	while(T--){
		solve();
	}
}


Measured memory_bytes: 5224
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,k,t;
string s;

int main(){
	cin>>n>>k>>s;
	t=n;
	for(int i=0;i<n-1;i++) if(s[i]=='R'&&s[i+1]=='L'){
		if(k) k--;
		else t-=2;
	}
	if(s[0]=='L'){
		if(k) k--;
		else t--;
	}
	if(s[n-1]=='R'){
		if(k) k--;
		else t--;
	}
	cout<<min(t,n-1)<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define mk make_pair

int main()
{
	ll a,b;
	cin>>a>>b;
	ll c[a];
	for(ll i=0;i<a;i++)cin>>c[i];
	ll e[a]={-1};
	for(ll i=0;i<a;i++)e[i]=-1;
	for(ll i=0;i<b;i++)
	{
		ll m,n;
		cin>>m>>n;
		if(c[m-1]>c[n-1]&&e[m-1]!=0)
		{
			e[m-1]=1;
			e[n-1]=0;
		}
		else if(c[n-1]>c[m-1]&&e[n-1]!=0)
		{
			e[n-1]=1;
			e[m-1]=0;
		}
		else
		{
			e[m-1]=0;
			e[n-1]=0;
		}
	}
	ll count=0;
	for(ll i=0;i<a;i++)
	{
	//	cout<<e[i]<<" ";
		if(e[i]==1||e[i]==-1)
		count++;
	}
	cout<<count<<endl;
}


Measured memory_bytes: 5100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 100005

ll mult(ll a, ll b)
{
	return a*b;
}
ll pw(ll a, ll b)
{
	ll r=1;
	while(b){
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	ll x; cin>>x;
	
	for(ll i=0;i<=5e3;i++){
		for(ll j=0;j<i;j++){
			if(pw(i,5)-pw(j,5)==x){
				cout<<i<<" "<<j<<'\n';
				return 0;
			}
			if(pw(i,5)+pw(j,5)==x){
				cout<<i<<" "<<-j<<'\n';
				return 0;
			}
		}
	}
	
	return 0;
}


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

int max64(int64_t x,int64_t y){
    if(x>y){
        return x;
    }else{
        return y;
    }
}


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

    if(k<a){
        cout << a-k << " " << b << endl;
        return 0;       
    }else if(a+b>=k){
        cout << 0 << " " << a+b-k << endl;
        return 0;
    }else{
        cout << "0 0" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int n, ans;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		if (1 <= i && i < 10)ans++;
		if (100 <= i && i < 1000)ans++;
		if (10000 <= i && i < 100000)ans++;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include<stdio.h>

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



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

using namespace std;
int main(){
  long n;
   cin >>n;
  
  vector<long> a(n+2);
  long s=0;
  
  a[0]=0;
  for(int i=1;i<=n;i++){
   cin >>a[i];
    s+=abs(a[i]-a[i-1]);
  }
  a[n+1]=0;
   s+=abs(a[n+1]-a[n]);
  
  for(int i=1;i<=n;i++){
   cout << s+abs(a[i-1]-a[i+1])-abs(a[i-1]-a[i])-abs(a[i]-a[i+1]) << endl;
  }
    
}


Measured memory_bytes: 2048
Module Program
  Sub Main
    Dim s=GetInts()
    Dim a=s(0)*s(1),b=s(2)
    Dim ans=Math.Min(a,b)
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

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

#define ll long long
#define pii pair<ll,ll>

using namespace std;

int main(void)
{
    int n;
    cin>>n;

    vector<ll> v(n);

    for(int i=0; i<n; i++) cin>>v[i];
    ll ans = 0;
    for(int i=1; i<n; i++)
    {
        if(v[i-1] > v[i])
        {
            ans += v[i-1] - v[i];
            v[i] = v[i-1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4844
# import numpy as np
from collections import deque

N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
# row = [A[0], A[1]]
min_list = deque([A[1], A[1]])
ans = A[0]
for i in range(2, N):
    # index = np.argmax(min_list)
    ans += min_list.popleft()
    # if index == len(min_list)-1:
    #     l, r = row[index], row[0]
    # else:
    #     l, r = row[index], row[index+1]
    # row.insert(index+1, A[i])
    min_list.append(A[i])
    min_list.append(A[i])
    # min_list.insert(index+1, A[i])
print(ans)

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n;
  cin >> n;
  f64 ans = 0;
  rep(_, n) {
    f64 x;
    string s;
    cin >> x >> s;
    if (s[0] == 'J') ans += x;
    else ans += x * 380000.0;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*          IT IS GOING TO HAPPEN
                    because
                     I AM GOING TO MAKE IT HAPPEN      */
 
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define V vector<ll int>
#define VPI vector<pair<int,int>>
#define pb push_back  
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
 
const ll cnst=1e9+7,di=998244353,N=2e5+1;
 
bool IsQuery=false,found=false; 
ll q=1,a[N],ans;
 
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
 
string s,t;

void solve()
{
    ll n,k,val,ans,W;

    cin>>n>>W;

    ll w[n],v[n];

    for(int i=0;i<n;i++)
    cin>>w[i]>>v[i];
    
    map<int,bool> occ;
    map<ll,ll> dp;

    occ[0]=true;

    for(int i=0;i<n;i++)
    {
        for(int j=1e5;j>=0;j--)
        {
            if(occ[j])
            {
                occ[j+v[i]]=true;

                if(dp[j+v[i]]==0)
                    dp[j+v[i]]=dp[j]+w[i];

                else
                dp[j+v[i]]=min(dp[j]+w[i],dp[j+v[i]]);
            }
        }
    }

    for(int i=0;i<=1e5;i++)
    {
        if(occ[i] && dp[i]<=W)
        ans=i;
    }

    cout<<ans;
    
    return;   
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    if(IsQuery)
    cin>>q;
 
    for(int i=0;i<q;i++)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 11504
n=int(input())
A=[int(input()) for i in range(n)]
ma=max(A)
flag=False
if A.count(ma)>=2:
  flag=True
for i in range(n):
  if A[i] != ma:
    print(ma)
  else:
    if flag:
      print(ma)
    else:
      A[i]=0
      print(max(A))

Measured memory_bytes: 85536