akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
3 2 0 = 2 //121 212
3 2 1 = 6 // 2*(2+1)
3 2 2 = 8 // 2^3

2通りとれるばしょ
4 2 1だとして
1121
ペアは3か所。そのうち1か所まで
2 * 

DP

DP[K]
DP[0] = M;
1回目のループ
DP[0] = DP[0] * (M-1)
DP[1] = DP[0];
DP(NK)になってまう

3 3 0
3 * 2 * 2
=12
3 3 1 = 3^2 3^(N-K)
3 3 2 = 3^1
330+
112
113
221
223
331
332
122
133
211
233
311
322
=9通り
3*3

3 3 2
=3通り

1=0+1
2=0+1+2

3 3 0 = 12
3 3 1 = 12 + 9同じペアをくっつけてカウント？
3 3 2 = 12 + 9 + 3

4 4 0 = 4*3*3*3
4 4 1 = 4 * 3 * 3 * 3C1 = (N-1)CK
4 4 2 = 4 * 3 * 2C2？
1122 1133
1112 1113とか
3通りある。3C2か
1123
1223
1233
1112
1222
1122
1111

4 4 0 = 4*3*3*3* 3C0//1234
4 4 1 = 4*3*3* 3C1//1123 1223 1233
4 4 2 = 4*3 * 3C2//1122 1112 1222
4 4 3 = 4 * 3C3 //1111
M * (M-1)^(N-1-K)*(N-1)CK

3 2 0 = 2 //121 212
2 * 1 * 1 * 2C0
*/

const int MAX = 210000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2; i<MAX; i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

ll COM(int n, int k){
  if(n<k)
    return 0;
  if(n<0 || k<0)
    return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  COMinit();
  
  ll N, M, K; cin >> N >> M >> K;
  ll ans = 0;
  vector<ll> Z(N+1, 1);
  rep(i, N){
    Z[i+1] = Z[i] * (M-1);
    Z[i+1] %= MOD;
  }
  for(ll k=K; k>=0; k--){
//cout << "k;"<<k<<" ans:"<<ans<<endl;
//M * (M-1)^(N-1-K)*(N-1)CK
    ll tmp = M * Z[N-1-k];
    tmp %= MOD;
    tmp *= COM(N-1, k);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 9732
import java.util.Scanner;
public class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int X=(sc.nextInt())-1;
		int Y=(sc.nextInt())-1;
		int ans[]=new int[N-1];

		for(int start=0;start<N-1;start++) {
			for(int goal=start+1;goal<N;goal++) {
				if(start<=X) {
				if(goal<=X) {
					ans[goal-start-1]++;
				}else {
					if((X+Y+1)/2>=goal) {
						ans[goal-start-1]++;
					}else {
						//System.out.println("a");
						ans[X-start+Math.abs(goal-Y)]++;
					}
				}}else {
					if(start-X+Math.abs(goal-Y)+1<=goal-start) {
						ans[start-X+Math.abs(goal-Y)]++;
					}else {
						ans[goal-start-1]++;
					}
				}

			}
		}
		for(int i=0;i<N-1;i++) {
			System.out.println(ans[i]);
		}

	}
}


Measured memory_bytes: 22356
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>
#include <stdio.h>
#include <sstream>
#define int_inf 1000000000 //1e9
#define ll_inf  1000000000000000000 //1e18
using namespace std;
template <typename T> std::string to_string(const T& t){
	std::ostringstream os; os<<t; return os.str();
}

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




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

int main() {
    int a,b;
    cin >> a >> b;
    if(a % 3 == 0) {
        cout << "Possible" << endl;
    } else if(b % 3 == 0) {
        cout << "Possible" << endl;
    } else if((a+b) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}


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

#define NIL NULL

struct node {
  int key;
  struct node *left;
  struct node *right;
  struct node *point;
};
struct node *root;

void inorder(struct node *);
void preorder(struct node *);
void insert(int);

int main()
{
  int i, x, n;
  char s[10];

  scanf("%d", &n);
  for(i=0; i<n; i++) {
    scanf("%s", s);
    if(strcmp("insert", s) == 0) {
      scanf("%d", &x);
      insert(x);
    }
    else if(strcmp("print", s) == 0) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

void inorder(struct node *T)
{
  if(T != NIL) {
    if(T->left != NIL)
      inorder(T->left);
    printf(" %d", T->key);
    if(T->right != NIL)
      inorder(T->right);
  }
}

void preorder(struct node *T)
{
  printf(" %d", T->key);
  if(T != NIL) {
    if(T->left != NIL)
      preorder(T->left);
    if(T->right != NIL)
      preorder(T->right);
  }
}

void insert(int key)
{
  struct node *y = NIL;
  struct node *x = root;
  struct node *z;

  z = (struct node *)malloc(sizeof(struct node));
  z->key = key;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL) {
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }
  z->point = y;
  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->left = z;
  else
    y->right = z;
}

Measured memory_bytes: 24040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AtCoder_Project_CSharp
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(a.Sum(e=>e-1));
        }
    }
}


Measured memory_bytes: 13424
#include<stdio.h>
int main(void)
{
  int a,b,c,i,d=0;
   scanf("%d%d%d", &a,&b,&c);
        for(i=0; i<c; i++){
         if (b >= a) b = b - a;
          else d++;}
        printf("%d\n",i-d);
return 0;
}


Measured memory_bytes: 128
from functools import lru_cache
 
@lru_cache(maxsize=100000)
def n_th_prime(n):
    if n == 0:
        return 2
    primes = [n_th_prime(k) for k in range(n)]
    k = 1
    x = primes[-1] + 1
    while True:
        for p in primes[:k]:
            if x % p == 0:
                x += 1
                break
        else:
            if x > p**2:
                k += 1
            else:
                return x

x = int(input())

k = 0
p = 2
while True:
    for i in range(k):
        p = n_th_prime(i)
        if x % p == 0:
            x += 1
            break
    else:
        if x > p**2:
            k += 1
        else:
            print(x)
            break

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define pb push_back
#define mp make_pair
const int mod=1e9+7;
bool isPalindrome(string s)
{
  int k=s.length();
  int l=0,r=k-1;
  while(l<r)
  {
    if(s[l++]!=s[r--])
    {
      return false;
    }
  }
  return true;
}
void solve()
{
  string str;
  cin>>str;
  int n=str.length();
  if(!isPalindrome(str))
  {
    cout<<"No";
    return;
  }
  int k=(n-1)/2;
  string s="";
  for(int i=0;i<k;i++)
  s+=str[i];
  if(!isPalindrome(s))
  {
    cout<<"No";
    return;
  }
  k=(n+3)/2;
  s="";
  for(int i=k-1;i<n;i++)
  s+=str[i];
  {
    if(isPalindrome(s))
      cout<<"Yes";
      else
        cout<<"No";
  }
}

int main()
{
  fastio
  solve();
}


Measured memory_bytes: 256
a,b = map(int,raw_input().split())
s = raw_input()
no = 0;
for i in range(len(s)):
	if i == a and s[i] != '-':
		no = 1;
	elif i != a and s[i] == '-':
		no = 1;

if no:
	print 'No'
else:
	print 'Yes'

Measured memory_bytes: 2568
def main():
    n = int(input())
    t, a = map(int, input().split())
    hs = list(map(int, input().split()))
    p = min((abs(t - h * 0.006 - a), i) for i, h in enumerate(hs))
    print(p[1] + 1)


if __name__ == '__main__':
    main()


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

int main() {
    int L, R, D, N, O;
    cin >> L >> R >> D;
    N = L;
    O = 0;

    while (N <= R) {
        int M = N % D;
        if (M == 0) {
            O++;
            N++;
        }
        else {
            N++;
        }
    }

    cout << O << endl;
}

Measured memory_bytes: 3620
#include<stdio.h>

int main(void){
  char a[11];
  scanf("%s", a);

  int i = 5;
  int month = 0;
  int monthTmp = 0;

  while(i <= 6){
    monthTmp = (a[i] - '0');
    int j = i;
    while(j < 6){
      monthTmp = monthTmp * 10;
      j++;
    }
    month = month + monthTmp;
    i++;
  }

  if(month >= 5){
    printf("TBD");
  } else {
    printf("Heisei");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back

const int P = 1e9+7;

using namespace std;

string k;
int n, d;
ll dp[2][101][10101];

/*

dp for how many different numbers o (with trailing 0s) fulfill the conditions:

dp[s][j][i]:
i -> look at the last i+1 digits of o.
j -> sum of o's digits after i mod d.
s -> are digits after position i in o the same as in k?

*/

int main(){

	cin >> k >> d;
	n = k.size();

	dp[0][0][0] = 1;
	dp[1][0][0] = 1;

	for(int i=0; i<n; i++){
		for(int j=0; j<d; j++){
			dp[1][j][i] %= P;
			dp[0][j][i] %= P;
			for(int b=0; b<10; b++){
				if(b==(k[n-i-1]-48)) dp[1][(j+b)%d][i+1] += dp[1][j][i];
				if(b<(k[n-i-1]-48)) dp[1][(j+b)%d][i+1] += dp[0][j][i];
				dp[0][(j+b)%d][i+1] += dp[0][j][i];
			}
		}
	}

	cout << (dp[1][0][n]+P-1)%P << endl;

	return 0;
}


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


int prime[1000001]={};

int power(int x, unsigned int y, int p)  
{  
    int res = 1;     
  
    x = x % p; 
   
    if (x == 0) return 0; 
  
    while (y > 0)  
    {  
         
        if (y & 1)  
            res = (res*x) % p;  
  
        
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  

void pr()
{
  prime[1]=0;

 for(int i=2;i*i<1000001;i++)
  if(prime[i]==0)
  for(int j=i*i;j<1000001;j+=i)
  prime[j]=1;

}

int countSetBits( int n) 
{ 
     int count = 0; 
    while (n) { 
        count += n & 1; 
        n >>= 1; 
    } 
    return count; 
} 
  




int main()
{
   //pr();
  int t;
   //cin>>t;
   t=1;

  while(t--)
{

    long a,b;
     cin>>a>>b;

   long c= a%b;
   long d= b-c;

   cout<<min(c,d);
   
}




return 0;
}


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

int key[150][150];

void N(int key[150][150], int n){
	int change = key[n][1];
	key[n][1] = key[n][2];
	key[n][2] = key[n][6];
	key[n][6] = key[n][5];
	key[n][5] = change;
}

void S(int key[150][150], int n){
	int change = key[n][1];
	key[n][1] = key[n][5];
	key[n][5] = key[n][6];
	key[n][6] = key[n][2];
	key[n][2] = change;
}

void W(int key[150][150], int n){
	int change = key[n][1];
	key[n][1] = key[n][3];
	key[n][3] = key[n][6];
	key[n][6] = key[n][4];
	key[n][4] = change;
}

void E(int key[150][150], int n){
	int change = key[n][1];
	key[n][1] = key[n][4];
	key[n][4] = key[n][6];
	key[n][6] = key[n][3];
	key[n][3] = change;
}

int equal(int n, int k){
	int i,j;
	int count;
	for(j=k;j<n;j++){
		count = 0;
		for(i=0;i<6;i++){
			if(key[k][i+1] == key[j+1][i+1]){
				count++;
				if(count == 6){
					return 1;
				}
			}
		}
	}
	return 0;
}

int main(void){
	int i,j,k,n;
	int check = 0;
	
	scanf("%d", &n);
	
	for(i=0;i<n;i++){
		for(j=0;j<6;j++){
			scanf("%d", &key[i][j+1]);
		}
	}
	
	for(k=0;k<n;k++){
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				N(key, k);
				E(key, k);
				S(key, k);
				if(equal(n, k) == 1){
					printf("No\n");
					return 0;
				}
			}
			E(key, k);
		}
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				N(key, k);
				E(key, k);
				S(key, k);
				if(equal(n, k) == 1){
					printf("No\n");
					return 0;
				}
			}
			N(key, k);
		}
	}

	printf("Yes\n");
	
	return 0;
	
}


Measured memory_bytes: 2124
#include <map>
#include <iostream>
using namespace std;
int par[100100], rk[100100];

int getroot(int x) {
    if (par[x] == x) return x;
    else return par[x] = getroot(par[x]);
}

void unite(int x, int y) {
    int rx = getroot(x), ry = getroot(y);
    if (rx != ry) {
        if (rk[rx] > rk[ry]) {
            par[ry] = rx;
        } else {
            par[rx] = ry;
            if (rk[rx] == rk[ry]) rk[ry]++;
        }
    }
}

int main() {
    int n, m; cin >> n >> m;
    if (n/2 + m < n - 1) { cout << "Impossible\n"; return 0; }
    if (m == n - 1) { cout << "0\n"; return 0; }
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    map<int, int> costs;
    for (int i = 0; i < n; i++) {
        par[i] = i; rk[i] = 0; costs[a[i]]++;
    }

    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        unite(x, y);
    }
    int tmp[n];
    fill(tmp, tmp+n, 1<<30);
    for (int i = 0; i < n; i++) {
        int r = getroot(i);
        tmp[r] = min(tmp[r], a[i]);
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        if (i == getroot(i)) {
            ans += tmp[i];
            costs[tmp[i]]--;
        }
    }
    int c = n - m - 2;
    auto it = costs.begin();
    while (c > 0) {
        while (it->second == 0) it++;
        ans += it->first;
        it->second--;
        c--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};

const int N=1e5+5;
vector<int> g[N];
set<int> g2[N];
int u[N];
void no(){
	cout<<"-1\n";
	exit(0);
}
vector<int> bu(int s,int t){
	vector<int> res;
	res.pb(1);
	int l=2;
	int v=s,pred=-1;
	while(1){
		int go=-1,c=0;
		for(int to:g[v]){
			if(u[to]==2&&to!=pred){
				go=to;
			}
			if(u[to]==1)c++;
		}
		if(v==s||v==t)c--;
		dbg(s,t,v,l,pred,go,c);
		for(int i=l+1;i<=l+c;++i)res.pb(i);
		res.pb(l);
		l+=c+1;
		pred=v;
		v=go;
		if(v==-1)break;
	}
	res.pb(l);
	return res;
}
int32_t main(){

	int n;
	cin>>n;
	if(n==2){
		cout<<"1 2\n";
		return 0;
	}
	forn(i,n-1){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
		g2[a].insert(b);
		g2[b].insert(a);
	}
	int f=0;
	for(int i=1;i<=n;++i){
		if(sz(g[i])==1){
			int to=g[i][0];
			u[i]=1;
			f++;
			g2[to].erase(i);
			g2[i].erase(to);
		}
	}
	int v1=-1,v2=-1;
	for(int i=1;i<=n;++i){
		if(sz(g2[i])==1){
			int v=i;
			v1=v;
			while(!g2[v].empty()){
				u[v]=2;
				f++;
				int to=*g2[v].begin();
				g2[v].erase(to);
				if(!g2[v].empty())no();
				g2[to].erase(v);
				v=to;
			}
			u[v]=2;
			v2=v;
			f++;
			break;
		}
	}
	dbg(v1,v2);
	if(v1==-1){
		for(int i=1;i<=n;++i){
			if(!u[i]&&g2[i].empty()){
				f++;
				break;
			}
		}
		if(f==n){
			cout<<"1 ";
			for(int i=3;i<=n-1;++i)cout<<i<<' ';
			cout<<"2 "<<n<<'\n';
			return 0;
		}else no();
	}
	if(f!=n)no();
	auto ans=bu(v1,v2);
	upn(ans,bu(v2,v1));
	for(int i:ans)cout<<i<<' ';
	cout<<'\n';
    return 0;
}


Measured memory_bytes: 26680
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}
template < typename T, typename U >
ostream &operator<<(ostream &os, const pair< T, U > &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

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

struct edge {
	int from, to, d, c, i;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

template < typename A, size_t N, typename T >
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	int A, B;
	cin >> A >> B;
	int X = 0;
	rep(i, N - 2) {
		int a;
		cin >> a;
		X ^= a;
	}
	map< tuple< int, int, int >, int > m;
	auto f = [&](auto &&f, int A, int B, int X) -> int {
		if (((A & 1) ^ (B & 1)) != (X & 1))
			return LINF;
		if (A == 0 && B == 0 && X == 0)
			return 0;
		auto t = make_tuple(A, B, X);
		if (m.count(t))
			return m[t];
		int tmp1 = f(f, A / 2, B / 2, X / 2) * 2;
		int tmp2 = LINF;
		if (A > 0)
			tmp2 = f(f, (A - 1) / 2, (B + 1) / 2, X / 2) * 2 + 1;
		return min(LINF, min(tmp1, tmp2));
	};
	int ans = f(f, A, B, X);
	if (ans == LINF || ans == A)
		ans = -1;
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<long long> a(n);
  for (auto& e : a) {
    cin >> e;
    if (e == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  long long ans = 1;
  long long thres = 1e18;
  for (auto e : a) {
    if (thres / e < ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= e;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3996
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>

using namespace std;

void GCD()
{
	int x, y;

	cin>>x>>y;
    
	int temp;

    while (y != 0)
	{
		temp = x % y; //x ??¨ y ????????§??¬?´???°??? y ??¨ x % y ????????§??¬?´???°????????????
        x = y;
		y = temp; // at the end, temp = 0
	}

	cout<<x<<endl;
	

}

int main()
{
	GCD();
	return 0;
}

Measured memory_bytes: 1160
from collections import defaultdict


def combination(a, b):
    if b > a - b:
        return combination(a, a - b)
    return fact[a] * ifact[b] * ifact[a-b]


MOD = 10**9+7
n, k = map(int, input().split())
k = min(k, n-1)
# 階乗を前処理
fact = defaultdict(int)
fact[0] = 1
for i in range(1, n+1):
    fact[i] = fact[i-1] * i
    fact[i] %= MOD
# 階乗の逆元を前処理
ifact = defaultdict(int)
ifact[n] = pow(fact[n], MOD-2, MOD)
for i in reversed(range(1, n + 1)):
    ifact[i-1] = ifact[i] * i
    ifact[i-1] %= MOD

ans = 0
for i in range(k+1):
    ans += combination(n, i) * combination((n-i-1)+i, i)
    ans %= MOD

print(ans % MOD)


Measured memory_bytes: 63972
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int l,i,j,n,S=0;
        String c="";
        for(i=0; ;i++){
            c=sc.next();    
            l=c.length();
            if(c.equals("0")){
                break;
            }else{
                for(j=0;j<=l-1;j++){
                    n=Integer.parseInt(c.substring(j,j+1));
                    S+=n;
                }
            }
            System.out.println(S); 
            S=0;                   
        } 
    }
}


Measured memory_bytes: 26880
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
char s[5555];
const int M=1000000007;
int f[5005][5005];
int g[5005][5005];
int h[5005];
int main()
{
	int n=io::F();
	scanf("%s",s+1); 
	int m=strlen(s+1);
	g[1][0]=1,g[1][1]=2;
	for(register int i=1;i<5000;++i)
		for(register int j=0;j<=5000;++j)
			g[i+1][j+1]=(g[i+1][j+1]+2ll*g[i][j])%M,g[i+1][j?j-1:0]=(g[i+1][j?j-1:0]+g[i][j])%M;
	h[0]=1;
	for(register int i=1;i<=5000;++i)
	h[i]=g[i][0];
	f[1][1]=1;
	for(register int i=1;i<5000;++i)
		for(register int j=1;j<=5000;++j)
			f[i+1][j+1]=(f[i+1][j+1]+f[i][j])%M,f[i+1][j-1]=(f[i+1][j-1]+2ll*f[i][j])%M;
	int ans=0;
	for(register int k=0;k<n;++k)
		ans=(ans+(long long)h[k]*f[n-k][m])%M;
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 195840
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a,x,b) (a<=x && x<=b)
#define WS std::cout<<" ";
#define NL std::cout<<"\n"
#define OUT(dist) std::cout<<(dist);
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;

V2<int> v;

int main(){
    INIT;
    int N, D; cin >> N >> D;
    v.resize(N);
    REP(i,N) {
        REP(j,D) {
            int x; cin >> x;
            v[i].push_back(x);
        }
    }
    V<int> d;
    int maxd = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            int sum = 0;
            REP(k,D) sum += std::abs(v[i][k]-v[j][k])*std::abs(v[i][k]-v[j][k]);
            d.push_back(sum);
            CHMAX<int>(maxd, sum);
        }
    }
    int ans = 0;
    for(int i = 0; i <= sqrt(maxd); i++) {
        for(int j = 0; j < d.size(); j++) {
            if(i*i == d[j]) ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
using matrix = vector<vector<uint>>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

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

    int N, K;
    cin >> N >> K;
    vector<vector<int>> wcnt(K + 1, vector<int>(K + 1));
    vector<vector<int>> bcnt(K + 1, vector<int>(K + 1));
    for (int i = 0; i < N; ++i) {
        int x, y;
        char c;
        cin >> x >> y >> c;

        bool iswhite = (c == 'W');
        iswhite ^= ((x / K) & 1) ^ ((y / K) & 1);
        x %= K, y %= K;
        (iswhite ? wcnt : bcnt)[y][x]++;
    }

    for (int i = 0; i < K; ++i) {
        for (int j = 0; j <= K; ++j) {
            wcnt[i + 1][j] += wcnt[i][j];
            bcnt[i + 1][j] += bcnt[i][j];
        }
    }
    for (int i = 0; i <= K; ++i) {
        for (int j = 0; j < K; ++j) {
            wcnt[i][j + 1] += wcnt[i][j];
            bcnt[i][j + 1] += bcnt[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < K; ++i) {
        for (int j = 0; j < K; ++j) {
            int sum = wcnt[K][K] - wcnt[i][K] - wcnt[K][j] + 2 * wcnt[i][j];
            sum += bcnt[i][K] + bcnt[K][j] - 2 * bcnt[i][j];
            ans = max(ans, sum);
            ans = max(ans, N - sum);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 8192
#include <iostream>

using namespace std;

int main(){
  string w;
  int a[26];
  cin >> w;
  for (int i = 0; i < 26; i++){
    a[i] = 0;
  }

  for (int i = 0; i < w.size(); i++){
    int n = w[i] - 'a';
    a[n]++;
  }

  int flg = 0;
  for (int i = 0; i < 26; i++){
    if (a[i]%2 != 0) flg = 1;
  }

  if (flg == 0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  
}


Measured memory_bytes: 3608
n = int(input())
mn = float('inf')
s = [int(input())for i in range(n)]
ss = []
for i in range(n):
    if s[i] %10 != 0:
        ss.append(s[i])
ss.sort()
if sum(s) % 10 == 0:
    if ss:
        print(sum(s) - ss[0])
    else:
        print(0)
else:
    print(sum(s))

Measured memory_bytes: 38512
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w,r;
string s,s1,s2;
//vvl v;
//vl vis,d;

int main() {
    IOS;
    cin>>n>>h;
    vl a(n+1),b(n+1);
    fo(i,n)cin>>b[i+1]>>a[i+1];
    vvl dp(n+1,vl(1000001,inf*inf));
    dp[0][0]=0;
    fo(i,n+1){
        fo(j,1000001){
            if(i==0){continue;}
            dp[i][j]=dp[i-1][j];
            if(j>=a[i]){
                dp[i][j]=min(dp[i][j],dp[i-1][j-a[i]]+b[i]);
            }
            //cout<<dp[i][j]<<" "<<i<<" "<<j<<endl;
        }
    }
    fo(i,1000001)if(dp[n][i]<=h&&i>kv)kv=i;
    cout<<kv;
    return 0;
}


Measured memory_bytes: 797568
def resolve():
    import copy
    D = int(input())
    cost = list(map(int, input().split()))
    sat = [list((map(int, input().split()))) for _ in range(D)]
    last = [0]*26

    for i in range(D):
        maxcost = -float("INF")
        ans = 0
        for j in range(26):
            nowlast = copy.deepcopy(last)
            nowlast[j] = i+1
            plussat = sat[i][j]
            minussat = 0
            for k in range(26):
                minussat += (i + 1 - nowlast[k]) * (cost[k])
            cum = plussat-minussat

            if maxcost < cum:
                ans = j
                maxcost = cum
        last[j] = i+1

        print(ans+1)
resolve()

Measured memory_bytes: 72856
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a,const void *b)
{
    return *(int*)a-*(int*)b;
}
int main()
{
		int N,K,A[200000],i;
		int ans=0,count[200000]={0};
		scanf("%d", &N);
		scanf("%d", &K);
		for (i = 0; i < N; i++)scanf("%d",&A[i]);
		for (i = 0; i < N; i++)count[A[i]-1] +=1;
		qsort(count,N,sizeof(int),compare_int);
		  for(i=0;i<N-K;i++)ans+=count[i];
			  printf("%d",ans);
		return 0;
}

Measured memory_bytes: 2556
#include<stdio.h>
#define N 101
#define inf 1000000000
#define NIL -1

int A[N][N],d[N],v[N],color[N],pi[N];

int main(){
  int n,i,j,mincost,v,cost=0,u,k,a;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j] = NIL;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&a);
      scanf("%d",&A[i][a]);
    }
  }

  for(u=0;u<n;u++){
    d[u] = inf;
    pi[u] = NIL;
    color[u] = 0;
  }
  d[0] = 0;
  
  while(1){
    mincost = inf;
    for(i=0;i<n;i++){
      if(color[i] != 1 && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if(mincost == inf){
      break;
    }
    color[u] = 1;
    for(v=0;v<n;v++){
      if(color[v] != 1 && d[u] + A[u][v] < d[v] && A[u][v] != -1){
	pi[v] = u;
	d[v] = d[u] + A[u][v];
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }

  return 0;
  
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x,ans=0,d=100;cin>>x;
  for(ll y=1;y<5000;++y) {
    d=floor(d*1.01);
    if(d>=x) {ans=y;break;}
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3760
s = input()
t = input()
ns = len(s)
nt = len(t)
ans = float("inf")

for i in range(ns-nt+1):
    res = 0
    
    for j in range(nt):
        if t[j] != s[i:i+nt][j]:
            res += 1
            
    ans = min(ans,res)
    
print(ans)

Measured memory_bytes: 9060
#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(){
  ll n,k;cin>>n>>k;
  vector<char> past(n,'0');
  int R,S,P;
  cin>>R>>S>>P;
  string s;cin>>s;
  ll ans=0;
  for(int i=0;i<n;i++){
    if(i>=k){
      if(past[i-k]==s[i]){
        continue;
      }
    }
    if(s[i]=='r'){
      //cout<<"R"<<i<<endl;
      past[i]='r';
      ans+=P;
    }else if(s[i]=='s'){
      //cout<<"S"<<i<<endl;
      past[i]='s';
      ans+=R;
    }else if(s[i]=='p'){
      //cout<<"P"<<i<<endl;
      past[i]='p';
      ans+=S;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3388
import math
n = int(input())
dp = [float("inf")] * (10 ** 5 + 10)
dp[0] = 0
for i in range(1,n + 1):
  power = 1
  while n >= power:
    dp[i] = min(dp[i],dp[i - power] + 1)
    power *= 6
  power = 1
  while n >= power:
    dp[i] = min(dp[i],dp[i - power] + 1)
    power *= 9
print(dp[n])

Measured memory_bytes: 3828
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = 2000000000;
// const ll MOD = 1000000007;

int N, K;
string S;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  cin >> S;

  int ans = 0;
  int l = 0, r = 0;

  // 最初のrの位置まで進める
  int num_zero = 0;
  while (r < N) {
    while (r < N && S[r] == '1') {
      r++;
    }
    if (++num_zero > K) {
      break;
    }
    while (r < N && S[r] == '0') {
      r++;
    }
  }
  ans = max(ans, r - l);

  // l, rを動かしながら、最大のansを求める
  while (r < N) {
    // lを進める
    while (l < N && S[l] == '1') {
      l++;
    }
    while (l < N && S[l] == '0') {
      l++;
    }

    // rを進める
    while (r < N && S[r] == '0') {
      r++;
    }
    while (r < N && S[r] == '1') {
      r++;
    }
    ans = max(ans, r - l);
  }

  cout << ans << endl;
  return 0;
}

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

int main()
{


        int N,K; cin>>N>>K;
        int arr[N];
        int minNum = 0 ;

        for(int i = 0 ; i< N ; i++)
        {
            cin>>arr[i];
        }
        int ans = 0 ;
        while(true)
        {
        if(minNum==0)minNum+=K;
        else minNum+=(K-1);
        ans++;
        if(minNum>=N)break;

        }
        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 1000050
char s[N],t[N];
int n,su[5],fg,v,ct,s1[N],s2[N],ed[N],is;
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;i++)if(s[i]!=s[i-1])t[++v]=s[i],su[s[i]-'A'+1]++;
	if(su[1]<su[2]&&su[1]<su[3])fg=1;
	else if(su[2]<su[3])
	{
		fg=2;
		for(int i=1;i<=v;i++)if(t[i]=='A')t[i]='B';else if(t[i]=='B')t[i]='A';
		su[1]^=su[2]^=su[1]^=su[2];
	}
	else
	{
		fg=3;
		for(int i=1;i<=v;i++)if(t[i]=='A')t[i]='C';else if(t[i]=='C')t[i]='A';
		su[1]^=su[3]^=su[1]^=su[3];
	}
	is=(t[v]=='A');
	ct=1;
	for(int i=1;i<=v;i++)
	if(t[i]=='A')ct++;
	else if(t[i]=='B')s1[ct]++,ed[ct]=1;
	else s2[ct]++,ed[ct]=2;
	int v1=su[2]-su[1],v2=su[3]-su[1];
	for(int i=1;i<=ct;i++)
	{
		if(v1>0&&v2>0)
		{
			int st=min(v1,v2),st2=min(s1[i],s2[i]);
			if(s1[i]==s2[i]&&(1<i&&i<v))st2--;
			st2--;
			if(st2<0)st2=0;
			st=min(st,st2);
			v1-=st,v2-=st,s1[i]-=st,s2[i]-=st;
		}
//		if(v1>v2){int tp=min(s1[i]+s2[i]-(1<i&&i<v),s1[i]-s2[i]+1);if(v1<tp)tp=v1;if(s1[i]<tp)tp=s1[i];if(tp<0)tp=0;s1[i]-=tp,v1-=tp;}
//		else if(v1<v2){int tp=min(s1[i]+s2[i]-(1<i&&i<v),s2[i]-s1[i]+1);if(v2<tp)tp=v2;if(s2[i]<tp)tp=s2[i];if(tp<0)tp=0;v2-=tp,s2[i]-=tp;}
	}
	for(int i=1;i<=ct;i++)
	{
		if(v1>0&&v2>0)
		{
			int st=min(v1,v2),st2=min(s1[i],s2[i]);
			if(s1[i]==s2[i]&&(1<i&&i<v))st2--;
			if(st2<0)st2=0;
			st=min(st,st2);
			v1-=st,v2-=st,s1[i]-=st,s2[i]-=st;
		}
		if(v1>v2){int tp=min(s1[i]+s2[i]-(1<i&&i<v),s1[i]-s2[i]+1);if(v1<tp)tp=v1;if(s1[i]<tp)tp=s1[i];if(tp<0)tp=0;s1[i]-=tp,v1-=tp;}
		else if(v1<v2){int tp=min(s1[i]+s2[i]-(1<i&&i<v),s2[i]-s1[i]+1);if(v2<tp)tp=v2;if(s2[i]<tp)tp=s2[i];if(tp<0)tp=0;v2-=tp,s2[i]-=tp;}
	}
	for(int i=1;i<=ct;i++)
	if(v1>v2){int tp=min(s1[i]+s2[i]-(1<i&&i<v),s1[i]-s2[i]+1);if(v1<tp)tp=v1;if(s1[i]<tp)tp=s1[i];if(tp<0)tp=0;s1[i]-=tp,v1-=tp;}
	else {int tp=min(s1[i]+s2[i]-(1<i&&i<v),s2[i]-s1[i]+1);if(v2<tp)tp=v2;if(s2[i]<tp)tp=s2[i];if(tp<0)tp=0;v2-=tp,s2[i]-=tp;}
	if(v1)
	{
		if(s1[1]==1&&s2[1]==0)v1--,s1[1]--;
		if(s1[ct]==1&&s2[ct]==0&&v1)s1[ct]--,v1--,is=1;
		int tp=v1,tp2=v1;
		for(int i=1;i<=ct;i++)if(s1[i]==1&&s2[i]==0&&tp)s1[i]=0,tp--;
		for(int i=1;i<=ct;i++){int fg=min(tp2,min(s1[i],s2[i]-1));if(fg<0)fg=0;s1[i]-=fg,s2[i]-=fg,tp2-=fg;}
	}
	if(v2)
	{
		if(s2[1]==1&&s1[1]==0)v2--,s2[1]--;
		if(s2[ct]==1&&s1[ct]==0&&v2)s2[ct]--,v2--,is=1;
		int tp=v2,tp2=v2;
		for(int i=1;i<=ct;i++)if(s1[i]==0&&s2[i]==1&&tp)s2[i]=0,tp--;
		for(int i=1;i<=ct;i++){
		int fg=min(tp2,min(s1[i]-1,s2[i]));if(fg<0)fg=0;
		s1[i]-=fg,s2[i]-=fg,tp2-=fg;}
	}
	for(int i=1;i<=ct;i++)
	{
		if(s1[i]+s2[i]&&i>1)printf("%c",'A'+fg-1);
		if(s1[i]>s2[i])
		{
			for(int j=1;j<=s2[i];j++)
			printf("%c",fg==2?'A':'B'),
			printf("%c",fg==3?'A':'C');
			printf("%c",fg==2?'A':'B');
		}
		else if(s1[i]<s2[i])
		{
			for(int j=1;j<=s1[i];j++)
			printf("%c",fg==3?'A':'C'),
			printf("%c",fg==2?'A':'B');
			printf("%c",fg==3?'A':'C');
		}
		else if(ed[i]==2)
		for(int j=1;j<=s2[i];j++)
		printf("%c",fg==2?'A':'B'),
		printf("%c",fg==3?'A':'C');
		else 
		for(int j=1;j<=s2[i];j++)
		printf("%c",fg==3?'A':'C'),
		printf("%c",fg==2?'A':'B');
	}
	if(is)printf("%c",'A'+fg-1);
}

Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b; cin>>a>>b;
  if(abs(a)==abs(b)){
    if(a!=b)cout<<1<<endl;
    else cout<<0<<endl;
  }
  else if(abs(a)<abs(b)){
    int ans=0;
    if(a<0)ans++;
    if(b<0)ans++;
    cout<<ans+abs(b)-abs(a)<<endl;
  }
  else{
    int ans=0;
    if(a>0)ans++;
    if(b>0)ans++;
    cout<<ans+abs(a)-abs(b)<<endl;
  }
}

Measured memory_bytes: 3640
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READV(D);
    D=D*D;
    ll ans=0;
    FORI(i,0,N)
    {
        READV(x);
        READV(y);
        if(x*x+y*y<=D)
        {
            ans++;
        }
    }
    cout<<ans<<endl;

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


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3792
#include<iostream>
#include<ctime>
#include<cstdlib>

using namespace std;

int main()
{
    
    int n,k;
    int card[505][505];
    
    cin >> n >> k;
    for(int i=0;i<k;i++){
        for(int j=0;j<n/2;j++) cin >> card[i][j];
    }
    
    srand( (unsigned int)time(NULL) );
    
    int sum,cnt,ans[1010];
    
    do{
        
        for(int i=1;i<=n;i++) ans[i] = rand() % 2;
        
        cnt = 0;
        for(int i=0;i<k;i++){
            sum = 0;
            for(int j=0;j<n/2;j++){
                sum += ans[ card[i][j] ];
            }
            if(sum >= n/8 && sum <= 3*n/8) cnt++;
        }
        
   }while(cnt < k);
    
    for(int i=1;i<=n;i++) cout << ans[i];
    cout << endl;
    
    return(0);
}



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

int h, w;
vector<vector<char>> a;
vector<vector<int>> cnt;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};

int bfs() {
    queue<pair<int, int>> que;
    for ( int i{}; i < h; i++ ) {
        for ( int j{}; j < w; j++ ) {
            if ( a[i][j] == '#' ) {
                que.push(pair<int, int>(i, j));
                cnt[i][j] = 0;
            }
            else {
                cnt[i][j] = -1;
            }
        }
    }

    int ans = 0;
    while(!que.empty()) {
        pair<int, int> now_p = que.front();
        que.pop();

        ans = cnt[now_p.first][now_p.second];
        for ( int i = 0; i < 4; i++ ) {
            int y = now_p.first + dy[i];
            int x = now_p.second + dx[i];
            if ( y < 0 || y >= h || x < 0 || x >= w || cnt[y][x] >= 0 || a[y][x] == '#' ) continue;
            cnt[y][x] = ans + 1;
            que.push(pair<int, int>(y, x));
        }
    }

    return ans;

}

int main() {

    cin >> h >> w;

    a.resize(h);
    cnt.resize(h);

    for ( int i = 0; i < h; i++ ) {
        a[i].resize(w);
        cnt[i].resize(w);
    }


    for ( int i = 0; i < h; i++ ) {
        for ( int j = 0; j < w; j++ ) {
            cin >> a[i][j];
        }
    }

    cout << bfs() << endl;

    return 0;
}


Measured memory_bytes: 13328
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n, m;
  cin >> n >> m;

  cout << n * m << endl;

  return 0;
}



Measured memory_bytes: 3180
from collections import deque

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

graph = [[] for _ in range(N * N)]
ins = [0] * (N * N)

for i, nodes in enumerate(X):
    for j1, j2 in zip(nodes[:-1], nodes[1:]):
        n1 = max(i, j1 - 1) * N + min(i, j1 - 1)
        n2 = max(i, j2 - 1) * N + min(i, j2 - 1)
        graph[n1].append(n2)
        ins[n2] += 1

dist = [0] * (N * N)
visited = [False] * (N * N)
q = deque()
for i in range(N):
    visited[N * i + i] = True

for i, v in enumerate(ins):
    if v == 0:
        q.append(i)
        visited[i] = True
        dist[i] = 1

while q:
    u = q.popleft()
    for v in graph[u]:
        if visited[v]:
            continue

        ins[v] -= 1
        if ins[v] == 0:
            visited[v] = True
            dist[v] = dist[u] + 1
            q.append(v)
            
print(max(dist) if all(visited) else -1)



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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define inf 0x3f3f3f3f
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/* 
* stuff you should look for
* int overflow, array bounds
* special cases (n=1?), set tle
*/

const int N = 2e5+5;
ull score[N];
ull ans[N];
int vis[N];
vector<int> e[N];

void dfs(int u, ll acc){
	vis[u] = 1;
	ans[u] = acc + score[u];
	for(auto v : e[u]){
		if(!vis[v]) dfs(v, acc + score[u]);
	}
}

int main(){
    fcin;
	int n, q;
	cin >> n >> q;
	for(int i = 0; i < n-1; i++){
		int u, v;
		cin >> u >> v;
		e[u].pb(v);
		e[v].pb(u);
	}
	while(q--){
		int p;
		ll x;
		cin >> p >> x;
		score[p] += x;
	}
	
	dfs(1, 0);
	for(int i = 1; i <= n; i++) cout << ans[i] << " \n"[i==n];
    return 0;
}

Measured memory_bytes: 26368
#include<bits/stdc++.h>
using namespace std;
 int n;
int arr[100000+3][3];
int dp[10000+3][3];
int main()
{

    cin>>n;

    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++) cin>>arr[i][j];
    }

    for(int i=1;i<=n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+arr[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+arr[i][2];
    }

    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
 
using namespace std;
 
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
 
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
 
#define PB(a) push_back(a)
#define PF(a) pop_front(a)
 
#define MP(a,b) make_pair(a,b)
 
#define FS first
#define SE second
 
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
//grobal var
//------------------------------------------
LL dp[100002];

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  LL A,B;
  while(cin >> A >> B){
    str ans = "Yes";
    str S;
    cin >> S;
    EACH(i,S){
      if(i-S.begin()==A) {
        if((*i)!='-'){
          ans = "No";
          break;
        }
      }
      else if(!isdigit(*i)) {
        ans = "No";
        break;
      } 
    }
    cout << ans << endl;
    
  }

  return 0;
}

Measured memory_bytes: 256