akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 36

int isStable(char[][max],char[][max],int);
void selectionSort(char[][max],int);
void bubbleSort(char[][max],int);

int main(){
    char cards[max][max];
    char bubble[max][max];
    char selection[max][max];
    int n;

    scanf("%d",&n);

    for(int i = 0;i < n;i++){
        scanf("%s",cards[i]);
        strcpy(bubble[i],cards[i]);
        strcpy(selection[i],cards[i]);
    }

    bubbleSort(bubble,n);
    for(int i = 0;i < n;i++){
        printf("%s",bubble[i]);
        if(i < n-1)printf(" ");
    }
    printf("\n");
    if(isStable(cards,bubble,n) == 1)printf("Stable\n");
    else printf("Not stable\n");

    selectionSort(selection,n);
    for(int i = 0;i < n;i++){
        printf("%s",selection[i]);
        if(i < n-1)printf(" ");
    }
    printf("\n");
    if(isStable(cards,selection,n) == 1)printf("Stable\n");
    else printf("Not stable\n");

    return 0;
}

int isStable(char in[][max],char out[][max],int n){
    for(int i = 0;i < n;i++){
        for(int j = i + 1;j < n;j++){
            for(int a = 0;a < n;a++){
                for(int b = a+1;b < n;b++){
                    if(in[i][1] == in[j][1] && strcmp(in[i],out[b]) == 0 && strcmp(in[j],out[a]) == 0)return 0;
                }
            }
        }
    }
    return 1;
} 

void selectionSort(char cards[][max],int n){
    int minj;
    char tmp[max];
    int count = 0;
    int flag;

    for(int i = 0;i < n;i++){
        minj = i;
        flag = 0;
        for(int j = i;j < n;j++){
            if(atoi(&cards[j][1])< atoi(&cards[minj][1])){
                minj = j;
                flag = 1;
            }
        }
        if(flag == 1){
            strcpy(tmp,cards[minj]);
            strcpy(cards[minj],cards[i]);
            strcpy(cards[i],tmp);
        }
    }
}

void bubbleSort(char cards[][max],int n){
    char tmp[max];
    int i = 0;
    int flag = 1;
    while(flag){
        flag = 0;
        for(int j = n-1;j > i;j--){
            if(atoi(&cards[j][1]) < atoi(&cards[j-1][1])){
                strcpy(tmp,cards[j]);
                strcpy(cards[j],cards[j-1]);
                strcpy(cards[j-1],tmp);
                flag = 1;
            }
        }
        i++;
    }
}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

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

int main(){
	//input
	string s; cin>>s;
	bool ans=true;
	rep(i,sz(s)){
		if(i%2==0){
			if(s[i]=='R' || s[i]=='U' || s[i]=='D') continue;
			else ans=false;
		}
		else{
			if(s[i]=='L' || s[i]=='U' || s[i]=='D') continue;
			else ans=false;
		}
	}

	if(ans) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    if(s.equals("Sunny")){
      System.out.println("Cloudy");
    }else if(s.equals("Cloudy")){
      System.out.println("Rainy");
    }else{
      System.out.println("Sunny");
    }
  }
}


Measured memory_bytes: 22868
s = input()
r_s = s[::-1]
w = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]

num = 0
b = True
while num < len(r_s) and b == True:
    b = False
    for i_w in w:
        if i_w == r_s[num:num+len(i_w)]:
            b = True
            num += len(i_w)

if b:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3188
import numpy as np
NUMBER = 998244353
 
N, *D = map(int, open(0).read().split())
bincnt = np.bincount(D)
if D[0] != 0:
    print('0')
elif (bincnt==0).sum() > 0:
    print('0')
elif bincnt[0]!=1:
    print('0')
else:
    val = 1
    for i in range(2, bincnt.shape[0]):
        for _ in range(bincnt[i]):
            val = (val*bincnt[i-1]%NUMBER)
    print(val)

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    char a, b;
    cin >> a >> b;
    if (a == 'H' && b == 'H')
        cout << 'H' << endl;
    else if (a == 'H' && b == 'D')
        cout << 'D' << endl;
    else if (a == 'D' && b == 'H')
        cout << 'D' << endl;
    else
        cout << 'H' << endl;
    return 0;
}

Measured memory_bytes: 3564
def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg

import sys
from fractions import gcd

sys.setrecursionlimit(1500000)

s=input()
t=input()
n=len(s)
m=len(t)
if n!=m:
    s=(m//n+2)*s
    data=Z_algorithm(t+'?'+s)
    bool=[False for i in range(0,n)]
    for i in range(m+1,m+1+n):
        if data[i]==m:
            bool[i-m-1]=True

    g=gcd(n,m)
    for i in range(0,g):
        for j in range(0,n//g):
            if not bool[i+j*g]:
                break
        else:
            print(-1)
            exit()

    ans=[[] for i in range(0,g)]
    for i in range(0,g):
        ans[i].append(bool[i])
        x=(i+m)%n
        while x!=i:
            ans[i].append(bool[x])
            x=(x+m)%n

    from itertools import groupby
    answer=0
    for i in range(0,g):
        a=groupby(ans[i])
        d=[]
        for key,group in a:
            g=len(list(group))
            d.append([key,g])
        if d:
            if d[0][0] and d[-1][0]:
                d[-1][1]+=d[0][1]
        for j in range(len(d)):
            if d[j][0]:
                answer=max(answer,d[j][1])
    print(answer)


else:
    s=2*s
    data=Z_algorithm(t+'?'+s)
    for i in range(m+1,n+m+1):
        if data[i]==m:
            print(-1)
            break
    else:
        print(0)


Measured memory_bytes: 123308
#include <bits/stdc++.h>
using  namespace std;
int main(){
    long long n, m, p, y;
    cin >> n >> m;
    map<long long, long long> Number;
    vector<vector<long long>> Order(n+1);
    vector<long long> P, Y;
    for(int i=0;i<m;i++){
        cin >> p >> y;
        Number[y]=1;
        Order[p].push_back(y);
        P.push_back(p);
        Y.push_back(y);
    }
    for(int i=1;i<=n;i++){
        sort(Order[i].begin(), Order[i].end());
    }
    for(int i=1;i<=n;i++){
        for(int j = 0; j < (int)Order[i].size(); ++j){
            Number[Order[i][j]] = j + 1;
        }
    }
    for(int i=0;i<m;i++){
        printf("%06i", P[i]);
        printf("%06i\n", Number[Y[i]]);   
    }
    return 0;
}


Measured memory_bytes: 14824
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    string s,t;
    cin>>s>>t;
    cout<<t+s<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int num[100] = {0};
	int tmp[100] = {0};
	int big;
	int n, i, j;
	
	while (scanf("%d", &n) != EOF){
		num[n - 1]++;
	}
	
	big = 0;
	j = 0;
	
	for (i = 1; i < 100; i++){
		if (num[i] > num[big]){
			while (j > 0){
				tmp[j] = 0;
				j--;
			}
			big = i;
		}
		else if (num[i] == num[big]){
			tmp[j] = big;
			big = i;
			j++;
		}
	}
	
	tmp[j] = 101;
	
	for (i = 0; i < 100; i++){
		if (tmp[i] < tmp[i + 1]){
			printf("%d\n", tmp[i] + 1);
		}
		else {
			break;
		}
	}
	
	printf("%d\n", big + 1);
	
	return (0);
}

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

using ll = long long int;
int n, t;
ll sum = 0;
int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> t;
        sum += (t-1);
    }
    std::cout << sum << std::endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int n;
typedef long long ll;
ll now=1,a[100004];
const ll M=1e18; 
int main(){
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==0){
			puts("0");return 0;
		}
	}
	for(int i=1;i<=n;i++){
		ll x=a[i];
		if(M/x>now || (M%x==0 && M/x==now))now*=x;
		else{
			puts("-1");return 0;
		}
	}
	cout<<now;
}

Measured memory_bytes: 4412
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[][] x = new int[2][N];
        for(int i = 0; i < N; i++){
            x[0][i] = sc.nextInt();
            x[1][i] = sc.nextInt();
        }
        Map<List<List<Integer>>, Integer> map = new HashMap<>();
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                if(i != j){
                    List<List<Integer>> lists = new ArrayList<>();
                    List<Integer> list = new ArrayList<>();
                    list.add(x[0][i]-x[0][j]);
                    list.add(x[1][i]-x[1][j]);
                    lists.add(list);
                    if(map.containsKey(lists)){
                        map.put(lists, map.get(lists)+1);
                    } else {
                        map.put(lists, 1);
                    }
                }
            }
        }
        int max = 0;
        for(List<List<Integer>> key: map.keySet()){
            max = Math.max(map.get(key), max);
        }
        System.out.println(N-max);
    }
}

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

int main(){
    int n, b, f, r, v;
    int count[4][3][10] = {};
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> b >> f >> r >> v;
        count[b-1][f-1][r-1] += v;
    }
    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < 10; k++){
                cout << ' ' << count[i][j][k];
            }
            cout << endl;
        }
        if (i != 3) cout << "####################" << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    long long num,n,i,tow=0,d=0,nd=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>num;
        if(num%4==0)d++;
        else if(num%2==0) tow++;
        else nd++;
    }
    nd +=(tow&1);
    if(d>=nd-1)
        cout<<"Yes";
    else
        cout<<"No";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repi(i,a,b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;

int main() {
  char X, Y;
  cin >> X >> Y;
  
  if (X < Y) cout << "<" << endl;
  if (X > Y) cout << ">" << endl;
  if (X == Y) cout << "=" << endl;
}

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

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let n: f64 = read();
    let a: Vec<u64> = (0..5).map(|_| read()).collect();

    let min_a = a.into_iter().min().unwrap();

    let ans = (n / min_a as f64).ceil() + 4.0;

    println!("{}",ans);

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
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;}
/*
void chmin(ll a, ll b){if (a>b){a = b; return true;}return false;}
void chmax(ll a, ll b){if (a<b){a = b; return true;}return false;}
*/

const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  ll a,b,k; cin >>a >>b >>k;
  ll ans1 = a, ans2 = b;
  if (a >= k){
    ans1 -= k; cout <<ans1 <<" " <<ans2 <<endl;
  }else{
    ans1 = 0;
    k -= a;
    if (b >= k){
      ans2 -= k; cout <<ans1 <<" " <<ans2 <<endl;
    }else{
      ans2 = 0; cout <<ans1 <<" " <<ans2 <<endl;
    }
  }
}

Measured memory_bytes: 256
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int p,q,r;
int solve(){
  int n;cin>>n;
  int a,b;cin>>a>>b;
  
  rep(i, n) {
    int t;
    cin>>t;
    if (t>=b+1) r++;
    else if (t<=a) p++;
    else q++;
  }
  dump(p, q, r);

  cout << min(min(p, q), r) << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
//#define INF  (1<<30)
#define INFL (1LL<<60)
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
#define ARR(...) vector<int>({__VA_ARGS__})
#define ARS(...) vector<string>({__VA_ARGS__})
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<double> base;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    os << '[';
    for (auto p : v) os << p << ",";
    os << "]";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
    os << "{";
    for (auto p : v) os << p << ",";
    os << "}";
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const multiset<T, V> &v) {
    os << "{";
    for (auto p : v) os << p << ",";
    os << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    os << "{";
    for (auto p : v) os << p << ",";
    os << "}";
    return os;
}
 
ostream& operator<<(ostream &os, tuple<int, int, int> t) {
    os << "<" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ">";
    return os;
}
 
#ifndef ONLINE_JUDGE
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
auto x = []{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    return 0;
}();

template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

ll N, D, A;
pll X[200000];

int main(void) {
    cin >> N >> D >> A;
    rep(i, N) cin >> X[i].fi >> X[i].se;

    sort(X, X+N);

    queue<pll> q;
    ll val = 0;
    ll res = 0;
    rep(i, N) {
        while(sz(q) > 0 and q.front().fi < X[i].fi) {
            val -= q.front().se;
            q.pop();
        }

        if (val < X[i].se) {
            int need = (X[i].se-val-1)/A + 1;
            res += need;
            val += need*A;
            q.push({X[i].fi+2*D, need*A});
        }
    }

    cout << res << endl;
}




Measured memory_bytes: 4992
n,m,x,y = map(int,input().split())
xn = list(map(int, input().split()))
yn = list(map(int, input().split()))
ans = "War"
for i in range(x+1, y+1):
    if i > max(xn):
        if i <= min(yn):
            ans = "No War"
            break
print(ans)

Measured memory_bytes: 3060
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let ab: Vec<f64> = read_vec();
  let ans = ((ab[1] - ab[0]) / (ab[0] - 1.0)).ceil() + 1.0;

  if ab[1] == 1.0 {
    println!("{}", 0);
  } else {
    println!("{}", ans);
  }
}


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

typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;

#define MOD1        1000000007
#define MOD2        998244353
#define PI          3.1415926535897932384626433832795
#define FILL(a, value) memset(a, value, sizeof(a))
#define BOOST       ios_base::sync_with_stdio(false); cin.tie(NULL)
#define what_is(x)  cerr << #x << " is " << x << endl;
#define ASSERT(left,operator,right) { if(!((left) operator (right))){ std::cerr << "ASSERT FAILED: " << #left << #operator << #right << " @ " << __FILE__ << " (" << __LINE__ << "). " << #left << "=" << (left) << "; " << #right << "=" << (right) << std::endl; } }

#define rep01(k,n)      for (ll i=k; i<n; i++)
#define rep02(k,n)      for (ll j=k; j<n; j++)
#define rep03(k,n)      for (ll k=k; k<n; k++)
#define rep11(k,n)      for (ll i=k; i<=n; i++)
#define rep12(k,n)      for (ll j=k; j<=n; j++)
#define rep13(k,n)      for (ll k=k; k<=n; k++)
#define repIT(c,it)     for(typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
#define all(c)      c.begin(), c.end()

using namespace std;

const double pi = acos(-1.0);
const double epsilon = 1e-9;        // Add epsilon when casting double to int to avoid rounding pitfall issues, eg, 0.94*8178 in int
const int maxn = 1e6+10;


void solve()
{
    ll h, w;
    cin >> h >> w;

    if(h == 1 || w == 1)
        cout << 1;
    else
    {
        ll ans = ceil(w*0.5)*(ceil(h*0.5)) + floor(w*0.5)*floor(h*0.5);
        cout << ans;
    }
    
}

int main()
{
    

    int t = 1;
    //cin >> t;
    while(t--)
        solve();

    cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 3728
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 左の子(left child), r:右の子(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];
int H[MAX];
int S[MAX];
int c=0;

void print(int u){
  int i, s=0;
  printf("node %d: parent = %d, sibling = %d, ", u, T[u].p, S[u]);
  if(T[u].r!=NIL) s++;
  if(T[u].l!=NIL) s++;
  printf("degree = %d, depth = %d, height = %d, ",s,D[u],H[u]);

  if(T[u].p==-1) printf("root\n");
  else if(T[u].l==NIL&&T[u].r==NIL) printf("leaf\n");
  else printf("internal node\n");
  
}

void calcDepth(int u, int p){
  int a=0;
  D[u] = p;
  if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
  if(T[u].r!=NIL) calcDepth(T[u].r,p+1);
}
int calcHeight(int u){
  int rc=0,lc=0;
  int max;
  if(u==NIL) return 0;

  rc=calcHeight(T[u].r)+1;
  lc=calcHeight(T[u].l)+1;

  if(rc < lc) max=lc;
  else max=rc;

  return max;
}

int main(){
  int i, j, k;
  int n;
  int id, sib,r,l;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    T[i].p = T[i].l = T[i].r = NIL;
    H[i]=0;
  }
  
  for(i=0; i<n; i++){
    scanf("%d %d %d", &id, &r, &l);
    if(r!=NIL){
      T[id].r=r;
      T[r].p=id;
      S[r]=l;
    }
    if(l!=NIL){
      T[id].l=l;
      T[l].p=id;
      S[l]=r;
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  S[root]=-1;
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);
  //高さ
  for(i=0; i<n; i++) H[i]=calcHeight(i)-1;
  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 2104
class Solver:

    def __init__(self):
        pass

    def solve(self, a, b, k):
        for n in range(min(a,b), 0, -1):
            if (a % n) == 0 and (b % n) ==0:
                k -= 1
                if k == 0:
                    return n
        return 1


if __name__ == '__main__':

    solver = Solver()

    a, b, k = map(int, input().split())

    n = solver.solve(a, b, k)
    print(n)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 100000

int primes[N+10];
void li(){
	int p=0,i,j;bool b;
	primes[p++]=2;
	for(i=3;;i+=2){
		b=true;
		for(j=0;j<p&&primes[j]*primes[j]<=i;j++){
			if(i%primes[j]==0) {b=false;break;}
		}
		if(b) primes[p++]=i;
		if(p==N) break; 
	}
	//cout<<primes[N-1]<<endl;
}
int main(){
	li();
	int n;
	while(scanf("%d",&n)&&n){
		int z=lower_bound(primes,primes+N,n)-primes;
		if(primes[z]==n) puts("0");
		else{
			printf("%d\n",primes[z]-primes[z-1]);
		}
	}
	
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int n; cin >> n;
    V<int> A(n);
    loop (n, i) cin >> A[i];
    sort(A.begin(), A.end());
    if (n == 2) {
        cout << A[n - 1] - A[0] << endl;
        cout << A[n - 1] << " " << A[0] << endl;
        return 0;
    }

    ll ans = A[n - 1] - A[0];
    loop (n - 2, i) {
        int j = i + 1;
        ans += abs(A[j]);
    }
    cout << ans << endl;

    int n_right = 0;
    loop (n - 2, i) {
        int j = i + 1;
        if (A[j] < 0 && (A[j + 1] >= 0 || j + 1 == n - 1)) n_right = j;
    }
    int positive = A[n - 2] > 0;

    ll m = A[n - 1];
    loop (n - 1, i) {
        if (positive && (i == n_right || i == n - 2)) {
            cout << A[i] << " " << m << endl;
            m = A[i] - m;
        } else {
            cout << m << " " << A[i] << endl;
            m = m - A[i];
        }
    }
    return 0;
}



Measured memory_bytes: 2304
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
int a[55]={2,3,13,23,43,53,73,83,103,113,163,173,193,223,233,263,283,293,313,353,373,383,433,443,463,503,523,563,593,613,643,653,673,683,733,743,773,823,853,863,883,953,983,1013,1033,1063,1093,1103,1123,1153,1163,1193,1213,1223,1283};
int main()
{
    int n;
    int b[60];
    cin>>n;
    for(int i=0;i<n-1;i++)
        printf("%d ",a[i]);
    printf("%d\n",a[n-1]);
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > mat;

//UnionFind
const int MAX_N = 100100;
const int MAX_Q = 100100;
struct UnionFind
{
  int par[MAX_N];	//親
  int height[MAX_N];	//木の深さ
  int size[MAX_N];	//子の数

	//n要素で初期化
  void init (int n)
  {
    for (int i = 0; i < n; i++)
    {
      par[i] = i;
      height[i] = 0;
      size[i] = 1;
    }
  }

	//木の根を求める
  int find (int x)
  {
    if (par[x] == x)
    {
      return x;
    }
    else
    {
      return par[x] = find(par[x]);
    }
  }

	//xとyの属する集合を併合
  void unite (int x, int y)
  {
    x = find(x);
    y = find(y);
    if (x == y)
    {
      return;
    }

    if (height[x] < height[y])
    {
      par[x] = y;
      size[y] = size[x] + size[y];
    }
    else
    {
      par[y] = x;
      size[x] = size[x] + size[y];
      if (height[x] == height[y])
      {
        height[x]++;
      }
    }
  }

	//xとyが同じ集合に属するか否か
  bool same (int x, int y)
  {
    return find(x) == find(y);
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  int p[MAX_N];
  for (int i = 0; i < n; i++)
  {
    cin >> p[i];
    p[i]--;
  }
  UnionFind uf;
  uf.init(n);
  int x[MAX_Q], y[MAX_Q];
  for (int i = 0; i < m; i++)
  {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
    uf.unite(x[i], y[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    if (uf.same(i, p[i]))
    {
      ans++;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 2560
program sample
    implicit none
    integer(8) ::a, b,c,i,j,m,n,k,a1,b1,c1
    integer(8)::x,y
    
    read(*,*) x,y
   
    a=2*x-y/2
    b=y/2-x
    if (mod(y,2)==1)then
        write(*,*)'No'
        stop
    end if
    if (b<0 .or. a<0)then
        write(*,*)'No'
        stop
    
    end if
    write(*,*)'Yes'

    stop
end program sample
  



Measured memory_bytes: 2792
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace  std;

typedef long long Long;

const int M = 1e6 + 5;
const int MOD = 998244353;
vector<int> divos[M];
int bufferVal[M];
int cnt[M];
int val[M];
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif // ONLINE_JUDGE

  for(int i = 1; i < M; i++){
    for(int j =  i; j < M; j += i)
      divos[j].push_back(i);
  }
  int n;  cin >> n; 
  for(int i = 0; i < n; i++){
    int x;
    cin >> x; cnt[x]++;
  }
  int ans = 0;
  for(int i = M - 1; i >= 1; --i){
    if(cnt[i]){
      reverse(divos[i].begin(), divos[i].end());
      for(auto x : divos[i]){
        val[x] -= bufferVal[x];
        if(val[x] < 0)val[x] += MOD;
        ans += (i / x) * 1ll * val[x] % MOD * cnt[i] % MOD;
        if(ans >= MOD)ans -= MOD;
        for(auto y : divos[x])if(x != y){
          bufferVal[y] += val[x];
          if(bufferVal[y] >= MOD)bufferVal[y]-=MOD;
        }
        val[x]+=bufferVal[x];
        if(val[x] >= MOD)val[x] -= MOD;
        bufferVal[x] = 0;
        val[x] += 1ll * i * cnt[i] % MOD;
        if(val[x] >= MOD)val[x]-=MOD;
      }
      ans += 1ll * cnt[i] * (cnt[i] - 1) / 2 % MOD * i % MOD;
      if(ans >= MOD)ans -= MOD;
    }
  }
  cout << ans << '\n';

  return 0;
}




Measured memory_bytes: 126464
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
const int N=5005;
typedef long long ll;
const ll mod=1e9+7;
std::vector<int>edge[N];
inline void read(int &x){
    register char ch=0;
    for(;!std::isdigit(ch);ch=getchar());
    for(x=0;std::isdigit(ch);x=x*10+ch-'0',ch=getchar());
}
int n,siz[N];
ll f[N][N],tmp[N],h[N];
void dfs(int now,int fa){
    siz[now]=1,f[now][1]=1;
    for(register unsigned i=0;i<edge[now].size();++i){
        int v=edge[now][i];
        if(v==fa)continue;
        dfs(v,now);
        for(register int j=0;j<=siz[now]+siz[v];++j)tmp[j]=0;
        for(register int j=1;j<=siz[now];++j)
            for(register int k=0;k<=siz[v];++k){
                tmp[j+k]=(tmp[j+k]+f[now][j]*f[v][k]%mod)%mod;
                if(!(k&1))tmp[j]=tmp[j]-f[now][j]*f[v][k]%mod*h[k]%mod,tmp[j]=(tmp[j]%mod+mod)%mod;
            }
        for(register int j=0;j<=siz[now]+siz[v];++j)f[now][j]=tmp[j];
        siz[now]+=siz[v];
    }
}
int main(){
    read(n);
    for(register int i=1;i<n;++i){
        int u,v;read(u),read(v),edge[u].push_back(v),edge[v].push_back(u);
    }
    h[0]=1;for(register int i=2;i<=n;i+=2)h[i]=1ll*(i-1)*h[i-2]%mod;
    dfs(1,0);
    ll ans=0;for(register int i=2;i<=n;i+=2)ans=(ans+f[1][i]*h[i]%mod)%mod;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 195200
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 500 + 5;
const int M = 20;
const int V = 500 * 15 + 5;
const int MOD = (int)1e9 + 7;

struct Matrix
{
	long long a[V][M * 3];
	long long& getEntry(int x, int y) {
		return a[x][y - x + M];
	}
	bool haveEntry(int x, int y) {
		return 0 <= y - x + M && y - x + M < M * 3;
	}
	void clear() {
		memset(a, 0, sizeof a);
	}
} a;

int n, m;
char c[N][M];
int id[N][M];

#define getId(x,y) (id[x][y])

long long modPow(long long a, long long p, long long MOD)
{
	long long ret = 1;
	for( ; p; p >>= 1, a = a * a % MOD) {
		if (p & 1) {
			ret = ret * a % MOD;
		}
	}
	return ret;
}


void solve()
{
	a.clear();
	int v = 0;
	for(int i = 0; i < n; ++ i) {
		scanf("%s", c[i]);
		for(int j = 0; j < m; ++ j) {
			if (c[i][j] == '.') {
				id[i][j] = v ++;
			}
		}
	}
	for(int i = 0; i < n; ++ i) {
		for(int j = 0; j < m; ++ j) {
			if (c[i][j] == '.') {
				if (i + 1 < n && c[i + 1][j] == '.') {
					a.getEntry(getId(i, j), getId(i, j)) ++;
					a.getEntry(getId(i + 1, j), getId(i + 1, j)) ++;
					a.getEntry(getId(i, j), getId(i + 1, j)) --;
					a.getEntry(getId(i + 1, j), getId(i, j)) --;
				}
				if (j + 1 < m && c[i][j + 1] == '.') {
					a.getEntry(getId(i, j), getId(i, j)) ++;
					a.getEntry(getId(i, j + 1), getId(i, j + 1)) ++;
					a.getEntry(getId(i, j), getId(i, j + 1)) --;
					a.getEntry(getId(i, j + 1), getId(i, j)) --;
				}
			}
		}
	}
	--v;
	long long ret = 1;
	for(int col = 0; col < v; ++ col) {
		if (a.getEntry(col, col) == 0) {
			for(int i = col + 1; a.haveEntry(i, col) && i < v; ++ i) {
				if (a.getEntry(i, col)) {
					for(int j = col; a.haveEntry(col, j) && a.haveEntry(i, j) && j < v; ++ j) {
						swap(a.getEntry(col, j), a.getEntry(i, j));
					}
					ret = -ret;
					break;
				}
			}
		}
		if (a.getEntry(col, col)) {
			ret = ret * a.getEntry(col, col) % MOD;
			long long inv = modPow(a.getEntry(col, col), MOD - 2, MOD);
			for(int i = col + 1; a.haveEntry(i, col) && i < v; ++ i) {
				if (a.getEntry(i, col)) {
					long long by = -a.getEntry(i, col) * inv % MOD;
					for(int j = col; a.haveEntry(col, j) && a.haveEntry(i, j) && j < v; ++ j) {
						(a.getEntry(i, j) += a.getEntry(col, j) * by) %= MOD;
					}
				}
			}
		} else {
			ret = 0;
			break;
		}
	}
	cout << (ret + MOD) % MOD << endl;
}

int main()
{
	int t = 0;
	for( ; scanf("%d%d", &n, &m) == 2 && (n || m); ) {
		printf("Case %d: ", ++ t);
		solve();
	}
	return 0;
}

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

inputlist = list(map(int, input().split()))
A = inputlist[0]
B = inputlist[1]
K = inputlist[2]

k = 0
min = min(A, B)

for ans in list(range(min, 0, -1)):
    if A%ans == 0 and B%ans == 0:
        k += 1
        if k == K:
            print(ans)
            break

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

using namespace std;

struct Rectangle {
	int h;
	int w;
};

int main(void) {
	int a, b;
	vector<struct Rectangle> v;

	while (cin >> a >> b) {
		if (a == 0 && b == 0) {
			break;
		}
		
		struct Rectangle wk;
		wk.h = a;
		wk.w = b;
		v.push_back(wk);
	}

	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].h; j++) {
			for (int k = 0; k < v[i].w; k++) {
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, a, b, c, d;
  cin >> N;
  a = (N-N%1000)/1000;
  b = (N%1000-N%100)/100;
  c = (N%100-N%10)/10;
  d = N%10;
 
  if ( (a == b) && (b == c)) {
    cout << "Yes" << endl;
  }
  
  else if ( (b == c) && (c == d)) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
 
}


Measured memory_bytes: 256
#include <stdio.h>
  
int main(void)
{   int a,b,i;
    char op;
    for(;;){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+')
        {printf("%d\n",a+b);
        }
        if(op=='-')
        {printf("%d\n",a-b);
        }
        if(op=='*')
        {printf("%d\n",a*b);
        }
        if(op=='/'){
            printf("%d\n",a/b);
        }
        if(op=='?') {
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 2048
/**
 *    DP
 *    24.04.2020 09:01
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, a, b, c;
  vector<int> vv;
  vector<vector<int>> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    vv.push_back(a);
    vv.push_back(b);
    vv.push_back(c);
    v.push_back(vv);
    vv.clear();
  }
  vector<vector<int>> dp (n + 1, vector<int> (3, 0));
  dp[1][0] = v[0][0], dp[1][1] = v[0][1], dp[1][2] = v[0][2];
  for (int i = 2; i <= n; i++) {
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + v[i - 1][0];
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + v[i - 1][1];
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + v[i - 1][2];
  }
  cout << max({dp[n][0], dp[n][1], dp[n][2]}) << "\n";
  return 0;
}


Measured memory_bytes: 11312
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    s = input()
    print("A" if s.lower() != s else "a")
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 21412
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;
// Welcome to my source code!

int main() {
    int a, b;
    cin >> a >> b;
    if (b*2 >= a) cout << 0 << endl;
    else cout << a-(b*2) << endl;
}


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

void call(int n){
	int i = 1;
	do {
		int x = i;
		if ( x % 3 == 0 ){
			cout << " " << i;
			continue;
		}
		do {
			if ( x % 10 == 3 ){
				cout << " " << i;
				break;
			}
			x /= 10;
		} while ( x );
	} while ( ++i <= n );
        cout << endl;
}

int main(){
	int n;
	cin >> n;
	call(n);
}

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

int compare(const void *n1, const void *n2){
	if(*(int *)n1 > *(int *)n2)
		return 1;
	else if(*(int *)n1 < *(int *)n2)
		return -1;
	else
		return 0;
}

int main(void){
	int min = 1 << 29;
	int n, temp;
	int num[100] = {0};

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

	qsort(num, n, sizeof(num[0]), compare);

	if(num[0] == num[n-1]) {
		printf("0");
		return 0;
	}

	for(int i=num[0]; i < num[n-1]; i++) {
		temp = 0;
		for(int j=0; j < n; j++) {
			temp += (i - num[j])*(i - num[j]);
		}
		if(min > temp)
			min = temp;
	}
	printf("%d", min);

	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
int main(){
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a+b>c+d)
		printf("Left");
	else if(a+b==c+d)
		printf("Balanced");
	else printf("Right");
	return 0;
}

Measured memory_bytes: 128
<?php  
$stdin1 = trim(fgets(STDIN));  
$array1 = explode(' ', $stdin1);
$select = $array1[1];
$stdin2 = trim(fgets(STDIN));  
$array2 = explode(' ', $stdin2);
$sum = array_sum($array2);
$count = 0;
$warukazu = $select * 4;
 
foreach ($array2 as $num) {
  if ($sum / $warukazu > $num) {
    continue;
  }
  $count++;
}

if ($count >= $select) {
  echo 'Yes';
} else {
  echo 'No';
}

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

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

    vector<int> x(n);
    vector<int> y(n);
    vector<int> h(n);

    int x0,y0,h0;
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i]!=0){
            x0=x[i];y0=y[i];h0=h[i];
        }
    }

    for(int cx=0;cx<101;cx++){
        for(int cy=0;cy<101;cy++){
            int ch=h0+abs(cx-x0)+abs(cy-y0);

            int flg=true;
            for(int i=0;i<n;i++){
                if(h[i]!=max(ch-abs(cx-x[i])-abs(cy-y[i]),0)){
                    flg=false;
                    break;
                }
            }

            if(flg){
                printf("%d %d %d\n",cx,cy,ch);
                return 0;
            }
        }
    }
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    long long K;
    cin >> N >> K;
    vector<int> P(N);
    for (int i = 0; i < N; ++i) {
        cin >> P[i];
        --P[i];
    }
    vector<long long> C(N);
    for (int i = 0; i < N; ++i) {
        cin >> C[i];
    }
    long long max_score = numeric_limits<long long>::min();
    for (int i = 0; i < N; ++i) {
        int cur = i;
        long long cycle_length = 1, cycle_score = C[i];
        while (P[cur] != i) {
            ++cycle_length;
            cycle_score += C[P[cur]];
            cur = P[cur];
        }
        long long score = 0;
        long long T = min(K, cycle_length);
        cur = i;
        for (long long t = 1; t <= T; ++t) {
            score += C[P[cur]];
            max_score = max(score + max((long long)0, ((K - t) / cycle_length) * cycle_score), max_score);
            cur = P[cur];
        }
    }
    cout << max_score << '\n';
    return 0;
}

Measured memory_bytes: 3656
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple{
    private double R, G;
    void Solve(){
        //input
        R = io.Double;
        G = io.Double;
        //cal
        var X = 2 * G - R;
        //ret
        Console.WriteLine(X);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream(){
        Solve();
        io.writeFlush();
    }
}
class SimpleIO{
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[]{' '};
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
    public SimpleIO(){
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next(){
        if(BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while(st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 11092
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.ArrayList;
public class Main {
  public static void main (String args[]) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int three = N/3;
    ArrayList<Integer>[] edge  = new ArrayList[N];
    for(int i = 0; i < N; i++){
      edge[i] = new ArrayList<>();
    }
    while(sc.hasNext()) {
      int from = sc.nextInt()-1;
      int to = sc.nextInt()-1;
      edge[from].add(to);
      edge[to].add(from);
    }
    int ans[] = new int[N];
    int depth[] = new int[N];
    depth[0] = 1;
    int ki, gu;
    ki = gu = 0;
    ArrayDeque<Integer> adq = new ArrayDeque<>();
    adq.add(0);
    while(adq.size()>0){
      int now = adq.pollFirst();
      if(depth[now]==1){
        gu++;
      } else {
        ki++;
      }
      for(int next : edge[now]){
        if(depth[next]==0){
          depth[next] = -depth[now];
          adq.addLast(next);
        }
      }
    }
    int k, l, m;
    k = l = 0;
    m = 1;
    if(ki<=three){
      for(int i=0;i<N;i++){
        if(depth[i]==-1) {
          ans[i]=3*m;
          m++;
        } else {
          if(3*k+1<=N){
            ans[i]=3*k+1;
            k++;
          } else if(3*l+2<=N){
            ans[i]=3*l+2;
            l++;
          } else {
            ans[i]=3*m;
            m++;
          }
        }
      }
    }
    else if(gu<=three){
      for(int i=0;i<N;i++){
        if(depth[i]==1) {
          ans[i]=3*m;
          m++;
        } else {
          if(3*k+1<=N){
            ans[i]=3*k+1;
            k++;
          } else if(3*l+2<=N){
            ans[i]=3*l+2;
            l++;
          } else {
            ans[i]=3*m;
            m++;
          }
        }
      }
    }
    else {
      for(int i=0;i<N;i++){
        if(depth[i]==-1) {
          if(3*k+1<=N){
            ans[i]=3*k+1;
            k++;
          } else {
            ans[i]=3*m;
            m++;
          }
        }
        else if(depth[i]==1){
          if(3*l+2<=N){
            ans[i]=3*l+2;
            l++;
          } else {
            ans[i]=3*m;
            m++;
          }
        }
      }
    }
    int c = 0;
    for(int i=0;i<N;i++){
      System.out.print(ans[i]+" ");
    }
  }
}

Measured memory_bytes: 185356
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;

int main() {
	int N, T;
	cin >> N >> T;
	vector<int> c(N), t(N);
	for (int i = 0; i < N; i++) {
		cin >> c[i] >> t[i];
	}
	vector<int> c_filtered;
	for (int i = 0; i < N; i++) {
		if (t[i] <= T) {
			c_filtered.push_back(c[i]);
		}
	}
	if (c_filtered.size() == 0) {
		cout << "TLE" << endl;
	}
	else {
		cout << *min_element(c_filtered.begin(), c_filtered.end()) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

using namespace std;

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

int Read()
{
	char c;
	c=getchar();

	int tsqua=0;

	while(c!=' '&&c!='\n')
	{
		tsqua=(((tsqua<<1)<<1)<<1)+(tsqua<<1)+(int)(c-'0');

		c=getchar();
	}

	return tsqua;
}

typedef long long ll;

int n,m;
int Deg[111111],Q[111111];
vector<int> E[111111];
int Head,Tail;
int res;
int D[111111];

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		
		E[a].pb(b);
		Deg[b]++;
	}
	
	for(int i=1;i<=n;i++)if(!Deg[i])Q[++Tail]=i;
	
	while(Head<Tail)
	{
		int x=Q[++Head];
		
		res=max(res,D[x]);
		
		for(int i=0;i<E[x].size();i++)Deg[E[x][i]]--;
		
		for(int i=0;i<E[x].size();i++)D[E[x][i]]=max(D[E[x][i]],D[x]+1);
		
		for(int i=0;i<E[x].size();i++)if(!Deg[E[x][i]])Q[++Tail]=E[x][i];
	}
	
	cout<<res;
	
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

Measured memory_bytes: 7168