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

using namespace std;

const int MAXN = 100005;

const int MOD = 1000000007;

long long d[2][MAXN];

vector<vector<int>> ad(MAXN);

void dfs(int s, int w)
{
    d[0][s] = d[1][s] = 1;
    for (int x : ad[s])
    {
        if (x ^ w)
        {
            dfs(x, s);
            d[0][s] = (d[0][s] * (d[0][x] + d[1][x]))%MOD;
            d[1][s] = (d[1][s] * d[0][x])%MOD;
        }
    }
    d[0][s] %= MOD;
    d[1][s] %= MOD;
}


int main()
{
    int n, a, b, c;
    scanf("%i", &n);
    for (int x = 1; x < n; x++)
    {
        scanf("%i%i", &a, &b);
        ad[a].push_back(b);
        ad[b].push_back(a);
    }
    dfs(1,1);
    printf("%lli\n", (d[0][1] + d[1][1])%MOD);
}


Measured memory_bytes: 14208
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long 
using namespace std;

signed main() {
	int A,B;
	char op;
	cin >> A >> op >> B;
	if(op == '+') {
		cout << A + B << endl;
	}
	else {
		cout << A - B << endl;
	}
}

Measured memory_bytes: 256
#coding=UTF-8

import sys
#if digit(a)==digit(b) then
# a <= b <=> a <=_{str} b
# easy nomal

# 1. serch digit(N)
# 2. serch N

#note '0' < '1' < '2'

# utopian when N=123
# ? 1     => Y
# ? 12    => Y
# ? 123   => Y
# ? 1230  => N

# most cases
# ? 100   => Y
# ? 1000  => N
# ==> 3 digits!

# when N=10^c
# no jump (...,{<=,<=_{str}},{>,>_{str}},...)
# => Try 9,99,999,9999,...
# or 11 101 1001 whatsoever...
# always str(N) <= '9'*c

# ? 10**18 is allowed tho N<10**9
# 1 10 100 1000,... are least str for most N (n <=_{str} N)
# In such case, 2nd cond is never true

ans=None
for idx in range(0,11,1):
    print('? 1'+'0'*idx)
    sys.stdout.flush()
    kekka=input()
    if kekka=='N':
        digits=idx
        break
else:
    # 10**c case
    for idx in range(1,11,1):
        print('? '+'9'*idx)
        sys.stdout.flush()
        kekka=input()
        if kekka=='Y':#no cross
            c=idx-1
            break
    ans='! 1'+'0'*c

if ans==None:
    #other case
    #To fix one cmp, query str(guess_number)+'0'
    #so that always n > N

    # if responce == 'Y'
    # myon+'0' >_{str} N
    # i.e. myon >= N (note that boundary)
    kagen=10**(digits-1) # known highest false
    jogen=10**(digits)-1 # known lowest true
    while jogen-kagen>1: # i.e. #not_sure !=0
        miru=(jogen+kagen)//2
        print('? '+str(miru)+'0')
        sys.stdout.flush()
        kekka=input()
        if kekka=='Y':
            jogen=miru
        else:
            kagen=miru

    ans='! '+str(jogen)
            

print(ans)


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

#define MAX 1e12 + 1

int64_t gcd(int64_t a, int64_t b) {
    int64_t tmp;
    if(a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    int64_t r = a % b;
    while(r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

bool IsPrime(int64_t num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    for (int64_t i = 3; i * i <= num; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

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

    int64_t n = gcd(a, b);

    int64_t count = 0;
    for(int64_t i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            if(i == 1 || IsPrime(i)) count += 1;
            if(i * i != n && IsPrime(n / i)) count += 1;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    int a[2] = {-1, 1};
    int b[2] = {-1, 1};
    int c[2] = {-1, 1};
    for(int i = 0; i <= 1; i++)
    {
        for(int j = 0; j <= 1; j++)
        {
            for(int k = 0; k <= 1; k++)
            {
                vector<int> ani(n+2);
                ani[0] = a[i];
                ani[1] = b[j];
                ani[2] = c[k];
                bool flag = true;

                for(int x = 0; x < n; x++)
                {
                    if(s[x] == 'o')
                    {
                        if(ani[x] * ani[x+1] == -1) 
                        {
                            ani[x+2] = -1;
                        }
                        else ani[x+2] = 1;
                    }
                    else
                    {
                        if(ani[x] * ani[x+1] == 1)
                        {
                            ani[x+2] = -1;
                        }
                        else ani[x+2] = 1;
                    }
                }
                if(ani[1] == ani[n+1] && ani[0] == ani[n])
                {
                    for(int x = 1; x <= n; x++)
                    {
                        if(ani[x] == 1) cout << "S";
                        else cout << "W";
                    }
                    return 0;
                }
            }
        }
    }
    cout << -1 << endl;
}



Measured memory_bytes: 1016
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	int n;
	cin >> n;
	
	int c[500],s[500],f[500];
	for (int i=0;i<n-1;i++) {
	cin >> c[i] >> s[i] >> f[i];
	}

	for (int i=0;i<n;i++) {
	int sum =0;
	if (i == n-1) cout << sum << endl;
	else {
	sum = c[i] + s[i];
	for (int j=i;j<n-2;j++) {
	if (sum <= s[j+1]) {sum = s[j+1];}
	else if ((sum - s[j+1])%f[j+1] != 0) {
	sum+=f[j+1] - (sum - s[j+1])%f[j+1];
	}
	sum += c[j+1];
	}
	cout << sum << endl;
	}
	}
	return 0;
}


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

int main() {

  string S;
  int ans = 800;
  
  cin >> S;
  for(int i=0;i<S.size() - 2;++i){
   	string T;
    T.push_back(S.at(i));
    T.push_back(S.at(i+1));
    T.push_back(S.at(i+2));
    int k = stoi(T);
    
    if(abs(753 - k) < ans) ans = abs(753 - k);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static void Main()
    {
        const long Divisor = 1000000007;
        string[] inputs = Console.ReadLine().Split(' ');
        int n = int.Parse(inputs[0]);
        int m = int.Parse(inputs[1]);
        int[] x = Console.ReadLine().Split(' ')
                        .Select(int.Parse)
                        .OrderBy(elem => elem)
                        .ToArray();
        int[] y = Console.ReadLine().Split(' ')
                        .Select(int.Parse)
                        .OrderBy(elem => elem)
                        .ToArray();

        long totalArea = 0, areaX = 0, areaY = 0;
        for (int i = 1; i < n; i++)
        {
            areaX += (long)(x[i] - x[i - 1]) * i % Divisor * (n - i) % Divisor;
            areaX %= Divisor;
        }
        for (int i = 1; i < m; i++)
        {
            areaY += (long)(y[i] - y[i - 1]) * i % Divisor * (m - i) % Divisor;
            areaY %= Divisor;
        }
        totalArea = areaX * areaY % Divisor;
        
        Console.WriteLine(totalArea);
    }
}

Measured memory_bytes: 37664
#include <iostream>

using namespace std;

int main()

{
string c1 , c2 ,c3;
    cin>>c1>>c2;

    int no1,no2;
    cin>>no1>>no2;

    cin>>c3;

if (c1==c3){
    no1--;
}
else{
    no2--;
}
cout<<no1<<" "<<no2<<endl;


 return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <tuple>
#include <functional>

using namespace std;

#define ll long long

ll h[100050] = {};

int main() {
	ll n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	if (n == 1) {
		cout << "Yes" << endl;
		return 0;
	}

	for (int i = 0; i < n - 1; i++) {
		if (h[i] < h[i + 1]) {
			h[i + 1] = h[i + 1] - 1;
		}
	}

	for (int i = 0; i < n - 1; i++) {
		if (h[i] > h[i + 1]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const double PI = 3.14159265358979;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

ll a[10001] = {};
ll b[100][100] = {};
int main() {
	ll h, w, n; cin >> h >> w >> n;
	repe(i, 1, n)cin >> a[i];

	ll curH = 0;
	ll curW = 0;
	bool right = true;
	repe(i, 1, n) {
		rep(j, 0, a[i]) {
			b[curH][curW] = i;

			if (right) {
				curW++;
			}
			else {
				curW--;
			}

			if (curW == w) {
				right = false;
				curW--;
				curH++;
			}
			else if (curW == -1) {
				right = true;
				curW++;
				curH++;
			}
		}
	}

	rep(i, 0, h) {
		rep(j, 0, w) {
			cout << b[i][j];
			if (j != w - 1)cout << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

vec L(0), R(0),ordL(0), ordR(0);
void mysort(){
    sort(ALL(ordL), [&](ll x, ll y){
        return L[x] > L[y];
    });
    sort(ALL(ordR),[&](ll x, ll y){
        return R[x] < R[y];
    });
    return;
}

ll solve(){
    ll last = L[ordL[0]], numL = 1, numR = 0, res = 0;
    if(last <= 0) return res;
    reps(i,1,N){
        bool r = i%2;
        ll id = r ? ordR[i/2] : ordL[i/2], now = r ? R[id] : L[id];
        if(r && last <= now){
            if(last <= 0) --numL;
            break;
        }else if(!r && now <= last){
            if(last >= 0) --numR;
            break;
        }
        r ? ++numR : ++numL;
        last = now;
    }
    rep(i,numL) res += 2 * L[ordL[i]];
    rep(i,numR) res -= 2 * R[ordR[i]];
    return res;
}

int main(){
    cin>>N;
    rep(i,N){
        cin>>A>>B;
        L.push_back(A);
        R.push_back(B);
    }
    rep(i,N){
        ordL.push_back(i);
        ordR.push_back(i);
    }
    mysort();
    ll ans = solve();
    rep(i,N){
        ll t = R[i];
        R[i] = -L[i];
        L[i] = -t;
        ordR[i] = ordL[i] = i;
    }
    mysort();
    cout<<max(ans, solve())<<endl;
}


Measured memory_bytes: 4204
from collections import deque
import sys
input = sys.stdin.readline


N = int(input())
G = [[] for _ in range(N)]
for _ in range(N):
    ls = list(map(int, input().split()))
    u = ls[0] - 1
    for v in ls[2:]:
        G[u].append(v - 1)

time = 1
d = [None for _ in range(N)]
f = [None for _ in range(N)]

def dfs(v):
    global time
    d[v] = time
    time += 1
    
    for u in range(N):
        if u in G[v]:
            if d[u] is None:
                dfs(u)

    f[v] = time
    time += 1

for v in range(N):
    if d[v] is None:
        dfs(v)

for v in range(N):
    print("{} {} {}".format(v + 1, d[v], f[v]))


Measured memory_bytes: 6036
#include <bits/stdc++.h>
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end());
  if (n % 2 == 1) {
    ll ans = 0;
    rep(i, n / 2) ans -= a[i] * 2;
    ans += a[n / 2] + a[n / 2 + 1];
    FOR(i, n / 2 + 2, n) ans += a[i] * 2;
    ll res = 0;
    rep(i, n / 2 - 1) res -= a[i] * 2;
    res -= a[n / 2 - 1] + a[n / 2];
    FOR(i, n / 2 + 1, n) res += a[i] * 2;
    chmax(ans, res);
    cout << ans << endl;
  }
  else {
    ll ans = 0;
    rep(i, n / 2 - 1) {
      ans -= a[i] * 2;
    }
    ans += a[n / 2] - a[n / 2 - 1];
    FOR(i, n / 2 + 1, n) {
      ans += a[i] * 2;
    }
    cout << ans << endl;
  }


  
  return 0;
}

Measured memory_bytes: 1024
n = int(input())
list = list(map(int,input().split()))

product_list = [1]*n

for i in range(len(list)):
  for j in range(len(list)):
    if i != j :
      product_list[i] *= list[j]
  
product_sum = 0
for i in range(len(list)):
  product_sum += product_list[i]
  
total_product = product_list[0] * list[0]

print( total_product / product_sum)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	static final boolean debugMode = false;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = readInt(sc);
		int a = x / 500;
		x -= 500 * a;
		int b = x / 5;
		System.out.println(a * 1000 + b * 5);

	}

	static int readInt(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	static void log(String s) {
		if (debugMode) {
			System.out.println(s);
		}
		return;
	}
}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}

}

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

using namespace std;

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

  int x1, y1, x2, y2, x3, y3, x4, y4;
  cin >> x1 >> y1 >> x2 >> y2;

  x3 = x2 + (y1 - y2);
  y3 = y2 - (x1 - x2);
  x4 = x1 + (y1 - y2);
  y4 = y1 - (x1 - x2);

  cout << x3 << " " << y3 << " " << x4 << " " << y4 << '\n';

  return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair



int main() {
  int n, h, w;
  cin >> n >> h >> w;
  cout << (n - h + 1) * (n - w + 1) << endl;
}


Measured memory_bytes: 256
l=[]
for i in range(5):
    l.append(int(input()))
#print(l)
s=[]
for i in range(5):
    s.append([i,l[i]%10 if l[i]%10!=0 else 10])
s.sort(key=lambda x:x[1])
#print(s)
ans=0
for i in range(4):
    ans+=l[s[4-i][0]]+(10-s[4-i][1])
    #print(ans)
print(ans+l[s[0][0]])

Measured memory_bytes: 3064
main = do
 abc <- map read . words <$> getLine
 print $ minimum $ map sum (comb 2 abc)

comb :: Int -> [a] -> [[a]]
comb 0 _ = [[]]
comb _ [] = []
comb n (x:xs) = [x:y | y <- comb (n-1) xs] ++ comb n xs 

Measured memory_bytes: 508
#include <bits/stdc++.h> 
using namespace std; 
 
int main() 
{ 

    int r,D,x;
    cin>>r>>D>>x;

    int64_t x_next;
    for(int i=0;i<10;i++){
        x_next = r*x - D;
        cout<<x_next<<endl;
        x = x_next;
    }

    return 0; 
} 


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=100000;
int n,v[MAXN+5],Ans;
int c[2][MAXN+5],cnt[2];
int vis[2][MAXN+5];
int ret[2],ret2[2];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&v[i]);
	for(int i=1;i<=n;i++)
		c[i%2][++cnt[i%2]]=v[i];
	for(int k=0;k<2;k++)
		for(int i=1;i<=cnt[k];i++)
			vis[k][c[k][i]]++;
	for(int k=0;k<2;k++)
		for(int i=1;i<=MAXN;i++)
			if(vis[k][ret[k]]<vis[k][i])
				ret[k]=i;
	if(ret[0]==ret[1]){
		for(int k=0;k<2;k++)
			for(int i=1;i<=MAXN;i++)
				if(i!=ret[k])
					if(vis[k][ret2[k]]<vis[k][i])
						ret2[k]=i;
		Ans=cnt[0]+cnt[1];
		Ans-=max(vis[0][ret[0]]+vis[1][ret2[1]],vis[1][ret[1]]+vis[0][ret2[0]]);
	}
	else Ans=cnt[0]-vis[0][ret[0]]+cnt[1]-vis[1][ret[1]];
	printf("%d\n",Ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){
  string S;
  cin >> S;
  int N = S.size();

  //0番目を白
  int counter1 = 0;
  int counter2 = 0;
  for(int i = 0; i < N; i++){
    if(i % 2 == 0 && S.at(i) == '0') counter1++;
    if(i % 2 == 0 && S.at(i) == '1') counter2++;
    if(i % 2 == 1 && S.at(i) == '1') counter1++;
    if(i % 2 == 1 && S.at(i) == '0') counter2++;
  }
  cout << min(counter1, counter2) << endl;
}

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

using namespace std;

const int MAX_N = 2e5 + 200, LOG = 60;

int n, ai[MAX_N], mem[MAX_N], nxt[MAX_N], up[LOG][MAX_N], ansBox[MAX_N];
long long k;

int main()
{
	scanf("%d%lld", &n, &k);
	for (int i = 1; i <= n; i++)
		scanf("%d", &ai[i]);
	for (int i = n; i >= 1; i--)
		mem[ai[i]] = i;
	for (int i = n; i >= 1; i--)
		nxt[i] = mem[ai[i]], mem[ai[i]] = i;
	up[0][0] = 1;
	for (int i = n; i >= 1; i--)
		if (nxt[i] <= i)
			if (nxt[i] == n)
				up[0][i] = 0;
			else
				up[0][i] = nxt[i] + 1;
		else if (nxt[i] == n)
			up[0][i] = 1;
		else
			up[0][i] = up[0][nxt[i] + 1];
	for (int i = 1; i < LOG; i++)
		for (int j = 0; j <= n; j++)
			up[i][j] = up[i - 1][up[i - 1][j]];
	int ans = 0;
	for (int i = LOG - 1; i >= 0; i--)
		if (k & (1LL << i))
			ans = up[i][ans];
	memset(mem, 0, sizeof(mem));
	int tot = 0;
	if (ans == 0)
		return 0;
	for (int i = ans; i <= n; i++)
	{
		if (mem[ai[i]] == 0)
			ansBox[++tot] = ai[i], mem[ai[i]] = tot;
		else
		{
			int pos = mem[ai[i]];
			while (tot >= pos)
				mem[ansBox[tot--]] = 0;
		}
	}
	for (int i = 1; i <= tot; i++)
		printf("%d ", ansBox[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 53768
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt(),B = sc.nextInt(),C = sc.nextInt(),D = sc.nextInt();
		int left = A + B,right = C + D;

		if(left > right) {
			System.out.println("Left");
		}else if(left < right) {
			System.out.println("Right");
		}else {
			System.out.println("Balanced");
		}
	}
}


Measured memory_bytes: 21844
import java.util.Arrays;
import java.util.Scanner;

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

	public static void main(String[] args) {
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] P = new int[N][D];
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < D; ++j) {
				P[i][j] = sc.nextInt();
			}
		}
		int INF = 1 << 28;
		int[][][] dp = new int[D + 1][N][D + 1];
		int[][][] prev = new int[D + 1][N][D + 1];
		for (int[][] aa : dp) {
			for (int[] a : aa) {
				Arrays.fill(a, INF);
			}
		}
		for (int i = 0; i < N; ++i) {
			dp[D][i][0] = 0;
		}
		for (int i = D - 1; i >= 0; --i) {
			for (int j = 0; j < N; ++j) {
				for (int k = 0; k < N; ++k) {
					for (int l = 0; l < D - i; ++l) {
						if (dp[i + 1][k][l] == INF) continue;
						if (j == k) {
							if (dp[i + 1][k][l] + P[j][i] < dp[i][j][l]) {
								dp[i][j][l] = dp[i + 1][k][l] + P[j][i];
								prev[i][j][l] = k;
							}
						} else {
							if (dp[i + 1][k][l] + P[j][i] < dp[i][j][l + 1]) {
								dp[i][j][l + 1] = dp[i + 1][k][l] + P[j][i];
								prev[i][j][l + 1] = k;
							}
						}
					}
				}
			}
		}

		int min = INF;
		int minM = 0;
		int minH = 0;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j <= D; ++j) {
				if (dp[0][i][j] < min || (dp[0][i][j] == min && j < minM)) {
					min = dp[0][i][j];
					minM = j;
					minH = i;
				}
			}
		}
		System.out.println(min + " " + minM);
		for (int i = 0; i < D; ++i) {
			System.out.println(minH + 1);
			int p = prev[i][minH][minM];
			if (p != minH) --minM;
			minH = p;
		}
	}
}

Measured memory_bytes: 28776
#include <stdio.h>

int main(){
	int x,a,b;
	scanf("%d %d %d",&x,&a,&b);
	int dis_a=x-a;
	int dis_b=x-b;
	if(dis_a<0){
		dis_a*=-1;
	}
	if(dis_b<0){
		dis_b*=-1;
	}
	if(dis_a>dis_b){
		printf("B");
	}
	else if (dis_a<dis_b){
		printf("A");
	}
	return 0;
}

Measured memory_bytes: 1616
/* ex4_2
  terakura */

#include <stdio.h>
#include <math.h>

int main(void){
    double short_hund, long_hund, hour, minute, angle, area;
    scanf("%lf %lf %lf %lf", &short_hund, &long_hund, &hour, &minute );


//短針とが０時０分の為す角は(時間＊2π/12) + (π/6の”分”ぶんの60)
    angle = ((hour *  2 * M_PI / 12) +( M_PI / 6 * minute / 60)) -(minute / 60) * 2 * M_PI ;     //短針と長針のなす角度(ラジアン)
    area = sqrt( pow(short_hund, 2) + pow(long_hund, 2) - 2 * short_hund * long_hund * cos(angle));     //余弦定理で面積を計算

    printf("%.20lf\n", area);

    return 0;
}


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

using namespace std;

struct node {
	int key;
	node *parent, *right, *left;
};

node *root, *NIL;

void insert(int n) {
	node *y = NIL;						//今の親；とりあえずNIL
	node *x = root;						//今の位置,とりあえずroot
	node *z;							//挿入される節

//	z = (node *)malloc(sizeof(node));	//挿入節の領域確保
	z = new node;						//これでもいいじゃん

	z->key = n;							//keyは入力値
	z->left = NIL;						//left,rightは葉なのでNIL
	z->right = NIL;

	while (x != NIL) {					//なにも無い位置まで行く
		y = x;							//後で下に行くので親を自分にしておく
		if (z->key < x->key) {			//値が小さければ左に行く
			x = x->left;
		}
		else {
			x = x->right;
		}
	}

	z->parent = y;						//場所が分かったので親を設定						
	if (y == NIL) {						//親がなければｚは根
		root = z;
	}
	else {
		if (z->key < y->key) {			//親がいたら親のどっちに自分がいるか設定
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}

void find(int n) {
	node *x = root;
	if (x == NIL) { cout << "no" << endl; return; }
	while (x != NIL) {
		if (x->key == n) { cout << "yes" << endl; return; }
		else if (x->key > n) { x = x->left; }
		else { x = x->right; }
	}
	cout << "no" << endl;
}

void inorder(node *x) {
	if (x == NIL) {
		return;
	}

	inorder(x->left);
	cout << " " << x->key;
	inorder(x->right);

}

void preorder(node *x) {
	if (x == NIL) {
		return;
	}

	cout << " " << x->key;

	preorder(x->left);
	preorder(x->right);

}

void del0(node *x,int n) {
	if (x->parent->key > n) { x->parent->left = NIL; }
	else if (x->parent->key <= n) { x->parent->right = NIL; }
	free(x);
}

void del1(node *x, int n) {
	if (x->left != NIL) {
		if (x->parent->key > n) { x->parent->left = x->left; }
		else if (x->parent->key <= n) { x->parent->right = x->left; }
		x->left->parent = x->parent;
	}
	else {
		if (x->parent->key > n) { x->parent->left = x->right; }
		else if (x->parent->key <= n) { x->parent->right = x->right; }
		x->right->parent = x->parent;
	}
	free(x);
}

void del2(node *x, int n) {

	node *y = x->right;
	while (y->left != NIL) {
		y = y->left;
	}
	x->key = y->key;

	while (y != NIL) {
		if (y->right == NIL && y->left == NIL) {
			del0(y, y->key);
			y = NIL;
		}
		else if (y->right == NIL || y->left == NIL) {
			del1(y, n);
			y = NIL;
		}
		//else {
		//	del2(y, n);
		//}
	}
}

void del(int n) {
	node *x = root;
	if (x == NIL) { return; }
	while (x != NIL) {
		if (x->key == n) { break; }
		else if (x->key > n) { x = x->left; }
		else { x = x->right; }
	}

	if (x->right == NIL && x->left == NIL) {
		del0(x,n);
	}
	else if (x->right == NIL || x->left == NIL) {
		del1(x, n);
	}
	else {
		del2(x, n);
	}

}

void pr() {
	inorder(root);
	cout << endl;
	preorder(root);
	cout << endl;

}

int main() {

	int m;
	cin >> m;
	string str;
	int n;
	for (int i = 0; i < m; i++) {
		cin >> str;
		if (str == "insert") {
			cin >> n;
			insert(n);
		}
		else if (str == "find") {
			cin >> n;
			find(n);
		}
		else if (str == "delete") {
			cin >> n;
			del(n);
		}
		else if (str == "print") {
			pr();
		}
	}
}


Measured memory_bytes: 21864
import math
import collections

N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

factors = prime_factorize(N)

c = collections.Counter(factors)

count = 0

for k, v in c.items():
    i = 0
    rem = v
    while True:
        i += 1
        rem -= i
        if rem < 0:
            break
        count += 1

print(count)

Measured memory_bytes: 9460
import java.util.*;
public class Main {
    static class Node{
        List<Integer> to;
        Node(){
            to = new ArrayList<Integer>();
        }
    }
    static Node g[];
    static int ans[];
    static Map<Long, Integer> mp;
    public static void dfs(int s, int p, int c){
        if(p != -1){
            ans[mp.get(((long)s << 31) + p)] = c;
        }
        int now = 1;
        for(Integer x : g[s].to){
            if(x == p)continue;
            if(now == c)now++;
            dfs(x, s, now++);
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        g = new Node[n];
        ans = new int[n - 1];
        mp = new HashMap<>();
        for(int i = 0; i < n; i++){
            g[i] = new Node();
        }
        for(int i = 0; i < n - 1; i++){
            Integer a = sc.nextInt() - 1;
            Integer b = sc.nextInt() - 1;
            g[a].to.add(b);
            g[b].to.add(a);
            mp.put(((long)a << 31) + b, i);
            mp.put(((long)b << 31) + a, i);
        }
        dfs(0, -1, 10000000);
        int mx = -1;
        for(int i : ans){
            mx = Math.max(mx, i);
        }
        System.out.println(mx);
        for(int i : ans){
            System.out.println(i);
        }
    }
}


Measured memory_bytes: 114100
#include <iostream>

using namespace std;
long long t[2],a[2],b[2];
int main(){
	int i;
	for(i=0;i<2;i++){
		cin >> t[i];
	}
	for(i=0;i<2;i++){
		cin >> a[i];
	}
	for(i=0;i<2;i++){
		cin >> b[i];
	}
	if((a[0]*t[0] + a[1]*t[1])==(b[0]*t[0] + b[1]*t[1])){
		cout << "infinity" << endl;
		return 0;
	}
	if((a[0]*t[0] + a[1]*t[1])<(b[0]*t[0] + b[1]*t[1])){
		swap(a[0],b[0]); swap(a[1],b[1]);
	}
	if(a[0]>b[0]){
		cout << 0 << endl;
		return 0;
	}
	long long x = a[0]*t[0] + a[1]*t[1] - b[0]*t[0] - b[1]*t[1];
	long long y = (b[0] - a[0])*t[0];
	long long n = y/x;
	if(x*n==y){
		cout << 2*n << endl;
	}else{
		cout << 2*n + 1 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
double ans = 0;
bool arg(pair<ll,ll> a,pair<ll,ll> b,pair<ll,ll> c){
return (b.first-a.first)*(c.second-b.second)-(b.second-a.second)*(c.first-b.first)<0;
}
bool arg2(pair<ll,ll> a,pair<ll,ll> b,pair<ll,ll> c){
return (b.first-a.first)*(c.second-b.second)-(b.second-a.second)*(c.first-b.first)>0;
}

int main()
{
ll n ;
cin >> n ;
set<pair<ll,ll>> s;
s.insert({0,0});
rep(i,n){
  ll x , y ;
  cin >> x >> y ;
  vector<pair<ll,ll>> vs;
  for(auto p:s){
    vs.push_back({x+p.first,y+p.second});
  }
  for(auto p:vs){
    s.insert(p);
  }
  vector<pair<ll,ll>> v;
  for(auto p:s){
    if(v.size()<2)v.push_back(p);
    else{
      while(!arg(v[v.size()-2],v[v.size()-1],p)&&v.size()>=2)v.pop_back();
      v.push_back(p);
    }
  }
  vector<pair<ll,ll>> vv;
    for(auto p:s){
    if(vv.size()<2)vv.push_back(p);
    else{
      while(!arg2(vv[vv.size()-2],vv[vv.size()-1],p)&&vv.size()>=2)vv.pop_back();
      vv.push_back(p);
    }
  }
  s.clear();
  for(auto p:v){
    s.insert(p);
  }
    for(auto p:vv){
    s.insert(p);
  }
}
for(auto p:s){
  ans=max(ans,sqrt(p.first*p.first+p.second*p.second));
}
cout<<fixed<<setprecision(13)<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[105][105];
int hh[105],ll[105],h,l;
int main(){
	cin>>h>>l;
	for(int i=1;i<=h;++i)
		for(int j=1;j<=l;++j){
			cin>>a[i][j];
			if(a[i][j]=='#') hh[i]=1;
		}
	for(int j=1;j<=l;++j)
		for(int i=1;i<=h;++i)
			if(a[i][j]=='#'){
				ll[j]=1;break;
			} 
	for(int i=1;i<=h;++i){
		if(!hh[i]) continue;
		for(int j=1;j<=l;++j){
			if(!ll[j]) continue;
			cout<<a[i][j];
		}
		cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n!=0){
    int h[n+1];
    for(int i=0;i<n+1;i++){
      cin >>h[i];
    }
    int sub1=h[1]-h[0];
    int sub2=h[2]-h[1];
    int sub3=h[3]-h[2];
    int sub4=h[4]-h[3];
    int sub;
    int iti=true;
    for(int i=0;i<1;i++){
      if(sub1==sub4){
        sub=sub1;
        break;
      }
      if((sub1==sub2)&&(sub2==sub3)){
        sub=sub1;
        break;
      }
      if((sub2==sub3)&&(sub3==sub4)){
        sub=sub4;
        iti=false;
        break;
      }
      if((sub1==sub2)&&(sub1==sub3+sub4)){
        sub=sub1;
        break;
      }
      if((sub4==sub3)&&(sub4==sub1+sub2)){
        sub=sub4;
        break;
      }
    }
    for(int i=0;i<n+1;i++){
      if((h[i+1]-h[i]!=sub)&&(iti==true)){
        cout <<h[i+1]<<endl;
        break;
      }
    }
    if(iti==false)cout <<h[0]<<endl;
    cin >>n;
  }
  return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

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

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

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

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

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

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

    int x;
    cin >> x;
    LL res = 0;
    res += x / 500 * 1000;
    x %= 500;
    cout << res + x / 5 * 5 << endl;
    return 0;
}



Measured memory_bytes: 256
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

A, V = rl()
B, W = rl()
T = ri()

if A <= B:
	if B+W*T <= A+V*T:
		print('YES')
	else:
		print('NO')
else:
	if B-W*T >= A-V*T:
		print('YES')
	else:
		print('NO')



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

int main(void){
    unsigned long long int K, A, B, koukan, amari, saisyo;
    unsigned long long int ans;
    cin >> K >> A >> B;
    if (A + 2ULL >= B) cout << K + 1ULL << endl;
    else {
        saisyo = K - (A - 1ULL);
        koukan = saisyo / 2ULL;
        amari = saisyo % 2ULL;
        ans = koukan * (B - A) + amari + A;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a;
    cin>>a;
    long long sum=0;
    char t;
    long long f=0;
    for(long long i=0;i<a;i++)
    {
        cin>>t;
        if(t=='I')
        {
            f++;
        }
        if(t=='D')
        {
            f--;
        }
        if(f>sum)
        {
            sum=f;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans=0

for i in range(n):
  if a[i]>=b[i]:
    ans+=b[i]
    a[i]-=b[i]
  else:
    ans+=a[i]
    b[i]-=a[i]
    a[i]=0
    if a[i+1]>=b[i]:
      ans+=b[i]
      a[i+1]-=b[i]
    else:
      ans+=a[i+1]
      a[i+1]=0
print(ans)

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

const int MOD = 1e9+7;
 ;
int main(){
	
	int n,m;
	cin >> n >> m;
	
	vector<int> a(m);
	vector<bool> broken(n, false);
	rep(i,m){
		cin >> a[i];
		broken[a[i]-1] = true;
	}

	vector<ll> dp(n); // n段目まで上る総数
	dp[0] = 1; dp[1] = 2;
	for(int i=0;i<n;i++){
		if(broken[i]){
			dp[i] = 0;
			if(i==0) dp[i+1] = 1;
		}
		else if(i>1) dp[i] = (dp[i-1] + dp[i-2]) % MOD;
	}

	cout << dp[n-1] << endl;
	
	return 0;
}

Measured memory_bytes: 1408
#include <vector>
#include <cstdio>
#include <assert.h>
using namespace std;
#define ll long long
#define N 200010
int n,m,L[N],R[N],t[N],fa[N],sz[N];
ll tot,cnt,ans,mx,dis[N],a[N*4],b[N*4],ta[N*2],tb[N*2];
vector<ll>A[N],B[N]; 
void add(ll x,ll y)
{
    if (!cnt){ta[1]=x,tb[1]=y,cnt=1;return;}
    assert(ta[cnt]<=x);
    if(ta[cnt]==x){tb[cnt]=min(tb[cnt],y);}
    else if(tb[cnt]>y) ++cnt,ta[cnt]=x,tb[cnt]=y;
}
bool check(int x,ll r)
{
    A[x].clear(),B[x].clear();
    if (!L[x]) { A[x].push_back(0),B[x].push_back(0); return 1; }
    if (!check(L[x],r)) return 0;
    if (!check(R[x],r)) return 0;
    if (A[L[x]].size()>A[R[x]].size()) swap(L[x],R[x]);
    for (int i=0,p=A[L[x]].size();i<p;i++) A[L[x]][i]+=t[L[x]],B[L[x]][i]+=t[L[x]];
    for (int i=0,p=A[R[x]].size();i<p;i++) A[R[x]][i]+=t[R[x]],B[R[x]][i]+=t[R[x]];
    tot=cnt=0;
    for (int i=0,cnt=0,q=A[R[x]].size(),p=A[L[x]].size();i<p;i++)
	{
        while (cnt+1<q&&A[R[x]][cnt+1]+B[L[x]][i]<=r) cnt++;
        if (cnt<q&&A[R[x]][cnt]+B[L[x]][i]<=r) a[tot]=A[L[x]][i],b[tot]=B[R[x]][cnt],tot++;
    }
    for (int i=tot-1;i>=0;i--) a[tot]=b[i],b[tot]=a[i],tot++; 
	tot>>=1; int p1=0,p2=tot;
    while (p1<tot||p2<tot*2)
        if (p2==tot+tot) add(a[p1],b[p1]),p1++; else if (p1==tot) add(a[p2],b[p2]),p2++;
        else if (a[p1]<a[p2]) add(a[p1],b[p1]),p1++; else add(a[p2],b[p2]),p2++;
    for (int i=1;i<=cnt;i++) A[x].push_back(ta[i]),B[x].push_back(tb[i]);
    return cnt>0;
}
int main()
{
	scanf("%d",&n);
    for (int x=2,y;x<=n;x++)
	{
		scanf("%d%d",&y,&t[x]),fa[x]=y;
        if (!L[y]) L[y]=x; else R[y]=x;
        dis[x]=dis[y]+t[x],mx=max(mx,dis[x]);
    }
    for (ll l=0,r=(mx*2),mid=mx;l<=r;mid=l+r>>1) if (check(1,mid)) ans=mid,r=mid-1; else l=mid+1;
    printf("%lld",ans);
}

Measured memory_bytes: 47600
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int ans = -1;
        int k ;
        cin >> k;
        int r = 7%k;
        if(r == 0)cout << 1 << "\n";
        else{
            int count = 0;
            for(int i = 1; i<=k; i++){
                r = (r*10 + 7)%k;
                count += 1;
                if(r == 0){
                    ans = count+1;
                    break;
                }
            }
            cout << ans << "\n";}

}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3632
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>

using namespace std;

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

    if(A >= 30){
        cout << "Yes";
    }else{
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 3132
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n + 1];
        int[] b = new int[n];
        for (int i = 0 ; i < n + 1 ; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0 ; i < n ; i++) {
            b[i] = sc.nextInt();
        }
        long ans = 0;
        int res = 0;
        for (int i = 0 ; i < n ; i++) {
            if (a[i] - b[i] >= 0) {
                ans += (long) b[i];
            } else {
                ans += (long) a[i];
                res = b[i] - a[i];
                ans += (long) Math.min(res, a[i + 1]);
                a[i + 1] = Math.max(0, a[i + 1] - res);
            }
        }
        System.out.println(ans);
    }

}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}



//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



int main(){
    
    ll a,b;
    ld h,m;
    cin >> a >> b >> h >> m;

    ll gcd_ = gcd(a,b);
    ll gcd_a = a/gcd_;
    ll gcd_b = b/gcd_;

    ld da = h*30+m*0.5;
    ld db = m*6;

    ld d = min(abs(da-db),360-abs(da-db));
    
    d = cosl(d/180*M_PI);

    ld ans = sqrt(pow(gcd_a,2)+pow(gcd_b,2)-(2*gcd_a*gcd_b*d));


    cout << setprecision(20) << ans*gcd_ << endl;

    
}


Measured memory_bytes: 4128
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int table[26] = {0};
    rep(i, s.size()) table[s[i] - 'a']++;
    ll sum = 1;
    rep(i, 26) {
        sum *= table[i] + 1;
        sum %= (ll)(1e9 + 7);
    }
    cout << sum - 1 << endl;
    
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int w,h;
int mp[20][20],memo[20][20];
int dx[] = {-1,0,1};

void saiki(int x,int y) {
  if(y >= h-1) memo[y][x]++;
  else if(mp[y][x] != 1) {
    for(int i=0;i<3;i++) {
      int nx = dx[i]+x, ny = y+1;
      if(nx <0|| nx >= w ||mp[ny][nx] == 1) continue;
      if(memo[ny][nx] > 0 && mp[ny][nx] == 0) memo[y][x] += memo[ny][nx];
      else if(mp[ny][nx] == 0){
	saiki(nx,ny);
	memo[y][x] += memo[ny][nx];
      }
      else if(nx==x && mp[ny][nx] == 2){
	int ty = ny;
	while(mp[ty][nx] == 2) ty+=2;
	if(mp[ty][nx] == 0 && memo[ty][nx] == 0){
	  saiki(nx,ty);
	  memo[y][x] += memo[ty][nx];
	}
	else if(mp[ty][nx] == 0 && memo[ty][nx] > 0) memo[y][x] += memo[ty][nx];
      }
    }
    if(memo[y][x] == 0) mp[y][x] = 1;
  }
}
  
int main() {
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    for(int i=0;i<=19;i++)
      for(int j=0;j<=19;j++)memo[i][j] = mp[i][j] = 0;
    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin >> mp[i][j];
 
    for(int i=0;i<w;i++) 
      if(mp[0][i] !=1) saiki(i,0);
    
    int cnt = 0;
    for(int i=0;i<w;i++)
      if(memo[0][i] > 0) cnt+=memo[0][i];
    cout <<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
using namespace std;

int main(){
	string a, b, c;
	cin >> a >> b >> c;

	char flag = 'a';
	int abc[3] = {0};

	while(1){
		if (flag == 'a'){
			abc[0]++;
			if ((abc[0]-1) ==a.length()){
				cout << 'A' << endl;
				break;
			}
			flag = a[abc[0]-1];
		}
		else if (flag == 'b'){
			abc[1]++;
			if ((abc[1]-1) ==b.length()){
				cout << 'B' << endl;
				break;
			}
			flag = b[abc[1]-1];
		}
		else{
			abc[2]++;
			if ((abc[2]-1) ==c.length()){
				cout << 'C' << endl;
				break;
			}
			flag = c[abc[2]-1];
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> t(n);
    REP(i,n){
        cin >> t[i] >> a[i];
    }
    ll na = 1;
    ll nt = 1;
    REP(i,n){
        ll ta = (na+a[i]-1)/a[i];
        ll tt = (nt+t[i]-1)/t[i];
        ll b = max(ta,tt);
        na = a[i]*b;
        nt = t[i]*b;
    }
    put(na+nt);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,a,b) for(register int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(register int i=(a),i##_st=(b);i>=i##_st;--i)
#define rpg(i,x) for(register int i=fir[x];i;i=e[i].nxt)
#define ull unsigned long long
#define fi first
#define se second
#define pb push_back
#define bin(i) (1<<i)
#define cls(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pa;
typedef long long LL;
const int INF = 0x7fffffff;
const int oo = 0x3f3f3f3f;
/*
const int _L = 1e6+5;
char ibuf[_L],*ih=ibuf+_L;
inline char gc(){return (ih==ibuf+_L?fread(ibuf,1,_L,stdin),ih=ibuf:0),*ih++;}
#define  getchar() gc() //*/
template <typename T>
inline void rd(T &x)
{
    x = 0; int f = 1; char CH = getchar();
    while(!isdigit(CH)) {if(CH=='-')f=0;CH=getchar();}
    while(isdigit(CH)) {x=(x<<3)+(x<<1)+(CH-48);CH=getchar();}
    x=(f==1)?x:-x;  return;
}
int main()
{
#ifdef iloi
//	   freopen("test.txt","r",stdin);
#endif
	int n,a,b;
	rd(n),rd(a),rd(b);
	if((abs(a-b)-1)%2) {
		cout<<"Alice"<<endl;
	}
	else cout<<"Borys"<<endl;
	return 0;
		 
}

Measured memory_bytes: 256
from operator import itemgetter

N, K = list(map(int, input().split()))
ab = []
for i in range(N):
    ab.append(list(map(int, input().split())))
ab = sorted(ab, key=itemgetter(0,1))

for a, b in ab:
    K -= b
    if K <= 0:
        print(a)
        break

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve()
{
	int n;
	cin >> n;
	string str;
	cin >> str;
	if (str.length() > n){
		for (int i = 0; i < n; ++i){
			cout << str[i];
		}
		cout << "...";
		return;
	}
	cout << str;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	solve();
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#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 rep(i,n) REP(i,0,n)
#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 rd(a) cin>>(a)
#define RD(a,b) cin>>(a)>>(b)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

int main() {
  int n;
  while(cin >> n && n) {
    string s[n];
    rep(i,n) cin >> s[i];
    rep(i,n) {
      rep(j,s[i].size()) {
	if(s[i][j]=='.') s[i][j]=' ';
	if(s[i][j]==' ' && isalpha(s[i][j+1])) {
	  s[i][j]='+';
	  int k=i-1;
	  while(k>=0) {
	    if(j>=s[k].size()) break;
	    if(s[k][j]!=' ') break;
	    s[k][j]='|';
	    k--;
	  }
	  break;
	}
      }
    }
    rep(i,n) pr(s[i]);
  }
  return 0;
}


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

const int mod=1000000007;
int n,x,y,hd[5010],f[5010][5010],g[5010],cnt,siz[5010],ff[5010];
struct node{int to,next;}e[10010];

void addedge(int x,int y)
{
	e[++cnt]=(node){y,hd[x]},hd[x]=cnt;
	e[++cnt]=(node){x,hd[y]},hd[y]=cnt;
}

void dfs(int x,int fa)
{
	siz[x]=1,f[x][1]=1,f[x][0]=0;
	for (int i=hd[x]; i; i=e[i].next)
		if (e[i].to!=fa) 
		{
			dfs(e[i].to,x);
			for (int j=0; j<=siz[x]+siz[e[i].to]; j++) ff[j]=0;
			for (int j=0; j<=siz[x]; j++)
				for (int k=0; k<=siz[e[i].to]; k++)
					ff[j+k]=(ff[j+k]+1ll*f[x][j]*f[e[i].to][k])%mod;
			siz[x]+=siz[e[i].to];
			for (int j=0; j<=siz[x]; j++) f[x][j]=ff[j];
		}
	for (int i=2; i<=siz[x]; i+=2) f[x][0]=(f[x][0]+1ll*f[x][i]*(mod-g[i]))%mod;
}

int main()
{
	g[0]=1;
	for (int i=2; i<=5000; i+=2) g[i]=1ll*g[i-2]*(i-1)%mod;
	scanf("%d",&n);
	for (int i=1; i<n; i++) scanf("%d%d",&x,&y),addedge(x,y);
	dfs(1,0),printf("%d\n",(mod-f[1][0])%mod);
	return 0;
}

Measured memory_bytes: 97280