akhauriyash/Code-Regression huggingface dataset:
//--- pA ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	public Solution () {
		reader = new Reader();
		while (reader.hasNext()) {
			run_case();
		}
	}
	int[] fact;
	private void run_case() {
		int N = reader.ni(), M = reader.ni();

		fact = new int[101];
		fact[0] = 1;
		for (int i=1; i<101; i++) {
			fact[i] = fact[i-1] * i;
		}

		long res = nCr(N, 2) + nCr(M, 2);
		System.out.println(res);

		return;
	}

	private long nCr(int n, int r) {
		if (n < r) return 0;
	    // return fact[n] / fact[n - r] / fact[r];
		long res = 1;
		for (long i=n-r+1; i<=n; i++) {
			res *= i;
		}
		res /= 2;
		return res;
	}
	//
	// // Returns factorial of n
	// private int fact(int n) {
	//     int res = 1;
	//     for (int i = 2; i <= n; i++)
	//         res = res * i;
	//     return res;
	// }
}


class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public String ns() {return this.next();}
}


Measured memory_bytes: 23124
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    a = list(int(_) for _ in input().split())
    a.sort()
    A = a[0]
    B = a[2]
    C = a[1]    
    if (C-A)%2 == 0:
        print((B-C)+math.ceil((C-A)/2))
    else:
        print((B-C)+math.ceil((C-A)/2)+1)
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range;
 
void main() {
    auto tmp = readln.split.to!(uint[]);
    auto A = tmp[0];
    auto B = tmp[1];
    auto C = tmp[2];
    auto D = tmp[3];
    auto E = tmp[4];
    auto F = tmp[5];

    real rateMax = 0;
    int waterMax = 0;
    int sugarMax = 0;
    foreach (a; 0..cast(int)(F / (100 * A))+1) {
        foreach (b; 0..cast(int)((F - 100 * A * a) / (100 * B))+1) {
            foreach (c; 0..cast(int)((F - 100 * (A * a + B * b)) / C)+1) {
                foreach (d; 0..cast(int)((F - 100 * (A * a + B * b) - C * c) / D)+1) {
                    auto water = 100 * (A * a + B * b);
                    auto sugar = C * c + D * d;
                    if (100 * sugar > water * E) continue;
                    auto rate = cast(real)sugar / water;
                    if (rate <= rateMax) continue;
                    rateMax = rate;
                    waterMax = water;
                    sugarMax = sugar;
                }
            }
        }
    }
    writeln(waterMax+sugarMax, " ", sugarMax);
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
long long s[100001];
int main(){
    int n;
    long long m;
    scanf("%d%lld",&n,&m);
    s[0]=0;
    for(int i=1;i<=n;i++){
        scanf("%lld",&s[i]);
        s[i]=(s[i-1]+s[i])%m;
    }
    std::sort(s,s+n+1);
    long long ans=0;
    int l=0,r;
    for(r=1;r<=n;r++){
        if(s[l]!=s[r]){
            ans+=((long long)(r-l))*(r-l-1)/2;
            l=r;
        }
    }
    ans+=((long long)(r-l))*(r-l-1)/2;
    printf("%lld",ans);
    return 0;
}

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

int main(){
    int K,A,B;
    string ans;
    cin >> K ;
    cin >> A >> B;
    for(int i = A; i < B + 1; i++){
        if(i % K == 0){
            ans = "OK";
            break;
        }else{
            ans = "NG" ;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,X,T;
void input(){
    fast_io();
    cin >> N >> X >> T;
}

int solve(){
    cout << ((N+X-1)/X)*T << endl;
    return 0;
}   

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

Measured memory_bytes: 3648
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int R, S, P;
    cin >> R >> S >> P;
    string T; cin >> T;
    int ans = 0;
    for(int j = 0; j < K; j++) {
        int sum = 0;
        char prev = '0';
        for(int i = j; i < N; i += K) {
            if(prev == '0' || T[i] != prev) {
                if(T[i] == 'r') sum += P;
                else if(T[i] == 's') sum += R;
                else sum += S;
                prev = T[i];
            } else if(T[i] == prev) {
                prev = '0';
            }
        }
        //cout << j << " " << sum << endl;
        ans += sum;
    }
    cout << ans << endl;

    return 0;
}


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

#define rep(i, x, n) for(int i=(x);i<(n);i++)
#define reps(i, x, n) for(int i=(x);i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;
//八方向を見るのに使うと便利(楽)
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  string s;
  map<string, int> score;
  cin >> n;
  rep(i, 0, n){
    cin >> s;
    score[s] ++;
  }
  cin >> n;
  rep(i, 0, n){
    cin >> s;
    score[s] --;
  }
  int ans = 0;
  for(auto x : score){
    ans = max(ans, x.second);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3620
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int m = scanner.nextInt(), k = scanner.nextInt();
			if (((m <= 1) && (0 != k)) || (k >= (1 << m))) {
				// mが0か1のとき、kは0以外、あるいは kは2^m以上
				System.out.println(-1);
				return;
			}
			int max = 1 << m;
			int[] result = new int[max << 1];
			if ((1 == m) && (0 == k)) {
				result[0] = result[1] = 0;
				result[2] = result[3] = 1;
			} else {
				IntStream.range(0, k).forEach(i -> result[i] = result[(max << 1) - i - 2] = i);
				IntStream.range(k + 1, max).forEach(i -> result[i - 1] = result[(max << 1) - i - 1] = i);
				result[max - 1] = result[(max << 1) - 1] = k;
			}
			System.out.println(Arrays.stream(result).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
		}
	}
}


Measured memory_bytes: 68876
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

const double time_limit = 1.9;
double start;

unsigned rando() {
	static unsigned y = 2463534242;
    y ^= y << 13;y ^= y >> 17;y ^= y << 5;
    return y;
}


double sec() {
	struct timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_sec + tv.tv_usec * 1e-6;
}

double pastTime() {
	return sec() - start;
}

int d;

int c[26];
int s[365][26];

int score(vector<int>& t) {
	int score = 0;
	vector<int> last(26,0);
	rep(i, d) {
		score += s[i][t[i]];
		last[t[i]] = (i + 1);

		rep(j,26) {
			score -= ((i + 1) - last[j]) * c[j];
		}
		//cout  << score << endl;

	} 


	return score;

}

void output(vector<int>& t) {
	rep(i, d) {
		cout << t[i] + 1 << endl;
	}
}


int main() {
	
	cin >> d;
	rep(i, 26) {
		cin >> c[i];
	} 
	rep(i, d) {
		rep(j,26) {
			cin >> s[i][j];
		}
	}
	start = sec();
	vector<int> t(d);

	rep(i, d) {
		int max_j = -1;
		int max_s = -1;
		rep(j, 26) {
			if (s[i][j] > max_s) {
				max_j = j;
				max_s = s[i][j];
			}
		}
		t[i] = max_j;
		
	}

	int cur = score(t);


	while(true) {
		double cur_time = pastTime();
		if (cur_time > time_limit) {
			break;
		}
		int size = (int) ((time_limit - cur_time) / time_limit * 3.5) + 1;
		if (size == 1) {
			for (int loop = 0; loop < 100; loop++) {
				int cur_d = rando() % d;
				int cur_c = rando() % 26;
				int prev_c =  t[cur_d];
				t[cur_d] = cur_c;
			
				int next = score(t);
				if (cur < next) {
					cur = next;
				} else {
					t[cur_d] = prev_c;
				}
			}
			continue;
		}
		for (int loop = 0; loop < 100; loop++) {
			stack<P> cd;
			rep(i ,size) {
				int cur_d = rando() % d;
				int cur_c = rando() % 26;
				cd.push(mkp(cur_d, t[cur_d]));
 
				t[cur_d] = cur_c;
			}
			int next = score(t);
			if (cur < next) {
				cur = next;
			} else {
				while(!cd.empty()) {
					auto cur = cd.top();
					t[cur.first] = cur.second;
					cd.pop();
				}
			}
		}
	}
	output(t);

	return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <string>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <climits>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int x = min(a, b);
    int y = max(a, b);
    for(int i = 0; i < y; ++i){
        cout << x;
    }
  
    cout << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int n;
int a[55];
int mx_id,mi_id;
int mx=-INF,mi=INF;
int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		if(mx<a[i]){
			mx = a[i];
			mx_id = i;
		}
		if(mi>a[i]){
			mi = a[i];
			mi_id = i;
		}
	}
	if(mx+mi>=0){
		cout << 2*n-1 << endl;
		for(int i=0;i<n;i++)printf("%d %d\n",mx_id+1,i+1);
		for(int i=0;i<n-1;i++)printf("%d %d\n",i+1,i+2);
	}else{
		cout << 2*n-1 << endl;
		for(int i=0;i<n;i++)printf("%d %d\n",mi_id+1,i+1);
		for(int i=n-1;i>0;i--)printf("%d %d\n",i+1,i);
	}
	return 0;
}

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

int main() {
    
    double X;
    cin>>X;
    double answer=360/X;
    double counter=2;
    if(fmod(360.0,X)==0){//1回転
     cout<<answer<<endl;
     return 0;
    }
    else{//2回転以上する場合
     while(1)
     {
       //answer*=10;
       //cout<<"counter"<<endl;
       if(fmod((360*counter),X)==0){
         answer=(360*counter)/X;
     	 cout<<answer<<endl;
         return 0;
    	}
       counter++;
     }
    }
  
    return 0;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    string W;
    cin >> W;
    
    vector<int> alphabet(26);
    /*int a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0, j=0, k=0, l=0, m=0, n=0, o=0;
    int p=0, q=0, r=0, s=0, t=0, u=0, v=0, w=0, x=0, y=0, z=0;*/
    
    for(int I = 0; I < W.size(); I++) {
        if (W.at(I) == 'a') alphabet.at(0)++;
        else if (W.at(I) == 'b') alphabet.at(1)++;
        else if (W.at(I) == 'c') alphabet.at(2)++;
        else if (W.at(I) == 'd') alphabet.at(3)++;
        else if (W.at(I) == 'e') alphabet.at(4)++;
        else if (W.at(I) == 'f') alphabet.at(5)++;
        else if (W.at(I) == 'g') alphabet.at(6)++;
        else if (W.at(I) == 'h') alphabet.at(7)++;
        else if (W.at(I) == 'i') alphabet.at(8)++;
        else if (W.at(I) == 'j') alphabet.at(9)++;
        else if (W.at(I) == 'k') alphabet.at(10)++;
        else if (W.at(I) == 'l') alphabet.at(11)++;
        else if (W.at(I) == 'm') alphabet.at(12)++;
        else if (W.at(I) == 'n') alphabet.at(13)++;
        else if (W.at(I) == 'o') alphabet.at(14)++;
        else if (W.at(I) == 'p') alphabet.at(15)++;
        else if (W.at(I) == 'q') alphabet.at(16)++;
        else if (W.at(I) == 'r') alphabet.at(17)++;
        else if (W.at(I) == 's') alphabet.at(18)++;
        else if (W.at(I) == 't') alphabet.at(19)++;
        else if (W.at(I) == 'u') alphabet.at(20)++;
        else if (W.at(I) == 'v') alphabet.at(21)++;
        else if (W.at(I) == 'w') alphabet.at(22)++;
        else if (W.at(I) == 'x') alphabet.at(23)++;
        else if (W.at(I) == 'y') alphabet.at(24)++;
        else alphabet.at(25)++;
    }
    
    bool flag = true;
    for (int I = 0; I < 26; I++) {
        if (alphabet.at(I) % 2 == 1) {
            flag = false;
            break;
        }
    }
    
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;
#define odd 1
#define even 0

int main() {
	int n,count=1;
	cin >> n;
	int ans1 = n / 2,ans2=n/2;
	vector<int>v(n),vo,ve;
	vector<tuple<int, int,int>>vc;
	repp(i, 0, n)cin >> v[i];
	for (int i = 0; i < n - 1; i += 2)vo.push_back(v[i]);
	for (int i = 1; i < n; i += 2)ve.push_back(v[i]);
	sort(vo.begin(), vo.end()); sort(ve.begin(), ve.end());
	for (int i = 0; i < vo.size()-1; ++i) {
		if (vo[i] == vo[i + 1])++count;
		else {
			vc.push_back(make_tuple(count, vo[i],odd));
			count = 1;
		}
	}vc.push_back(make_tuple(count, vo[vo.size() - 1],odd));
		count = 1;
	for (int i = 0; i < ve.size() - 1; ++i) {
		if (ve[i] == ve[i + 1])++count;
		else {
			vc.push_back(make_tuple (count, ve[i],even));
			count = 1;
		}
	}vc.push_back(make_tuple (count, ve[ve.size() - 1],even));
	sort(vc.begin(), vc.end());
	for (int i = 0;i<vc.size(); i++) {
		if (get<1>(vc[vc.size()-2]) != get<1>(vc[i])) {
			if (get<2>(vc[vc.size() - 2]) != get<2>(vc[i])) {
				ans1 = n / 2 - get<0>(vc[vc.size() - 2]) + n / 2 - get<0>(vc[i]);
			}
		}

		if (get<1>(vc[vc.size() - 1]) != get<1>(vc[i])) {
			if (get<2>(vc[vc.size() - 1]) != get<2>(vc[i])) {
				ans2 = n / 2 - get<0>(vc[vc.size() - 1]) + n / 2 - get<0>(vc[i]);
			}
		}
	}
	cout << min(ans1,ans2) << endl; return 0;
}

Measured memory_bytes: 2676
import java.util.*;
import java.lang.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        long k = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long biscuit = 1;
        long rest = k;
        long max = 0;
        long ans = 0;
        int money = 0;
        
        
        rest = k - (a - 1);
        biscuit = a;
        
        if (b - a <= 1) {
            max = k + 1;
        } else {
            while (rest > 0) {
                if (rest == 1) {
                    if (money == 0) {
                        biscuit++;
                    } else {
                        biscuit += b;
                    }
                    break;
                }
                if (biscuit >= a && money == 0) {
                    biscuit -= a;
                    money ++;
                } else {
                    biscuit += b;
                    money --;
                }
                rest --;
                //System.out.println(biscuit);
            }
            max = biscuit;
        }
        
        ans = max;
        //System.out.println("---");
        System.out.println(ans);
    }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
 
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;
}

ll lcm(ll a,ll b){
    return (a * b) / __gcd(a,b);
}

const ll INF = 10010001010;
const int inf = 1000034000;
 
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    deque<int> B;
    for(int i = 0;i < N;i++){
        cin >> A[i];
        if(i%2 == 1){
            B.push_back(A[i]);
        }
        else{
            B.push_front(A[i]);
        }
    }
    if(N %2 == 0){
        for(int i = B.size()-1;i >= 0;i--){
            cout << B[i] <<" ";
        }
    }
    else{
        for(int i = 0;i < B.size();i++){
            cout << B[i] <<" ";
        }
    }
    cout << endl;
} // 7 7 0 6 6 0

Measured memory_bytes: 4804
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    int t[n],x[n],y[n];
    int inx=0,iny=0,intt=0;
    for(i=0;i<n;i++)
    {
        cin>>t[i]>>x[i]>>y[i];
    }
    for(i=0;i<n;i++)
    {
        int g=abs(x[i]-inx);
        int h=abs(y[i]-iny);
        int timt=t[i]-intt;
       // cout<<(timt-(g+h))<<endl;
        if((g+h)<=timt&&(timt-(g+h))%2==0)
        {
            continue;
        }
        else
        {
            cout<<"No\n";
            return 0;
        }
        intt=t[i];
        inx=x[i];
        iny=y[i];
    }
    cout<<"Yes\n";
}


Measured memory_bytes: 1408
#include<stdio.h>

int main(void){
    long long int N;
    long long int U[5];
    scanf("%lld", &N);
    //long long int UN[5] = {N, 0, 0, 0, 0};
    //long long int UN_tmp[5] = {N, 0, 0, 0, 0};
    for(int i = 0; i < 5; i++){
        scanf("%lld", &U[i]);
    }
    
    long long int t = U[0];
    for(int i = 1; i< 5; i++){
        t = U[i] < t ? U[i] : t;
        //printf("%lld\n", t);
    }
    //printf("%lld\n", t);
    //t = (int)( (double)(N) / (double)(t) + 0.9) + 4;
    t = (N + t - 1) / t + 4;
    printf("%lld", t);
    /*
    int flag = 0;
    for(;;){
        for(int i = 3; i >= 0; i--){
            if(UN[i] > 0){
                UN_tmp[i] -= U[i];
                int s = 0;
                if(UN_tmp[i] < 0){
                    s = UN_tmp[i];
                    UN_tmp[i] = 0;
                }
                UN_tmp[i + 1] += (U[i] + s);
                flag++;
            }
        }
        for(int i = 0; i < 4; i++){
            UN[i] = UN_tmp[i];
            //printf("%lld ", UN[i]);
        }
        //printf("\n");
        t++;
        if(flag == 0){
            printf("%lld", t);
            break;
        }
        flag = 0;
    }
    */
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <algorithm>
#include <cmath>
#define INF 99999999
using namespace std;

class Point {
public:
  int x;
  int y;
  int id;
  Point(int x=0, int y=0) : x(x), y(y) {}
  Point operator -(Point p) {
    return Point(x-p.x, y-p.y);
  }
};

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    Point bill[n];
    map<int, int> id_i;
    for(int i = 0; i < n; i++) {
      int id, x, y;
      cin >> id >> x >> y;
      id_i[id] = i;
      bill[i].x = x;
      bill[i].y = y;
      bill[i].id = id;
    }

    double data[n][n];
    fill(&data[0][0], &data[n-1][n-1]+1, INF);
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
	data[i][j] = data[j][i]
	  = sqrt(pow((double)(bill[i].x-bill[j].x), 2)
		 +pow((double)(bill[i].y-bill[j].y), 2));
      }
    }

    int m;
    cin >> m;
    for(int t = 0; t < m; t++) {
      int s, g;
      cin >> s >> g;

      int cost[n];
      int from[n];
      bool visited[n];
      fill(&cost[0], &cost[n], INF);
      cost[id_i[s]] = 0;
      fill(&visited[0], &visited[n], false);

      while(1) {
	int min = INF;
	int p;
	for(int i = 0; i < n; i++) {
	  if(!visited[i] && cost[i] < min) {
	    min = cost[i];
	    p = i;
	  }
	}
	if(min == INF) break;

	visited[p] = true;

	for(int i = 0; i < n; i++) {
	  if(!visited[i] && data[p][i] <= 50) {
	    int newValue = cost[p] + data[p][i];
	    if(newValue < cost[i]) {
	      cost[i] = newValue;
	      from[i] = p;
	    }
	  }
	}
      }

      if(cost[id_i[g]] == INF) {
	cout << "NA" << endl;
      } else {
	int out[n];
	out[0] = id_i[g];
	int out_lim;
	for(int i = 1; i < n; i++) {
	  if(out[i-1] == id_i[s]) {
	    out_lim = i-2;
	    break;
	  }
	  out[i] = from[out[i-1]];
	}

	cout << s;
	for(int i = out_lim; i >= 0; i--) {
	  cout << " " << bill[out[i]].id;
	}
	cout << endl;
      }
    }
  }
}

Measured memory_bytes: 0
# Sum of 4 Integers

import sys

datas = []

for line in sys.stdin:
	datas.append(int(line))

for data in datas:
	count = 0
	for a in xrange(10):
		for b in xrange(10):
			for c in xrange(10):
				for d in xrange(10):
					if data == a + b + c + d:
						count += 1
	print count

Measured memory_bytes: 4216
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

void solved(){
  string s;
  getline(cin,s);
  string w[] = {"apple","peach"};
  
  rep(i,s.size()-5+1){
        string ss=s.substr(i,5);
        if(ss==w[0])s.replace(i,5,w[1]);
        else if(ss==w[1])s.replace(i,5,w[0]);
    }

  cout<<s<<endl;
}

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

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

int main() {
  int N;
  cin >> N;
  double x[N], y[N];
  for (int i=0; i<N; i++)
    cin >> x[i] >> y[i];
  double inf = 0.0, sup = 1000.0;
  while (sup - inf > 0.000000001) {
    double m = (sup + inf)/2;
    bool check = false;
    for (int i=0; i<N-1; i++) {
      for (int j=i+1; j<N; j++) {
        double xi = x[i], xj = x[j], yi = y[i], yj = y[j];
        double d = (xi-xj)*(xi-xj) + (yi-yj)*(yi-yj);
        d /= 4;
        if (m*m < d)
          break;
        double a = sqrt(m*m - d);
        d = sqrt(d);
        double x1 = (xi+xj)/2 + (yj-yi)/2/d*a, x2 = (xi+xj)/2 - (yj-yi)/2/d*a, y1 = (yi+yj)/2 - (xj-xi)/2/d*a, y2 = (yi+yj)/2 + (xj-xi)/2/d*a;
        bool c = true;
        for (int k=0; k<N; k++) {
          if ((x1-x[k])*(x1-x[k]) + (y1-y[k])*(y1-y[k]) > m*m+0.000001) {
            c = false;
            break;
          }
        }
        if (c)
          check = true;
        c = true;
        for (int k=0; k<N; k++) {
          if ((x2-x[k])*(x2-x[k]) + (y2-y[k])*(y2-y[k]) > m*m+0.000001) {
            c = false;
            break;
          }
        }
        if (c)
          check = true;
      }
    }
    if (check)
      sup = m;
    else
      inf = m;
  }
  printf("%.18lf\n", inf);
  return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int A, B;
    cin >> A >> B;

    for (int c = 1; c <= 3; c++) {
        if (A * B * c % 2) {
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int A[100], N;
int main(){
  int i, k, mn, res, tmp;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY, Q5VJL1cS;
    if(N==0){
      Q5VJL1cS = 0;
    }
    else{
      Q5VJL1cS = A[0];
      for(KL2GvlyY=1;KL2GvlyY<N;KL2GvlyY++){
        Q5VJL1cS += A[KL2GvlyY];
      }
    }
    k = 2*Q5VJL1cS;
  }
  mn = 1000000000;
  for(i=0;i<N;i++){
    tmp = abs(2*A[i]*N - k);
    if(mn > tmp){
      mn = tmp;
      res = i;
    }
  }
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20180730-1

// --- original code ---
// int N, A[100];
// {
//   int i, k;
//   int res, mn, tmp;
//   
//   rd(N,A(N));
//   k = 2*sum(A(N));
// 
//   mn = 1d9;
//   rep(i,N){
//     tmp = abs(2*A[i]*N - k);
//     if(mn > tmp){
//       mn = tmp;
//       res = i;
//     }
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;


// ============union_find_tree===============
vector<ll> par;//MAX_N == num of node
vector<ll> tree_rank;

void init(ll n)
{
  par = vector<ll>(n);
  tree_rank = vector<ll>(n, 0);
  for (ll i = 0; i < n; ++i)
  {
    par.at(i) = i;
  }
}

ll find(ll x)
{
  if (par.at(x) == x)
  {
    return x;
  }
  else
  {
    return par.at(x) = find(par.at(x));
  }
}

void unite(ll x, ll y)
{
  x = find(x);
  y = find(y);
  if (x == y)
  {
    return;
  }
  if (tree_rank.at(x) < tree_rank.at(y))
  {
    par.at(x) = y;
  }
  else
  {
    par.at(y) = x;
    if (tree_rank.at(x) == tree_rank.at(y))
    {
      tree_rank.at(x)++;
    }
  }
}

bool same(ll x, ll y)
{
  return find(x) == find(y);
}
// =======================================

int main()
{
  ll N, M;
  cin >> N >> M;
  init(N);
  for (ll i = 0; i < M; ++i)
  {
    ll x, y, z;
    cin >> x >> y >> z;
    unite(x - 1, y - 1);
  }
  vector<bool> p(N, false);
  ll ans = 0;
  for (ll i = 0; i < N; ++i)
  {
    find(i);
    if (p.at(par.at(i)))
    {
      continue;
    }
    p.at(par.at(i)) = true;
    ans += 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
using namespace std;

const int H_MAX = 300;
const int Q_MAX = 100000;

int H, W, D;
int Q;
int L[Q_MAX + 1], R[Q_MAX + 1];

int memo[H_MAX * H_MAX][2];
int sum[H_MAX * H_MAX + 1];

int main() {
  scanf("%d %d %d", &H, &W, &D);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int x;
      scanf("%d", &x);
      memo[x][0] = i;
      memo[x][1] = j;
    }
  }
  for (int i = D + 1; i <= H * W; i++) {
    sum[i] = sum[i - D] + abs(memo[i][0] - memo[i - D][0]) + abs(memo[i][1] - memo[i - D][1]);
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d %d", &L[i], &R[i]);
  }
  for (int i = 0; i < Q; i++) {
    int r = R[i];
    int l = L[i];
    printf("%d\n", sum[r] - sum[l]);
  }
}


Measured memory_bytes: 2816
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long n =sc.nextLong();
		int f = (int)Math.floor((double)500*sc.nextDouble());
		long temp = n*f;
		temp/=(long)500;
		System.out.println(temp);
	}
}

Measured memory_bytes: 37376
from sys import stdin, setrecursionlimit
from collections import deque


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    g = [[] for _ in range(n)]
    for _ in range(m):
        u, v = map(int, input().split())
        g[u - 1].append(v - 1)
    s, t = map(int, input().split())

    q = deque()
    q.append(s - 1)
    seen = [[-1 for _ in range(3)] for _ in range(n)]
    seen[s - 1][2] = 0

    while q:
        u = q.popleft()

        for v in g[u]:
            for i in range(3):
                if seen[u][i] != -1 and seen[v][(i + 1) % 3] == -1:
                    seen[v][(i + 1) % 3] = seen[u][i] + 1
                    q.append(v)
                    if seen[t - 1][2] != -1:
                        print(seen[t - 1][2] // 3)
                        exit()
    print(-1)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 67504
import { count } from 'console';

process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const k = Number(inputs[0]);
  const [a, b] = inputs[1].split(' ').map(Number);
  let isPossible = false;

  for (let i = a; i <= b; i++) {
    if (i % k === 0) {
      isPossible = true;
      break;
    }
  }

  if (isPossible) {
    console.log('OK');
  } else {
    console.log('NG');
  }
}


Measured memory_bytes: 29916
use std::io;
fn main() {
    let _ = get_line();
    let has_four = get_line().split_whitespace().fold(false, |acc, h| match h {
        "Y" => true,
        _ => acc,
    });
    if has_four {
        println!("Four");
    } else {
        println!("Three");
    }
}

fn get_line() -> String {
    let mut inp = String::new();
    io::stdin().read_line(&mut inp).expect("read error");
    inp.trim().to_string()
}


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

int main() {
 ll x;
 cin >>x;
 ll r = x%11;
 ll q = x/11;
 
 if(r == 0){
   cout << q*2 << endl;
 }
  else if(r>=1 && r<=6){
   cout << q*2 + 1 <<endl;
  }
  else if(r>=7){
   cout << q*2 + 2 <<endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int i,j;
	if(s.compare(t)==0)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	for(i=0;i<s.length();i++)
	{
		char temp = s[s.length()-1];
		char te = s[0];
		char ye;
		for(j=0;j<s.length()-1;j++)
		{
			ye = s[j+1];
			s[j+1]=te;
			te=ye;
		}
		s[0]=temp;
		// cout<<s<<endl;
		if(s.compare(t)==0)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <chrono>
#include <complex>
using namespace std;

#define rep(i,n) for(int i=0; i < n; i++)
#define REP(i,n) for(int i=1; i <= n; i++)
#define Rep(i,a,n) for(int i=a; i < n; i++)
#define ll long long int
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define F first
#define S second


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	char alpha;
	cin >> alpha;

	for (int i=65; i<91; i++){
		if (int(alpha) == i){
			cout << "A"<< endl;
			break;
		}
	}
	for (int i=97; i<123; i++){
		if (int(alpha) == i){
			cout << "a"<< endl;
			break;
		}
	}

	return 0;
}

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

int digit(int n){
    int ans = 0;
    while(n > 0){
        ans += n % 10;
        n /= 10;
    }
    return ans;
}

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

    long long ans = 0;
    for(int i = 1;i <= n;i++){
        if(a <= digit(i) && digit(i) <= b){
            ans += i;
        }
    }

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



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

#define int long long
#define pii pair<int,int>
#define pqi priority_queue<int>
#define pb push_back()
#define INF 1000000000000000000

#define pi acos(-1)

const int modu= (1e9)+7;

void testCase(int ti){
    cout<<"Case "<<ti<<": ";
}

int bigmod(int n,int p){
    if(p==0) return 1;
    int x=bigmod(n,p/2)%modu;
    x=(x*x)%modu;
    if(p%2) return (x*n)%modu;
    return x;
}

int modInverse(int a){
    return bigmod(a,modu-2)%modu;
}

void debug(string pr,vector<int> var,bool out=true){
    #ifdef OFFLINE
        ofstream fl;
        fl.open("debug.txt");
        fl<<pr;
        for(int i=0;i<var.size();i++) fl<<" "<<var[i];
        fl<<endl;
        fl.close();
    if(out){
        cout<<pr;
        for(int i=0;i<var.size();i++) cout<<" "<<var[i];
        cout<<endl;
    }
    #endif
}

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
}

void defInit(){
    //faster();
    #ifdef OFFLINE
      freopen("in.txt", "r", stdin);
      freopen("out.txt", "w", stdout);
    #endif
}

int add(int x,int y){
    int z =(x%modu + y%modu)%modu;
    while(z<0) z=(z+modu)%modu;
    return z;
}

int mul(int x,int y){
    int z = (x%modu * y%modu)%modu;
    while(z<0) z=(z+modu)%modu;
    return z;
}
// starts here
#define float long double
const int MAXN = 3000;
int n;
float ara[MAXN];
vector<vector<float>> dp(MAXN,vector<float>(MAXN,-1));

float calc(int idx,int rem){
    float &now=dp[idx][rem];
    if(now!=-1) return now;
    if(idx==n) return now=1;
    float ans1=0,ans2=0;
    if(rem) ans1=(1-ara[idx])*calc(idx+1,rem-1);
    ans2=ara[idx]*calc(idx+1,rem);
    return now=ans1+ans2;
}

int32_t main(){
    defInit();
    //Now I will start writing codes and start preparation to get errors
    cin>>n;
    for(int i=0;i<n;i++) cin>>ara[i];
    int rem=(n-1)/2;
    cout<<fixed<<setprecision(10);
    cout<<calc(0,rem);
    return 0;
}


Measured memory_bytes: 141312
from collections import defaultdict


def solve():
    _ = int(input())
    a = list(map(int, input().split()))
    
    b_dict = defaultdict(int)
    for ai in a:
        b_dict[ai] += 1
    
    ans = 0
    for key, val in b_dict.items():
        if val < key:
            ans += val
        elif key < val:
            ans += val - key
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 18676
# coding: utf-8
N = input()
length = len(N)
ans = 0
if length == 1:
    ans = int(N)
elif length == 2:
    ans = 9
elif length == 3:
    ans = 9 + int(N) - 99
elif length == 4:
    ans = 909
elif length == 5:
    ans = 909 + int(N) - 9999
elif length == 6:
    ans = 90909
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define FIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define fore(i,a,b) for(int i = a; i < b; i++)
using namespace std;
typedef long long ll;

const int MXN = 1e5+1, INF = 1<<28;
int N;
vector<int> g[MXN], P;
int V[MXN];

int dfs(int u, int p=-1){
  if(u == N-1) { P.pb(u); return 1; }
  for(int v : g[u])
    if(p != v && dfs(v,u)){
      P.pb(u); return 1;
    }
  return 0;
}

void dfs2(int u){
  for(int v : g[u])
    if(!V[v])
      V[v] = V[u], dfs2(v);
}

int main() {
  cin >> N;
  fore(x,0,N-1){
    int u,v; cin >> u >> v;u--;v--;
    g[u].pb(v); g[v].pb(u);
  }

  dfs(0);
  reverse(ALL(P));

  int i = 0, j = SZ(P)-1;
  for(int x = 0; x < SZ(P); x+=2){
    V[P[i]] = 1; i++;
    if(i <= j) V[P[j]] = 2, j--;
  }

  for(int v : P)
   dfs2(v);
  cout << (count(V,V+N,1) > count(V,V+N,2) ? "Fennec" : "Snuke") << "\n";
}


Measured memory_bytes: 11256
from collections import deque
from collections import defaultdict
n, m = map(int, input().split())

edges = defaultdict(lambda: [])
for i in range(m):
    u, v = map(int, input().split())
    u1, v1 = (0, u), (1, v)
    u2, v2 = (1, u), (2, v)
    u3, v3 = (2, u), (0, v)
    edges[u1].append(v1)
    edges[u2].append(v2)
    edges[u3].append(v3)
    #u1, v1 = (0, v), (1, u)
    #u2, v2 = (1, v), (2, u)
    #u3, v3 = (2, v), (0, u)
    #edges[u1].append(v1)
    #edges[u2].append(v2)
    #edges[u3].append(v3)

#print(edges)
s, t = map(int, input().split())
s = (0, s)
t = (0, t)
#print(edges)
dist = {}
dist[s] = 0
visiting = deque()
visiting.append(s)
while len(visiting) > 0:
    #print(visiting)
    v = visiting.popleft()
    # check neighbors of v
    neighbors = edges[v]
    for neighbor in neighbors:
        if neighbor in dist:
            continue
        visiting.append(neighbor)
        if neighbor in dist:
            dist[neighbor] = min([dist[neighbor], dist[v] + 1])
        else:
            dist[neighbor] = dist[v] + 1
        
#print(dist)
#print(dist)
if t not in dist:
    print(-1)
else:
    if dist[t] % 3 == 0:
        print(dist[t] // 3 )
    else:
        print(-1)


Measured memory_bytes: 123292
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>

using namespace std;

const int MAXN = 100000 + 1000;

int n, tot, ans = 0;
int a[MAXN], b[MAXN];
vector<int> edg[MAXN];

void discrete()
{
	static map<int, int> d;
	for(int i = 0; i <= n; i++)
		a[i] = (d[a[i]] ? d[a[i]] : d[a[i]] = ++tot);
	for(int i = 0; i <= n; i++)
		b[i] = (d[b[i]] ? d[b[i]] : d[b[i]] = ++tot);
}

bool check_no()
{
	static int arr1[MAXN], arr2[MAXN];
	for(int i = 0; i <= n; i++)
		arr1[i] = a[i], arr2[i] = b[i];
	sort(arr1, arr1 + n + 1);
	sort(arr2, arr2 + n + 1);
	for(int i = 0; i <= n; i++)
		if(arr1[i] != arr2[i])
			return true;
	return false;
}

bool vis[MAXN];
int dfs(int x)
{
	int ret = 1;
	vis[x] = true;
	for(int i = 0; i < edg[x].size(); i++)
		if(!vis[edg[x][i]])
			ret += dfs(edg[x][i]);
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 1; i <= n; i++)
		cin >> b[i];
	for(int i = 1; i <= n; i++)
		a[0] ^= a[i], b[0] ^= b[i];

	if(check_no())
	{
		cout << -1 << endl;
		return 0;
	}
	discrete();
	for(int i = 0; i <= n; i++)
		if(a[i] != b[i])
		{
			ans++;
			edg[a[i]].push_back(b[i]);
			edg[b[i]].push_back(a[i]);
		}
	if(!ans)
	{
		cout << 0 << endl;
		return 0;
	}
	if(a[0] != b[0])
		ans = ans - 1;
	for(int i = 1; i <= n + 1; i++)
		if(!vis[i])
			if(dfs(i) > 1 || (i == a[0] && a[0] == b[0]))
				ans++;
	ans = ans - 1;
	cout << ans << endl;


	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define Max(x, y)(max(decltype(x)(0), max((x), (y))))
#define Min(x, y)(max(decltype(x)(0), min((x), (y))))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define _end '\n'
#define Out(x) cout<<(x)<<_end
template<typename T> inline bool _max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool _min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    bool isY = false;
    char ch;

    int i;

    rep(i, n) {
        cin >> ch;

        if (ch == 'Y') isY = true;
    }

    if (isY) Out("Four");
    else Out("Three");

    return 0;
}


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

int w,h,n;

int main(){
	cin >> w >> h >> n;
	int lx = 0, rx = w;
	int ly = 0, ry = h;
	while(n--){
		int x,y,a;
		cin >> x >> y >> a;
		if(a==1){
			lx = max(lx,x);
		} else if(a==2){
			rx = min(rx,x);
		} else if(a==3){
			ly = max(ly,y);
		} else if(a==4){
			ry = min(ry,y);
		}
	}
	cout << max(0,rx-lx)*max(0,ry-ly) << endl;
	return 0;
}


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

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(a >= 13){
        cout << b;
    }else if(a <= 5){
        cout << 0;
    }else{
        cout << b/2;
    }
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 500010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
#define ull unsigned long long
#define mp make_pair
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int n, m;

int main() {
	io(); cin >> n >> m;
	if (n < m) rep(i, 1, m) cout << n;
	else rep(i, 1, n) cout << m;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int p,q;
    char x,y;
    cin>>x>>y;
    p=x,q=y;

    if(p>=65 && p<=70 && q>=65 && q<=70)
    {
        if(p>q) cout<<">\n";
        else if(p<q) cout<<"<\n";
        else if(p==q) cout<<"=\n";
    }
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat
const int N = 1e5 + 5;
bool visited[N]={false};
int dp[N]={0};
int indegree[N]={0};
vector<int> adj[N];

void dfs(int start){
	visited[start] = true;
	for(auto x:adj[start]){
		dp[x] = max(dp[x],dp[start]+1);
		indegree[x]--;
		if(!visited[x] && indegree[x]==0){
			dfs(x);
		}
	}
}

int main(int argc, char const *argv[])
{
	sync;
	int n, m;
	cin >> n >> m;
	int u, v;
	rep(i,m)
	{
		cin >> u >> v;
		adj[u].pb(v);
		indegree[v]++;
	}
	for(int i=1; i<=n; i++){
		if(!visited[i] && indegree[i]==0){
			dfs(i);
		}
	}
	int ans = 0;
	for(int i=1; i<=n; i++){
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  int a, b, c;
  cin >> a >> b >> c;
  int s;
  for (int i = 1; i < 1000; i++){
    s = (a * i) % b;
    if (s == c){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256