akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	s := getNextInt(scanner)
	var ans mint
	mc := newModcom(s << 1)
	for i := 1; i*3 <= s; i++ {
		ss := s - 3*i
		ans.AddAs(mc.Choose(ss+i-1, i-1))
	}
	fmt.Fprintln(writer, ans)

}

type modcom struct {
	Facs, Invs []mint
}

func newModcom(n int) modcom {
	facs := make([]mint, n+1)
	invs := make([]mint, n+1)
	facs[0] = 1
	for i := 0; i < n; i++ {
		facs[i+1] = facs[i].Mul(mint(i + 1))
	}
	invs[n] = facs[n].Inv()
	for i := n - 1; i >= 0; i-- {
		invs[i] = invs[i+1].Mul(mint(i + 1))
	}
	return modcom{
		Facs: facs,
		Invs: invs,
	}
}
func (mc *modcom) Choose(n, k int) mint {
	return mc.Facs[n].Mul(mc.Invs[k]).Mul(mc.Invs[n-k])
}

type mint int64

func (mt mint) Mod() mint {
	m := mint(1e9 + 7)
	mt %= m
	if mt < 0 {
		return mt + m
	}
	return mt
}
func (mt mint) Inv() mint {
	return mt.Pow(mint(0).Sub(2))
}
func (mt mint) Pow(n mint) mint {
	p := mint(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(mt)
		}
		mt.MulAs(mt)
		n >>= 1
	}
	return p
}
func (mt mint) Add(x mint) mint {
	return (mt + x).Mod()
}
func (mt mint) Sub(x mint) mint {
	return (mt - x).Mod()
}
func (mt mint) Mul(x mint) mint {
	return (mt * x).Mod()
}
func (mt mint) Div(x mint) mint {
	return mt.Mul(x.Inv())
}
func (mt *mint) AddAs(x mint) *mint {
	*mt = mt.Add(x)
	return mt
}
func (mt *mint) SubAs(x mint) *mint {
	*mt = mt.Sub(x)
	return mt
}
func (mt *mint) MulAs(x mint) *mint {
	*mt = mt.Mul(x)
	return mt
}
func (mt *mint) DivAs(x mint) *mint {
	*mt = mt.Div(x)
	return mt
}


Measured memory_bytes: 1872
def checknum(i)
  if i % 3 == 0
    return i
  end
  include3(i)
end

def include3(i, x = nil)
  x = i unless x
  if x % 10 == 3
    return i
  end
  if x / 10 != 0
    return include3(i, x / 10)
  end
end

def call
  n = gets.to_i
  puts (1..n).map { |i| checknum(i) }.compact.map { |i| " #{i}" }.join
end

call

Measured memory_bytes: 6296
#include <iostream>
#include <set>

using namespace std;

typedef long long ll;

int main(){
    int N;
    scanf("%d",&N);
    set<ll> st;
    ll n;
    bool flag=true;
    for(int i=0;i!=N;++i){
        cin>>n;
        st.insert(n);
        if(st.size()!=i+1){
            flag=false;
            break;
        }
    }
    if(flag){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int bigint;

const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

struct BIT2d{
	int ymx, xmx;
	vector<vector<int>> dt;
	BIT2d(int my, int mx): ymx(my), xmx(mx), dt(my+5,(vector<int>(mx+5))){};
	void add(int y, int x, int v){
		for(int i = y; i <= ymx; i += i & -i)
			for(int j = x; j <= xmx; j += j & -j) dt[i][j] += v;
	}
	int qsum(int y, int x){
		int res = 0;
		for(int i = y; i > 0; i -= i & -i)
			for(int j = x; j > 0; j -= j & -j) res += dt[i][j];
		return res;
	}
	int qsum(int y0, int x0, int y1, int x1){
		return qsum(y1, x1) - qsum(y0-1, x1) - qsum(y1, x0-1) + qsum(y0-1, x0-1);
	}
};


int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n,m,q;
	cin >>n >>m >>q;
	
	vector<int> l(m), r(m), s(q), t(q);
	
	rep(i,m) cin >>l[i] >> r[i];
	rep(i,q) cin >>s[i] >> t[i];
	
		
	BIT2d bt(n, n);
	rep(i,m) bt.add(l[i], r[i], 1);
		
	rep(i, q){
		int w = bt.qsum(s[i], s[i], t[i], t[i]);
		cout << w <<"\n";
	}
	
	return 0;
}


Measured memory_bytes: 4352
#####

import numpy as np
from numpy import newaxis, float32, float64, int32, int64, int16, int8, uint8, uint32, complex64, complex128

#####

def getIntList(inp):
	return [int(_) for _ in inp]
	

from sys import stdin

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs


def m(t0,x0,y0,t1,x1,y1):
	d=abs(x1-x0)+abs(y1-y0)
	dt=t1-t0
	if d>dt: return False
	dd=d-dt
	return dd%2==0


def main(inputs):
	n=int(inputs[0][0])
	print(int(np.ceil(n/2)))
	

if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)
	


Measured memory_bytes: 21544
import java.util.*;


class Guidebook implements Comparable<Guidebook>{
    public int a;
    public String b;
    public int c;
    public  Guidebook(int a, String b, int c){
        this.a = a;
        this.b = b;
        this.c = c;
    }
    public int compareTo(Guidebook all){
        int answer = b.compareTo(all.b);
        if(answer!=0){
            return answer;
        }
        return Integer.compare(all.c, c);
    }
}


public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
        String b[] = new String[a];
        int c[] = new int[a];
      
        for(int i = 0;i < a;i++){
          b[i] = sc.next();
          c[i] = sc.nextInt();
        }
      
        List <Guidebook> list = new ArrayList<Guidebook>();
        
        for(int i = 0;i < a;i++){
          list.add(new Guidebook(i+1,b[i],c[i]));
        }
        Collections.sort(list);
      for (Guidebook book: list) {
        System.out.println(book.a);
      }
    }
}


Measured memory_bytes: 35992
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;
const int MOD = 1000000007;
const int INF = 1LL << 30;

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

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


int main(int argc, char**argv){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0;  i < n; i++){
        cin >> h[i];
    }

    vector<int> dp(n, INF);
    dp[0] = 0;

    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            if (i - j < 0) continue;
            chmin(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    cout << dp[n-1] << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF 999999999
using namespace std;
int f[1005][1005];
int fa[305];
int ss[1005];
int v[1005];

int ji = 0;
//struct A
//{
//    int x;
//    int y;
//    int w;
//};
//A a[305];
//int cmp(A a, A b)
//{
//    return a.w < b.w;
//}
//int finds(int a)
//{
//    return fa[a] == a?a:fa[a] = finds(fa[a]);
//}

int main()
{
    int n, m, r;
    scanf("%d%d%d", &n, &m, &r);

    for(int i = 0; i < r; i++)
    {
        scanf("%d", &ss[i]);
    }
    sort(ss, ss+r);
    for(int i = 1; i <= n; i++)
    for(int j = 1; j <= n; j++)
    if(i == j)f[i][j] = 0;
    else f[i][j] = INF;
    for(int i = 0; i < m; i++)
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        if(c < f[a][b])
        {
            f[a][b] = c;
            f[b][a] = c;
        }
    }
    for(int k = 1; k <= n; k++)
    for(int i = 1; i <= n; i++)
    for(int j = 1; j <= n; j++)
    {
        f[i][j] = min(f[i][j], f[i][k]+f[k][j]);
    }
//    for(int i = 1; i <= 205; i++)
//    fa[i] = i;
//    for(int i = 0; i < ji; i++)
//    {
//        int x = finds(a[i].x);
//        int y = finds(a[i].y);
//        if(fa[x] != y)
//        {
//            fa[x] = y;
//            sum += a[i].w;
//        }
//    }
    long long mins = INF;
    do
    {
        long long sum = 0;
        for(int i = 1; i < r; i++)
        sum += f[ss[i]][ss[i-1]];
        mins = min(mins, sum);

    }while(next_permutation(ss, ss+r));
    printf("%lld\n", mins);
    return 0;
}


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

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

	long double pi = 3.14159265358979323846;
	long double r;
	cin >> r;
	cout << 2*r*pi << endl;

	return 0;
}


Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
     if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int M=600002,N=M+2,mod=1e9+7;
const ll mod2=(ll)mod*mod*7;
ll fac[N],ni[N];
ll ksm(ll a,int b){
	int ans=1;
	for(;b;b>>=1){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
	}
	return ans;
}
ll c(int a,int b){
	return b>=0&&a>=b?fac[a]*ni[b]%mod*ni[a-b]%mod:0;
}
ll C(int a,int b){
	return (b&1)?mod-c(a,b):c(a,b);
}
int solve(int n,int m,int x){
	ll ans=0;
	For(i,1,x/m){
		For(j,0,(x-i*m)/i){
			int sy=x-i*m-j*i;
			ans+=C(n-m,j)*c(sy+n,n);
			if(ans>=mod2)ans-=mod2;
		}
		if(i>1)For(j,0,(x-i*m)/(i-1)){
			int sy=x-i*m-j*(i-1);
			ans-=C(n-m,j)*c(sy+n,n);
			if(ans<0)ans+=mod2;
		}
	}
	ans%=mod; 
	ans=(c(x+n,n)-ans*c(n,m)%mod+mod)%mod;
	return ans;
}
int main(){
	For(i,fac[0]=1,M)fac[i]=fac[i-1]*i%mod;
	ni[M]=ksm(fac[M],mod-2);
	Rep(i,M,1)ni[i-1]=ni[i]*i%mod;
	int n=read(),m=read(),l=read(),r=read();
	writeln((solve(n,m,r)-solve(n,m,l-1)+mod)%mod);
}

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

using namespace std;
const long long INF = 1LL <<60;

int main(void){
  long long N,W;
  cin>>N>>W;
  long long w[N+1],v[N+1];
  long i,j,k;
  long long dp[N+1][W+1];
  
  for(j=0;j<=W;j++){
    dp[0][j]=0;
  }
  
  for(i=0;i<N;i++){
    cin>>w[i]>>v[i];
    dp[i][0]=0;
    for(j=1;j<w[i];j++){
      dp[i+1][j]=dp[i][j];
      //cout<<dp[i][j]<<" ";
    }
    for(j=w[i];j<=W;j++){
      dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
      //cout<<dp[i][j]<<" ";
      //cout<<i<<" "<<j<<" ";
    }
    //cout<<endl;
  }
  cout<<dp[N][W]<<endl;
  return 0;
}

Measured memory_bytes: 79104
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string n;
	cin >> n;
	int x = n.size();
	for (int i = 0; i < x; i++) {
		if (n[i] == '1')n[i] = '9';
		else n[i] = '1';
	}
	cout << n << endl;
	return 0;
}

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

# https://qiita.com/snow67675476/items/e87ddb9285e27ea555f8
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    if n == 1:
      return []
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

import fractions

print(len(factorization(fractions.gcd(a, b)))+1)


Measured memory_bytes: 5176
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin >> a;
  a.pop_back();
  int aa = a.size();
  for(int i = 0;i< aa;i++){
    int key = 0;
    if(a.size() == 1){
      cout << 1 << endl;
    }
    else if(a.size()%2 == 1){
      a.pop_back();
    }
    else{
      for(int j = 0;j< a.size()/2;j++){
      	if(a.at(j) != a.at((a.size()/2) + j)){
          key = 1;
        }
      }
      if(key == 0){
        cout << a.size() << endl;
        break;
      }
      a.pop_back();  
    }
  }
}
     


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    sc.close();
    long now = 0;
    for (long i=1;i<=x;i++){
      now += i;
      if (now >= x){
        System.out.println(i);
        break;
      }
    }
  }
}

Measured memory_bytes: 23888
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int nextd[64][200010];
int A[400010];
vector<int> v[200010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    
    rep(i, N) cin >> A[i];
    rep(i, N) A[N + i] = A[i];
    rep(i, N * 2) {
        v[A[i]].push_back(i);
    }
    rep(i, 60) rep(j, 200010) nextd[i][j] = INF2;
    // rep(i, N) {
    //     cout << i + 1 << ": ";
    //     rep(j, v[i + 1].size()) {
    //         cout << v[i + 1][j] << " ";
    //     }
    //     cout << endl;
    // }
    rep(i, N) {
        auto head = lower_bound(v[A[i]].begin(), v[A[i]].end(), i);
        auto nxt = head;
        ++nxt;
        //cout << *head << " " << *nxt << endl;
        nextd[0][i] = *nxt - *head + 1;
    }
    rep(i, 59) {
        rep(j, N) {
            if (nextd[i][j] != INF2){
                int nxt = j;
                nxt += nextd[i][nxt];
                nxt += nextd[i][nxt % N];
                if (nxt - j <= N * K)
                    nextd[i + 1][j] = nxt - j;
            }
        }
    }

    int now = 0;
    while(true) {
        int nxt = now;
        rep(i, 60) {
            if (now + nextd[i][now % N] <= N * K) {
                nxt = now + nextd[i][now % N];
            } else {
                break;
            }
        }
        if (nxt == now) break;
        now = nxt;
        //cout << now << " " << now % N << " "<< N * K - now << endl;
    }
    int s = now % N;
    int c = N * K - now;
    int cnt[200010] = {};
    vector<int> v2;
    rep(i, c) {
        if (cnt[A[(s + i) % N]] == 0) {
            cnt[A[(s + i) % N]]++;
            v2.push_back(A[(s + i) % N]);
        }
        else {
            while (cnt[A[(s + i) % N]] > 0) {
                cnt[v2[v2.size() - 1]]--;
                v2.pop_back();
            }
        }
    }
    rep(i, v2.size()) {
        cout << v2[i] << " ";
    }
    cout << endl;
    



    return 0;
}


Measured memory_bytes: 113396
import sys
input = sys.stdin.readline

n,m,r= map(int, input().split())
rr= list(map(int, input().split()))
a= [list(map(int, input().split())) for i in range(m)]
d=[[float('inf')]*n for i in range(n)]
for i in range(n):
    d[i][i]=0

for i,j,k in a:
    i-=1
    j-=1
    d[i][j]=k
    d[j][i]=k


# ワーシャルフロイド　全点最短経路、負の距離あっても可　o(n**3)
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])

    return d
d=warshall_floyd(d)


# bit DP
# dp[S][v]: 訪れた点の集合がSで最後にVを訪れた時のVのMIN
INF=float('inf')
dp=[[INF]*r for i in range(1<<r)]
dp[0]=[0]*r

for i in range(1<<r):
    for k in range(r):
        # 訪問リストに入っているものを最後に訪問する時
        if (i >> k) & 1:
            if i^(1<<k)==0:
                dp[i][k]=0
            else:
                # 最後に訪れるものを除いた集合でどこを最後に訪問した時がminか調べる
                for l in range(r):
                    if (i ^ (1 << k))>>l:
                        dpm = dp[i ^ (1 << k)][l]
                        ad = d[rr[l] - 1][ rr[k] - 1]
                        dp[i][k] = min(dpm + ad, dp[i][k])

print(min(dp[-1]))

Measured memory_bytes: 59100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,w,wei[102],val[102],visit[100002][102];

ll dp(ll pos, ll we)
{
    ll j,p,q;
    if(pos==n)return 0;
    if(visit[we][pos]!=-1)return visit[we][pos];
    p=q=0;
    if(we+wei[pos]<=w)p=val[pos]+dp(pos+1,wei[pos]+we);
    q=dp(pos+1,we);
    return visit[we][pos]=max(p,q);
}

int main()
{
    ll i,ans;
    scanf("%lld %lld",&n,&w);
    for(i=0; i<n; i++)scanf("%lld %lld",&wei[i],&val[i]);
    memset(visit,-1,sizeof(visit));
    ans=dp(0,0);
    printf("%lld\n",ans);
    return 0;
}


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

int main()
{
	int a , b, c, i, j;

	cin >> a >> b >> c;

	i = 0;

	for(j = a;j < b + 1;j++)
	{
		if (c % a == 0)
		{
			i++;
		}
		a++;
	}

if(a == 0 && b == 0)
{
	cout << 0 << endl;
}
else
{
	cout << i  << endl;
}
	return 0;
}


Measured memory_bytes: 3108
#include<iostream>
#include<string.h>
using namespace std;
long long sin[100001];
int main(){
	while(1){
	memset(sin,0,sizeof(sin));
	long n,k;
	int i,j,max=0,x;
		cin>>n>>k;if(n==0&&k==0)break;
	for(i=1;i<=n;i++){
		cin>>sin[i];
	}
	x=0;
	for(j=1;j<=k;j++){
		x+=sin[j];
	}
		for(i=k+1;i<=n;i++){
			x+=sin[i];
			x-=sin[i-k];
			if(x>max)max=x;
		}
		cout<<max<<endl;
	}
	return 0;
}

Measured memory_bytes: 3856
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

bool isprime(int n) {
    if (n % 2 == 0 && n != 2) return false;
    for (int i = 3; i <= sqrt(n); i += 2) {
        if (n % i == 0) return false;
    }
    if (n == 1) return false;
    return true;
}

int main() {
    int N;
    cin >> N;
    int x = N, ans = N;
    if (x % 2 == 0) {
        while (x % 2 == 0) {
            x /= 2;
        }
        ans /= 2;
    }
    for (int i = 3; i <= sqrt(N); i += 2) {
        if (x % i == 0 && isprime(i)) {
            while (x % i == 0) {
                x /= i;
            }
            ans *= (1 - (double)1 / i);
        }
    }
    if (isprime(x)) ans *= (1 - (double)1 / x);
    cout << ans << endl;
    return 0;
}


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

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

bool istop[100];
int position[100];
void init() {}

bool solve() {
    int N;
    cin >> N;
    int i, j;
    cin >> i >> j;
    if (N == 0) return false;
    // i--, j--;
    int m = N;
    int pos = i;
    while (m) {
        if (i <= (1LL << (m - 1))) {
            position[m - 1] = (1LL << (m - 1)) - i + 1;
            istop[m - 1] = true;
        } else {
            position[m - 1] = i - (1LL << (m - 1));
            istop[m - 1] = false;
        }
        i = position[m - 1];
        m--;
    }
    string ans;
    REP(i, N) {
        int sum = 1LL << (N - i);
        if (istop[i]) {
            if (j <= sum / 2) {
                ans += 'L';
                j = sum / 2 - j + 1;
            } else {
                ans += 'R';
                j = sum - j + 1;
            }
        } else {
            if (j <= sum / 2) {
                ans += 'R';
                // j = sum / 2 - j + 1;
            } else {
                ans += 'L';
                j = j - sum / 2;
            }
        }
    }
    cout << ans << endl;
    return true;
}
signed main() {
    init();
    while (solve())
        ;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

const int MAX_N = 1001;
bool dp[MAX_N][MAX_N];
int dp2[MAX_N];

int main()
{
    ios::sync_with_stdio(false);

    int N;
    while (cin >> N, N) {
        vector<int> W(N);
        rep(i, N) cin >> W[i];

        memset(dp, 0, sizeof(dp));
        memset(dp2, 0, sizeof(dp2));

        for (int i=0; i<N-1; i++) {
            if (abs(W[i] - W[i+1]) <= 1) {
                dp[i][i+1] = true;
            }
        }

        for (int len=2; len<=N; len += 2) {
            for (int l=0; l<=N-len; l++) {
                int r = l + len - 1;

                for (int k=2; k<=len-2; k+=2) {
                    if (dp[l][l+k-1] && dp[l+k][r]) dp[l][r] = true;
                }


                if (!dp[l][r]) continue;
                if (0 <= l-1 && r+1 < N && abs(W[l-1] - W[r+1]) <= 1) {
                    dp[l-1][r+1] = true;
                }
            }
        }

#ifdef DEBUG
        rep(i, N) {
            rep(j, N) {
                cerr << "xo"[dp[i][j]] << " ";
            }
            cerr << endl;
        }
#endif

        for (int r=1; r<=N; r++) {
            dp2[r] = max(dp2[r], dp2[r-1]);
            for (int l=0; l<r; l++) {
                if (dp[l][r-1]) {
                    int len = r - l;
                    dp2[r] = max(dp2[r], dp2[l] + len);
                }
            }
        }

#ifdef DEBUG
        rep(i, N+1) cerr << dp2[i] << " ";
        cerr << endl;
#endif

        cout << dp2[N] << endl;
    }
}

Measured memory_bytes: 4128
#include <bits/stdc++.h>
#define lp(n) for(int i = 0; i < n; i++)
#define lpp(i,n) for(int i = 0; i < n; i++)
int n;
int g[101][103];
void dfs(int v);
using namespace std;
int t = 0;
int main(){
  int u,k,v;
  cin >> n;
  lp(n) {
    cin >> u >> k;
    lpp(j,k) {
      cin >> v;
      g[u][v] = 1;
    }
  }
  int y = 1;
  while(y != 0){
    dfs(y);
    y = 0;
    lp(n) {
      if(g[0][i+1] == 0) {
	y = i+1;
	break;
      }
    }
  }
  lp(n) cout << i+1 << " " << g[i+1][101] << " " << g[i+1][102] << endl;
  return 0;
}
void dfs(int v) {
  g[0][v] = 1;
  g[v][101] = ++t;
  lp(n){
    if(g[v][i+1] == 1 && g[0][i+1] == 0){
      dfs(i+1);
    }
  }
  g[v][102] = ++t;
  /*
  int v;
  int t = 1;
  vector<int> st;
  int *visited = g[0];
  v = 1;
  visited[v] = 1;
  st.push_back(v);
  g[v][101] = t;
  while(!st.empty()) {
    lp(st.size()) cout << st[i]<<" ";cout<<endl;
    v = st.front();
    st.pop_back();
    lp(100) {
      if(g[v][i+1] == 1) {
	if(visited[i+1] == 0) {
	  visited[i+1] = 1;
	  st.push_back(i+1);
	  g[i+1][101] = ++t;
	}
      }
    }
    }*/
}



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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  vll a(3); rep(i, 3) cin >> a[i];
  map<ll, ll> ans;
  rep(i, 3) if(!ans.count(a[i])) ans[a[i]]++;
  fin(ans.size())
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
int main(){
  ll n,m; cin >> n >> m;
  if(m==0){
    if(n==1){
      std::cout << 0;
      return 0;
    }
    string ans0="1";
    rep(i,n-1){
      ans0.append("0");
    }
    std::cout << ans0;
    return 0;
  }
  vector<ll> v(n,-1);
  rep(i,m){
    ll s,c; cin >> s >> c;
    if((s==1&&c==0&&n!=1)||(v[s-1]!=-1&&v[s-1]!=c)){
      std::cout << -1;
      return 0;
    }
    v[s-1]=c;
  }

  string ans;
  rep(i,n){
    if(v[i]==-1){
      if(i==0) ans+="1";
      else ans+="0";
      continue;
    }
    ans.append(to_string(v[i]));
  }
  std::cout << stoi(ans);
  return 0;
}
// 1 2 3 4 5 6 7 8 9


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

const ll MX = 1e18;
const long double PI = acos(-1);

int main()
{
    int n, q;
    cin >> n;
    vector<int> a(100005);
    ll ans = 0;
    rep(i,n)
    {
        int num;
        cin >> num;
        ans += num;
        a[num] += 1;
    }
        cin >> q;
    
    rep(i,q)
    {
        int b,c; cin >> b >> c;
        if(a[b] != 0)
        {
            a[c] += a[b];
            ans += a[b]*(c-b);
            a[b] = 0;
        }
    
        pri(ans);
    }
    return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
#include <string.h>
int main()
{
  int comp,tim,i,ptim=0,tima[50000],end=0,endc=0,timb[50000],count=0,flag=0;
  char p1[10],pa[50000][10],pb[50000][10];
  scanf("%d%d",&comp,&tim);
  endc=comp;
  //データの格納
  for(i=0;i<comp;i++)
    {
      scanf("%s%d",pa[i],&tima[i]);
    }
   
  //処理
  while(comp/2>end)
    {
      //残りプロセスが半分以上の場合	
	  for(i=0;i<comp;i++)
	    {
	      //計算  
	      //完了したプロセスの場合
	      if(tima[i] == -1);
	      //プロセスが完了した場合
	      else if((tima[i]-tim) <= 0)
		{
		  ptim += tima[i]; 
		  printf("%s %d\n",pa[i],ptim);
		  tima[i]= -1;
		  end++;
		}
	      //プロセスが完了しなかった場合
	      else if((tima[i]-tim) > 0)
		{
		  tima[i] -=  tim;
		  ptim += tim;	 
		}
	    }
    }
      
  //残りプロセスが半分以下の場合
  //完了したプロセスを消去する。
  for(i=0;i<comp;i++)
    {
      if(tima[i] != -1)
	{
	  timb[count]=tima[i];
	  strcpy(pb[count],pa[i]);
	  count++;
	}
    }

  while(endc!=end)
    {
      for(i=0;i<count;i++)
	{
	  //計算  
	  //完了したプロセスの場合
	  if(timb[i] == -1);
	  //プロセスが完了した場合
	  else if((timb[i]-tim) <= 0)
	    {
	      ptim += timb[i]; 
	      printf("%s %d\n",pb[i],ptim);
	      timb[i]= -1;
	      end++;
	    }
	  //プロセスが完了しなかった場合
	  else if((timb[i]-tim) > 0)
	    {
	      timb[i] -=  tim;
	      ptim += tim;	 
	    }
	}
   
    }  
  return 0;
}




Measured memory_bytes: 2632
# AOJ 0117 A reward for a Carpenter
# Python3 2018.6.21 bal4u

INF = 0x7fffffff

import heapq
def dijkstra(V, to, start, goal):
	dist = [INF]*V
	Q = []
	dist[start] = 0
	heapq.heappush(Q, (0, start))
	while len(Q):
		t, s = heapq.heappop(Q)
		if s == goal: break
		if dist[s] < t: continue
		for i in to[s]:
			e, cost = i
			nt = t + cost
			if dist[e] > nt:
				dist[e] = nt
				heapq.heappush(Q, (nt, e))
	return dist[goal]

n = int(input())+1
to = [[] for i in range(n)]
for i in range(int(input())):
	a, b, c, d = list(map(int, input().split(',')))
	to[a].append((b, c))
	to[b].append((a, d))
s, g, V, P = list(map(int, input().split(',')))
if s == g: print(V-P)
else: print(V-P - dijkstra(n, to, s, g) - dijkstra(n, to, g, s))


Measured memory_bytes: 5668
# AtCoder Beg Contest 042 A (100)
a, b, c = map(int, input().split())
if a > b:
    a, b = b, a
if b > c:
    c, b = b, c
if a == 5 and b == 5 and c == 7:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
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; }

using Lint=long long;

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

    int N; cin>>N;
    vector<int> x(N),y(N);
    for(int i=0;i<N;i++) cin>>x[i]>>y[i];

    double ans=0;
    for(int i=0;i<N;i++) for(int j=0;j<N;j++) if(i!=j){
        double dx=x[i]-x[j];
        double dy=y[i]-y[j];
        ans+=hypot(dx,dy);
    }
    ans/=N;
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}

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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = int.Parse(Console.ReadLine());
        long[] a = new long[n];
        long[] b = new long[n];

        for (int i = 0; i < n; i++)
        {
            int[] tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            a[i] = tmp[0];
            b[i] = tmp[1];
        }

        var t = 0L;
        var ans = 0L;
        for (int i = n - 1; i >= 0; i--)
        {
            t = (ans + a[i]) % b[i];
            if (t != 0) t = b[i] - t;
            ans += t;
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 48244
#include<bits/stdc++.h>
const int N=1e6+5,mo=1e9+7;
int n,h,d,fac[N],i,f[N],s,ss,ans;
int main(){
	scanf("%d%d%d",&n,&h,&d);
	for(i=*fac=1;i<=n;++i)fac[i]=1ll*i*fac[i-1]%mo,ss=(ss+fac[i])%mo;
	for(i=1,*f=s=fac[n];i<=h;++i){
		if(i>d)s=(s+mo-f[i-d-1])%mo;
		f[i]=i==h?s:1ll*ss*s%mo,s=(s+f[i])%mo;
	}
	printf("%d\n",f[h]);
	return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
int main(){
   int a,b;
   int i;
   scanf("%d%d",&a,&b);
   if(a>b){
      for(i=0;i<a;i++){
         printf("%d",b);
      }
   }else{
      for(i=0;i<b;i++){
         printf("%d",a);
      }
   }
   return 0;
}

Measured memory_bytes: 3212
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>QUE;//きゅー
int main(void)
{
	char S[100010];
	ll K;
	scanf("%s%lld", S, &K);
	char max;
	ll int i = 0;
	while (true) {
		if (S[i] != '1') {
			max = S[i];
			break;
		}
		i++;
	}
	if (K >= i+1) {
		printf("%c", max);
		return 0;
	}
	printf("1");
	
}


Measured memory_bytes: 256
import heapq
import math

n, m = map(int, input().split())
a = []
for i in input().split():
    a.append(-1 * int(i))
heapq.heapify(a)
for _ in range(m):
    b = heapq.heappop(a)
    heapq.heappush(a, math.ceil(b / 2))
print(-1 * sum(a))

Measured memory_bytes: 97944
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

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

	int* A = new int[M];
	int* B = new int[M];

	for (int i = 0; i < M; i++) {
		int b; cin >> A[i] >> b;
		B[i] = 0;
		for (int j = 0; j < b; j++) {
			int c; cin >> c; c--;
			B[i] += (1 << c);
		}
	}

	map<int, int> mp;
	mp.insert(make_pair(0, 0));

	for (int i = 0; i < M; i++) {
		map<int, int>mp2;
		for (auto itr = mp.begin(); itr != mp.end(); itr++) {
			mp2.insert(make_pair(itr->first, itr->second));
		}
		for (auto itr = mp.begin(); itr != mp.end(); itr++) {
			int x = itr->first | B[i];
			if (mp2.find(x) == mp2.end()) {
				mp2.insert(make_pair(x, itr->second + A[i]));
			}
			else {
				mp2[x] = min(mp2[x], itr->second + A[i]);
			}
		}
		mp.clear();
		for (auto itr = mp2.begin(); itr != mp2.end(); itr++) {
			mp.insert(*itr);
		}
		mp2.clear();
	}
	int k = 0;
	for (int i = 0; i < N; i++) {
		k += (1 << i);
	}

	if (mp.find(k) == mp.end()) {
		cout << -1 << endl;
	}
	else {
		cout << mp[k] << endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include <iostream>

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

  for (int i = 1; i < b; i++) {
    if ((a*i)%b == c) {
      std::cout << "YES" << std::endl;
      return 0;
    }
  }
  std::cout << "NO" << std::endl;

  return 0;
}

Measured memory_bytes: 256
using System;
namespace AT
{
  class A
  {
    static void Main()
    {
      var read = Console.ReadLine();
      string[] readline = read.Split(' ');
      int a=int.Parse(readline[0]);
      int b=int.Parse(readline[1]);
      int ans=MAX(a,b);
      Console.WriteLine(ans);
    }
    static int MAX(int a,int b)
    {
      int p=a+b;
      int x =a*b;
      int m = a-b;
      if(p>=x && p>=m)
      {
        return p;
      }
      else if(x>=p && x>=m)
      {
        return x;
      } 
      else
      {
        return m;
      }
    }
  }
}

Measured memory_bytes: 27424
#include<bits/stdc++.h>
using namespace std;
namespace io{
    const int l=1<<20;
    char buf[l],*s,*t,c;
    inline void gc(){
        if(s==t){
            t=(s=buf)+fread(buf,1,l,stdin);
            c=s==t?EOF:*s++;
        }else c=*s++;
    }
    template<class IT>inline void gi(IT &x){
        x=0;gc();while(c<'0'||c>'9')gc();
        while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);gc();}
    }
    char buf0[20];int a;
    template<class IT>inline void pi(IT x){
        if(x<0){putchar('-');x=-x;}
        do buf0[++a]=x%10+48;while(x/=10);
        while(a)putchar(buf0[a--]);
        putchar('\n');
    }
};
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
#define pque priority_queue
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
map<string,int>a;string b[200005];
int main(){
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n,m=0,t=0;string s;
	cin>>n;
	while(n--){cin>>s;cmax(m,++a[s]);}
	for(map<string,int>::iterator it=a.begin();it!=a.end();++it)if((*it).se==m)b[++t]=(*it).fi;
	sort(b+1,b+t+1);
	rep(m,1,t)cout<<b[m]<<endl;
    return 0;
}

Measured memory_bytes: 27776
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
typedef long long i64;
inline i64 Powlog(i64 a, i64 b, i64 MOD) {
    i64 res(1);
    while (b) {
        if (b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}
inline bool Prim(i64 n) {
    if (n < 2) return false;
    if (n == 2 || n == 3 || n == 5) return true;
    if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0) return false;
    i64 d(n - 1);
    while (d % 2 == 0)
        d >>= 1;
    for (int i = 1; i <= 1; ++i) {
        bool ch(true);
        i64 a = 2 + rand() % (n - 4), temp(d);
        i64 x = Powlog(a, temp, n);
        if (x == 1 || x == n - 1)
            continue;
        while (temp != n - 1) {
            x = (x * x) % n;
            temp <<= 1;
            if (x == 1)
                return false;
            if (x == n - 1) {
                ch = false;
                break;
            }
        }
        if (ch) return false;
    }
    return true;
}
int n;
int main() {
    DAU
    cin >> n;
    while (true) {
        if (Prim(n)) {
            cout << n;
            PLEC
        }
        ++n;
    }
    PLEC
}


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

int main()
{
	long long W, H, x, y;
	cin >> W >> H >> x >> y;
	cout << setprecision(6) << fixed << W * H / 2.0;
	if (x*2 == W && y*2 == H)
		cout << " 1\n";
	else
		cout << " 0\n";
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    if (N & 1)
    {
        writeln(0);
        return;
    }
    long x = 10;
    long ans;
    while (x <= N)
    {
        ans += N / x;
        x *= 5;
    }
    writeln(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll x, y;
  cin >> x >> y;
  cout << (y%2==0 and 2*x<=y and y<=4*x ? "Yes" : "No") << newl;
  return 0;
}


Measured memory_bytes: 3464
#include <stdio.h>
#define MAX 10001

int S[MAX];
int T[500];

int main(void)
{
	int n, i, j, q, cnt;
	
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf(" %d", &S[i]);
	}

	scanf("%d", &q);
	for (i = 0; i < q; ++i) {
		scanf(" %d", &T[i]);
	}

	cnt = 0;
	for (i = 0; i < q; ++i) {
		for (j = 0; j < n; ++j) {
			if (T[i] == S[j]) {
				++cnt;
				break;
			}
		}
	}
	printf("%d\n", cnt);
	
	return 0;
}

Measured memory_bytes: 640
decode = ["afkpuz",
          "bglqv.",
          "chmrw?",
          "dinsx!",
          "ejoty "]

def check(i,j):
    return 0<=i<=5 and 0<=j<=4

while True:
    try:
        line = raw_input()
    except EOFError:
        break
    if len(line)%2 == 1:
        line += "9"
    ans = ""
    for i,j in zip(line[::2],line[1::2]):
        i,j = int(i)-1,int(j)-1
        if not check(i,j):
            print "NA"
            break
        ans += decode[j][i]
    else:
        print ans

Measured memory_bytes: 4224
#include<bits/stdc++.h>
//"谷は0にすることが可能"
int main()
{
    std::string s;
    std::cin >> s;
    s.insert(s.begin(), '>');
    s.push_back('<');
    int n = s.size() + 1;
    std::vector<int> h(n,-1); //各地点の高さ
    for(int i = 1; i < n; i++){
        //谷検出
        if(s[i-1] == '>' && s[i] == '<')h[i] = 0;
    }
    for(int i = 1; i < n; i++){
        if(h[i] == 0){
            //左
            int j = i - 1;
            while(s[j] == '>'){
                h[j] = std::max(h[j + 1] + 1,h[j]);
                j--;
            }

            //右
            j = i + 1;
            while(s[j - 1] == '<'){
                h[j] = h[j - 1] + 1;
                j++;
            }
        }
    }
    long long res = 0;
    //for(int i = 0; i < n; i++)std::cout << h[i] << " ";
    //std::cout << std::endl;
    for(int i = 1; i < n-1; i++)res += h[i];
    std::cout << res <<std::endl;
}
// 0<3>2>1>0<1<2>0<1<2<3<4<5>2>1>0<

Measured memory_bytes: 2820
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;

int main()
{
  int n, i, j, min_=1000000000, max_=1;
  cin >> n;
  int a[n];
  for(i=0; i<n; i++)
    cin >> a[i];
  for(i=0; i<n; i++) {
    if(a[i]<min_)
      min_ = a[i];
    if(a[i]>max_)
      max_ = a[i];
  }
  cout << max_-min_;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define M 10000
void shell_sort(int a[],int n);
void insertionSort(int a[], int num,int g ,int *cnt);
int main(){
	int n,i;
	scanf("%d",&n);
	int *a;
	a = (int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	shell_sort(a,n);
	for(i=0;i<n;i++){
		printf("%d\n",a[i]);
	}
	free(a);

	return 0;
}
void insertionSort(int a[], int num,int g,int *cnt)
{
    int v, i, j;
    for (i = 1; i < num; i++)
    {
        v = a[i];
        j = i - g;
        while (j >= 0 && a[j] > v)
        {
            a[j + g] = a[j];
            j -=g ;
			*cnt=*cnt+1;
        }
        a[j + g] = v;
    }
	
}
void shell_sort(int a[],int n){
	int cnt = 0;
	int *g;
	int i,tmp;
	for(i =1;i<M;i++){
		if((pow(3,i)-1)/2>n){
			tmp = i;
			break;
		}
	}
	g = (int *)malloc(sizeof(int)*(tmp-1));
	printf("%d\n",tmp-1);
	for(i =0;i<tmp-1;i++){
		if(i !=0){printf(" ");}
		g[i] = (pow(3,tmp-i-1)-1)/2;
		printf("%d",g[i]);
		}
		printf("\n");
	
	for(i =0;i<tmp-1;i++){
		insertionSort(a,n,g[i], &cnt);
	}
	free(g);
	printf("%d\n",cnt);
}


Measured memory_bytes: 5524
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  int x,a,b; cin>>x>>a>>b;
  if(x<(b-a)) cout<<"dangerous";
  else if((b-a)<=0) cout<<"delicious";
  else cout<<"safe";
  
  return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._
import scala.collection._

object Main {

  class Sieve(val n: Int){
    private[this] val top = (n - 3) / 2 + 1
    private[this] val sqrtLimit = (Math.sqrt(n).toInt - 3) / 2

    private[this] val cmpsts = new Array[Int]((top >>> 5) + 1)
    def isPrime(ci: Int): Boolean = (cmpsts(ci >>> 5) & (1 << (ci & 31))) == 0
    def notPrime(ci: Int): Unit = cmpsts(ci >>> 5) |= 1 << (ci & 31)

    def next(i: Int): Int = if((i > top) || isPrime(i)) 2 * i + 3 else next(i + 1)

    def exec: Iterator[Int] = {

      for{
        i <- 0 to sqrtLimit
        if isPrime(i)
        val p = 2 * i + 3
        j <- Range((p * p - 3)/2, top, p)
      } notPrime(j)

      /*
      (0 to sqrtLimit).map{ i =>
        val p = 2 * i + 3
        if(isPrime(i))Range((p*p-3)/2, top, p).map{notPrime}
      }
      */
/*
      (0 to sqrtLimit).withFilter(isPrime).map { i =>
        val p = 2 * i + 3
        Range((p*p-3)/2, top, p).map(notPrime)
      }
*/
      if(n==2)Iterator.single(2)
      else Iterator.single(2) ++ Iterator.iterate(3)(p => next((p - 1) / 2)).takeWhile(_ <= n)
    }
  }

  def loop(s: String){
    if(s != null){
       val Array(n,_*) = s.split(" ").map(_.toInt)
       if(n<2) println(0)
       else println(new Sieve(n).exec.size)
       loop(readLine)
    }
  }

  def main(args: Array[String]): Unit = loop(readLine)
}

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

int main() 
{
  int n, d;
  cin >> n >> d;
   
  int x[n][d];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> x[i][j];
    }
  }

  int count = 0;

  for (int y = 0; y < n; y++) {
    for (int z = 0; z < n; z++) {
      double a = 0;
      if (y == z) continue;
      for (int j = 0; j < d; j++) {
        a += (x[y][j] - x[z][j]) * (x[y][j] - x[z][j]);
      }
      if (sqrt(a) == floor(sqrt(a))) {
        count++;
      }
    }
  }
  cout << count / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, Q;
    string S;
    cin >> N >> Q;
    cin >> S;
    vector<pair<int, int>> lr(Q);
    for(int i = 0; i < Q; i++) {
        cin >> lr.at(i).first >> lr.at(i).second;
    }

    vector<int> ac(N);
    ac.at(0) = 0;
    for(int i = 1; i < N; i++) {
        ac.at(i) = ac.at(i - 1);
        if(S.at(i - 1) == 'A' && S.at(i) == 'C') {
            ac.at(i)++;
        }
        // cout << i << ":" << ac.at(i) << endl;
    }


    for(int i = 0; i < Q; i++) {
        cout << (ac.at(lr.at(i).second - 1) - ac.at(lr.at(i).first - 1)) << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
ll modpow(ll a,ll b){
    if(a>=mod)a%=mod;
    if(b==0)return 1;
    if(b&1)return a*modpow(a,b-1)%mod;
    ll k=modpow(a,b/2);
    return k*k%mod;
}
ll n;
vvi g;
vi dp;
ll dfs(ll i,ll p){
    if(dp[i]!=-1)return dp[i];
    ll res=0;
    for(ll x:g[i])if(x!=p)res+=dfs(x,i);
    dp[i]=res+1;
    return dp[i];
}
ll ans=0;
void dfs2(ll i,ll p){
    ll res=modpow(2,n-1)-1;
    for(ll x:g[i]){
        if(x!=p)res-=modpow(2,dp[x])-1;
        else res-=modpow(2,dp[0]-dp[i])-1;
        res%=mod;
        if(x!=p)dfs2(x,i);
    }
    res=(res%mod+mod)%mod;
    ans=(ans+res)%mod;
}
int main(){
    cin>>n;
    g=vvi(n);
    rep(i,n-1){
        ll a,b;cin>>a>>b;a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    dp=vi(n,-1);
    dfs(0,-1);
    dfs2(0,-1);
    out(ans*modpow(modpow(2,n),mod-2)%mod);
}

Measured memory_bytes: 24192
#include <iostream>

using namespace std;

//
int nleg(int turu, int kame)
{
    return turu * 2 + 4 * kame;
}

int main()
{
    int X, Y;
    cin >> X >> Y;
    for (int i = 0; i <= X; i++)
    {
        if (Y == nleg(i, X - i))
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3116