akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int sol = (int) 1e9;
  for (int x = a[0]; x <= a.back(); x++) {
    int cur = 0;
    for (auto &y : a) {
      cur += (x - y) * (x - y);
    }
    sol = min(sol, cur);
  }
  cout << sol << "\n";

}


Measured memory_bytes: 256
## 0~Nまでの数のxorsを計算する
def xors_0toN(N):
  if N <= 1:
    return N
  #bin_lst = [1*(N%4==1 or N%4==2)] ## 最下位ビット
  ans = 1*(N%4==1 or N%4==2)
  i = 2
  while (N >= i):    
    if N % (2*i) > i-1 and N % 2 == 0:
      ans += i
    i *= 2
  return ans


A, B = map(int, input().split())

ans = xors_0toN(B) ^ xors_0toN(max(A-1,0))
print(ans)

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

#define MAXN 420
#define INF 100000000000000

int N;
long long a[MAXN];
long long dp[MAXN][MAXN];
long long pre[MAXN];

int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> a[i];
  for (int i = 1; i <= N; i++) pre[i] = pre[i-1] + a[i];
  
  for (int i = 1; i <= N; i++) dp[i][i] = 0;
  
  for (int j = 1; j < N; j++) {
    for (int i = 1; i + j <= N; i++) {
      dp[i][i+j] = INF;
      for (int k = i; k < i+j; k++) {
        dp[i][i+j] = min(dp[i][i+j],dp[i][k]+dp[k+1][i+j]+pre[i+j]-pre[i-1]);
      }
    }
  }
  cout << dp[1][N] << endl;
}
  

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T> T expo(T base, T e, T mod) { T res = 1;
  while(e > 0) { if(e&1) res = res * base % mod; base = base * base % mod; e >>= 1; }
  return res;
}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}
int main() {
  ios_base::sync_with_stdio(false);
	LL n, a, b;
	cin >> n >> a >> b;
	LL res = (b*(n-1) + a) - (b + a*(n - 1)) + 1;
	res = max(res, 0ll);
	cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
const int MOD=1e9+7;
using pii=std::pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

using namespace std;

int n,y;
class COtoshidama {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> n >> y;
		f(i,0,n+1)
		    f(j,0,n+1-i)
		    	if(i*10000+j*5000+(n-i-j)*1000==y)
				{
		    		out << i << " " << j << " " << (n-i-j) << "\n";
					return;
				}
		out << "-1 -1 -1\n";
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	COtoshidama solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005

int main()
{
    fastread;
    string s;
    cin>>s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7') {
    	cout<<"Yes"<<endl;
    }
    else {
    	cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<pair<int, int> > a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i].first;
		b[i].second = i;
	}
	sort(a.begin(), a.end());              // 从小到大排序 
	sort(b.begin(), b.end());
	for (int i = 0; i < n; i++) {
		if (a[i].first > b[i].first) {
			cout << "No\n";
			return 0;
		}
	}
	for (int i = 1; i < n; i++) {
		if (a[i] <= b[i - 1]) {
			cout << "Yes\n";
			return 0;
		}
	}
	vector<int> to(n);
	for (int i = 0; i < n; i++) {
		to[a[i].second] = b[i].second;
	}
	int cur = 0;
	int cnt = 0;
	do {
		cur = to[cur];
		cnt++;
	} while (cur != 0);
	cout << (cnt > (n - 1) ? "No\n" : "Yes\n");
	return 0;
}

Measured memory_bytes: 2176
AC = 0
WA = 0
TLE = 0
RE = 0

N = int(input())
for _ in range(N):
    S = input()
    if S == 'AC':
        AC += 1
    elif S == 'WA':
        WA += 1
    elif S == 'TLE':
        TLE += 1
    else:
        RE += 1

print('AC' + ' x ' + str(AC))
print('WA' + ' x ' + str(WA))
print('TLE' + ' x ' + str(TLE))
print('RE' + ' x ' + str(RE))


Measured memory_bytes: 69872
#define _CRT_SECURE_NO_WARNINGS
//#include <bits/stdc++.h>
#include <iostream>
#define stop(x) {cout<<x<<endl;exit(0);}
#define all(x) x.begin(),x.end()
#define szz(s) int(s.size())
#define endl '\n'
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
typedef long long ll;
using namespace std;

void file() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    if (freopen("input.txt", "r", stdin));
    if (freopen("output.txt", "w", stdout));
#endif
}


int main()
{
    file();

    int n;
    cin >> n;
    cout << 2 * (22/7.0) * n << endl;




}


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

const int dire4[8] = {
	-1, 0,
	0, 1,
	1, 0,
	0, -1
};

int main(){
	pair<int, int> box[200];
	
	while(1){
		box[0].first = 0;
		box[0].second = 0;
		int N;
		cin >> N;
		if(N == 0) break;
		int width = 1, height = 1;
		for(int i = 1;i < N;i++){
			int n, d;
			cin >> n >> d;
			box[i].first = box[n].first + dire4[d * 2];
			box[i].second = box[n].second + dire4[d * 2 + 1];
			bool ext = true;
			for(int j = 0;j < i;j++){
				if(d % 2 == 0){
					if(box[i].first == box[j].first){
						ext = false;
						break;
					}
				}else{
					if(box[i].second == box[j].second){
						ext = false;
						break;
					}
				}
			}
			if(ext){
				if(d % 2 == 0) width++;
				else height++;
			}
		}
		
		cout << width << ' ' << height << endl;
	}
	
	return 0;
}

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  
  int countshou=0;
  int countdai=0;
  
  vector<int> a(M);
  for(int i=0;i<M;i++){
    cin >> a.at(i);
    if(a.at(i)<X){countshou++;}
    else if(a.at(i)>X){countdai++;}
  }
  
  cout << min(countshou,countdai) << endl;
    
          
}

Measured memory_bytes: 3636
number = int(input())
heights = list(map(int, input().split()))
plusminus=[]
answerlist = [0]
q = 0
for i in range(number-1):
    if i != number-2 and heights[i]>=heights[i+1]:
        q += 1
    elif i == number-2 and heights[i]>=heights[i+1]:
        q += 1
        answerlist.append(q)
    else:
        answerlist.append(q)
        q = 0
print(max(answerlist))

Measured memory_bytes: 14352
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<functional>
#include<set>
using namespace std;
#define int long long
typedef pair<int, int> P;
#define inf 114514
string s[55];
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 };
int d[55][55];
signed main() {
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++)cin >> s[i];
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)d[i][j] = inf;
	queue<P>Q;
	d[0][0] = 0;
	Q.push(P(0, 0));
	if (s[0][0] == '#') {
		cout << -1 << endl; return 0;
	}
	while (Q.size()) {
		P p = Q.front();
		Q.pop();
		int pf = p.first, ps = p.second;
		
		for (int i = 0; i < 4; i++) {
			int nf = p.first + dx[i], ns = ps + dy[i];
			if (0 <= nf&&nf < h && 0 <= ns&&ns < w&&d[nf][ns] == inf&&s[nf][ns] == '.') {
				d[nf][ns] = d[pf][ps] + 1;
				Q.push(P(nf, ns));
			}
		}
	}
	if (d[h - 1][w - 1] == inf) {
		cout << -1 << endl;
		return 0;
	}
	else {
		int cnd = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (s[i][j] == '.')cnd++;
			}
		}
		cout << max(0ll, cnd - d[h-1][w-1]-1) << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  cout << (N+1)/2 << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
main()
{
	int n,m,l,b;
	while(cin>>n>>m>>l>>b,n)
	{
		vector<int> back,lose;
		for(int i=0;i<l;i++)
		{
			int u;cin>>u;
			lose.push_back(u);
		}
		for(int i=0;i<b;i++)
		{
			int u;cin>>u;
			back.push_back(u);
		}
		double dp[102][101]={};//tarn,place
		dp[0][0]=1.0;
		for(int i=0;i<m;i++)
		{
			for(int p=0;p<n;p++)
			{
				for(int j=1;j<=6;j++)
				{
					int u=p+j;
					int t=1;
					if(u>n)u=n-(u-n);
					bool flag=false;
					for(int k=0;k<l;k++)if(u==lose[k])flag=true;
					if(flag)t++;
					flag=false;
					for(int k=0;k<b;k++)if(u==back[k])flag=true;
					if(flag)u=0;
					dp[i+t][u]+=dp[i][p]/6.0;
				}
			}
			dp[i+1][n]+=dp[i][n];
		}
		cout<<fixed<<setprecision(9)<<dp[m][n]+dp[m+1][n]<<endl;
	}
}

Measured memory_bytes: 3268
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int a,b;
  cin >> a >> b;
  cout << 6-a-b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) (v).begin(),(v).end()

using namespace std;

typedef pair<int,int>P;

int p;

class BIT{
public:
    int n; vector<int> bit;
    void add(int i,int x){
        i++;
        while(i < n) bit[i] = (bit[i]+x)%p, i += i & -i;
    }
    int sum(int i){
        i++;
        int s = 0;
        while(i > 0) s = (s+bit[i])%p, i -= i & -i;
        return s;
    }
    BIT(int sz){
        n = sz+1, bit.resize(n,0);
    }
};

int dp[100005];

int main()
{
    while(1){
        int a,b;
        cin >> a >> b >> p;
        if(a == 0) break;
        vector<string> s(b-a+1);
        int n = b-a+1;
        for(int i=a;i<=b;i++){
            string t;
            int nw = i;
            while(nw){
                t.push_back((char)('0'+nw%10));
                nw /= 10;
            }
            reverse(all(t));
            s[i-a] = t;
        }
        sort(all(s));
        vector<int> num(n);
        rep(i,n){
            dp[i] = 0, num[i] = stoi(s[i]);
        }
        BIT bt(n);
        rep(i,n){
            int res = bt.sum(num[i]-a);
            res = (res+1)%p;
            bt.add(num[i]-a,res);
        }
        cout << bt.sum(n-1) << "\n";
    }
}



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

const int N = 500009;
const int mod = 1000000007;

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define int long long int
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()

int n, t;
vector<pair<int, int>> v;
vector<int> dp;

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	cin >> n >> t;
	v.resize(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i].first >> v[i].second;
	}
	dp.assign(4000, 0);
	sort(all(v));
	reverse(all(v));
	// hard code
	for (int i = 1; i < (4000); i++)
	{
		dp[i] = v[0].second;
	}
	vector<int> prevDp;
	prevDp = dp;
	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j < v[i].first; j++)
		{
			dp[j] = max(prevDp[j], v[i].second);
		}
		for (int j = v[i].first; j < 4000; j++)
		{
			dp[j] = max(dp[j], prevDp[j - v[i].first] + v[i].second);
		}
		prevDp = dp;
	}
	cout << dp[t] << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(){
        double n;
        double a[10];
        double ans[50];
        double sum = 0;
        int i,j;
        int c = 0;
        for(j=0;j<50;j++)
                ans[j] = -1; 
    
        while(scanf("%lf", &n)!=-1){
                a[0] = n;
                for(i = 0; i < 10; i++){
                        if(i%2 == 0){ 
                                a[i+1] = a[i]*2;
                        }else if(i%2 ==1){
                                a[i+1] = a[i]/3;
                        }   
                        sum += a[i];
                }   
                ans[c] = sum;
                c++;
                printf("%f\n", sum);
                sum = 0;
        }   
        return (0);
}


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

template <class Abel> struct BIT {
    const Abel UNITY_SUM = 0;                       // to be set
    vector<Abel> dat;
    
    /* [1, n] */
    BIT(int n) : dat(n + 1, UNITY_SUM) { }
    void init(int n) { dat.assign(n + 1, UNITY_SUM); }
    
    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }
    
    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }
    
    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> S(N+1, 0);
    for (int i = 0; i < N; ++i) {
        long long a;
        cin >> a;
        S[i+1] = S[i] + (a - K);
    }
    vector<long long> SS = S;
    sort(SS.begin(), SS.end());
    SS.erase(unique(SS.begin(), SS.end()), SS.end());
    long long res = 0;
    BIT<long long> bit(N+10);
    for (int i = 0; i <= N; ++i) {
        int id = lower_bound(SS.begin(), SS.end(), S[i]) - SS.begin();
        res += bit.sum(id+1);
        bit.add(id+1, 1);
    }
    cout << res << endl;
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Schema;

class IDONTKNOWCSHARP
{

    public static void Main()
    {
        string  s=Console.ReadLine();

        if (s[s.Length - 1] == 's')
        {
            s+="es";
        }
        else
        {
            s+="s";
        }

        Console.WriteLine(s);

    }
}

Measured memory_bytes: 25804
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long x,y,ans,sum=0;
    cin>>x>>y;
    ans=((long long)(y/x));
    while(ans>=1)ans/=2,sum++;
    cout<<sum<<endl;
    while(0){
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util._

object Main extends App{
  override def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    val s = scanner.nextInt
    println(solve(s))

  }
  def solve(second : Int): String = {
    val h = second / 3600
    val m = (second / 60) % 60
    val s = second % 60
    
    format(h,m,s)
  }
  def format(h: Int, m :Int, s: Int): String = {
    "%d:%d:%d".format(h,m,s)
  }
}

Measured memory_bytes: 45040
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    string M = to_string(N);
    for (int i = 0; i < M.length(); i++) {
        if (M[i] == '7') {
            cout<< "Yes" <<endl;
            goto OUT;
        }
    }
    cout<< "No" <<endl;
    OUT:;
}


Measured memory_bytes: 3688
N = int(input())
A = list(map(int,input().split()))

mae_max = []
max_tall = 0
for i in range(N):
    max_tall = max(max_tall, A[i])
    mae_max.append(max_tall)

ans = 0
for i in range(N):
    ans += max(mae_max[i]-A[i], 0)

print(ans)

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

int main(){
  int a,b,c; cin>>a>>b>>c;
  int ans=0;
  if(a%2==1 || b%2==1 || c%2==1){
    cout<<0<<endl;
    return 0;
  }
  if(a==b && b==c){
    cout<<-1<<endl;
    return 0;
  }
  int ab=abs(a-b),bc=abs(b-c),ca=abs(c-a);
  while(ab%2!=1 && bc%2!=1 && ca%2!=1){
    ab/=2; bc/=2; ca/=2;
    ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
def Roll(c, lst) :
    if c == 'N' :
        lst[0], lst[1], lst[5], lst[4] = lst[1], lst[5], lst[4], lst[0]
    elif c == 'S' :
        lst[0], lst[1], lst[5], lst[4] = lst[4], lst[0], lst[1], lst[5]
    elif c == 'E' :
        lst[0], lst[2], lst[5], lst[3] = lst[3], lst[0], lst[2], lst[5]
    elif c == 'W' :
        lst[0], lst[2], lst[5], lst[3] = lst[2], lst[5], lst[3], lst[0]
    return lst
    

dice = list(map(int, input().split()))

direction = list(input())
for i in range(len(direction)) :
    D = direction.pop(0)
    Roll(D, dice)


print(dice[0])


Measured memory_bytes: 5608
#pragma warning disable
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
using System.Collections;
using static System.Math;
using static System.Console;

class E { static void Main() => new J(); }
class J
{
	const int Mod = 1000000007;
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	public J()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var d = new Dictionary<int, int> { [2] = -1, [4] = 1, [6] = 1, [9] = 1, [11] = 1 };
		for (var i = 0; i < 100; i++) if (!d.ContainsKey(i)) d[i] = 0;
		var I = G();
		Console.WriteLine(d[I[0]] == d[I[1]] ? "Yes" : "No");
	}
	long GCD(long a, long b)
	{
		var n = (ulong)Abs(a); var m = (ulong)Abs(b);
		if (n == 0) return (long)m; if (m == 0) return (long)n;
		int zm = 0, zn = 0;
		while ((n & 1) == 0) { n >>= 1; zn++; }
		while ((m & 1) == 0) { m >>= 1; zm++; }
		while (m != n)
		{
			if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; }
			else { n -= m; while ((n & 1) == 0) n >>= 1; }
		}
		return (long)n << Min(zm, zn);
	}
}

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int h[n];
  int ans = 0;
  int max = 0;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    if (max <= h[i]) {
      ans++;
      max = h[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import math, fractions


def num_prime_factor(n):
    
    ret = 0
    
    for i in range(1, 3):

        composite = False

        if n % i == 0:
            ret += 1
            n = n / i

            if i != 1:
                while n % i == 0:
                    n = n / i

            if n == 1:
                break

            for j in range(2, int(math.sqrt(n)) + 2):
                if n % j == 0:
                    composite = True
                    break

            if not composite:
                ret += 1
                break
    
    for i in range(3, int(math.sqrt(n)) + 2, 2):
        
        composite = False

        if n % i == 0:
            ret += 1
            n = n / i

            if i != 1:
                while n % i == 0:
                    n = n / i

            if n == 1:
                break

            for j in range(2, int(math.sqrt(n)) + 2):
                if n % j == 0:
                    composite = True
                    break

            if not composite:
                ret += 1
                break
                
    return ret

if __name__ == "__main__":
    A, B = map(int, input().split())
    n = fractions.gcd(A, B)
    if n == 1:
        print(1)
    else:
        print(num_prime_factor(n))

Measured memory_bytes: 64236
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1; i>=0; i--)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n;
  while(cin >> n && n) {
    int a[n];
    rep(i,n) cin >> a[i];
    int sum=32,k=0;
    bool t=false;  
    while(sum!=0) {
      if(!t) sum-=min(sum,(sum-1)%5);
      else sum-=min(sum,a[(k++)%n]);
      pr(sum);
      t=!t;
    }
  }
  return 0;
}


Measured memory_bytes: 1160
//Graph
#include <iostream>

using namespace std;

int main() {
    int n, u, k, v;
    cin >> n;
    int M[n+1][n+1];
    for(int i=0; i<n+1; i++)
        for(int j=0; j<n+1; j++)
            M[i][j] = 0;

    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        for(int j = 0; j < k; j++) {
            cin >> v;
            M[u][v] = 1;
        }
    }
    for(int i=1; i<n+1; i++) {
        for(int j=1; j<n; j++)
            cout << M[i][j] << " ";
        cout << M[i][n] << endl;
    }
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=1e5+10;
priority_queue<int>que;
vector<int>vt[maxn];
int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        int a,b;
        cin>>a>>b;
        vt[a].push_back(b);
    }
    ll sum=0;
    for(int i=1;i<=m;i++){
        for(auto it:vt[i])que.push(it);
        if(!que.empty()){
            sum+=que.top();
            que.pop();
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

int main()
{
    cin >> N;
    int j = N-1;
    vector<char> arr(N);
    for (int i = 0; i < N; i++) cin >> arr.at(i);

    for (int i = 0; i < N; i++)
    {
        if(arr[i]=='W')
        {
            for (; j >= 0; j--)
            {

                    if(i>=j)
                    {
                        cout << C;
                        return 0;
                    }
                if(arr[j] == 'R')
                {
                    arr[i] = 'R';
                    arr[j] = 'W';
                    C++;
                    break;
                }
            }
        }
        // if(i>=j)
        // {
        //     cout << C;
        //     return 0;
        // }
    }
    cout << 0;
    
    return 0;
}

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

using namespace std;

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

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

#endif

const int MAX = 3010000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll f(ll r, ll c) {
    ll res = COM(r + c + 2, r + 1) % MOD;
    res--;
    return res;
}

void Main() {
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    COMinit();
    ll ans = f(r2, c2);
    ans -= f(r2, c1 - 1);
    if (ans < 0) ans += MOD;
    ans -= f(r1 - 1, c2);
    if (ans < 0) ans += MOD;
    ans += f(r1 - 1, c1 - 1);
    ans %= MOD;
    cout << ans << '\n';
}

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


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,a,b;
    while(cin>>n>>a>>b){
        ll rslt=n/(a+b)*a;
        ll r=n%(a+b);
        cout<<rslt+min(r,a)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N;
vector<int> g[11234];
int cnt[11234], c[11234];
int ans[11234];

int main() {
	cin >> N;
	REP(i, N - 1) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
		cnt[a]++; cnt[b]++;
	}
	REP(i, N) scanf("%d", c + i);
	vector<pii> v;
	REP(i, N) v.push_back(pii(c[i], i));
	sort(ALL(v));
	
	memset(ans, -1, sizeof(ans));
	queue<int> que;
	REP(i, N) if (cnt[i] == 1) que.push(i);
	
	int pos = 0;
	while (!que.empty()) {
		int u = que.front(); que.pop();
		
		ans[u] = v[pos++].se;
		cnt[u]--;
		for (int v : g[u]) {
			if (--cnt[v] == 1) que.push(v);
		}
	}
	
	cout << accumulate(c, c + N, 0) - *max_element(c, c + N) << endl;
	REP(i, N) printf("%d%c", c[ans[i]], i == N - 1 ? '\n' : ' ');
	
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
 
#define all(v) v.begin(),v.end()
#define test() int t;cin>>t;while(t--) 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
const int mod = (int)1e9 + 7;

int main()
{
    int x;
    cin>>x;
    if(x)
        cout<<0<<endl;
    else 
        cout<<1<<endl;
}


Measured memory_bytes: 3592
from collections import deque

h,w=map(int,input().split())
w_sum=0
maze=[]
inf=10000000
for _ in range(h):
  s=list(input())
  for i in range(w):
    if s[i]=='.':
      s[i]=inf
      w_sum+=1
  maze.append(s)
  
def solve(maze,h,w):
  qu=deque([[0,0]])
  maze[0][0]=0
  while qu:
    y,x=qu.popleft()
    t=maze[y][x]
    for i in ([1,0],[-1,0],[0,1],[0,-1]):
      ny=y+i[0]
      nx=x+i[1]
      if 0<=ny<=h-1 and 0<=nx<=w-1 and maze[ny][nx]!='#':
        if maze[ny][nx]>t+1:
          maze[ny][nx]=t+1
          qu.append([ny,nx])
          
  return maze[h-1][w-1]
  
if solve(maze,h,w)==inf:
  print(-1)
else:
  print(w_sum-solve(maze,h,w)-1)

Measured memory_bytes: 9412
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // 標準入力を受け取る
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        
        // N以上である最小の111の倍数を探す
        for (int i = 1; i <= 9; i++) {
            if (N <= 111 * i) {
                // N以上である最小の111の倍数を標準出力
                System.out.println(111 * i);
                break; // これ以上探す必要がない
            }
        }

    }

}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int n;
ll l,t;
ll x[100005],w[100005];
ll res[100005];

int main(void){
	scanf("%d%lld%lld",&n,&l,&t);
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&x[i],&w[i]);
	}
	ll cnt=0;
	for(int i=0;i<n;i++){
		if(w[i]==1){
			res[i]=(x[i]+t)%l;
			cnt+=(x[i]+t)/l;
		}else{
			res[i]=((x[i]-t)%l+l)%l;
			cnt-=(t-x[i]+l-1LL)/l;
		}
		cnt%=(ll)n;
	}
	sort(res,res+n);
	int v=0;
	for(int i=0;i<n;i++){
		printf("%lld\n",res[(i+cnt+n)%n]);
	}
	return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

void solve() {
    int n, k; scanf("%d%d", &n, &k);
    long long ans = 0;
    for (int b = 1; b <= n; ++b) {
        ans += (n/b)*max(0, b-k) + max(0, n%b - k + 1);
        ans -= (0%b>=k);
    }
    printf("%lld", ans);
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int i;
    int brpkali;
    long long hasil=1;
    unsigned long long Data = 1000000000000000000u;
    scanf("%d", &brpkali);
    long long arr[1000000]={};
    for(i=0;i<brpkali;i++)
    {
        scanf("%lld", &arr[i]);
    }
    for(i=0;i<brpkali;i++)
    {
    
        if (arr[i]==0){
            printf("0\n");
            return 0;
        }
    }
    for(i=0;i<brpkali;i++)
    {
        if (arr[i]<=(Data/hasil))
        {   
            hasil*=arr[i];
            
        }
        else
        {
            printf("-1\n");
            return 0;
        }  
    }
    printf("%lld\n", hasil);

    return 0;
}

Measured memory_bytes: 9516
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define sd(t)       scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii         cout << "hii" << endl
#define okay        cout << "okay" << endl
#define hey         cout << "hey" << endl
const int INF = 1e12;
const int MOD = 1e9+7;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.x << ' ' << v.y; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.x << "=>" << i.y << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
 
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("jjj.txt", "w", stdout);
    #endif
}

void solve(){


    int n;
    cin >> n;

    string s;
    cin >> s;

    int cnt1 = 0, cnt2 = 0, cnt3 = 0;;
    rep(i, 0, n){
        if(s[i]=='W') cnt1++;
        else cnt2++;
    }   

    for(int i=0; i<cnt2; i++){
        if(s[i]=='R') cnt3++;
    }

    int ans = min(cnt1, cnt2);

    ans = min(ans, cnt2 - cnt3);

    cout << ans << endl;

}         

int32_t main(){
    fast();
    int t = 1;
    // cin>> t;
    for(int i=1; i<=t; i++){
        // cout << "Case #" << i << ": ";
        solve();
    }
    starboy1299();
}

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

int main(){
    int W,h,x,y,r;
    cin >> W >> h >> x >> y >> r;
    if (x-r < 0 || x+r > W || y-r < 0 || y+r > h) cout << "No";
    else cout << "Yes";
    cout << endl;
}


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

template<typename T>
struct Dijkstra {
	struct Edge {
		const int from;
		const int to;
		const T cost;
		Edge(const int from, const int to, const T cost) :
			from(from),
			to(to),
			cost(cost)
			{}
	};
	const int V;
	vector<vector<Edge>> G;
	int start;
	const T INF = numeric_limits<T>::max();
	vector<T> dist;
	vector<int> rec;
	Dijkstra(const int V) :
		V(V),
		G(vector<vector<Edge>>(V, vector<Edge>()))
		{}
	void addEdge(const int from, const int to, const T cost) {
		assert(cost >= 0);
		G[from].emplace_back(from, to, cost);
	}
	void build(const int start) {
		(*this).start = start;
		dist = vector<T>(V, INF);
		rec = vector<int>(V, -1);
		priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> que;
		dist[start] = 0;
		que.push({0, start});
		while(que.size()) {
			T cost;
			int from;
			tie(cost, from) = que.top();
			que.pop();
			for(Edge e : G[from]) {
				if(dist[e.from] + e.cost < dist[e.to]) {
					dist[e.to] = dist[e.from] + e.cost;
					rec[e.to] = e.from;
					que.push({dist[e.to], e.to});
				}
			}
		}
	}
	T distance(const int to) {
		if(dist[to] == INF) throw "INVALID";
		return dist[to];
	}
	vector<int> route(int to) {
		distance(to);
		vector<int> ret;
		while(to != start) {
			ret.push_back(to);
			to = rec[to];
		}
		ret.push_back(start);
		reverse(ret.begin(), ret.end());
		return ret;
	}
};

int main() {
	int n, m; cin >> n >> m;
	int s, t; cin >> s >> t;
	--s, --t;
	Dijkstra<int64_t> dijk(n);
	Dijkstra<int64_t> stra(n);
	while(m--) {
		int u, v; cin >> u >> v;
		--u, --v;
		int a, b; cin >> a >> b;
		dijk.addEdge(u, v, a);
		dijk.addEdge(v, u, a);
		stra.addEdge(u, v, b);
		stra.addEdge(v, u, b);
	}
	dijk.build(s);
	stra.build(t);
	vector<int64_t> ans(n);
	ans[n - 1] = dijk.distance(n - 1) + stra.distance(n - 1);
	for(int i = n - 2; i >= 0; --i) {
		ans[i] = min(ans[i + 1], dijk.distance(i) + stra.distance(i));
	}
	const int64_t INF = 1e15;
	for(int64_t i : ans) {
		cout << INF - i << '\n';
	}
	return 0;
}

Measured memory_bytes: 19780
/**
 *    author:  [itmo] enot.1.10
 *    created: 23.10.2016 15:06:48       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int mod = 1e9 + 7;
const int N = 1e5 + 10;

int l[N];
int r[N];

int a[N];
int b[N];


int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    int n;
    scanf("%d", &n);
    forn(i, n) scanf("%d", a + i);
    forn(i, n) scanf("%d", b + i);
    forn(i, n) r[i] = inf;

    forn(i, n) l[i] = 1;
    l[0] = r[0] = a[0];
    for (int i = 1; i < n; ++i)
    {
        r[i] = min(r[i], a[i]);
        if (a[i] != a[i - 1])
        {
            l[i] = max(l[i], a[i]);
        }
    }

    l[n - 1] = max(l[n - 1], b[n - 1]);
    r[n - 1] = min(r[n - 1], b[n - 1]);
    for (int i = n - 2; i >= 0; --i)
    {
        r[i] = min(r[i], b[i]);
        if (b[i] != b[i + 1]) l[i] = max(l[i], b[i]);
    }

    int res = 1;
    forn(i, n)
    {
        eprintf("%d %d\n", l[i], r[i]);
        if (l[i] > r[i]) res = 0;
        else res = (res * (ll)(r[i] - l[i] + 1)) % mod;
    }
    printf("%d\n", res);

    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


Measured memory_bytes: 1792
object Main extends App {
	import scala.math._

	val NZW = scala.io.StdIn.readLine.split(" ").map(_.toLong)
	val A = scala.io.StdIn.readLine.split(" ").map(_.toLong)

	val N = NZW(0).toInt

	if(N == 1){
		println((A(N-1)-NZW(2)).abs)
	}else{
		val a = (NZW(2) - A(N-1)).abs
		val b = (A(N-1) - A(N-2)).abs

		println(max(a,b))

	}
	

}

Measured memory_bytes: 27372
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val m = cin.nextInt()

    val go = Array<MutableList<Int>>(n, { mutableListOf() })
    val d = Array<Array<Int>>(n, { Array<Int>(3, { -1 }) })

    for (i in 0..m-1) {
        val u = cin.nextInt() - 1
        val v = cin.nextInt() - 1
        go[u].add(v)
    }

    val s = cin.nextInt() - 1
    val t = cin.nextInt() - 1

    val queue: MutableList<Int> = mutableListOf(s)
    d[s][0] = 0

    var ans = -1

    while (queue.size != 0 && ans == -1) {
        val now = queue.removeAt(0)
        for (next in go[now]) {
            var will_add = false
            for (i in 0..2) {
                if (d[now][i] == -1) {
                    continue
                }
                val distance = d[now][i] + 1
                if (d[next][distance % 3] != -1) {
                    continue
                }
                if (next == t && distance % 3 == 0) {
                    ans = distance/3
                    break
                }
                d[next][distance % 3] = distance
                will_add = true
            }
            if (will_add) {
                queue.add(next)
            }
        }
    }
    println(ans)
}

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

void solve()
{
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    long long int ans = a[n - 1];
    int k = n - 1;
    for (int i = n - 3; i >= 0; i--)
    {
        if ((n - 3 - i) % 2 == 0)
            k--;
        ans += a[k];
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 4416
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll N;

int main() {
    fastio();
    cin >> N;
    vector<pair<ll, int>> A(N);
    REP(i, N) {
        cin >> A[i].first;
        A[i].second = i & 1;
    }
    sort(ALL(A));
    ll ans = 0;
    for(int i = 0; i < N; i += 2) if(A[i].second == 1) ans++;
    cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);
const ll MAX_N = 3000010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i*fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll k;
    string s;
    cin >> k >> s;
    ll n = s.size();

    init();

    ll ans = 0;
    exrep(i, n, n+k) {
        ll x = (modpow(25, i-n) * modpow(26, n+k-i))%mod;
        ans += (x * Comb(i-1, n-1))%mod;
        ans %= mod;
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 74692
#include <stdio.h>

int count(int n) {
	int cnt;

	cnt = 0;
	while (n % 100 == 0) {
		n /= 100;
		cnt++;
	}
	return cnt;
}

int main() {
	int d, n, a, b;

	scanf("%d%d", &d, &n);
	a = b = 0;
	while (a < n) {
		b++;
		if (count(b) == d)
			a++;
	}
	printf("%d\n", b);
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    if (n >= 195) {
        cout << 5;
    }
    else if (n >= 189) {
        cout << 4;
    }
    else if (n >= 165) {
        cout << 3;
    }
    else if (n >= 135) {
        cout << 2;
    }
    else if (n >= 105) {
        cout << 1;
    }
    else {
        cout << 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,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; }
//ミョ(-ω- ?)
int main() {
    ll n,q;
    cin >> n;
    unordered_set<ll> s;
    rep(i,n){
        ll a;
        cin >> a;
        s.insert(a);
    }
    cin >> q;
    ll res = 0;
    rep(i,q){
        ll a;
        cin >> a;
        if(s.find(a) != s.end())res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	auto judge = [&](string a) {
		string b = a;
		reverse(b.begin(), b.end());
		return b == a;
	};
	if (!judge(s)) {
		cout << "No" << endl;
		return 0;
	}
	int n = s.size();
	if (!judge(s.substr(0, (n - 1) / 2))) {
		cout << "No" << endl;
		return 0;
	}
	if (!judge(s.substr((n + 3) / 2 - 1))) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3652
log = console.log;

var stdin = require("fs").readFileSync("/dev/stdin", "UTF-8");
var lines = stdin.split("\n");
var N = lines[0].split(" ").map(Number)[0];
var M = lines[0].split(" ").map(Number)[1];
var A = lines
  .slice(1)
  .filter(v => v !== "")
  .map(v => v.split(" ").map(Number));

var nLists = [];

for (var i = 0; i < M; i++) {
  nLists[i] = [];
  A.forEach((nm, A_i) => {
    if (A_i === i) return;
    var n = nm[0];
    var m = nm[1];
    if (nLists[i][m] === undefined) {
      nLists[i][m] = [n];
    } else {
      nLists[i][m].push(n);
    }
    if (nLists[i][n] === undefined) {
      nLists[i][n] = [m];
    } else {
      nLists[i][n].push(m);
    }
  });
}

function dfs(list, start, visited) {
  visited[start] = 1;
  list[start].forEach(point => {
    if (!visited[point]) dfs(list, point, visited);
  });
}

count = 0;
nLists.forEach(list => {
  var visited = [0];
  var firstPoint = list.findIndex(v=> v !== undefined)
  dfs(list, firstPoint, visited);
  if (visited.reduce((a,b)=>a+b) !== N) count += 1;
});

log(count);


Measured memory_bytes: 8264