akhauriyash/Code-Regression huggingface dataset:
//32
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int ans=0;
    while(n--){
      int s[]={60,80,100,120,140,160};
      int wt[]={2,5,10,15,20,25};
      int p[]={600,800,1000,1200,1400,1600,0};
      int x,y,h,w;
      cin>>x>>y>>h>>w;
      ans+=p[max(lower_bound(s,s+6,x+y+h)-s,lower_bound(wt,wt+6,w)-wt)];
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  if (s == "SUN") cout << 7 << endl;
  if (s == "MON") cout << 6 << endl;
  if (s == "TUE") cout << 5 << endl;
  if (s == "WED") cout << 4 << endl;
  if (s == "THU") cout << 3 << endl;
  if (s == "FRI") cout << 2 << endl;
  if (s == "SAT") cout << 1 << endl; 
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long x = in.nextLong(), y = in.nextLong();
            int res = 0;
            while (x <= y) {
                ++res;
                x *= 2;
            }
            out.println(res);
        }

    }
}



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

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        if((i+1)%3==0||(i+1)%10==3){
            cout<<" "<<i+1;
        }else{
            int j=(i+1)/10;
            while(j){
                if(j%10==3){
                    cout<<" "<<i+1;
                    break;
                }
                j/=10;
            }
        }
    }
    cout<<endl;
}


Measured memory_bytes: 3092
#include <stdio.h>
int main(){
  int i ,j=0 ,n ,total=0;

  for( i=0 ; i<4 ; i++ ){
    scanf( "%d" ,&n );
    total = total + n;
  }

  if( total >= 60 ){
    while( total >= 60 ){
      total = total - 60;
      j++;
    }
  }

  printf( "%d\n%d\n" ,j ,total );
  return 0;
}

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

int main(){
	int a,b,c,d,e,f;
	long long w,s,max_s=0,max_sum=0;
	double s100_now=0,s100_max=0;
	cin >> a >> b >> c >> d >> e >> f;
	
	for(int i=0;i<=f/100;i++){
		for(int j=0;j<=f/100;j++){
			for(int x=0;x<=f/c;x++){
				for(int y=0;y<=f/d;y++){
					w=100*i*a+100*j*b;
					s=c*x+d*y;
					if(w+s>f)continue;
					if(w==0)continue;
					s100_now=((double)s*100)/(double)w;
					if(s100_now>e)continue;
					if(s100_max<=s100_now){
							s100_max=s100_now;
							max_sum=w+s;
							max_s=s;
					}
				}
			}
		}
	}
	
	cout << max_sum << " " << max_s << endl;	
					
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define fish        push_front
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Deque       std::deque
#define PQueue      std::priority_queue
#define Set         std::set
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    inline boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    llong ans, tmp;

    signed call_of_Cthulhu( signed datum ) {

        String s;
        read s;
        for ( int i = 0; i < s.size(); i++ ) {
            if ( s[i] == 'W' ) {
                ans += tmp;
            }
            else {
                tmp++;
            }
        }

        echo ans fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


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

int main() {
  int n;
  cin >> n;

  int x[3];
  for (int i=0; i<3; ++i) {
    x[2-i] = n % 10 == 9 ? 1 : 9;
    n /= 10;
  }

  for (int i=0; i<3; ++i) cout << x[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/problems/1042

#include <bits/stdc++.h>

using namespace std;

int main() {
    while (true) {
        string s;
        getline(cin, s);
        if (s == "END OF INPUT") return 0;

        stringstream ss;
        ss << s;
        string buf;
        while (getline(ss, buf, ' ')) {
            cout << buf.length();
        }
        cout << endl;
    }
}

/*
 * getlineで空白を含む文字列を行ごとに取得。
 * stringstreamで空白で区切った文字列を作る。
 */


Measured memory_bytes: 3160
n = int(input())
a = list(map(int,input().split()))

def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)
    
def lcm(x,y):
    return x//gcd(x,y)*y

l = 1
for i in a:
    l = lcm(i,l)
    
ans = 0
for i in a:
    ans += l//i
    
print(ans%(10**9+7))

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    ll N; cin >> N;
    cout << (N)*(N-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define f(i,a,b) for(i=a;i<=b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ll long long
#define mod (1000*1000*1000+7)
#define scan1(x) scanf("%lld",&x)
#define scan2(x,y) scanf("%lld %lld",&x,&y)
#define scan3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define print(x) printf("%lld\n",x)
#define ff first
#define ss second
using namespace std;


int main(){
    ll n,w,i,j;
    scan2(n,w);
    vector<vector<ll>> dp(n+1,vector<ll>(100001,INT_MAX));
    vector<ll> weight(n),value(n);
    f(i,0,n-1)
    scan2(weight[i],value[i]);
    
    dp[0][value[0]]=weight[0];
    
    f(i,1,n-1){
        if(weight[i]<=w)
        dp[i][value[i]]=weight[i];
        
        ll curr_weight=weight[i];
        ll curr_value=value[i];
        f(j,1,100000)
        if(dp[i-1][j]<=w){
            
            if(dp[i-1][j]+curr_weight<=w)
            dp[i][j+curr_value]=min(dp[i][j+curr_value],dp[i-1][j]+curr_weight);
            
            dp[i][j]=min(dp[i][j],dp[i-1][j]);
            
        }
    }
    
    ll ans=INT_MIN;
    f(i,1,100000)
    if(dp[n-1][i]<=w)
    ans=max(ans,i);
    cout<<ans<<endl;
    
}

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

using namespace std;
typedef long long ll;

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

    const int INF = INT_MAX;
    
    int n, r, rmin = INF, ans = -INF;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> r;
        ans = max(ans, r - rmin);
        rmin = min(rmin, r);
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 3256
"""
最高得点＝初期状態の白タイルの数 - ゴールまでの最短経路上の白タイルの数

まず、白タイルの数を全部数える。
次に、BFSで探索を行い、最短経路を求める。
"""
from collections import deque
H,W = map(int,input().split())
maze = [list(input()) for _ in range(H)]
default = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            default += 1

que = deque()
que.append((0,0,1))
patterns = [(1,0),(-1,0),(0,1),(0,-1)]
count = 0
while que:
    y,x,cost = que.popleft()
    if y == H-1 and x == W-1:
        count = cost
        break
    for a,b in patterns:
        if 0<=y+a<H and 0<=x+b<W and maze[y+a][x+b]==".":
            maze[y+a][x+b] = "o"
            que.append((y+a,x+b,cost+1))


if count == 0:
    print(-1)
else:
    print(default-count)

Measured memory_bytes: 3316
S = input()
cnt = 0

if len(S) % 2 == 0:
    n = len(S) // 2
    s1 = S[:n]
    s2 = S[:n-1:-1]
else:
    n = len(S) // 2 + 1
    s1 = S[:n-1]
    s2 = S[:n-1:-1]

for i in range(len(S)//2):
    if s1[i] != s2[i]:
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) ((v).begin(), (v).end())
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    ll x;
    cin>>x;
    for(int i=-1000;i<=1000;i++){
        for(int j=-1000;j<=000;j++) {
            if(pow(i,5)-pow(j,5)==x){
                cout << i << ' ' << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#pragma region
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#pragma endregion

int n, k, pref[200'001];
vector<int> a;
void solve()
{
    cin>>n>>k;
    a.resize(n);
    forn(i, n) cin>>a[i];
    //
    forn(i, n) pref[i+1] = pref[i] + a[i];
    map<int, int> cnt;
    int ans = 0;
    forn(i, n + 1)
    {
        if (i >= k)
            cnt[ ((pref[i-k] - (i-k))%k+k)%k ]--;
        ans += cnt[((pref[i]-i)%k+k)%k]++;
    }
    cout << ans << '\n';
}

signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(22);
    // cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 18768
import math
x,k,d = map(int,input().split())

if x-k*d > 0:
    print(x-k*d)
    exit
elif x+k*d < 0:
    print(-1*(x+k*d))
    exit
else:
    m = 2 * math.ceil(((k-2)*d-x)/(2*d))- k
    print(min(abs(x+m*d), abs(x+(m+2)*d)))

Measured memory_bytes: 61868
k=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

import math 

def gcds(l):
    res=0
    for val in l:
        res=math.gcd(res,val)
    return res
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            ans+=gcds([i,j,m])
print(ans)


Measured memory_bytes: 74300
n, m, x = gets.chomp.split(" ").map(&:to_i)
a = Array.new(0)
na = gets.chomp.split(" ").map(&:to_i)

cost_a = 0
cost_b = 0

na.each do |i|
  a[i] = 1
end

(0..x).each do |p|
  cost_a += 1 if a[p] == 1
end

(x..n).each do |p|
  cost_b += 1 if a[p] == 1
end

puts [cost_a, cost_b].min

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++) 
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second
int main(){
  int n;
  int t1=0,x=0,y=0;
  cin>>n;
  r(i,n){
    int t2,x2,y2,sum=0;
    cin>>t2>>x2>>y2;
    sum+=abs(x-x2);
    sum+=abs(y-y2);
    if((sum%2!=abs(t2-t1)%2)||(t2-t1)<sum){
      cout<<"No"<<endl;
      return 0;
    }
    t1=t2;
    x=x2;
    y=y2;
  }
cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size()/2;i++){
		if(s[i]!=s[s.size()-i-1])
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}


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

ans=0
rest=x
target=sorted(a)
if sum(target)<x:
    print(n-1)
elif sum(target)==x:
    print(n)
else:
    for i in range(n):
        rest-=target[i]
        if rest<0:
            ans=i
            break
        if rest==0:
            ans=i+1
            break
    print(ans)


Measured memory_bytes: 9028
import glob
import bisect



# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\159\\D'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def calc(self, num):
        if num < 2:
            return 0
        return num * (num-1) / 2

    def resolve(self):

        N = int(self.input_data())
        balls = [int(i)-1 for i in self.input_data().split()]
        balls_org = balls.copy()
        ball_count = [0 for i in range(N)]

        balls.sort()
        ptn_all = 0
        count = 0
        now = -1
        for b in balls:
            if b != now:
                if now != -1:
                    ball_count[now] = count
                ptn_all += self.calc(count)
                now = b
                count = 1
            else:
                count += 1

        if count > 1:
            ball_count[now] = count
            ptn_all += self.calc(count)

        for i in balls_org:
            print(str(int(ptn_all - self.calc(ball_count[i]) + self.calc(ball_count[i]-1))))



solver = Solver(REL_PATH)
solver.exec_resolve()


Measured memory_bytes: 26408
import sys
n=input()
sys.setrecursionlimit(n+1000)
adj=[[] for i in range(n+1)]
for i in range(n-1):
	a, b, c=map(int, raw_input().split())
	adj[a].append((b, c))
	adj[b].append((a, c))
size=[0]*(n+1)
def dfs(cur, father):
	size[cur]=1
	for to, weight in adj[cur]:
		if to!=father:
			dfs(to, cur)
			size[cur]+=size[to]
dfs(1, 0)
center=1
while True:
	change=False
	for to, weight in adj[center]:
		if size[to]<size[center] and size[to]*2>=n:
			center=to
			change=True
			break
	if not change:
		break
print>>sys.stderr, center
dfs(center, 0)
result=0
for cur in range(1, n+1):
	for to, weight in adj[cur]:
		if size[to]<size[cur]:
			result+=size[to]*weight
result*=2
print>>sys.stderr, result
for to, weight in adj[center]:
	assert size[to]*2<=n
	if size[to]*2==n:
		print>>sys.stderr, "special"
		print result-weight
		exit()
min_weight=1000000000
for to, weight in adj[center]:
	min_weight=min(min_weight, weight)
print result-min_weight


Measured memory_bytes: 115312
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 3e5 + 5;


int main(){
    IO;
    ll n;
    cin >> n;
    ll ans = 1;
    for(int i = 0 ; i < 3 ; ++i)
        ans *= n;
    cout << ans << endl;
}

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

using namespace std;

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

const int INF10=1000000001,ID_MAX=20;
const long mod=100000009;
const long long INF18=100000000000000001;

struct edge{
    int to;
    vector<int> child;
    long cost;
};

void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁
int bi_max(long n){
    int m=0;
    for(m;(1<<m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入
void bi_exs(long n){
    memset(bi_e,0,sizeof(bi_e));
    if(n<(1<<ID_MAX)){
        for(int i=0;n>0;n=(n>>1),i++)bi_e[i]=n&1;
    }
}
//x^n mod m (nが負の時は０)
long myPow(long x, long n, long m){
  if(n<0)return 0;
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
struct node{
    int to;
    vector<int> child;
    pair<int,int> weight;
    int color;

    bool leaforn(){
        return child.empty();
    }
    int sizeofchild(){
        return child.size();
    }
};

const int N_MAX=1001;
int n,x[N_MAX],larger[N_MAX],dp[5001];
node v[N_MAX];

int rec(int m,int k){
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=0;i<k;i++){
        for(int j=m-larger[i];j>=0;j--){
            if(dp[j]!=0)dp[j+larger[i]]=1;
        }
    }
    int res=0;
    rep(i,m+1){
        if(dp[i]!=0){
            res=i;
        }
    }
    return res;
}

int solve(){
    queue<int> que;
    stack<int> dq;
    que.push(0);
    while(que.size()){
        int w=que.front();
        dq.push(w);
        que.pop();
        rep(i,v[w].child.size()){
            que.push(v[w].child.at(i));
        }
    }

    while(dq.size()){
        int w=dq.top();
        dq.pop();
        if(v[w].leaforn()){
            v[w].weight.first=x[w];
            v[w].weight.second=0;
            continue;
        }

        int m,sumn=0,sum=0;
        memset(larger,0,sizeof(larger));
        rep(i,v[w].child.size()){
            larger[i]=v[v[w].child.at(i)].weight.first-v[v[w].child.at(i)].weight.second;
            sumn=sumn+v[v[w].child.at(i)].weight.second;
            sum=sum+v[v[w].child.at(i)].weight.first+v[v[w].child.at(i)].weight.second;
        }
        
        if(sumn>x[w]){
            cout<<"IMPOSSIBLE"<<endl;
            return 0;
        }
        m=x[w]-sumn;
        int res=rec(m,v[w].child.size());
        v[w].weight.first=max(x[w],sum-res-sumn);
        v[w].weight.second=min(x[w],sum-res-sumn);
    }

    cout<<"POSSIBLE"<<endl;
    return 0;
}

int main(){
    int i,y;
    //入力
    cin>>n;
    for(int i=1;i<n;i++){
        cin>>y;
        v[y-1].child.push_back(i);
        v[i].to=y-1;
    }
    rep(i,n){
        cin>>x[i];
    }
    //処理
    //出力
    solve();
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+9;

typedef vector<LL> Col;
typedef vector<Col> Matrix;

Matrix mul(const Matrix& A, const Matrix& B){
  const int R = A.size(), C = B[0].size(), sz = B.size();
  Matrix AB(R, Col(C));

  for(int i=0;i<R;++i)
    for(int j=0;j<C;++j)
      for(int k=0;k<sz;++k)
		(AB[i][j] += A[i][k] * B[k][j] % MOD) %= MOD;

  return AB;
}
Matrix powA(const Matrix& A, LL n){
  const int N = A.size();
  Matrix p(N, Col(N, 0)), w = A;
  for(int i=0;i<N;++i) p[i][i] = 1;

  while(n>0){
	if(n&1)
	  p = mul(p, w);
	w = mul(w, w);
	n >>= 1;
  }

  return p;
}

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

  LL W, H, N, cnt = 1;
  while(cin >> W >> H >> N, W){
	map<LL,VL> xs;
	REP(i,N){
	  LL x, y;
	  cin >> x >> y;
	  --y;
	  --x;
	  xs[y].EB(x);
	}
	if(!xs.count(H-1)) xs[H-1] = {};

	Matrix crt(W, Col(1));
	crt[0][0] = 1;
	LL py = 0;
	for(auto&& p: xs){
	  VVL tmp(W, Col(W));
	  REP(i,W){
		if(i-1 >= 0) tmp[i][i-1] = 1;
		tmp[i][i] = 1;
		if(i+1 < W) tmp[i][i+1] = 1;
	  }
	  tmp = powA(tmp, p.FF - py);
	  crt = mul(tmp, crt);
	  py = p.FF;

	  for(LL x: p.SS)
		crt[x][0] = 0;
	}
	cout << "Case " << cnt++ <<": " << crt[W-1][0] << endl;
  }
  

  return 0;
}

Measured memory_bytes: 3248
#include<iostream>
#include<string>
#include<cctype>
using namespace std;


    

int main(){
    
    string letters;
    int m, h;
    
    while(1){
        cin >> letters;
        if(letters == "-") break;
        
        cin >> m;
        for(int i =0; i<m; i++){
            cin >> h;
            string str1 = letters.substr(0,h);
            string str2 = letters.substr(h,letters.size()-h);
            
            letters = str2 + str1;
            
            
            
        }
        cout << letters << endl;
        
    }
    
    
    return 0;
    
    
}


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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int R, G, B, N;

int main(){
    
    cin >> R >> G >> B >> N;
    ll sum = 0;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            int k = N - (i*R + j*G);
            if(k >= 0 && k % B == 0){
                sum++;
                // cout << i << " " << j << " " << k << endl;
            }
        }
    }
    cout << sum << endl;


    return 0;
}


Measured memory_bytes: 256
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 
     
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //start from here

    readb(x, y); readc(a, b, c);
    readarr(p, a); readarr(q, b); readarr(r, c);

    sort(p+1, p+a+1, greater<int>());
    sort(q+1, q+b+1, greater<int>());

    vi vec;

    fori(i, 1, c) vec.pb(r[i]);
    fori(i, 1, x) vec.pb(p[i]);
    fori(i, 1, y) vec.pb(q[i]);

    sort(all(vec)); reverse(all(vec));
    int sum = 0;

    fori(i, 0, x+y-1) sum += vec[i];

    cout << sum;

    return 0;
}


Measured memory_bytes: 8816
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  rep(i, N) cin >> D[i];
  int ans = 0;  
  rep(i, N) rep(j, i) {
    ans += D[i] * D[j];
  }
  cout << ans << '\n';
  
  return 0;
}

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

vector<int> px = {0, 1, 0, -1};
vector<int> py = {1, 0, -1, 0};

int main() {
  int h,w,numPoints=0,ans=0;
  cin >> h >> w;
  vector<string> a(h);
  for(int i=0; i<h; i++) cin >> a[i];
  vector<vector<bool>> isBlack(h,vector<bool>(w, false));
  queue<pair<int,int>> que;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++) {
      if(a[i][j]=='#') {
        isBlack[i][j] = true;
        que.push({i,j});
        numPoints++;
      }
    }
  }
  while(!que.empty()) {
    vector<pair<int,int>> points;
    int numNewPoints=0;
    for(int i=0; i<numPoints; i++) {
      points.push_back(que.front());
      que.pop();
      for(int j=0; j<4; j++) {
        int nx=points[i].first+px[j];
        int ny=points[i].second+py[j];
        if(nx<0 || nx>=h || ny<0 || ny>=w) continue;
        if(isBlack[nx][ny]) continue;
        isBlack[nx][ny] = true;
        que.push({nx,ny});
        numNewPoints++;
      }
    }
    numPoints=numNewPoints;
    ans++;
  }
  cout << ans-1 << endl;
}


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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    if((abs(a - b) <= d) && (abs(b - c) <= d)) cout << "Yes" << endl;
    else if(abs(a - c) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <cmath>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;

int main(void) {
  int N, M; cin >> N >> M;
  ll ans = (1900 * M + 100 * (N - M)) * (ll)pow(2, M);
  cout << ans << endl;
}


Measured memory_bytes: 256
# ここから
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(1000000)
from collections import Counter

def resolve():
    n,k,q = map(int, input().split())
    a = [int(input()) for _ in range(q)]

    counter = Counter(a)

    for i in range(1,n+1):
        if counter[i] > q - k:
            print('Yes')
        else:
            print('No')


resolve()

Measured memory_bytes: 54108
import math
A,B,H,M = map(int,input().split())
# long M
long = M * 6
# short H
short = (H * 60 + M ) / 2
# COS
kakudo = long - short
COS = math.cos(math.radians(kakudo))

ans = ((A**2 + B**2)-(2*A*B*COS))**0.5
print(ans)

Measured memory_bytes: 9572
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("unused")
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(); // 県の個数
		int m = in.nextInt(); // 市の個数

		int city[][] = new int[m + 1][4]; // id, pref, year, number in pref
		int copycity[][] = new int[m + 1][4];

		// 県、年でソート
		for ( int id = 1; id <= m; id++ ) {
			city[id][0] = id;
			city[id][1] = in.nextInt();
			city[id][2] = in.nextInt();

			copycity[id] = city[id]; // 参照のコピーを作る
		}
		// コピー側をソート
		Arrays.sort(copycity, new Comparator<int[]>() {

			@Override
			public int compare(int[] o1, int[] o2) {
				if ( o1[1] != o2[1] ) {
					return o1[1] - o2[1];	// １．prefでソート
				} else {
					return o1[2] - o2[2];	// ２．yearでソート
				}
			}
		});

		// 年を見てナンバリング
		DecimalFormat df = new DecimalFormat("000000");
		//		String result[] = new String[m];
		int pref = 0;
		int num = 0;
		for ( int i = 1; i <= m; i++ ) {
			int p = copycity[i][1];
			if ( pref != p ) {
				pref = p;
				num = 1;
			} else {
				num++;
			}
			copycity[i][3] = num;
			// result[city[i][0] - 1] = df.format(pref) + df.format(num);
		}

		StringBuilder sb = new StringBuilder();
		for ( int i = 1; i <= m; i++ ) {
			sb.append(df.format(city[i][1])).append(df.format(city[i][3])).append("\n");
		}
		System.out.println(sb);
		in.close();
	}

	private static String padding(int n) {
		String padded = "";
		if ( n < 10 ) {
			padded = "00000" + n;
		} else if ( n < 100 ) {
			padded = "0000" + n;

		} else if ( n < 1000 ) {
			padded = "000" + n;

		} else if ( n < 10000 ) {
			padded = "00" + n;

		} else if ( n < 100000 ) {
			padded = "0" + n;

		} else {
			padded = String.valueOf(n);
		}
		return padded;
	}
}


Measured memory_bytes: 101040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll K; cin >> K;
    ll A, B; cin >> A >> B;
    string ans = "NG";
    for (int i = A; i <= B; ++i) {
        if (i % K == 0) {
            ans = "OK";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
W, H, x, y, r = map(int, input().split())
def discriminator(x, W, r):
    if (x >= r) & (x <= (W-r)):
        return True
    else:
        return False
    
if (discriminator(x, W, r)) & (discriminator(y, H, r)):
    print("Yes")
else:
    print("No")

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

int main(){
    int a,b,k; cin>>a>>b>>k;
    int cnt=0;
    for(int i=100;i>0;i--){
        if(a%i==0&&b%i==0){
            cnt++;
            if(cnt==k){
                cout<<i<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) return 0;
        else{
            vector<int> person(n);
            double ave = 0;
            REP(i, n){
                cin >> person[i];
                ave += person[i];
            }
            ave /= n;
            int count = 0;
            REP(i, n){
                if(ave >= person[i]) count++;
            }
            cout << count << endl;
        }       
    }
}


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

int main(){
	int n, pos, flag;
	string s;
	cin >> s;
	if (s == "zyxwvutsrqponmlkjihgfedcba"){
		cout << -1 << '\n';
		return 0;
	}
	n = s.size();
	for (char ch = 'a'; ch <= 'z'; ch++){
		flag = 1;
		for (int i = n - 1; i >= 0; i--){
			if (s[i] == ch){
				flag = 0;
				break;
			}
		}
		if (flag){
			cout << s << ch << '\n';
			return 0;
		}
	}
	pos = 0;
	for (int i = n - 1; i >= 0; i--){
		for (char ch = s[i] + 1; ch <= 'z'; ch++){
			flag = 1;
			for (int j = i - 1; j >= 0; j--){
				if (ch == s[j]){
					flag = 0;
					break;
				}
			}
			if (flag){
				pos = i;
				s[i] = ch;
				break;
			}
		}
		if (pos) break;
	}
	for (int i = 0; i <= pos; i++) cout << s[i];
	cout << '\n';
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer a;
  for(a=nil->next;a!=nil;a=a->next){
if(a->key==key)return a;
}
  return NULL;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

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

void deleteNode(NodePointer t){
  
  t->next->prev=t->prev;
t->prev->next=t->next;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
 NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
NodePointer t = listSearch(key);
 if(t==NULL)return;
 deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next=nil->next;
 
  x->next->prev=x;
 nil->next=x;
  x->prev=nil;
}

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

  printList();
  return 0;
}

Measured memory_bytes: 31788
W, H, N = map(int, input().split())

w1 = 0
w2 = W
h1 = 0
h2 = H
ans = 0
tLst = [list(map(int, input().split())) for i in range(N)]

for i in range(N):
    if tLst[i][2] == 1:
        w1 = max(w1, tLst[i][0])
    elif tLst[i][2] == 2:
        w2 = min(w2, tLst[i][0])
    elif tLst[i][2] == 3:
        h1 = max(h1, tLst[i][1])
    elif tLst[i][2] == 4:
        h2 = min(h2, tLst[i][1])

w = w2 - w1
h = h2 - h1
if w <= 0 or h <= 0:
    ans = 0
else:
    ans = int(w * h)
print(ans)

Measured memory_bytes: 3064
/*
  Krishnakant Tiwari
  Problem Link:

 */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
using namespace std;
typedef long long ll;
#define _cin      ios_base::sync_with_stdio(0);  cin.tie(0);
#define endl "\n"
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define vvll vector<vector<ll> >
#define vll vector<ll>
#define mll map<ll,ll>
#define sz(x) (ll)x.size()
#define sll set<ll>
#define pll pair<ll,ll>
#define F first
#define S second
#define eb	emplace_back
#define ppb	pop_back
#define pf	push_front
#define ppf	pop_front
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define precise(x)	cout<<fixed<<setprecision(x)
const ll MAX = 1000004;
const ll INF = 1e18L + 5;
template <class T, class U>
void chmin(T &t, const U &u)
{
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T &t, const U &u)
{
    if (t < u) t = u;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}
template <typename Arg1>
void pn(Arg1 &&arg1)
{
    cout << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void pn(Arg1 &&arg1, Args &&... args)
{
    cout << arg1 << "\n";
    pn(args...);
}
template <typename Arg1>
void ps(Arg1 &&arg1)
{
    cout << arg1 << " ";
}
template <typename Arg1, typename... Args>
void ps(Arg1 &&arg1, Args &&... args)
{
    cout << arg1 << " ";
    ps(args...);
}
template <typename Arg1>
void read(Arg1 &&arg1)
{
    cin >> arg1;
}
template <typename Arg1, typename... Args>
void read(Arg1 &&arg1, Args &&... args)
{
    cin >> arg1;
    read(args...);
}

ll g[MAX];
ll a[MAX];

void solve()
{
    ll n, x, t;
    read(n, x, t);
    ll ans = n / x;
    if(n % x != 0) ans++;
    pn(ans * t);
}


int main()
{

    _cin
// #ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// #endif
    // ll tc;
    // cin>>tc;
    // while(tc--){
    solve();
    // }

}


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

int main() {
    string s;
    cin >> s;
    for(int i=0; i<s.length()-1; i++) {
        for(int j=i+1; j<s.length(); j++) {
            if(s[i]==s[j]) {
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader read = new BufferedReader(
                new java.io.InputStreamReader(System.in));

       int x = Integer.parseInt(read.readLine());

       for(int i=0;i<x;i++){
       String y=  read.readLine();
       String z [] =y.split(" ");
       //System.out.println(z[2]);
       //System.out.println(x);
	// TODO ティツ?ェテ・ツ仰陛ァツ板淌ヲツ按静」ツ?陛」ツつ古」ツ?淌」ツδ。テ」ツつステ」ツδε」ツδ嘉」ツδサテ」ツつケテ」ツつソテ」ツδ?
       int a=Integer.parseInt(z[0]);
       int b=Integer.parseInt(z[1]);
       int c=Integer.parseInt(z[2]);
       a=a*a;
       b=b*b;
       c=c*c;
       if (a==(b+c)){
		System.out.println("YES");
       }else if (b==(a+c)){
   	   System.out.println("YES");
       }else if(c==(a+b)){
   	   System.out.println("YES");
       }else{
  	   System.out.println("NO");
       }
      }
	}

}

Measured memory_bytes: 26460
void main() {
  problem();
}

void problem() {
  const MAX = 10L.pow(18);
  auto N = scan!int;
  auto A = scan!ulong(N);

  long solve() {
    ulong multi = 1;
    real floatMulti = 1;
    foreach(a; A) {
      floatMulti *= cast(real)a;
      multi *= a;
    }

    return floatMulti > MAX ? -1 : multi;
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 8380
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    map<int,int> m;
    for(int i=1;i<=n;i++)
    {
        m.insert(pair<int,int>(i,0));
    }
    int f;
    for(int i=1;i<n;i++)
    {
        cin>>f;
        auto itr=m.find(f);
        itr->second++;
    }
    
    for(auto it=m.begin();it!=m.end();it++)
    {
        cout<<it->second<<endl;
    }

    return 0;
}


Measured memory_bytes: 13008
#include <iostream>
#include <vector>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
#define repi(i, n, init) for (int i = init; i < int(n); i++)

long long merge(vector<int> &vec, int left, int mid, int right)
{
    int n1 = mid - left,
        n2 = right - mid;
    vector<int> L(n1 + 1), R(n2 + 1);
    repi(i, n1, 0)
    {
        L[i] = vec.at(left + i);
    }
    repi(i, n2, 0)
    {
        R[i] = vec.at(mid + i);
    }
    L[n1] = INF;
    R[n2] = INF;
    long long i = 0, j = 0, cnt = 0;
    repi(k, right, left)
    {
        if (L.at(i) <= R.at(j))
        {
            vec.at(k) = L.at(i);
            i++;
        }
        else
        {
            vec.at(k) = R.at(j);
            j++;
            cnt += mid + j - k - 1;
        }
    }
    return cnt;
}
long long mergeSort(vector<int> &vec, int left, int right)
{
    long long sum = 0;
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        sum += mergeSort(vec, left, mid);
        sum += mergeSort(vec, mid, right);
        sum += merge(vec, left, mid, right);
    }
    return sum;
}
int main()
{
    int n;
    cin >> n;
    vector<int> s(n);
    repi(i, n, 0)
    {
        cin >> s[i];
    }
    long long cnt = mergeSort(s, 0, n);
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

int main(int argc, char* argv[]) 
{
    int N; cin >> N;

    set<int> rice;
    for (int i = 0; i < N; i++) {
        int d; cin >> d;
        rice.insert(d);
    }

    cout << rice.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mx = 100005;
int dp[mx];
int A[mx];
void memo(int i,int n)
{
	if(i>n) return;
	dp[i] = min(dp[i-2]+abs(A[i-2]-A[i]),dp[i-1]+abs(A[i-1]-A[i]));
	memo(i+1,n);
}
int main()
{
     int n;cin>>n;
     for(int i=1;i<=n;i++)
     	cin>>A[i];
     memset(dp,0,sizeof(dp));
     dp[2] = abs(A[1]-A[2]);
     memo(3,n);
     cout<<dp[n]<<endl;
     return 0;
}

Measured memory_bytes: 1024
x1, y1, x2, y2 = map(int, input().split())

y3 = y2 + x2- x1
y4 = x2 - x1 + y1
x3 = y1 - y2 + x2
x4 = y1 - y2 + x1

print(x3, y3, x4, y4)


Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>

#define MAXN 100009

int v[MAXN + 1];

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

    for (int i = 1; i <= n; i++)
        scanf("%d", &v[i]);

    int ans = 0;
    std::sort(v + 1, v + n + 1);
    int x = 0;
    for (int i = 1; i <= n + 1; i++) {
        if (v[i] != v[i - 1]) {
            if (x > v[i - 1])
                ans += x - v[i - 1];
            else if (x < v[i - 1])
                ans += x;
            x = 1;
        } else {
            x++;
        }
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;


template<class T> T gcd(T a,T b) {return (b ? gcd(b,a%b): a);}

vector<int> sieve(int n) {
    vector<bool> prime(n + 1,true);
    prime[0] = false;
    prime[1] = false;
    for (int i = 3; i * i <= n; i += 2) {
        if (prime[i]) {
            int j = 2;
            while (i * j <= n) {
                prime[i * j] = false;
                j ++;
            }
        }
    }
    vector<int> ans = {2};
    for (int i = 3; i < n + 1; i += 2) {
        if (prime[i]) ans.push_back(i);
    }
    return ans; 
}

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

    int N; cin >> N;
    vector<int> A(1000010);
    rep(i,N) {
        int a ; cin >> a;
        A[a]++;
    }

    vector<int> primes = sieve(1000010);
    bool pairco = true;
    rep(i,1000010) {
        if (i != 1 && A[i] > 1) {
            pairco = false;
            break;
        }
    }

    for (int p: primes) {
        int cnt = 0;
        for (int j = p; j < 1000010; j += p) {
            if (A[j] > 0) ++cnt;
        }
        if (cnt > 1) {
            pairco = false;
            break;
        }
    }

    if (pairco) {
        cout << "pairwise coprime" << '\n';
        return 0;
    }
    int g = 0;
    rep(i,1000010) {
        if (A[i] > 0) g = gcd(g,i);
    }
    if (g == 1) cout << "setwise coprime" << '\n';
    else cout << "not coprime" << '\n';
    return 0;
}

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

#define next '\n'
#define rep(i, n) for(int (i) = (0); (i) < (n); (i++))
using ll = long long;

int a[5];

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

    int a, b, c;
    char d, f;
    cin >> a >> d >> b >> f >> c;

    if(b <= 4 && c <= 30){
        cout << "Heisei";
    }else{
        cout << "TBD";
    }

    cout << next;
}

Measured memory_bytes: 256