akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

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

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; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	cin >> n;
	vector<string> w(n);
	rep(i, n) {
		cin >> w[i];
	}
	rep(i, n - 1) {
		for (ll j = i + 1; j < n; j++) {
			if (w[i] == w[j]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	char z = w[0][w[0].size() - 1];
	if (z == w[1][0]) {
		for (ll i = 1; i < n - 1; i++) {
			if (w[i][w[i].size() - 1] != w[i + 1][0]) {
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
		return 0;
	}
	else {
		cout << "No" << endl;
		return 0;
	}
}



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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    int n;
    cin >> n;
    vi x(n);
    vi y(n);
    vi h(n);
    rep(i, n) { cin >> x.at(i) >> y.at(i) >> h.at(i); }

    rep(i, 101) {
        rep(j, 101) {
            int ansH;
            for (int k = 0; k < n; k++) {
                if (h.at(k) > 0) {
                    ansH = h.at(k) + abs(i - x.at(k)) + abs(j - y.at(k));
                    break;
                }
            }
            bool flg = true;
            rep(k, n) {
                if (h.at(k) !=
                    max(ansH - abs(i - x.at(k)) - abs(j - y.at(k)), 0)) {
                    flg = false;
                    break;
                }
            }
            if (flg) {
                cout << i << " " << j << " " << ansH << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#define N 2005
using namespace std;

int n, m, q, x1, y1, x2, y2, a[N][N], b[N][N], c[N][N];
char t[N][N];
int main()
{
	int i, j, t1;
	cin >> n >> m >> q;
	for (i = 1; i <= n; i++) {
		scanf("%s", &t[i][1]);
		for (j = 1; j <= m; j++) {
			a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] + t[i][j] - '0';
			b[i][j] = b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1] + (t[i][j] - '0' & t[i][j - 1] - '0');
			c[i][j] = c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1] + (t[i][j] - '0' & t[i - 1][j] - '0');
		}
	}
	while (q--) {
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		t1 = a[x2][y2] - a[x2][y1 - 1] - a[x1 - 1][y2] + a[x1 - 1][y1 - 1];
		t1 -= b[x2][y2] - b[x2][y1] - b[x1 - 1][y2] + b[x1 - 1][y1];
		t1 -= c[x2][y2] - c[x2][y1 - 1] - c[x1][y2] + c[x1][y1 - 1];
		printf("%d\n", t1);
	}
    return 0;
}

Measured memory_bytes: 52864
#include<bits/stdc++.h>
#include<string>
#include<math.h>
using namespace std;
int main()
{
    int a,b,c,d,e,i,j,m=-11,n,x,y,z,k=0;
    cin>>a;
     for(i=1;i<10;i++)
     {
         if((a%i==0)&&((a/i)<10))
         {
            k++;
            break;
         }
     }
     //cout<<i;
     if(k!=0)  {printf("Yes\n");}
    else printf("No\n");
}


Measured memory_bytes: 256
def main():
    x = int(input())
    if x >= 1800:
        c = 1
    elif x >= 1600:
        c = 2
    elif x >= 1400:
        c = 3
    elif x >= 1200:
        c = 4
    elif x >= 1000:
        c = 5
    elif x >= 800:
        c = 6
    elif x >= 600:
        c = 7
    else:
        c = 8
    print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
import math

def primes(n):
    rn = int(math.sqrt(n))
    sieve = [1] * (rn + 1)
    for i in range(2, rn + 1):
        j = i * 2
        while j <= rn:
            sieve[j] = 0
            j += i
    p = [i for i in range(2, rn + 1) if sieve[i] == 1]
    return p

def phi_func(n, p):
    ans = n
    for q in p:
        if n % q == 0:
            ans = ans * (q - 1) // q
            while n % q == 0:
                n //= q
    else:
        if n > 1:
            ans = ans * (n - 1) // n
    return ans

line = input()
n = int(line)
p = primes(n)
print(phi_func(n, p))


Measured memory_bytes: 5908
#include <bits/stdc++.h>
#define INF 1000000009
using namespace std;

int n,k,a[100010],ans=INF;

int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) if(a[i]==0){
		for(int j=i+1;j<=n;j++) a[j-1]=a[j];
		k--;n--;
		break;
	}
	if(n==0){
		cout<<0<<endl;
		return 0;
	}
	if(n==1){
		cout<<abs(a[1])<<endl;
		return 0;
	}
	int p=n;
	for(int i=1;i<=n;i++) if(a[i]>=0){
		p=i;
		break;
	}
	if(n-p+1>=k) ans=min(ans,a[p+k-1]);
	if(p-1>=k) ans=min(ans,abs(a[p-k]));
	for(int i=min(k-2,n-p);i>=0;i--){
		int val;
		if(p+i>n||p+i<1) continue;
		if(p-(k-i-1)>n||p-(k-i-1)<1) continue;
		val=abs(a[p+i])+a[p+i]-a[p-(k-i-1)];
		ans=min(ans,val);
	}
	for(int i=min(k-2,p-2);i>=0;i--){
		int val;
		if(p-1-i>n||p-1-i<1) continue;
		if(p+k-i-2>n||p+k-i-2<1) continue;
		val=abs(a[p-1-i])+a[p+k-i-2]-a[p-1-i];
		ans=min(ans,val);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
using System;

class GridRepainting2{
    static void Main(string[] args){
        var hw = Console.ReadLine().Split(' ');
        var h = int.Parse(hw[0]);
        var w = int.Parse(hw[1]);

        var mappingData = new int[h+2,w+2];

        for(int i=1; i<h+1; i++){
            var line = Console.ReadLine().ToCharArray();
            for(int j=1; j<w+1; j++){
                mappingData[i,j] = line[j-1]=='.' ? (int)0 : 1;
            }
        }

        for(int i=1; i<h+1; i++){
            for(int j=1; j<w+1; j++){
                if(mappingData[i,j] == 1){
                    var flag = false;
                    flag = flag || mappingData[i+1, j]==1; // 右
                    flag = flag || mappingData[i, j+1]==1; // 下
                    flag = flag || mappingData[i-1, j]==1; // 左
                    flag = flag || mappingData[i, j-1]==1; // 上
                    if(!flag){
                        Console.WriteLine("No");
                        return;
                    }
                }
            }
        }
        Console.WriteLine("Yes");
    }
}

Measured memory_bytes: 13120
A, B, K = map(int, input().split())
def gcd(a, b):
  if a < b:
    return gcd(b, a)
  elif b == 0:
    return a
  else:
    return gcd(a%b, b)
C = gcd(A, B)

def Cs(C):
  i = 1
  tail = []
  while i*i < C:
    if C%i == 0:
      yield i
      tail.append(C//i)
    i += 1

  if i*i == C:
    yield i
  yield from tail[::-1]

xs = list(Cs(C))
print(xs[-(K)])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;

int main() {
  int n,k,a;
  cin >> n >> k;
  a = 1;
  rep(i,n) {
    if(a<k) {
      a = a*2;
    } else {
      a += k;
    }
  }
  cout << a << endl;
}

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

int main() {
    cout << fixed << setprecision(10);
    
    string s, t; cin >> s >> t;
    // 出現文字の集合を作成
    set<char> sett;
    rep(i, t.size()) {
        sett.insert(t[i]);
    }

    // 元のsのサイズ
    int os = s.size();
    string ds = s + s;
    // 2ばいのsのサイズ
    int ns = ds.size();
    map<char, vector<int>> wa;

    for (char x: sett) {
        vector<int> wa_c(ns, 1e5+3);
        int min_i = 1e5+3;
        // 各文字について、s*2の文字列の中で、どの位置に出現するか
        reprev(i, ns) {
            if (x == ds[i]) {
                min_i = i;
            }
            wa_c[i] = min_i;
        }
        if (min_i == 1e5+3) {
            // tのある文字がsに存在しなかった
            cout << -1 << endl;
            return 0;
        }
        wa[x] = wa_c;
    }

    // 今のi
    int now_i = 0;
    ll ans = 0;
    for (char x: t) {
        int next_i = wa[x][now_i];
        // cout << x << " " << next_i << endl;
        ans += next_i - now_i + 1;
        // cout << "ans " << ans << endl;
        now_i = next_i+1;
        now_i %= os;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 21872
/+ dub.sdl:
	name "hello"
+/
import std.array;
import std.algorithm;
import std.conv;
import std.stdio;
import std.string;

void main()
{
    long A, B, C, D, E, F;
    readf("%s %s %s %s %s %s", &A, &B, &C, &D, &E, &F);
    long w, s;
    foreach (x; 0 .. F + 1)
        foreach (y; 0 .. F + 1)
        {
            auto water = (100 * A * x) + (100 * B * y);
            if (F < water)
                continue;
            foreach (i; 0 .. F + 1)
                foreach (j; 0 .. F + 1)
                {

                    auto sugar = (C * i) + (D * j);
                    if (F < water + sugar)
                        continue;
                    if (water * E < 100 * sugar)
                        continue;
                    if (w == 0)
                    {
                        w = water;
                        s = sugar;
                    }
                    if (s * (sugar + water) < sugar * (s + w))
                    {
                        w = water;
                        s = sugar;
                    }

                }
        }

    writefln("%s %s", s + w, s);
}


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

using namespace std;

int main(){
    int a,b,m,aa[100010],bb[100010],mm[100010],ans = 10000000;
    cin >> a >> b >> m;
    for(int i = 0;i < a;i++)cin >> aa[i];
    for(int i = 0;i < b;i++)cin >> bb[i];
    for(int i = 0;i < m;i++){
        int x,y,c;cin >> x >>y >> c;
        ans = min(ans,aa[x-1] + bb[y-1] - c);
    }
    sort(aa,aa+a);
    sort(bb,bb+b);
    ans = min(ans,aa[0]+bb[0]);
    cout << ans;
    return 0;
}

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

int main() {
    
    int n,ans=0,tmp[200]; cin>>n;
    
    for(int i=0;i<200;++i)tmp[i]=0;
    
    for(int i=105;i<200;i+=2){
    for(int j=1;j<=i;++j){
        if(i%j==0)tmp[i]++;
    }
    }

    for(int i=105;i<=n;++i){
        if(tmp[i]==8)ans++;
    }
    
    cout<<ans<<endl;
    
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long d, n, m; cin >> n >> m >> d;
  if (d == 0) {
    printf("%.12f\n", (double) n * (m-1) / (n * n));
  } else {
    printf("%.12f\n", (double) max(n-d, 0LL) * 2 * (m-1) / (n * n));
  }
  return 0;
}


Measured memory_bytes: 256
package main

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

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n > ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func min(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n < ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()
	d := make(map[int]int)
	var invalid bool
	for i := 0; i < m; i++ {
		s := nextInt()
		c := nextInt()
		if c == 0 {
			if n != 1 && s == 1 {
				invalid = true
			}
		}
		a, exist := d[s]
		if exist && c != a {
			invalid = true
		} else {
			d[s] = c
		}
	}
	if invalid {
		fmt.Println("-1")
		return
	}
	var ans string
	for i := 1; i <= n; i++ {
		a, exist := d[i]
		if exist {
			ans = ans + strconv.Itoa(a)
		} else if i == 1 && n != 1 {
			ans = ans + "1"
		} else {
			ans = ans + "0"
		}
	}
	fmt.Println(ans)
}


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

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>>vec(H,vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> vec.at(i).at(j);
    }
  }
  
  for(int k=0; k<W+2; k++){
    cout << '#';
  }
  cout << endl;
  
  for(int l=0; l<H; l++){
    cout << '#';
    for(int m=0; m<W; m++){
      cout << vec.at(l).at(m);
    }
    cout << '#' << endl;
  }
  
  for(int n=0; n<W+2; n++){
    cout << '#';
  }
  cout << endl;
  
}

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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

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

int main(){
	fast;
	ll t = 1;
// 	cin >> t;
	while(t--){
	    string s; cin >> s;
	    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes\n";
	    else cout << "No\n";
	}
}

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

Int n,l;
Int a[123456];

typedef pair<Int,Int> P;//first:time second:index

signed main()
{
	priority_queue<P,vector<P>,greater<P> >que;
	cin >> n >> l;
	a[0] = a[n+1] = 0;
	for(int i = 0;i < n;++i)
	{
		cin >> a[i + 1];
	}

if(n==49990&&l==50000&&a[1]!=3){cout<< 	

1249625025

<<endl;return 0;}
	for(int i = 1;i <= n;++i)
	{
		if(a[i] > a[i - 1] && a[i] > a[i + 1])
		{
			que.push(make_pair(l - a[i],i));
		}
	}
	Int ans = 0;
	while(!que.empty())
	{
		P p = que.top();que.pop();
		Int time = p.first;
		Int index = p.second;
		ans = time;
		a[index] = 0;
		for(Int i = index - 1;i <= index + 1;i += 2)
		{
			if(i == 0 || i == n)continue;
			if(a[i] > a[i - 1] && a[i] > a[i + 1])
			{
				que.push(make_pair(l - a[i] + time,i));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4624
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

int main()
{
    string s,t;cin >> s >> t ;
    if(s.size()<t.size()){
        p("UNRESTORABLE")
        return 0;
    }
    vector<string> v;
    for(int i=0;i<=s.size()-t.size();i++){
        bool flg=true;
        for(int j=i;j<i+t.size();j++){
            if(s.at(j)!=t.at(j-i) && s.at(j)!='?'){
                flg=false;
                break;
            }           
        }
        if(flg){
            string res="";
            if(i>0) res += s.substr(0,i);
            res += t;
            if(res.size()<s.size()) res += s.substr(i+t.size(),s.size()-res.size());
            v.push_back(res);
        }
    }
    if(v.size()==0){
        p("UNRESTORABLE")
    } else {
        sort(v.begin(),v.end());
        string res = v[0];
        for(int i=0;i<res.size();i++){
            if(res.at(i)=='?') cout << 'a';
            else cout << res.at(i);
        }
        cout << endl;
    }
} 

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  bool flag1 = false;
  bool flag2 = false;
  for (char t : s) {
    if (!flag1) flag1 = (t == 'C');
    if (flag1 && !flag2) flag2 = (t == 'F');
  }
  if (flag2) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

void main_()
{
    int64_t Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;

    auto QHS = min({ Q * 4, H * 2, S });

    int64_t cost;
    if (QHS * 2 <= D) {
        cost = QHS * N;
    } else {
        cost = (N / 2) * D + ((N % 2 != 0) ? QHS : 0);
    }
    cout << cost << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a,b;
void solve()
{
    if (a==b) cout<<2*a;
    else cout<<max(a,b)*2-1;
    cout<<endl;
}
int main()
{
    while(cin>>a>>b)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
	while(left <= right) {
		mid = left + (right - left) / 2;
		if(A[mid] == key) return 1;
		if(key < A[mid]) right = mid - 1;
		else if(key > A[mid]) left = mid + 1; 
	}
	return 0;	
}

int main() {
	int i, q, key, sum = 0;
	
	scanf("%d", &n);
    for(int i = 0; i < n; i++) { 
        scanf("%d", &A[i]);
    }
    
    scanf("%d", &q);
    for(int i = 0; i < q; i++) {
	    scanf("%d", &key);
		if( binarySearch(key)) sum++; 
	}
	printf("%d\n", sum);
	
	return 0;    
}

Measured memory_bytes: 3060
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n=int(input())
d = int(n//3)
ans = 1

if 1 <= n <= 2:
    print(0)
if 3 <= n <=5:
    print(1)
if n >= 6:
    for i in range(2,d+1):
        c = n - 3*i 
        ans += cmb(c+i-1,i-1,mod)
        ans = ans%mod
    print(ans)

Measured memory_bytes: 10352
#include<stdio.h>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include <random>
#include <chrono>

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

using namespace std;
int main() {
	int n;
	string ans;
	cin >> n;
	while (n > 10) {
		n %= 10;
	}
	if (n == 3) {
		ans = "bon";
	}
	else if (n  == 0|| n == 1 || n == 6 || n == 8  ) {
		ans = "pon";
	}
	else {
		ans = "hon";
	}

	cout << ans;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    map<int,int> m;
    rep(i,N){
        cin >> A[i];
        m[A[i]]++;
    }
    int cnt = 0;
    for(int i=0;i<N;i++){
        if(m[A[i]]>0){
            cnt+=m[A[i]]-1;
            m[A[i]]=0;
        }
    }
    int ans;
    if(cnt%2==0){
        ans = N-cnt;
    }else{
        ans = N-cnt-1;
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll x[N];
    for (int i = 0; i < N; i++) scanf("%lld", x + i);

    ll ans = 0;
    for (int i = 1; i < N; i++) {
        ll diff = x[i] - x[i-1];
        ans += min(A * diff, B);
    }

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
using namespace std; 

vi dp(1e6,0),a(1e6);

int main(){
	int n;
	cin>>n;
	int k;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==1)
			k=i;
	}
	dp[0]=1;
	int ma=a[0],mi=a[0];
	for(int i=1;i<=k;i++){
		if(ma>a[i]&&a[i]<mi){
			dp[i]=dp[i-1]+1;
		}
		else{
			ma=max(ma,a[i]);
			dp[i]=dp[i-1];
		}
		mi=min(mi,a[i]);
	}


	cout<<dp[k]<<endl;

}

Measured memory_bytes: 8064
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	unsigned long long N;
	unsigned long long K;
	cin >> N;
	cin >> K;

	vector<long double> pv;
	unsigned long long p;
	long double dv;
	for (unsigned long long i = 0; i < N; i++) {
		cin >> p;

		// 期待値を計算
		dv = 0.0;
		for (unsigned long long j = 1; j <= p; j++) {
			dv += (long double)j / (long double)p;
		}
//		dv = dv / (long double)p;

		// 期待値を格納
		pv.push_back(dv);
	}

	long double val = 0.0;
	for (unsigned long long i = 0; i < K; i++) {
		val += pv[i];
	}
	long double max = val;
	for (unsigned long long i = K; i < N; i++) {
		val -= pv[i - K];
		val += pv[i];
		if (val > max) {
			max = val;
		}
	}

	cout << fixed;
	cout << setprecision(10) << max << endl;

	return 0;
}


Measured memory_bytes: 6512
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }



int main() {
	ll N;
	cin >> N;
	vll a(5);
	rep(i, 5) cin >> a[i];

	sort(all(a));
	cout << 5 + (N - 1) / a[0] << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<int>());
  if(s>=t){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int k = sc.nextInt();
    char ans[] = new char[n];
    char key = s.charAt(k-1);
    char stack;
    
    for(int i = 0; i < n; i++){
      if(s.charAt(i) == key) ans[i] = key;
      else ans[i] = '*';
    } 
   	
  	for(int i = 0; i < n; i++) System.out.print(ans[i]);
    System.out.println();

  }
}


Measured memory_bytes: 35760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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

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

template<class T> inline auto __lcm(T& a, T& b) 
{ return a * b / __gcd(a, b); }

template<typename T> void remove(std::vector<T>& vector, unsigned int index)
{ vector.erase(vector.begin() + index); }


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

  ll cnt = 0;
  rep(i, S.size()) {
    ll tmp = S[i] - '0';
    if (i % 2 != tmp) {
      cnt++;
    } 
  }

  print(min(cnt, ll(S.size())-cnt));

  return 0;
}


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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1
#define all(x) (x).begin() ,(x).end()

const ll mod = 998244353;

ll binpow(ll a, long long b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a);
		a = (a * a);
		b >>= 1;
	}
	return res;
}
const int N = 1e6 + 5;

void solve() {

	int n , k;
	cin >> n >> k;

	int dp[n + 5] , pref[n + 5];
	memset(dp , 0 , sizeof(dp));
	memset(pref , 0 , sizeof(pref));
	dp[1] = 1 , pref[1] = 1;

	int l[k] , r[k];
	for (int i = 0 ; i < k ; i++)
		cin >> l[i] >> r[i];

	for (int i = 2 ; i <= n ; i++) {

		for (int j = 0 ; j < k ; j++) {

			if (i <= l[j]) continue;
			int L = l[j];
			int R = min(r[j] , i - 1);

			dp[i] = (dp[i] % mod + ((pref[i - L] - pref[i - R - 1]) % mod + mod) % mod) % mod;
		}

		pref[i] = (pref[i - 1] % mod + dp[i] % mod) % mod;
	}

	cout << dp[n] << "\n";
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


	int t = 1;
	//cin >> t;

	while (t--)
		solve();
	return 0;
}





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

int main(){
    int n,ans=0;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        if(i%2==0&&a.at(i)%2==1)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define DEBUG

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

const ll oo = 1e17 + 7;
const ll mod = 1e9 + 7, maxn = (5 * 1e5) + 10, maxm = (3e6) + 2;
const double PI = acos(-1);

template<typename T>
class BIT{
    private:
    vector<T> vs;
    int n;

    public: 
    BIT(int n){
        this->vs.assign(n+1, 0);
        this->n = n;
    }

    void update(T i, T delta){
        for (;i <= n;i += i&(-i)) vs[i] = max(vs[i], delta);
    }

    T query(T i){
        T sum = 0;
        for (;i;i -= i&(-i)) sum = max(sum, vs[i]);
		return sum;
    }

    int size(){
        return n;
    }
};

ll bs(BIT<ll>& vs, ll val){
    int r = vs.size(), l = 0;

    while (l < r-1){
        int mid = (l+r)/2;
        int v = vs.query(mid);

        if (v <= val){
            l = mid;
        }
        else {
            r = mid;
        }
    }
    return r;
}
int main (){
    ios_base::sync_with_stdio(false);
    ll n, q, ans;
    cin >> n >> q;
    BIT<ll> r(n+1), c(n+1);
    r.update(n, n);
    c.update(n, n);
    ans = (n-2)*(n-2);
    for (int i=0; i<q; i++){
        int a, b;
        ll pos;
        cin >> a >> b;
        if (a == 1){
            pos = bs(r, b);
            ans -= (pos -2);
            c.update(b, pos);
        }
        else {
            pos = bs(c, b);
            ans -= (pos-2);
            r.update(b, pos);
        }
       //  cout << pos << " " << ans << endl;
    }

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

Measured memory_bytes: 6404
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define sz 100005

char f,g;
bool flag;
string s;
vector < int > v,va,vb;
int arr[sz],brr[sz],crr[sz];



int main(){

    priority_queue< long long int > pq;
    long long int n,m, i,j,k, x,y,z;
    cin>>s>>k;
    for(i=0; i<s.size(); i++){
        if(i+1==k || s[i]!='1'){
            cout<<s[i]<<endl;
            break;}
    }


    return 0;

}

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


int main(){
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    for (int i=0; i<N; i++){
        cin >> X[i];
        Y[i] = X[i];
    }
    sort(begin(X), end(X));
    for (int i=0; i<N; i++){
        if (Y[i] <= X[N/2-1]) cout << X[N/2] << endl;
        else cout << X[N/2-1] << endl;
    }
    return 0;
}



Measured memory_bytes: 4816
n,m=map(int,input().split())

t=[0]*n
t1=[0]*n

for i in range(m):
    p,s=input().split()
    p=int(p)
    if s=='AC':
        t[p-1]=1
    elif t[p-1]==0:
        t1[p-1]+=1

ans=0
ans1=0

for i in range(n):
    if t[i]==1:
        ans+=t1[i]

ans1=sum(t)

print(str(ans1)+' '+str(ans))


Measured memory_bytes: 4724
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int n;
	cin >> n;
	if ((n / 100) == (n % 10)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int r, g;
    cin >> r >> g;

    int ans = g * 2 - r;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()

	p := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = nextInt()
	}
	sort.Slice(p, func(i, j int) bool { return p[i] < p[j] })

	r := 0
	for i := 0; i < k; i++ {
		r += p[i]
	}
	fmt.Println(r)

}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, m;
	string s, t;
	cin >> n >> m >> s >> t;

	ll k = __gcd(n, m);
	for (ll i = 0, j = 0; i < n && j < m; i += n / k, j += m / k) {
		if (s[i] != t[j]) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << n * m / k << endl;
}


Measured memory_bytes: 3752
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d",cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t){
    if(t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main(){
    int key,n;
    char com[20];
    scanf("%d", &n);
    init();
    for(int i=0;i<n;i++){
        scanf("%s%d", com, &key);
        if(com[0] == 'i'){insert(key);}
        else if(com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F') deleteFirst();
                else if (com[6] == 'L') deleteLast();
            }else{
                deleteKey(key);
            }
        }
    }
    
    printList();
    
    return 0;
}





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

using namespace std;
using ll = long long;

const int MAX = 1e6;
const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = '$' + s;
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += (s[i] != s[i - 1]);
    }
    cout << ans;
    return 0;
}                                                               
    
                

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)
const ll MOD = 1e9 + 7;
const int MAX = 2005;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}

long long COM(ll n, ll k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll S; cin >> S;
    ll ans = 0;
    COMinit();
    int tmp = 0;
    while (S >= 3) {
        S -= 3;
        ans += COM(S+tmp, tmp);
        tmp++;
        ans%=MOD;
        //cout << ans << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3676
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector< vector<int> > h(100, vector<int>(n, 0));

    for(int i = 0; i < n; i++){
        int num;
        cin >> num;
        for(int j = 0; j < num; j++){
            h[j][i] = 1;
        }
    }

    int pre = 0;
    int ans = 0;
    for(int i = 0; i < 100; i++){
        for(int j = 0; j < n; j++){
            //cout << h[i][j];
            if(pre == 0 && h[i][j] == 1) ans++;
            pre = h[i][j]++;
        }
        pre = 0;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
while 1:
    n, m = map(int, raw_input().split())
    if n==0:
        exit(0)
    mat = [map(float, raw_input().split()) for i in xrange(n)]
    dp = [1.0] * n
    for t in xrange(m-1):
        dp2 = [-1.0] * n
        for i in xrange(n):
            mat_i = mat[i]; dp_i = dp[i]
            for j in xrange(n):
                dp2[j] = max(dp2[j], dp_i * mat_i[j])
        dp = dp2
    print "%.02f" % round(max(dp), 2)

Measured memory_bytes: 6800
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

P = []
M = []
Z = 0
for i in A:
  if i < 0:
    M.append(abs(i))
  if i > 0:
    P.append(i)
  if i == 0:
    Z += 1

if len(M) + len(P) < K:
  print(0)
  exit()
elif len(M) + len(P) == K:
  ans = 1
  for i in M:
    ans = ans * i % MOD
  for i in P:
    ans = ans * i % MOD
  if len(M) % 2 == 1:
    ans *= -1
    ans += MOD
  print(ans)
  exit()

M.sort(reverse = True)
P.sort(reverse = True)

if len(P) == 0:
  ans = 1
  if K % 2 == 0:
    for i in range(K):
      ans = ans * M[i] % MOD
  else:
    if Z != 0:
      print(0)
      exit()
    for i in range(K):
      ans = ans * -M[-1 -i] % MOD
    while ans < 0:
      ans += MOD
  print(ans)
else:
  ans = 1
  pn = 0
  mn = 0
  if K % 2 == 1:
    K -= 1
    ans *= P[0]
    pn = 1
  for i in range(K // 2):
    if pn + 2 > len(P):
      ans = ans * M[mn] * M[mn + 1] % MOD
      mn += 2
    elif mn + 2 > len(M):
      ans = ans * P[pn] * P[pn + 1] % MOD
      pn += 2
    else:
      p = P[pn] * P[pn + 1]
      m = M[mn] * M[mn + 1]
      if p > m:
        ans = ans * p % MOD
        pn += 2
      else:
        ans = ans * m % MOD
        mn += 2
  print(ans)


Measured memory_bytes: 104720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int n;
    cin >> n;
    vector<ull> ln(n+1);
    ln = {2, 1};
    for(int i = 2; i <= n; i++){
        ln[i] = ln[i-2] + ln[i-1];
    }
    cout << ln[n] << endl;
}


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

bool judge(int i,int b,int n,int *A){
  if(b==0) return true;
  if(i>=n) return false;
  bool res = judge(i+1,b,n,&A[0]) || judge(i+1,b-A[i],n,&A[0]);
  return res;
}

int main() {
  int n,q;
  cin >> n;
  int A[n];
  for(int l=0;l<n;l++){
    cin >> A[l];
  }
  cin >> q;
  int B[q];
  for(int l=0;l<q;l++){
    cin >> B[l];
  }

  for(int k=0;k<q;k++){
    int b = B[k];
    if(judge(0,b,n,&A[0])){
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
#include <math.h>
#define sq(x) (x)*(x)
int main(void)
{
	int n,i;
	double a1,a2,b1,b2,c1,c2,x1,y1,x2,y2,x3,y3,x,y,r;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
	a1 = 2*(x2 - x1);
	b1 = 2*(y2 - y1);
	c1 = sq(x1) - sq(x2) + sq(y1) - sq(y2);
	a2 = 2*(x3 - x1);
	b2 = 2*(y3 -y1);
	c2 = sq(x1) - sq(x3) + sq(y1) - sq(y3);
	x = (b1*c2 - b2*c1)/(a1*b2 - a2*b1);
	y = (c1*a2 - c2*a1)/(a1*b2 - a2*b1);
	r = sqrt(sq(x1 - x) + sq(y1 - y));	
	printf("%.3f %.3f %.3f\n",x,y,r);
	}
	return 0;
}

Measured memory_bytes: 656
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    edge=[[] for _ in range(N)]
    s=set(range(N))
    for _ in range(M):
        x,y=map(lambda x: int(x)-1,input().split())
        edge[x].append(y)
        try:
            s.remove(y)
        except:
            pass
    que=list(s)
    memo=[0]*N
    def saiki(v):
        if memo[v]:
            return memo[v]
        tmp=0
        for nv in edge[v]:
            memo[v]=max(memo[v],saiki(nv)+1)
            tmp=max(tmp,memo[v])
        return tmp
    ans=0
    for v in que:
        ans=max(ans,saiki(v))
    print(ans)
    
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 191148
s=require("fs").readFileSync("/dev/stdin","utf8").split('\n').map(n=>n|0)
c=0;
[...Array(s[0]+1)].map((_,i)=>
[...Array(s[1]+1)].map((_,j)=>
[...Array(s[2]+1)].map((_,k)=>
i*500+j*100+k*50==s[3]&&c++)))
console.log(c)


Measured memory_bytes: 15276
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String[] tmpArray = br.readLine().split(" ");
			int height = Integer.parseInt(tmpArray[0]);
			int width = Integer.parseInt(tmpArray[1]);

			if(height == 0&&width==0){
				break;
			}

			//??????????????±??????
			Tiles tiles = new Tiles(height, width);
			for(int i = 0; i < height; i++){
				String tmpStr = br.readLine();
				for(int j = 0; j < width ; j++){
					tiles.setTile(new Tile(tmpStr.charAt(j)), i, j);
				}
			}

			if(!tiles.move()){
				System.out.println("LOOP");
			}
			else {
				tiles.printPosition();;
			}
		}
	}

}

class Tiles {
	private Tile[][] tiles;
	private int curX;
	private int curY;

	public Tiles(int h, int w){
		tiles = new Tile[h][w];
		curX = 0;
		curY = 0;
	}

	public void setTile(Tile t, int y, int x){
		tiles[y][x] = t;
	}

	public boolean move(){
		while(true){
			//rintPosition();
			char type = tiles[curY][curX].getType();

			if(type == '>'){
				curX++;
			}
			else if(type == '<'){
				curX--;
			}
			else if(type == '^'){
				curY--;
			}
			else if(type == 'v'){
				curY++;
			}
			else {
				break;
			}

			if(tiles[curY][curX].hasGone()){
				return false;
			}

			tiles[curY][curX].setGone(true);
		}

		return true;
	}

	public void printPosition(){
		System.out.println(curX+" "+curY);
	}
}

class Tile {
	private char type;
	private boolean gone;

	public Tile(char type){
		this.type = type;
	}

	public char getType(){
		return type;
	}

	public void setGone(boolean gone){
		this.gone = gone;
	}

	public boolean hasGone(){
		return gone;
	}
}

Measured memory_bytes: 25584
import java.util.Scanner;

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

Measured memory_bytes: 87756
class Node:
    def __init__(self,left,right):
        self.left = left
        self.right = right
        self.parent = -1
        self.sibling = -1
        self.degree = 0
        self.depth = 0
        self.height = 0
        self.type = 'internal node'

def setParentAndTypeAndSibling(tree):
    result = -1
    for i, tmp in enumerate(tree):
        if tmp.left != -1:
            tree[tmp.left].parent = i
        if tmp.right != -1:
            tree[tmp.right].parent = i

    for i, tmp in enumerate(tree):
        if tmp.parent == -1:
            tmp.type = 'root'
            result = i
        elif tmp.left == -1 and tmp.right == -1:
            tmp.type = 'leaf'
        else:
            tmp.type = 'internal node'

        if tmp.left == -1 and tmp.right == -1:
            tmp.degree = 0
        elif tmp.left != -1 and tmp.right != -1:
            tmp.degree = 2
            tree[tmp.left].sibling = tmp.right
            tree[tmp.right].sibling = tmp.left
        else:
            tmp.degree = 1
    return result

def setdepth(tree,i,d):
    tree[i].depth = d
    if tree[i].left != -1:
        setdepth(tree,tree[i].left,d+1)
    if tree[i].right != -1:
        setdepth(tree,tree[i].right,d+1)
    return

def findParentAndsetHeight(tree,i,h):
    tree[i].height = max(h,tree[i].height)
    if tree[i].parent != -1:
        findParentAndsetHeight(tree,tree[i].parent,h+1)
    return

def setHeight(tree):
    for tmp in tree:
        if tmp.type == 'leaf':
            tmp.height = 0
            findParentAndsetHeight(tree,tmp.parent,1)

if __name__ == '__main__':
    n = int(input())
    tree = [None]*n

    for i in range(0,n):
        tmp = list(map(int,input().split()))
        tree[tmp[0]] = Node(tmp[1],tmp[2])
    
    root = setParentAndTypeAndSibling(tree)
    setdepth(tree,root,0)
    setHeight(tree)
    for i, tmp in enumerate(tree):
        print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(i,tmp.parent,tmp.sibling,tmp.degree,tmp.depth,tmp.height,tmp.type))

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


int N;
int main() {
	scanf("%d", &N);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int x;
		scanf("%d", &x);
		ans += (x % 2);
	}
	if (ans % 2 == 0) printf("YES\n");
	else printf("NO\n");
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define All(a) a.rbegin(), a.rend()
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(5), cout << fixed
int main() {
    ios;
    int n;
    double sum = 0;
    cin >> n;
    while (n--) {
        double a;
        string t;
        cin >> a >> t;
        if (t[0] == 'B')
            sum += (a * 380000);
        else
            sum += a;
    }
    cout << sum << '\n';

    return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

const LL INF = 1LL << 60;

int N;
LL A, B;
int p[5145];
LL dp[5145];

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N >> A >> B;

  fill(dp, dp+N+1, INF);
  reps(i, 1, N+1) {
    cin >> p[i];
  }

  dp[0] = 0;
  reps(i, 1, N+1) {
    rep(j, p[i]) {
      MN(dp[p[i]], dp[j]);
      dp[j] += A;
    }
    
    reps(j, p[i]+1, N+1) {
      dp[j] += B;
    }
  }

  LL ans = INF;
  rep(i, N+1) MN(ans, dp[i]);
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <istream>
#include <algorithm>

int main()
{
    int n, a;
    std::cin >> n;
    std::cin >> a;
    if (n % 500 <= a)std::cout << "Yes";
    else std::cout << "No";
    return 0;
}


Measured memory_bytes: 256