akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int T;
  cin >> T;
  while(T--) {
    int n;
    string s;
    cin >> n >> s;
    bool a[2][n+1];
    memset(a,0,sizeof(a));
    for(int i=0; i<4*n; i++) {
      if(i<2*n) a[0][(i+1)/2]|=s[i]=='Y';
      else a[1][(i+1-2*n)/2]|=s[i]=='Y';
    }
    int x=1<<29,y=0;
    for(int i=0; i<2; i++) {
      for(int j=0; j<n+1; j++) {
        if(a[i][j]) {
          x=min(x,j);
          y=max(y,j);
        }
      }
    }
    int ans=n;
    for(int j=x+1; j<y; j++) {
      for(int i=0; i<2; i++) {
        if(a[i][j]) ans++;
      }
    }
    if(a[1][x]) ans+=2;
    else if(a[0][x]) ans++;
    if(a[1][y]) ans+=2;
    else if(a[0][y]) ans++;
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int oo = 1e9 + 7;
const int modulo = 1e9 + 7;
template<typename T>
inline T sum(const T& a, const T& b) { return T((a % modulo + b % modulo) % modulo); }
template<typename T>
inline T mul(const T& a, const T& b) { return T((1LL * (a % (1LL * modulo)) * (b % (1LL * modulo))) % (1LL * modulo)); }
string to_string(string a) { return "\"" + a + "\""; }
#ifdef __LOCAL_DEBUG
#define debug(args...) { string __out = #args; replace(__out.begin(), __out.end(), ',', ' '); stringstream __out_ss(__out);\
istream_iterator<string> __it(__out_ss); _debug(__it, args); }
void _debug(istream_iterator<string> it) { }
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T a, Args... args){ cerr << *it << " = " << to_string(a) << '\n'; _debug(++it, args...); }
#else
#define debug(...)
#endif

const int N = 1e5 + 5;
char a[N];
int n, q, dp[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q >> a + 1;
  dp[0] = 0;
  for (int i = 1; i <= n - 1; ++i) {
    dp[i] = dp[i - 1];
    if (a[i] == 'A' && a[i + 1] == 'C')
      dp[i]++;
  }
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << dp[r - 1] - dp[l - 1] << '\n';
  }
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,k;
long double arr[200001],pre[200001],ans;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for (int i=1;i<=n;i++){
        cin>>arr[i];
        arr[i]=(arr[i]+1)/2;
        pre[i]=pre[i-1]+arr[i];
    }
    for (int i=k;i<=n;i++){
        ans=max(ans,pre[i]-pre[i-k]);
    }
    cout<<fixed<<setprecision(10);
    cout<<ans;
}

Measured memory_bytes: 6528
import numpy as np
n = int(input())
a = np.array(list(map(int,input().split())))
bit = []
ans = 0
mod = 10**9+7
# for i in a:
#     cnt = 1
#     while i:
#         bit[-cnt] += i%2
#         i //= 2
#         cnt += 1
for i in range(60):
    bit.append(np.count_nonzero(a&1))
    a >>= 1
# print(bit)
for i in range(60):
    ans += ((n-bit[i])*bit[i]) % mod * pow(2,i,mod)
    ans %= mod
print(ans%mod)

Measured memory_bytes: 48844
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll B, ll mod){
  if (B == 0) return 1;
  else{
    if (B % 2 == 0){
      return Pow(A * A % mod, B / 2, mod) % mod;
    }else{
      return A * Pow(A * A % mod, B / 2, mod) % mod;
    }
  }
}

ll nCr(ll N, ll C, ll mod){
  ll ans = 1; C = min(C, N - C);
  for (ll i = 1; i <= C; i++){
    ans *= N - i + 1; ans %= mod;
    ans *= Pow(i, mod - 2, mod); ans %= mod;
  }
  return ans;
}


int main(){
  int N, K; cin >> N >> K;
  vector <ll> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];
  sort(H.begin(), H.end(), greater<ll>());

  ll ans = 0;
  for (int i = K; i < N; i++){
    ans += H[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
import numpy as np
N, K = map(int, input().split())
 
A = np.zeros(N, dtype=int)
 
for _ in range(K):
    input()
    for i in input().split():
        A[int(i) - 1] += 1
 
ans = 0
for i in A:
    if i == 0:
        ans += 1
print(ans)
 

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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

int main() {
    int L,R,d;
    cin >> L >> R >> d;
    lld ans = 0;
    for (int i = L; i < R+1; i++) {
        if(i % d == 0){
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){
    const long long MODULO = (1e9) + 7;
    int N;
    cin >> N;

    long long zero_configs = 0;
    long long nine_configs = 0;
    long long pow8 = 1;
    long long pow10 = 1;
    for(int i = 1; i <= N; ++i){
        zero_configs = (9 * zero_configs + pow10) % MODULO;
        nine_configs = (9 * nine_configs + pow10) % MODULO;
        pow8 = (8 * pow8) % MODULO;
        pow10 = (10 * pow10) % MODULO;
    }

    long long answer = (zero_configs + nine_configs + pow8 - pow10 + MODULO) % MODULO; 
    cout << answer;

    return 0;
}

Measured memory_bytes: 3596
n = int(input())
ac = 0
wa = 0
tle = 0
re  = 0
for i in range(n):
  s = input()
  if s =="AC":
    ac += 1
  elif s == "WA":
    wa += 1
  elif s == "TLE":
    tle += 1
  elif s == "RE":
    re += 1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

Measured memory_bytes: 9128
void main()
{
    long[] tmp = readln.split.to!(long[]);
    long n = tmp[0], a = tmp[1], b = tmp[2];

    max(0, (n - 2) * (b - a) + 1).writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

struct Data
{
	int x;
	int y;
};

int main()
{
	Data data;
	std::vector<Data> vector;

	while (1)
	{
		std::cin >> data.x >> data.y;

		if (data.x == 0 && data.y == 0)
		{
			break;
		}

		vector.push_back(data);
	}

	for (int i = 0; i < vector.size(); ++i)
	{
		if (vector[i].x > vector[i].y)
		{
			std::cout << vector[i].y << " " << vector[i].x << std::endl;
		}

		else
		{
			std::cout << vector[i].x << " " << vector[i].y << std::endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3036
import itertools
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=i+1
P=list(itertools.permutations(a))
for i in range(len(P)):
  P[i]=list(P[i])
p=list(map(int,input().split()))
q=list(map(int,input().split()))
print(abs(P.index(p)-P.index(q)))

Measured memory_bytes: 12276
let rec tabulate n f = 
  let rec loop acc m =
    if m < n then loop (f m :: acc) (m + 1)
    else List.rev acc in
  loop [] 0

let () = 
  let w, h, n = Scanf.scanf "%d %d %d\n" (fun w h n -> w, h, n) in
  tabulate n (fun _ -> Scanf.scanf "%d %d %d\n" (fun x y a -> x, y, a))
    |> List.fold_left (fun (x1, y1, x2, y2) (x, y, a) ->
        match a with
        | 1 -> (max x1 x, y1, x2, y2)
        | 2 -> (x1, y1, min x2 x, y2)
        | 3 -> (x1, max y1 y, x2, y2)
        | 4 -> (x1, y1, x2, min y2 y)) (0, 0, w, h)
    |> (fun (x1, y1, x2, y2) -> max 0 (x2 - x1) * max 0 (y2 - y1))
    |> Printf.printf "%d\n"



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

using namespace std;

vector<int> SelectSort(vector<int> A,int n)
{
	int flag;
	int count = 0;
	for(int i=0;i<n-1;i++){
		int minj = i;
		flag = 0;
		for(int j=i+1;j<n;j++){
			if(A[j] < A[minj]){
				minj = j;
				flag = 1;
			}
		}
		if(flag == 1){
			swap(A[i],A[minj]);
			count++;
		}
	}
	A[n] = count;
	return A;
}

int main()
{
	int n;
	cin >> n;
	
	vector<int> A;
	A.resize(n+1);

	for(int i=0;i<n;i++)cin >> A[i];
	
	A = SelectSort(A,n);
	
	for(int i=0;i<n;i++){
		if(i == n-1)cout << A[i] <<flush;
		else{
			cout << A[i] << " " << flush;
		} 
	}
	cout << endl << A[n] << endl;
	
	return 0;
}

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

#define ll long long

int x[55];
ll	dp[55][55][2700];
int main() {

	int n, a;
	cin>>n>>a;
	
	for(int i=1; i<=n; i++) cin>>x[i];
	
	
	for(int i=0; i<=n; i++)
		dp[i][0][0]=1;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			for(int s=1; s<=2600 ; s++){
				 if(j==1 && x[i]==s) dp[i][j][s]=1LL;
				 if(x[i]>s) dp[i][j][s]=dp[i-1][j][s];
				else if(s>=x[i]) dp[i][j][s] = dp[i-1][j-1][s-x[i]] + dp[i-1][j][s];
				else dp[i][j][s]=0;
				}
			
			}
		
		}
	
	 ll ans=0LL;	
	for(int i=1; i<=n; i++){
		ans+=dp[n][i][i*a];
		}	
		
		cout<<ans<<endl;
		
		//for(int i=0; i<=n; i++)
		//for(int j=0; j<=n; j++)
			//for(int s=0; s<=30 ; s++){
				
				//cout<<i<<" "<<j<<" "<<s<<" "<<dp[i][j][s]<<endl;
				//}
	
	return 0;
}


Measured memory_bytes: 56752
h, w, n = map(int, input().split())

c = dict()
for _ in range(n):
    a, b = map(int, input().split())
    for da in -1, 0, 1:
        for db in -1, 0, 1:
            if (2 <= a + da <= h - 1) and (2 <= b + db <= w - 1):
                c[(a + da, b + db)] = c.get((a + da, b + db), 0) + 1

#print(c)
ans_cnt = [0 for _ in range(10)]
for cnt in c.values():
    ans_cnt[cnt] += 1

ans_cnt[0] = ((h - 1) - 2 + 1) * ((w - 1) - 2 + 1) - sum((1 for cnt in c.values() if cnt > 0))

for i in range(10):
    print(ans_cnt[i])

Measured memory_bytes: 166548
/*
f[i]=i子树如果有解，那么i的相反颜色的子树和的最小值
01背包转移
O(n*w)
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1010
using namespace std;
struct edge{int x, y, next;}a[N];
int n, l, p[N], x, f[N], f1[5010], g[5010], w[N];
inline void add(int x, int y){a[++l].x=x; a[l].y=y; a[l].next=p[x]; p[x]=l;}
inline void dp(int x){
	for(int i=p[x]; i; i=a[i].next)dp(a[i].y);
	for(int i=p[x]; i; i=a[i].next)if(f[a[i].y]==-1){f[x]=-1; return;}
	memset(f1, -1, sizeof(f1)); f1[0]=0; int w1, w2;
	for(int i=p[x]; i; i=a[i].next){
		w1=w[a[i].y]; w2=f[a[i].y];
		memset(g, -1, sizeof(g));
		for(int j=0; j<=5000; j++){
			if(j>=w1&&f1[j-w1]>=0)
				if(g[j]==-1||g[j]>f1[j-w1]+w2)g[j]=f1[j-w1]+w2;
			if(j>=w2&&f1[j-w2]>=0)
				if(g[j]==-1||g[j]>f1[j-w2]+w1)g[j]=f1[j-w2]+w1;
		}
		memcpy(f1, g, sizeof(f1));
	}
	f[x]=-1;
	for(int i=0; i<=w[x]; i++)if(f1[i]>=0)
		if(f[x]==-1||f[x]>f1[i])f[x]=f1[i];
}
int main(){
	scanf("%d", &n);
	l=0; memset(p, 0, sizeof(p));
	for(int i=2; i<=n; i++){scanf("%d", &x); add(x, i);}
	for(int i=1; i<=n; i++)scanf("%d", &w[i]);
	dp(1);
	if(f[1]==-1)printf("IMPOSSIBLE"); else printf("POSSIBLE");
	return 0;
}

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

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

int main(){
    int N;
    cin >> N;
    ll a[N];
    rep(i, N) cin >> a[i];
    int cnt_t = 0;
    int cnt_f = 0;
    rep(i, N){
        if(a[i] % 4 == 0) cnt_f++;
        else if(a[i] % 2 == 0) cnt_t++;
    }
    if(cnt_t >= 2) cnt_t -= 1;
    else cnt_t = 0;
    int ans = 2 * cnt_f + cnt_t;
    if(ans >= N-1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string S; cin >> S;
  int N = S.size();
  if (N & 1) { S.pop_back(); --N; }
  int ans = -1;
  for (int i = 2; i < N; i += 2) {
    string t = S.substr(0, N - i);
    int m = t.size();
    if (t.substr(0, m / 2) == t.substr(m / 2)) {
      ans = m;
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  set<int> s;
  int a, l;
  bool f = true;
  for(int i=0;i<n;++i){
    cin >> a;
    l = s.size();
    s.insert(a);
    if(s.size()==l){
      f = false;
      break;
    }
  }
  if(f) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 9600
import java.util.Scanner;

class Main{
      public static void main(String args[]){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] count = new int[4];
	for(int i=0;i<n;i++){
	    String str = sc.next();
	    if(str.equals("AC")){
		count[0]++;
	    }else if(str.equals("WA")){
		count[1]++;
	    }else if(str.equals("TLE")){
		count[2]++;
	    }else{
		count[3]++;
	    }
	}
	System.out.println("AC x "+count[0]);
	System.out.println("WA x "+count[1]);
	System.out.println("TLE x "+count[2]);
	System.out.println("RE x "+count[3]);
	sc.close();
      }
}


Measured memory_bytes: 58052
(let* ((s (read-line))
       (x nil))
  (loop :with b := #\L
        :for a :across s
        :if (char/= a b)
        :do (progn
              (push 0 x)
              (setf b a))
        :do (incf (car x)))
  (labels ((main (rest acc)
             (when rest
               (let* ((r (car rest))
                      (l (cadr rest))
                      (k (+ r l))
                      (a (floor (/ k 2)))
                      (b (ceiling (/ k 2))))
                 (loop :for i :from 1 :to (1- r)
                       :do (format t "0 "))
                 (format t "~{~A ~}" (if (oddp r) (list b a) (list a b)))
                 (loop :for i :from 1 :to (1- l)
                       :do (format t "0 "))                                              
                 (main (cddr rest) (+ acc k))))))
    (main (reverse x) 0)
    (format t "~%")))


Measured memory_bytes: 30324
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        //int n = Integer.parseInt(sc.next());
        String s = sc.next();
        boolean[] isDNA = new boolean[s.length()];
        char c = '\0';
        for(int i = 0;i<s.length();i++){
            c = s.charAt(i);
            if((c == 'A')||(c == 'C')||(c == 'G')||(c == 'T')) isDNA[i] = true;
        }
        int j =0, max=0;
        for(int i = 0;i<isDNA.length;i++){
            j=i;
            while((j<isDNA.length)&&isDNA[j]) j++;
            max = (j-i)>max ? j-i : max;
        }
        
        System.out.println(max);
    }
}

Measured memory_bytes: 23252
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

EPS = 1e-9

#http://www.deqnotes.net/acmicpc/2d_geometry/lines
def dot(a, b):
    return a.real * b.real + a.imag * b.imag

def cross(a, b):
    return a.real * b.imag - a.imag * b.real

def distance(a, b, c):
    if dot(b-a, c-a) <= EPS:
        return abs(c-a)
    if dot(a-b, c-b) <= EPS:
        return abs(c-b)
    return abs(cross(b-a, c-a)/(b-a))

class UnionFind:
    def __init__(self, size):
        self.table = [-1] * size

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

W, H = ln()

usedC = 0
usedR = 0

candidate = []
#column: 0, row: 1
for i in xrange(W):
    candidate.append((n(), i, 0))
for i in xrange(H):
    candidate.append((n(), i, 1))

#print candidate
candidate.sort()
#print candidate

result = 0
for cost, i, type in candidate:
    if type == 1:
        result += (W + 1 - usedC) * cost
        usedR += 1
    else:
        result += (H + 1 - usedR) * cost
        usedC += 1

print result


Measured memory_bytes: 54168
def array_integer(a)
	0.upto(a.count) {|x|
		a[x] = a[x].to_i
	}
	return a
end

n,m = array_integer(STDIN.gets.split(" "))

matrix = Array.new(n).map{Array.new(m)}
vector = Array.new(m)
multiple = Array.new(n, 0)

0.upto(n-1) {|i|
	matrix[i] = array_integer(STDIN.gets.split(" "))
}

0.upto(m-1) {|j|
	vector[j] = STDIN.gets.to_i
}

0.upto(n-1) {|i|
	0.upto(m-1) {|j|
		multiple[i] += matrix[i][j] * vector[j]
	}
	print multiple[i], "\n"
}



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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cout<<#x<<" = "<<x<<endl;

li fastpow(li base,li exp) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base);

        base=(base*base);
        exp>>=1;
    }
    return res;
}

void solve()
{
    li n;

    cin>>n;

    vi ans(n+1);

    f(i,1,105)
    {
        f(j,1,105)
        {
            f(k,1,105)
            {
                li val=fastpow(i+j+k,2)-i*j-j*k-k*i;

                if(val<=n)
                {
                    ans[val]++;
                }
            }
        }
    }

    f(i,1,n)
    cout<<ans[i]<<endl;
}

int main()
{    
    

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

    li t=1;

    // cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
}

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

int main()
{
    int n,k,res;
    cin >> n >> k;
    int arr[n+1];
    for(int i=0;i<n;i++)
        cin >> arr[i];

    res = INT_MAX;
    sort(arr,arr+n);

    for(register int i=0;i<=n-k;i++)
        res = min(res,arr[i+k-1]-arr[i]);

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void _IOS(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
#define PI 3.14159265359
int sx,sy,tx,ty;
ll a[200003];
ll b[2003];
bool vis[1009][1009];
int main()
{
   // freopen ("jumping.in","r",stdin);
   _IOS();
    cin>>sx>>sy>>tx>>ty;
    int x=tx-sx,y=ty-sy;
    for(int i=0;i<x;i++)
    {
        cout<<"R";
    }
    for(int i=0;i<y;i++)
        cout<<"U";
    for(int i=0;i<x;i++)
        cout<<"L";
    for(int i=0;i<y;i++)
        cout<<"D";
    cout<<"D";
    for(int i=0;i<x;i++)
        cout<<"R";
    cout<<"R";
    for(int i=0;i<y;i++)
        cout<<"U";
    cout<<"ULU";
    for(int i=0;i<x;i++)
        cout<<"L";
    cout<<"L";
    for(int i=0;i<y;i++)
        cout<<"D";
    cout<<"DR";


}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX = 1e6 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	#define endl '\n'
	vector<int> x(6);
	for(int i = 0; i <5; i++){
		int a; cin >> a; x[a] = 1;
	}
	for(int i = 1; i <= 5; i++)
	if(x[i] == 0)cout << i << endl;
}


Measured memory_bytes: 3648
n,m=gets.split.map(&:to_i)
d=gets.split.map(&:to_i)
d.sort!

dp=Array.new(50001,10000000)
dp[0]=0
for i in 0..n
    for j in 0..m-1
        if(i+d[j]>n)
            break
        end
       dp[i+d[j]]=[dp[i+d[j]],dp[i]+1].min
    
    end
end

p dp[n]


Measured memory_bytes: 9260
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

#define MOD 1000000007

int main(){
  long long A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;

  vector<long long> ans(3);
  ans.at(0)=A*X+B*Y;
  ans.at(1)=C*2*X+max((Y-X),(long long)0)*B;
  ans.at(2)=C*2*Y+max((X-Y),(long long)0)*A;
  sort(ans.begin(),ans.end());
  cout << ans.at(0) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 200000
#define SENTINEL 2000000000

int L[MAX/2+2],R[MAX/2+2];

long merge(int A[],int n,int left,int mid,int right){
   int i,j,k=0;
   long cnt=0;
  int n1;
  int n2;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0,j=0;
  for(k=left;k<right;k++){
      if(L[i]<=R[j]){
	A[k]=L[i];
	i++;
      }
      else{
	A[k]=R[j];
	j++;
	cnt+=n1-i;
      }
    }
  return cnt;
  }



long mergesort(int A[],int n,int left,int right){
  int mid;
  long v1,v2,v3;
  if(left+1<right){
   mid=(left+right)/2;
   v1=mergesort(A,n,left,mid);
   v2=mergesort(A,n,mid,right);
   v3=merge(A,n,left,mid,right);
   return v1+v2+v3;
  }
  else return 0;
}
int main(){
  int A[MAX],n,i;
  long ans=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  ans=mergesort(A,n,0,n);
  printf("%ld\n",ans);
  return 0;
}



Measured memory_bytes: 3416
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n, h, w; cin >> n >> h >> w;
    int ans = 0;
    FOR(i, 0, n) {
        int a, b; cin >> a >> b;
        if (h <= a && w <= b)++ans;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
///https://vjudge.net/contest/363384#problem/G
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define ss second
#define ff first
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 100005;
int sumA1[N], sumA2[N], sumB1[N], sumB2[N];

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    int q;
    string s, t; cin >> s >> t >> q;
    int n = max(s.length(), t.length());
    s = "#" + s;
    t = "#" + t;
    rep(i, 1, (int)s.length() - 1){
        if(s[i] == 'A'){
            sumA1[i] = sumA1[i - 1] + 1;
            sumB1[i] = sumB1[i - 1];
        }else{
            sumB1[i] = sumB1[i - 1] + 1;
            sumA1[i] = sumA1[i - 1];
        }
    }
    rep(i, 1, (int)t.length() - 1){
        if(t[i] == 'A'){
            sumA2[i] = sumA2[i - 1] + 1;
            sumB2[i] = sumB2[i - 1];
        }else{
            sumB2[i] = sumB2[i - 1] + 1;
            sumA2[i] = sumA2[i - 1];
        }
    }
    while(q--){
        int a, b, c, d; cin >> a >> b >> c >> d;
        a--; c--;
        int differenceS = (sumA1[b] - sumA1[a]) - (sumB1[b] - sumB1[a]);
        int differenceT = (sumA2[d] - sumA2[c]) - (sumB2[d] - sumB2[c]);
        if((differenceS - differenceT + 12 * n) % 3 == 0){
            cout << "YES\n";
        }else{
            cout << "NO\n";
        }
    }

    return 0;
}


Measured memory_bytes: 2540
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CSlimes {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int n;
        cin >> n;
        string s;
        cin >> s;

        int res = 0;
        char prev = '-';
        REP(i, n) {
            if (s[i] != prev) {
                res++;
            }
            prev = s[i];
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CSlimes solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n;
	cin>>n;
	cout<<(n+1)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

ans = -10**10
for bit in range(1, 1<<10):
    score = 0
    for i in range(n):
        time = 0
        for t in range(10):
            if bit&(1<<t) and f[i][t] == 1:
                time += 1
        score += p[i][time]
    ans = max(ans, score)

print(ans)


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

int main(){
	int n, x;
	cin >> n >> x;
	int prev = 0;
	long count = 0;
	for (int i=0; i<n; i++){
		int a;
		cin >> a;
		if(prev + a > x) {
			count += prev + a - x;
			prev = x - prev;
		} else {
			prev = a;
		}
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll k, a, b; cin >> k >> a >> b;
    if(b <= a+2) {
        cout << k+1 << endl;
        return 0;
    }
    if(k <= a) {
        cout << k+1 << endl;
        return 0;
    }
    if(a&1) {
        if(k&1) cout << a+1 + (k-a)/2 * (b-a) << endl;
        else cout << a + (k-a+1)/2 * (b-a) << endl;
    }
    else {
        if(k&1) cout << a + (k-a+1)/2 * (b-a) << endl;
        else cout << a+1 + (k-a)/2 * (b-a) << endl;
    }
}

Measured memory_bytes: 3628
program reconciled;
uses math;
const
  md: int64 = 1000000007;
  f10000: int64 = 531950728;
  f20000: int64 = 368774859;
  f30000: int64 = 548996970;
  f40000: int64 = 422550956;
  f50000: int64 = 737935835;
  f60000: int64 = 309944332;
  f70000: int64 = 296716438;
  f80000: int64 = 65533322;
  f90000: int64 = 851076783;
  f100000: int64 = 457992974;
function fact(n: int64): int64;
var
  i, k, f: int64;
begin
  if n < 10000 then
  begin
    f := 1;
    k := 1;
  end
  else if n < 20000 then
  begin
    f := f10000;
    k := 10001;
  end
  else if n < 30000 then
  begin
    f := f20000;
    k := 20001;
  end
  else if n < 40000 then
  begin
    f := f30000;
    k := 30001;
  end
  else if n < 50000 then
  begin
    f := f40000;
    k := 40001;
  end
  else if n < 60000 then
  begin
    f := f50000;
    k := 50001;
  end
  else if n < 70000 then
  begin
    f := f60000;
    k := 60001;
  end
  else if n < 80000 then
  begin
    f := f70000;
    k := 70001;
  end
  else if n < 90000 then
  begin
    f := f80000;
    k := 80001;
  end
  else if n < 100000 then
  begin
    f := f90000;
    k := 90001;
  end
  else
  begin
    f := f100000;
    k := 100001;
  end;
  for i := k to n do
    f := i*f mod md;
  fact := f;
end;
var
  n, m, x: int64;
begin
  read(n, m);
  if abs(n-m) > 1 then
  begin
    writeln(0);
    halt(0);
  end;
  x := ifthen(n = m, 2, 1);
  x := x*fact(n) mod md;
  x := x*fact(m) mod md;
  writeln(x);
end.

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

int main() {
  string S,T;
  cin >> S >> T;
  
/*  cout << "1" << S << endl; */
  if (S.size() > T.size()) {
    cout << "No" << endl;
  }
  /*
  if (T.size() == S.size() + 1) {
  cout << "2" << T.size() << endl;
  cout << "1" << S.size() << endl;
  */
  int count = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) != T.at(i)) {
      cout << "No" << endl;
      break;
    }
    else {
      count++;
    }
  }
  if (count == S.size()) {
    cout << "Yes" << endl;
  }
}
      
  
    

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

int main()
{
  int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << n / 2 - 1 << '\n';
  } else {
    cout << n / 2 << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
import Text.Printf

main :: IO ()
main = do
    getLine
    vectX <- fmap (map read . words) getLine
    vectY <- fmap (map read . words) getLine
    mapM_ (printf "%.6f\n" . minkowski vectX vectY) ps
    where ps = [1, 2, 3, read "Infinity"]

minkowski :: [Double] -> [Double] -> Double -> Double
minkowski xs ys p
    | isInfinite p = maximum [abs (x-y)  | (x,y) <- zip xs ys]
    | otherwise    = sum [abs (x-y) ** p | (x,y) <- zip xs ys] ** (1/p)


Measured memory_bytes: 4568
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 1e5 + 10;

int n, m, E = 1, tot, ban;
int fir[N], nex[N << 1], arr[N << 1];
int incircle[N], pnt[N];
LL dp[N];

inline void Add_Edge(int x, int y) {
	nex[++E] = fir[x];
	fir[x] = E; arr[E] = y;
}

namespace Subtask_tree {
	LL sum = 0;
	
	void dfs(int x, int dep, int fa) {
		dp[x] += (dep & 1) ? 1 : -1;
		for (int i = fir[x]; i; i = nex[i]) {
			if (arr[i] == fa || (i >> 1) == (ban >> 1)) continue;
			dfs(arr[i], dep + 1, x);
			dp[x] += dp[arr[i]];
		}
		sum += abs(dp[x]);
	}
	
	int main() {
		dfs(1, 1, 0);
		if (dp[1] != 0) puts("-1");
		else printf("%lld\n", sum);
		return 0;
	}
}

namespace circle_init {
	int top, vis[N], st[N], instack[N];
	
	void getcircle(int x, int fa) {
		st[++top] = x;
		instack[x] = 1;
		vis[x] = 1;
		for (int i = fir[x]; i; i = nex[i]) {
			if (arr[i] == fa) continue;
			if (instack[arr[i]]) {
				incircle[arr[i]] = 1;
				pnt[++tot] = arr[i];
				for (int j = top; st[j] != arr[i]; --j) {
					incircle[st[j]] = 1;
					pnt[++tot] = st[j];
				}	
			}
			else if (!vis[arr[i]]) getcircle(arr[i], x);
		}
		--top;
		instack[x] = 0;
	}

	void getvalue(int x, int dep, int fa) {
		dp[x] = (dep & 1) ? 1 : -1;
		for (int i = fir[x]; i; i = nex[i]) {
			if (arr[i] == fa || incircle[arr[i]]) continue;
			getvalue(arr[i], dep + 1, x);
			dp[x] += dp[arr[i]];
		}
	}
	
}

namespace Subtask_even {
	LL res = 0, del[N]; // xi = x1 + del[i]
	
	int main() {
		int tmp = 0;
		for (int i = 1; i <= n; ++i) {
			if (!incircle[i]) res += abs(dp[i]);
			else tmp += dp[i];
		}
		if (tmp != 0) return 0 * puts("-1");
		for (int i = 2; i <= tot; ++i) {
			del[i] = del[i - 1] + dp[pnt[i]];
		}
		sort(del + 1, del + tot + 1);
		int mid = del[tot >> 1];
		for (int i = 1; i <= tot; ++i) {
			res += abs(del[i] - mid);
		}
		cout << res << endl;
		return 0;
	}
}

namespace Subtask_odd {
	int tmp, to;

	int main() {
		for (int i = fir[pnt[1]]; i; i = nex[i]) {
			if (incircle[arr[i]]) {
				ban = i;
				break;
			}
		}
		for (int i = 1; i <= tot; ++i)
			tmp += dp[pnt[i]];
		if (tmp & 1) return 0 * puts("-1");
		memset(dp, 0, sizeof dp);
		dp[pnt[1]] -= tmp / 2;
		dp[arr[ban]] -= tmp / 2;
		Subtask_tree::dfs(pnt[1], 1, 0);
		cout << Subtask_tree::sum + abs(tmp / 2) << endl;
		return 0;
 	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		Add_Edge(x, y);
		Add_Edge(y, x);
	}
	if (m == n - 1) return Subtask_tree::main();
	circle_init::getcircle(1, 0);
	for (int i = 1; i <= tot; ++i) {
		circle_init::getvalue(pnt[i], i & 1, 0);
	}
	if (~tot & 1) return Subtask_even::main();
	else return Subtask_odd::main();
}


Measured memory_bytes: 10368
n = int(input())
from collections import deque
#隣接リストedge
edge = [[] for i in range(n)]
d = [-1] * n
#入力
for i in range(n-1):
    x,y,cost = map(int,input().split())
    #edge[x].append([cost,y])
    #edge[y].append([cost,x])
    x -=1
    y -=1
    cost %=2
    edge[x].append((cost,y))
    edge[y].append((cost,x))
q = deque()
q.append(0)
d[0] =0
while q:
    t = q.popleft()
    for s in edge[t]:
        if d[s[1]] == -1:
            d[s[1]] = d[t] + s[0]
            q.append(s[1])
for i in d:
    print(i%2)

Measured memory_bytes: 36464
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,K;
  cin >> A >> B;
  if((A+B)%2 == 1){
  	cout << "IMPOSSIBLE" << endl;
  }else{
  	cout << ((A+B) / 2)  << endl;
  }
}

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

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

const long long MOD = 1000000007;

int main(){
  int h,n,a;
  cin >> h >> n;
  rep(i,n){
    cin >> a;
    h-=a;
  }
  if(h>0) cout << "No" << endl;
  else cout << "Yes" << endl;
}


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

int main(){
    int N[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << N[K-1] << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>

#define rep(i,n) for(int i=0;i<n;i++)
#define llint long long int
#define vvint vector<vector<int>>
#define vint vector<int>

using namespace std;

int main() {
	int k, s;
	cin >> k >> s;
	int cnt = 0;
	rep(i, k + 1) rep(j, k + 1){
		int kkk = s - i - j;
		if (kkk >= 0 & kkk <= k)cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
cnt=0
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

for i in range(1,N+1,2):
    if(len(make_divisors(i))==8):
        cnt+=1
        
print(cnt)

Measured memory_bytes: 38384
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy

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

    int n; cin >> n;
    ll a[n];
    F0R(i, n) {
        cin >> a[i];
        if(a[i]==0) {
            cout<<0<<endl;
            return 0;
        }
    }

//    F0R(i, n) {
//        if (a[i] == 0) {
//            cout << 0 << nl;
//            return 0;
//        }
//    }

    ld L = 0;
    F0R(i, n) {
        L += log10(a[i]);
    }

    if (L > 18.1) {
        cout << -1 << nl;
        return 0;
    }
    ll ans = 1;
    F0R(i, n)
        ans *= a[i];

    ll m=1e18;
    if (ans > m) {
        cout << -1 << nl;
        return 0;
    }
    cout << ans << nl;

	return 0;
}




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

int ans[1000][1000];

int main() {
  long long H, W, A, B;
  std::cin>>H>>W>>A>>B;
  for (long long x=0;x<=H;++x) {
    long long u=(W-2*A)*x;
    long long v=H-2*B;
    if (u%v!=0||u/v>W) 
      continue;
    long long y=u/v;
    std::vector<long long> res(W, 0);
    for (int i=0;i<W;++i) {
      if (i<y) res[i]=B;
      else res[i]=H-B;
    }
    for (int i=0;i<H;++i) {
      long long n1=(i<x?A:W-A);
      for (int j=0;j<W;++j) {
	if (n1>0&&res[j]>0) {
	  ans[i][j]=1;
	    --res[j];
	    --n1;
	} else {
	  ans[i][j]=0;
	}
      }
    }
    for (int i=0;i<H;++i) {
      for (int j=0;j<W;++j) {
	std::cout<<ans[i][j];
      }
      std::cout<<std::endl;
    }
    return 0;
  }
  std::cout<<"No"<<std::endl;
}


Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std;

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

  vector<int> A(N+1), B(M+1);
  const int MAX_N = N*M;
  constexpr long long int MOD = 1000000007;
  for(int i = 0; i < N; ++i) scanf("%d", &A[i]);
  for(int j = 0; j < M; ++j) scanf("%d", &B[j]);

  sort(begin(A), end(A), greater<int>());
  sort(begin(B), end(B), greater<int>());
  
  long long int ba = 0, bb = 0;
  long long int ans = 1;
  for(long long int i = MAX_N; i > 0; --i){
    if(A[ba] > i){
      ans = 0;
      break;
    }
    if(B[bb] > i){
      ans = 0;
      break;
    }
    
    if(A[ba] == i && B[bb] == i){
      ++ba, ++bb;
    }else if(A[ba] == i && B[bb] != i){
      ++ba;
      ans = (ans*bb) % MOD;
    }else if(A[ba] != i && B[bb] == i){
      ++bb;
      ans = (ans*ba) % MOD;
    }else{
      ans = (ans*(ba*bb-MAX_N+i)) % MOD;
    }

    if(ans <= 0){
      ans = 0;
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "sstream"
#define EPS 1e-9
using namespace std;
const int N=1e5,INF=0x3f3f3f3f;
typedef long long ll;
int main()<%
int a,b,c,d,cnt=1; cin>>a>>b>>c>>d;
 while(a>0&&c>0){
     if((cnt&1))
         c-=b;
     else
         a-=d;
     cnt++;
 }

 cout<<(c<=0&&a>0?"Yes":"No");
%>

Measured memory_bytes: 3648
s = list(input())
bottom = int(s[2])*10 + int(s[3])
up = int(s[0])*10 + int(s[1])
if 1 <= bottom <= 12 and 1 <= up <= 12:
    print("AMBIGUOUS")
elif 1 <= bottom <= 12:
    print("YYMM")
elif 1 <= up <= 12:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = Console.ReadLine().Split().ToArray();
            Console.WriteLine(r[1] + r[0]);
        }

    }
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<ii> v(n);
	for (int i=0; i<n; i++)
		cin>>v[i].second>>v[i].first;
	sort(v.begin(),v.end());
	ll cur=0;
	for (auto it : v) {
		cur+=it.second;
		if(cur>it.first) {
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 1792
n,m = map(int, raw_input().split())
mat = []
for i in xrange(n):
    mat.append(list(raw_input()))

l = [[0 for i in xrange(m)] for j in xrange(n)]

for i in xrange(n):
    flag = 0
    for j in xrange(1,m):
        if mat[i][j] != mat[i][0]:
            flag = 1
    if flag or mat[i][0] != '.':
        for j in xrange(m):
            l[i][j] = 1


for i in xrange(m):
    flag = 0
    for j in xrange(1,n):
        if mat[j][i] != mat[0][i]:
            flag = 1

    if not flag and mat[0][i] == '.':
        for j in xrange(n):
            l[j][i] = 0



for i in xrange(n):
    s = ''
    for j in xrange(m):
        if l[i][j]:
            s += mat[i][j]
    if s != '':
        print s


Measured memory_bytes: 33260
// C - Bugged

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


int s[100];

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

	int score = 0;
	for (int i=0; i<N; i++) {
		cin >> s[i];
		score += s[i];
	}

	if (score % 10 != 0) {
		cout << score << endl;
		return 0;
	}

	sort(s, s+N);

	bool no_valid = true;
	for (int i=0; i<N; i++) {
		if (s[i] % 10 != 0) {
			score -= s[i];
			no_valid = false;
			break;
		}
	}

	if (no_valid) {
		cout << 0 << endl;
	} else {
		cout << score << endl;
	}

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = [a[0]]
money = 1000
kabu = 0

num_max = 0
num_min = 0
d_flg = False
u_flg = False

if n == 2 and a[1] > a[0]:
    b = a
else:
    for i in range(1, n-1):
        if a[i-1] <= a[i] and a[i] > a[i+1]:
            b.append(a[i])
            d_flg = False
            u_flg = True
        elif a[i-1] >= a[i] and a[i] < a[i+1]:
            b.append(a[i])
            u_flg = False
            d_flg = True

    if u_flg is True and b[-1] < a[-1]:
        b[-1] = a[-1]
    elif u_flg is True and b[-1] > a[-1]:
        b.append(a[-1])
    elif d_flg is True and b[-1] < a[-1]:
        b.append(a[-1])
    elif u_flg is True and b[-1] > a[-1]:
        b[-1] = a[-1]


if len(b) == 1:
    print(1000)
    exit()

for i in range(len(b)-1):
    if b[i] > b[i+1] and kabu > 0:
        money += kabu * b[i]
        kabu = 0

    elif b[i] < b[i+1] and money >= b[i]:
        kabu = money // b[i]
        money -= kabu * b[i]

money += kabu * b[i+1]

print(money)

Measured memory_bytes: 9316
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int N, M;
  cin >> N >> M;
  int a, b;
  vector<vector<int>> g(N);
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    g[a - 1].push_back(b - 1);
    g[b - 1].push_back(a - 1);
  }
  debug(g);
  vector<int> visit_status(N);
  vector<int> last_visit(N);
  vector<int> distance(N);
  vector<int> color(N, -1);
  int time = 0;
  function<void(int, int)> dfs = [&](int node, int col) {
    if (visit_status[node] != 0) return;
    visit_status[node] = 1;
    distance[node] = ++time;
    for (auto next_node : g[node]) {
      if (visit_status[next_node] != 0) continue;
      // color[next_node] = col;
      dfs(next_node, col);
    }
    color[node] = col;
    last_visit[node] = ++time;
  };
  int col = 0;
  for (int i = 0; i < N; i++) {
    if (color[i] == -1) {
      dfs(i, col);
      col++;
    }
  }
  debug(color);
  int ans = *max_element(color.begin(), color.end());
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11948