akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n, x, t; cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3644
nums = input().split()
W = int(nums[0])
H = int(nums[1])
X = int(nums[2])
Y = int(nums[3])
R = int(nums[4])
if (X - R) >= 0 and (X + R) <= W:
    if (Y - R) >= 0 and (Y+ R) <= H:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 6728
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

signed main()
{
  cin.tie(nullptr), ios::sync_with_stdio(false);

  int n; cin >> n;
  cout << n * (n+1) / 2 << endl;

  return 0;
}



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

int main() {
    string s;
    cin >> s;
    string operators[s.size() - 1];

    bool isFinished = false;

    for(int bit = 0; bit < (1 << (s.size() - 1)); bit++){
        long tmp = s.at(0) - '0';
        for(int i = 0; i < s.size() - 1; i++){
            if(bit & (1 << i)){
                tmp -= s.at(i + 1) - '0';
                operators[i] = "-";
            } else {
                tmp += s.at(i + 1) - '0';
                operators[i] = "+";
            }
            
        }
        if(tmp == 7){
            isFinished = true;
            break;
        }
        if (isFinished == true){
            break;
        }
    }
    cout << s.at(0) << operators[0] << s.at(1) << operators[1] << s.at(2) << operators[2] << s.at(3) << "=7" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            if (x == 3 || x == 5 || x == 7)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


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

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  int cnt;
  double ans,ki;
  ki = 0;
for(int i = 1; i < n + 1; i++){
  ans = 1.0/n;

  cnt = i;  
  while(cnt < k){
    cnt *= 2;
    ans = ans * 0.5;

  }
  ki += ans;
}

cout << fixed << setprecision(10) << ki << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mset(x, y) memset((x), (y), sizeof(x))
#define sz(x) ((ll)(x).size())
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'
using namespace std;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

const ll mxn = 5100;
ll ans = LLONG_MIN, n, k;
ll p[mxn], c[mxn];

void startat(ll ind)
{
	vl dp;
	//mset(dp, 0);
	ll val = 0, pre = 0, moves = 0, x, i = ind;
	while(p[i] != ind && moves < k)
	{
		val = c[p[i]];
		i = p[i];
		pre += val;
		dp.eb(val);
		ans = max(ans, pre);
		moves++;
	}
	if(moves < k && p[i] == ind)
	{
		val = c[p[i]];
		i = p[i];
		pre += val;
		dp.eb(val);
		ans = max(ans, pre);
		moves++;
	}
	//assert(sz(dp) <= n);
	//pr(dp, moves);
	if(moves == k)
		assert(sz(dp) == k);
	if(pre <= 0 || moves == k)
		return;

	else if(sz(dp) < k)
	{
		x = k / sz(dp);
		if(k % sz(dp) == 0)
		{
			pre *= (x - 1LL);
			ans = max(ans, pre);
			for(i = 0; i < sz(dp); i++)
			{
				pre += dp[i];
				ans = max(ans, pre);
			}
			return;
		}
		pre *= x;
		ans = max(ans, pre);
		moves = k % sz(dp);
		for(i = 0; i < moves; i++)
		{
			pre += dp[i];
			ans = max(ans, pre);
		}
	}
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	ll i;
	cin >> n >> k;
	rep(i, 1, n + 1) cin >> p[i];
	rep(i, 1, n + 1) cin >> c[i];

	rep(i, 1, n + 1)
	{
		//pr(i);
		startat(i);
	}
	cout << ans;
}

Measured memory_bytes: 3816
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]){
    int n, l;
    cin >> n >> l;
    int mn = l, mx = l + n -1;
    int sum = (mn+mx)*(n)/2;
    if ((mn*mx)<0){
        cout << sum << endl;
        return 0;
    }
    if (abs(mn)<=abs(mx)){
        cout << sum-mn << endl;
        return 0;
    }else{
        cout << sum-mx << endl;
        return 0;
    }
}

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

string s[4] = { "Sunny", "Cloudy", "Rainy", "Sunny" };
int main() {
  string t;
  cin >> t;
  for (int i = 0; i < 3; ++i) {
    if (t == s[i]) {
      cout << s[i + 1] << endl;
    }
  }
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <bitset>
#define PII pair<int,int>
#define MP make_pair
#define fir first
#define sec second
#define PB push_back
#define db long double
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2010;
char str[N];
int n;
bitset<2010> fl[N],fr[N],A[N];
int main() {
	rd(n);
	for(int i=2;i<=n;++i) {
		scanf("%s",str+1);
		for(int j=1;j<i;++j) {
			A[i][j]=str[j]-'0';
			A[j][i]=(str[j]-'0')^1;
		}
	}
	for(int i=1;i<=n;++i) fl[i][i]=fr[i][i]=1;
	for(int l=2;l<=n;l++)
		for(int i=1;i+l-1<=n;++i) {
			int j=i+l-1;
			fl[j][i]=(fr[i+1]&fl[j]&A[i]).count()!=0;
			fr[i][j]=(fl[j-1]&fr[i]&A[j]).count()!=0;
		}
	int ans=0;
	for(int i=1;i<=n;++i)
		ans+=fr[1][i]!=0&&fl[n][i]!=0;
	printf("%d\n",ans);
	return 0;
}
		

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
	int VLineNum, HLineNum;
	cin >> VLineNum;
	cin >> HLineNum;

	int* Data = new int[VLineNum];//あみだくじNo.配列初期化
	for (int i = 0; i < VLineNum; ++i){
		Data[i] = i + 1;
	}

	int a, b, temp;//データロード&あみだくじ数値反転
	for (int i = 0; i < HLineNum; ++i){
		scanf("%d,%d", &a, &b);
		temp = Data[b-1];
		Data[b-1] = Data[a-1];
		Data[a-1] = temp;
	}

	for (int i = 0; i < VLineNum; ++i){//出力
		cout << Data[i] << endl;
	}

	delete [] Data;

	return 0;
}

Measured memory_bytes: 1240
#include<stdio.h>
int main(){
	int a,b,c,d,n,aa,bb,cc,dd,i,x;
	scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
	for(i=1;;i++){
		aa=a*i;
		if(n<=aa){
		bb=b*i;
		break;
		}
	}
	for(i=1;;i++){
		cc=c*i;
		if(n<=cc){
		dd=d*i;
		break;
		}
	}
	if(bb<dd)
	x=bb;
	else
	x=dd;
	printf("%d\n",x);
	return 0;
}


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

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple

// #define N 311111
#define A 1111111
#define BLOCK 555 // ~sqrt(N)

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

const int INF = 1e9 +5;
const int nax = 100005;
const long M = 1000000007;

ll dp[nax];
// int in_degree[nax];
// vector<int> edges[nax];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	// cout<<fixed;
	// cout<<setprecision(10);
	int t;
	// cin>>t;
	t = 1;
	while(t--){
		int n,k;
		cin>>n>>k;
		int arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		dp[0] = 1;
		for(int child =0;child<n;child++){
			int up_to = arr[child];
			vector<int> vec(k+1);
			for(int used = k;used>=0; used--){
				int tmp = dp[used];
				int L = used + 1;
				int R = used + min(up_to, k-used);
				if(L<=R){
					vec[L] += tmp;
					vec[L]%= M;
					if(R+1 <=k){
						vec[R+1] -= tmp;						
						vec[R]%=M;
					}
				}
				// for(int here= 1; here <= min(up_to,k-used); here++){
					// dp[here + used] += dp[used];
					// cout<<"child : "<<child<<" used : "<<used<<" here : "<<here <<endl;
					// for (int l = 0;l<=k; l++){
					// 	cout<<dp[l]<<" ";
					// }
					// cout<<endl;
				
			}
			// for(int i=0;i<=k;i++){
			// 	cout<<vec[i]<<" ";
			// }
			// cout<<endl;
			// cout<<"-------------------"<<endl;
			ll prefixSum =0;
			for(int i=0;i<=k;i++){
				prefixSum += vec[i];
				dp[i] += prefixSum;
				dp[i]%=M;
			}
			// for(int i=0;i<=k;i++){
			// 	cout<<dp[i]<<" ";
			// }
			// cout<<endl;
		}
		cout<<dp[k]<<endl;
		// if(dp[k]==1){
		// 	cout<<"First"<<endl;
		// }
		// else{
		// 	cout<<"Second"<<endl;
		// }
	}
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define nn 22

int n,m;
char _map[nn][nn];
int dp[nn][nn][nn][nn];


int dfs(int x1,int y1,int x2,int y2){
	if(x1>x2 or y1>y2) return 0;
	if(dp[x1][y1][x2][y2]>-1) return dp[x1][y1][x2][y2];
	set<int> all;
	for(int i=x1;i<=x2;i++) {
		for(int j=y1;j<=y2;j++) if(_map[i][j]=='.'){
			int w=dfs(x1,y1,i-1,j-1)^dfs(x1,j+1,i-1,y2)^dfs(i+1,y1,x2,j-1)^dfs(i+1,j+1,x2,y2);
			all.insert(w);
		}
	}
	int res=0;
	while(all.count(res))res++;

	return dp[x1][y1][x2][y2]=res;
}

int main(){
	memset(dp,-1,sizeof dp);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",_map[i]+1);
	
	if(dfs(1,1,n,m)) puts("First");else puts("Second");	
	return 0;
} 


Measured memory_bytes: 4088
h, w = gets.split.map(&:to_i)

queue = []
dmap = Array.new(h) { Array.new(w) }

h.times do |i|
  gets.chomp!.each_char.with_index do |c, j|
    if c == '#'
      queue << [i,j]
      dmap[i][j] = 0
    end
  end
end

ans = nil
until queue.empty?
  i, j = queue.shift
  ans = dmap[i][j]

  if i + 1 < h && dmap[i + 1][j].nil?
    dmap[i+1][j] = ans + 1
    queue << [i+1, j]
  end

  if i - 1 >= 0 && dmap[i-1][j].nil?
    dmap[i-1][j] = ans + 1
    queue << [i-1, j]
  end

  if j + 1 < w && dmap[i][j+1].nil?
    dmap[i][j+1] = ans + 1
    queue << [i, j+1]
  end

  if j-1 >= 0 && dmap[i][j-1].nil?
    dmap[i][j-1] = ans + 1
    queue << [i, j-1]
  end
end
puts ans


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

//#include "atcoder/all"
//using namespace atcoder;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	if(a+b >= c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    int D; cin >> D;
    vl c(26);
    rep(i,26) cin >> c[i];
    vvl s(D, vl(26));
    rep(i,D) {
        rep(j,26) {
            cin >> s[i][j];
        }
    }
    rep(i,D) {
        cout << (i%26)+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin>>s;
    int c1=0,c0=0;
    for(int i=0;i<s.size();i++)if(s[i]=='1')c1++;else c0++;
    cout<<min(c1,c0)*2;
    return 0;
}

Measured memory_bytes: 512
#!/usr/bin python3
# -*- coding: utf-8 -*-

# ワーシャルフロイド法
# 全頂点間最短路
# d[i][j]は2頂点間i, j間の移動コストを格納, Mは頂点数

INF = float("inf")
import copy

def warshall_floyd(d):
    n = len(d)
    wf = copy.deepcopy(d)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])

    return wf #wf[i][j]に頂点i, j間の最短距離を格納

##############################

n = int(input())
d = [list(map(int,input().split())) for _ in range(n)]

if d != warshall_floyd(d):
    print(-1)
else:
    ret = 0
    for i in range(n):
        for j in range(i+1,n):
            if i == j: continue
            ret += d[i][j]
            for mid in range(n):
                if mid in (i, j): continue
                if d[i][mid] + d[mid][j] == d[i][j]:
                    ret -= d[i][j]
                    break
    print(ret)

Measured memory_bytes: 77088
#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(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i, n){
        cin >> a.at(i);
        b.at(i) = a.at(i);
    }
    sort(b.begin(), b.end());
    if(b.at(n/2-1) == b.at(n/2)){
        rep(i, n) cout << b.at(n/2) << endl;
    }else{
        rep(i, n){
            if(a.at(i) >= b.at(n/2)){
                cout << b.at(n/2-1) << endl;
            }else{
                cout << b.at(n/2) << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Forr(i,m,n) for(int i=m;i>n;i--)
#define Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define INF 999999999999

int main(){
  int N,max=0,mx_cnt=0,nxt_max=0; cin>>N;
  vll A(N);
  rep(i,N){
    cin>>A[i];
    if(max<A[i]) max=A[i];
  }

  rep(i,N){
    if(max==A[i]) mx_cnt++;
    else if(max>A[i]){
      if(nxt_max<A[i]) nxt_max=A[i];
    }
  }

  rep(i,N){
    if(A[i]!=max){
      cout<<max<<endl;
    }else if(mx_cnt!=1){
      cout<<max<<endl;
    }else cout<<nxt_max<<endl;
  }

return 0;
}


Measured memory_bytes: 3200
n = int(input())
h = list(map(int,input().split()))
max_height = max(h)
ans = 0

for i in range(1,max_height+1):
    switch = 0
    for j in range(n):
        if switch == 0:
            if h[j] >= i:
                switch = 1
                ans += 1
        if switch == 1:
            if h[j] < i:
                switch = 0

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std;
vector<int> a(51),b(51),c(51),d(51);
int n,m,q;
ll ans = 0;
void go(vector<int> &v){
	if(v.size()==n){
		ll res = 0;
		for(int i=0;i<q;i++){
			if(v[b[i]] - v[a[i]] == c[i]){
				res += d[i];
			}
		}
		ans = max(ans, res);
		return;
	}
	for(int j=(v.size() ? v.back() : 1); j<=m;j++){
		v.pb(j);
		go(v);
		v.pop_back();
	}
}
void solve(){
	cin >> n >> m >> q;
	for(int i=0;i<q;i++){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}
	vector<int> v;
	go(v);
	cout << ans << endl;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
    int t=1,l=1;
   	//cin >> t;
    while(t--){
    	solve();
    }    
}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

int main(){
    
    for(ll N, M;cin>>N>>M,N;){
        vector<ll>vec(M + 1, 0);
         for(ll i = 0; i < N; i++){
            ll d, v;
            cin >> d >> v;
            vec[d] = max(vec[d], v);
        }
        ll ans = 0;
        for(ll i = 1; i <= M; i++)ans += vec[i];
        cout << ans << endl;
    }
    
    return 0;    
}


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

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

fn main() {

    let s:i32 = read();
    let w:i32 = read();

    if w >= s {
        println!("unsafe");
    }else{
        println!("safe");
    }

}

Measured memory_bytes: 2072
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        int[] a = new int[n];
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        int[] time = new int[n];    //何回目に初めてその町に到達したかを示す 町番号は箱の番号+1
        time[0] = 0;
        int now = 0;
        for(int i=1;;i++){
            if(time[a[now] - 1] != 0){  //来たことがある場合
                int loop = i - time[a[now] - 1];
                k -= (k - i) / loop * loop;
                time = new int[n];
            }else {
                time[a[now] - 1] = i;
            }
            now = a[now] - 1;
            if(i == k){
                break;
            }
        }
        now++;
        System.out.println(now);
    }
}


Measured memory_bytes: 49760
#include<stdio.h>
int main()
{
	for(;;)
	{
		int p[101]={0,1,1},i,j,c=0;
		for(;;)
		{
			if(scanf("%d%d",&i,&j)<2) return 0;
			if(!i) break;
			p[i]++,p[j]++;
		}
		for(i=0;i<101;i++)
			if(p[i]&1) c++;
		printf("%s\n",c<1?"OK":"NG");
	}
	return 1;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final long N = sc.nextLong();
        final int X = sc.nextInt();
        final int M = sc.nextInt();
        
        if (X == 0) {
            System.out.println(0);
            return;
        }
        
        int A = X;
        
        // 数列の累積和を記録する。
        long[] sum = new long[M + 1];
        sum[0] = A;
        
        // その項が数列の何番目（0開始）に現れたかを記録する。
        int[] idx = new int[M + 1];
        idx[A] = 0;
        
        int i = 1;
        for (; i < N; i++) {
            long B = A;
            A = (int) (B * B % M);
            
            if (A == X || 0 < idx[A]) {
                break;
                
            } else {
                sum[i] = sum[i - 1] + A;
                idx[A] = i;
            }
        }
        
        if (i == N) {
            System.out.println(sum[i - 1]);
            return;
        }
        
        int idxRepeatStart = idx[A];
        
        int lenPrefix = idxRepeatStart;
        int lenRepeat = i - idxRepeatStart;
        long numRepeats = (N - lenPrefix) / lenRepeat;
        int lenSuffix = (int) (N - lenPrefix - lenRepeat * numRepeats);
        
        long sumPrefix = 0 < idxRepeatStart ? sum[idxRepeatStart - 1] : 0;
        long sumRepeat = sum[i - 1] - sumPrefix;
        long sumSuffix = 0 < lenSuffix ? sum[idxRepeatStart + lenSuffix - 1] - sumPrefix : 0;
        
        long answer = sumPrefix + sumRepeat * numRepeats + sumSuffix;
        System.out.println(answer);
    }
}


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

void str_rev(char* str,int n){
  char tmp;
  int i = 0;
  for(i=0;i<n/2;i++){
      tmp = str[i];
      str[i] = str[n-1-i];
      str[n-1-i] = tmp;
  }
}

int main(){
  int n;
  scanf("%d",&n);
  char ans[100]="";
  if(n==0){
    strcat(ans,"0");
  }
  while(n!=0){
    if(n%2!=0){
      strcat(ans,"1");
      n=n-1;
      n=n/2;
      n=(-1)*n;
    }else{
      strcat(ans,"0");
      n=n/2;
      n=(-1)*n;
    }
  }
  int l = strlen(ans);
  str_rev(ans,l);
  printf("%s\n",ans);
  return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int plan_b = sc.nextInt();
        
        int plan_a = a * b;
        
        if(plan_a <= plan_b) {
            System.out.println(plan_a);
        }
        else {
            System.out.println(plan_b);
        }
    }
}

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

using namespace std;

//#define FILE_IO

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    int x;
    cin >> x;
    cout << (x - 2) * 180;

    return 0;
}


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

int main() {
    string S,T;
    cin >> S >> T;
    
    int N = S.size();
    int count = 0;
    for ( int i = 0; i < N; ++i){
        if ( S[i] != T[i] ){
            ++count;
        }
    }
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D=0;
  cin >> A >> B >> C >> D;
  if(A+B > C+D){
    cout << "Left" << endl;
  }else if(A+B == C+D){
    cout << "Balanced" << endl;
  }else if(A+B < C+D){
    cout << "Right" << endl;
  }
  
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	long long x,y;
	int n;
	x=y=1;
	long long t,a;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>t>>a;
		long long tmp,p,q;
		p=x/t;
		q=y/a;
		if(x%t!=0) p++;
		if(y%a!=0) q++;
		tmp=max(p,q);
		if(tmp==0) tmp=1;
		x=t*tmp;
		y=a*tmp;
	}
	cout<<x+y<<endl;
	return 0;
}

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

int main(){
    int N;
    int temp;
    int flag=1;
    int d[101]={};
    int kagamimochi=0;

    cin >> N;
    for(int i=0;i<N;i++){
        flag=1;
        cin >> temp;
        for(int j=0;j<i;j++){
            if(temp==d[j]) flag=0;
        }
        d[i]=temp;
        if(flag==1) kagamimochi++;
    }
    cout << kagamimochi << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

ll mincd(ll a){
    ll ans = 0;
    for(ll i = 1; i * i <= a; ++i){
        if(a%i == 0) ans = max(ans, i);
    }
    return ans;
}

int main(){
    ll a, b; cin >> a >> b;
    vector<ll> ap, bp, cp;
    for(ll i = 1; i * i <= a; ++i){
        if(a%i == 0){
            ap.push_back(i);
            if(i*i != a) ap.push_back(a/i);
        }
    }
    for(ll i = 1; i * i <= b; ++i){
        if(b%i == 0){
            bp.push_back(i);
            if(i*i != b) bp.push_back(b/i);
        }
    }
    sort(ap.begin(), ap.end());
    sort(bp.begin(), bp.end());
    set_intersection(ap.begin(), ap.end(), bp.begin(), bp.end(), inserter(cp, cp.end()));
    ll cnt = 0, m = cp[cp.size()-1];
    vector<bool> cpb(cp.size(), true);
    for(ll i = 0; cp[i] * cp[i] <= m; ++i){
        if(cp[i] == 1) continue;
        if(cpb[i]){
            for(ll j = i+1; j < cp.size(); ++j){
                if(cp[j]%cp[i] == 0) cpb[j] = false;
            }
        }
    }
    for(auto i : cpb) if(i) cnt++;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
def sum_of_digits(x)
  x.to_s.split("").map {|s| s.to_i}.inject(:+)
end
n,a,b = gets.strip.split.map(&:to_i)
cnt = 0
for i in 1..n
  if a<=sum_of_digits(i) && sum_of_digits(i)<=b
    cnt += i
  end
end
puts cnt

Measured memory_bytes: 14304
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const long long mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main()
{
    ll w,h,x,y; cin >> w >> h >> x >> y;
    int ans = 0;
    if(w % 2 == 0 && h % 2 == 0){
        if(w / 2 == x && h / 2 == y){
            ans = 1;
        }
    }
    cout << (w / 2.0) * h << ' ' <<  ans ; 
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans;
int n,m;
int u,v;
vector<int> g[111111];
int d[111111],d2[111111];
void dfs(int i,int dist){
	if(d2[i]<=dist)d[i]=INF;
	else d[i]=dist;
	for(auto x:g[i]){
		if(d[x]==-1)dfs(x,dist+1);
	}
}
void dfs2(int i,int dist){
	d2[i]=dist;
	for(auto x:g[i]){
		if(d2[x]==-1)dfs2(x,dist+1);
	}
}
signed main(){
	
	cin>>n>>u>>v;
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	fill(d,d+n,-1);
	fill(d2,d2+n,-1);
	dfs2(v-1,0);
	dfs(u-1,0);
	
	rep(i,n){
		if(d[i]>=INF)continue;
		ans=max(d2[i]-1,ans);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,a[N];
ll sum[N],dp[N][3];
void setdp(int x,int y,ll v)
{
    if(y==x/2) dp[x][1]=max(dp[x][1],v);
    else if(y==x/2-1) dp[x][0]=max(dp[x][0],v);
    else if(y==x/2+1) dp[x][2]=max(dp[x][2],v);
}
ll getdp(int x,int y)
{
    if(y==x/2) return dp[x][1];
    else if(y==x/2-1) return dp[x][0];
    else if(y==x/2+1) return dp[x][2];
    return -inf;
}
int main()
{
    memset(dp,-inf,sizeof(dp));
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    ll ans=-inf;
    setdp(0,0,0);
    setdp(1,1,a[1]);
    setdp(1,0,0);
    for(int i=2;i<=n;i++)
        for(int j=i/2-1;j<=i/2+1;j++)
        setdp(i,j,getdp(i-2,j-1)+a[i]),setdp(i,j,getdp(i-1,j));
    printf("%lld\n",getdp(n,n/2));
}


Measured memory_bytes: 9292
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
const int MOD = (int)1e9 + 7;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<int> H(N);
  int ans = 1;

  REP(i, N) {
    cin >> H[i];

  }
  int highest=H[0];
  FOR(i,1,N){
    if(highest<=H[i]){
      ans++;
    }
    if(highest<H[i]){
      highest=H[i];
    }


  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

while True:

    line = list(input())

    if '-' in line:
        break

    m = int(input())
    for i in range(m):
        h = int(input())
        for j in range(h):
            line.append(line[0])
            line.pop(0)

    for i in range(len(line)):
        print(line[i],end='')
    print()


Measured memory_bytes: 5620
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=2e9;
const ll lnf=9e18;

map<int,int> mp;
int dp[20010]; //作れる最大桁数

int main(){
  rep(j,20010) dp[j]=-inf;
  mp[1]=2;
  mp[2]=5;
  mp[3]=5;
  mp[4]=4;
  mp[5]=5;
  mp[6]=6;
  mp[7]=3;
  mp[8]=7;
  mp[9]=6;
  itn n,m; cin >> n >> m;
  vector<int> a(m);
  rep(i,m) cin >> a[i];
  dp[0]=0;
  rep(i,m)rep(j,20010){
    if(j+mp[a[i]]<20010) chmax(dp[j+mp[a[i]]],dp[j]+1);
  }
  //cout << dp[n] << endl;
  rsort(a);
  string ans;
  while(n){
    rep(i,m){
      if(n-mp[a[i]]>=0&&dp[n-mp[a[i]]]==dp[n]-1){
        ans+=to_string(a[i]);
        n=n-mp[a[i]];
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3744
import java.util.Scanner;

public class Main{

	public static void main (String[] args) {

		Scanner sc = new Scanner (System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long num = gcd (A,B);
		boolean flag = true;

		long count = 0;

		for (int index=2; index<=Math.pow(num,0.5); index++) {
			if (num%index==0) {
				flag = true;
				count++;
			}
			while (flag) {
				if (num%index!=0) {
					flag = false;
				} else {
					num/=index;
				}
			}
		}

		if (num!=1) {
			count++;
		}

		System.out.println(count+1);

	}


	private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
}

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

using namespace std;

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

	for (int i = 1; i <= N; i++) {
		cin >> S;
		if (S == "Y") {
			cout << "Four" << endl;
			break;
		}
		if (i == N) {
			cout << "Three" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int bemiho,katoshi,kosakana;
  int kuboshi,miduki = 0;
  cin >> bemiho >> katoshi >> kosakana;
  vector<int> nibuchan(3*kosakana);
  for(int i = 0; i < 3*kosakana; i++) {
    cin >> nibuchan.at(i);
  }
  for(int i = 0; i < 3*kosakana; i += 3) {
    if(nibuchan.at(i + 2) == 1 && kuboshi <= nibuchan.at(i)) {
      kuboshi = nibuchan.at(i);
    }
    if(nibuchan.at(i + 2) == 2 && bemiho >= nibuchan.at(i)) {
      bemiho = nibuchan.at(i);
    }
    if(nibuchan.at(i + 2) == 3 && miduki <= nibuchan.at(i + 1)) {
      miduki = nibuchan.at(i + 1);
    }
    if(nibuchan.at(i + 2) == 4 && katoshi >= nibuchan.at(i + 1)) {
      katoshi = nibuchan.at(i + 1);
    }
  }
  int meina,yuna = 0;
  if(bemiho - kuboshi >= 0) {
    meina = bemiho - kuboshi;
  }
  else {
    meina = 0;
  }
  if(katoshi - miduki >= 0) {
    yuna = katoshi - miduki;
  }
  else {
    yuna = 0;
  }
  cout << meina*yuna << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FASTIO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll double
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define tr(it, a)   for(auto it=a.begin();it!=a.end();it++)
#define pb push_back
#define endl  "\n"
const int  MAX=3000+3;
//const int  mod=1e9+7;
int n;
vi v(MAX);
double dp[MAX][MAX];
ll fun(int i,int  k)
{
    if(i==n && k<=n/2)
        return 0;
    if(i==n && k>n/2)
        return 1;
       if(dp[i][k]>=0)
       return dp[i][k];
   ll a=v[i]*fun(i+1,k+1);
    ll b=(1-v[i])*fun(i+1,k);
    dp[i][k]=a+b;
    //cout<<a+b<<endl;;
    return a+b;
}
int main()
{
   FASTIO

    cin>>n;
    rep(i,0,n)
    cin>>v[i];
    memset(dp,-1,sizeof(dp));
    double ans=fun(0,0);
    cout << fixed << setprecision(12) << ans;
 return 0;
}


Measured memory_bytes: 70912
# 2019/05/30
# AtCoder Beginner Contest 058 - B

# Input
o = input()
e = input()
str = ""

for i in range(len(e)):
    str += o[i] + e[i]

if len(o) > len(e):
    str += o[len(o)-1]

# Output
print(str)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    if(n*a<b)cout<<n*a<<endl;
    else cout<<b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string S;
	cin >> S;
	if(S.at(0)==S.at(1)&&S.at(1)==S.at(2)){
		cout <<"No"<< endl;
	}
	else if(S.at(0)==S.at(1)&&S.at(2)==S.at(3)){
		cout <<"Yes"<< endl;
	}
	else if(S.at(0)==S.at(2)&&S.at(1)==S.at(3)){
		cout <<"Yes"<< endl;
	}
	else if(S.at(0)==S.at(3)&&S.at(2)==S.at(1)){
		cout <<"Yes"<< endl;
	}
	else {
		cout << "No" <<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        if (odd(N)) {
                cout << 0 << endl;
                return 0;
        }

        ll ans = 0;

        N /= 2;
        while (N > 0) {
                ans += N/5;
                N /= 5;
        }
        cout << ans << endl;
}


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

#define za ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod %1000000007
#define moz 1000000007
#define nl "\n"
#define S second
#define F first
#define PB push_back
#define MP make_pair
#define V vector
#define P pair
#define LEN length()
#define SZ size()
#define loop(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
typedef complex<ll> C;
#define X real()
#define Y imag()

int n,a,b,c;

int main()
{
    za;
    string s;
    cin >> s;
    if(s[0]==s[2]) cout << "Yes" << nl;
    else cout << "No" << nl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<climits>
#include<functional>

using namespace std;

int main() {
   int N, W;

   cin >> N >> W;
   int w[ N ], v[ N ];
   long long totalMax = 0;
   for( int i = 0; i < N; i++ ) {
      cin >> w[ i ] >> v[ i ];
      totalMax += v[ i ];
   }

   long long **dp = ( long long ** ) malloc( sizeof( long long * ) * N );
   for( int i = 0; i < N; i++ ) {
      dp[ i ] = ( long long * ) malloc( sizeof( long long ) * ( totalMax + 1 ) );
   }
   for( int i = 0; i < N; i++ ) {
      for( int j = 0; j < totalMax + 1; j++ ) {
         dp[ i ][ j ] = LONG_MAX;
      }
   }

   function< long long ( int, int ) > getDp;
   getDp = [ & ] ( int cn, int cv ) -> long long {
      if( cv <= 0 ) {
         return 0;
      }
      if( cn == 0 ) {
         if( cv <= v[ cn ] ) {
            return w[ cn ];
         }
         return LONG_MAX - 1;
      }
      if( dp[ cn ][ cv ] != LONG_MAX ) {
         return dp[ cn ][ cv ];
      }
      auto path1 = getDp( cn - 1, cv - v[ cn ] );
      path1 = path1 == LONG_MAX - 1 ? path1 : path1 + w[ cn ];
      dp[ cn ][ cv ] = min( path1, getDp( cn - 1, cv ) );

      return dp[ cn ][ cv ];
   };

   // Binary search with two ends
   function< int ( int, int ) > search;
   search = [ & ] ( int start, int end ) -> int {
      if( start == end ) {
         return start;
      }
      if( start + 1 == end ) {
         if( getDp( N - 1, end ) <= W ) {
            return end;
         } else {
            return start;
         }
      }
      auto mid = ( start + end ) / 2;
      auto mV = getDp( N - 1, mid );
      if( mV <= W ) {
         return search( mid, end );
      } else {
         return search( start, mid );
      }
   };

   cout << search( 0, totalMax );
   return 0;
}


Measured memory_bytes: 78720
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 105;

int n, a[MAXN], c[MAXN];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 1; i <= n; i ++)
		c[a[i] = Read()] ++;
	sort(a + 1, a + n + 1, greater <int> ());
	if (a[1] ^ a[2])
		return puts("Impossible"), 0;
	int mid = a[1] + 1 >> 1;
	for (int i = mid + 1; i <= a[1]; i ++)
		if (c[i] < 2)
			return puts("Impossible"), 0;
	if (c[mid] > (a[1] & 1) + 1)
		return puts("Impossible"), 0;
	if (a[n] < mid)
		return puts("Impossible"), 0;
	return puts("Possible"), 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main()
{
	int x;
	cin >> x;
	vector<int> v;
	if (x == 1) {
		cout << 1 << endl;
		return 0;
	}
	int mx = 0;
	for (int i = 2; i <= x; i++) {
		for (int j = 2; pow(i, j) <= x; j++) {
			if (mx < pow(i, j)) {
				mx = max(mx, (int)pow(i, j));
			}
		}
	}
	cout << mx << endl;
	return 0;
}

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

int main() {
	// your code goes here
	int i, j, k, ans=0;
	string s;
	cin>>s;
	cin>>k;
	int n=s.length();
	for(i=0; i<n; ++i) {
		if(!k)	break;
		if(s[i]=='a')	continue;
		int z=s[i]-'a';
		if(k>=26-z) {
			k=k-(26-z);
			s[i]='a';
		}
	}
	if(k) {
		k=k%26;
		for(i=0; i<k; ++i)	s[n-1]++;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    string o, e;
    cin >> o >> e;
    for(int i=0;i<e.size();i++){
        cout << o[i];
        cout << e[i];
    }
    if(o.size()>e.size()) cout << o.back() << endl;
    else cout << endl;
    return 0;
}

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

int n,k,ans;
vector<int> pos[2010];

inline int dfs(int x,int p,int d,int mx)
{
	int sum=1;
	if(d!=mx)
		for(int i:pos[x])
		{
			if(i==p) continue;
			sum+=dfs(i,x,d+1,mx);
		}
	return sum;
}

int main()
{
	cin>>n>>k;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		pos[a].push_back(b);
		pos[b].push_back(a);
	}
	
	if(k%2==0) for(int i=0;i<n;i++) ans=max(ans,dfs(i,-1,0,k/2));
	else
		for(int i=0;i<n;i++)
			for(int j:pos[i]) ans=max(ans,dfs(i,j,0,k/2)+dfs(j,i,0,k/2));
	
	cout<<n-ans;
	
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
int n,k,x[105];
int ans=0;
scanf("%d %d",&n,&k);
for(int i=0;i<n;i++){
    scanf("%d",&x[i]);
}

for(int i=0;i<n;i++){
    if(x[i]*2>=(k-x[i])*2){ans=ans+(k-x[i])*2;}
    else{ans=ans+x[i]*2;}
}

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

}


Measured memory_bytes: 128
import math

a,b,h,m=map(int,input().split())
m=h*60+m
aa=(0.5*m)%360
ba=(6*m)%360
ang=abs(aa-ba)
cos=math.cos(math.radians(ang))

ll=a*a+b*b-2*a*b*cos
ans=ll**0.5
print(ans)


Measured memory_bytes: 62496
program abc171
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n, ni, val
    character(20):: ans
    
    read*, n
    n=n-1
    ans = ''
    do while(.true.)
        if (n<0) exit
        ni = mod(n,26_8)
        ! if (ni==0) ni=26
        ! print'(*(i0,1x))', ni,n
        val = ni + ichar('a')
        ans = char(val) //trim(ans)
        n=n/26-1
    end do
    print'(a)', ans
end program abc171

Measured memory_bytes: 2924
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    int x,a,b,c,i,j,k,n=0;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    for(i=0;i<=a&&x>=500*i;i++){
        for(j=0;j<=b;j++){
            for(k=0;k<=c;k++){
                if(500*i+100*j+50*k==x)
                    n++;
            }
        }
    }
    printf("%d",n);
    return 0;
         }


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n, r;
  cin >> n >> r;
  if (n < 10) {
    r += 100 * (10 - n);
  }
  cout << r << nl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> A(n); rep(i, n) cin >> A[i];
  ll ans = 1000;
  rep(i, n-1) {
    if(A[i] < A[i+1]) {
      ll tmp = ans / A[i];
      ans += tmp * (A[i+1] - A[i]);
    }
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 3664
L = [int(i) for i in input()]
A = L[0]
B = L[1]
C = L[2]
D = L[3]
x="-"
y="-"
z="-"
if A+B+C+D==7:
    x="+"
    y="+"
    z="+"
elif A+B+C-D==7:
    x="+"
    y="+"
elif A+B-C+D==7:
    x="+"
    z="+"
elif A+B-C-D==7:
    x="+"
elif A-B+C+D==7:
    y="+"
    z="+"
elif A-B+C-D==7:
    y="+"
elif A-B-C+D==7:
    z="+"
print("{}{}{}{}{}{}{}{}".format(A,x,B,y,C,z,D,"=7"))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 12 );
	}

	void solve() {
		int L;
		cin >> L;
		cout << pow( L/3.0, 3.0 ) << endl;
	}
};

int main() {
	Solver().solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    string t = "RGB";
    vector<ll> p(3);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            if (s[i] == t[j]) {
                p[j]++;
                ll tmp = 1;
                for (int k = 0; k < 3; k++) {
                    if (j != k) {
                        tmp *= p[k];
                    }
                }
                ans += tmp;
            }
        }
    }
    for (int i = 1; i < n; i++) {
        int x = i, y = i * 2;
        for (int j = 0; y < n; j++, x++, y++) {
            if (s[j] != s[x] && s[x] != s[y] && s[y] != s[j]) {
                ans--;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3656
n=int(input())
A=[int(i) for i in input().split()]

A.sort()
A.append(-1)

dat={i:False for i in range(10**6+10)}

ans=0
for i in range(len(A)-1):
    if dat[A[i]]:
        pass
    else:
        if A[i]!=A[i+1]:
            ans+=1
        for i in range(A[i],10**6+10,A[i]):
            dat[i]=True

print(ans)

Measured memory_bytes: 103196
package main

import "fmt"

func gcd(A int, B int) int {

	if B == 0 {
		return A
	}
	return gcd(B, A%B)
}

func lcm(A int, B int) int {

	return (A / gcd(A, B)) * B
}

func main() {
	// Code for C - Multiple Clocks
	var N int
	fmt.Scan(&N)

	var T int
	var ans int = 1
	for i := 0; i < N; i++ {
		fmt.Scan(&T)
		ans = lcm(T, ans)
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1772