akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll N, K;
ll A[200010];
ll nxt[60][200010], over[60][200010];
ll pre[200010];

int main()
{
    cin >> N >> K;
    for(int i = 0; i < N; i++)cin >> A[i];

    if(N == 1)
    {
        if(K % 2)cout << A[0] << endl;
        else cout << endl;
        return 0;
    }

    for(int i = 0; i < 2 * N; i++)
    {
        if(pre[A[i % N]] == 0)pre[A[i % N]] = i + 1;
        else
        {
            int idx = (pre[A[i % N]] - 1) % N;
            nxt[0][idx] = (i + 1) % N;
            over[0][idx] = (nxt[0][idx] <= idx % N || idx == i % N) ? 1 : 0;
            if(idx == i % N && idx == N - 1)over[0][idx] = 2;
            pre[A[i % N]] = i + 1;
        }
    }

    for(int i = 1; i < 60; i++)
    {
        for(int j = 0; j < N; j++)
        {
            nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
            over[i][j] = min((ll)(10000000000000), over[i - 1][j] + over[i - 1][nxt[i - 1][j]]);
        }
    }

    ll mem = 0, sum = 0;
    for(int i = 59; i >= 0; i--)
    {
        if(sum + over[i][mem] < K)
        {
            sum += over[i][mem];
            mem = nxt[i][mem];
        }
    }
    /*
    ll l = 0, r = 100000000000000001;
    while(1)
    {
        ll mid = (l + r) / 2;
        ll now = 0, cnt = 0;
        for(int j = 0; j < 60; j++)if(mid & (1LL << j))
        {
            cnt += over[j][now];
            now = nxt[j][now];
        }
        if(K - 1 == cnt)
        {
            mem = now;
            break;
        }
        if(cnt < K - 1)l = mid;
        else r = mid;
    }
    */

    int bit[200010] = {0};
    vector<int> ans;
    for(int i = mem; i < N; i++)
    {
        if(bit[A[i]])
        {
            while(ans.back() != A[i])
            {
                bit[ans.back()] ^= 1;
                ans.pop_back();
            }
            bit[ans.back()] ^= 1;
            ans.pop_back();
        }
        else
        {
            bit[A[i]] ^= 1;
            ans.push_back(A[i]);
        }
    }

    for(int i = 0; i < ans.size(); i++)
    {
        cout << ans[i];
        if(i != ans.size())cout << " ";
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 193780
tmp = []

tmp = list(map(int, input().split()))

m = tmp.pop()
n = tmp.pop()

tmp.clear

flag = []
flag = [False]*n
pena = []
pena = [0]*n

correct = 0
penalty = 0

for i in range(m):
    tmp = input().split()
    status = tmp.pop()
    num = int(tmp.pop())
    if flag[num-1] == False:
        if status == "WA":
            pena[num-1] = pena[num-1] + 1
        elif status == "AC":
            correct = correct + 1
            penalty = penalty + pena[num-1]
            flag[num-1] = True


print("{} {}".format(correct, penalty))

Measured memory_bytes: 4724
import Control.Applicative
import Data.List
import Control.Monad

main = do
    [n,_,x] <- map read.words <$> getLine :: IO [Int]
    costs <- map read.words <$> getLine :: IO [Int]
    let cc = map (f costs) [1..n]
    putStrLn.show $ g x cc

f costs x = if x `elem` costs then 1 else 0
g x costs = min (sum (take x costs)) (sum (drop (x-1) costs))

answer bb x = sum $ map fst $ drop (x-1) bb

Measured memory_bytes: 892
from bisect import bisect_left
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
a=[0]*(n*m+1); b=[0]*(n*m+1)
for ax in A: a[ax]+=1
for bx in B: b[bx]+=1
# print(a,b)
ans=1; mod=pow(10,9)+7
for i in reversed(range(1,n*m+1)):
  if a[i]>0 and b[i]>0: 
    if a[i]>1 or b[i]>1: ans=0
  elif a[i]>0:
    if a[i]>1: ans=0
    ans*=m-bisect_left(B,i)
    ans%=mod
  elif b[i]>0:
    if a[i]>1: ans=0
    ans*=n-bisect_left(A,i)
    ans%=mod
  else:
    ax=n-bisect_left(A,i)
    bx=m-bisect_left(B,i)
    mul = ax*bx-(n*m-i)
    ans=(ans*mul)%mod
print(ans)


Measured memory_bytes: 18804
#include <bits/stdc++.h>
using namespace std;
#define int long long int

int n;
vector< vector<int> > v;
vector< vector<int> > dp;

int happy(int day, int last){
	if(day == n || dp[day][last] == -1){
		if(day == n){
			return 0;
		}
		else{
			dp[day][last] = 0;
			if(last!=0){
				dp[day][last] = max(dp[day][last], v[day][0] + happy(day+1, 0));
			}
			if(last!=1){
				dp[day][last] = max(dp[day][last], v[day][1] + happy(day+1, 1));
			}
			if(last!=2){
				dp[day][last] = max(dp[day][last], v[day][2] + happy(day+1, 2));
			}
			return dp[day][last];
		}
	}
	else{
		return dp[day][last];
	}
}

main(){

	cin >> n;
	v.resize(n, vector<int>(3));
	dp.resize(n, vector<int>(4, -1));

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

	cout << happy(0, 3) << "\n";

}

Measured memory_bytes: 18944
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;


ll n, d[55];
ll ans;
set<ll> S[2][25];
ll dp[110];
set<ll> s[2][25];
bool cando(ll star, ll t)
{
        ll pt = 0;
        ll cur = star;
        while(pt < n) {
                while(cur < 25 && s[0][cur].size() == 0 && s[1][cur].size() == 0) {
                        cur++;
                }
                if(cur == 25) return false;
                if(s[1][cur].size()) {
                        s[1][cur].erase(s[1][cur].begin());
                        cur += t;
                        pt++;
                        continue;
                }else {
                        ll mined = 25;
                        ll id = 0;
                        for(auto &i : s[0][cur]) {
                                if(24LL - d[i] < mined) {
                                        mined = 24 - d[i];
                                        id = i;
                                }
                        }
                        pt++;
                        s[1][mined].erase(id);
                        cur += t;
                        continue;

                }
        }
        return true;
}
bool ok(ll t)
{
        //set<pll> s[2][25];
        for(ll i=0;i<=1;i++) {
                for(ll j=0;j<=24;j++) s[i][j] = S[i][j];
        }
        for(ll i=0;i<=24;i++) {
                if(S[0][i].size() > 0) {
                        if(cando(i , t)) return true;
                }
        }
        return false;
}
int main()
{
        cin >> n;
        ans = 24;
        for(ll i=1;i<=n;i++) {
                cin >> d[i];
                ans = min(ans , d[i]);
                S[0][min(d[i], 24LL - d[i])].insert(i);
                S[1][max(d[i], 24LL - d[i])].insert(i);
        }
        ll ret = ans;
        for(ll i=ans;i>=0;i--){
                if(ok(i)) {
                        cout << i << endl; return 0;
                }
        }
        return 0;
}


Measured memory_bytes: 256
require 'matrix'
require 'bigdecimal'
require 'bigdecimal/util'
require 'bigdecimal/ludcmp'
include LUSolve

def len3d(x, y)
  l2=0.0
  0.upto(3-1){|i|
    l2 += (x[i] - y[i])**2
  }
  return Math.sqrt(l2)
end

def heron(a,b,c)
  s = (a + b + c) / 2.0
  return  Math.sqrt(s*(s-a).abs*(s-b).abs*(s-c).abs)
end

Eps=1e-9
def solve(a,b,c,d,e)   # returns true if beam hits barrier.
  # a, b, c: ????????¢???????§???¢??????????????????????????????
  # d:???????????????????????????
  # e:???????????????????????????
  # a + s*u + t*v = d + x*w ????§£??????(0<x<1) ???P(d+xw)???????§???¢ABC????????¨???????????°??????????????????????????????
  # ??????????????????true?????§???????????°false????????????
  u = c - a
  v = b - a
  w = e - d
  m = Matrix.columns([u, v, -w])

#  abort("Impssible case") if m.determinant.abs <Eps
  return false if m.determinant.abs <Eps
  parms = m.inv * (d - a)
  #parms = m.lup.solve(d - a)

  s = parms[0]
  t = parms[1]
  x = parms[2]
# ???P???????§???¢ABC??????????????¢??¨??´???DE??¨?????????
  return false if x < 0 or x > 1.0
  p = d + x*w
# ????§???¢ PAC, PAB, PBC?????¢???????????¨????§???¢ABC?????¢????????????????????°???P???ABC???????????????
  pa = len3d(a, p)
  pb = len3d(b, p)
  pc = len3d(c, p)

  ab = len3d(b, a)
  ac = len3d(c, a)
  bc = len3d(c, b)

  s0=heron(ab,ac,bc)
  s1=heron(pa,pc,ac)
  s2=heron(pa,pb,ab)
  s3=heron(pb,pc,bc)

  return  (s1+s2+s3-s0).abs <Eps
end

def main
  if true then
#  if false then
    fh=STDIN
  else
    #fh=open("in1_0115a.txt")
    #fh=open("in1_0115b.txt")
    fh=open("in1_0115c.txt")
  end
  d1,d2,d3=fh.gets.chomp.split.map{|x| x.to_i}
  e1,e2,e3=fh.gets.chomp.split.map{|x| x.to_i}

  a1,a2,a3=fh.gets.chomp.split.map{|x| x.to_i}
  b1,b2,b3=fh.gets.chomp.split.map{|x| x.to_i}
  c1,c2,c3=fh.gets.chomp.split.map{|x| x.to_i}

  d=Vector[d1,d2,d3]
  e=Vector[e1,e2,e3]
  a=Vector[a1,a2,a3]
  b=Vector[b1,b2,b3]
  c=Vector[c1,c2,c3]

  if solve(a,b,c,d,e) then
    puts "MISS"
  else
    puts "HIT"
  end

end

if $0 == __FILE__ then
  main
end

Measured memory_bytes: 9396
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N;
unordered_map<string, ll> M;
unordered_map<string, ll> A;
unordered_map<string, ll> R;
unordered_map<string, ll> C;
unordered_map<string, ll> H;

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

  cin >> N;
  string S;
  rep(i, N){
    cin >> S;
    char s = S[0];
    if (s == 'M') M[S]+=1ll;
    if (s == 'A') A[S]+=1ll;
    if (s == 'R') R[S]+=1ll;
    if (s == 'C') C[S]+=1ll;
    if (s == 'H') H[S]+=1ll;
  }
  ll m = M.size();
  ll a = A.size();
  ll r = R.size();
  ll c = C.size();
  ll h = H.size();
  ll ans = m*a*r+m*a*c+m*a*h+m*r*c+m*c*h+m*r*h;
  ans+=a*r*c+a*r*h+a*c*h+r*c*h;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 10880
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
vector<ll> A[100001];
vector<ll> C[100001];
ll N,M,K;
ll V[100001];
int length[100001];


void dfs(int i,int k){
    V[i] = k;
    for (int j=0;j<A[i].size();j++){
        if(V[A[i][j]] == 0){
            length[k]++;
            dfs(A[i][j],k);
        }
    }
}



int main(){
    cin >> N >> M >> K;
    for (int i=0;i<M;i++){
        ll a,b;
        cin >> a >> b;
        A[a-1].push_back(b-1);
        A[b-1].push_back(a-1);
    }
    for (int i=0;i<K;i++){
        ll c,d;
        cin >> c >> d;
        C[c-1].push_back(d-1);
        C[d-1].push_back(c-1);
    }
    int k=0;
    for (int i=0;i<N;i++){
        if(V[i] == 0){
            k++;
            dfs(i,k);
        }
    }
    for(int i=0;i<N;i++){
        ll ans=0;
        ans = length[V[i]];
        for(int j=0;j<C[i].size();j++){
            if(V[i]==V[C[i][j]]){
                ans--;
            }
        }
        ans -= A[i].size();
        cout << ans << endl;
    }
    
}




Measured memory_bytes: 14464
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 5000
#define MOD 1000000007

vector<vector<pair<int,int>>> tree;
vector<int> color;

void solve(int v){
  for(auto nv :tree.at(v)){
    if(color.at(nv.first)!=-1){
      continue;
    }
    if(nv.second%2==1){
      color.at(nv.first)=1-color.at(v);
    }else{
      color.at(nv.first)=color.at(v);
    }
    solve(nv.first);
  }
}

int main(){
  int N;
  cin>>N;
  tree.resize(N);
  color.resize(N,-1);
  for(int i=0;i<N-1;i++){
    int u,v;
    ll w;
    cin>>u>>v>>w;
    u--;
    v--;
    tree.at(u).push_back(make_pair(v,w));
    tree.at(v).push_back(make_pair(u,w));
  }

  color.at(0)=1;
  solve(0);

  for(int i=0;i<N;i++){
    cout<<color.at(i)<<endl;
  }
}


Measured memory_bytes: 8192
var
	i,N,q,r,answer: integer;
    
    
begin
	readln(N);

    i := 1;
    answer := 0;

    while i < 10 do
        begin
            q := N div i;
            r := N mod i;

            if (r = 0) and (q < 10) then
                answer := 1;

            i += 1;
        end;
    
    if answer = 1 then
        writeln('Yes')
    else
        writeln('No');

end.


Measured memory_bytes: 128
import java.util.*;
public class Main{
  static Scanner sc = new Scanner(System.in);
  static int ans;
  static char[][] map;
  static int width, height;

  public static void main(String [] args){
    while(true){
      ans = 0;
      width = sc.nextInt();
      height = sc.nextInt();
      if(width == 0 && height ==0) break;
      int x = 0, y = 0;
      map = new char[height][width];
      char[] line = new char[width];
      for(int i = 0; i < height; i++){
        line = sc.next().toCharArray();
        for(int j = 0; j < width; j++){
          map[i][j] = line[j];
          if(line[j] == '@'){
            x = j;
            y = i;
          }
        }
      }
      dfs(x, y);
      System.out.println(ans);
    }
  }
static void dfs(int x, int y){
    ans++;
    int next_x, next_y;
    int[] dx = {0, -1 ,0 ,1}, dy = {1, 0, -1, 0};
    for(int i = 0; i < dx.length; i++){
      next_x = x + dx[i];
      next_y = y + dy[i];
      if(next_x < 0 || next_x >= width || next_y < 0 || next_y >= height) continue;
      else if(map[next_y][next_x] != '.') continue;
      map[next_y][next_x] = 'a';
      dfs(next_x, next_y);
    }
    return ;
  }
}

Measured memory_bytes: 29132
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define MAX_N 101

using namespace std;

typedef long long ll;

int main() {
    int N;
    int A[2][MAX_N];
    cin >> N;
    for (int i = 0; i < N; ++i)
        cin >> A[0][i];
    for (int i = 0; i < N; ++i)
        cin >> A[1][i];
    
    int tmp = 0, ans = 0;
    tmp = A[0][0];
    for (int i = 0; i < N; ++i)
        tmp += A[1][i];
    ans = tmp;
    for (int i = 0; i < N - 1; ++i) {
        tmp = tmp - A[1][i] + A[0][i+1];
        ans = max(ans, tmp);
    }
    
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    
    const int NUM = 2019;
    
    reverse(s.begin(), s.end());

    ll t = 0;
    ll d = 1;
    ll l[NUM];
    fill(l, l+NUM, 0);
    for(int i=0; i<s.length(); i++){
        t = t + d*(s[i]-'0');
        t = t % NUM;
        // cout << t << endl;
        l[t]++;

        d = d * 10;
        d = d % NUM;
    }

    ll ans = 0;
    for(int i=0; i<NUM; i++){
        if(i == 0) ans = ans + l[i];
        ans = ans + l[i]*(l[i]-1)/2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3732
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define in inline
#define reg register
#define int long long
#define MAX 20030813
using namespace std;
namespace qwq{
	in void read(int &o) {
		o=0;
		int w=1;
		char c=getchar();
		while(c<'0'||c>'9') {
			if(c=='-')w*=-1;
			c=getchar();
		}
		while(c>='0'&&c<='9') {
			o=(o<<3)+(o<<1)+(c^48);c=getchar();
		}
		o*=w;
	}
	void write(int x){
	   	if(x<0)putchar('-'),x=-x;
    	if(x>9)write(x/10);
		putchar(x%10+48);
	}
	void Write(int x) {
		write(x);putchar(' ');
	}
	in int max(int x,int y){return x>y?x:y;}
	in int min(int x,int y){return x<y?x:y;}
}
using namespace qwq;
int N,D; 
signed main()
{
	read(N),read(D);
	D<<=1;D+=1;
	if(N%D)write(N/D+1);
	else write(N/D);
	return 0;
}




Measured memory_bytes: 256
N, M, Q = gets.split.map(&:to_i)
lrs = M.times.map { gets.split.map(&:to_i) }
pqs = Q.times.map { gets.split.map(&:to_i) }
count_list = Array.new(N) { Array.new(N){ 0 } }
lrs.each do |(l, r)|
  l -= 1
  r -= 1
  count_list[l][r] += 1
end
sum_list = Array.new(N) { Array.new(N){ 0 } }
N.times do |i|
  sum = 0
  N.times do |j|
    sum += count_list[i][j]
    sum_list[i][j] = sum
  end
end
N.times do |i|
  sum = 0
  N.times do |j|
    sum += sum_list[j][i]
    sum_list[j][i] = sum
  end
end
pqs.each do |(p, q)|
  p -= 1
  q -= 1
  ans = sum_list[q][q] - (p > 0 ? sum_list[p - 1][q] : 0)
  puts ans
end


Measured memory_bytes: 34172
def S(k):
    R = 0
    for i in range(1, k+1):
        R += i
    return R

N, K = [int(n) for n in input().split()]
# 0,1,2,...,Nからk個選ぶときの和の種類を求めて
# K <= k <= N+1 の総和をとる

# N + 1
# 2N - 2*1 + 1
# 3N - 2*(1+2) + 1

# 0     ~ N               N                   +1
# 0+1   ~ N+(N-1)         2N - (1)    -(1)    +1
# 0+1+2 ~ N+(N-1)+(N-2)   3N - (2+1)  -(1+2)  +1

# k個選ぶとき kN - 2*(1+2+...+(k-1)) + 1 種類
# これを KからN+1まで
M = 10**9 + 7
B = K*N - 2*S(K-1) + 1
A = B
for k in range(K+1, N+2):
    B += N - 2*(k-1)
    A += B
print(A % M)


Measured memory_bytes: 9196
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, ans int
	var t, a, diff, min_diff float64
	min_diff = 1000
	param := 0.006
	fmt.Scan(&n)
	fmt.Scanf("%f %f\n", &t, &a)
	h := make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
		diff = math.Abs(float64(a - (t - (h[i] * param))))
		if diff < min_diff {
			min_diff = diff
			ans = i + 1
		}
	}
	fmt.Println(ans)
}

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

int main()
{
	string a;
	cin>>a;
	for(int i=1;i<=3;i++)
    {
        if(a[i]==a[i-1])
            {
            cout<<"Bad";
            return 0;
        }
    }
    cout<<"Good";
	return 0;
}





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

void fukugo(char *out, const char *in, int in_length) {
	int i;
	int offset=0;
	for(i=0;i<in_length;i++) {
		switch(in[i]) {
			case '+':
				offset++;
				if(offset>=26)offset-=26;
				break;
			case '-':
				offset--;
				if(offset<26)offset+=26;
				break;
			case '?':
				*(out++)='A';
				offset=0;
				break;
			case '[':
				{
					char buffer[128];
					int j;
					int nest=1;
					for(j=i+1;nest>0;j++) {
						if(in[j]=='[')nest++;
						if(in[j]==']')nest--;
					}
					fukugo(buffer,in+i+1,j-i-2);
					i=j-1;
					for(j=strlen(buffer)-1;j>=0;j--)*(out++)=buffer[j];
				}
				break;
			default:
				*(out++)=(in[i]-'A'+offset)%26+'A';
				offset=0;
				break;
		}
	}
	*out='\0';
}

int main(void) {
	char input[128];
	char output[128];
	while(scanf("%s",input)==1 && input[0]!='.') {
		fukugo(output,input,strlen(input));
		puts(output);
	}
	return 0;
}

Measured memory_bytes: 528
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    int x,y,z;
    cin >> x >> y >> z;
    cout << z << " " <<  x << " " << y;
    return 0;
}

Measured memory_bytes: 256
use std::fmt::Write;

fn main() {
    let n = read::<usize>();
    let vec = read_as_vec::<u16>();
    insertion_sort(n, vec);
}

fn insertion_sort(n: usize, mut vec: Vec<u16>) -> Vec<u16> {
    for i in 0usize..n {
        let e = vec[i];
        for j in (0usize..i).rev() {
            if e < vec[j] {
                vec[j + 1] = vec[j];
                vec[j] = e;
            } else {
                break;
            }
        }
        println!("{}", join(' ', &vec));
    }
    vec
}

fn join<T: std::fmt::Display>(delimiter: char, arr: &[T]) -> String {
    let mut text = String::new();
    for (i, e) in arr.iter().enumerate() {
        if i > 0 {
            text.push(delimiter);
        }
        write!(text, "{}", e).unwrap();
    }
    text
}

fn read<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().parse::<T>().ok().unwrap()
}

fn read_as_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse::<T>().ok().unwrap())
        .collect()
}


Measured memory_bytes: 5040
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

main = do
  li <- BS.getLine
  let Just (n,_) = BS.readInt li
  li <- BS.getLine
  let as = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  let ans = compute n as
  print ans

base = 10^9+7
reg n = mod n base

compute :: Int -> [Int] -> Int
compute n as = fst $ foldr step (0,0) as

step ai (acc,sig) = (reg $ acc + ai * sig, reg $ sig + ai)

{-
A1 * A2 + A1 * A3 + ... + A1 * An = A1 * Σi=2～n Ai
-}


Measured memory_bytes: 44512
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if (a==b) {
        cout<<c<<endl;
    }else if (b==c){
        cout<<a<<endl;
    }else{
        cout<<b<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;

signed main()
{
    int h, w, n;
    cin >> h >> w >> n;
    
    vi a(n);
    rep(i, n) cin >> a[i];
    
    vvi ans(h, vi(w));
    
    int p = 0;
    rep(i, h){
        rep(j, w){
            ans[i][i%2 ? j : w-j-1] = p+1;
            --a[p];
            if(a[p] == 0) ++p;
        }
    }
    
    rep(i, h){
        rep(j, w) cout << ans[i][j] << (j==w-1 ? "\n" : " ");
    }
}


Measured memory_bytes: 384
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
using ll = long long;

int main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
    //    freopen("out", "w", stdout);
#endif
    //    ios::sync_with_stdio(0), cin.tie(0);
    ll n, c;
    scanf("%lld%lld", &n, &c);
    vector<ll> x(n), v(n), F(n), B(n), mxf(n), mxb(n);
    for (int i = 0; i < n; i++) {
        scanf("%lld%lld", &x[i], &v[i]);
    }

    F[0] = v[0];
    for (int i = 1; i < n; i++)
        F[i] = F[i - 1] + v[i];
    for (int i = 0; i < n; i++)
        F[i] -= x[i];
    mxf[0] = F[0];
    for (int i = 1; i < n; i++)
        mxf[i] = max(F[i], mxf[i - 1]);

    B[0] = v[n - 1];
    for (int i = 1; i < n; i++)
        B[i] = B[i - 1] + v[n - i - 1];
    for (int i = 0; i < n; i++)
        B[i] -= (c - x[n - i - 1]);
    mxb[0] = B[0];
    for (int i = 1; i < n; i++)
        mxb[i] = max(B[i], mxb[i - 1]);
    
    ll ans = LLONG_MIN;
    for (int i = 0; i < n; i++) {
        ll cur = F[i];
        if (i != n - 1)
            cur = max(cur, cur + mxb[n - 2 - i] - x[i]);
        ans = max(ans, cur);
    }

    ll res = LLONG_MIN;
    for (int i = 0; i < n; i++) {
        ll cur = B[i];
        if (i != n - 1)
            cur = max(cur, cur + mxf[n - 2 - i] - (c - x[n - 1 - i]));
        res = max(res, cur);
    }
    
    cout << max({0LL, res, ans}) << endl;

    return 0;
}


Measured memory_bytes: 4992
import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()

from itertools import accumulate
 
def execute():
    n = readInt()
    count = 0
    res = False
    for _ in range(n):
        a,b = readIntList()
        if a == b :
            count += 1
        else:
            count = 0
        if count == 3:
            res = True
    if res:
        print("Yes")
    else:
        print("No")


    
 
if __name__ == "__main__":
    execute()



Measured memory_bytes: 9200
L,R = map(int,input().split())
 
x = 2019**2
if R-L >2019:
  x= 0
else:
  for i in range(L, R):
    for r in range(i+1, R+1):
        ans = (i*r) % 2019 
        if x > ans:
            x = ans
            if x == 0:
        	    break
    if x == 0:
      break
print(x)

Measured memory_bytes: 38896
#include<stdio.h>
#define MAX 100000
typedef struct{//親、左の子供、右の兄弟 のid
  int p,l,r;
}Node;
Node N[MAX]; //本体
int S[MAX];//右の兄弟をつなぐために、一つ前の兄弟覚えてる必要がある.



void Scan(void){
  int id;
  int agree;
  int k;
  static int s=0;

  scanf("%d%d",&id,&agree);

  for(k=0;k<agree;k++,s++){
    scanf("%d",&S[s]);   //scan child
     
    if(k==0)N[id].l=S[s];     //初めの入力だけ、起動　つまり一番左の子供
  
    N[S[s]].p=id;//こども　とっては親
    if(k)N[S[s-1]].r = S[s];//子供同士　は右の　兄弟
  }
}

int Depth(int i){//深さ探索 id入力
  int count=0;
  Node X=N[i];

  for(;X.p!=-1;count++){
    X=N[X.p];
  }
  return count;
}

void Print(int i){
  int j;
  Node X=N[i];
  
  printf("node %d: ",i);
  printf("parent = %d, ",N[i].p);
  printf("depth = %d, ",Depth(i));

  if(N[i].p==-1){//N[i]はルート 親いない
    printf("root, [");
    if(X.l!=-1){
      printf("%d",X.l);
      
      X=N[X.l];
      for(j=0 ; X.r!=-1 ;){
	printf(", %d",X.r);
	X=N[X.r];
      }
    }
    printf("]");
  }
  else if(N[i].l==-1){//N[i]は子供なし 下に誰もいない
    printf("leaf, []");
  }
  else{//N[i]は子供あり　
    printf("internal node, [");

    if(X.l!=-1){
      printf("%d",X.l);

      X=N[X.l];
      
      for(j=0;X.r!=-1;){
	printf(", %d",X.r);
	  
	X=N[X.r];
      }
    }
    printf("]");
  }
  printf("\n");
}



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

  for(i=0;i<MAX;i++){//INITIATE//　全部　-1
    N[i].p = N[i].l = N[i].r = -1;
  }
  
  for(i=0;i<n;i++)Scan();//INPUT n回

  for(i=0;i<n;i++){//OUTPUT
    Print(i);	
  }
  return 0;
}



Measured memory_bytes: 3416
#include <bits/stdc++.h>
#define maxn 200005
#define MOD 1000000007
#define INF 10000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}


void solve(){

    ll n, k;
    cin >> n >> k;
    ll kk ;
    if(n%k)
        kk = n/k+1;
    else kk = n/k;
    kk = (kk*k);
    ll kk1 = (n/k) * k; //cout << kk << " "<< kk1 << endl;
    cout << min(abs(kk-n), abs(n-kk1));

}

int main()
{
    //fast();
    solve();
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll A,B;
  cin>>A>>B;
  if(A==B) {
cout<<"Draw"<<endl;
  }
  else if(A==1) {
cout<<"Alice"<<endl;
  }
  else if(B==1) {
cout<<"Bob"<<endl;
  }
  else if(A>B) {
cout<<"Alice"<<endl;
  }
  else {
cout<<"Bob"<<endl;
  }
}

Measured memory_bytes: 3612
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (X[i] % 2 == 1) cnt++;
  }
  if (cnt % 2 == 1) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);++i)
#define test(x) cout << #x << ' ' << x << endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair 

int main () {
	string s1,s2,s="";
	cin >> s1 >> s2;
	int dp[s1.length()+1][s2.length()+1];
	int p[s1.length()+1][s2.length()+1];
	fop (i,0,s1.length()+1) dp[i][0]=0;
	fop (i,0,s2.length()+1) dp[0][i]=0;
	fop (i,0,s1.length()) {
		fop (j,0,s2.length()) {
			if (s1[i]==s2[j]) {
				p[i+1][j+1]=-1;
				dp[i+1][j+1]=dp[i][j]+1;
			} else if (dp[i][j+1]>dp[i+1][j]) {
				p[i+1][j+1]=1;
				dp[i+1][j+1]=dp[i][j+1];
			} else {
				p[i+1][j+1]=2;
				dp[i+1][j+1]=dp[i+1][j];
			}
		}
	}
	int r=s1.length(),c=s2.length();
	while (r!=0 and c!=0) {
		if (p[r][c]==-1) {
			r--;
			c--;
			s+=s1[r];
		} else if (p[r][c]==1) {
			r--;
		} else {
			c--;
		}
	}
	for (int i=s.length()-1;i>=0;--i) {
		cout << s[i];
	}
	cout << endl;
}

Measured memory_bytes: 70656
import sys

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

if sum(A)<=sum(B):
    print(-1)
    sys.exit()

Y=0
K=0
Q=[]

for i in range(N):
    k=A[i]-B[i]
    if k>0:
        Q.append(k)
    elif k<0:
        K+=1
        Y+=-k

Q.sort(reverse=True)

while Y>0:
    q=Q.pop(0)
    Y-=q
    K+=1

print(K)    


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

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

  const ll MOD=1e9+7;

  void solve(){
     ll n,m,k;
     cin >> n >> m >> k;
     vector<ll> a(n),b(m);
     for(int i=0;i<n;i++)cin >> a[i];
     for(int i=0;i<m;i++)cin >> b[i];
     vector<ll> prefa(n),prefb(m);
     for(int i=0;i<n;i++){
       if(i)prefa[i]=prefa[i-1]+a[i];
       else prefa[i]=a[i];
     }
     for(int i=0;i<m;i++){
       if(i)prefb[i]=prefb[i-1]+b[i];
       else prefb[i]=b[i];
     }

     int cnt=0;
     cnt = lower_bound(all(prefb),k+1)-prefb.begin();

     for(int i=0;i<n;i++){
       if(prefa[i]>k)break;
       else if(prefa[i]==k){cnt=max(cnt,i+1);break;}
       else{
          int k1 = lower_bound(all(prefb),(k-prefa[i]+1))-prefb.begin();
          cnt = max(i+1+k1,cnt);
       }
     }
     cout << cnt;
  }


  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 9532
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define pb push_back
    #define mp make_pair
    #define mod 1e9+7
    #define sz 100000
    #define f(i,n) for(ll i=0;i<n;i++)
    #define fab(i,a,b) for(ll i=a;i<b;i++)
    #define fr(i,n) for(ll i=n-1;i>=0;i--)
    #define fba(i,b,a) for(ll i=b-1;i>=a;i--)
    #define tc(t) ll t;cin>>t;while(t--)
     
    ll pw(ll x,unsigned ll y) 
    { 
        if (y==0) 
            return 1; 
        else if (y%2==0) 
            return pw(x,y/2)*pw(x,y/2); 
        else
            return x*pw(x,y/2)*pw(x,y/2);
    }
     
    int main() 
    {
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        cout.tie(NULL);
        ll n;
        cin>>n;
        ll a[n],mi[n];
        f(i,n)
        {
            cin>>a[i];
        }
        mi[0]=a[0];
        fab(i,1,n)
        {
            mi[i]=min(mi[i-1],a[i]);
        }
        ll c=1;
        fab(i,1,n)
        {
            if(a[i]<=mi[i-1]) c++;
        }
        cout<<c;
        return 0;
    }

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
class state{
	public:
	char f[11][11],c,l;
	state(){}
	state(int c,int l):c(c),l(l){};
};
char in[11][11];
state ne;
bool used[11][11];
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
int n,m;
int res;

void dfs(int next,int prev,int x,int y){
	if(x==0 && y==0){
		memset(used,false,sizeof(used));
	}
	ne.f[x][y]=next;
	used[x][y]=true;
	for(int i=0;i<4;i++){
		int nx=x+dx[i],ny=y+dy[i];
		if(nx>=0 && nx<n && ny>=0 && ny<m){
			if(!used[nx][ny]){
				used[nx][ny]=true;
				if(ne.f[nx][ny]==next){
				}
				if(ne.f[nx][ny]==prev){
					dfs(next,prev,nx,ny);
				}	
			}
		}
	}
}

void cnt(int prev,int x,int y){
	if(x==0 && y==0){
		ne.l=0;
		memset(used,false,sizeof(used));
	}
	ne.l++;
	used[x][y]=true;
	for(int i=0;i<4;i++){
		int nx=x+dx[i],ny=y+dy[i];
		if(nx>=0 && nx<n && ny>=0 && ny<m){
			if(!used[nx][ny]){
				used[nx][ny]=true;
				if(ne.f[nx][ny]==prev){
					cnt(prev,nx,ny);
				}	
			}
		}
	}
}

void bfs(state init){
	queue<state> que;
	res=50;
	que.push(init);
	while(que.size()){
		state p=que.front();
		que.pop();
		if(p.c>=res)break;
		ne.c=p.c+1;
		for(int i=0;i<=2;i++){
			memcpy(ne.f,p.f,sizeof(ne.f));
			dfs(i,ne.f[0][0],0,0);
			cnt(ne.f[0][0],0,0);
			if(ne.l==n*m)res=min(res,p.c+1);
			else if(ne.l>p.l)que.push(ne);
		}
	}
}

int main(void){
	while(1){
		res=100;
		scanf("%d%d\n",&n,&m);
		if(n==0 && m==0)break;
		state init=state(0,1);
		for(int i=0;i<m;i++){
			for(int j=0;j<n;j++){
				cin >> in[j][i];
				if(in[j][i]=='R')init.f[j][i]=0;
				if(in[j][i]=='G')init.f[j][i]=1;
				if(in[j][i]=='B')init.f[j][i]=2;
			}
		}
		memcpy(ne.f,init.f,sizeof(ne.f));
		cnt(ne.f[0][0],0,0);
		if(ne.l==n*m)printf("0\n");
		else{
			bfs(init);
			printf("%d\n",res);
		}
	}
	return 0;
}

Measured memory_bytes: 9108
n = int(input())
A = [0] * n
B = list(map(int, input().split()))

A[0] = A[1] = B[0]
for i in range(1, n - 1):
    if A[i] > B[i]:
        A[i] = B[i]
    A[i + 1] = B[i]

answer = sum(A)
print(answer)


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
//const ll mod = 1000 * 1000 * 1000 + 7;




void solve() {
    ll n, mod;
    cin >> n >> mod;
    vector<ll> d(n + 1, 0);
    d[0] = 1;
    for (int i = 0; i < n; ++i) {
        ll x = (i + 2) / 2;
        for (int j = 0; j < d.size(); ++j) {
            if (j >= x) {
                d[j] = (d[j] + d[j - x]) % mod;
            }
        }
        //cerr << d[0] << endl;
    }

    ll res = 0;
    for (int i = 0; i < n; ++i) {
        //cerr << d[i] << endl;
        res = (res + d[i]) % mod;
    }
    cout << res << endl;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N =scn.nextInt();
		int ans = 0;
		int now = 1;
		for(int i = 0;i < N;i++) {
			int a = scn.nextInt();
			if(a == now) {
				now++;
			}else {
				ans++;
			}
		}
		System.out.println((ans==N)?-1:ans);
	}

}


Measured memory_bytes: 63976
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    int hen = sqrt(pow(y1-y2,2)+pow(x1-x2,2));
    int idoux = abs(x2-x1);
    int idouy = abs(y2-y1);
    int x3,y3,x4,y4;
    if(x2>=x1&&y2<=y1){
        x3 = x2+idouy;
        y3 = y2+idoux;
        x4 = x1+idouy;
        y4 = y1+idoux;
    }
    else if(x2>=x1&&y2>y1){
        x3 = x2-idouy;
        y3 = y2+idoux;
        x4 = x1-idouy;
        y4 = y1+idoux;
    }
    else if(x2<x1&&y2>y1){
        x3 = x2-idouy;
        y3 = y2-idoux;
        x4 = x1-idouy;
        y4 = y1-idoux;
    }
    else if(x2<x1&&y2<=y1){
        x3 = x2+idouy;
        y3 = y2-idoux;
        x4 = x1+idouy;
        y4 = y1-idoux;
    }
    cout <<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}

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

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int r[25][252525], v[25];
int x[252525];
int dp[2525252];
int solve(int r1, int r2, int u) {
	return r[u][r2] - r[u][r1];
}
int main() {
	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> x[i]; x[i]--; r[x[i]][i]++; v[x[i]]++;
	}
	for (int i = 0; i < m; i++) {
		for (int j = 1; j <= 199995; j++)r[i][j] += r[i][j - 1];
	}
	for (int i = 0; i < (1 << m); i++)dp[i] = 999999999;
	dp[0] = 0;
	for (int i = 0; i < (1 << m); i++) {
		int bit[20]; for (int j = 0; j < m; j++)bit[j] = (i / (1 << j)) % 2;
		int sum = 0; for (int j = 0; j < m; j++) { if (bit[j] == 1)sum += v[j]; }
		for (int j = 0; j < m; j++) {
			if (bit[j] == 1)continue;
			int KOSUU = v[j] - solve(sum, sum + v[j], j);
			dp[i + (1 << j)] = min(dp[i + (1 << j)], dp[i] + KOSUU);
		}
	}
	cout << dp[(1 << m) - 1] << endl;
	return 0;
}

Measured memory_bytes: 23284
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n, y;
	static int[][] banks;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		n = sc.nextInt();
		if( n == 0 )return false;
		banks = new int[n][3];
		y = sc.nextInt();
		for(int i = 0; i < banks.length; i++){
			banks[i][0] = sc.nextInt();
			banks[i][1] = sc.nextInt();
			banks[i][2] = sc.nextInt();
		}
		return true;
	}
	
	static void solve(){
		double max = -1.0;
		int res = -1;
		for(int i = 0; i < banks.length; i++){
			double money = 0.0;
			if( banks[i][2] == 1 ){
				money = getSimpleInterest(banks[i]);
			}else{
				money = getCompoundInterest(banks[i]);
			}
			if( max < money ){
				res = banks[i][0];
				max = money;
			}
		}
		System.out.println(res);
	}
	
	static double getSimpleInterest(int[] data){
		double r = (double)data[1];
		return 10000*(1+y*r/100);
	}
	
	static double getCompoundInterest(int[] data){
		double r = (double)data[1];
		return 10000*Math.pow(1+r/100, y);
	}

}

Measured memory_bytes: 37732
#include<bits/stdc++.h>
using namespace std;
void solve()
{
	long long n;
	cin>>n;
	long a[n];
	for(long long i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	if(a[0]==0)
	{
		cout<<0;
		return;
	}
	long long ans=1,tm=1e18;
	for(long long i=0;i<n;i++)
	{
		if((tm/ans)>=a[i]) 
			ans*=a[i];
		else
		{
			cout<<-1;
			return;
		}
	}
	cout<<ans<<endl;
}
int main()
{
 	solve();
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
#define pb push_back
#define ppb pop_back
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int N = 1e5 + 667;

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

    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes";
    else cout << "No";
    return 0;
}


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

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

  int n;
  int a_score;
  int b_score;
  while(true) {
    a_score = 0;
    b_score = 0;
    cin >> n;
    if(n == 0) break;
    for(int i=0;i<n;i++) {
      int a_card,b_card;
      cin >> a_card >> b_card;
      if( a_card > b_card ) {
        a_score += a_card + b_card;
      }
      else if( b_card > a_card) {
        b_score += a_card + b_card;
      }
      else {
        // if a_card == b_card
        a_score += a_card;
        b_score += b_card;
      }
    } // end for
    cout << a_score << " " << b_score << "\n";
  } // end while
}

Measured memory_bytes: 1196
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;

    vector<vector<int> > m(h, vector<int>(w, 0));
    REP(i, h) REP(j, w) {
        char c; cin >> c;
        if (c == '.') m[i][j] = 0;
        if (c == '#') m[i][j] = 1;
    }

    vector<vector<int> > l(h, vector<int>(w, 0));
    copy(m.begin(), m.end(), l.begin());

    REP(i, h) {
        int count = 0;
        REP(j, w)
            if (m[i][j] == 0) count++;
        if (count == w)
            REP(j, w) m[i][j] = -1;
    }

    REP(j, w) {
        int count = 0;
        REP(i, h)
            if (l[i][j] == 0) count++;
        if (count == h)
            REP(i, h) l[i][j] = -1;
    }

    REP(i, h) {
        REP(j, w) {
            if (m[i][j] != -1 && l[i][j] != -1) {
                if (l[i][j] == 0) cout << '.';
                if (l[i][j] == 1) cout << '#';
            }
        }
        int count = 0;
        REP(j, w)
            if (m[i][j] == -1) count++;
        if (count != w) cout << '\n';
    }
    return 0;
}


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

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

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

typedef long long ll;typedef vector<int> vi;typedef pair<int ,int > pii;typedef map<int,int>mii;

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define el <<"\n"
#define newline printf("\n")
#define scd(x) scanf("%d",&x)
#define scdd(x,y) scanf("%d%d",&x,&y)
#define scddd(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scd(x) scanf("%ld",&x)
#define scdd(x,y) scanf("%ld%ld",&x,&y)
#define scddd(x,y,z) scanf("%ld%ld%ld",&x,&y,&z)
#define yo printf("YES\n")
#define noo printf("NO\n")
#define F first
#define S second
#define pb(a) push_back(a)
#define bg begin()
#define en end()
#define itr iterator
#define gcd(a,b) __gcd(a,b)
#define all(x) x.bg,x.en
int i;

int main()
{
    int x,y;
    scdd(x,y);
    int a[]={4,6,9,11},b[]={1,3,5,7,8,10,12};
    int n=sizeof(a)/sizeof(a[0]),m=sizeof(b)/sizeof(b[0]);
    bool u=false,v=false;
    for(i=0;i<n;i++)
    {
        if(a[i]==x)
            u=true;
        if(a[i]==y)
            v=true;
    }
    if(u&&v)
        cout<<"Yes" el;
    else
    {
        u=false,v=false;
        for(i=0;i<m;i++)
    {
        if(b[i]==x)
            u=true;
        if(b[i]==y)
            v=true;
    }
    if(u&&v)
        cout<<"Yes" el;
    else
        cout<<"No" el;
    }
    return 0;
}



Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    if (a*b%2) {
        cout << "Odd" << endl;
    }
    else {
        cout << "Even" << endl;
    }

}


Measured memory_bytes: 256
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//$P = explode(" ",trim(fgets(STDIN)));
$H = array_map('intval',explode(" ",trim(fgets(STDIN))));
//function chmax(&$a,$b) {if ($a<$b){$a=$b;return true;}return false;}
//function chmix(&$a,$b) {if ($a>$b){$a=$b;return true;}return false;}

$cv = array_count_values($H);

foreach($cv as $v) {
  if ($v > 1) {
    printf("NO\n");
    exit;
  }
}
printf("YES\n");


Measured memory_bytes: 33780
s = int(input())

def func(n):
  if n % 2 == 0:
    return n // 2
  else:
    return 3 * n + 1
a = [s]
i = 1
while True:
  if func(a[i-1]) in a:
    print (i+1)
    break
  else:
    a.append(func(a[i-1]))
    i += 1

else:
  print ("not found")

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;
const int INF = (1e+9) + 1;
const int N = 500000;
int n, c;
int a[N], L[N], R[N];

void merge(int l, int m, int r) {
  int i, j, k;
  int nl = m - l;
  int nr = r - m;
  for (int i=0; i<nl; i++)
    L[i] = a[l + i];
  for (i=0; i<nr; i++)
    R[i] = a[m + i];

  L[nl] = R[nr] = INF;

  i = j = 0;
  for (k=l; k<r; k++) {
    c++;
    if (L[i] <= R[j])
      a[k] = L[i++];
    else
      a[k] = R[j++];
  }
}

void merge_sort(int l, int r) {
  if (l+1<r) {
    int m = (l+r)/2;
    merge_sort(l, m);
    merge_sort(m, r);
    merge(l, m, r);
  }
}

int main() {
  int i;
  c = 0;
  scanf("%d ", &n);
  for (i=0; i<n; i++)
    scanf("%d ", a+i);
  merge_sort(0, n);

  for (i=0; i<n; i++)
    printf("%d%c", a[i], ( (i==n-1) ? '\n' : ' '));
  printf("%d\n", c);

  return 0;
}

Measured memory_bytes: 6080
n=int(input())
a=[int(i) for i in input().split()]

s=[a[0]]
for i in range(n-1):
	s.append(s[i]+a[i+1])
ans=s[n-1]
j=0
k=2
for i in range(1,n-2):
	while abs(s[i]-2*s[j]) > abs(s[i]-2*s[j+1]):
		j=j+1
	while abs(s[n-1]-2*s[k]+s[i]) > abs(s[n-1]-2*s[k+1]+s[i]):
		k=k+1
	t=max(s[j],s[i]-s[j],s[k]-s[i],s[n-1]-s[k])-min(s[j],s[i]-s[j],s[k]-s[i],s[n-1]-s[k])
	if ans>t:
		ans=t
print(ans)


Measured memory_bytes: 24684
#include<bits/stdc++.h>
using namespace std;
int n,a[200001];
bool b[200001];
int l,r,mid,ans;
bool check (int x)
{
	for (int i=1;i<=2*n-1;i++)
	b[i]=(a[i]>=x);
	/*
	printf("%d\n",x);
	for (int i=1;i<=2*n-1;i++)
	printf("%d ",b[i]);
	printf("\n");
	*/
	bool bo=true;
	for (int i=2;i<=2*n-1;i++)
	if (b[i]==b[i-1]) { bo=false; break; }
	if (bo) return b[1];
	for (int l=n-1,r=n+1;;l--,r++)
	{
		if (b[l]==b[l+1]) return b[l];
		if (b[r]==b[r-1]) return b[r];
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=2*n-1;i++)
	scanf("%d",&a[i]);
	//printf("%d %d\n",check(2),check(3));
	l=1;
	r=2*n-1;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (check(mid)) l=mid+1,ans=mid;
			else r=mid-1;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1280
import math

n, d = map(int,input().split())
num = list(list(map(int, input().split())) for i in range(n))

count = 0

for i in range(n - 1):
  for j in range(i + 1, n):
    s = 0
    for k in range(d):
      s += (num[i][k] - num[j][k]) ** 2
    s = math.sqrt(s)
    if(s == int(s)):
      count += 1
print(count)


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

using namespace std;

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


int main(void){
    int n, W;
    cin >> n >> W;

    vector<int> v(n), w(n);
    vector<vector<int> > dp(105, vector<int>(10005, 0));

    rep(i, n){
        cin >> v[i] >> w[i];
    }

    rep(i, n){
        rep(j, W+1){
            if(j < w[i]){
                dp[i+1][j] = dp[i][j];
            }else{
                dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j]);
            }
        }
    }


    cout << dp[n][W] << "\n";

    return 0;
}


Measured memory_bytes: 7124
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    CNT = [0] * (N + 1)

    for ai in A:
        CNT[ai] += 1

    # print(CNT)

    CNT2 = [i for i in CNT if i != 0]
    CNT2.sort()
    # print(CNT2)

    x = len(CNT2) - K
    print(sum(CNT2[:x]))
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 25644
W,H,N=map(int,input().split())
x=y=0
for i in range(N):
  xi,yi,a=map(int,input().split())
  if a==1:
    x=max(x,xi)
  elif a==2:
    W=min(W,xi)
  elif a==3:
    y=max(y,yi)
  elif a==4:
    H=min(H,yi)
    
print(0 if x>=W or y>=H else (W-x)*(H-y))

Measured memory_bytes: 3064