akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

"""
URL: https://atcoder.jp/contests/dp/tasks/dp_p

P - Independent Set / 
実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 
100 点

問題文
N 頂点の木があります。 
頂点には 1,2,…,N と番号が振られています。
各 i (1≤i≤N−1) について、i 番目の辺は頂点 xi と yi を結んでいます。

太郎君は、各頂点を白または黒で塗ることにしました。 ただし、隣り合う頂点どうしをともに黒で塗ってはいけません。

頂点の色の組合せは何通りでしょうか？ 
10**9+7 で割った余りを求めてください。

制約
入力はすべて整数である。
1≤N≤10**5
1≤xi,yi≤N
与えられるグラフは木である。

"""

#solve
def solve():
    n = II()
    edg = [[] for _ in range(n)]
    for _ in range(n - 1):
        x, y = LI_()
        edg[x].append(y)
        edg[y].append(x)
    black = [1] * n
    white = [1] * n
    rank = [-1] * n
    rank[0] = [0, None]
    q = deque()
    q.append([0, -1])
    while q:
        node, pre = q.pop()
        for nex in edg[node]:
            if nex == pre:
                continue
            rank[nex] = [rank[node][0] + 1, node]
            q.appendleft((nex, node))

    ans = []
    for i in range(n):
        ans.append((-rank[i][0], rank[i][1], i))
    ans.sort()
    for _, i, j in ans[:-1]:
        black[i] *= white[j]
        white[i] *= white[j] + black[j]
        black[i] %= mod
        white[i] %= mod
    print((white[0] + black[0]) % mod)
    return


#main
if __name__ == '__main__':
    solve()


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

int main(){
	while(1){
		int n,h[102];
		scanf("%d",&n);
		if(n == 0)break;
		for(int i = 0 ; i < n+1 ; i ++){
			scanf("%d",&h[i]);
		}
		for(int i = 0 ; i < n+1 ; i ++){
			int d = (i<2)?h[n]-h[n-1]:h[1]-h[0];
			bool t = true;
			for(int j = 0 ; j < n && t ; j ++){
				if(j == i)continue;
				if(j+1 == i && j+2 <= n){
					t &= (h[j+2]-h[j]==d);
				}
				if(j+1 != i){
					t &= (h[j+1]-h[j]==d);
				}
			}
			if(t){
				cout << h[i] << endl;
				goto next_loop;
			}
		}
		next_loop:;
	}
}

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

int main(){
    int n;
    cin >> n;
    vector<string> v(n);
    cin >> v[0];
    int count = 0;
    for(int i=1;i<n;i++){
        cin >> v[i];
        if(v[i-1].back() != v[i].front()){
            count++;
            break;
        }
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(v[i]==v[j]){
                i=n-2;
                count++;
                break;
            }
        }
    }
    if(count!=0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
using System;

	public class Class1
	{
		public static void Main(String[] args)
		{   string line;
			while((line=Console.ReadLine())!="-")
			{				
			int m=int.Parse(Console.ReadLine());			
			shuffle(m,line);
			}
		}
		public static void shuffle(int count ,string abc)
		{	
			string h;
			for(int i=0;i<count;i++)
			{
				 h=Console.ReadLine();
				 
				 
				 int index=int.Parse(h);
				 string after=abc.Substring(index);
				 string tail=abc.Substring(0,index);
				 abc=after+tail;
				 
				 
			}
			Console.WriteLine(abc);
			
		}
	}

Measured memory_bytes: 8916
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    var t = 1L
    var a = 1L

    for (i in 0 until n) {
        val ti = sc.nextInt()
        val ai = sc.nextInt()

        val k = Math.max(1 + (t - 1) / ti, 1 + (a - 1) / ai)
        t = k * ti
        a = k * ai
    }
    println(t + a)
}


Measured memory_bytes: 31520
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int sum1[2010][2010],sum2[2010][2010],sum3[2010][2010];
char a[2010][2010];
int n,m,q;
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;i++)
		scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)sum1[i][j]=sum1[i][j-1]+a[i][j]-'0';
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)sum1[i][j]+=sum1[i-1][j];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			sum2[i][j]=sum2[i][j-1];
			sum3[i][j]=sum3[i][j-1];
			if(a[i][j]=='1'&&a[i][j-1]=='1')sum2[i][j]++;
			if(a[i][j]=='1'&&a[i-1][j]=='1')sum3[i][j]++;
		}
	}
/*	cout<<endl;
		for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<sum1[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;*/
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			sum2[i][j]+=sum2[i-1][j];
			sum3[i][j]+=sum3[i-1][j];
		//	if(a[i][j]=='1'&&a[i-1][j]=='1')sum2[i][j]++;
		}
	}
/*	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<sum2[i][j]<<" ";
		}
		cout<<endl;
	}*/
	while(q--){
		int x1,y1,x2,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		int s1=sum1[x2][y2]-sum1[x1-1][y2]-sum1[x2][y1-1]+sum1[x1-1][y1-1];
		y1++;
		int s2=sum2[x2][y2]-sum2[x1-1][y2]-sum2[x2][y1-1]+sum2[x1-1][y1-1];
		y1--;
	//	cout<<s1<<" "<<s2<<endl;
		x1++;
		int s3=sum3[x2][y2]-sum3[x1-1][y2]-sum3[x2][y1-1]+sum3[x1-1][y1-1];
		printf("%d\n",s1-s2-s3);
	}
//	while(1);
    return 0;
}


Measured memory_bytes: 52992
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

 ll MOD = 1000000007;

// a^p
 // 2^3 = 2 * 2^2
 // 2^2 = 2 * (2^1)
 // 2^1 = 2
 ll modpow(ll a, ll p, ll mod) {
   if (p == 0) return 1;

   if (p % 2 == 0) {
     ll half = modpow(a, p/2, mod) % mod;
     return half * half % mod;
   } else {
     return a * modpow(a, p - 1, mod) % mod;
   }
 }

 // nCa を求める
 ll modCombination(ll n, ll a, ll mod) {
   if (n - a < a) {
     return modCombination(n, n - a, mod);
   }

   ll denominator = 1; // 分母
   ll numerator = 1; // 分子

   for (ll i = 0; i < a; i++) {
     denominator *= a - i;
     numerator *= n - i;
     denominator %= mod;
     numerator %= mod;
   }

   return numerator * modpow(denominator, mod - 2, mod) % mod;
 }

int main() {
  ll H;
  cin >> H;

  ll h = H;

  ll num = 0;
  while (h != 0) {
    num++;
    h /= 2;
  }

  ll ans = 0;
  for (ll i = 0; i < num; i++) {
    ans += (ll)powl(2, i);
  }

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


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999
int dp[60000];



int main(){
    string s;
    while(cin>>s){
        if(s=="0")break;
        int l=s.size();
        rep(i,60000)dp[i]=INF;
        bool ff=true;
        rep(i,s.size()-1){
            if(s[i]!=s[i+1])ff=false;
        }
        if(ff)cout<<"0"<<endl;
        if(ff)continue;
        int num=0;
        rep(i,s.size()){
            num*=3;
            int p=0;
            if(s[i]=='g')p=1;
            if(s[i]=='b')p=2;
            num+=p;
        }
        dp[num]=0;
        
        queue<pii> que;
        que.push(pii(num,0));
        while(que.size()){
//            cout<<que.size()<<endl;
            pii q=que.front();
            que.pop();
            vector<int> vec;
            rep(i,l){
                vec.pb(q.first%3);
                q.first/=3;
            }
            reverse(all(vec));
            reverse(all(vec));
            rep(i,l-1){
                if(vec[i]!=vec[i+1]){
                    int a=vec[i],b=vec[i+1];
                    if(a>b)swap(a,b);
                    vector<int> v=vec;
                    if(a==0&&b==1)v[i]=v[i+1]=2;
                    if(a==1&&b==2)v[i]=v[i+1]=0;
                    if(a==0&&b==2)v[i]=v[i+1]=1;
                    bool f=true;
                    rep(i,vec.size()-1){
                        if(v[i]!=v[i+1])f=false;
                    }
                    if(f){
                        cout<<q.second+1<<endl;
                        goto next;
                    }
                    int x=0;
                    rep(j,v.size()){
                        x*=3;
                        x+=v[j];
                    }
                    if(dp[x]==INF){
                        dp[x]=q.second+1;
                        que.push(pii(x,q.second+1));
                    }
                }
            }
        }
        cout<<"NA"<<endl;
    next:;
    }
}

Measured memory_bytes: 1472
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a,b;
int main()
{
	a=read(); b=read();
	if((a+b)&1)puts("IMPOSSIBLE");
	else writeln((a+b)>>1);
	return 0;
}

Measured memory_bytes: 128
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,a,b=parseMap(split(readline()))
    s=chomp(readline())
    nihon=0
    kaigai=0
    for i in s
        if i=='a' && nihon+kaigai<a+b
            println("Yes")
            nihon+=1
        elseif i=='b' && nihon+kaigai<a+b && kaigai<b
            println("Yes")
            kaigai+=1
        else
            println("No")
        end
    end
end
main()

Measured memory_bytes: 172768
using System;
using System.Collections.Generic;

namespace MyProgram{
    class AtCoder{
        static void Main(string[] args){
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int min=300000;
            int sum=0;
            for(var i=1;i<N;i++){
                if(S[i]=='E')sum++;
            }
            min = sum;
            for(var i=1;i<N;i++){
                if(S[i-1] == 'E' && S[i] == 'E')sum-=1;
                else if(S[i-1] == 'W' && S[i] == 'W') sum+=1; 
                min = Math.Min(sum,min);
            }
            Console.WriteLine(min);
        }
    } 
}

Measured memory_bytes: 14176
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=1e3+3;
const int mod=1e9+7;

int x,y,xx,yy,n,m;

char a[N][N];
bool vis[N][N];
int cost[N][N];


void dijk(int r,int c){ 
    priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>> >q;      
    for(int i=0;i<n;i++){
    	for(int j=0;j<m;j++){
    		cost[i][j]=1e9;
    	}
    }
    cost[r][c]=0;
    q.push({0,{r,c}}); 
    while(q.empty()==false){ 
           
      ll r=q.top().second.first;
      ll c=q.top().second.second;
      ll curcost=q.top().first;
      q.pop();
      if(vis[r][c])continue;
      vis[r][c]=true;
      for(int i=-2;i<=2;i++){
         for(int j=-2;j<=2;j++){
             int nr=r+i;
             int nc=c+j;
             int dis=1;
             if((abs(nr-r)==1&&abs(nc-c)==0)||(abs(nr-r)==0&&abs(nc-c)==1))dis=0;
             if (nr>=n||nc>= m||nc<0||nr<0||a[nr][nc]=='#'||(nr==r&&nc==c)) continue;
             if(curcost+dis<cost[nr][nc]){
             	cost[nr][nc]=curcost+dis;
                q.push({cost[nr][nc],{nr,nc}}); 
              }
          }
       }
   }
}


int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    cin>>x>>y;
    cin>>xx>>yy;
    x--;y--;xx--;yy--;
    for(int i=0;i<n;i++){
    	for(int j=0;j<m;j++){
    		cin>>a[i][j];
    	}
    }
    dijk(x,y);
    cout<<(cost[xx][yy]==1e9?-1:cost[xx][yy]);
}

    


Measured memory_bytes: 9632
from heapq import *
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()[:-1]
N, M = map(int, input().split())
es = [[] for i in range(N+1)]
for id in range(M):
    a, b = map(int, input().split())
    es[a].append([b, id])
    es[b].append([a, id])
edge = [None] * M
h = [0] * (N+1)
lev = [None] * (N+1)
visit = [0] * (N+1)
def dfs(v, d):
    if visit[v]: return
    lev[v] = d
    visit[v] = 1
    for u, id in es[v]:
        if edge[id] == None:
            edge[id] = [v, u]
            h[v] ^= 1
            dfs(u, d+1)
dfs(1, 0)
q = [(-lev[v], v) for v in range(1, N+1)]
heapify(q)
while q:
    lv, v = heappop(q)
    lv = -lv
    if h[v] % 2 == 0: continue
    for u, id in es[v]:
        if lev[u] < lv:
            h[v] ^= 1
            h[u] ^= 1
            k, l = edge[id]
            edge[id] = [l, k]
            break
if h[1]:
    print(-1)
else:
    for u, v in edge:
        print(u, v)


Measured memory_bytes: 510600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll l, r;
    cin >> l >> r;
    vector<ll> mods;
    if (r - l < 2019)
    {
        for (ll i = l; i < r; i++)
        {
            for (ll j = i + 1; j <= r; j++)
            {
                mods.emplace_back(i * j % 2019);
            }
        }
    }
    else
    {
        for(ll i = l; i <= l + 2018; i++){
            for(ll j = l + 1; j <= l + 2019; j++){
                mods.emplace_back(i * j % 2019);
            }
        }
    }
    sort(mods.begin(),mods.end());
    cout << mods[0] << endl;
}

Measured memory_bytes: 35172
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	int a, b, m;
	cin >> a >> b >> m;
	int i;
	V A(a);
	V B(b);
	int Amin = Inf;
	for (i = 0; i < a; i++) {
		cin >> A[i];
		chmin(Amin, A[i]);
	}
	int Bmin = Inf;
	for (i = 0; i < b; i++) {
		cin >> B[i];
		chmin(Bmin,B[i]);
	}
	int ans = Amin + Bmin;
	for (i = 0; i < m; i++) {
		int d, e, f;
		cin >> d >> e >> f;
		d--;
		e--;
		chmin(ans, A[d] + B[e] - f);
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
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; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

template<typename T>
vector<T> smallest_prime_factors(T n) {
    vector<T> spf(n + 1);
    for (int i = 0; i <= n; i++) spf[i] = i;
    for (T i = 2; i * i <= n; i++) {
        if (spf[i] == i) {
            for (T j = i * i; j <= n; j += i) {
                if (spf[j] == j) {
                    spf[j] = i;
                }
            }
        }
    }
    return spf;
}

template<typename T>
vector<T> primefactor(T x, vector<T> &spf) {
    vector<T> ret;
    while (x != 1) {
        ret.push_back(spf[x]);
        x /= spf[x];
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main() {
    ll MAX = 10000000;
    auto spf = smallest_prime_factors(MAX);
    ll N;
    cin >> N;
    ll ans = 1;
    for (ll i = 2; i <= N; i++) {
        map<int, int> temp;
        for (auto now : primefactor(i, spf)) temp[now]++;
        ll cnt = 1;
        for (auto now: temp) cnt *= now.second + 1;
        ans += i * cnt;
    }
    cout << ans << endl;
}


Measured memory_bytes: 81232
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int int_vector_find(std::vector<int> vec, int num) {
	auto itr = std::find(vec.begin(), vec.end(), num);
	int index = std::distance(vec.begin(), itr);

	if (index != vec.size()) {
		return 1;
	}
	else {
		return 0;
	}
}

int main() {
	int r, d, rn;
	std::cin >> r >> d >> rn;
	
	for (int i = 0; i < 10; ++i) {
		std::cout << r * rn - d << std::endl;
		rn = r * rn - d;
	}

}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
ns, ps = gets.split.map(&:to_i).partition(&:negative?)
ns = ns.map(&:abs).reverse
ans = Float::INFINITY
for i in 0..([ns.size, k].min) do
  j = k - i
  next if ps.size < j
  if i == 0
    ans = [ans, ps[j - 1]].min
  elsif j == 0
    ans = [ans, ns[i - 1]].min
  else
    x, y = ns[i - 1], ps[j - 1]
    ans = [ans, x + y + [x, y].min].min
  end
end
p ans

Measured memory_bytes: 12812
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;
const long long Maxn=10000+10,mval=1e18;
long long a[Maxn];
long long n=8005,m,ans;
inline long long power(long long x)
{
	return x*x*x*x*x;
}
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	m=read();
	for(int i=1;i<=n;++i)
	a[i]=power(i-4001);
	for(int i=1;i<=n;++i)
	for(int j=1;j<=n;++j)
	if(a[i]-a[j]==m)
	{
		cout<<i-4001<<' '<<j-4001<<endl;
		return 0;
	}
	
	return 0;
}

Measured memory_bytes: 3696
#include "iostream"
#include <vector>
#include <array>

const uint32_t BILL_TYPE_NUM = 3;
const std::array<uint32_t, BILL_TYPE_NUM> BILL_COST_LIST = {10000, 5000, 1000}; 

int main()
{
    uint32_t N, Y;
    std::cin >> N >> Y;
    
    std::array<uint32_t, BILL_TYPE_NUM> billNUM;

    for (uint32_t billType0Num = 0; billType0Num <= N; billType0Num++) {
        for (uint32_t billType1Num = 0; billType1Num <= N - billType0Num; billType1Num++) {
            const uint32_t billType2Num = N - billType0Num - billType1Num;

            if ((10000 * billType0Num + 5000 * billType1Num + 1000 * billType2Num) == Y){
                std::cout << billType0Num << " " << billType1Num << " " << billType2Num << std::endl;
                return 0;
            }
        }
    }
    
    std::cout << "-1 -1 -1" << std::endl;
  
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <complex>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

typedef long double ld;
typedef complex<ld> P;
typedef vector<P> VP;
const ld eps = 1e-8, pi = acos(-1.0);

#define EQ(a,b) (abs((a)-(b))<eps)

ld dot (P a, P b) { return real(conj(a) * b); }
ld cross (P a, P b) { return imag(conj(a) * b); }

namespace std {
  bool operator<(const P &lhs, const P &rhs) {
    return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
  }
}

// Line
class L{
public:
  P a, b;
  L (P aa, P bb) { a = aa; b = bb; }
  L (ld ax, ld ay, ld bx, ld by) { a = P(ax, ay); b = P(bx, by); }
};

// Circle
class C { public: P p; ld r; };

VP is_cc(C c1, C c2){
  VP res;
  ld d = abs(c1.p - c2.p);
  ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d);
  ld dfr = c1.r * c1.r - rc * rc;
  if (abs(dfr) < eps) dfr = 0.0;
  else if (dfr < 0.0) return res; // no intersection
  ld rs = sqrt(dfr);
  P diff = (c2.p-c1.p)/d;
  res.push_back(c1.p + diff * P(rc, rs));
  if (dfr != 0.0) res.push_back(c1.p + diff * P(rc, -rs));
  return res;
}

bool isis_vc(vector<C> vc) {
  VP crs;
  int n=vc.size();
  REP(i,n)REP(j,i)
    for(P p:is_cc(vc[i],vc[j]))
      crs.push_back(p);
  REP(i,n)
    crs.push_back(vc[i].p);
  for(P p:crs){
    bool valid=true;
    REP(i,n)
      if(abs(p-vc[i].p)>vc[i].r+eps)
        valid=false;
    if(valid) return true;
  }
  return false;
}

int main() {
  while(1) {
    int n;
    cin>>n;
    if(!n)break;
    VP vp(n);
    vector<int> vel(n);
    REP(i,n) {
      ld x,y;
      cin>>x>>y>>vel[i];
      vp[i] = P(x,y);
    }
    ld lb = 0.0, ub = 100.0;
    while(ub - lb > eps) {
      ld mid = (lb + ub) / 2.0;
      vector<C> vc;
      REP(i,n) {
        vc.push_back((C){vp[i], mid*vel[i]});
      }
      if (isis_vc(vc)) {
        ub = mid;
      } else {
        lb = mid;
      }
    }
    cout << setprecision(10) << fixed << lb << endl;
  }
  return 0;
}

Measured memory_bytes: 1448
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int64)n;i++)
#define FORr(i,k,n)  for(int64 i=(int64)k;i>=n;i--)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define FOREACHr(it, l) for (auto it = l.rbegin(); it != l.rend(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}


int main(){
//	in_o();
	string s;
	cin>>s;
	int n=s.length();
	for(int i=n-2;i>=0;i-=2){
		if(s.substr(0,i/2)==s.substr(i/2,i/2))
			return cout<<i<<endl,0;
	}
	return 0;
}

Measured memory_bytes: 256
s=input()
n=len(s)

t1='01'*(n//2+1)
t2='10'*(n//2+1)

t1_chk=0
t2_chk=0

for i in range(n):
	if s[i]!=t1[i]:
		t1_chk+=1
	if s[i]!=t2[i]:
		t2_chk+=1

print(min(t1_chk,t2_chk))

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

using namespace std;

#define debug(x) cout << '[' << #x << " is: " << x << "] " << '\n';
#define imod(a , n) (a % n + n ) % n

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define inF freopen("lineup.in","r",stdin );
#define outF freopen("lineup.out" , "w" , stdout ) ;
#define sor(v) sort(v.begin() , v.end());
#define print(v) for(auto f : v ) cout << f << " " ;
#define ll long long
#define int ll
const double eps = 1e-6 , PI = acos(-1) ;
const long long OO = 1e18 ;
const ll N = 200 , oo = 1e7 , M = 6, mod = 1e9 + 7 , K = 12;

int32_t main(){
    // inF;outF;

    fastio;
    // Dont Forget memset

    //calculate constraints please!!!
   int n ;
   cin >> n ;
   map<int , int > mp ;
   vector<int>v(n);
   int sum = 0 ;
   for(auto &it : v){
    cin >> it ;
    mp[it]++;
    sum += it ;
   }
   int q ;
   cin >> q;
   while(q--){
    int a , b ;
    cin >> a >> b ;
    sum -= (a * mp[a]);
    sum += mp[a] * b ;
    mp[b] += mp[a];
    mp[a] = 0 ;
    cout << sum << '\n';
   }
}


Measured memory_bytes: 9940
import java.util.*;

public class Main {

    static int n;
    static int[][] d;
    static double ans = 0.0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        d = new int[n][2];
        double k = 1.0;
        for (int i = 0; i < n; i++) {
            d[i][0] = sc.nextInt();
            d[i][1] = sc.nextInt();
            k *= (i+1.0);
        }
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                ans += distance(d[i], d[j]) * (n-1) * 2 * k / n /(n-1);
            }
        }
        System.out.println(ans / k);
        sc.close();

    }
//    private static void dfs(int i, boolean[] used, double sum) {
//        used[i] = true;
//        boolean end = true;
//        for (int j = 0; j < n; j++) {
//            if(used[j]) continue;
//            end = false;
//            sum += distance(d[i], d[j]);
//            dfs(j, used, sum);
//        }
//        if(end) ans += sum;
//        used[i] = false;
//    }
    private static double distance(int[] d1, int[] d2) {
        return Math.sqrt( (d1[0]-d2[0])*(d1[0]-d2[0]) + (d1[1]-d2[1])*(d1[1]-d2[1]) );
    }

}


Measured memory_bytes: 35952
import java.util.*;
import java.io.*;

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

		if(a == b)
			System.out.println("Draw");
		else if(a == 1)
			System.out.println("Alice");
		else if(b == 1)
			System.out.println("Bob");
		else if(a > b)	
			System.out.println("Alice");
		else
			System.out.println("Bob");		
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

int main( void ){
  //それぞれのマスをTRUEとしたときに、島が一つであるか
  //島が人である場合が存在　-> YES
  int n; cin >> n;
  map<string,bool> mp;
  string s,t;
  rep(i,n){
    cin >> s >> t;
    if(s == "insert"){
      mp[t]  = true;
    }else{
      if( mp[t]) cout << "yes\n"; 
      else cout << "no\n";
    }
  }
}


Measured memory_bytes: 52560
import sys
import itertools
import bisect
import math
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
s = input()
print('Yes') if s[:n//2] == s[n//2:]and n % 2 == 0 else print('No')







Measured memory_bytes: 3060
import sys
N = int(input())
TXY = [list(map(int,input().split())) for _ in range(N)]

t0,x0,y0 = 0,0,0

for i in range(N):
    t,x,y = TXY[i][0],TXY[i][1],TXY[i][2]
    if t-t0 >= abs(x-x0)+abs(y-y0) and (t-t0)%2 == abs(x-x0+y-y0)%2:
        t0,x0,y0 = t,x,y
        continue
    else:
        print("No")
        sys.exit()

print("Yes")

Measured memory_bytes: 27380
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) ((abs((a)-(b)))<EPS)

int a[100001];
int n,l;

bool check(double f){
	double lf=l;
	double rec=0;
	bool flag=false;
	for(int j=0;j<3;j++){
		for(int i=1;i<=86400;i++){
			if(j==1&&a[i]!=0&&!flag){
				rec=lf;
				flag=true;
			}
			else if(j==2&&a[i]!=0){
				if(EQ(rec,lf))return true;
				return false;
			}
			double b=-a[i]+f;
			lf+=b;
			if(EQ(lf,0)||lf<0)return false;
			lf=min(lf,1.0*l);
		}
	}
	return true;
}

int main(){

	while(cin>>n>>l&&!(n==0&&l==0)){
		memset(a,0,sizeof(a));
		int s,t,u;
		for(int j=0;j<n;j++){
			cin>>s>>t>>u;
			for(int i=s+1;i<=t;i++)a[i]=u;
		}
		double ub=10000000;
		double lb=0;
		int cnt=80;
		while(cnt--){
			double mid=(ub+lb)/2;
			if(check(mid))ub=mid;
			else lb=mid;
		}
		printf("%.10f\n",ub);
	}
	return 0;
}

Measured memory_bytes: 1296
S = input()
HITACHI = "hi"
is_hitachi = True

if len(S)%2 == 0:
  for i in range(len(S)//2):
    if S[2*i:2*i+2] != HITACHI:
      is_hitachi = False
      break
else:
  is_hitachi = False
  
if is_hitachi:
  print("Yes")
else:
  print("No")

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

#define endl '\n'
#define LL long long
#define MP make_pair
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define FORR(i, a, b) for(int i = b - 1; i >= a; --i)
#define EB emplace_back
#define ST first
#define ND second
#define S size()
#define RS resize

using VI = vector<int>;
using VVI = vector<VI>;
using PI = pair<int, int>;
using VPI = vector<PI>;
using VVPI = vector<VPI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VB = vector<bool>;

int main()
{ 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string k;
    int d, mod = 1000000007;
    cin >> k >> d;
    int s = int(k.S);
    if (s == 1)
    {   
        int wyn = 0;
        FOR(i, 1, k[0] - '0' + 1)
            if (i % d == 0)
                wyn++;
        cout << wyn;
        return 0;
    }
    vector<VVI> dp(s);
    REP(i, s)
    {
       dp[i].RS(d);
       REP(j, d)
          dp[i][j].RS(10);
    }
    FOR(i, 0, 10)
        dp[0][i % d][i] = 1;
    FOR(i, 1, s)
        REP(j, d)
            REP(l, 10)
                REP(m, 10)
                {
                    int a = j - l;
                    while (a < 0)
                        a += d;
                    dp[i][j][l] += dp[i - 1][a][m];
                    dp[i][j][l] %= mod;
                }
    int wyn = -1;
    int akt_d = 0;
    REPR(i, s)
    {   
        int x = k[s - i - 1] - '0';
        FOR(j, 0, x)
        {   
            wyn += dp[i][akt_d][j];
            wyn %= mod;
        }
        akt_d -= k[s - i - 1] - '0';
        while (akt_d < 0)
            akt_d += d;
    }
    if (akt_d == 0)
        wyn += 1;
    wyn %= mod;
    cout << wyn;
    return 0;
}


Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
    int A,B,C,K;
    cin>>A>>B>>C>>K;
    bool a=true;
    while(a==true){
        if(K<0){
            a=false;
            cout<<"No"<<endl;
        }
        else if(B<=A){
            B*=2;
            K--;
        }
        else if(C<=B){
            C*=2;
            K--;
        }
        else{
          a=false;
            cout<<"Yes"<<endl;
        }
    }
}


Measured memory_bytes: 3588
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e10+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)


int main()
{
  
        int n,m,a,b,c;
        scf(a),scf(b),scf(c),scf(n),scf(m);

        int x=min(n,m);


        int v=min(a*x+b*x,2*c*x);

        n-=x,m-=x;
        
        v=v+min(2*c*n,n*a)+min(2*c*m,m*b);
          

          prin(v);
        

    
      

            
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

//素数判定
template <class T>
bool is_prime(T x){
	for(T i=2;i*i<=x;i++){
		if(x%i==0){
			return false;
		}
	}
	return x!=1;
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	vector<int> sum(200010,0);
	rep(i,100010){
		sum[i+1]=sum[i];
		if(i%2==0) continue;
		if(is_prime(i) && is_prime((i+1)/2)){
			sum[i+1]++;
		}
	}
	int q;
	cin>>q;
	while(q--){
		int l,r;
		cin>>l>>r;
		cout<<sum[r+1]-sum[l-1]<<endl;
	}
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	string S;
	cin >>S;
	cout <<"ABC" <<S <<endl;
	return 0;
}



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

const ll INF = 1e18;
ll dp[200005][4];

int main(){
	int n;
  	cin >> n;
  	vector<int> a(n);
  	rep(i, n) cin >> a[i];
  
  	int k = 1 + n % 2;
  	rep(i, n+1)rep(j, k+1) dp[i][j] = -INF;
  	dp[0][0] = 0;
  	
  	rep(i, n){
    	rep(j, k+1){
        	dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]);
          	ll now = dp[i][j];
          	if((i+j)%2 == 0) now += a[i];
          	dp[i+1][j] = max(dp[i+1][j], now);
        }
    }
  
  	ll ans = dp[n][k];
  	cout << ans << endl;
}


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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;cin>>n;
  double sum=0,a;
  rep(i,n){
    cin>>a;
    sum+=1/a;
  }
  cout<<1/sum<<endl;
}


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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  int ans=0;
  int count=0;
  for (int i=0;i<n;++i){
    if (s[i]=='I'){
      count++;
    }
    if (s[i]=='D'){
      count--;
    }
    ans=max(ans,count);
  }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <unordered_set>
using namespace std;
int N, M, K;
unordered_set <int> edge[200005];
int par[200005];
int size[200005];
int decrease[200005];

int fnd(int v){
    if (v == par[v]) return v;
    return par[v] = fnd(par[v]);
}

void unite(int a, int b){
    int x = fnd(a), y = fnd(b);
    if (x == y) return;
    if (size[x] >= size[y]){
        par[y] = x;
        size[x] += size[y];
    }
    else if (size[x] < size[y]){
        par[x] = y;
        size[y] += size[x];
    }
}

int main() {
    cin >> N >> M >> K;
    int a, b;
    for (int i=1; i<=N; i++) {
        par[i] = i;
        size[i] = 1;
    }
    for (int i=0; i<M; i++){
        scanf("%d %d", &a, &b);
        edge[a].insert(b);
        edge[b].insert(a);
        unite(a,b);
    }
    for (int i=0; i<K; i++){
        scanf("%d %d", &a, &b);
        if (!edge[a].count(b) && fnd(a) == fnd(b)){
            decrease[a]++;
            decrease[b]++;
        }
    }
    for (int i=1; i<=N; i++){
        printf("%d ", size[fnd(i)]-edge[i].size()-decrease[i]-1);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 23680
N, Y = map(int,input().split())
for x in range(N+1):
  for y in range(N+1):
    z = N-x-y
    if x+y+z == N and z >= 0:
      if 10000*x + 5000*y + 1000*z == Y:
        print(x,y,z,sep=" ")
        exit()
print("-1 -1 -1")

Measured memory_bytes: 3060
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  int dp[10][10][10] = {0};
  dp[0][0][0] = 1;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        if (i == 0 && j == 0 && k == 0)
          continue;
        bool b = false;
        if (i > 0)
          b |= dp[i - 1][j][k];
        if (j > 0)
          b |= dp[i][j - 1][k];
        if (k > 0)
          b |= dp[i][j][k - 1];
        if (i > 0 && j > 0)
          b |= dp[i - 1][j - 1][k];
        if (j > 0 && k > 0)
          b |= dp[i][j - 1][k - 1];
        if (i > 0 && k > 0)
          b |= dp[i - 1][j][k - 1];
        dp[i][j][k] = !b;
      }
    }
  }
  for (int i = 0; i < n; i++)
    cin >> a[i];
  bool ok = true, ok2 = true;
  for (int i = 0; i < n; i++) {
    if (a[i] % 2 == 0)
      ok = false;
    else
      ok2 = false;
  }
  if (n == 1) {
    if (a[0] % 2 == 0)
      cout << "second" << endl;
    else
      cout << "first" << endl;
    return 0;
  }
  if (n % 2 == 0) {
    if (ok2)
      cout << "second" << endl;
    else
      cout << "first" << endl;
    return 0;
  }
  if (ok || ok2) {
    cout << "second" << endl;
  } else {
    cout << "first" << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 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(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

vector<int> prime;
bool is_prime[MAX_N + 1];

int sieve(int n) {//n??\???????´???°?????°?????????
	int p = 0;
	for (int i = 0; i <= n; i++)is_prime[i] = 1;
	is_prime[0] = is_prime[1] = 0;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime.push_back(i);
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = 0;
		}
	}
	return p;
}

int n;

int main() {
	cin >> n;
	sieve(10000);
	ll ans = 0;
	rep(i, n) {
		int num;
		cin >> num;
		bool f = 1;
		rep(j, prime.size()) {
			if (num%prime[j] == 0 && num != prime[j])f = 0;
		}
		ans += f;
	}
	cout << ans << endl;
}

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


#define Reverse(v) reverse(v.begin(),v.end())
typedef long long ll;

int main(){
    ll n;
    cin>>n;
    string s="";
    while(n!=0){
        ll k=n%26;
        if(k==0) k=26;
        s+=char(96+k);
        n--;
        n/=26;
    }
    Reverse(s);
    cout<<s<<endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    int w, h; cin >> w >> h;
    if (w == 0) return;
    vector<vi32> a(h, vi32(w));
    rep(i, h) cin >> a[i];
    function<void(int, int)> dfs = [&](int x, int y) {
      a[x][y] = 0;
      for (int i = -1; i <= 1; i++)
      for (int j = -1; j <= 1; j++) {
        if (i == 0 && j == 0) continue;
        int wx = x + i, wy = y + j;
        if (wx < 0 || wx >= h || wy < 0 || wy >= w) continue;
        if (a[wx][wy] == 0) continue;
        dfs(wx, wy);
      }
    };
    int ans = 0;
    rep(i, h) rep(j, w) if (a[i][j] == 1) ans++, dfs(i, j);
    cout << ans << '\n';
  }
}



Measured memory_bytes: 3432
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

const int INF = 1001001001;
vector<int> to[100005];

int main() {
  int n, m;
  cin >> n >> m;
  rep(i,0,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  dist[0] = 0;
  q.push(0);
  while (!q.empty()) {
    int v = q.front(); 
    q.pop();
    for (int u : to[v]) {
      if (dist[u] != INF) continue;
      dist[u] = dist[v]+1; //子の属する層を求める(親の属する層+1)
      pre[u] = v; //親の部屋番号
      q.push(u); //子の部屋を次に探索
    }
  }

  cout << "Yes" << endl;
  rep(i,0,n) {
    if (i == 0) continue;
    int ans = pre[i];
    ++ans;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 10208
#include <bits/stdc++.h>
using namespace std;
///https://www.youtube.com/watch?v=-tJYN-eG1zk&list=RD-tJYN-eG1zk&start_radio=1
const int MOD = 1e9 + 7;
#define ll long long int
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define vi vector<int>
#define vpii vector<pii>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue<int>
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
const int MXX = 1e5 + 5;

//int a[MXX], b[MXX], c[MXX];
int main()
{

    FAST_IO;
    int n;cin>>n;
    vi v;
    int x;
    for(int i = 0; i<n-1; i++)
    {
        cin>>x;
        if(i == 0)v.pb(x);
        v.pb(x);
    }
    v.pb(x);
    int ans = 0;
    for(int i = 0; i<v.size()-1; i++)
    {
        ans+=min(v[i], v[i+1]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 50;
int main() {
	int N, M; cin >> N >> M;
	const int NMAX = 1000, MMAX = 2000;
	int a[MMAX], b[MMAX];
	ll c[MMAX];
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i] >> c[i];
		c[i] = -c[i];
	}
	ll dist[N];
	for (int i = 0; i < N; i++) dist[i] = INF;
	dist[0] = 0;
	for (int loop = 0; loop < N - 1; loop++) {
		for (int i = 0; i < M; i++) {
			if (dist[a[i] - 1] == INF) continue;
			if (dist[a[i] - 1] + c[i] < dist[b[i] - 1]) dist[b[i] - 1] = dist[a[i] - 1] + c[i];
		}
	}
	ll ans = dist[N - 1];
	bool negative[NMAX];
	for (int i = 0; i < N; i++) negative[i] = false;
	for (int loop = 0; loop < N; loop++) {
		for (int i = 0; i < M; i++) {
			if (dist[a[i] - 1] == INF) continue;
			if (dist[a[i] - 1] + c[i] < dist[b[i] - 1]){
				dist[b[i] - 1] = dist[a[i] - 1] + c[i];
				negative[b[i] - 1] = true;
			}
			if (negative[a[i] - 1]) negative[b[i] - 1] = true;
		}
	}
	if (negative[N - 1]) cout << "inf" << endl;
	else {
		cout << -ans << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int A,B,K;
    int c;
    int i;
    int count = 0;
    scanf("%d %d %d", &A, &B, &K);
    
    for(i=B; count < K ; i--){
        if(A%i == 0 && B%i == 0){    
                count ++;
                c = i;
        }
    }
    printf("%d\n", c);

    return 0;

}

Measured memory_bytes: 128
use proconio::input;

fn main() {
    input! {
        n : usize,
        a : [usize; n]
    };
    let mut cnt = vec![0; n];
    let mut res : u64 = 0;
    for i in (0..n).rev() {
        let idx = a[i] + i;
        if idx < n { res += cnt[idx]; }
        if i >= a[i] { cnt[i - a[i]] += 1; }
    }
    println!("{}", res);
}


Measured memory_bytes: 6684
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val s: String = sc.next()
    val (zero, one) = s.partition(_.toString == "0")
    println(Array(zero.length, one.length).min * 2)
  }
}


Measured memory_bytes: 39700
import heapq

n, m = map(int, input().strip().split())
heap = list(map(lambda a: -int(a), input().strip().split()))

heapq.heapify(heap)

for i in range(m):
    highest = heap[0]
    heapq.heapreplace(heap, highest / 2.0)

ans = -sum(map(int, heap))
print(ans)


Measured memory_bytes: 14180
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b && b == c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int a,b,c;
  cin  >> a >> b >> c;
  if (b / a  <= c){
    cout << b / a << '\n';
  }
  else{
    cout << c << '\n';
  }
  return 0; 
}

Measured memory_bytes: 384