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

using namespace std;

int INF = 1e9 + 5;

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

    int n;
    scanf("%d",&n);
    
    vector<int> h(n);
    for(auto& x: h)
    {
        scanf("%d",&x);
    }
    
    int i=0,curr=0,step1=INF,step2;
    
    for(;; ++i)
    {
        step1 = min(step1,curr + abs(h[i+1]-h[i]));
        
        if(i == n-2)  break;
        
        step2 = curr + abs(h[i+2]-h[i]);
        
        curr = step1;
        step1 = step2;
        
    }
    
    cout << step1;
}


Measured memory_bytes: 640
#include <stdio.h>

int main( void ){
    int a_ij[100][100];
    int b[100];
    int c[100];
    int m,n;
    int i,j;

    scanf( " %d %d", &n, &m );
    for( i = 0; i < n; i++ ){
        for( j = 0; j < m; j++ ){
            scanf( " %d", &a_ij[i][j] );
        }
    }

    for( i = 0; i < m; i++ ){
        scanf( " %d", &b[i] );
    }

    for( i = 0; i < n; i++ ){
        for( j = 0; j < m; j++ ){
            c[i] += a_ij[i][j] * b[j];
        }
        printf( "%d\n",c[i] );
    }

    return 0;

}

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

int n;
int cx[20],cy[20];
int dx,dy;

double dist(int x1,int y1,int x2,int y2){
	return sqrt((double)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
bool check(double t,int s,int x,int y){
	for(int i=0;i<n;i++){
		if(s>>i&1)continue;
		if(dist(dx,dy,cx[i],cy[i])-1e-8 < t+dist(x,y,cx[i],cy[i]))return false;
	}
	return true;
}
bool dfs(double t,int s,int x,int y){
	if((1<<n)-1==s)return true;
	if(!check(t,s,x,y))return false;
	for(int i=0;i<n;i++){
		if(s>>i&1)continue;
		if(dfs(t+dist(x,y,cx[i],cy[i]),s|1<<i,cx[i],cy[i]))return true;
	}
	return false;
}
int main(){
	int hx,hy;
	while(cin>>n>>hx>>hy>>dx>>dy,n|hx|hy|dx|dy){
		for(int i=0;i<n;i++){
			cin>>cx[i]>>cy[i];
		}
		cout<<(dfs(0,0,hx,hy)?"YES":"NO")<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
//encoding:utf-8
#include <iostream> //c++
#include<time.h> //時間にかんして
#include<stack> //スタックに関して　最新のデータから捨てる
#include<queue> //キューに関して　最古のデータから捨てる
#include<math.h>
#include<vector>
#include<algorithm> //sort とかにいる

#define ll long long
using namespace std;

// int main(){
//   int a;
//   cin>>a;
//   cout<<a<<endl;
// }
int main(){
  int n,d,x;
  cin>>n>>d>>x;
  vector<int>a(n+1);
  for(int i=0;i<n;i++){
    cin>>a[i];
    // cout<<i<<endl;
  }

  int ans = x;
  int days;
  for(int i=0;i<n;i++){
    days = 1;
    while(days<=d){
      ans += 1;
      days += a[i];
    }
  }

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


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  
  int arr[10],N,A;
  cin >> N >> A;
  cout << N*N - A << endl;
    
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



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

int stack[102]; int top;
char buf[2000];

int main()
{
	int  v1, v2;
	char *p;

	fgets(p=buf, 500, stdin);
	top = 0;
	while (*p >= ' ') {
		while (isspace(*p)) p++;
		if (isdigit(*p)) {
			v1 = 0;
			while (isdigit(*p)) v1 = 10*v1 + (*p++ & 0xf);
			stack[top++] = v1;
		} else {
			v1 = stack[--top];
			v2 = stack[--top];
			if      (*p == '+') v2 += v1;
			else if (*p == '-') v2 -= v1;
			else if (*p == '*') v2 *= v1;
			stack[top++] = v2;
			p++;
		}
	}
	printf("%d\n", stack[--top]);
	return 0;
}




Measured memory_bytes: 2060
# -*- coding: utf-8 -*-


def main():
    h, w = map(int, input().split())
    a = [list(input()) for _ in range(h)]
    dp = [[0 for _ in range(w)] for _ in range(h)]
    mod = 10 ** 9 + 7

    # See:
    # https://qiita.com/drken/items/03c7db44ccd27820ea0d#h-%E5%95%8F%E9%A1%8C---grid-1
    # ◯：自力で気がつけた点
    # △：自力で気がつけなかった点/解説を読めば理解できた点
    # ×：解説を読んでも理解できていない点

    # ◯経路のパターン数を管理
    # △2次元の配列で管理
    # ◯初期値は1通り
    dp[0][0] = 1

    for i in range(h):
        for j in range(w):
            # 配るDP
            # △数え上げDPでは，dp[to] += dp[from]が基本形
            # 次に進むマスがグリッドの範囲内，かつ，進むことができる
            if (j + 1 < w) and (a[i][j + 1] == '.'):
                dp[i][j + 1] += dp[i][j]
                dp[i][j + 1] %= mod

            if (i + 1 < h) and (a[i + 1][j] == '.'):
                dp[i + 1][j] += dp[i][j]
                dp[i + 1][j] %= mod

    # △求めるべき経路数
    print(dp[h - 1][w - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 52404
#include <iostream>

using namespace std;

void solve()
{
	int x, y;
	cin >> x >> y;
	int group_x, group_y;
	if (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12)
	{
		group_x = 0;
	}
	else if (x == 4 || x == 6 || x == 9 || x == 11)
	{
		group_x = 1;
	}
	else
	{
		group_x = 2;
	}
	if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)
	{
		group_y = 0;
	}
	else if (y == 4 || y == 6 || y == 9 || y == 11)
	{
		group_y = 1;
	}
	else
	{
		group_y = 2;
	}
	if (group_x == group_y)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

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

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

int main(){
    
    string s,t;
    cin >> s >> t;
    vector<char> s_sort(s.size()),t_sort(t.size());
    for(int i=0; i<s.size(); i++){
        s_sort.at(i)=s.at(i);
    }
    for(int i=0; i<t.size(); i++){
        t_sort.at(i)=t.at(i);
    }   

    sort(s_sort.begin(),s_sort.end());
    sort(t_sort.begin(),t_sort.end(),greater<>());

    if(s_sort<t_sort) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

bool is_prime[50001];
int main() {
	memset(is_prime, 1, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= 50000; i++) {
		if (is_prime[i]) {
			for (int j = i * 2; j <= 50000; j += i)is_prime[j] = false;
		}
	}
	int n;
	while (cin >> n, n) {
		int cnt = 0;
		for (int i = 2; i <= n / 2; i++) {
			if (is_prime[i] && is_prime[n - i])cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3140
s=str(input())

first=s[0]+s[1]
last=s[2]+s[3]
first=int(first)
last=int(last)

if (last<13 and first<13) and (last>0 and first>0):
    print("AMBIGUOUS")
    
elif (last==0 or first==0) and (last>12 or first>12) :
    print("NA")

elif last>12 and first>12:
    print("NA")
elif last==0 and first==0:
    print("NA")

elif (first>12 or first==0) and (last<13 and last>0) :
    print("YYMM")

elif (last>12 or last==0) and (first<13 and first>0) :
    print("MMYY")

Measured memory_bytes: 3064
def warshall_floyd(n,d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
##################################################################
import itertools
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N, M, R = LI()
r = LI()
cur = 0
ans = inf
d = [[float("inf") for i in range(N)] for i in range(N)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(M):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(N):
    d[i][i] = 0 #自身のところに行くコストは０
#print(warshall_floyd(N,d))
W = warshall_floyd(N,d)
loop = int(1)
#for i in range(len(r)):
#    loop *=(i+1)
for course in itertools.permutations(r):
    cur = int(0)
    for i in range(len(course)-1):
        to = course[i+1]
        go = course[i]
        cur += W[go-1][to-1]
    ans = min(ans,cur)

print(ans)

Measured memory_bytes: 59864
#include <iostream>
  
using namespace std;
  
int a[8][8] = {{}};
int row[8] = {};
int l[15] = {};
int r[15] = {};
int s[8] = {};
  
void print(){
  
  for(int i = 0;i < 8;i++){
    for(int j = 0;j < 8;j++){
      if(a[i][j] == 1){
        if(row[i] != j) {
          return;
        }
      }
    }
  }
  for(int i = 0;i < 8;i++){
    for(int j = 0;j < 8;j++){
      if(row[i] == j) cout << "Q";
      else cout << ".";
    }
    cout << endl;
  }
  
}
  
void backtrack(int i){
  
  if(i == 8){
    print();
    return;
  }
  
  for(int j = 0;j < 8;j++){
    if(s[j] == 1 || l[i + j] == 1 || r[i - j + 7] == 1) continue;
  
    row[i] = j;
    l[i + j] = r[i - j + 7] = s[j] = 1;
  
    backtrack(i + 1);
  
    row[i] = s[j] = l[i + j] = r[i - j + 7] = 0;
  
  }
  
}
  
  
int main(){
  
  int r,c,k;
  
  cin >> k;
  
  for(int i = 0;i < k;i++){
    cin >> r >> c;
    a[r][c] = 1;
  }
  backtrack(0);
}


Measured memory_bytes: 3104
// D - Bouquet
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

// a^n mod m を計算する(二分累乗法:O(logn))
ll modpow(ll a, ll n, ll m) {
	ll x = 1;
	while(n > 0){
		if(n & 1) x = x * a % m;
		a = a * a % m;
		n >>= 1;
	}
	return x;
}

// nCr mod m
ll nCr(ll n, ll r, ll m){
	ll a = 1, b = 1;
	for(ll i=0; i<r; ++i){
		a *= n - i;
		b *= r - i;
		a %=m;
		b %=m;
	}
	return a * modpow(b, m-2, m) % m;
}

int main(){
	ll MOD = 1000000007, N,A,B;
	cin>>N>>A>>B;
	ll ans = modpow(2, N, MOD) - 1;
	ans -= nCr(N, A, MOD);
	ans -= nCr(N, B, MOD);
	ans %= MOD;
	if(ans < 0L) ans += MOD;
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0,ans=0;
bool graph[8][8];

 int main(){
     ll k;  cin >> k;

     vector<int> a(k+10);
     for(int i=0;i<=k;i++){
         a[i] = 0;
     }

     for(int i=1;i<=k;i++){
         for(int j=i;j<=k;j+=i){
             a[j]++;
         }
     }

     for(ll i=1;i<=k;i++){
         ans+=i*a[i];
     }
     cout << ans << endl;
    }

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

int main() {
    string s;
    cin >> s;

    double center = (double)s.size()/2;
    int ans = 0;
    int left = 0;
    int right = s.size() -1;

    while(left<right){
        if(s[left] == s[right]){
            left++;right--;
            continue;
        }
        if(s[left] == 'x'){
            ans++;
            left++;
            continue;
        }
        if(s[right] == 'x'){
            ans++;
            right--;
            continue;
        }
        if(s[left] != s[right]){
            cout << -1 << endl;
            return 0; 
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int n,k,k2,k4;
  int x,y;
  char c;
  int ans=0,sum,suma,sumb;

  scanf("%d%d", &n,&k);
  k2 = k*2;
  k4 = k2*2;
  vector<vector<int> > vvi(k4,vector<int>(k4,0));
  for(int i=0;i<n;++i){
    scanf("%d%d%*c%c",&x,&y,&c);
    if(c == 'B'){
      ++vvi[x%k2][y%k2];
      ++vvi[x%k2+k2][y%k2];
      ++vvi[x%k2][y%k2+k2];
      ++vvi[x%k2+k2][y%k2+k2];
    }else{
      ++vvi[x%k2][(y+k)%k2];
      ++vvi[x%k2+k2][(y+k)%k2];
      ++vvi[x%k2][(y+k)%k2+k2];
      ++vvi[x%k2+k2][(y+k)%k2+k2];
    }
  }
  for(int i=0;i<k4;++i){
    for(int j=0;j<k4-1;++j){
      vvi[j+1][i] += vvi[j][i];
    }
  }
  for(int i=0;i<k4;++i){
    for(int j=0;j<k4-1;++j){
      vvi[i][j+1] += vvi[i][j];
    }
  }
  for(int i=0;i<k2;++i){
    for(int j=0;j<k2;++j){
      suma = vvi[i+k][j+k] + vvi[i][j] - vvi[i+k][j] - vvi[i][j+k];
      sumb = vvi[i+k2][j+k2] + vvi[i+k][j+k] - vvi[i+k2][j+k] - vvi[i+k][j+k2];
      sum = suma + sumb;
      if(ans < sum) ans = sum;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 64896
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
  string s;
  cin >> s;
  int n=s.size();
  
  sort(all(s));
  
  repo(i,n){
    if(s[i-1]==s[i]){
    cout << "no" << endl;
    return 0;
    }
  }
  
  cout << "yes" << endl;
  
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    s = [0]
    for i in a:
        s.append(s[-1]+i)
    ans = float("inf")
    for i in range(n):
        k = abs(s[-1]-s[i]-s[i])
        ans = min(ans,k)
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main(){
    int N,K,p,i;
    double ans=0;
    cin >>N>>K;

    for (i = 1; i <= N; i++){
        p=0;
        while (i*pow(2.0,p)<K){
            p++;
        }
        ans += (pow(2.0,-p))/N;
    }

    cout <<fixed<<setprecision(16)<< ans <<endl;
    return 0;
}


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

using namespace std;

using ull = unsigned long long;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  
  int s = accumulate(a.begin(), a.end(), 0);
  double tmp = (double) s / (4 * m);
  int tmp1 = ceil(tmp);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if ((double) a[i] >= tmp1) {
      cnt++;
      if (cnt == m) {
        break;
      }
    }
  }
  if (cnt == m) {
    cout << "Yes" << '\n';
  }
  else {
    cout << "No" << '\n';
  }
  
  return 0;
}


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

int main(){
  int a = 0, b =0, c= 0;
  cin >> a >> b >> c;
  int tmp1 = a;
  a = b;
  b = tmp1;
  
  int tmp2 = a;
  a = c;
  c = tmp2;
  
  cout << a << " " << b << " " << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
#define INF  0x7fffffff//ffffffff
#define M 4010
ll n,a[M],maxl,ans,flag = 0;
int main(void){
	cin>>n;
	for(ll i = 0;i < n;i++){
		cin>>a[i];
		ans +=a[i];
	}
	ans -=n;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
def solve():
    n, m = list(map(int, input().split(" ")))
    roads = [0 for _ in range(n)]
    for _ in range(m):
        a, b = list(map(int, input().split(" ")))
        roads[a - 1] += 1
        roads[b - 1] += 1

    for road in roads:
        print(road)


solve()

Measured memory_bytes: 3060
N, X = map(int, input().split())
input_list = []
for i in range(N):
    input_list.append(int(input()))
count = N
for i in input_list:
    X -= i
input_list.sort()
while True:
    X -= input_list[0]
    if X < 0:
        break
    count +=1
print(count)

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

int main(){
    int N;
    string s;

    cin>>N;
    int a=0, b=0, c=0, d=0;
    for(int i=0;i<N;i++){
        cin>>s;
        if(s=="AC")
            a++;
        else if (s=="WA")
            b++;
        else if (s=="TLE")
            c++;
        else d++;
    }

    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;

    return 0;

}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll n,m;cin>>n>>m;
    ll ans=0;
    if(n>=2)ans+=n*(n-1)/2;
    if(m>=2)ans+=m*(m-1)/2;
    cout<<ans<<endl;
}

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

int main(){
  int64_t H,c=0;
  int N,A;
  cin >> H >>N;
  for(int i=0;i<N;i++){
    cin >> A;
    H-=A;
    if(H<=0){
      c=1;
      break;
    }
  }

  if(c==0)
    cout << "No"<<endl;
  else 
    cout << "Yes"<<endl;
}


Measured memory_bytes: 256
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
                         **/
#include<bits/stdc++.h>
using namespace std;
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define f1 '\n'
#define vi vector<int>
#define sz size
#define rep(i,x,y) for(int i=(x);i<(y);i++)
#define rep2(i,x,y) for(int i=(x);i>(y);i--)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 1e5+1;
const int mod = 1000000009;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 10000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if(!e)return 1;
    if(e&1) return qpow(b,e-1)*b;
    int pwur=qpow(b,e>>1);
    return pwur*pwur;
}
int modinv(int x){
    return qpow(x,mod-2);
}

/// My Code -------------------------------------------------

int a[3]={10000,5000,1000};

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n,s;
    cin>>n>>s;
    rep(i,0,2001){
        rep(j,0,2001){
            int tmp=s-((i*10000)+(j*5000));
            if(tmp>=0&&tmp%1000==0 && i+j+tmp/1000==n){
                cout<<i<<' '<<j<<' '<<tmp/1000;
                return 0;
            }
        }
    }

    cout<<"-1 -1 -1";

    return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

ll solve(V<int> a,int K,int M){
	int N = si(a);
	show(a);show(K);show(M);
	V<ll> f(N+1);
	{
		ll C[60][60]={};
		rep(i,60){
			C[i][0] = C[i][i] = 1;
			rep1(j,i-1) C[i][j] = C[i-1][j-1] + C[i-1][j];
		}
		rep(i,N+1) rep(j,K) f[i] += C[i][j];
	}
	show(f);
	ll ans = 0;
	rep(l,N){
		rep(s,1<<M){
			int match = 0;
			for(int i=l+1;i<N;i++){
				if((a[l]&s) == (a[i]&s)) match++;
			}
			if(__builtin_popcount(s)%2 == 0) ans += f[match];
			else ans -= f[match];
		}
	}
	return ans;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N,K,S,T; cin >> N >> K >> S >> T;
	if((S&T) != S){
		cout << 0 << endl;
		return 0;
	}
	V<int> vs;
	rep(i,N){
		int a; cin >> a;
		if((a&S) != S) continue;
		if((a|T) != T) continue;
		vs.pb(a);
	}
	N = si(vs);
	V<int> us; int M=0;
	for(int v: vs){
		int u = 0;
		int I = 0;
		rep(i,18){
			if(!(S&1<<i) && (T&1<<i)){
				if(v&1<<i) u |= 1<<I;
				I++;
			}
		}
		us.pb(u);
		M = I;
	}
	cout << solve(us,K,M) << endl;
}


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

int64_t stable = 1000000007;
//コンビネーションの配列
vector<vector<int64_t>> combination(int n) {
  vector<vector<int64_t>> v(n + 1,vector<int64_t>(n + 1));
  for (int i = 0; i < n + 1; i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < n; j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]) % stable;
    }
  }
  return v;
}
int main() {
  int N, K;
  cin >> N >> K;
  vector<vector<int64_t>> comb = combination(N);
  for(int i = 1; i < K + 1; i++){//iが操作数
    int64_t bluecase = comb[K - 1][i - 1];
    //if(N - K < i - 1){
      //break;
    //}
    int64_t redcase = comb[N - K + 1][i];
    cout << (bluecase * redcase) % stable << endl;
  }
}


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

int main() {
  int n,count = 0;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,a.size()) {
    int mini = i;
    for(int j = i; j < a.size(); j++) {
      if(a[j] < a[mini]) {
        mini = j;
      }
    }
    swap(a[i],a[mini]);
    if(a[i] != a[mini]) {
      count++;
    }
  }

  rep(i,n) {
    if(i != n-1) {
      cout << a[i] << ' ';
    }else {
      cout << a[i] << endl;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3080
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

a,b,c,d = map(int,input().split())

c_m = b//c - (-(-a//c)) +1
d_m = b//d  - (-(-a//d)) + 1
cd = lcm(c,d)
cd_m = b//(cd) - (-(-a//(cd))) + 1

print(b-a+1 -(c_m + (d_m -cd_m)*(d%c != 0)))

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

typedef long long ll;

int main() {
	ll n, z, w; cin >> n >> z >> w;
	vector<ll>a(n); for (auto&& x : a)cin >> x;
	ll ans = 0;
	if (n == 1)ans = abs(a[0] - w);
	else ans = max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1]));
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(N):
    ans += B[A[i]-1]
    if i < N-1 and A[i+1] == A[i] + 1:
        ans += C[A[i]-1]

print(ans)


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

int abs(int x){
  if(x<0){
    x=-x;
  }
  return x;
}

int dist(int x1,int y1,int x2,int y2){
  return abs(x1-x2)+abs(y1-y2);
}

int main(){
  int N;
  cin>>N;
  vector<int> t(N+1,0),x(N+1,0),y(N+1,0);
  t.at(0)=0;
  for(int i=1;i<=N;i++){
    cin>>t.at(i)>>x.at(i)>>y.at(i);
  }

  bool flag=true;
  for(int i=1;i<=N;i++){
    int distance=dist(x.at(i),y.at(i),x.at(i-1),y.at(i-1));
    int time=t.at(i)-t.at(i-1);
    if(distance>time||(time-distance)%2==1){
      flag=false;
      break;
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 1408
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
//        sc.useDelimiter(",");
//        DecimalFormat df = new DecimalFormat("0.00000000");

        final int N = Integer.parseInt(sc.next());
        String s = sc.next();
        String t = s.substring(0,N/2);
        t += t;
        out.println(s.equals(t) ? "Yes" : "No");
        
        out.flush();
    }
}

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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int N = 1000007, inf = 0x3f3f3f3f;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n; cout << 1 - n << endl;
}

Measured memory_bytes: 3640
//============================================================================
// Name        : d.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n,m;cin>>n>>m;
	vector<int> a(m);
	vector<int> dp(10001,-1);
	dp[0]=0;
	vector<int> ma(10,5);
	ma[1]=2;
	ma[4]=4;
	ma[6]=6;
	ma[7]=3;
	ma[8]=7;
	ma[9]=6;
	vector<int> num;
	for(auto& x:a){
		cin>>x;
	}
	sort(a.begin(),a.end());
	for(auto& x:a){
		num.push_back(ma[x]);
		dp[ma[x]]=1;
	}

	for(int i=1;i<=n;i++){
		for(auto x:num){
			if(i-x<0){
				continue;
			}
			if(dp[i-x]==-1)continue;
			int t=dp[i-x]+1;
			if(t>dp[i]){
				dp[i]=t;
			}
		}
	}

//	for(auto x:dp){
//		cout<<x<<endl;
//	}
//	cout<<endl;

	int remn=n;
	for(int i=dp[n];i>0;i--){
		for(int j=m-1;j>=0;j--){
			int use=ma[a[j]];
//			cout<<remn<<' '<<i<<' '<<use<<endl;
			if(remn<use)continue;
			if(dp[remn-use]==i-1){
				cout<<a[j];
				remn-=use;
				break;
			}
		}
	}
	cout<<endl;

//	cout<<dp[n]<<endl;
	return 0;
}

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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int hor[2100][2100];


int main() {
  int H, W;
  cin >> H>>W;
  vector<string> field(H);
  for(int i = 0; i < H; i++) {
    cin>>field[i];
  }
  int ans=0;
  bool M = false;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(field[i][j]=='#') continue;
      int cnt = 0;
      int k = 0;
      if(j==0||field[i][j-1]=='#'){
        while(j+k<W){
          if(field[i][j+k]=='.') hor[i][j]++;
          if(field[i][j+k]=='#') break;
          k++;
        }
        k=0;
        while(j+k>=0){
          if(field[i][j+k]=='.') hor[i][j]++;
          if(field[i][j+k]=='#') break;
          k--;
        }
      }
      else hor[i][j] = hor[i][j-1];
      k=0;
      while(i+k<H){
        if(field[i+k][j]=='.') cnt++;
        if(field[i+k][j]=='#') break;
        k++;
      }
      k=0;
      while(i+k>=0){
        if(field[i+k][j]=='.') cnt++;
        if(field[i+k][j]=='#') break;
        k--;
      }
      cnt+=hor[i][j];
      cnt-=3;
      chmax(ans,cnt);
      if (ans == H+W-1){
        M = true;
        break;
      }
    }
    if(M) break;
  }
  cout<<ans<<endl;
}

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

using namespace std;

int A, B, C, X, Y;

void solve() {
    int res = pow(10, 9);
    for (int i = 0; i <= max(X, Y) * 2; ++i) {
        res = min(
                (int) (C * i
                       + A * max(0, (int) round(X - i * 0.5))
                       + B * max(0, (int) round(Y - i * 0.5))),
                res);
    }
    printf("%d\n", res);
}

int main() {
    cin >> A >> B >> C >> X >> Y;
    solve();
    return 0;
}

Measured memory_bytes: 3744
N, C, K = [int(x) for x in input().split()]
T = [int(input()) for _ in range(N)]
T.sort()
depart = T[0] + K  # 出発時刻
passenger = 0  # 乗客数
bus = 1
for i in range(N):
    if passenger >= C or depart < T[i]:  # すでに満員または待ち時間オーバー
        bus += 1
        passenger = 1
        depart = T[i] + K
    else:
        passenger += 1

print(bus)

Measured memory_bytes: 13340
pattern = [ %w|# .|, %w|. #| ]

loop do

  h, w = gets.split.map(&:to_i)
  exit if h + w == 0

  for i in 0...h do
    pat = pattern[ ( i % 2 ) ] # initial pattern
    for j in 0...w do
      print pat[ ( j % 2 ) ]
    end
    puts
  end
  puts

end

Measured memory_bytes: 6100
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>

#define DEBUG 0

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){

	lli n;
	vector<lli> a;
	cin>>n;
	REP(i,n){
		lli tmp;
		cin>>tmp;
		a.push_back(tmp);
	}

	lli cnt=0;
	lli ans=0;
	lli now=0;
	lli before=-1;
	lli flag=0;
	for(int i=0;i<n;i++){
		now=a[i];
		if(now == before){
			ans++;
			before=-1;
		}
		else{
			before=a[i];
		}
	}
	cout<<ans<<endl;



	return 0;

}

Measured memory_bytes: 256
from math import gcd
from functools import reduce

def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(4, n + 1, 2):
        sieve[i] = 2
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i * 2):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


def prime_factorize(n):
    result = []
    while n != 1:
        p = prime_table[n]
        e = 0
        while n % p == 0:
            n //= p
            e += 1
        result.append((p, e))
    return result


def f():
    s = set()
    for i in range(N - 1, -1, -1):
        t = prime_factorize(A[i])
        for p, _ in t:
            if p in s:
                return False
            s.add(p)
    return True


N, *A = map(int, open(0).read().split())

prime_table = make_prime_table(10 ** 6)
if f():
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')


Measured memory_bytes: 223616
//#pragma GCC         optimize("O3")
#include            <bits/stdc++.h>
#include            <ext/pb_ds/assoc_container.hpp>
#include            <ext/pb_ds/tree_policy.hpp>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define mp          make_pair
#define mem(x,i)    memset(x,i,sizeof(x))
#define ff          first
#define ss          second
#define popcount(x) __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define Case(t)     for(int ks=1;ks<=t;ks++)
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define D(x)        cerr<< __LINE__ <<": "<< #x << " = "<<(x) <<'\n';
#define endl        '\n'

using namespace std;
using namespace __gnu_pbds;

using ll  = long long;
using ld  = long double;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;

const int INF    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 998244353;
const int mx     = 100005;
template <typename T>  using orderedSet =
    tree<T, null_type, less_equal<T>,
    rb_tree_tag, tree_order_statistics_node_update>;//find_by_order,order_of_key*/

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

//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;}
/*----------------------BitMask-----------------------------------------*/
//inline int setBit(int N,int pos){return N=N | (1<<pos);}
//inline int resetBit(int N,int pos){return N= N & ~(1<<pos);}
//inline bool checkBit(int N,int pos){return (bool) (N& (1<<pos));}

int main()
{
    int n;
    cin>>n;
    ll vil[n+1];
    ll her[n];
    for(int i=0;i<=n;i++)cin>>vil[i];
    for(int i=0;i<n;i++) cin>>her[i];
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        ll c=her[i];
        if(c>vil[i])
        {
            ans+=vil[i];
            c-=vil[i];
            if(c>vil[i+1]) ans+=vil[i+1];
            else ans+=c;
            vil[i+1]=max(0LL,vil[i+1]-c);
        }
        else ans+=c;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5148
require 'prime'
$prime_array = Prime.each(999999).flat_map{|v|;v}

def judge_prime_with_index(num)
	return $prime_array.include?(num) ? $prime_array.index(num) + 1 : nil
end

while input = gets
	n = input.strip.to_i
	count = 0
	n.downto(2) {|num|
		result = judge_prime_with_index(num)
		if result != nil
			count = result
			break
		end
	}
	puts count
end

Measured memory_bytes: 6992
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      f: [[usize;10];n],
      p: [[i32;11];n],
   }
   let mut ans = std::i32::MIN;
   for k in 1..1 << 10 {
      let opn: Vec<_> = (0..10).map(|i| (k >> i) & 1).collect();
      let mut c = vec![0; n];
      for i in 0..n {
         for j in 0..10 {
            if f[i][j] * opn[j] == 1 {
               c[i] += 1;
            }
         }
      }
      ans = std::cmp::max(
         ans,
         c.iter().enumerate().fold(0, |sum, (i, &c)| sum + p[i][c]),
      );
   }
   println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S[] = new String[N];
		boolean isFollowRule = true;
		Set set = new HashSet<String>();

		for (int i = 0; i < N; i++) {
			S[i] = sc.next();
			set.add(S[i]);
			if (i != 0 && !(S[i - 1].substring(S[i - 1].length() - 1).equals(S[i].substring(0, 1)))) {
				isFollowRule = false;
			}
		}

		if (N == set.size() && isFollowRule) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22228
import java.util.stream.*;

class Main{
	public static void main(String[] A){
		System.out.println(
				IntStream.rangeClosed(2,55555)
						.filter(o->o%5==1&&IntStream.range(2,o).noneMatch(p->o%p==0))
						.limit(new java.util.Scanner(System.in).nextInt())
						.mapToObj(String::valueOf)
						.collect(Collectors.joining(" "))
						);
	}
}


Measured memory_bytes: 26836
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define ll long long int
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define deb(x) cerr<<#x<<" = "<<x<<endl

using namespace std;

int main() {
    IOS;

    int n; cin>>n;
    cout<<n*n*n<<endl;

    return 0;
}


Measured memory_bytes: 256
def getBaseM2Num(n):
  if n == 0:
    return 0
  
  #下位ビットから計算していく
  base = 1
  b2 = []
  while n != 0:
    if n % (2*base) == 0:
      #2のcnt乗で割り切れると、下からcntビット目は０
      b2.insert(0,"0")
    else:
      #割り切れない場合は1
      b2.insert(0,"1")
      n -= base
      
    base *= -2

  return "".join(b2)


n = int(input())
print(getBaseM2Num(n))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long
int a[10],b[10],n,Sum=0;
LL jc[15],Pro=1,ans=0;
char s[20];
LL cal(int n)
{
    int i;LL ans=jc[n]; 
    for (i=0;i<=9;i++) ans/=jc[b[i]];
    return ans;
}
LL cal0()
{
    for (int i=0;i<=9;i++) b[i]=a[i];
    return cal(n);
}
LL cal1()
{
    int i,j;LL ans=0;
    for (i=0;i<=9;i++) b[i]=a[i];
    for (i=1;i<n;i++)
    {
        for (j=0;j<s[i]-'0';j++) if (b[j]) {b[j]--;ans+=cal(n-i);b[j]++;}
        if (b[s[i]-'0']) b[s[i]-'0']--; else break;
    }
    return ans;
}
void dfs(int x,int num,int sum,LL pro)
{
    if (sum>Sum||sum==Sum&&pro>Pro) return;
    if (x==n)
    {
        if (sum<Sum||sum==Sum&&pro<Pro) ans+=cal0();
         else ans+=cal1();
        return;
    }
    for (int j=num;j<=9;j++) {a[j]++;dfs(x+1,j,sum+j,pro*((LL)(j+1)));a[j]--;}
}
int main()
{
  //  freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    scanf("%s",s+1);n=strlen(s+1);jc[0]=1;
    for (int i=1;i<=n;i++) {Sum+=s[i]-'0';Pro*=(LL)(s[i]-'0'+1);jc[i]=jc[i-1]*((LL)i);}
    for (int i=0;i<=9;i++) {a[i]++;dfs(1,i,i,i+1);a[i]--;}
    printf("%lld\n",ans);
    
    return 0;
}

Measured memory_bytes: 1140
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int n;
	cin >> n;
	int ans(0);
	vector<int>v(n),c(n);
	rep(i, n)cin >> v[i];
	rep(i, n)cin >> c[i];
	rep(i, n) {
		if (v[i] > c[i])ans += v[i] - c[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3576
import sys

input = sys.stdin.readline

def main():
    ans = 'NO'
    k = 'keyence'
    S = input().rstrip('\n')
    if S[:7] == k or S[-7:] == k:
        ans = 'YES'
    elif S[0] == k[0]:
        for i in range(1,len(k)):
            if S[i] != k[i]:
                if S[-(7-i):] == k[i:]:
                    ans = 'YES'
                    break
                else:
                  break
    print(ans)

if __name__ == '__main__':
    main()

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

int main(){
    int D;
    cin>>D;
    if(D==25)cout<<"Christmas"<<endl;
    else if(D==24)cout<<"Christmas Eve"<<endl;
    else if(D==23)cout<<"Christmas Eve Eve"<<endl;
    else if(D==22)cout<<"Christmas Eve Eve Eve"<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int N,Q;
    cin >> N >> Q;
    pair<lint,pair<lint,lint>> T[N];
    rep(i,N){
        cin >> T[i].second.first >> T[i].second.second >> T[i].first;
        T[i].second.second--;
    }
    multiset<plint> D;
    rep(i,Q){
        plint X;
        cin >> X.first;
        X.second=i;
        D.insert(X);
    }
    lint ans[Q];
    sort(T,T+N);
    rep(i,Q) ans[i]=LINF;
    rep(i,N){
        lint beg=T[i].second.first-T[i].first;
        lint en=T[i].second.second-T[i].first;
        auto s=D.lower_bound(plint(beg,0));
        auto g=D.upper_bound(plint(en,INF));
        auto itr=s;
        while(itr!=g){
            plint save=*itr;
            ans[save.second]=T[i].first;
            itr++;
        }
        D.erase(s,g);
    }
    rep(i,Q){
        if(ans[i]==LINF) cout << -1 << endl;
        else cout << ans[i] << endl;
    }
}

Measured memory_bytes: 20608
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

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

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(string, s);
    print(count(all(s), '1'));

    return 0;
}


Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
mod = 998244353


def main():
    N = I()
    A = LI()

    if A[0] != 0:
        return 0

    DistCnt = [0] * (max(A)+1)
    for i in range(N):
        DistCnt[A[i]] += 1

    if DistCnt[0] != 1:
        return 0

    ans = 1
    for i in range(1,len(DistCnt)):
        ans *= pow(DistCnt[i-1],DistCnt[i],mod)
        ans %= mod
    return ans

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 52764
#include <cstdio>
#include <string>
using namespace std;
char word[201];

void copy_word(char* s, char* t, int n){
	//source t:new
	for(int i = 0; i<n; ++i){
		t[i] = s[i];
	}
}

int main(){
	while(1){
		scanf("%s", word);
		if(word[0] == '-'){
			break;
		}
		/*int length;
		length = strlen(word);*/
		
		int length =0;
		while(word[length]!='\0'){
			++length;
		}
		
		int m, b;
		char new_word[201];
		scanf("%d", &m);
		
		for(int i=0; i<m; ++i){
			scanf("%d", &b);
			copy_word(word+b,new_word,length-b);
			copy_word(word,new_word+length-b,b);
			copy_word(new_word,word,length);
		}
		printf("%s\n", word);
		
	}
}


Measured memory_bytes: 2596
#include<iostream>
using namespace std;
int main ()
{
	int i,n;
	while(cin>>n)
	{
		int a=0,b=0,t;
		for(i=0;i<n;i++)
		{
			cin>>t;
			if(t%2==0)
				a++;
			if(t%4==0)
				b++;
		}
		a=a-b;
		if((n-a)<=2*b&&a!=0)
			cout<<"Yes"<<endl;
		else if((n-a-1)<=2*b&&a==0)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <map>
#include <cctype>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
string s;
map<string,int> mp;
typedef string::const_iterator State;
bool isC(char c){
	return'A'<=c && c<='Z';
}
bool isS(char c){
	return'a'<=c && c<='z';
}
int atom(State &be){
	string a;
	a+=(*be);
	be++;
	if(isS(*be)) a+=(*be),be++;
	if(mp.count(a)==0) return -1;
	return mp[a];
}
int num(State &be){
	int ret=0;
	while(isdigit(*be)){
		ret*=10;
		ret+=(*be)-'0';
		be++;
	}
	return ret;
}
int mol(State &be){
	int ret=0;
	while((*be)!='$' && (*be)!=')'){
		int x;
		if(isC(*be)){
			x=atom(be);
			if(x==-1) return -1;
			if(isdigit(*be)) x*=num(be);
		}else if(*be=='('){
			be++;
			x=mol(be);
			if(x==-1) return -1;
			be++;
			x*=num(be);
		}
		ret+=x;
	}
	return ret;
}
int main(){
	while(true){
		int x;
		cin >> s;
		if(s.size()>2) break;
		cin >> x;
		mp.insert(make_pair(s,x));
	}
	while(true){
		cin>>s;
		if(s[0]=='0') break;
		s+='$';
		State be=s.begin();
		int ans=mol(be);
		if(ans==-1) cout << "UNKNOWN\n";
		else cout << ans << endl;
	}
}

Measured memory_bytes: 1232