akhauriyash/Code-Regression huggingface dataset:
/**
 *      AGC 3 A
 *      author  : kyomukyomupurin
 *      created : 2018-10-11 06:00:36
**/

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define int64 long long
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string S; cin >> S;
    if ((S.find("S") != string::npos && S.find("N") == string::npos) || (S.find("S") == string::npos && S.find("N") != string::npos)){
        cout << "No" << endl;
    }
    else if ((S.find("E") != string::npos && S.find("W") == string::npos) || (S.find("E") == string::npos && S.find("W") != string::npos)){
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i = 0; i < n; i++)
const int INF = 1e9;
const int N = 1e5+7;
const int MOD = 1e9+7;

int a[N];

int main(){

  ll X,Y; cin >> X >> Y;
  int ans = 0;
  while( X <= Y){
    X *= 2;
    ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
const int MAX = 1010000;
const int MOD = 1000000007;

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(int n, int 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 x,y;
	cin>>x>>y;
	ll X=INF,Y=INF;
	for(ll i=0;i<=x;i++){
		ll zanx=x-i;
		if(zanx%2!=0){
			continue;
		}
		ll k=zanx/2;
		if(y==i*2+k){
			X=i;
			Y=k;
		}
	}
	if(X==INF){
		cout << 0;
		return 0;
	}
    COMinit();

    // 計算例
    cout << COM(X+Y,X) << endl;	
	return 0;
}

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

int main(){
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int cnt = 0;
  for(int i = 0; i <= a; i++){
    for(int j = 0; j <= b; j++){
      for(int k = 0; k <= c; k++){
        int ans = 500 * i + 100 * j + 50 * k;
        if(ans == x) cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3596
s=input()
t=input()
arr1=[0]*26
arr2=[0]*26
check='abcdefghijklmnopqrstuvwxyz'
for i in range(26):
  arr1[i]=s.count(check[i])
  arr2[i]=t.count(check[i])
arr1=sorted(arr1)
arr2=sorted(arr2)
for i in range(26):
  if arr1[i]!=arr2[i]:
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 3632
from collections import Counter
import math

def main():
    num = int(input())
    data = list(map(int, input().split()))
    count_num = Counter(data)

    overlap_num = 0
    for ele, value in count_num.items():
        if value > 1:
            overlap_num += value - 1

    ans = num - math.ceil(overlap_num / 2) * 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62124
a = int(input())


if 400 <= a and a <= 599:
    print(8)
elif 600 <= a and a <= 799:
    print(7)

elif 800 <=  a and a <= 999:
    print(6)
elif 1000 <= a and a <= 1199:
    print(5)

elif 1200 <= a and a <= 1399:
    print(4)
elif 1400 <= a and a <= 1599:
    print(3)
elif 1600 <= a and a <= 1799:
    print(2)

elif 1800 <= a and a <= 1999:
    print(1)


Measured memory_bytes: 9188
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        Console.WriteLine(Enumerable.Repeat(0, n).Select(_ => Console.ReadLine().Split()).Select(x => (x[1] == "JPY" ? 1 : 380000) * double.Parse(x[0])).Sum());
    }
}

Measured memory_bytes: 11348
#include<cstdio>
#include<queue>
using namespace std;
int n,a,b,c[200000],vis[200000];
vector<int> w[200000];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&a,&b);
		w[a].push_back(b);
		w[b].push_back(a);
	}
	c[n]=vis[1]=vis[n]=1;
	c[1]=0;
	queue<int> q;
	q.push(1);
	q.push(n);
	while(!q.empty())
	{
		int u=q.front();q.pop();
		for(int i=0;i<w[u].size();i++)
			if(!vis[w[u][i]])
			{
				c[w[u][i]]=c[u];
				vis[w[u][i]]=1;
				q.push(w[u][i]);
			}
	}
	int cnt=0;
	for(int i=1;i<=n;i++)cnt+=c[i];
	puts(cnt<n-cnt?"Fennec":"Snuke");
	return 0;
}

Measured memory_bytes: 9728
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int n,Q,k;

struct edge{
  int to;
  ll cost;

  edge(int t, ll c) : to(t),cost(c) {}
};

bool operator < (const edge& a, const edge& b) {
  return a.cost > b.cost;
}

vector<edge> g[100005];
ll dist[100005];
const ll INF = 1e17;

int main() {
  cin >> n;

  for(int i = 0; i < n - 1; i++) {
    int a,b; ll c;
    cin >> a >> b >> c;
    a--; b--;
    g[a].push_back(edge(b,c));
    g[b].push_back(edge(a,c));
  }
  cin >> Q >> k;
  priority_queue<edge> q;
  /* q.push(edge(1,100));
  q.push(edge(1,1000));

  for(int i = 0; i < 2; i++) {
    edge tmp = q.top();
    q.pop();
    cout << tmp.cost << endl;
    }*/
  
  fill(dist,dist+n,INF);
  q.push(edge(k-1,0));
  dist[k-1] = 0;
  
  while(!q.empty()) {
    edge e = q.top();
    q.pop();
    int v = e.to;
    if(dist[v] < e.cost) continue;
    for(int i = 0; i < g[v].size(); i++) {
      edge u = g[v][i];
      if(dist[u.to] > dist[v] + u.cost) {
	dist[u.to] = dist[v] + u.cost;
	q.push(edge(u.to,dist[u.to]));
      }
    }
  }

  //for(int i = 0; i < n; i++) cout <<"iji"<< dist[i] << endl;

  for(int i = 0; i < Q; i++) {
    int x,y;
    cin >> x >> y;
    x--;y--;
    cout << dist[x] + dist[y] << endl;
  }
  
}


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

int main() {
    string S;
    cin >> S;
    long long ans=0;
    for (int bit=0; bit < (1<<S.size()-1); bit++) {
        string tmp;
        for (long long p=0; p<S.size(); p++) {
            tmp += S.at(p);
            if (!(bit & (1<<p))) {
                ans += stol(tmp);
                tmp = "";
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

void move_E(int sai[]){
	int temp;
	int i;

	temp = sai[1];
	sai[1] = sai[4];
	sai[4] = sai[6];
	sai[6] = sai[3];
	sai[3] = temp;
	
}


void move_S(int sai[]){
	int temp;
	int i;
	temp = sai[1];
	sai[1] = sai[5];
	sai[5] = sai[6];
	sai[6] = sai[2];
	sai[2] = temp;
}

void move_R(int sai[]){
	int temp;
	int i;
	temp = sai[2];
	sai[2] = sai[3];
	sai[3] = sai[5];
	sai[5] = sai[4];
	sai[4] = temp;
}

int sarch(int sai[], int sai2[]){
	int re[7];
	int i, j, k;
	int flag = 0;
	int ori[7];
	for(i=0; i<7; i++)
		ori[i] = sai[i];


	//printf("top:1,2,6,5\n");
	/* top:1,2,6,5 */
	for(j=0; j< 4; j++){
		for(i=0; i< 4; i++){
			flag = 1;
//			printf("%d%d%d%d%d%d %d%d%d%d%d%d\n", sai[1],sai[2],sai[3],sai[4],sai[5],sai[6],sai2[1],sai2[2],sai2[3],sai2[4],sai2[5],sai2[6]);
			for(k=1; k< 7; k++){
				if(sai[k] != sai2[k])
					flag *= 0;
			}			

			move_R(sai);
			if(flag == 1)
				break;
		}
		if(flag == 1)
			break;
		move_S(sai);
	}

	if(flag == 0){
		//printf("top:3\n");
		/* top:3 */
		for(i=0; i<7; i++)
		sai[i] = ori[i];

		move_E(sai);
		move_E(sai);
		move_E(sai);
		for(i=0; i< 4; i++){
			flag = 1;
//			printf("%d%d%d%d%d%d %d%d%d%d%d%d\n", sai[1],sai[2],sai[3],sai[4],sai[5],sai[6],sai2[1],sai2[2],sai2[3],sai2[4],sai2[5],sai2[6]);
			for(k=1; k< 7; k++){
				if(sai[k] != sai2[k])
					flag *= 0;
			}
			move_R(sai);
			if(flag == 1)
				break;
		}
	}

	if(flag == 0){
		/* top:4 */
		//printf("top:4\n");
		for(i=0; i<7; i++)
			sai[i] = ori[i];

		move_E(sai);
		for(i=0; i< 4; i++){
			flag = 1;
//			printf("%d%d%d%d%d%d %d%d%d%d%d%d\n", sai[1],sai[2],sai[3],sai[4],sai[5],sai[6],sai2[1],sai2[2],sai2[3],sai2[4],sai2[5],sai2[6]);
			for(k=1; k< 7; k++){
				if(sai[k] != sai2[k])
					flag *= 0;
			}
			move_R(sai);
			if(flag == 1)
				break;
		}
	}
	
	return flag;
	
}

int main(){
	int sai[7];
	int sai2[7];
	int i;
	char com[256];

	int temp;
	int q;
	int d1, d2;

	for(i=0; i<6; i++){
		scanf("%d", &sai[i+1]);
	}

	for(i=0; i<6; i++){
		scanf("%d", &sai2[i+1]);
	}
	
	if(sarch(sai, sai2) == 1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	

	return 0;

}


Measured memory_bytes: 2100
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}

int main(void){
	int m=in(),f=in(),b=in();
	int t=b-m;
	if(t<=0)puts("0");
	else if(f-t<0)puts("NA");
	else print(t);
		
	return 0;
}

Measured memory_bytes: 1788
// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
    out << '[' << p.first << ", " << p.second << ']';
    return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
    while (*name == ',' || *name == ' ')
        name++;
    std::cerr << name << " { ";
    for (const auto &v : arg)
        cerr << v << ' ';
    cerr << " }\n";
}
template <typename Arg1, typename... Args>
void PC(const char *names, Arg1 &&arg1, Args &&... args)
{
    while (*names == ',' || *names == ' ')
        names++;
    const char *comma = strchr(names, ',');
    std::cerr.write(names, comma - names) << " { ";
    for (const auto &v : arg1)
        cerr << v << ' ';
    cerr << " }\n";
    PC(comma, args...);
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
    std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    std::cerr.write(names, comma - names) << " = " << arg1;
    ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 2e5 + 5, MOD = 1000000007;

void solveCase(int caseNo)
{
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x)
        cout << "Yes\n";
    else
        cout << "No\n";
}

int main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    for (int i = 1; i <= t; ++i)
    {
        solveCase(i);
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


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

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

    vector<int> v(26);

    for(auto c : s) v[c - 'a']++;

    int fl = 1;
    
    for(auto x : v) fl &= x <= 1;

    if(fl) cout << "yes" << endl;
    else cout << "no" << endl;

    return 0;
}

Measured memory_bytes: 256
import heapq
 
X, Y, A, B, C = [int(i) for i in input().split()]
P = sorted([int(i) for i in input().split()])[-X:]
Q = sorted([int(i) for i in input().split()])[-Y:]
R = sorted([int(i) for i in input().split()])[::-1]
heapq.heapify(P)
heapq.heapify(Q)
i = 0
while(True):
    if P[0] >= R[i] and Q[0] >= R[i]:
        break
    if P[0] > Q[0]:
        if Q[0] < R[i]:
            heapq.heappop(Q)
            heapq.heappush(Q, R[i])
    else:
        if P[0] < R[i]:
            heapq.heappop(P)
            heapq.heappush(P, R[i])
    i += 1
    if i == len(R):
        break
print(sum(P) + sum(Q))

Measured memory_bytes: 116648
#include <stdio.h>
#include<stdlib.h>

int main(void)
{
	char a[200001];
	int i,s;
	scanf("%s",a);
	s=strlen(a);
	for(i=0;i<s;i++){
		if(a[i]=='?'){
			a[i]='D';
		}
	}
	for(i=0;i<s;i++)printf("%c",a[i]);
	return 0;
}

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

int n;  
string s,a,b,c;

int main() {
  cin >> n >> a >> b >> c;
  int ans=0,cnt=0;
  rep(i,n){
    cnt=0;
    if(a[i]==b[i]) cnt++;
    if(b[i]==c[i]) cnt++;
    if(c[i]==a[i]) cnt++;
    if(cnt==1) ans++;
    if(cnt==0) ans+=2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def prime(n):
    is_prime=[True]*(n+1)
    is_prime[0],is_prime[1]=False,False
    for i in range(2,int(n**0.5)+1):
        if not is_prime[i]:continue
        for j in range(i*2,n+1,i):
            is_prime[j]=False
    return [i for i in range(n+1) if is_prime[i]]


q=int(input())
LR=[list(map(int,input().split())) for _ in range(q)]
prime=prime(10**5)

DP=[0]*(10**5+1)
for i in prime:
    if i*2-1 in prime:
        DP[i*2-1]=1

for i in range(1,10**5+1):
    DP[i]=DP[i-1]+DP[i]

for l,r in LR:
    print(DP[r]-DP[l-1])

Measured memory_bytes: 72920
import java.util.Scanner;
import java.util.stream.IntStream;

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

        String s = sc.next();

        System.out.println(solve(s));

        sc.close();
    }

    static int solve(String s) {
        return IntStream.range(0, s.length()).map(i -> {
            char t = s.charAt(i);
            char a = (i % 2 == 0) ? 'g' : 'p';

            if (a == t) {
                return 0;
            } else if (a == 'p') {
                return 1;
            } else {
                return -1;
            }
        }).sum();
    }
}

Measured memory_bytes: 28972
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
	VI a(3); rep(i,3) cin>>a[i]; sort(ALL(a));
	cout<<a[0]+a[1]<<endl;
	return 0;
}


Measured memory_bytes: 256
use proconio::input;
use std::cmp::Ordering;
use std::fmt::Debug;
use std::mem::swap;
use proconio::marker::Usize1;

fn next_permutation<T>(mut v: Vec<T>) -> Option<Vec<T>>
    where T: Ord + Debug {
    let mut t = Vec::new();
    t.push(v.pop().unwrap());
    while let Some(mut lst) = v.pop() {
        if lst.cmp(t.last().unwrap()) != Ordering::Less {
            t.push(lst);
            continue;
        }
        t.sort();
        for i in 0..t.len() {
            if t[i] > lst {
                swap(&mut t[i], &mut lst);
                break;
            }
        }
        v.push(lst);
        return Some(v.into_iter().chain(t).collect::<Vec<T>>());
    }
    None
}

fn main()
{
    input! {
    n:usize,
    m:usize,
    edge:[(Usize1,Usize1);m],
    }
    let mut v = (0..n).collect::<Vec<usize>>();

    let mut ans = 0;
    loop {
        let mut exist = true;
        for i in 0..n - 1 {
            let (x, y) = (v[i], v[i + 1]);
            if let Some(_) = edge.iter()
                .find(|&t| (t.0, t.1) == (x, y) || (t.1, t.0) == (x, y)) {
                continue;
            } else {
                exist = false;
                break;
            }
        }
        if exist {
            ans += 1;
        }
        if let Some(nxt) = next_permutation(v) {
            v = nxt;
            if v[0] > 0 {
                break;
            }
        } else {
            break;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2176
N = int(input())
A = list(map(int,input().split()))

ans = [0 for x in range(N+1)]
ans_m = 0
ans_a = []
for i in range(N,0,-1):
    s = 0
    for j in range(2*i,N+1,i):
        if ans[j] == 1:
            s += 1
    if s & 1 != A[i-1]:
        ans[i] = 1
        ans_m += 1
        ans_a.append(i)

print(ans_m)
if ans_m > 0:
    print(" ".join(map(str,ans_a)))



Measured memory_bytes: 19836
#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 long double ld;
typedef pair<int,int> P;

int main(){ 
  int n;
  cin >> n;
  ll res = 0;
  vector<ll> cnt(n + 1, 0);
  for (int x = 1; x <= n; x++) {
    cnt[x]++;
    for (ll y = x + x; y <= n; y += x) {
      cnt[y]++; 
    }
    //cout << cnt[x] << endl;
    res += cnt[x] * x;
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 81380
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop, heapify
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

LR = [[A[-1], A[-1]]]
for i, b in enumerate(A[::-1][1:], 1):
	if N-i+1 < 30:
		LR.append([-(-LR[-1][0]//2)+b, min(LR[-1][1]+b, pow(2, N-i+1))])
	else:
		LR.append([-(-LR[-1][0]//2)+b, LR[-1][1]+b])


LR = LR[::-1]
if LR[0][0] <= 1 <= LR[0][1]:
	pass
else:
	print(-1)
	exit()

ans = 1
tmp = 1
for i, (L, R) in enumerate(LR[1:], 1):
	tmp = min(2*tmp-A[i], R-A[i])
	ans += tmp+A[i]

print(ans)

Measured memory_bytes: 32784
#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 ((i) = 0; (i) < (n); (i)++)
#define rep2(i, s, e) for ((i) = (s); (i) < (e); (i)++)
#define repd(i, n) for ((i) = (n)-1; (i) >= 0; (i)--)
#define rep2d(i, s, e) for ((i) = (e)-1; (i) >= (s); (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; }

#define MAXN 15
int c[MAXN], a[MAXN][MAXN];

int main()
{
    // cout << fixed << setprecision(5);

    // Failed to predict input format
    long long n, m, x;
    cin >> n >> m >> x;
    long long i, j, k;
    rep(i, n)
    {
        cin >> c[i];
        rep(j, m)
        {
            cin >> a[i][j];
        }
    }
    ll total = INF;
    rep(i, 1 << n)
    {
        ll tmp[m], tmpc = 0;
        rep(j, m)
            tmp[j] = 0;
        rep(j, n)
        {
            tmpc += ((i & (1 << j)) != 0) * c[j];
            rep(k, m)
            {
                tmp[k] += ((i & (1 << j)) != 0) * a[j][k];
            }
        }

        int flg = 1;
        rep(j, m)
        {
            if (tmp[j] < x)
                flg = 0;
        }
        if (flg)
        {
            total = min(total, tmpc);
        }
    }
    if (total == INF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << total << endl;
    }

    return 0;
}


Measured memory_bytes: 3576
S=list(input())
T=list(input())

ls=len(S)
lt=len(T)

anslist=[]

for i in range(ls-lt+1):
    ans=lt
    S_list=S[i:i+lt]
    for j in range(lt):
        if S_list[j]==T[j]:
            ans-=1
    anslist.append(ans)

print(min(anslist))

Measured memory_bytes: 9068
n = int(input().split()[0])
h_list = list(map(int, input().split()))

is_ok = True
before_n = 0
kotae_list = []

for i, h in enumerate(h_list[:-1]):
    if h_list[i] <= h_list[i+1]:
        # OK. 何も操作しなくてもクリアできる
        # 1つさげても前回値を下回らないなら、下げといた方がよい
        if before_n <= h_list[i] - 1:
            before_n = h_list[i] - 1

        else:
            # 下げれないときはそのまま
            before_n = h_list[i]
        kotae_list.append(before_n)
        continue
    else:
        if before_n <= h_list[i] - 1:
            # 1つさげても前回値を下回らないなら、下げることでクリアできる可能性がある
            if h_list[i] - 1 <= h_list[i+1]:
                # OK
                before_n = h_list[i] - 1
                kotae_list.append(before_n)
                continue
            else:
                # NG
                # 1つ下げたとしたもクリアできないのでダメ
                is_ok = False
                break
        else:
            # クリアできる可能性がない
            is_ok = False

# print('->'.join([str(x) for x in kotae_list]))

ans = 'Yes' if is_ok else 'No'
print(ans)

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

string S;
int x[4];

int main(){
 
cin>>S;

for(int i=0; i<S.size(); i++){
	if(S[i]=='N') x[0]=1;
	if(S[i]=='W') x[1]=1;
	if(S[i]=='S') x[2]=1;
	if(S[i]=='E') x[3]=1;
}

if(x[0]+x[2]==1||x[1]+x[3]==1) puts("No");
else puts("Yes");

return 0;
 
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>
#include <numeric>

using namespace std;

int main(void)
{ 
	int x, a, b;

	cin >> x >> a >> b;

	if (a >= b)
	{
		cout << "delicious" << endl;
	}
	else
	{
		if (b - a <= x)
		{
			cout << "safe" << endl;
		}
		else
		{
			cout << "dangerous" << endl;
		}
	}

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int X=N/1.08;
  if((int)(X*1.08)==N){
  cout << X << endl;
  }else if((int)((X+1)*1.08)==N){
    cout << X+1 << endl;
  }else{
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()

int main(){
    int i,j,k,n,m,l=1,s,t,flag;
    cin>>n>>m;
    vector<int> c(3,-1);
    for(i=0;i<m;i++){
        cin>>s>>t;
        if(c[s-1]==-1){
            c[s-1]=t;
        }else if(c[s-1]!=t){
            cout<<"-1";
            return 0;
        }
    }
    for(i=0;i<1000;i++){
        flag=0;
        if(i==10) l=2;
        if(i==100) l=3;
        if(l!=n) continue;
        vector<int> a(l);
        if(i<10){
            if(c[1]>=0 or c[2]>=0){
                cout<<"-1";
                return 0;
            }
            a[0]=i;
        }else if(i<100){
            if(c[2]>=0){
                cout<<"-1";
                return 0;
            }
            a[0]=i/10;
            a[1]=i%10;
        }else{
            a[0]=i/100;
            a[1]=(i/10)%10;
            a[2]=i%10;
        }
        for(j=0;j<3;j++){
            if(a[j]!=c[j] and c[j]!=-1){
                flag=1;
            }
        }
        if(flag==0){
            cout<<i;
            return 0;
        }
    }
    cout<<"-1";
    return 0;
}



Measured memory_bytes: 256
n = int(input())

def formula(x, p):
    return 0 if p>x else (x//p)+formula(x//p,p)

def calc(x):
    two = x//2
    two += formula(x//2, 2)
    five = formula(x//2, 5)
    return min(two, five)

print("%d"% (0 if n%2==1 else calc(n)) )

Measured memory_bytes: 3060
from fractions import gcd

N,M = list(map(int, input().split()))
s = input()
t = input()

if s[0] != t[0]:
    print(-1)
    exit()
if s == t:
    print(N)
    exit()

saisho_kobaisu = (N * M) // gcd(N, M)
# print(saisho_kobaisu)

s_d = saisho_kobaisu // N
t_d = saisho_kobaisu // M

s_set = set([i * s_d + 1 for i in range(N)])
t_set = set([i * t_d + 1 for i in range(M)])

# print(s_set)
# print(t_set)
# print(s_set.intersection(t_set))
for idx in s_set.intersection(t_set):
    if (idx-1)//s_d > N or (idx-1)//t_d > M:
        break
    if s[(idx-1)//s_d] != t[(idx-1)//t_d]:
        print(-1)
        exit()

print(saisho_kobaisu)

Measured memory_bytes: 21168
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
    string w;
    map<char, int> t;
    cin >> w;
    for (int i = 0; i < w.size(); ++i) ++t[w.at(i)];
    for (auto i = t.begin(); i != t.end(); ++i) if ((*i).second % 2) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main(){
   int n;
   cin >> n;
   vector<pair<ll,ll>> x(n);
   vector<ll> a(n),b(n);
   rep(i,n){
      cin >> a[i];
      x[i]=make_pair(a[i],i);
   }
   sort(x.begin(),x.end());
   rep(i,n) b[x[i].second]=i;
   rep(i,n){
      if(b[i]>=n/2) cout << x[n/2-1].first << endl;
      else cout << x[n/2].first << endl;
   }
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
 
#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define rap(i,n,N) for(ll i=n;i>=N;--i)
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl;
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define plll pair<ll,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
//#define endl "\n"
const int MAX = 1e3+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll INF = 1e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 450;

int a,b,c,x,y,z;

int main(){
//	cout<<fixed<<setprecision(15);
//    freopen("output.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>a>>b>>c;
    rep(i,0,50000000){
    	if((a&1)||(b&1)||(c&1))return cout<<i<<endl,0;
    	x = (b>>1)+(c>>1), y = (a>>1)+(c>>1), z = (b>>1)+(a>>1);
    	a = x, b = y, c = z;
	}
	cout<<"-1\n";
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, ans = 0;
  cin >> N;
  if(N / 100 == 1) ans += 900, N -= 100;
  else ans += 100, N -= 900;
  if(N / 10 == 1) ans += 90, N -= 10;
  else ans += 10, N -= 90;
  if(N == 1) ans += 9;
  else ans += 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
object Main {
    def a(l: List[String]): List[List[String]] = {
        if (l.isEmpty) Nil
        else {
            val (x, y) = l.span(_ != "OUT")
            x :: a(y.tail)
        }
    }
    def main(args: Array[String]) = {
        val in = io.Source.stdin.getLines.toList.tail
        a(in).grouped(3).map(_.flatten).map(x => x.size - (3 to 0 by -1).find(y => x.endsWith(List.fill(y)("HIT"))).get).foreach(println)
    }
}

Measured memory_bytes: 43728
#include<stdio.h>
int main(void){
   int i, t, n;
   for ( i = 0; i < 4; i++ ) {
      scanf("%d %d", &t, &n);
      if ( t == 1 ) printf("%d\n", 6000 * n);
      else if ( t == 2 ) printf("%d\n", 4000 * n);
      else if ( t == 3 ) printf("%d\n", 3000 * n);
      else if ( t == 4 ) printf("%d\n", 2000 * n);
   }
}

Measured memory_bytes: 1860
#include "bits/stdc++.h"

#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			1'010'000'000'000'000'017LL
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )

using namespace std;

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


void Main()
{
	ll N;
	cin >> N;
	vi A(N, 0);
	rep(i, 0, N) cin >> A[i];

	sort(A.begin(), A.end(), greater<int>());
	ll sum = 0;
	sum += A[0];
	rep(i, 2, N) {
		sum += A[(i/2)];
	}

	cout << sum << endl;
}

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

	Main();
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n,m;
  cin >> n;
  vll t(n);
  REP(i, n)
    cin >> t[i];
  
  cin >> m;
  vector<pll> p(m);
  REP(i, m){
    cin >> p[i].FI >> p[i].SE;
    p[i].FI--;
  }
  
  ll sum = 0;
  REP(i, n)
    sum += t[i];
    
  REP(i, m)
    cout << sum + (p[i].SE-t[p[i].FI]) << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn.readInt
  
object Main {
  val r = Array(2,3,5,7)
  
  def twoPow(d:Int,s:Int):(Int,Int) = {
    if(d%2 == 1) (d,s)
    else twoPow(d>>1,s+1)
  }
  
  def maybePrime(i:Int,d:Int,s:Int, n:Int):Boolean = {
    if(i>3) true
    else {
      val a = r(i)
      val x = BigInt(a).modPow(d,n).toLong
  
      if(x==1 || x==n-1) maybePrime(i+1,d,s,n)
      else repeat(s-1,x*x%n, i, d, s, n)
    }
  }
  
  def repeat(j:Int, x:Long, i:Int, d:Int, s:Int, n:Int):Boolean = {
    if(j==0) false
    else if(x==1) false
    else if(x==n-1) maybePrime(i+1,d,s,n)
    else repeat(j-1,x*x%n,i,d,s,n)
  }
  
  def isPrime(n:Int):Boolean = {
    if(n<4000) (2 to Math.sqrt(n).toInt).forall(n%_ != 0)
    else if(n%2==0) false
    else {
      val (d,s) = twoPow(n-1,0)
      maybePrime(0,d,s,n)
    }
  }
  
  def main(args:Array[String]) = {
    val n = readInt
    println((0 until n).count{ _=> isPrime(readInt) })
  }
}

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

int main(){
  string S;
  cin>>S;
  bool flag = 1;
  for (int i=1;i<4;i++){
    if (S.at(i) == S.at(i-1)){
      flag=0;
    }
  }
  if (flag==0){
    cout<<"Bad"<<endl;
  }
  else{
    cout<<"Good"<<endl;
  }
}
      

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int GCD(int A, int B)
{
	for(;;)
	{
		int Mod = A % B;
		if(Mod == 0)
		{
			return B;
		}
		A = B;
		B = Mod;
	}
}

int main()
{
	int K;
	int A;
	int B;
	int C;
	int Sum = 0;
	scanf("%d", &K);
	for(A=1; A<=K; A++)
	{
		for(B=1; B<=K; B++)
		{
			for(C=1; C<=K; C++)
			{
				Sum += GCD(GCD(A, B), C);
			}
		}
	}
	printf("%d", Sum);
	return 0;
}

Measured memory_bytes: 3824
n = int(input())
l = [0,0,0,0]
for i in range(n):
  s = input()
  if s == "AC":
    l[0] += 1
  if s == "WA":
    l[1] += 1
  if s == "TLE":
    l[2] += 1
  if s == "RE":
    l[3] += 1
print("AC x "+str(l[0]))
print("WA x "+str(l[1]))
print("TLE x "+str(l[2]))
print("RE x "+str(l[3]))

Measured memory_bytes: 74872
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <utility>
#include <functional>

using namespace std;

struct Edge {
	int from, to, cost;

	friend bool operator <(Edge const& left, Edge const& right) {
		return make_tuple(left.from, left.to, left.cost) < make_tuple(right.from, right.to, right.cost);
	}
};

struct State {
	int vertex;
	int cost;

	friend bool operator <(State const& left, State const& right) {
		return left.cost > right.cost;
	}
};

struct State2 {
	unordered_set<int> visited;
	int vertex;
	int cost;

	friend bool operator <(State2 const& left, State2 const& right) {
		return left.cost > right.cost;
	}
};

int main() {
	int n, m, r;
	cin >> n >> m >> r;
	
	vector<int> towns(n + 1, 0);
	vector<vector<Edge>> edges(n + 1, vector<Edge>());
	vector<int> destinations(r, 0);
	unordered_map<int, int> dest_to_index;

	for (int i = 0; i < r; i++) {
		cin >> destinations[i];
		dest_to_index[destinations[i]] = i;
	}

	for (int i = 0; i < m; i++) {
		Edge edge, other;
		cin >> edge.from >> edge.to >> edge.cost;
		other.from = edge.to;
		other.to = edge.from;
		other.cost = edge.cost;
		edges[edge.from].push_back(edge);
		edges[other.from].push_back(other);
	}

	vector<set<Edge>> dest_edges(n + 1, set<Edge>());
	for (auto x : destinations) {
		vector<int> min_cost(n + 1, 1 << 30);
		priority_queue<State> fringe;

		min_cost[x] = 0;
		fringe.push(State{ x, 0 });

		while (!fringe.empty()) {
			auto state = fringe.top();
			fringe.pop();
			if (state.cost > min_cost[state.vertex]) {
				continue;
			}
			for (auto edge : edges[state.vertex]) {
				if (min_cost[edge.to] > state.cost + edge.cost) {
					min_cost[edge.to] = state.cost + edge.cost;
					fringe.push(State{ edge.to, min_cost[edge.to] });
				}
			}
		}

		for (auto y : destinations) {
			if (x != y) {
				Edge edge, other;
				edge.from = x;
				edge.to = y;
				edge.cost = min_cost[y];
				other.from = y;
				other.to = x;
				other.cost = min_cost[y];
				dest_edges[edge.from].insert(edge);
				dest_edges[other.from].insert(other);
			}
		}
	}

	vector<vector<int>> dp(1 << r, vector<int>(r, 1 << 30));
	for (int i = 0; i < r; i++) {
		dp[1 << i][i] = 0;
	}
	for (int s = 0; s < (1 << r); s++) {
		for (int i = 0; i < r; i++) {
			if (s & (1 << i)) { // s includes i
				auto x = destinations[i];
				for (auto edge : dest_edges[x]) {
					auto j = dest_to_index[edge.to];
					auto ss = s | (1 << j);
					if (dp[ss][j] > dp[s][i] + edge.cost) {
						dp[ss][j] = dp[s][i] + edge.cost;
					}
				}
			}
		}
	}

	auto min_it = min_element(dp[(1 << r) - 1].begin(), dp[(1 << r) - 1].end());
	cout << *min_it << endl;
}

Measured memory_bytes: 896
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	double sum = 0;
	REP(i,N){
		int a = in();
		sum += 1.0/(double)a;
	}

	printf("%.15lf\n",1.0/sum);
	//out(N>=3200 ? s : "red");
	return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))
ev = []
ans = 0
for pi in p:
    ev.append((pi + 1) / 2)
cs = [0]
for i in range(n):
    cs.append(cs[i] + ev[i])

for i in range(k, n+1):
    cost = cs[i] - cs[i-k]
    # print(cs[i], cs[i-k])
    if ans < cost:
        ans = cost
# print(cs, ev)
print(ans)

Measured memory_bytes: 25060
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    while (cin >> n)
    {
        if (n == 0)
            break;
        //cerr << n << endl;
        bool s[n][31], p[n][n];
        rep(i, n)
        {
            rep(j, 31)
            {
                s[i][j] = false;
            }
            rep(j, n)
            {
                p[i][j] = false;
            }
        }
        //map<int, map<int, bool>> s, p;
        bool flg = false;
        rep(i, n)
        {
            int f;
            cin >> f;
            rep(j, f)
            {
                int t;
                cin >> t;
                s[i][t] = true;
                p[i][i] = true;
            }
        }

        rep(d, 1, 31)
        {
            vector<int> v;
            rep(j, n)
            {
                if (s[j][d] == true)
                {
                    v.push_back(j);
                }
            }
            // line();
            rep(i, v.size())
            {
                rep(j, i, v.size())
                {
                    rep(k, n)
                    {
                        p[v[i]][k] = p[v[i]][k] || p[v[j]][k];
                        p[v[j]][k] = p[v[i]][k] || p[v[j]][k];
                    }
                }
            }
            // line();

            rep(i, n)
            {
                flg = true;
                //  cerr << i << " : ";
                rep(j, n)
                {
                    //  cerr << p[i][j] << " ";
                    if (p[i][j] == false)
                    {
                        flg = false;
                        break;
                    }
                }
                //    cerr << endl;
                if (flg)
                    break;
            }
            if (flg)
            {
                cout << d << endl;
                flg = true;
                break;
            }
        }

        if (flg == false)
            cout << -1 << endl;
    }

    return 0;
}



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

using int64 = long long;
const int64 kMod = 1000000007;

int64 Count(int64 n, int64 m) {
  if (n > m)
    std::swap(n, m);
  if (n + 1 < m)
    return 0;

  int64 ret = 1;
  for (int64 i = 1; i <= n; ++i) {
    ret = ret * i % kMod;
  }
  for (int64 i = 1; i <= m; ++i) {
    ret = ret * i % kMod;
  }
  if (n == m) {
    ret = ret * 2 % kMod;
  }
  return ret;
}

int main(void) {
  int64 n, m;
  cin >> n >> m;
  cout << Count(n, m) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void) {
    int N;
    int x,y,t,ax=0,ay=0,at=0;
  	int dis;
    char buf[1000];

    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d \n", &N);
  
  for(int i=0;i<N;i++){
        fgets(buf, sizeof(buf), stdin);
  	    sscanf(buf, "%d %d %d\n", &t,&x,&y);
   	    dis=abs(x-ax+y-ay)-t+at;
		if(dis>0||dis%2==-1){
	    printf("No");
        return 0;
        }
    	ax=x;
    	ay=y;
    	at=t;
  }
	printf("Yes");
    return 0;
}

Measured memory_bytes: 1736
#include<iostream>
using namespace std;
int main(){
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if (x + r > w ||x-r<0){
		cout << "No" << endl;
	}
	else if (y + r > h ||y - r<0){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
	return 0;
}

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

int INF = 2e9;

int main(){
    int n;
    cin >> n;
    int res = 0;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = INF;
    for(int i = -100;i <= 100;i++){
        int sum = 0;
        rep(j,n){
            sum += pow(a[j]-i,2);
        }
        ans = min(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math


while 1:
    try:
        while 1:
            v=float(raw_input())
            t=v/9.8
            y=t*t*4.9
            n=int(math.ceil((y+5.0)/5.0))
            tmp=0
            while 1:
                if tmp*5-5>=y:
                    n=tmp
                    break
                tmp+=1
            print n
    except:
        break

Measured memory_bytes: 6320
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

#define p(a, b) make_pair(a, b)
int a[100000];

int main()
{
	int N, ans = 0;
	map<pair<int, int>, bool> mp;

	cin >> N;
	rep(i, N) cin >> a[i];

	rep(i, N) {
		if (mp.count(p(a[i], i + 1)) > 0) ans++;
		mp[p(i + 1, a[i])] = true;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6912
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int a, b;
  cin >> a >> b;
  if (a * b == 15) {
    cout << "*" << endl;
  } else if (a + b == 15) {
    cout << "+" << endl;
  } else {
    cout << "x" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  long double r;
  cin >> r;
  printf("%.10Lf\n",(2*r*M_PI));
}


Measured memory_bytes: 3792
import java.util.*;
public class Main {

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

	    int ans = 0;
	    int count = 1;
        while (count < b){
            count = count - 1 + a;
            ans++;
        }

        System.out.println(ans);

    }
}


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

int main(){
  int n;
  cin >> n;
  vector<vector<bool>> card(4, vector<bool>(13, false));
  rep(i, n){
    string M;
    int N;
    cin >> M >> N;
    if(M == "S"){
      card.at(0).at(N-1) = true;
    }
    else if(M == "H"){
      card.at(1).at(N-1) = true;
    }
    else if(M == "C"){
      card.at(2).at(N-1) = true;
    }
    else if(M == "D"){
      card.at(3).at(N-1) = true;
    }
  }
  rep(i, 4){
    rep(j, 13){
      if(card.at(i).at(j) == false){
        if(i == 0){
          cout << "S " << j+1 << endl;
        }
        else if(i == 1){
          cout << "H " << j+1 << endl;
        }
        else if(i == 2){
          cout << "C " << j+1 << endl;
        }
        else if (i == 3){
          cout << "D " << j+1 << endl;
        }
      }
    }
  }



  return 0;
}



Measured memory_bytes: 3140