akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

// 幅優先探索 
using Graph = vector<vector <int> >; 
  
int main() { 
    // 頂点数と辺数 
    int N, M;
    cin >> N >> M;
  
    // グラフ入力受取 (ここでは無向グラフを想定) 
    Graph G(N); 
    for (int i = 0; i < M; ++i) { 
        int a, b; 
        cin >> a >> b;a--;b--;
        G[a].push_back(b); 
        G[b].push_back(a); 
    } 
  
    int ans[100005];
    vector<bool> seen(100005);
    queue<int> que;
    //スタート始点
    que.push(0);int pos=0;seen[0]=true;
    while(que.size()>0){
      int pos = que.front();que.pop();
      for(auto nx:G[pos]){
        //探索済みなら次
        if(seen[nx]==true)continue;
        seen[nx]=true;
        que.push(nx);
        ans[nx]=pos;
        pos = ans[nx];
      }
    }

    bool flag=true;
    rep(i, N){  
      // cout << "[" << seen[i] << "]";
      if(seen[i]==false){
        flag=false;
      }
    }

    if(flag){
      cout << "Yes" << endl;
      rep(i, N-1){
        cout << ans[i+1]+1 << endl;
      }
    }else{
      cout << "No" << endl;
    }
} 


Measured memory_bytes: 10092
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <string>
using namespace std;

typedef long long ll;
int a[500001];
int q;
struct A {
	int x, y, idx;
	bool operator<(A obj) const{
		int X = y / q;
		int Y = obj.y / q;
		if (X == Y) {
			return x < obj.x;
		}
		else {
			return X < Y;
		}
	}
}b[500001];
int c[500001];
int ans[500001];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL);
	int n, qe; cin >> n >> qe;
	q = sqrt(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < qe; i++) {
		cin >> b[i].x >> b[i].y;
		b[i].idx = i;
		b[i].x -= 1; b[i].y -= 1;
	}
	sort(b, b + qe);

	c[a[0]] += 1;
	int cnt = 1;
	int x = 0;
	int y = 1;

	for (int i = 0; i < qe; i++) {
		while (x < b[i].x) {
			c[a[x]] -= 1;
			if (c[a[x]] == 0)cnt -= 1;
			x += 1;
		}
		while (x > b[i].x) {
			x -= 1;
			if (c[a[x]] == 0)cnt += 1;
			c[a[x]] += 1;
		}
		while (y <= b[i].y) {
			if (c[a[y]] == 0)cnt += 1;
			c[a[y]] += 1;
			y += 1;
		}
		while (y > b[i].y + 1) {
			y -= 1;
			c[a[y]] -= 1;
			if (c[a[y]] == 0)cnt -= 1;
		}
		ans[b[i].idx] = cnt;
	}//0 2       

	for (int i = 0; i < qe; i++) {
		cout << ans[i] << '\n';
	}

}

Measured memory_bytes: 15460
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int s[N];
    int i, sum=0, mi=101;
    for(i=0;i<N;i++){
        cin >> s[i];
        sum += s[i];
        if(s[i] % 10 != 0){
            mi = min(mi, s[i]);
        }
    }
    
    if(sum % 10 == 0){
        if(mi == 101){
            cout << 0 << endl;
        }else{
            cout << sum - mi << endl;
        }
    }else{
        cout << sum << endl;
    }
    
}


Measured memory_bytes: 256
def input(f):
    global V, E, s, t, Q, u, v
    
    V, E = map(int, f.readline().split())
    s = [None for _ in range(E)]
    t = [None for _ in range(E)]
    for i in range(E):
        s[i], t[i] = map(int, f.readline().split())
        
    Q = int(f.readline())
    u = [None for _ in range(Q)]
    v = [None for _ in range(Q)]
    for i in range(Q):
        u[i], v[i] = map(int, f.readline().split())

import sys
sys.setrecursionlimit(1000000)

def solve():
    G = [[] for _ in range(V)]
    G_inv = [[] for _ in range(V)]
    for i in range(E):
        G[s[i]].append(t[i])
        G_inv[t[i]].append(s[i])

    def find_order():
        order = []
        used = [False for _ in range(V)]
        def rec(cur):
            if used[cur]:
                return
            used[cur] = True
            for nxt in G[cur]:
                rec(nxt)
            order.append(cur)
        
        for i in range(V):
            rec(i)
        
        return reversed(order)

    def decomp(order):
        groups = [None for _ in range(V)]
        used = [False for _ in range(V)]
        def rec(cur, group_id):
            if used[cur]:
                return
            used[cur] = True
            groups[cur] = group_id
            for nxt in G_inv[cur]:
                rec(nxt, group_id)
        
        group_id = 0
        for start in order:
            if used[start]:
                continue
            rec(start, group_id)
            group_id += 1
        
        return groups

    order = find_order()
    groups = decomp(order)

    for i in range(Q):
        if groups[u[i]] == groups[v[i]]:
            print('1')
        else:
            print('0')

with open('/dev/stdin') as f:
    input(f)
    solve()


Measured memory_bytes: 23628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=2147483647;
inline ll read(){
	ll 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<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int a,b,c,k,ans;
int main(){
	a=read(),b=read(),c=read(),k=read();
	if(k<=a) ans=k;
	else if(k<=a+b) ans=a;
	else if(k<=a+b+c) ans=2*a+b-k;
	else ans=a-c;
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  int t=0,x=0,y=0;
  for(int i=0;i<n;i++){
    int T,X,Y;
    cin>>T>>X>>Y;
    int d=abs(X-x)+abs(Y-y);
    if(d>T-t) {cout<<"No"<<endl; return 0;}
    if(d==T-t) {x=X;y=Y;t=T; continue;}
    if(d<T-t){ 
      if((T-t)%2==d%2) {x=X;y=Y;t=T;}
      else {cout<<"No"<<endl; return 0;}
    }
  }
  cout<<"Yes"<<endl;
}
  

Measured memory_bytes: 256
n=int(input())
s=input()
ans=0
ans_index=0
for i in range(n):
  ans_index=0
  Left=s[0:i]
  Right=s[i:]
  #print(Left)
  #print(Right)
  if (Left.count("a")>0 and Right.count("a")>0):
    ans_index+=1
  if (Left.count("b")>0 and Right.count("b")>0):
    ans_index+=1
  if (Left.count("c")>0 and Right.count("c")>0):
    ans_index+=1
  if (Left.count("d")>0 and Right.count("d")>0):
    ans_index+=1
  if (Left.count("e")>0 and Right.count("e")>0):
    ans_index+=1
  if (Left.count("f")>0 and Right.count("f")>0):
    ans_index+=1
  if (Left.count("g")>0 and Right.count("g")>0):
    ans_index+=1
  if (Left.count("h")>0 and Right.count("h")>0):
    ans_index+=1
  if (Left.count("i")>0 and Right.count("i")>0):
    ans_index+=1
  if (Left.count("j")>0 and Right.count("j")>0):
    ans_index+=1
  if (Left.count("k")>0 and Right.count("k")>0):
    ans_index+=1
  if (Left.count("l")>0 and Right.count("l")>0):
    ans_index+=1
  if (Left.count("m")>0 and Right.count("m")>0):
    ans_index+=1
  if (Left.count("n")>0 and Right.count("n")>0):
    ans_index+=1
  if (Left.count("o")>0 and Right.count("o")>0):
    ans_index+=1
  if (Left.count("p")>0 and Right.count("p")>0):
    ans_index+=1
  if (Left.count("q")>0 and Right.count("q")>0):
    ans_index+=1
  if (Left.count("r")>0 and Right.count("r")>0):
    ans_index+=1
  if (Left.count("s")>0 and Right.count("s")>0):
    ans_index+=1
  if (Left.count("t")>0 and Right.count("t")>0):
    ans_index+=1
  if (Left.count("u")>0 and Right.count("u")>0):
    ans_index+=1
  if (Left.count("v")>0 and Right.count("v")>0):
    ans_index+=1
  if (Left.count("w")>0 and Right.count("w")>0):
    ans_index+=1
  if (Left.count("x")>0 and Right.count("x")>0):
    ans_index+=1
  if (Left.count("y")>0 and Right.count("y")>0):
    ans_index+=1
  if (Left.count("z")>0 and Right.count("z")>0):
    ans_index+=1
  
  ans=max(ans,ans_index)
print(ans)

Measured memory_bytes: 3192
import sys
sys.setrecursionlimit(10**8)

n = int(input())
h = list(map(int,input().split()))

dp = [float("inf")] * n #dpテーブル
#dp[i]メモ化テーブル

def rec(i):#再帰による全探索
    if dp[i] != float("inf"):
        return dp[i]
    if i == 0:
        return 0
    elif i == 1:
        return abs(h[0]-h[1])
    else:
        dp[i] = min(rec(i-1)+abs(h[i]-h[i-1]),rec(i-2)+abs(h[i]-h[i-2]))
        return dp[i]

print(rec(n-1))


Measured memory_bytes: 93716
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    long long N,K,M;
    cin>>K>>N;
    long long A[N+1];
    for(int i=0;i<N;i++)
    {
        cin>>A[i];
    }
    A[N]=K+A[0];
    M=max(A[1]-A[0],A[2]-A[1]);
    for(int i=1;i<N-1;i++)
    {
        M=max(M,A[i+2]-A[i+1]);
    }
    cout<<K-M<<endl;
    return 0;



}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int n;
    cin >> n;

    ll sum = 0;
    for (int i = 1; i <= n; ++i) {
        if(i % 3 != 0 && i % 5 != 0){
            sum += i;
        }
    }

    cout << sum << endl;

    return 0;
}

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


int main(){
	string tmp[200];
	string out="aaaa";
	string s;
	int count=0;
	while(1){
		cout<<"?"<<out<<endl;
		tmp[count]=out;
		count++;
		
		cin>>s;
		if(s[0]!=out[3]){
			cout<<"!OUT"<<endl;
			return 0;
		}
		for(int i=0;i<count;i++){
			if(tmp[i]==s){
				cout<<"!OUT"<<endl;
				return 0;
			}
		}
		tmp[count]=s;
		count++;
		
		
		out[0]=s[s.size()-1];
		if(out[1]!='z'){
			out[1]++;
		}else{
			out[2]++;
		}
		
		
	}
}

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

int main()
{
    int n;
    cin >> n;
    
    if(n%2==0){ cout << fixed << setprecision(10) << (double)(n/2)/(double)n << endl;}
    else{cout << fixed << setprecision(10) << (double)(n/2+1)/(double)n << endl;}
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int ans = 0;
	scanf("%d %d %d", &a, &b, &c);
	
	if (a == 7){
		if (b == 5 && c == 5){
			ans = 1;
		}
	}
	else if (b == 7){
		if (a == 5 && c == 5){
			ans = 1;
		}
	}
	else if (c == 7){
		if (a == b && b == 5){
			ans = 1;
		}
	}
	
	if (ans == 1){
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
	return (0);
}

Measured memory_bytes: 128
r, c = map(int, input().split())
arr = []
for i in range(r):
    arr.append(list(map(int, input().split())))

for line in arr:
    line.append(sum(line))
    
arr.append([sum([line[i] for line in arr]) for i in range(c  + 1)])

for line in arr:
    print(*line)


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

ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  ll N, X;
  cin >> N >> X;
  ll min_dif = pow(10, 9) + 1;
  vector<ll> x(N), difs(N);
  for (int i = 0; i < N; ++i) {
    cin >> x[i];
    ll dif = abs(X - x[i]);
    difs[i] = dif;
    min_dif = min(min_dif, dif);
  }
  
  ll result = difs[0];
  for (int i = 1; i < N; ++i) {
    ll dif = difs[i];
    ll a = max(result, dif);
    ll b = min(result, dif);
    result = gcd(a, b);
  }
  cout << result << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<long long int> w(n);
  int all=0;
  for(long long int i=0; i<n; i++){
    cin>>w.at(i);
    all+=w.at(i);
  }

  int be=0;
  long long int ans=9999999999999;
  for(int i=0; i<n; i++){
    be+=w.at(i);
    all-=w.at(i);
    long long int pre=abs(all-be);
    ans=min(ans,pre);
  }
  cout<<ans<<endl;
}

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

double calcAngle(float h, double m)  {  

    if (h == 12.0) h = 0;  
    if (m == 60.0) m = 0;  
  
    double hour_angle = 0.500000000000 * (h * 60.000000000000 + m);  
    double minute_angle = 6.0000000000000 * m;  
  
    double angle = fabs(hour_angle - minute_angle);  
  
    if(360.00000000000 - angle < angle)
	    angle = 360.00000000000 - angle;

    return angle;  
}  

int main(){
	double a,b,h,m;
	cin>>a>>b>>h>>m;

	double angle = calcAngle(h,m);

	double ans = a*a + b*b - 2.0000000000*a*b*cos(angle*0.01745329252);
	cout<<setprecision(20)<<sqrt(ans)<<endl;
	
	return 0;
}


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

int main(){
    //input
    int m1, d1, m2, d2;
    scanf("%d%d", &m1, &d1);
    scanf("%d%d", &m2, &d2);

    //judge
    if(m1 != m2) cout << "1" << endl;
    else cout << "0" << endl;

    return 0;
}

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

string S;

int main() {
	cin >> S;
	long long ans = 0;
	while (S.length() <= 18) {
		//printf("length: %d\n", S.length());
		int carries[S.length()];
		bool fail = 0;
		for (int i = 0; i < S.length(); i++) {
			if (i * 2 + 1 == S.length()) {
				if (S[i] != '0' && S[i] != '9') fail = 1;
				else if (S[i] == '0') carries[i] = 0;
				else carries[i] = 1;
				continue;
			}
			int sum = (S[i] - '0' + S[S.length() - 1 - i] - '0') % 10;
			if (sum != 8 && sum != 9 && sum != 10 && sum != 0) fail = 1;
			else if (sum == 8) carries[i] = 2;
			else if (sum == 9) carries[i] = 1;
			else carries[i] = 0;
		}
		if (!fail) {
			
			for (int i = 0; i < (1 << (S.length() - 1)); i++) {
				bool flag = 0;
				int carry[S.length()];
				carry[S.length() - 1] = 0;
				for (int j = 0; j < S.length() - 1; j++) carry[j] = (i & (1 << j)) > 0;
				for (int j = 0; j < S.length(); j++) {
					if (j * 2 >= S.length()) break;
					int sum = carry[j] + carry[S.length() - j - 1];
					if (j == S.length() - j - 1) sum -= carry[j];
					if (sum != carries[j]) flag = 1;
				}
				if (flag) continue;
				//printf("didnt fail\n");
				long long minans = 1;
				for (int j = 0; j < S.length(); j++) {
					if (j * 2 >= S.length()) break;
					int l = j, r = S.length() - j - 1;
					long long potate = 0;
					for (int k1 = 0; k1 <= 9; k1++) {
						for (int k2 = 0; k2 <= 9; k2++) {
							if (k1 != k2 && l == r) continue;
							if (l == 0 && k2 == 0) continue;
							
							// test position l
							int x = (k1 - carry[l]), y = k2;
							int rem = x - y;
							if (rem < 0) {
								if (l == 0 || !carry[l - 1]) continue;
							}
							if (rem >= 0) {
								if (!(l == 0 || !carry[l - 1])) continue;
							}
							if (rem < 0) rem += 10;
							if (rem != S[l] - '0') continue;
							
							// test position r
							x = (k2 - carry[r]);
							y = k1;
							rem = x - y;
							if (rem < 0) {
								if (r == 0 || !carry[r - 1]) continue;
							}
							if (rem >= 0) {
								if (!(r == 0 || !carry[r - 1])) continue;
							}
							if (rem < 0) rem += 10;
							if (rem != S[r] - '0') continue;
							potate++;
							//printf("%d %d works\n", k1, k2);
						}
					}
					minans *= potate;
				}
				ans += minans;
			}
		}
		S = "0" + S;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	float a;
	while (cin >> a){
		cout<< ceil((a*a / 19.6f)/5.0)+1<<endl;
		
	}
}

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

int main(){
    int a, b;
    
    cin >> a >> b;
    
    if( a >= b ){
        cout << 1 << endl;
    }else{
        if( b % a != 0){
            cout << b / a  + 1<< endl;
        }else{
            cout << b / a << endl;
        }
    }
}


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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;
    //agc32 b
    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        StringBuilder sb = new StringBuilder();
        if(n%2==0){
            sb.append(n*(n-2)/2).append("\n");
            for (int i = 1; i <= n; i++) {
                for (int j = i+1; j <= n; j++) {
                    if(i+j!=1+n){
                        sb.append(i).append(' ').append(j).append("\n");
                    }
                }
            }
        }else{
            sb.append((n-1)*(n-1)/2).append("\n");
            for (int i = 1; i <= n; i++) {
                for (int j = i+1; j <= n; j++) {
                    if(i+j!=n){
                        sb.append(i).append(' ').append(j).append("\n");
                    }
                }
            }
        }
        out.print(sb.toString());
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    string s;
    cin >> n;
    ll res = 0;
    map<string, int> cache;
    for (int i = 0; i < n; i++) {
        cin >> s;
        sort(all(s));
        res += cache[s];
        cache[s]++;
    }
    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
#define INF 2147483640
using namespace std;
long long a[100015];
int main()
{
	//freopen("out.txt","w",stdout);
	int n,zero=0;
	cin >> n;
	for(int i=0; i<n; i++)
	{
		cin >> a[i];
		if(!a[i]) zero++;
	}
	if(zero>0)
	{
		cout << 0 << '\n';
		return 0;
	}
	long long cnt=1;
	for(int i=0; i<n; i++)
	{
		if(a[i] <=1000000000000000000/cnt) cnt*=a[i];
		else
		{
			cout << -1 << '\n';
			return 0;
		}
	}
	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 4424
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <string>
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

using namespace std;
typedef long long ll;
#define PAI 3.14159265358979323846
const int MAX = 0x7ffffff;
int t;

int main()
{
	SIS;
	double r;
	cin >> r;
	printf("%.20f\n", 2 * PAI * r); 
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int n,m;
int a[55],b[55];
int get(int x){
  if(x==0)return 1;
  int pos=0;
  while(x){
    pos++;
    x/=10;
  }
  return pos;
}
int c[55],pos[55];
int main() {
  ios::sync_with_stdio(false);
  cin>>n>>m;
  for(int i=1;i<=n;i++)c[i]=-1,pos[i]=-1;
  for(int i=1;i<=m;i++){
    cin>>a[i]>>b[i];
    if(pos[a[i]]==-1)pos[a[i]]=b[i];
    else {
      if(pos[a[i]]!=b[i])return cout<<-1,0;
    }
  }
  if(n==1){
    if(pos[1]==-1)return cout<<0,0;
    else cout<<pos[1];
  }else{
    if(pos[1]==0)return cout<<-1,0;
    if(pos[1]==-1)pos[1]=1;
    for(int i=1;i<=n;i++)cout<<max(pos[i],0);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX_N 5000
#define P 1000000007
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, sz[MAX_N+5]; vector <int> G[MAX_N+5];
lnt f[MAX_N+5][MAX_N+5], g[MAX_N+5], cur[MAX_N+5];
void DFS(int u, int fa) {
	f[u][sz[u] = 1] = 1;
	for (int v : G[u]) if (v ^ fa) {
		DFS(v, u);
		for (int i = 1; i <= sz[u]+sz[v]; i++) cur[i] = 0;
		for (int i = 1; i <= sz[u]; i++)
			for (int j = 0; j <= sz[v]; j++)
				(cur[i+j] += f[u][i]*f[v][j]%P) %= P;
		sz[u] += sz[v];
		for (int i = 1; i <= sz[u]; i++) f[u][i] = cur[i];
	}
	for (int i = 2; i <= sz[u]; i += 2)
		(f[u][0] += P-f[u][i]*g[i]%P) %= P;
}
int main() {
	read(n), g[0] = 1;
	for (int i = 2; i <= n; i += 2) g[i] = g[i-2]*(i-1)%P;
	for (int i = 1, u, v; i < n; i++)
		read(u), read(v), G[u].push_back(v), G[v].push_back(u);
	return DFS(1, 0), printf("%lld\n", P-f[1][0]), 0;
}


Measured memory_bytes: 195200
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
#define FOR(i, a, b) for(LL i=(LL)(a);i<(LL)(b);i++)
#define REP(i,x) for(LL i=0;i<(LL)(x);i++)

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // cout << fixed << setprecision(10);
    LL n, m;
    cin >> n >> m;

    vector<LL> v_a;
    REP(i, m)
    {
        LL temp;
        cin >> temp;
        v_a.push_back(temp);
    }

    LL rest = n;
    for(auto it = v_a.begin(); it != v_a.end(); it++)
    {
        rest = rest - *it;
        if(rest < 0)
        {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << rest << endl;
    return 0;
}

Measured memory_bytes: 3780
// https://atcoder.jp/contests/agc024/tasks/agc024_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  VL as(N);
  rep(i, N) cin >> as[i];

  if (as[0] > 0) drop(-1);

  rep(i, N - 1) {
    if (as[i + 1] > as[i] + 1) drop(-1);
  }

  ll res = 0;

  rep1(i, N - 1) {
    if (as[i] == as[i - 1] + 1) {
      res++;
    } else {
      res += as[i];
    }
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 1920
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextInt64() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}


func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func (io *Io) PrintBool(b bool, trueS, falseS string) {
	if b {
		io.PrintLn(trueS)
	} else {
		io.PrintLn(falseS)
	}
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func absi(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

type Int64s []int64
func (f Int64s) Len() int {
	return len(f)
}
func (f Int64s) Less(i, j int) bool {
	return f[i] < f[j]
}

func (f Int64s) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}


func abcInt(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func gcdInt(a, b int) int {
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

var (
	io *Io
)

type P struct {
	s string
	p int
	id int
}

type PS []P
func (f PS) Len() int {
	return len(f)
}
func (f PS) Less(i, j int) bool {
	if f[i].s != f[j].s {
		return f[i].s< f[j].s
	}
	return f[i].p > f[j].p
}

func (f PS) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}

const MOD = 1000000007

func solve() {
	s := io.Next()
	threes := make([]int, len(s) + 1)
	twos := make([]int, len(s) + 1)

	for i := range threes {
		if i == 0 {
			threes[i] = 1
			twos[i] = 1
			continue
		}
		threes[i] = threes[i-1] * 3 % MOD
		twos[i] = twos[i-1] * 2 % MOD
	}

	ones := 0
	ans := 0
	for i := range s {
		if s[i] == '0' {
			continue
		}

		rem := len(s) - i - 1

		cans := twos[ones] * threes[rem]
		ans = (ans + cans) % MOD

		ones++
	}
	ans = (ans + twos[ones]) % MOD
	io.PrintLn(ans)
}


func main() {
	io = NewIo()
	f, err := os.Open("src/input")
	if err == nil {
		io.reader = bufio.NewReader(f)
	}
	defer io.Flush()

	solve()
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int n,i,r,l;
  cin>>s;
  n=s.length();
  vector<int> a(n);
  i=0;
  while(i<n){
    r=i;
    i++;
    while(s.at(i)=='R') i++;
    l=i;
    a.at(l-1)+=(l-r+1)/2;
    a.at(l)+=(l-r)/2;
    i++;
    while(i<n && s.at(i)=='L') i++;
    r=i;
    a.at(l-1)+=(r-l)/2;
    a.at(l)+=(r-l+1)/2;
  }
  for(i=0;i<n;i++){
    cout<<a.at(i);
    if(i<n-1) cout<<' ';
    else cout<<endl;
  }
}

Measured memory_bytes: 1024
use itertools::Itertools as _;
use proconio::*;
use std::io::{stdout, BufWriter, Write};
macro_rules! p {
    ($x:expr) => {
        println!("{}", $x);
    };
}
fn main() {
    input! {
        n:usize,
        s:[usize;n],
        t:[usize;n],
        u:[u64;n],
        v:[u64;n],
    }
    let mask = std::u64::MAX;
    let (or, and) = (1, 0);
    // 1確定
    let mut one = vec![vec![0u64; n]; n];
    // 0確定
    let mut zero = vec![vec![0u64; n]; n];

    // 自明
    for i in 0..n {
        for j in 0..n {
            if s[i] == and {
                one[i][j] |= u[i];
            } else {
                zero[i][j] |= !u[i];
            }
            if t[j] == and {
                one[i][j] |= v[j];
            } else {
                zero[i][j] |= !v[j];
            }
            if one[i][j] & zero[i][j] != 0 {
                p!(-1);
                return;
            }
        }
    }
    let mut ans = one.clone();

    // 条件を満たさない行/列のあるbitを調べる
    let check = |ans: &[Vec<u64>]| {
        let mut u_check = (0..n)
            .map(|i| if s[i] == or { 0 } else { mask })
            .collect_vec();
        let mut v_check = (0..n)
            .map(|j| if t[j] == or { 0 } else { mask })
            .collect_vec();

        for i in 0..n {
            for j in 0..n {
                if s[i] == and {
                    u_check[i] &= ans[i][j];
                } else {
                    u_check[i] |= ans[i][j];
                }
                if t[j] == and {
                    v_check[j] &= ans[i][j];
                } else {
                    v_check[j] |= ans[i][j];
                }
            }
        }
        let check = u
            .iter()
            .zip(&u_check)
            .chain(v.iter().zip(&v_check))
            .map(|(x, y)| x ^ y)
            .fold(0, |x, y| x | y);
        check
    };

    // 市松
    // 未確定が2*2以上なら必ず通る
    // 市松が間違っていたので修正
    let mut iflip;
    let mut jflip = 0u64;
    for i in 0..n {
        iflip = 0;
        jflip ^= if s[i] == and { !u[i] } else { u[i] };
        for j in 0..n {
            ans[i][j] |= !zero[i][j] & (iflip ^ jflip);
            iflip ^= !(one[i][j] | zero[i][j]);
        }
    }

    let fail = check(&ans);
    // 全部or
    for i in 0..n {
        for j in 0..n {
            ans[i][j] &= !fail;
            ans[i][j] |= fail & (u[i] | v[j]) & !zero[i][j];
        }
    }

    let fail = check(&ans);
    // 全部and
    for i in 0..n {
        for j in 0..n {
            ans[i][j] &= !fail;
            ans[i][j] |= fail & ((u[i] & v[j]) | one[i][j]);
        }
    }

    let fail = check(&ans);
    if fail != 0 {
        p!(-1);
        return;
    }
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    ans.iter().for_each(|x| {
        x.iter().for_each(|x| {
            out.write((x.to_string() + " ").as_bytes()).unwrap();
        });
        out.write(b"\n").unwrap();
    });
}

Measured memory_bytes: 11528
/// sultanov

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
using namespace __gnu_pbds;
                                                          
template<typename T> 
using ordered_set = tree<T, null_type,   
less<T>, rb_tree_tag,
tree_order_statistics_node_update>;

using ll = long long;
using pii = pair<int, int>;                                   

const int INF32 = 1e9;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) 
        cin >> a[i] >> b[i] >> c[i];
    vector<vector<ll>> dp(3, vector<ll>(n));
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for (int i = 1; i < n; i++) {
        dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a[i];
        dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + b[i];
        dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + c[i];
    }
    cout << max({dp[0].back(), dp[1].back(), dp[2].back()});
    return false;                                                       
}


Measured memory_bytes: 4608
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if(k<e-a)cout<<":("<<endl;
  else cout<<"Yay!"<<endl;
}

Measured memory_bytes: 256
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array

# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

# 再帰の制限設定
sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    K = ii()

    substring = set()
    for i in range(len(S)):
        for j in range(i+1, i+K+1):
            substring.add(S[i:j])
    ret = sorted(list(substring))
    print(ret[K-1])


if __name__ == '__main__':
    main()


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

int main(){
	int w, n, a, b, temp;
	vector<int> array;
	cin >> w >> n;
	for(int i=1; i<=w; i++){
		array.push_back(i);
	}
	for(int i=0; i<n; i++){
		temp = 0;
		a = 0;
		b = 0;
		scanf("%d,%d",&a,&b);
		a--;
		b--;
		temp = array[a];
		array[a] = array[b];
		array[b] = temp;
	}
	for(int i=0; i<w; i++){
		cout << array[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1260
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

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

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

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

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n; ll sum = 0;
  vector<pair<string,ll>> table(n+1);
  
  for(ll i=1; i <= n; i++){
    string s; ll x; cin >> s >> x; sum += x;
    table[i] = make_pair(s,x+table[i-1].second);
  }
  
  string sleep; cin >> sleep;
  
  for(auto p : table){
    if(p.first == sleep){
      cout << sum - p.second << endl;
      return 0;
    }
  }
  
  
}

Measured memory_bytes: 3484
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N; cin>>N;
  vector < pair<pair<string, int>, int > > data(N);
  REP(i,N) {
    string S; int P; cin>>S>>P;
    data[i] = make_pair(make_pair(S, -P), i+1);
  }
  sort(data.begin(), data.end());
  REP(i,N) {
    cout << data[i].second << endl;
  }
  return 0;
}



Measured memory_bytes: 888
#define _USE_MATH_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    string a,b;
    cin >> a >> b;
    int x = atoi((a + b).c_str());
    for (int i = 0; i <= sqrt(x); i++){
        if (i*i == x) {
            cout << "Yes"<<endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        int h = t/3600;
        int m = (t%3600)/60;
        int s = (t%3600)%60;
        System.out.println(h + ":" + m + ":" + s);
    }
}

Measured memory_bytes: 26272
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vl x(n),y(n),p(n);
  ll pow3 = 1;
  rep(i,n){
    cin >> x[i] >> y[i] >> p[i];
    pow3*=3;
  }
  vl X,Y,Z;
  vl ans(16,10010010010010LL);
  for(ll i = 0;i<=pow3;i++){
    ll trit = i;
    X.clear();
    Y.clear();
    Z.clear();
    rep(j,n){
      if(trit%3 == 0)Z.push_back(j);
      if(trit%3 == 1)X.push_back(x[j]);
      if(trit%3 == 2)Y.push_back(y[j]);
      trit/=3;
    }
    ll dist = 0;
    for(auto z:Z){
      ll tmp = min(abs(x[z]),abs(y[z]));
      for(auto _x:X) mins(tmp,abs(x[z]-_x));
      for(auto _y:Y) mins(tmp,abs(y[z]-_y));
      dist+=tmp*p[z];
    }
    //show(dist);
    mins(ans[sz(X)+sz(Y)],dist);
  }
  for(int i = 0;i<=n;i++){
    cout<<ans[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3636
from collections import deque
import sys
sys.setrecursionlimit(10**7)
#input = sys.stdin.readline
def isprime(n):
  if n <= 1:
    return False
  else:
    for i in range(2,(int(n**0.5)+2)):
      if n%i == 0:
        return False
    return True

def solve():
  n = int(input())
  query = []
  for i in range(3,1311):
    if isprime(i):
      if i%5 == 2:
        query.append(i)
  #1311で55個あったので
  for i in range(n):
    print(query[i],end =" ")
      
solve()

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

#define int long long
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*
ifstream ifs("in.txt");
ofstream ofs("out.txt");
#define cin ifs
#define cout ofs
//*/

int N;
char c[4400];
int a[4400];
int bAry[2200], wAry[2200];
int bTable[2200][2200], wTable[2200][2200];

// Binary Indexed Tree(1-indexed)
const int MAX_N = 4400;

struct BIT {
    int bit[MAX_N + 1] = {}, n;

    void init(int n_) {
        n = n_;
    }

    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }
};

BIT black, white;
int dp[2200][2200];

int DP(int b, int w) {
    if (b == 0 && w == 0) return 0;
    if (dp[b][w] != -1) return dp[b][w];
    int res = 1145141919;
    if (b != 0) {
        int cur = b + w - bAry[b] - bTable[b][w] - 1;
        cur += DP(b - 1, w);
        res = min(res, cur);
    }
    if (w != 0) {
        int cur = b + w - wAry[w] - wTable[w][b] - 1;
        cur += DP(b, w - 1);
        res = min(res, cur);
    }
    return dp[b][w] = res;
}

signed main() {
    cin >> N;
    black.init(N), white.init(N);
    for (int i = 0; i < 2 * N; i++) {
        cin >> c[i] >> a[i];
        if (c[i] == 'B') {
            bAry[a[i]] = black.sum(a[i]);
            for (int j = 1; j <= N; j++) {
                bTable[a[i]][j] = white.sum(j);
            }
            black.add(a[i], 1);
        } else {
            wAry[a[i]] = white.sum(a[i]);
            for (int j = 1; j <= N; j++) {
                wTable[a[i]][j] = black.sum(j);
            }
            white.add(a[i], 1);
        }
    }
    for (int i = 0; i < 2200; i++) {
        for (int j = 0; j < 2200; j++) {
            dp[i][j] = -1;
        }
    }
    cout << DP(N, N) << endl;
}

Measured memory_bytes: 111104
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
// http://drken1215.hatenablog.com/entry/2019/03/24/091900
int main() {
    int A, B, C;
    cin >> A >> B >> C;
    //解毒剤入りの美味しくないクッキーを A
    //解毒剤入りの美味しいクッキーをB
    //毒入りの美味しいクッキーを C 枚持っていま
    //美味しいクッキー
    if(A + B >= C - 1) {
        //毒は全部食べれる
        cout << B + C << endl;
        return 0;
    }
    cout << A + B + 1 + B << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <climits>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int p; cin >> p;
	int t=12*60/360;
	p*=t;
	cout << p/60 << " " << p%60 << endl;
}


Measured memory_bytes: 3216
#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;
const int MOD = (int)1e9 + 7;

int main(){
  int n;
  cin >> n;
  vector<int> w(n);
  rep(i,n) cin >> w[i];
  int S1,S2;
  int min_dif=1000000;
  rep(t,n){
    S1=0;
    S2=0;
    rep(i,n){
    if(i<=t) S1 += w[i];
    else S2 += w[i];
    }
    if(min_dif > max(S2-S1,S1-S2)) min_dif = max(S2-S1,S1-S2);
  }
  cout << min_dif << endl;
}



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

using namespace std;

const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, m;
vector<int> rs[N];

bool read() {
    if (!(cin >> n >> m))
        return false;

    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        rs[a].emplace_back(b);
    }

    return true;
}

int solve() {
    auto cmp = [](const pair<int, int>& a, const pair<int, int>& b) {
        return make_pair(a.first, -a.second) < make_pair(b.first, -b.second);
    };
    multiset< pair<int, int>, decltype(cmp)> ms1(cmp);
    multiset<int> ms2;

    for (auto r : rs[0])
        ms2.insert(r);

    for (int i = 1; i <= m; ++i)
        for (auto r : rs[i])
            ms1.insert(make_pair(i, r));

    int ans = 0;

    for (int i = 1; i <= m; ++i) {
        if (!ms1.empty()) {
            ms1.erase(ms1.begin());
            ++ans;
        } else if (!ms2.empty() && *ms2.begin() <= i) {
            ms2.erase(ms2.begin());
            ++ans;
        }

        for (auto r : rs[i]) {
            auto it = ms1.find(make_pair(i, r));

            if (it != ms1.end()) {
                ms1.erase(it);
                ms2.insert(r);
            }
        }
    }

    cout << n - ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 17920
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>?5*8},'ruby',$0)
R=Hash.new 0
E=Hash.new{|h,k|h[k]=[]}
def f(x,q)
E[x].each{|v|(f(v,x);R[x]^=R[v]+1)if v!=q}
end
gets;$<.each{|e|
u,v=e.split.map &:to_i
E[u]<<v;E[v]<<u
}
f(1,0)
puts R[1]>0 ? :Alice : :Bob

Measured memory_bytes: 226128
/*????¨?*/
#include <stdio.h>
int main(){
  int h, m, s, S;
  scanf("%d", &S);
  h = S / 3600;
  m = S % 3600 / 60;
  s = S % 3600 % 60;
  printf("%d:%d:%d\n", h, m, s);
  return 0;
}

Measured memory_bytes: 592