akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        Integer[] nums = new Integer[200000];
        Arrays.fill(nums, 0);
        for(int i = 0; i < n; i++) {
            int num = sc.nextInt();
            nums[num]++;
        }
        Arrays.sort(nums, Collections.reverseOrder());
        long sum = 0;
        for(int i = k; i < 200000; i++) {
            sum += nums[i];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 82840
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=6005;
int n,q[N],hd=1,tl,mat[N],vis[N];string str,f[N];
int main(){
	cin>>n>>str;n<<=1;
	for(int i=0;i<n;++i)
		if(hd<=tl&&str[q[hd]]!=str[i])
			mat[i]=q[hd],mat[q[hd]]=i,++hd;
		else
			q[++tl]=i;
	f[n]="";
	for(int i=n-1;~i;--i){
		if(mat[i]>i)
			if(str[i]=='a')
				f[i]="ab"+f[mat[i]+1];
			else{
				memset(vis,0,sizeof(vis));
				int k=i;
				for(int j=i;j<=k;++j){
					if(str[j]=='b')
						vis[j]=vis[mat[j]]=1,k=mat[j];
					if(vis[j])
						f[i]+=str[j];
				}
				f[i]+=f[k+1];
			}
		f[i]=max(f[i],f[i+1]);
	}
	cout<<f[0]<<endl;
	return 0;
}


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

int main(void){
    // Your code here!
    long long l, r;
    string s;
    
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A'){
            l = i;
            break;
        }
    }
    
    for(int i = s.size()-1; 0 <= i; i--){
        if(s[i] == 'Z'){
            r = i;
            break;
        }
    }
            
    cout << r - l + 1 << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
char a[105][105];

int w, h;
char flag;
int ans;

void dfs(int x, int y)
{
    if(a[x][y] == flag && x >= 0 && x < h && y >= 0 && y < w)
    {
        a[x][y] = '.';
        dfs(x+1, y);
        dfs(x-1, y);
        dfs(x, y+1);
        dfs(x, y-1);
    }

}

int main()
{
    while(~scanf("%d %d", &h, &w))
    {
        ans = 0;
        if(w == 0 && h == 0)
            break;
        for(int i = 0; i < h; i++)
            for(int j = 0; j < w; j++)
                cin >> a[i][j];
        for(int i = 0; i < h; i++)
            for(int j = 0; j < w; j++)
                if(a[i][j] != '.')
                {
                    flag = a[i][j];
                    dfs(i, j);
                    ans++;
                }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3708
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define INF (2000000000)
#define MOD (1000000007)
using namespace std;

typedef vector<int> VI;
typedef vector<int>::iterator VII;
typedef vector<double> VD;
typedef vector<double>::iterator VDI;
typedef pair<int, int> P;


int prime[300000];

int main()
{
	for (int i = 2; i < 300000; i++){
		prime[i] = 1;
	}
	for (int i = 2; i * i < 300000; i++){
		for (int j = i * i; j < 300000; j += i){
			prime[j] = 0;
		}
	}
	for (int i = 1; i < 300000; i++){
		prime[i] += prime[i - 1];
	}
	
	int n;
	while (scanf("%d", &n), n){
		printf("%d\n", prime[n * 2] - prime[n]);
	}
	
	return 0;
}

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

int N;

int main(){
    string pe;
    cin >> N;
    cin >> pe;
    vector<int> cot(N, 0);
    for(int i = 1; i<N; i++){
        if(pe[i] == 'E'){
            cot.at(0)++;
        }
    }

    for(int i = 1; i<N; i++){
        int buf = 0;
        if(pe[i-1] == 'W'){
            buf++;
        }
        if(pe[i] == 'E'){
            buf--;
        }
        cot.at(i) = cot.at(i-1) + buf;
    }
    sort(cot.begin(), cot.end());
    cout << cot.at(0) << endl;


}

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

int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    long long cnt = 0;
    for (int i = 0; i < n; i++) {
        if (!i && s[i] || i && s[i] - s[i - 1] > 1) {
            cout << "-1" << endl;
            return 0;
        }
        if (i) {
            cnt += s[i] > s[i - 1] ? 1 : s[i];
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1024
N,K,Q = map(int, input().split())

point = [0 for i in range(N)]
for i in range(Q):
    point[int(input())-1] += 1

d = Q - K
ans = []
if d < 0:
    for i in range(N):
        print("Yes")
else :
    for i in range(0, N):
        if point[i] > d:
            print("Yes")
        else:
            print("No")


Measured memory_bytes: 4668
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;

int main(){
    ll mx = pow(10, 18);
    int n;
    cin >> n;
    ll ans = 1;
    bool flag = false;
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x;
        if(ans == 0) continue;

        if(x == 0){
            ans = 0;
            flag = false;
        }
        else if(log10(x) + log10(ans) >= 18){
            if(ans * x  != mx){
                flag = true;
            }
        } 
        
        if(flag) continue;
        ans *= x;
    }

    if(flag){
        cout << -1 << endl;
        return 0;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3964
#include<bits/stdc++.h>
 using namespace std;
int main(){
  int n, m;
  cin >> n;
  int l[20];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> l[i];
    sum += l[i];
    m = max(m, l[i]);
  }
  string res = "Yes";
  if (sum - m <= m) {
    res = "No";
  }

  cout << res << "\n";
}


Measured memory_bytes: 256
import math
n,d=map(int,input().split())
x=[]
for i in range(n):
    x.append(list(map(int,input().split())))
ans=0
for i in range(n):
    for j in range(i+1,n):
        if i!=j:
            dis=0
            for k in range(d):
                dis+=(x[i][k]-x[j][k])**2
            dis=math.sqrt(dis)
            if dis==int(dis):
                ans+=1

print(ans)

Measured memory_bytes: 9160
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace AtCoderABC111
{
    class Program
    {
        static string Cal(char i, char j)
        {
            return (i == '1' && j == '1') ? "R":
                   (i == '1' && j == '0') ? "U":
                   (i == '0' && j == '1') ? "D": "L";
        }
        static long pow(long i, long j)
        {
            return (j > 0)? i * pow(i, j - 1) : 1;
        }

        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long two31 = pow(2, 31);
            long[,] a = new long[N, 2];
            for (int i = 0; i < N; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                a[i, 0] = long.Parse(s[0]);
                a[i, 1] = long.Parse(s[1]);
            }
            long mod = Math.Abs(a[0, 0] + a[0, 1]) % 2;
            for (int i = 1; i < N; i++)
            {
                if (Math.Abs(a[i, 0] + a[i, 1]) % 2 != mod)
                {
                    Console.WriteLine("-1");
                    return;
                }
            }

            if (mod == 0)
            {
                for (int i = 0; i < N; i++) a[i, 0]--;
            }

            if (mod == 0)
            {
                Console.WriteLine("32");
                Console.Write("1 ");
                long temp = 1;
                for (int i = 0; i < 30; i++)
                {
                    Console.Write("{0} ", temp);
                    temp *= 2;
                }
                Console.WriteLine(temp);
            }
            else
            {
                Console.WriteLine("31");
                long temp = 1;
                for (int i = 0; i < 30; i++)
                {
                    Console.Write("{0} ", temp);
                    temp *= 2;
                }
                Console.WriteLine(temp);
            }

            for (int i = 0; i < N; i++)
            {
                long x = a[i, 0], y = a[i, 1];
                string u = Convert.ToString((x + y + two31 - 1) / 2, 2).PadLeft(31, '0');
                string v = Convert.ToString((x - y + two31 - 1) / 2, 2).PadLeft(31, '0');

                string s = (mod == 0)? "R": "";

                for (int j = 30; j > -1; j--) s += Cal(u[j], v[j]);

                Console.WriteLine(s);
            }
        }
    }
}

Measured memory_bytes: 15420
a,b,c,k=map(int,input().split())
ans=0
if a>=k:
    ans+=k
    print(ans)
    exit()
else:
    k-=a
    ans+=a
if b>=k:
    print(ans)
    exit()
else:
    k-=b
if c>=k:
    ans-=k
    print(ans)
    exit()


Measured memory_bytes: 9188
#include<iostream>

int main()
{
	using namespace std;
	int a,b,c,x,y,t;
	long int sum=0;
	cin>>a>>b>>c>>x>>y;
	double aver=(a+b)/2;
	if(aver>c)
	{
		t=x-y;
		if(t<0)
		{
			t*=-1;
			sum+=x*c*2;
			sum+=t*b;
			if(sum>y*c*2)
			{
				sum=y*c*2;
			}
		}
		else{
			sum+=y*c*2;
			sum+=t*a;
			if(sum>c*x*2)
			{
				sum=c*x*2;
			}
		}
	}
	else
	{
		sum+=a*x+b*y;
		if(sum>c*2*(x<y?y:x))
			sum=c*2*(x<y?y:x);
	}
	cout<<sum<<endl;
	return 0;
}


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

typedef long long ll ;
using namespace std;

void solve(){
    int n, m;
    cin >> n >> m;

    vector<vector<int>> g(n, vector<int>());
    int u, v;
    while (m--) {
        cin >> u >> v;
        u--;v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    vector<bool> vis(n, false);
    queue<int> q;
    q.push(0);
    vis[0] = true;

    int ans[n];

    while(!q.empty()) {
        int f = q.front();
        q.pop();
        for (int to : g[f]) {
            if (!vis[to]) {
                ans[to] = f + 1;
                vis[to] = true;
                q.push(to);
            }
        }
    }

    for (auto const & b : vis) {
        if (!b) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << ans[i] << endl;
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 10180
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000
void csort(int, int*);
main()
{
        int i, n, *table;
        scanf("%d", &n);
        table = (int*)malloc(sizeof(int) * n);
        for (i= 0; i < n; i++) {
                scanf("%d", &table[i]);
        }
        csort(n, table);
        for (i= 0; i < n - 1; i++) {
        printf("%d ", table[i]);
    }
        printf("%d\n", table[i]);
        free(table);
}
void csort(int n, int *table)
{
        int i, work[n], count[MAX + 1] = {0};
        for (i = 0; i < n; i++) {
                int key = table[i];
                count[key]++;
        }
        for (i = 0; i < MAX; i++) {
        count[i + 1] += count[i];
    }
        for (i = 0; i < n; i++) {
        int key = table[i];
                work[--count[key]] = key;
    }
        for (i = 0; i < n; i++) {
        table[i] = work[i];
    }
}


Measured memory_bytes: 17060
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(A),
    get_number(B),
    get_number(C),
    X is max(max(A, B), C),
    Z is min(min(A, B), C),
    Y is A + B + C - X - Z,
    R is 10 * X + Y + Z,
    writeln(R).


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

def ans_one(i):
    ans=0
    for a in A:
        ans += (a-i)**2
    return ans

ans=10**20
for i in range(-102,103):
    ans_ = ans_one(i)
    if ans_ < ans:
        ans =ans_
print(ans)

Measured memory_bytes: 8952
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] a = new long[N];
		long sum = 0;
		long ans = Long.MAX_VALUE;
		for(int i=0; i<N; i++) {
			sum += sc.nextLong();
			a[i] = sum;
		}
		for(int i=0; i<N-1; i++) {
			ans = Math.min(ans, Math.abs(sum-2*a[i]));
		}
		System.out.println(ans);
	}
	
	// print
	static void print(String s) {
		System.out.println(s);
	}
	
	// union find lib
	// usage:
	// 最初にinitを呼ぶ
	// root: 直接は呼ばないで
	// unite: まとめる
	// same: グループ判定
	static void init(int par[], int N) {
		for(int i=0; i<N; i++) {
			par[i] = i;
		}
	}
	
	static int root(int x, int [] par) {
		if(par[x] == x) {
			return x;
		} else {
			return (par[x] = root(par[x], par));
		}
	}
	
	static boolean same(int x, int y, int[] par) {
		return root(x, par) == root(y, par);
	}
	
	static void unite(int x, int y, int[] par) {
		x = root(x, par);
		y = root(y, par);
		if(x == y) return;
		par[x] = y;
	}
	
	// end union find lib
	
	// number lib
	
	static long lcm(long a, long b) {
		return a*(b/gcd(a, b));
	}
	
	static long gcd(long a, long b) {
		long ta = Math.max(a, b);
		long tb = Math.min(a, b);
		long tmp;
		while((tmp = ta%tb) != 0) {
			ta = tb;
			tb = tmp;
		}
		return tb;
	}
	
	static long modcomb(long n, long k, long mod) {
		if(k==1) {
			return n;
		}
		
		long ans = 1;
		for(long i=n; i>=n-k+1; i--) {
			ans = (ans * i)%mod;
		}
		for(long i=k; 0<i; i--) {
			ans = (ans * modpow(i, mod-2, mod)) % mod;
		}
		return ans;
	}
	
	static long modpow(long a, long b, long mod) {
		if(b==0) return 1;
		if(b%2==0) {
			long d = modpow(a, b/2, mod);
			return (d*d)%mod;
		} else {
			return (a*modpow(a, b-1, mod))%mod;
		}
	}
	
	static int disit(long a, long d) {
		int count = 0;
		while(a!=0) {
			a = a/d;
			count++;
		}
		return count;
	}
	
	// end number lib
}

Measured memory_bytes: 64216
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[8] = { 0,0,1,-1, 1,1,-1,-1 };// 前４つで４近傍
const int c_Dy[8] = { 1,-1,0,0 ,1,-1,1,-1};// 全部で８近傍
const int c_div = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846;


int main() {


	char S[1000];
	scanf("%s", S);

	printf("%c%d%c", S[0], strlen(S) - 2, S[strlen(S) - 1]);










}







Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int A[][] = new int[n][m];
        int b[] = new int[m];
        int i,j,c;
        
        for(i=0; i<n; i++){
            for(j=0; j<m; j++){
                A[i][j] = sc.nextInt();
            }
        }
        
        for(j=0; j<m; j++){
            b[j] = sc.nextInt();
        }
        
        for(i=0; i<n; i++){
            c = 0;
            for(j=0; j<m; j++){
                c += ( A[i][j] * b[j] );
            }
            System.out.println(c);
        }
    }
}

Measured memory_bytes: 40820
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
	
  	if(a + b >= c)
    	cout << "Yes" << endl;
	else
      	cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100

void swap(int*, int*);
void pr(int*, int);

int main(){
  int n, i, j, k;
  int t=0; // times
  int a[N];

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &a[i]);

  for( i = 0 ; i < n ; i++){
    for(j = n-1 ; j > i ; j--){
      if( a[j] < a[j-1] ){
	swap(&a[j] ,&a[j-1]);
	t++;
      }
    }
  }

  pr(a,n);
  printf("%d\n" ,t);
  return 0;
}

void swap(int *a_p, int *b_p){
  int k;
  k    = *a_p;
  *a_p = *b_p;
  *b_p = k;
}

void pr(int *a_p, int n){
  int i;
  for( i = 0 ; i < n-1 ; i++ ){
    printf("%d " ,a_p[i]);
  }
  printf("%d" , a_p[n-1]);
  printf("\n");
}

Measured memory_bytes: 604
#include<iostream>
#include<string>
int main(){
    double a,b,n;
    int n2;
    std::cin>>a>>b;
    n=(a+b)/2;
    n2=n;
    if((n-n2)>0)printf("%d",n2+1);
    else printf("%d",n2);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S =(list(input()))
newS=[]
for i in S:
    if i == ".":
        newS.append(0)
    else:
        newS.append(1)

countW=newS.count(0)
countB=newS.count(1)
ans=min(countW,countB)
countB=0
for s in newS:
    if s ==1:
        
        countB+=1
    else:
      countW-=1
      
        
    ans=min(ans,countB+countW)
    #print(countB,countW)
#print(ans)
print(ans)

Measured memory_bytes: 6436
n = int(input())
a = [int(i) for i in input().split()]
alice = 0
bob = 0

while a != []:
  alice += max(a)
  a.remove(max(a))
  try:
  	bob += max(a)
  except:
    break
  try:
    a.remove(max(a))
  except:
    break
    
print(alice-bob)

Measured memory_bytes: 3060
#include<stdio.h>
 
int gcd(int a,int b){
	if(b==0)
      return a;
  	return gcd(b,a%b);
}
 
int gcd2(int a,int b,int c){
  int t;
  t=gcd(a,b);
  return gcd(t,c);
}
 
int main(void){
	int n,i,j,k,t=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
    	for(j=1;j<=n;j++){
    		for(k=1;k<=n;k++){
    			t+=gcd2(i,j,k);
		    }
		}
	}

  printf("%d",t);
  return 0;
}

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

int main()
{
	double n, ans = 0;
	bool flag = false;
	cin >> n;
	
	for (int i = 1; i <= n; ++i)
	{
		if ((int)n == (int)(i * 1.08))
		{
			ans = i;
			flag = true;
			break;
		}
	}
	
	if (flag)
	{
		cout << ans << endl;
	}
	else
	{
		cout << ":(" << endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

int dp[40000][5];

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;

		memset(dp,0,sizeof(dp));

		dp[0][0] = 1;
		for(int i=1;i*i<=n;i++){
			for(int k=1;k<=4;k++){
				for(int j=i*i;j<=n;j++){
					dp[j][k] += dp[j-i*i][k-1];
				}
			}
		}

		printf("%d\n",dp[n][4] + dp[n][3] + dp[n][2] + dp[n][1]);
	}
}

Measured memory_bytes: 1976
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=4;
LL a,b,c,k;
LL v[N][N];
LL LLabs(LL a){
	return a<0?-a:a;
}
int main(){
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	k%=2;
	if (k){
		LL aa,bb,cc;
		aa=b+c,bb=a+c,cc=a+b;
		a=aa,b=bb,c=cc;
	}
	LL ans=a-b;
	if (LLabs(ans)>10e18)
		puts("-1");
	else
		printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
import math

N = int(input())
A = [int(input()) for i in range(N)]

B = sorted(A)

for i in range(N):
    if A[i] != B[-1]:
        print(B[-1])
    else:
        if B[0] == B[-1]:
            print(B[0])
        else:
            print(B[-2])


Measured memory_bytes: 14112
#include<stdio.h>
#define MAX 3000

int main(void)
{

    int a,b;
    int i;
    int temp;

    for(i = 1;i <= MAX;i++){
      scanf("%d %d",&a,&b);

      if(a == 0 && b == 0)
        break;
      else{
        if(a > b){
          temp = a;
          a = b;
          b = temp;
        }

        printf("%d %d\n",a,b);
      }
    }

    return 0;
}




Measured memory_bytes: 2580
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main()
{
    int X;
    cin >> X;
    if(X == 1){
        cout << 1 << endl;
        return 0;
    }
    int mnum = 1;
    for(int b = 2; b < X; ++b){
        int p = 2;
        while(true){
            if(pow(b,p) <= X){
                mnum = max(mnum, static_cast<int>(pow(b, p)));
                p++;
                continue;
            }else{
                break;
            }
        }
    }
    cout << mnum << endl;
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
pair <pii,int> city[200000];
int n,m;
str id[200000];
str ID(int p, int x){
    str temp = "";
    while(x>0){
        int last = x%10;
        temp = char(last+'0') + temp;
        x/=10;
    }
    while(temp.size()<6){
        temp = '0' + temp;
    }
    while(p>0){
        int last = p%10;
        temp = char(last+'0') + temp;
        p/=10;
    }
    while(temp.size()<12){
        temp = '0' + temp;
    }
    return temp;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int p,y;
        cin>>p>>y;
        city[i] = mp (mp (p,y),i);
    }
    sort(city+1,city+1+m);
    int f = 0;
    for(int i=1;i<=m;i++){
        if(city[i].ff!=city[i-1].ff){f=1;}
        else{f++;}
        id[city[i].se] = ID(city[i].ff,f);
    }
    for(int i=1;i<=m;i++)cout<<id[i]<<endl;


}


Measured memory_bytes: 8960
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
//set<pair<ll,ll>> spll;
//map<string,ll> mp;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<ll> deq;
//vector<ll> vll;
ll num[ten5];
//priority_queue<ll> pq;          //decreasing

int main(void)
{
    ll m,n,i,j,k=0,d,re=0;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        re+=s[i]-'0';
        re%=9;
    }
    re%=9;
    if(re==0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}





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

int main(){
    int n;
    cin >> n;
    int A[n],B[n],C[n];
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    for(int i=0;i<n;i++){
        cin >> B[i];
    }
    for(int i=0;i<n;i++){
        cin >> C[i];
    }
    sort(A,A+n);
    sort(C,C+n);

    long long ans=0;
    for(int i=0;i<n;i++){
        int mid=B[i];
        auto up=lower_bound(A,A+n,mid);
        auto low=upper_bound(C,C+n,mid);
        
        long long a=up-A;
        long long c=C+n-low;

        ans+=a*c;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
	//変数の宣言
	int n,l;
	int a[100010];

	//よく使う変数
	int i,j,k;
	int flag=0;
	long int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	//データの読み込み
	
	scanf("%d %d",&n,&l);
	
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=0;i<n-1;i++){
		if(a[i]+a[i+1]>=l){
			flag=1;
			break;
		}
	}
	
	if(flag==0){
		printf("Impossible");
	}else{
		printf("Possible\n");
		temp=i;
		for(i=1;i<=temp;i++){
			printf("%d\n",i);
		}
		for(i=n-1;i>temp;i--){
			printf("%d\n",i);
		}
	}
	
	
//	printf("計算部分終了\n");
	//出力
	
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define INF 111111111111111111
#define MOD 1000000007
#define pb push_back
#define F first 
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag;
#pragma endregion
#define MAX 111111


int main(void) {
  ll a, b;
  cin >> a >> b;
  ans = a;
  if (a > b) ans--;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main() {
	string N; cin >> N;
	for (int i = 0; i < 3; ++i) {
		if (N[i] == '7') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m ;
    cin>>m;
    return m ;
}
int main()
{
 string s1,s2,s3;
 cin>>s1>>s2>>s3;
 cout<<s1[0]<<s2[0]<<s3[0]<<endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll n, a, b;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> a >> b;
  ll ans;
  if(abs(a - b) % 2 == 0) {
    ans = abs(a - b) / 2;
  } else {
    ll ma = n - max(a, b) + 1 + ((n - min(a, b)) - (n - max(a, b) + 1)) / 2;
    ll mb = min(a, b) + ((max(a, b) - 1) - min(a, b)) / 2;
    ans = min(ma, mb);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
A11, A12, A13 = gets.split(" ").map(&:to_i)
A21, A22, A23 = gets.split(" ").map(&:to_i)
A31, A32, A33 = gets.split(" ").map(&:to_i)

nums = []
gets.to_i.times do |_|
  nums << gets.to_i
end

nums.sort!

if ((nums & [A11, A12, A13].sort) == [A11, A12, A13].sort) ||
	((nums & [A21, A22, A23].sort) == [A21, A22, A23].sort) ||
	((nums & [A31, A32, A33].sort) == [A31, A32, A33].sort) ||
	((nums & [A11, A21, A31].sort) == [A11, A21, A31].sort) ||
	((nums & [A12, A22, A32].sort) == [A12, A22, A32].sort) ||
	((nums & [A13, A23, A33].sort) == [A13, A23, A33].sort) ||
	((nums & [A11, A22, A33].sort) == [A11, A22, A33].sort) ||
	((nums & [A13, A22, A31].sort) == [A13, A22, A31].sort)
  puts "Yes"
else
  puts "No"
end

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

using namespace std;

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

  if (find(N.begin(), N.end(), '7') != N.end()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3620
import sys
sys.setrecursionlimit(10000000)


def main():
    N = int(input())
    A = [int(c) for c in input().split()]

    # 自分が1だったときのそれ以降
    lists = [0] * (N + 1)
    for i, a in enumerate(A):
        if i <= a:
            continue
        lists[i + 1 - a] += 1
    
    num = 0
    for i, a in enumerate(A):
        idx = i + 1
        if idx + a <= N:
            num += lists[idx + a]
    print(num)







if __name__ == '__main__':
    main()


Measured memory_bytes: 32144
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, q;
        long com, x, y;
        RmQ dat;

        n = Integer.parseInt(sc.next());
        q = Integer.parseInt(sc.next());

        dat = new RmQ(n);

        for (int i = 0; i < q; i++) {
            com = Long.parseLong(sc.next());
            x = Long.parseLong(sc.next());
            y = Long.parseLong(sc.next());

            if (com == 0) {
                dat.update((int)x, y);
            }
            else {
                System.out.println(dat.query((int)x, (int)y + 1));
            }

        }
    }
}

class RmQ extends SegmentTree<Long> {
    public RmQ(int nmemb) {
        super(nmemb, (1l << 31l) - 1);
    }
    
    @Override
    protected Long operator(Long x, Long y) {
        return Math.min(x, y);
    }
}


/**
 * モノイドを乗せられるセグメントツリーの抽象クラス<br>
 * operator メソッドをオーバライドすることで二項演算を定義する<br>
 * データの1点更新と区間に対する質問クエリをO(log(N))で行う
 */
abstract class SegmentTree<T> {

    /** 単位元 */
    protected T e;

    protected int n;
    protected ArrayList<T> tree;

    
    abstract protected T operator(T x, T y);

    /**
     * 要素eで埋められた要素数nmemb個のセグ木を生成
     * @param nmemb 要素数
     * @param e 初期要素(単位元であること)
     */
    public SegmentTree(int nmemb, T e) {
        this.e = e;
        
        n = 1;
        while (n < nmemb) {
            n *= 2;
        }

        tree = new ArrayList<T>(2 * n - 1);
        for (int i = 0; i < 2 * n - 1; i++) {
            tree.add(e);
        }
    }

    /**
     * データを更新する.<br>
     * O(log(N))
     * @param k データの位置
     * @param dat 更新データ
     */
    public void update(int k, T dat) {
        k += n - 1;

        tree.set(k, dat);

        while(k > 0) {
            k = (k - 1) / 2;
            tree.set(k, operator(tree.get(k * 2 + 1), tree.get(k * 2 + 2)));
        }
    }
    
    /**
     * [l, r)区間の二項演算の結果を返す.<br>
     * O(log(N))
     * @param l 区間の左
     * @param r 区間の右
     * @return 演算結果
     */
    public T query(int l, int r) {
        l += n - 1;
        r += n - 1;

        T d = e;
        while (l < r) {
            if ((l & 1) == 0) {
                d = operator(d, tree.get(l));
                l++;
            }
            if ((r & 1) == 0) {
                r--;
                d = operator(d, tree.get(r));
            }

            l = (l - 1) / 2;
            r = (r - 1) / 2;
        }

        return d;
    }

    /**
     * デバッグ情報の出力
     */
    public void debugPrint() {
        int cnt = 1;
        int i = 0;

        System.err.printf("n:%d tree.size():%d\n", n, tree.size());

        while (i < 2 * n - 1) {
            for (int j = 0; j < cnt; i++, j++) {
                System.err.printf(" [%d]: ", i);
                System.err.print(tree.get(i));
            }
            System.err.println("");
            
            cnt *= 2;
        }
    }
}



Measured memory_bytes: 105336
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<climits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<iomanip>
#include<sstream>
using namespace std;
#define ll long long
inline ll read() {
    char ch = getchar(); ll x = 0, f = 1;
    while(ch < '0' || ch > '9') {
        if(ch == '-') f = -1;
        ch = getchar();
    } while('0' <= ch && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    } return x * f;
}
ll gcd(ll i,ll j){
	if (j) return gcd(j,i%j);
	return i;
}
int main(){
	int T=read();
	while (T--)
	{
		ll a=read(),b=read(),c=read(),d=read();
		if ((a<b)||(b>d))
		{
			printf("No\n");
			continue;
		}
		a=a%gcd(b,d);
		ll p=c%gcd(b,d);
		if (p<a)
			c+=a-p;
		else
		if (p>=a)
			c+=gcd(b,d)-p+a;
		if ((b>c))
		{
			printf("No\n");
			continue;
		}
		printf("Yes\n");
		
		
		
	
	}
}
		



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
int main(){
        int x, y, z, k; scanf("%d %d %d %d", &x, &y, &z, &k);
        vector<long long> xx(x); for(long long & v : xx) scanf("%lld", &v);
        vector<long long> yy(y); for(long long & v : yy) scanf("%lld", &v);
        vector<long long> zz(z); for(long long & v : zz) scanf("%lld", &v);
        sort(xx.rbegin(), xx.rend());
        sort(yy.rbegin(), yy.rend());
        sort(zz.rbegin(), zz.rend());
        set<vector<long long> > tot;
        long long st = xx[0] + yy[0] + zz[0];
        tot.insert({-st, 0, 0, 0});
        for(int i = 0; i < k; i++){
                vector<long long> now = *tot.begin(); tot.erase(tot.begin());
                printf("%lld\n", -now[0]);
                if (now[1] + 1 < x) {
                        tot.insert({-(-now[0]-xx[now[1]]+xx[now[1]+1]), now[1] + 1, now[2], now[3]});
                }
                if (now[2] + 1 < y) {
                        tot.insert({-(-now[0]-yy[now[2]]+yy[now[2]+1]), now[1], now[2] + 1, now[3]});
                }
                if (now[3] + 1 < z) {
                        tot.insert({-(-now[0]-zz[now[3]]+zz[now[3]+1]), now[1], now[2], now[3] + 1});
                }
        }
        return 0;
}

Measured memory_bytes: 768
while True:
    line = input().split()
    if line[1] == '+':
        print(int(line[0]) + int(line[2]))
    if line[1] == '-':
        print(int(line[0]) - int(line[2]))
    if line[1] == '*':
            print(int(line[0]) * int(line[2]))
    if line[1] == '/':
        print(int(line[0]) // int(line[2]))
    if line[1] == '?':
        break

Measured memory_bytes: 7752
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi =vector<vi>;

int main(){
  int N;
  cin >> N;
  int A=N/500;
  int B=N%500;
  int C=B/5;
  
  cout << 1000*A+5*C << endl;
}

Measured memory_bytes: 384
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	while(1)
	{
	double dp[50*100][50]={0};
	int E[100]={0},A[100]={0};
	int X,Y,Z;
	cin >> X >> Y >> Z;
	//cout << X << ", " << Y << ", " << Z << endl;
	if(X==0&&Y==0&&Z==0){
		break;
	}
	vector<int> V;
	for(int i=0;i<X;i++){
		int v;
		cin >> v;
		V.push_back(v);
	}
	for(int i=0;i<Z;i++){
		int n;
		cin >> n;
		cin >> E[n] >> A[n];
	}

	for(int i=Y-1;i>=0;i--){
		//cout << i << endl;
		for (int j=0;j<=i*100;j++)
		{
			double s=0;
			for(auto v:V){
				if (i+v>=Y){
					s+=j;
					continue;
				}
				switch(E[i+v]){
					case 0:
						s+=dp[j][i+v];
						break;
					case 1:
						if(i+v+A[i+v]>=Y){
							s+=j;
						}
						else
						{
							s+=dp[j][i+v+A[i+v]];
						}
						break;
					case 2:
						s+=dp[j+A[i+v]][i+v];
						break;
					case 3:
						s+=dp[max(j-A[i+v],0)][i+v];
						break;
				}
			}
			dp[j][i]=s/V.size();
			//cout << dp[j][i] << ", ";
		}
		//cout << endl;
	}
	/*
	for(int i=0;i<Y;i++){
		cout << i << ": " << dp[i] << ", ";
	}*/
	cout << (int)(dp[0][0]+1e-9) << endl;
	}
}

Measured memory_bytes: 3168
#include <iostream>
#include <string>
using namespace std;
int main() {
    char AA,BB,C,D; cin >> AA >> BB >> C >> D;
    int a = AA - '0';
    int b = BB - '0';
    int c = C - '0';
    int d = D - '0';
    int A = 10*a + b;
    int B = 10*c + d;
    //string ans="NA";
    //if (A>=1&&A<=12&&B>=1&&B<=12) ans = "AMBIGUOUS";
    //else if (A>=1&&A<=12) ans = "MMYY";
    //else if (B>=1&&B<=12) ans = "YYMM";
    string ans;
    if (A>=1&&A<=12){
        if (B>=1&&B<=12) ans ="AMBIGUOUS"; 
        else ans = "MMYY";
    }
    else {
        if (B>=1&&B<=12) ans = "YYMM";
        else ans = "NA";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
        i Apologize 3la el Habda
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 50;
long double EPS = 1e-6;


int ans[N];
int h[N];
int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i = 0; i < n; ++i){
            cin >> h[i];
            ans[i] = 2e9;
    }
    ans[0] = 0;
    ans[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; ++i){
            for(int j = i - 1; j >= max(0,i - k); --j){
                    ans[i] = min(ans[i], ans[j] + abs(h[i] - h[j]));
            }
    }
    cout << ans[n-1] << "\n";
 return 0;
}


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

using namespace std;
int32_t  main(){
    int a, b, c,k;
    cin>>a>>b>>c>>k;
    while(b<=a){
        b*=2;
        k--;
    
    }
    while(c<=b){
         c*=2;
         k--;
     
        }
        if(k<0){
            cout<<"No";
        }else{
            cout<<"Yes";
        }



}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    
    vector<int> dp(2e4 + 1, INF);
    dp[0] = 0;
    rep(i, N) rep(h, H + 1) {
        dp[h + A[i]] = min(dp[h + A[i]], dp[h] + B[i]);
    }
    write(*min_element(dp.begin() + H, dp.end()));
}

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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 5005;

int mod;

void add(int &a,int b)  {
    a += b;
    if (a >= mod)
        a -= mod;
}
void sub(int &a,int b)  {
    a -= b;
    if (a <  0)
        a += mod;
}
int mul(int a,int b)    {
    return  1ll * a * b % mod;
}
int Pow(int a,int b)    {
    int ans = 1;
    while (b)   {
        if(b & 1)   ans = mul(ans,a);
        a = mul(a,a);   b >>= 1;
    }
    return  ans;
}
int inv(int a,int p)    {
    return  a == 1 ? 1 : p - 1ll * p * inv(p % a,a) / a;
}

typedef pair<int,int>   ii;

int c[N];
int f[N];

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

    int n;  cin >> n >> mod;
    int k = (n + 1) / 2;

    for(int i = 0 ; i < k - 1 ; ++i)    {
        c[i + 1]++;
        c[n - i]--;
    }
    c[k]++;
    f[0] = 1;

    int val = 0;

    for(int i = 1 ; i < n ; ++i)    {
        val += c[i];

        for(int j = val ; j < n ; ++j)
            add(f[j],f[j - val]);
    }
    int ans = 0;

    for(int j = 0 ; j < n ; ++j)
        add(ans,mul(f[j],n - j));

    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = unsigned long long;


ll Mx = pow(10,18);

int main() {

	ll n, a, ans =1;
	cin >> n;
	bool f = false;

	rep(i, n) {
		cin >> a;


		if (a == 0) {
			cout << '0' << endl;

			return 0;
		}

		if (f || a > Mx/ans) {

			f = true;

		}

		ans *= a;
	}

	if (f)cout << "-1" << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3644
N = int(input())

import math

if N % 2 == 1:
    print(0)
elif N == 0:
    print(0)
else:
    half = N // 2
    m = math.floor(math.log(half, 5))
    cnt = 0
    for i in range(m):
        cnt += half // (5 ** (i+1))
    print(cnt)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//解説を思い出しながら自分で書く→自分で書けた
vector<int>to[100005];
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    --a;--b;
    to[b].push_back(a);
    to[a].push_back(b);
  }
  queue<int>q;
  q.push(0);
  vector<int>dist(n,INT_MAX);
  vector<int>pre(n,-1);
  dist[0]=0;
  pre[0]=0;
  while(!q.empty()){
    int v=q.front();q.pop();
    for(int x:to[v]){
      if(dist[x]!=INT_MAX)continue;
      dist[x]=dist[v]+1;
      pre[x]=v;
      q.push(x);
    }
  }
  cout<<"Yes"<<endl;
  for(int i=1;i<n;i++){
    cout<<pre[i]+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 10724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private class Node<T> {
		T key;
		Node<T> left;
		Node<T> right;
		public Node(T key) {
			this.key = key;
			left = right = null;
		}
		public String toString() {
			return key.toString();
		}
	}
	
	private class BST {
		
		private Node<Integer> rootNode;
		public BST() {
			rootNode = null;
		}
		
		public void insert(Node<Integer> node) {			
			Node<Integer> parent = null;
			Node<Integer> cur = rootNode;
			while (cur != null) {
				parent = cur;
				if (node.key < cur.key) {
					cur = cur.left;
				} else {
					cur = cur.right;
				}
			}
			if (parent == null) {
				rootNode = node;
			} else if (node.key < parent.key) {
				parent.left = node;
			} else {
				parent.right = node;
			}
		}
		
		public void print() {
			printInOrder(rootNode);
			System.out.println("");
			printPreOrder(rootNode);
			System.out.println("");
		}
		
		private void printInOrder(Node<Integer> node) {
			if (node != null) {
				printInOrder(node.left);
				System.out.print(" " + node);
				printInOrder(node.right);
			}			
		}
		
		private void printPreOrder(Node<Integer> node) {
			if (node != null) {
				System.out.print(" " + node);
				printPreOrder(node.left);
				printPreOrder(node.right);
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		BST bst = new BST();
		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			String cmd = st.nextToken();
			if (cmd.equals("insert")) {
				bst.insert(new Node<Integer>(Integer.parseInt(st.nextToken())));
			} else {
				bst.print();
			}
		}
		reader.close();
	}
}


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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
//int dx[] = {0,1,0,-1};
//int dy[] = {-1,0,1,0};

//   cout<<std::setprecision(12)<<


int main()
{
    int i,j,k,l,m,n,a,b;
    cin >> a >> b >> m;
   swap(a,b);
   swap(a,m);
   cout << a<<" "<<b<<" "<<m<<endl;
}


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

#define int long long
#define uint unsigned int
#define pii pair<int, int>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin()), ((c).end())

#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))

#define PW(n) (1LL << (n))

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNI(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int a[5];
int k;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  REP(i, 5) cin >> a[i];
  cin >> k;
  sort(a, a+5);
  cout << (a[4]-a[0] <= k ? "Yay!" : ":(") << endl;

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;
const ll INF = 1e18;

int main() {
    int n, v;
    vector<vector<int>> c(2, vector<int>(100000, 0));
    cin >> n;
    rep(i, n) {
        cin >> v;
        c[i % 2][v - 1]++;
    }
    vector<pair<int, int>> a[2];
    rep(i, 2) {
        rep(j, 100000) {
            a[i].push_back(make_pair(c[i][j], j));
        }
        sort(a[i].begin(), a[i].end());
    }
    if (a[0][99999].second != a[1][99999].second) {
        cout << n - a[0][99999].first - a[1][99999].first << "\n";
    } else {
        cout << n - max(a[0][99999].first + a[1][99998].first, a[0][99998].first + a[1][99999].first) << "\n";
    }
}

Measured memory_bytes: 3316
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007


int A,B,C,K;

signed main(){
    scanf("%lld %lld %lld %lld",&A,&B,&C,&K);
    int ans=min(A,K)-max((int)0,K-A-B);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1736