akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long
const int maxn=55;
int mp[maxn][maxn];
int n,m;
int dir[4][2]={0,1,0,-1,1,0,-1,0};
using namespace std;
//#define debug
int main()
{
	#ifdef debug
	freopen("test3.txt","r",stdin);
	#endif
	char ch;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			cin>>ch;
			if(ch=='#')
				mp[i][j] = 1;
		}
	bool res=0;
	for(int i=1;i<=n;i++){
		if(res) break;
		for(int j=1;j<=m;j++){
			if(res) break;
			if(mp[i][j]==0)
				continue;
			int k=0;
			for(k=0;k<4;k++){
				int x = i + dir[k][0];
				int y = j + dir[k][1];
				if(mp[x][y]==1)
					break;
			} 
			if(k==4)
				res=1;
		}
		
	}
	if(res)
		cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func max(nums ...int) (m int) {
	m = 0
	for _, x := range nums {
		if x > m {
			m = x
		}
	}
	return
}

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	fmt.Println(max(a, b, c)*9 + a + b + c)
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

int main() {
	
	long long int n,k;
	cin >> n>>k;
	vector<pair<int,int>>p(n);
	for (int i = 0; i < n; i++) {
		int t, d;
		cin >> t >> d;
		p[i].first = d; p[i].second = t;
	}
	
	sort(p.rbegin(), p.rend());
	vector<bool>f(n + 1);
	long long int ans = 0;
	stack<int>s;
	int cnt = 0;
	long long int tp = 0;
	long long int res = 0;
	for (int i = 0; i < n; i++) {

		if (cnt < k) {

			if (!f[p[i].second]) {
				tp++;
				f[p[i].second] = 1;
			}
			else {
				s.push(p[i].first);
			}
			res += p[i].first;
			cnt++;
			ans = max(ans, res + tp*tp);

		}
		else {
			if (!s.size())break;
			if (f[p[i].second])continue;
			f[p[i].second] = 1;
			tp++;
			res -= s.top();
			res += p[i].first;
			s.pop();
			ans = max(ans, res + tp*tp);
		}
	//	cout << res << endl;
	}


	cout << ans << endl;

	return 0;


}

Measured memory_bytes: 1152
h,w=map(int,input().split())
a = [list(input()) for _ in range(h)]
a[0][0] = "."
q=[(0,0)]
dy=[0,1]
dx=[1,0]
while len(q)>0:
    y,x=q.pop(0)
    if y == h-1 and x == w-1:
        break
    for i in range(2):
        if not (0<=dy[i]+y<h and 0<=dx[i]+x<w):
            continue
        if a[dy[i]+y][dx[i]+x] != "#":
            continue
        else:
            a[dy[i]+y][dx[i]+x] = "."
            q.append((dy[i]+y,dx[i]+x))
            break
f = True
for i in range(h):
    for j in range(w):
        #print(a[i][j])
        if a[i][j] == "#":
            f = False
if f:
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 38384
#include <iostream>
#include <set>
using namespace std;
int n,parent[100000],mod=1000000007;
set<int> st;
void init(){
	for(int i=0;i<n;i++) parent[i]=i;
	st.clear();
}
int find(int id){
	if(id==parent[id]) return id;
	parent[id]=find(parent[id]);
	return parent[id];
}
void unite(int a, int b){
	if(find(a)==find(b)) return;
	parent[find(a)]=find(b);
	return;
}
int main(){
	while(true){
		int m;
		cin >> n >> m;
		if(!n) break;
		init();
		for(int i=0;i<m;i++){
			int a,b;
			cin >> a >> b;
			a--;b--;
			unite(a,b);
		}
		for(int i=0;i<n;i++) st.insert(find(i));
		long long ans=1;
		for(int i=0;i<st.size();i++){
			ans*=2;
			ans%=mod;
		}
		if(m!=0){
			ans++;
			ans%=mod;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 6264
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    multiset<ll> st;

    rep(i,n) {
        ll a; cin>>a;
        if (st.empty()) st.insert(a);
        else {
            auto itr = st.lower_bound(a);
            if (itr == st.begin()) st.insert(a);
            else {
                st.erase(prev(itr));
                st.insert(a);
            }
        }
    }
    
    cout << st.size() << '\n';

    return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

typedef struct node{
	int key;
	int priority;
	struct node *left;
	struct node *right;
}node;


int find(node *p,int x){

	while(p!=NULL){
		if(p->key == x)return 1;
		else if(p->key > x)p=p->left;
		else p=p->right;
	}
	
	return 0;
	
}


node * makenode(int x,int y){
	node *new=malloc(sizeof(node));
	new->key=x;
	new->priority=y;
	new->left=NULL;
	new->right=NULL;
	return new;
}

node *rightRotate(node *p){
	node *q=p->left;
	p->left=q->right;
	q->right=p;
	return q;
}

node *leftRotate(node *p){
	node *q=p->right;
	p->right=q->left;
	q->left=p;
	return q;
}


node* insert(node **t,int key,int priority){
	node *new;
	
	if((*t)==NULL)
		return new=makenode(key,priority);
	if ((*t)->key==key)
		return *t;
	
	if(key < (*t)->key){
		(*t)->left=insert(&(*t)->left,key,priority);
		if((*t)->priority < (*t)->left->priority)
			(*t)=rightRotate((*t));
	}
	else {
		(*t)->right=insert(&(*t)->right,key,priority);
		if((*t)->priority < (*t)->right->priority)
			(*t)=leftRotate((*t));
	}
	
	return *t;
}





int main(){
	int q,x,com;
	int num=0;
	node *root=NULL;
	srand((unsigned)time(NULL));
	
	scanf("%d",&q);
	
	for(int i=0;i<q;i++){
		scanf("%d %d",&com,&x);
		
		if(com==0){
			if(!find(root,x)){
				root=insert(&root,x,rand()%200001);
				num++;
			}
			printf("%d\n",num);
		}
		else {
			if(find(root,x))printf("1\n");
			else printf("0\n");
		}
		
	}
		
	return 0;
	
}


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

#define ll long long int
int main()
{
	string s;
	cin>>s;
	char s1,s2,s3;

	for(int i=0;i<s.size()-1;i++)
	{
		s1=s[i];
		s2=s[i+1];
		if(s1==s2)
		{
			cout<<i+1<<" "<<i+2<<endl;
			return 0;
		}
		if(i+2<s.size())
		{
			s3=s[i+2];
			if(s1==s3)
			{
				cout<<i+1<<" "<<i+3<<endl;
				return 0;
			}
		}
	}
	cout<<"-1"<<" "<<"-1"<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;

int main() {
	while(1){
		char p[100];
		scanf("%s", p);
		if(p[0] == '#')
			break;
			
		const int s = strlen(p);
		//cout << s << endl;
		int n[100];
		for(int i = 0; i < 100; ++i)
			n[i] = -1;
			
		for(int i = 0; i < s; ++i){
			n[i] = p[i] - '0';
		}
		int c = 0;
		char now = 'A';
		while(c < s){
			if(now == 'A'){
				if(n[c] == 0)
					now = 'X';
				else if(n[c] == 1)
					now = 'Y';
			}
			else if(now == 'X'){
				if(n[c] == 0)
					break;
				else if(n[c] == 1)
					now = 'Z';
			}
			else if(now == 'Y'){
				if(n[c] == 0)
					now = 'X';
				else if(n[c] == 1)
					break;
			}
			else if(now == 'W'){
				if(n[c] == 0)
					now = 'B';
				else if(n[c] == 1) 
					now = 'Y';
			}
			else if(now == 'Z'){
				if(n[c] == 0)
					now = 'W';
				else if(n[c] == 1)
					now = 'B';
			}
			else if(now == 'B'){
				if(n[c] == 0)
					now = 'Y';
				else if(n[c] == 1)
					now = 'X';
			}
			c++;
		}
		if(now == 'B')
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1144
#include <stdio.h>

int Pow(int a,int b){
    int p  = 1;
    for(;b>>0;b--){
        p = p * 2;
    }
    return p;
}

int main(){
    int N;
    int i,Ans;
    scanf("%d",&N);
    for(i = 0;;i++){
        N = N/2;
        if(N<1){
            break;
        }
    }
    Ans = Pow(2,i);
    printf("%d",Ans);
}

Measured memory_bytes: 128
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(now, ContestType):
  res = c[ContestType] * (now - LastDay[ContestType])
  return res

def nasu(now, x, y, z):
  res = 0
  res += s[now-1][x]
  res += s[now][y]
  res += s[now+1][z]
  if x == y == z:
    res += (D - now) * ((now - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * (1 * c[y])
    now += 1
    res += (D - now) * (1 * c[z])
  elif x == y:
    res += (D - now) * ((now - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * (1 * c[y])
    now += 1
    res += (D - now) * ((now - LastDay[z]) * c[z])
  elif y == z:
    res += (D - now) * ((now - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * ((now - LastDay[y]) * c[y])
    now += 1
    res += (D - now) * (1 * c[z])
  elif x == z:
    res += (D - now) * ((now - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * ((now - LastDay[y]) * c[y])
    now += 1
    res += (D - now) * (2 * c[z])
  else:
    res += (D - now) * ((now - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * ((now - LastDay[y]) * c[y])
    now += 1
    res += (D - now) * ((now - LastDay[z]) * c[z])
  return res

D = I()
c = IL()
s = [IL() for i in range(D)]

LastDay = [0]*26
for i in range(1,D+1-3):
  tmp = ["", 0]
  for x in range(26):
    for y in range(26):
      for z in range(26):
        score = nasu(i, x, y, z)
        if tmp[1] < score:
          tmp = [(x, y, z), score]
  LastDay[tmp[0][0]] = i
  print(tmp[0][0]+1)
else:
  tmp = ["", 0]
  for x in range(26):
    for y in range(26):
      for z in range(26):
        score = nasu(D-2, x, y, z)
        if tmp[1] < score:
          tmp = [(x, y, z), score]
  for i in tmp[0]:
    print(i+1)

Measured memory_bytes: 75084
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) { 
	string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
	string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += to_string(x);
	}
	res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.f)+", "+to_string(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
const int MOD = 1e9 + 7, INF = 1e9 + 5;
inline ll powmod(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)res=res*a%MOD;return res;}
inline ll power(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a)if(b&1)res=res*a;return res;}

const int MAXN = 2e5 + 10;

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, ans = 0;
	cin >> n;
	int in;
	for(int i =1; i <= n; i++){
		cin >> in;
		if((i & 1) && (in & 1))
			ans++;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3604
from math import sqrt

class UF():
  def __init__(self, N):
    self.parents = [-1] * (N+1)

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

  def union(self, u,v):
    p1,p2 = self.find(u),self.find(v)
    if p1 == p2: return

    if p1 > p2:
      p1,p2 = p2,p1
    self.parents[p1] += self.parents[p2]
    self.parents[p2] = p1

  def same(self, u, v):
    return self.find(u) == self.find(v)

ans = []
while True:
  # sphere-shaped
  n = int(input())
  if n==0: exit()
  C = []
  # for _ in range(n):
    # C.append(list(map(float,input().split())))
  C = [[float(i) for i in input().split()] for _ in range(n)]

  uf = UF(n)
  edges = []
  for i in range(n):
    for j in range(i+1, n):
      x1,y1,z1,r1 = C[i]
      x2,y2,z2,r2 = C[j]
      d = ((x1-x2)**2+(y1-y2)**2+(z1-z2)**2)**0.5-r1-r2
      if d <= 0:
        uf.union(i,j)
      else:
        edges.append((d,i,j))
  edges.sort(key=lambda x: x[0])

  res = 0
  for d,u,v in edges:
    if not uf.same(u,v):
      uf.union(u,v)
      res += d

  print(f"{res:.3f}")


Measured memory_bytes: 6420
using System;

namespace dot
{
    class Program
    {
        static void Main(string[] args)
        {
            const int min = -1000000;
            const int max = 1000000;

            var input = Console.ReadLine().Split(' ');
            int k = int.Parse(input[0]);
            int x = int.Parse(input[1]);

            int i = Math.Max(x-k+1, min);
            int j = Math.Min(x+k-1, max);

            for (int l=i; l<j; l++)
            {
                Console.Write(l);
                Console.Write(' ');
            }
            Console.WriteLine(j);

        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
// #include <boost/multiprecision/mpfr.hpp>  // Defines the Backend type that wraps MPFR
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(long long int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);

// namespace mp = boost::multiprecision;     // Reduce the typing a bit later...
using namespace std;


int main(){
	long long int n;
	cin >> n;
	long long int a[n],b[n];
	forn(i,0,n) cin >> a[i];
	forn(i,0,n) cin >> b[i];
	long long int ans = 0;
	long long int mxk = 30;
	while(mxk--){
		// checking for mxk bit;
		long long int ca[n],cb[n];
		memcpy(ca,a,sizeof(ca));
		memcpy(cb,b,sizeof(cb));
		long long int t = (1<<mxk);
		forn(i,0,n){
			ca[i] = (a[i]%(2*t));
			cb[i] = (b[i]%(2*t));
		}
		sort(cb,cb+n);
		long long int cnt = 0;
		forn(i,0,n){
			long long int l= 0 ,r = n-1;
			while(l<=r){
				long long int m  = l+r>>1;
				if(ca[i]+cb[m]>=t)
					r = m-1;
				else
					l = m+1;
			}
			// l gives the smallest j s.t. ai + b[j] >= t
			long long int jmin = l;
			l = 0;r = n-1;
			while(l<=r){
				long long int m = l+r>>1;
				if(ca[i]+cb[m]<2*t)
					l = m+1;
				else
					r = m-1;
			} 
			long long int jmax = r;
			if(jmax>=jmin)
				cnt += (jmax-jmin + 1);
			l = 0,r = n-1;
			while(l<=r){
				long long int m  = l+r>>1;
				if(ca[i]+cb[m]>=3*t)
					r = m-1;
				else
					l = m+1;
			}
			// l gives the smallest j s.t. ai + b[j] >= t
			jmin = l;
			l = 0;r = n-1;
			// while(l<=r){
			// 	long long int m = l+r>>1;
			// 	if(ca[i]+cb[m]<4*t)
			// 		l = m+1;
			// 	else
			// 		r = m-1;
			// } 
			jmax = n-1;
			if(jmax>=jmin)
			cnt += (jmax-jmin + 1);
		}
		if(cnt%2==1)
			ans += (1<<mxk);
	}
	cout << ans << endl;

}

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

#define fi first
#define se second
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;

const int N = 80 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

ll f[N], a[N];

int main() {
	ios::sync_with_stdio(0);

	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		f[i] = 1000;
	}
	f[0] = 1000;

	for (int i = 1; i <= n; i++) {
		for (int l = 1; l < i; l++) {
			for (int j = l; j <= i; j++)
				for (int k = j + 1; k <= i; k++) {
					ll det = f[l - 1] / a[j] * a[k] + f[l - 1] % a[j];
					f[i] = max(f[i], det);
				}
		}
	}
	cout << f[n] << endl;

	return 0;
}


Measured memory_bytes: 3656
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return "".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = list(input())[:-1]

pata = ["S","W"]

for fi in pata:
    for se in pata:
        aaa = [fi,se]
        for i in range(1,n-1):
            if aaa[-1] == "S":
                if a[i] == "o":
                    aaa.append(aaa[-2])
                else:
                    if aaa[-2] == "S":
                        aaa.append("W")
                    else:
                        aaa.append("S")
            else:
                if a[i] == "o":
                    if aaa[-2] == "S":
                        aaa.append("W")
                    else:
                        aaa.append("S")
                    
                else:
                    aaa.append(aaa[-2])
        flag = True

        if aaa[-1] == "S":
            if a[-1] == "o":
                if aaa[-2] != aaa[0]:
                    flag = False
            else:
                if aaa[-2] == aaa[0]:
                    flag = False
        else:
            if a[-1] == "x":
                if aaa[-2] != aaa[0]:
                    flag = False
            else:
                if aaa[-2] == aaa[0]:
                    flag = False
        if aaa[0] == "S":
            if a[0] == "o":
                if aaa[-1] != aaa[1]:
                    flag = False
            else:
                if aaa[-1] == aaa[1]:
                    flag = False
        else:
            if a[0] == "x":
                if aaa[-1] != aaa[1]:
                    flag = False
            else:
                if aaa[-1] == aaa[1]:
                    flag = False
        if flag:
            print(jo(aaa))
            exit()
print(-1)
exit()







Measured memory_bytes: 61816
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
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;}
// clang-format on

void solve(long long N, std::vector<long long> A) {
  if (find(all(A), 0) != A.end()) {
    ANS(0);
    return;
  }
  ll L = 1e18;
  ll ans = 1;
  rep(i, N) {
    if (L / ans < A[i]) {
      ANS(-1);
      return;
    }
    ans *= A[i];
  }
  ANS(ans);
}

// clang-format off
int main() {
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 4068
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

template <int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0)
            v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
    constexpr Fp operator+(const Fp &r) const noexcept {
        return Fp(*this) += r;
    }
    constexpr Fp operator-(const Fp &r) const noexcept {
        return Fp(*this) -= r;
    }
    constexpr Fp operator*(const Fp &r) const noexcept {
        return Fp(*this) *= r;
    }
    constexpr Fp operator/(const Fp &r) const noexcept {
        return Fp(*this) /= r;
    }
    constexpr Fp &operator+=(const Fp &r) noexcept {
        val += r.val;
        if (val >= MOD)
            val -= MOD;
        return *this;
    }
    constexpr Fp &operator-=(const Fp &r) noexcept {
        val -= r.val;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr Fp &operator*=(const Fp &r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp &operator/=(const Fp &r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr bool operator==(const Fp &r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator!=(const Fp &r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream &operator<<(ostream &os,
                                         const Fp<MOD> &x) noexcept {
        return os << x.val;
    }
    friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0)
            return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1)
            t = t * a;
        return t;
    }
};

const int MOD = 998244353;
using mint = Fp<MOD>;

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

    int N, K;
    cin >> N >> K;
    vector<int> L(K), R(K);
    vector<mint> dp(N, 0), sdp(N + 1, 0);
    dp[0] = 1, sdp[1] = 1;
    rep(i, K) { cin >> L[i] >> R[i]; }

    // 累積和しながらdp
    for (int i = 1; i < N; i++) {
        rep(j, K) {
            int l = max(0, i - R[j]);
            int r = max(0, i - L[j] + 1);
            dp[i] += sdp[r] - sdp[l];
            // iに飛ぶ連続した区間の累積和
        }
        sdp[i + 1] = sdp[i] + dp[i];
        // 累積和も更新
    }

    cout << dp[N - 1] << endl;
}

Measured memory_bytes: 6328
n=int(input())
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
l3 = list(map(int,input().split()))
m=0
m+=l2[l1[0]-1]
for i in range(1,n):
    if l1[i] == l1[i-1]+1:
        m+=l2[l1[i]-1]+l3[l1[i]-2]
    else:
        m+=l2[l1[i]-1]
print(m)

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

using namespace std;



int n, m;
vector<bool> used;
vector<vector<tuple<long long, int, int> > > r;

long long getCost(tuple<long long, int, int> info)
{
  return get<0>(info);
}

int getTo(tuple<long long, int, int> info)
{
  return get<1>(info);
}

int getNo(tuple<long long, int, int> info)
{
  return get<2>(info);
}

void Dijkstra(int start)
{
  priority_queue<tuple<long long, int, int>, vector<tuple<long long, int, int> >, greater<tuple<long long, int, int> > > q;
  vector<long long> costs(n, numeric_limits<long long>::max());
  costs[start] = 0;
  for (auto&& i : r[start]) {
    q.push(i);
  }
  while (q.size()) {
    int to = getTo(q.top());
    long long cost = getCost(q.top());
    if (costs[to] < cost) {
      q.pop();
      continue;
    }
    costs[to] = cost;
    used[getNo(q.top())] = true;
    q.pop();
    for (auto&& i : r[to]) {
      if (costs[getTo(i)] < cost + getCost(i)) continue;
      q.push(make_tuple(cost + getCost(i), getTo(i), getNo(i)));
    }
  }
}

void hawawa()
{
  cin >> n >> m;
  r.resize(n);
  used.resize(m, false);
  for (int i = 0; i < m; i++) {
    int a, b;
    long long c;
    cin >> a >> b >> c;
    a--;
    b--;
    r[a].push_back(make_tuple(c, b, i));
    r[b].push_back(make_tuple(c, a, i));
  }
  for (int i = 0; i < n; i++) {
    Dijkstra(i);
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (!used[i]) ans++;
  }
  cout << ans << "\n";
}

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define in(s,x) s.find(x) != s.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<pair<int,int>> VPII;
const ll mod=1000000007;
const ll INF= 1LL<<60-1;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}

// head


int m,n,k,res,tmp,tmp2,tmp3,h,x,y;
VI a;
deque<PII> que;
string s;
VI b;
vector<PII> g[2100600];
//int b[2100000] = {};
int c[210000] = {};
int rui[2100][2100];
int dp[2200][2200];

void make(string s){
  if(s.length()==11){b.pb((atoll(s.c_str())));return;}
  if(atoi(s.c_str())==0){rep(i,0,10){
    make(s+to_string(i));
  }}
  else{
    char v_ = s[s.length()-1];
    string v = {v_};
    if(v=="0"){make(s+"1");make(s+"0");}
    else if(v=="9"){make(s+"9");make(s+"8");}
    else{make(s+to_string((atoi(v.c_str())+1)));make(s+v);make(s+to_string((atoi(v.c_str())-1)));}
  }
}

signed main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>k;
  make("0");
  sort(all(b));
  cout << b[k] << '\n';

}

Measured memory_bytes: 51828
#include <iostream>
using namespace std;
int main(){
    int n,i,k,j,x,a;
    cin >> n;
    k=0;
    a=0;
    for(i=1;i<=n;i++){
        x=0;
        k=i; 
        for(j=1;j<=k;j++){
            if(k%j==0)
                x++;
        }
        if(x==8&&i%2!=0)
            a++;
    }

    cout << a << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int n;
  cin >> n;
  
  int sum = 0;
  
  while(n != 0){
    sum += n % 10;
    n /= 10;
  }
  
  if(sum == 1)
    cout << 10 << endl;
  else
    cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 256
/*input
7
314159265
358979323
846264338
327950288
419716939
937510582
0
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

ll a[maxn];

ll dp[maxn][5];

int main()
{
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];
	for(int i=1;i<=n;i++) dp[i][0]=dp[i-1][0]+a[i-1];

	{
		int pre=0;
		int cnt=0;
		for(int i=1;i<=n;i++){
			if(a[i-1]==0) cnt+=2;
			if(a[i-1]%2) cnt++;
			if(dp[pre][0]+cnt<dp[i][0]){
				dp[i][1]=dp[pre][0]+cnt;
			}
			else{
				dp[i][1]=dp[i][0];
				cnt=0;
				pre=i;
			}
		}
	}
	{
		int pre=0;
		int cnt=0;
		for(int i=1;i<=n;i++){
			if(a[i-1]%2==0) cnt++;
			if(dp[pre][1]+cnt<dp[i][1]){
				dp[i][2]=dp[pre][1]+cnt;
			}
			else{
				dp[i][2]=dp[i][1];
				cnt=0;
				pre=i;
			}
		}
	}
	{
		int pre=0;
		int cnt=0;
		for(int i=1;i<=n;i++){
			if(a[i-1]==0) cnt+=2;
			if(a[i-1]%2) cnt++;
			if(dp[pre][2]+cnt<dp[i][2]){
				dp[i][3]=dp[pre][2]+cnt;
			}
			else{
				dp[i][3]=dp[i][2];
				cnt=0;
				pre=i;
			}
		}
	}
	{
		int pre=0;
		int cnt=0;
		for(int i=1;i<=n;i++){
			cnt+=a[i-1];
			if(dp[pre][3]+cnt<dp[i][3]){
				dp[i][4]=dp[pre][3]+cnt;
			}
			else{
				dp[i][4]=dp[i][3];
				cnt=0;
				pre=i;
			}
			//if(i==n) cout<<pre<<' '<<dp[pre][3]<<'\n';
		}
	}

	//REP(i,5) REP(j,n+1) cout<<dp[j][i]<<" \n"[j==n];
	cout<<dp[n][4]<<'\n';
}


Measured memory_bytes: 11520
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;

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

	ll K, X;
	cin >> K >> X;
	
	for (int i = 1; i <= K; i++) {
		cout << X - K + i << " ";
	}
	for (int i = 1; i < K; i++) {
		cout << X + i;
		if (i != K - 1) {
			cout << " ";
		}
	}

	cout << endl;

	return 0;
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};
typedef vector<int> V;
typedef vector<V> VV;
int col[612][612][2];
int N;
void coloring(int r, int c, int k, VV& edge) {
	for (auto &e : edge) {
		int nr = r + e[0];
		int nc = c + e[1];
		if (nr < 0 || N <= nr)continue;
		if (nc < 0 || N <= nc)continue;
		if (col[nr][nc][k] != -1)continue;
		col[nr][nc][k] = 1 - col[r][c][k];
		coloring(nr, nc, k, edge);
	}
}
int main() {
	LL latte, malta;
	cin >> N >> latte >> malta;
	N *= 2;
	vector<VV> e(2);
	for (int i : range(-N,N+1))for (int j : range(-N,N+1)) {
		if (i*i + j*j == latte)e[0].push_back({ i,j });
		if (i*i + j*j == malta)e[1].push_back({ i,j });
	}
	for (int i : range(N))for (int j : range(N))for (int k : range(2))col[i][j][k] = -1;
	for (int i : range(N))for (int j : range(N))for (int k : range(2))if (col[i][j][k] == -1) {
		col[i][j][k] = 0;
		coloring(i, j, k, e[k]);
	}
	int cnt[2][2] = { {0,0},{0,0} };
	for (int i : range(N))for (int j : range(N)) {
		cnt[col[i][j][0]][col[i][j][1]]++;
	}
	int ai = 0, aj = 0;
	for (int i : range(2))for (int j : range(2)) {
		if (cnt[ai][aj] < cnt[i][j])ai = i, aj = j;
	}
	int M = N * N / 4;
	for (int i : range(N))for (int j : range(N)) {
		if (col[i][j][0] == ai && col[i][j][1] == aj && M > 0) {
			cout << i << " " << j << endl;
			M--;
		}
	}

	return 0;
}


Measured memory_bytes: 31872
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

bool isPrime( int x ) {
	if( x == 2 ) { return true; }
	if( x <= 1 || (x&1) == 0 ) { return false; }

	for( long i = 3; i*i <= x; i += 2 ) {
		if( x % i == 0 ) {
			return false;
		}
	}

	return true;
}

int main() {
	ios_base::sync_with_stdio( false );

	int X;
	cin >> X;

	while( !isPrime( X ) ) {
		X += 1;
	}

	cout << X << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
const ll ddx[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const ll ddy[8]={ 1, 0,-1, 0, 1,-1, 1,-1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    vvl g(n);
    rep(i,n){
        ll a,b;cin >> a >>b;
        a--;
        rep(j,b){
            ll c;cin >> c;
            g[a].pb(c-1);
        }
    }
    queue<ll> que;
    que.push(0);
    vl dist(n,-1);
    dist[0]=0;
    while(!que.empty()){
        ll v=que.front();
        que.pop();
        for(auto nv:g[v]){
            if(dist[nv]!=-1)continue;
            dist[nv]=dist[v]+1;
            que.push(nv);
        }
    }
    rep(i,n)cout << i+1 <<" "<<dist[i] << endl;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

void solve(){
  string s;
  ll k;
  cin >> s >> k;
  string ss = s + s;
  int n = s.size();

  set<char> st;
  rep(i,n){
    st.insert(s[i]);
  }
  if(st.size()==1){
    cout << (n*k)/2 << endl;
  }

  else{
  ll tmp = 0;
  ll ans1 = 0;
  for(int i=1; i<n; i++){
    if(s[i-1]==s[i]){
      tmp++;
    }
    else{
      ans1 += (tmp+1)/2;
      tmp = 0;
    }
  }
  ans1 += (tmp+1)/2;

  tmp = 0;
  ll ans2 = 0;
  for(int i=1; i<n*2; i++){
    if(ss[i-1]==ss[i]){
      tmp++;
    }
    else{
      ans2 += (tmp+1)/2;
      tmp = 0;
    }
  }
  ans2 += (tmp+1)/2;
  //cout << ans1 << " " << ans2 << endl;

  cout << (ans2-ans1)*(k-1) + ans1 << endl;
  }

}

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

Measured memory_bytes: 256
MOD = 998244353
inpl = lambda: list(map(int,input().split()))
A, B, C, D = inpl()
dp = [ [0]*(D+1) for _ in range(C+1) ]
dp[A][B] = 1
for a in range(A+1, C+1):
    dp[a][B] = (dp[a-1][B] * B) % MOD
for b in range(B+1, D+1):
    dp[A][b] = (dp[A][b-1] * A) % MOD

for a in range(A+1,C+1):
    for b in range(B+1,D+1):
        dp[a][b] = (b * dp[a-1][b] + a * dp[a][b-1] - (a-1)*(b-1)*dp[a-1][b-1]) % MOD

print(dp[C][D])


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

MAX = 1000005
cnt = [0] * MAX
for x in a:
    if cnt[x] != 0:
        cnt[x] = 2
        continue
    #cnt配列の各倍数のところに+1
    for i in range(x, MAX, x):
        cnt[i] += 1
ans = 0
for x in a:
    if cnt[x] == 1:
        ans += 1

print(ans)

Measured memory_bytes: 31896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n+1), b(n+1), c(n+1);
    rep(i, 1, n+1) cin >> a[i];
    rep(i, 1, n+1) cin >> b[i];
    rep(i, 1, n) cin >> c[i];
    ll ans = 0;
    rep(i, 1, n+1){
        //cerr << b[a[i]] << endl;
        ans += b[a[i]];
        if(i+1 <= n && a[i+1] == a[i] + 1) ans += c[a[i]]; 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
import sys
import itertools
import queue
from fractions import gcd
 
def lcm(a, b):
    return a * b // gcd(a, b)
 

mod = 1000000007
 
if __name__ == "__main__":
    #inputfile = open("input.txt")
    N, A, B, C = map(int, sys.stdin.readline().split())
    l = [int(sys.stdin.readline()) for i in range(N)]
    INF = 10 ** 9
 
    def dfs(idx, a, b, c):
        if idx == N:
            # 初期値a,b,c = 0となっているため、一本目の竹についても合成された扱いになってしまっている
            # したがって、実際はかかっていない合成コスト30を引いている
            # a,b,cのうち少なくとも一本は必ず使われる設定になっているため、30を必ず引くような実装であっても問題はない
            return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF
        # 一本あたりの竹について、合成しない、Aに合成、Bに合成、Cに合成の全てのパターンを以下で試行している
        no_synth = dfs(idx + 1, a, b, c)
        synth_A  = dfs(idx + 1, a + l[idx], b, c) + 10
        synth_B  = dfs(idx + 1, a, b + l[idx], c) + 10
        synth_C  = dfs(idx + 1, a, b, c + l[idx]) + 10
        return min(no_synth, synth_A, synth_B, synth_C)
 
    print(dfs(0,0,0,0))
 

Measured memory_bytes: 5196
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    b = [0] * N
    for a in A:
        b[a-1] += 1
    return b


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N - 2 + 1)]  # type: "List[int]"
    print(*solve(N, A), sep='\n')

if __name__ == '__main__':
    main()


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

using namespace std;

using ll = long long;

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

    int n, a, ans = 0;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        while (a % 2 == 0) {
            ++ans;
            a /= 2;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(void){
	int h, n, i, j;
	u_int d[20001];
	memset(d, -1, sizeof(d));
	d[0]=0;
	scanf("%d%d", &h, &n);
	for(i=0; i<n; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		for(j=0; j<h; j++){
			if(d[j]!=UINT_MAX && d[j]+b < d[j+a]) d[j+a] = d[j]+b;
		}
	}
	int min=INT_MAX;
	for(i=h; i<h+10000; i++){
		if(d[i]<min) min=d[i];
	}
	printf("%d\n", min);
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

int main(){
  double A,B;cin>>A>>B;
  double p=M_PI;
  int H,M;cin>>H>>M;
  double sum=H*60+M;
  double a=sum*0.5*p/180.0;
  double b=sum*6*p/180.0;
  double ax,ay,bx,by;
  ax=cos(a);
  ay=sin(a);
  bx=cos(b);
  by=sin(b);
  ax=A*ax;
  ay=A*ay;
  bx=B*bx;
  by=B*by;
  double ans=(ax-bx)*(ax-bx)+(ay-by)*(ay-by);
  ans=pow(ans,0.5);
  cout<<setprecision(15)<<ans<<endl;
}

Measured memory_bytes: 3680
n,m=map(int,input().split())
l=[0]*n
ac=[False]*n
cnt=0;acnt=0
for i in range(m):
  a,b=input().split()
  a=int(a)
  if ac[a-1]:continue
  if b=="AC":
    cnt+=l[a-1]
    acnt+=1
    ac[a-1]=True
  if b=="WA":
    l[a-1]+=1
print(acnt,cnt)
    

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n, k;
  cin >> n >> k;
  vi h(n);
  rep(i,n) cin >> h[i];
  sort(all(h));
  int ans = inf;
  for(int i = 0; i <= n-k; i++) {
    int d = h[i+k-1] - h[i];
    ans = min(ans, d);
  }
  cout << ans << endl;
}

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

using namespace std;

struct ops{
    ops() {};
    ops(long long b, long long c) : B(b), C(c) {};
    long long B,C;

    bool operator<(const ops &rhs) const {
        return C < rhs.C;
    };

    bool operator>(const ops &rhs) const {
        return C > rhs.C;
    };
};

int main() {
    int N,M; cin >> N >> M;
    vector<long long> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    vector<ops> O(M);
    for(int i=0;i<M;i++) {
        long long b,c; cin >> b >> c;
        O[i] = ops(b,c);
    }

    sort(O.begin(), O.end(), greater<ops>());
    sort(A.begin(), A.end());

    long long ans = 0;
    vector<long long>::iterator pos = A.begin();

    for(int i=0;i<M;i++) {
        long long B = O[i].B, C = O[i].C;
        auto ub = upper_bound(pos, A.end(), C);
        long long dist = distance(pos, ub);
    
        ans += C * min(dist, B);
        pos += min(dist, B);
    }

    for(auto itr = pos; itr!=A.end();itr++) {
        ans += *itr;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int K; cin >> K;

    int ans = ((K + 1)/2) * (K / 2);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
N,C=map(int,input().split())

nofc=np.zeros((C,10**5),dtype=int)

for i in range(N):
  s,t,c=map(int,input().split())
  vec=np.ones(t-s+1,dtype=int)
  nofc[c-1][s-1:t]=vec
print(int(max(np.sum(nofc,axis=0))))

Measured memory_bytes: 43004
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

ll dp[51][51][2510];
int main() {
    int n, a, m = 0;
    cin >> n >> a;
    VI x(n);
    FOR(i, n) {
        cin >> x[i];
        chmax(m, x[i]);
    }
    eFOR(j, n)eFOR(k, n)eFOR(s, n* m) {
        if (!(j || k || s))dp[j][k][s] = 1;
        else if (j && s < x[j - 1])dp[j][k][s] = dp[j - 1][k][s];
        else if (j && k && s >= x[j - 1])dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]];
        else dp[j][k][s] = 0;
    }
    ll ans = 0;
    eFOR1(i, n) {
        ans += dp[n][i][a * i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 51200