akhauriyash/Code-Regression huggingface dataset:
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
void solve()
{
	int n;
	cin>>n;
	cout<<(n+1)/2;	



}
signed main()
{
	fastio;
//	test
		solve();
}




Measured memory_bytes: 256
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define sh short int
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
const int inf = 1e9*2;
const int mod = 1e9+7;
ll k;
ll dp[109][9][9];
string s;
ll bt(ll id,ll cnt,ll flag){
    if(cnt > k) return 0;
    if(id == s.size()) return (cnt == k);
    ll &ret = dp[id][cnt][flag];
    if(ret != -1) return ret;
    int ID = s[id] - '0';
    ret = bt(id+1,cnt,(flag || ID));
    if(!ID && !flag) return ret;
    for(int i=1;i<ID;i++){
        ret += bt(id+1,cnt+1,1);
    }
    if(flag){
        for(int i=max(1,ID);i<=9;i++){
            ret += bt(id+1,cnt+1,1);
        }
    }
    else if(ID) ret += bt(id+1,cnt+1,0);
    return ret;
}
int main(){
    fast,cin>>s>>k;
    memset(dp,-1,sizeof(dp));
    cout<<bt(0,0,0)<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll N;
    cin >> N;
    auto A = InputVec(N);
    ll mode = 0;
    ll count = 1;
    for (int i = 0; i < N-1; ++i) {
        if(mode == 0){
            if(A[i] == A[i+1]){

            }else if(A[i] < A[i+1]){
                mode = 1;
            }else if(A[i] > A[i+1]){
                mode = -1;
            }
        }else{
            if(mode == 1 && A[i] <= A[i+1]){
                continue;
            }
            if(mode == -1 && A[i] >= A[i+1]){
                continue;
            }
            count++;
            mode = 0;
        }
    }
    cout <<count << endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  ll N , A ,B ;
  cin >> N >> A >> B ;
  ll ans = N / ( A + B ) ;
  cout << ans * A + min(N - ans * (A + B) , A) << endl;
}

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

using namespace std;

using ll=long long ;
void solve() {
    int n; ll m;
    cin >> n >> m;
    vector<ll> a(n+1);
    a[0] = 0;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        a[i] = a[i-1] + x;
        a[i] %= m;
    }
    map<ll, ll> cnt;
    for (ll x: a){
        cnt[x]++;
    }
    ll res = 0;
    for (auto& p: cnt) {
        ll t = p.second;
        res += t*(t-1)/2;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 4992
import java.util.*;

public class Main {
	static long MOD = (long) 1e9 + 7;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] grid = new int[h][w];
		for (int i = 0; i < h; i++) {
			String line = sc.next();
			for (int j = 0; j < w; j++) {
				grid[i][j] = (line.charAt(j) == '.' ? 0 : 1);
			}
		}
		sc.close();

		final long MOD = 1000000007l;
		long[][] ans = new long[h][w];
		ans[0][0] = 1;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (grid[i][j] == 0 && (i != 0 || j != 0)) {
					ans[i][j] = (i >= 1 ? ans[i - 1][j] : 0) + (j >= 1 ? ans[i][j - 1] : 0);
					ans[i][j] %= MOD;
				}
			}
		}
		/*
		 * for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) {
		 * System.out.print(ans[i][j] + " "); } System.out.println(); }//
		 */
		System.out.println(ans[h - 1][w - 1]);
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static Integer[] arrayInteger(Scanner sc, int n) {
		Integer[] array = new Integer[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


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

int main(){
	
	long long x;
	cin>>x;
	int y=0;
	long long sum=100;
	while(sum<x)
	{
		sum=sum+sum*0.01;
		y++;
	}
	cout<<y;
	
	return 0;
}

Measured memory_bytes: 3624
#include<bits//stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int d=0;
    for(int i=1;i<100;i++){
        if(a%i==0&&b%i==0&&c%i>0){
            d++;
        }
        else{
        }
    }
    if(d==0){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

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

using namespace std;

int INF = 1e9 + 5;

int a[100005];

int minCost(int pos, vector<int>& memo) {
    if (pos < 0)
        return INF;
    if (pos == 0)
        return 0;
    if (memo[pos] != -1)
        return memo[pos];
        
    int cost1 = minCost(pos-1, memo), cost2 = minCost(pos-2, memo);
    if (pos - 1 >= 0) {
        cost1 += abs(a[pos] - a[pos-1]);
    }
    if (pos - 2 >= 0) {
        cost2 += abs(a[pos] - a[pos-2]);
    }
    memo[pos] = min(cost1, cost2);
    return memo[pos];
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> memo(n, -1);
    cout << minCost(n-1, memo) << endl;
    return 0;
}

Measured memory_bytes: 7296
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        int hrs = 0;
        int min = 0;

        Scanner sc = new Scanner(System.in);

        int sec = sc.nextInt();

        if (sec < 60) {
            hrs = 0;
            min = 0;
        } else if (sec >= 60 && sec < 60*60) {
            hrs = 0;
            min = sec / 60;
            sec %= 60;
        } else if (sec >= 60*60) {
            hrs = sec / (60*60);
            min = (sec - hrs*60*60) / 60;
            sec = sec - hrs*60*60 - min*60;
        }


        System.out.println(hrs + ":" + min + ":" + sec);

        sc.close();
    }

}


Measured memory_bytes: 26248
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
#include<ctime>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>

using namespace std;
typedef long long ll;
#define MP make_pair

ll num[300000]={},a[300000]={};

int main(void) {
    ll n,tmp,ans=0,eans,ai;
    cin>>n;
    for (int i = 0; i < n; i++) {
        cin>>a[i];
        num[a[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        if(num[i]>0)ans+=(num[i]*(num[i]-1))/2;
    }

    for (int i = 0; i < n; i++) {
        eans=ans;
        ai=num[a[i]];
        if(ai>0)eans-=(ai*(ai-1))/2;
        if(ai>1)eans+=((ai-1)*(ai-2))/2;
        cout<<eans<<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 6144
import sys
input=sys.stdin.readline
import collections

def main():
    N,K,Q=map(int,input().split())
    X = [K-Q]*N
    for _ in range(Q):
        X[int(input())-1] += 1
    for x in X:
        if x > 0:
            print("Yes")
        else:
            print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 6952
s = list(input())
k = int(input())


if k <= len(s):
  for i in range(k):
    if not s[i] == '1':
      print(s[i])
      break
  else:
    print(1)
elif k > len(s):
  for i in s:
    if not i == '1':
      print(i)
      break

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cstdio>
#define MN 300
#define mod 1000000007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
vector<pair<int,int> >v[MN+5];
int f[MN+5][MN+5][MN+5],n,m;
bool vis[MN+5][MN+5][MN+5];
int F(int a,int b,int c)
{
	if(vis[a][b][c]) return f[a][b][c];vis[a][b][c]=1;
	for(int i=0;i<v[a].size();++i)
	{
		int l=v[a][i].first,x=v[a][i].second;
		if((a>=l)+(b>=l)+(c>=l)!=x) return 0;	
	}
	if(a==n) return f[a][b][c]=1;
	return f[a][b][c]=((F(a+1,b,c)+F(a+1,a,c))%mod+F(a+1,a,b))%mod;
}
int main()
{
	n=read();m=read();
	for(int i=1;i<=m;++i)
	{
		int l=read(),r=read(),x=read();
		v[r].push_back(make_pair(l,x));	
	}
	printf("%d\n",F(0,0,0));
	return 0;
}



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

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

int main() {
        string s;
        cin >> s;
        cout << s.substr(0, 4) << ' ' << s.substr(4) << endl;
        return 0;
}



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

const ll mod = 1e9+7;

ll fact(ll n) {
  ll f = n;
  for (ll i = 2; i < n; i++) {
    (f *= i) %= mod;
  }
  return f;
}

int main(){
  ll n,m;
  cin >> n >> m;
  if (abs(n-m) == 0) {
    cout << (2*fact(n)*fact(m))%mod << endl;
  } else if (abs(n-m) == 1) {
    cout << (fact(n)*fact(m))%mod << endl;
  } else cout << 0 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    int h=(N-(N%100))/100;
    int o=(N%100)%10;
    if(o==h)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    cout<<endl;
  
    return 0;
}



Measured memory_bytes: 256
from sys import stdin

a, b = [int(x) for x in stdin.readline().split()]

while b != 0:
    a, b = b, a % b

c = 1
lim = a ** 0.5 + 2
n = 0
i = 2
while a > 1 and i <= lim:
    n = 0
    while a % i == 0:
        a //= i
        n += 1
    if n > 0:
        c += 1
    i += 1
if a > 1:
    c += 1

print(c)


Measured memory_bytes: 40172
/**
 * @author karayuu
 */
fun main(args: Array<String>) {
    val (n, y) = readLine()!!.split(" ").map { it.toInt() }
    for (i in 0..n) {
        if (i * 10000 > y) {
            /* 10000の位 */
            continue
        }
        for (j in 0..n) {
            if (i * 10000 + j * 5000 > y) {
                continue
            }
            val remaining = y - (i * 10000 + j * 5000)
            val k = remaining / 1000
            if (i + j + k == n) {
                print("$i $j $k")
                return
            }
        }
    }
    print("-1 -1 -1")
}

Measured memory_bytes: 37868
#[allow(unused)]
use proconio::marker::*;
use proconio::{fastout, input};
#[allow(unused)]
use std::cmp::{max, min};
#[allow(unused)]
use std::collections::{HashMap, HashSet, VecDeque};

#[fastout]
fn main() {
    input! {
        h1: i32,
        m1: i32,
        h2: i32,
        m2: i32,
        k: i32,
    }
    let ans = (h2 - h1) * 60 + (m2 - m1) - k;
    println!("{}", ans);
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    string S;
    cin >> S;
    int ans = INT_MAX;
    for (int i = 0; i + 2 < S.size(); ++i) {
        ans = min(ans, abs(753 - stoi(S.substr(i, 3))));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
    int n;
    int a[100];
    
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    
    for(int i = n-1; i > 0; i--){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[0]);
}

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

using namespace std;

vector <int> V[101010];
int n;

int dfs(int p, int r)
{
	int ret, k, f;
	
	ret = f = 0;
	
	for(int t: V[p]){
		if(t != r){
			k = dfs(t, p);
			ret += k;
			if(k == 0) f ++;
		}
	}
	
	if(f > 1) ret += f - 1;
	
	return ret;
}

int main()
{
	int i, a, b, r;
	
	scanf("%d", &n);
	
	if(n == 2){
		printf("1\n");
		return 0;
	}
	
	for(i=1; i<n; i++){
		scanf("%d%d", &a, &b);
		V[a].push_back(b);
		V[b].push_back(a);
	}
	
	for(i=r=0; i<n; i++){
		if(V[r].size() < V[i].size()) r = i;
	}
	
	printf("%d\n", dfs(r, r));
	
	return 0;
}

Measured memory_bytes: 11904
import java.util.Scanner;
public class Main
{
    public static void main(String[]args)
    {
        Scanner ra = new Scanner(System.in);
        String s = ra.next();
        String[] arreglo = s.split("");
        int []arregloenteros = new int [arreglo.length];
        for(int i=0;i<arreglo.length;i++)
        {
            arregloenteros[i] = Integer.parseInt(arreglo[i]);
        }
        boolean estaelsiete=false;
        for(int i=0;i<arreglo.length;i++)
        {
            estaelsiete= arregloenteros[i]==7;
            if(estaelsiete==true)
            {
                System.out.println("Yes");
                break;
            }
        }
        if(estaelsiete==false)
        System.out.print("No");
    }
}

Measured memory_bytes: 35704
#C
from collections import deque
n,m = map(int,input().split())
gate = deque()
for _ in range(m):
    l,r = map(int,input().split())
    if len(gate) == 0:
        gate.append([l,r])
        #print(gate)
    else:
        check = gate.pop()
        #print(gate)
        if check[0] <= l:
            check[0] = l
            #print(check)
        if check[1] >= r:
            check[1] = r
            #print(check)
        gate.append(check)
     
result = gate.pop()
if result[1] < result[0]:
    print(0)
else:
    print(result[1]-result[0]+1)

Measured memory_bytes: 3444
mod = 10 ** 9 + 7
N, M = [int(_) for _ in input().split()]

MAX_N = 10 ** 5 + 100

factorize_result = {}
def factorization(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            factorize_result[i] = 1
            n = n // i
            while n % i == 0:
                factorize_result[i] += 1
                n = n // i
    if n > 1:
        factorize_result[n] = 1


factorial = [1] * MAX_N
def calc_factorial():
    for i in range(1, MAX_N):
        factorial[i] = i * factorial[i - 1] % mod


def comb(n, k):
    a = factorial[n] % mod
    b = (factorial[k] * factorial[n - k]) % mod
    b_ = pow(b, mod - 2, mod)
    return (a * b_) % mod


# 素因数分解
factorization(M)

# 階乗を用意
calc_factorial()

ans = 1
for k, v in factorize_result.items():
    ans *= comb(N + v - 1, v) % mod

print(ans % mod)


Measured memory_bytes: 7028
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

X,N=nm()
p=nl()
cur=0
while(1):
    min_X=X-cur
    max_X=X+cur
    if(min_X not in p):
        print(min_X)
        sys.exit(0)
    if(max_X not in p):
        print(max_X)
        sys.exit(0)
    cur+=1


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

bool era[252525];

int main(){
  REP(i,252525)era[i]=true;
  era[0]=false;
  era[1]=false;
  vi ps(25252,1000000000);
  int psiter = 0;
  FOR(i,2,252525){
    if(!era[i])continue;
    ps[psiter] = i;
    psiter++;
    if(psiter==25252)break;
    int iter = 2*i;
    while(iter < 252525){
      era[iter] = false;
      iter += i;
    }
  }
  while(true){
    int n;
    cin>>n;
    if(n==0)break;
    int cnt = 0;
    REP(i,psiter){
      int p = ps[i];
      if(p>=n)break;
      int s = n-p;
      if(s<p)break;
      if(binary_search(ALL(ps),s)){
        ++cnt;
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
/*
直径がもともとK以下なら0でよくて、Kより大きいならちょうどKにしたいはず
根付き木で考えた場合、全部深さがK/2以下くらいならよさそう？
でも実際は、一つの葉の深さだけ大きくて残りの葉の深さを減らすだったり、そもそも根自体を使わない選択肢もある
出来上がるのも木で、距離がKになる葉の組みが存在する
それらを結んで、そこからのそれはそいつらを越さないようにするので一意に決まる
つまり？距離がKの2点を選ぶのが2e6通り
そこから進んでいくのが2e3通り？
距離がKの点はKが2だったりするとうにで沢山
距離がKの点でも一回見たやつはなくすとかで案外？
やってみよう！
*/
int d[2005];
struct e{int a,b,d;};
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

signed main(){
  int n,k;cin>>n>>k;
  vector<int> edge[n];
  for(int i=0;i<n-1;i++){
    int a,b;cin>>a>>b;a--;b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  int ans=0;
  if(k&1){
    queue<e> que;
    for(int a=0;a<n;a++){
      for(int b:edge[a]){
        que.push({a,b,0});
        que.push({b,a,0});
        int res=0;
        while(que.size()){
          e p=que.front();que.pop();
          int u=p.a,pre=p.b,d=p.d;
          res++;if(d==k/2)continue;
          for(int q:edge[u]){
            if(q==pre)continue;
            que.push({q,u,d+1});
          }
        }
        chmax(ans,res);
      }
    }
    cout<<n-ans<<endl;
  }
  else{
    queue<e> que;
    for(int a=0;a<n;a++){
      que.push({a,-1,0});
      int res=0;
      while(que.size()){
        e p=que.front();que.pop();
        int u=p.a,pre=p.b,d=p.d;
        res++;if(d==k/2)continue;
        for(int q:edge[u]){
          if(q==pre)continue;
          que.push({q,u,d+1});
        }
      }
      chmax(ans,res);
    }
    cout<<n-ans<<endl;
  }
}

/*
解説AC
これは解けてよかったんじゃないか？なんか根付き木がダメなのはそうで
両端全探索も多分うまく実装して差がKのペアを全部ちょうど一回ずつだけ試せれば通せたとは思うけど流石にやばすぎ
中心って概念知らなかったけど両端全探索でも結局やろうとしていたこと自体はほぼ一緒なんだよな
悲しいね
とりあえず中心って概念は覚えよう　木だけじゃなくて距離の上限に対して強そう？結局木構造にしか使えない気もするけど
*/


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a;  cin >> n >> a;
    if (n % 500 <= a) {
      cout << "Yes" << '\n';
    } else {
      cout << "No" << '\n';
    }

    return 0;
}


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

int main(){
    int health, n;
    cin >> health >> n;
    vector<int> damage(n);
    for(int i = 0; i < n; i++){
        cin >> damage[i];
        health -= damage[i];
    }
    
    if(health <= 0){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
}

Measured memory_bytes: 640
w,h,n = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]

a1,a2,a3,a4 = 0,w,0,h
for i in range(n):
    if l[i][2] == 1:
        a1 = max(l[i][0], a1)
    elif l[i][2] == 2:
        a2 = min(l[i][0], a2)
    elif l[i][2] == 3:
        a3 = max(l[i][1], a3)
    else:
        a4 = min(l[i][1], a4)

if a2-a1 <= 0 or a4-a3 <= 0:
    print(0)
else:
    print((a2-a1)*(a4-a3))


Measured memory_bytes: 3064
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
std::string s[3];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (size_t i = 0; i < 3; i++)
	{
		in >> s[i];
	}

	int32_t count = 0;
	for (size_t i = 0; i < N; i++)
	{
		char ss[3] = { s[0][i],s[1][i],s[2][i], };
		std::sort(ss, ss + 3);
		if (ss[0] == ss[1])
		{
			if (ss[1] == ss[2]) {

			}
			else {
				++count;
			}
		}
		else {
			if (ss[1] == ss[2]) {
				++count;
			}
			else {
				++count;
				++count;
			}
		}

	}
	out << count << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >>n;
  int n2=0;
  int ans =1;
  int ans2 =1;
  for(int i=0;i<n;i++){
    int m;
    cin >>m;
    if(m%2==0){
      ans2 *=2;
    }
    ans *=3;
  }
  cout << ans - ans2;
    
  
}


Measured memory_bytes: 256
//#include<stdio.h>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
#include<bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(false)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf

typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;

int main()
{
    fast;

    int n;
    vii v;
    while(cin >> n)
    {
        v.clear();

        int i=0 , x;

        for(; i<n; i++)
        {
            cin >> x;
            v.push_back(x);
        }

        LL mxe = *max_element(v.begin(), v.end()) , mini = 1000000000 ,sum=0 , df=0;
        //cout << mxe << "\n";
        LL tmini = mini;
        int  j=0 ;

        for(i=-101; i<=100; i++)
        {
            sum=0;

            for(j=0; j<n; j++)
            {
                df = i > v[j] ? i - v[j] : v[j] - i ;

                sum+=(df * df);
            }

            mini = min(mini, sum);
        }


       // if(mini == tmini) mini = 0;

        cout << mini << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
//به نامش
//how we code is who we are :))
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
const ll MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7;

struct pair_hash {
	template <class T1, class T2>
		std::size_t operator () (const std::pair<T1,T2> &p) const {
			auto h1 = std::hash<T1>{}(p.first);
			auto h2 = std::hash<T2>{}(p.second);

			return h1 ^ h2;  
		}
};

ll pw(ll te, ll tee) {
	if (tee == 0)	return 1;
	ll res = pw(te, tee / 2);
	return (tee % 2 ? te * res * res : res * res);
}

ll n, a, b, c, tmp;
vector <ll> v;

void Read_input() {
	cin >> n >> a >> b >> c;
	for (ll i = 1; i <= n; i++)	cin >> tmp,	v.pb(tmp);
}

map <pair <vector <ll>, ll>, ll> mp;


ll doit(vector <ll> vec) {
	ll ans = inf;
	for (ll i = 0; i < vec.size(); i++) {
		for (ll j = 0; j < vec.size(); j++) {
			for (ll k = 0; k < vec.size(); k++) {
				if (i == j or k == j or i == k)
					continue;
				ll o = abs(vec[i] - c) + abs(vec[j] - b) + abs(vec[k] - a);
				ans = min(o, ans);
			}
		}
	}
	return ans;
}

ll dom(vector <ll> vec, ll m) {
	sort(v.begin(), v.end());
	pair <vector <ll> , ll> d = {vec, m};
	if (mp.count(d) != 0)	return mp[d];
	if (m == 0) {
		ll o = doit(vec);
		mp[d] = o;
		return o;
	}
	vector <ll> p = vec;
	ll ans = inf;
	for (ll i = 0; i < vec.size(); i++) {
		for (ll j = i + 1; j < vec.size(); j++) {
			p = vec;
			p.erase(p.begin() + j);
			p.erase(p.begin() + i);
			p.pb(vec[i] + vec[j]);
			ans = min(ans, dom(p, m - 1));
		}
	}
	mp[d] = ans;
	return ans;
}

void Solve() {
	ll ans = inf;
	for (ll i = 0; i <= n - 3; i++) {
		tmp = i * 10;
		vector <ll> k = v;
		tmp = (dom(k, i) + 10 * i);
		//cerr << tmp <<endl;
		ans = min(ans, tmp);
	}
	//vector <ll> f;
	cout << ans;

}


int main() {

	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	//freopen("input.txt", "r", stdin),	freopen("output.txt", "w", stdout);

	Read_input(),	Solve();
	return 0;
}


Measured memory_bytes: 4608
/*
 * $File: p1001.cpp
 * $Author: Wayne <tletletle@163.com>
 *
 * Task:
 *   Given two binary trees, we need to
 *   calculate the intersection or the
 *   union of them.
 *
 * Solution:
 *   Parsing. Graph theory.
 *   Just Build the trees and implement.
 */

#include <cstdio>
#include <cstring>

const int kMaxVtx = 100;
const int kMaxBuf = 512;
char buf[kMaxBuf];

struct TreeNode {
	TreeNode *son[2];
	TreeNode() {
		son[0] = son[1] = NULL;
	}
};

struct Tree {
	TreeNode *root;
	Tree() {
		root = NULL;
	}
} a, b, c;

TreeNode *BuildTree(int l, int r) {
	if (l > r) return NULL;
	TreeNode *res = new TreeNode;
	if (l + 1 == r - 1) return res;
	int mid, sum = 0;
	for (int i = l + 1; i <= r - 1; ++ i)
		if (buf[i] == '(') ++ sum;
		else if (buf[i] == ')') -- sum;
		else if (buf[i] == ',' && sum == 0) mid = i;
	res->son[0] = BuildTree(l + 1, mid - 1);
	res->son[1] = BuildTree(mid + 1, r - 1);
	return res;
}

void ReadTree(Tree &des) {
	scanf("%s", buf);
	des.root = BuildTree(0, strlen(buf) - 1);
}

TreeNode *DfsIntersection(TreeNode *u, TreeNode *v) {
	if (!u || !v) return NULL;
	TreeNode *res = new TreeNode;
	res->son[0] = DfsIntersection(u->son[0], v->son[0]);
	res->son[1] = DfsIntersection(u->son[1], v->son[1]);
	return res;
}

TreeNode *DfsUnion(TreeNode *u, TreeNode *v) {
	if (!u && !v) return NULL;
	TreeNode *res = new TreeNode;
	res->son[0] = DfsUnion(u ? u->son[0] : NULL, v ? v->son[0] : NULL);
	res->son[1] = DfsUnion(u ? u->son[1] : NULL, v ? v->son[1] : NULL);
	return res;
}

Tree GetIntersection(const Tree &a, const Tree &b) {
	Tree res;
	res.root = DfsIntersection(a.root, b.root);
	return res;
}

Tree GetUnion(const Tree &a, const Tree &b) {
	Tree res;
	res.root = DfsUnion(a.root, b.root);
	return res;
}

void OutputTree(TreeNode *cur) {
	if (!cur) return;
	putchar('(');
	OutputTree(cur->son[0]);
	putchar(',');
	OutputTree(cur->son[1]);
	putchar(')');
}

int main() {
	static char cmd[2];
	while (scanf("%s", cmd) != EOF) {
		ReadTree(a);
		ReadTree(b);
		if (cmd[0] == 'i') c = GetIntersection(a, b);
		else c = GetUnion(a, b);
		OutputTree(c.root);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 992
#include <stdio.h>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
//#define rep(i,n) for(i=0; i < n; i++)
typedef long long ll;
#define MAX 100000

vector<int> V(MAX);


int main(){
    ll X,Y;
    cin >> X >> Y;
    int cnt = 0;
    while(true){
        if(Y<X) break;
        Y/=2;
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 640
n = int(input())
hb = 0
ta = 0
hbta = 0
ab = 0
for i in range(n):
  s = input()
  ab += s.count('AB')
  f = (s[len(s) -1] == 'A')
  g = (s[0] == 'B')
  if f and g:
    hbta += 1
  elif f:
    ta += 1
  elif g:
    hb += 1
if not hb and not ta and not hbta:
  print(ab)
elif not hb and not ta:
  print(ab + hbta - 1)
elif not hb or not ta:
  print(ab + hbta)
else:
  print(ab + hbta + min(hb, ta))

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

long long gcd(long long p, long long q) {
	if (p < q) swap(p, q);
	if (p % q == 0) return q;
	else return gcd(p / q, p % q);
}
int keta(long long p, int q) {
	if (p / 10 == 0) return q + 1;
	else return keta(p / 10, q + 1);
}
long long kaijo(int p, int q) {
	if (p == 1) return q;
	else return kaijo(p - 1, p * q);
}

int main() {
	long N;
	cin >> N;
	vector<long> vec(N);
	rep(i, N) cin >> vec[i];
	sort(vec.begin(), vec.end());
	pair<long, long> length;
	bool finished = false;
	rep(i, N){
		if (length.first == vec[N - 1 - i]) {
			if (finished == false) { 
				swap(length.first, length.second); 
				finished = true;
			}
			else break;
		}
		else length.first = vec[N - 1 - i];
	}
	cout << length.first * length.second << endl;
}

Measured memory_bytes: 4032
sx,sy,tx,ty = map(int,input().split())
x_move = tx - sx
y_move = ty - sy
ans = ""
for i in range(x_move):
  ans += "R"
for j in range(y_move):
  ans += "U"
for a in range(x_move):
  ans += "L"
for b in range(y_move):
  ans += "D"
ans += "L"
for i in range(y_move + 1):
  ans += "U"
for i in range(x_move + 1):
  ans += "R"
ans += "D"
ans += "R"
for i in range(y_move + 1):
  ans += "D"
for i in range(x_move + 1):
  ans += "L"
ans += "U"
print(ans)

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

int main() {




	int n, k;
	int min = 0;
	cin >> n >> k;

	int arr[n];

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

	sort(arr, arr + n);
	for (int j = 0; j < k; j++) {
		min = min + arr[j];
	}

	cout << min;

}

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

using namespace std;

int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  long long ans = 0;
  long long d = min(c, b);
  ans += d * 2;
  c -= d;
  b -= d;
  if (c > 0) {
    ans += min(c, a + 1);
  } else {
    ans += b;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
L,R = map(int,input().split())


dp = []

for i in range(62):

    nowA = []

    for i in range(2):

        nowB = []

        for i in range(2):

            nowC = []

            for i in range(2):

                nowC.append(0)

            nowB.append(nowC)

        nowA.append(nowB)

    dp.append(nowA)

dp[0][0][0][0] = 1
#print (dp[3][0][0][0])


for i in range(61):

    i += 1
    keta = 62-i

    lb = (L >> (keta-1)) % 2
    rb = (R >> (keta-1)) % 2


    for j in range(2):
        for k in range(2):
            for m in range(2):

                pre = dp[i-1][j][k][m]

                for x in range(2):
                    for y in range(2):

                        nj = j
                        nk = k
                        nm = m

                        if x == 1 and y == 0:
                            continue;

                        if x != y and m == 0:
                            continue;

                        if j == 0 and lb == 1 and x == 0:
                            continue;

                        if k == 0 and rb == 0 and y == 1:
                            continue;

                        if j == 0 and lb == 0 and x == 1:
                            nj = 1

                        if k == 0 and rb == 1 and y == 0:
                            nk = 1

                        if m == 0 and x == 1 and y == 1:
                            nm = 1


                        dp[i][nj][nk][nm] += dp[i-1][j][k][m]
                        dp[i][nj][nk][nm] %= 10 ** 9 +7

ans = 0

for j in range(2):
    for k in range(2):

        ans += dp[-1][j][k][1]

print (ans % (10 ** 9 + 7))

Measured memory_bytes: 40048
from heapq import heappop, heappush


def p_d():
    n, m = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]

    ab.sort()
    ans = 0
    j = 0
    H = []

    for i in range(1, m + 1):
        while j < n and ab[j][0] <= i:
            heappush(H, -ab[j][1])
            j += 1

        if H:
            ans -= heappop(H)

    print(ans)


if __name__ == '__main__':
    p_d()


Measured memory_bytes: 20680
N = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for i in range(N-2):
    for j in range(i, N-1):
        for k in range(j, N):
            a, b, c = L[i], L[j], L[k]
            if a == b or b == c or c == a:
                continue
            elif a+b>c and b+c>a and c+a>b:
                cnt+=1

print(cnt)


Measured memory_bytes: 9056
#include <stdio.h>
int main(void) {
  int i, n[100000], num;

  i = 0;  num = 0;
  do {
    scanf("%d", &n[i]);
    num++;
    i++;
  } while (n[i - 1] != 0);

  for (i = 0; i < num - 1; i++){
    printf("Case %d: %d\n", i + 1, n[i]);
  }
  return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;

int main()
{		
	
    IOS
    ll n;
    cin>>n;
    ll a[n+1],b[n+1];
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }

    memset(b,0,sizeof(b));

    for(ll i=n;i>=1;i--)
    {
           ll count=0;
            for(ll j=2*i;j<=n;j+=i)
            {
                count+=b[j];
            }
            if((count%2)==a[i])
            {
                b[i]=0;
            }
            else 
                b[i]=1;
        
    }
    ll m=0;
    for(ll i=1;i<=n;i++)
        if(b[i]==1) m++;

    cout<<m<<endl;
    for(ll i=1;i<=n;i++)
        if(b[i]==1) cout<<i<<" ";
    cout<<endl;

    

    
    



    
}


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

using namespace std;

bool checkBreak(int T,int L){
    if(T <= 0 || T > L) return 1;
    return 0;
}

int main(){
    int N,T,H,L;
    cin >> N >> T >> H >> L;
    vector<int> t(N),h(N);
    for(int i = 0 ; i < N ; i++){
        cin >> t[i] >> h[i];
    }
    int p = 0,coin = 0;
    vector<bool> flg(N,0);
    while(1){
        if(t[p] > 0){
            t[p]--; T++;
            coin += 10;
        }else{
            h[p]--; H++;
            coin += 100;
        }
        if(coin >= 90){
            coin -= 90;
            t[p] += coin/10;
            T -= coin/10;
            coin = 0;
        }
        if(checkBreak(T,L) || flg[p]) break;
        if(t[p] == 0 && h[p] == 0){
            flg[p] = 1;
        }
        p = (p + 1) % N;
    }
    cout << p+1 << endl;
    return 0;
}

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

int main() {
   char S[5];
   char moji[] = {"ABC"};
   int count = 0;

   scanf("%s", S);

   for(int i = 0; i < strlen(moji); i++) {
      if(S[i] != moji[i]) {
         count++;
         break;
      }
   }
   if(count > 0) {
      printf("%s\n", moji);
   }else {
      printf("ARC\n");
   }

   return 0;

}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int a, b; cin >> a >> b;

    if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        String[] words=new String[n];
        for(int i=0;i<n;i++){
            words[i]=scn.next();
        }
        int flag=0;
        char b='a';
        for(int i=0;i<n;i++){
            char a=words[i].charAt(0);
            if(i>0&&a!=b){
                flag++;
                break;
            }
            b=words[i].charAt(words[i].length()-1);
            int f=0;
            for(int j=i+1;j<n;j++){
                if(words[i].equals(words[j])){
                    f++;
                    break;
                }
            }
            if(f>0){
                flag++;
                break;
            }
        }
        if(flag>0){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 23124
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

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

Node *root, *NIL;

Node * find(Node *u, int k) {
  while (u != NIL && k != u->key) {
    if (k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    cin >> com;
    if ( com == "insert") {
      scanf("%d", &x);
      insert(x);
    } else if (com == "find") {
      scanf("%d", &x);
      Node *t = find(root, x);
      if (t != NIL) printf("yes\n");
      else printf("no\n");
    } else if (com == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 22080
import itertools
import functools
import math
from collections import Counter
from itertools import combinations

A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
A3=list(map(int,input().split()))
N=int(input())
for i in range(N):
    chk = int(input())
    for m in range(3):
        if A1[m] == chk:
            A1[m] = 0
        if A2[m] == chk:
            A2[m] = 0
        if A3[m] == chk:
            A3[m] = 0



if (A1[0] == 0 and A1[1] == 0 and A1[2] == 0) \
or (A2[0] == 0 and A2[1] == 0 and A2[2] == 0) \
or (A3[0] == 0 and A3[1] == 0 and A3[2] == 0) \
or (A1[0] == 0 and A2[0] == 0 and A3[0] == 0) \
or (A1[1] == 0 and A2[1] == 0 and A3[1] == 0) \
or (A1[2] == 0 and A2[2] == 0 and A3[2] == 0) \
or (A1[0] == 0 and A2[1] == 0 and A3[2] == 0) \
or (A1[2] == 0 and A2[1] == 0 and A3[0] == 0) :
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9516
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	int a, d, p, x;
	ll sum = 0;
	string s, t;
	cin >> s;
	s.push_back('E');
	rep(i, 0, s.size()) {
		if (s[i] == 'B' && s[i + 1] == 'C')t.push_back('D'), i++;
		else t.push_back(s[i]);
	}
	rep(i, 0, t.size() + 1) {
		a = d = x = 0;
		p = i;
		while (t[i] == 'A' || t[i] == 'D') {
			i++;
		}
		rep(i2, p, i) {
			if (t[i2] == 'A')sum += (i - i2 - ++x);
		}
	}
	printf("%lld\n", sum);
	return 0;
}


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

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int grid[3][n+1];
    for(int i=1;i<=2;i++){
    	for(int j=1;j<=n;j++){
    		cin >> grid[i][j];
		}
	}
    for(int i=1;i<=2;i++){
    	for(int j=1;j<=n;j++){
    		if(i==1 && j==1) continue;
    		if(i==1 && j>1) grid[i][j] += grid[i][j-1];
    		else if(i==2 && j==1) grid[i][j] += grid[i-1][j];
    		else grid[i][j] += max(grid[i-1][j],grid[i][j-1]);
		}
	}
	cout << grid[2][n] << endl;
    
	return 0;
}


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

vector<int> x, y;
int n;

double dist(int i, int j) {
    double dx = x[i]-x[j];
    double dy = y[i]-y[j];
    return sqrt(dx*dx + dy*dy);
}

long double q(int k, int bit, double sum) {
    if (bit == (1<<n) - 1) return sum;
    double k_sum = 0.0;
    rep(i,n) {
        if (!((bit>>i)&1)) {
            int next_bit = bit | (1<<i);
            double res = sum + dist(k,i);
            k_sum += q(i, next_bit, res);
        }
    }
    return k_sum;
}

int main() {
    cin >> n;
    x.resize(n);
    y.resize(n);
    rep(i,n) cin >> x[i] >> y[i];
    int res = 1;
    for (int i = 1; i <= n; ++i) res *= i;
    long double ans = 0;
    rep(i,n) ans += q(i, 1<<i, 0) / res;
    cout << std::fixed;
    cout << std::setprecision(10) << ans << endl;
}

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

public class Main {
	public static void main(String[] args) { new Main(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);

	int a, b;	
	
	Main() {
		a = in.nextInt();
		b = in.nextInt();
		if (a <= 9 && b <= 9)
			out.println((a * b));
		else
			out.println(-1);

		out.close();
	}

	
	
	int abs(int x) { if (x < 0) return -x; return x; }
	long abs(long x) { if (x < 0) return -x; return x; }
	int max(int x, int y) { if (x < y) return y; return x; }
	int min(int x, int y) { if (x > y) return y; return x; }
	long max(long x, long y) { if (x < y) return y; return x; }
	long min(long x, long y) { if (x > y) return y; return x; }

	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }

		void intArr(int sz, int[] x) { for (int i = 0; i < sz; i++) x[i] = nextInt(); }
		void longArr(int sz, long[] x) { for (int i = 0; i < sz; i++) x[i] = nextLong(); }
		void doubleArr(int sz, double[] x) { for (int i = 0; i < sz; i++) x[i] = nextDouble(); }
	}
}



Measured memory_bytes: 21204