akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

struct MyStruct {
	long long a, b;
};

bool comp(const MyStruct& s, const MyStruct& t) {
	if (s.a != t.a)
		return s.a < t.a; // 昇順
	return s.b > t.b;
}

int N, M;


int main() {
	cin >> N >> M;

	vector<MyStruct> drinks(N);
	REP(i, N) {
		cin >> drinks[i].a >> drinks[i].b;
	}

	sort(drinks.begin(), drinks.end(), comp);
	int left = M;
	long long ans = 0;
	int i = 0;
	while (left > 0) {
		if (drinks[i].b <= left) {
			ans += drinks[i].a*drinks[i].b;
			left -= drinks[i].b;
		}
		else {
			ans += drinks[i].a*left;
			break;
		}
		i++;
	}

	ANS(ans);

	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
 
#define NIL NULL
 
struct node{
  struct node *left;
  struct node *right;
  struct node *parent;
  int key;
};
 
typedef struct node * Node;
 
Node root;
 
void preorder(Node u){
  printf(" %d",u->key);
  if(u!=NIL){
    if(u->left!=NIL)preorder(u->left);
    if(u->right!=NIL)preorder(u->right);
  }
}
 
void inorder(Node u){
   
  if(u!=NIL){
    if(u->left!=NIL){
      inorder(u->left);
      }
    printf(" %d",u->key);
     
    if(u->right!=NIL){
      inorder(u->right);
      }
  }
}
 
void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
   
  while(x!=NIL){
    y=x;
 
    if(z->key<x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;
   
  if(y==NIL) root=z;
  else if(z->key<y->key) y->left=z;
  else y->right=z;
}
 
main(void){
  int n, i, x;
  char com[20];
   
  scanf("%d",&n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s",com);
 
    if (com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if (com[0]=='p'){
      inorder(root);
      printf("\n");
       
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 24040
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    ll A,B; cin>>A>>B;
    ll Gcd = __gcd(A,B);

    ll ans = 1;
    for (ll i = 2; i*i <= Gcd; ++i) {
        if(Gcd % i ==0){
            ans++;
            while(Gcd % i == 0){
                Gcd /= i;
            }
        }
    }

    if(Gcd > 1) ans++;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn =new Scanner(System.in);
		 String s =scn.next();
		  long sum=0;
		  for(int i=0;i<s.length();i++){
			  sum+=(s.charAt(i)-'0');
			  sum%=9;
		  }
		  if(sum==0){
			  System.out.println("Yes");
		  }else{
			  System.out.println("No");
		  }

	}

}

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

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



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

  int k;
  string s;
  cin >> k >> s;
  if(sz(s) <= k) cout << s << endl;
  else cout << s.substr(0,k) << "..." << endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T &a, T b) {if (a < b) {a = b;return 1;}return 0;}
template<class T> inline bool chmin(T &a, T b) {if (a > b) {a = b;return 1;}return 0;}

using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  map<string,int> cnt;
  rep(i,n) {
    string s;
    cin >> s;
    cnt[s]++;
  }
  for (string s : {"AC", "WA", "TLE", "RE"}) {
    cout << s << " x " << cnt[s] << endl;
  }
  return 0;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
void dump(vector<int> &v){
	for(int i=0;i<v.size();i++){
		cout << v[i] << ' ';
	}
	cout << endl;
}
int n,k,s;
int x[2010],y[2010],z[2010];
int c[2010][2010];
struct edge{
	int to,cost;
	edge(){}
	edge(int to,int cost):to(to),cost(cost){}
};
bool used[2010];
vector<edge> g[2010];
int lap(int *w,int a,int b){
	int d = abs(w[a]-w[b]);
	if(d<s)return s-d;
	else return -1;
}
int f(int a,int b){
	int X = lap(x,a,b);
	int Y = lap(y,a,b);
	int Z= lap(z,a,b);
	if(X==-1||Y==-1||Z==-1)return 0;
	return 2*X*Y+2*Y*Z+2*Z*X;
}
vector<int> path;
void dfs(int v,int p){
	used[v]=true;
	path.pb(v);
	for(int i=0;i<g[v].size();i++){
		int u = g[v][i].to;
		if(u==p)continue;
		if(!used[u])dfs(u,v);
	}
}
int sol_sub_path(){
	int s = 0;
	int t = 0;
	int res = 0;
	int cur = 0;
	int ps = path.size();
	if(k==1)return 0;
	if(ps<k)return -1;
	else{
		for(int i=0;i<(k-1);i++){
			cur += c[path[i]][path[i+1]];
		}
		res = cur;
		for(int i=0;i<ps-k;i++){
			cur -= c[path[i]][path[i+1]];
			cur += c[path[i+k-1]][path[(i+k)]];
			res = max(res,cur);
		}
	}
	return res;
}
int sol_sub_loop(){
	int s = 0;
	int t = 0;
	int res = 0;
	int cur = 0;
	int ps = path.size();
	if(k==1)return 0;
	if(ps<k)return -1;
	else if(ps==k){
		for(int i=0;i<ps;i++){
			res += c[path[i]][path[(i+1)%ps]];
		}
		return res;
	}else{
		/*while(t<path.size()){
			while(t<path.size()&&t-s+1<k){
				cur += c[path[t]][path[(t+1)%ps]];
				t++;
			}
			//cout << s << ' ' << t << ' ' << cur << endl;
			if(t-s+1<k)return res;
			res = max(res,cur);
			cur -= c[path[s]][path[s+1]];
			s++;
		}*/
		for(int i=0;i<(k-1);i++){
			cur += c[path[i]][path[i+1]];
		}
		res = cur;
		for(int i=0;i<ps;i++){
			cur -= c[path[i]][path[(i+1)%ps]];
			cur += c[path[(i+k-1)%ps]][path[(i+k)%ps]];
			res = max(res,cur);
		}
	}
	return res;
}
bool solve(){
	scanf("%d %d %d",&n,&k,&s);
	if(n==0&&k==0&&s==0)return false;
	for(int i=0;i<n;i++){
		scanf("%d %d %d",&x[i],&y[i],&z[i]);
	}
	memset(used,false,sizeof(used));
	for(int i=0;i<n;i++)g[i].clear();
	memset(c,0,sizeof(c));
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			c[i][j] = c[j][i] = f(i,j);
			if(c[i][j]!=0){
				g[i].pb(edge(j,c[i][j]));
				g[j].pb(edge(i,c[i][j]));
			}
		}
	}
	/*for(int i=0;i<n;i++){
		cout << i << ": ";
		for(int j=0;j<g[i].size();i++){
			cout << g[i][j].to << ' ';
		}
		cout << endl;
	}*/
	/*for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cout << c[i][j] << ' ';
		}
		cout << endl;
	}*/
	int ans = -1;
	for(int i=0;i<n;i++){
		if(!used[i]&&g[i].size()==1){
			used[i]=true;
			path.clear();
			dfs(i,-1);
			//dump(path);
			int res = sol_sub_path();
			//cout << res << endl;
			ans = max(ans,res);
		}
	}
	for(int i=0;i<n;i++){
		if(!used[i]){
			used[i]=true;
			path.clear();
			dfs(i,-1);
			//dump(path);
			int res = sol_sub_loop();
			//cout << res << endl;
			ans = max(ans,res);
		}
	}
	if(ans==-1)printf("-1\n");
	else printf("%d\n",s*s*6*k-ans);
	return true;
}
int main() {
	while (solve());
	return 0;
}


Measured memory_bytes: 19132
n = int(input())

ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
    s = input()

    if s == "AC":
        ac += 1
    if s == "WA":
       wa += 1
    if s == "TLE":
       tle += 1
    if s == "RE":
       re += 1

a1 = "AC x " + str(ac)
a2 = "WA x " + str(wa)
a3 = "TLE x " + str(tle)
a4 = "RE x " + str(re)

print(a1)
print(a2)
print(a3)
print(a4)

Measured memory_bytes: 9220
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll l,r;
int main(){FAST;
cin>>l>>r;
if(r/2019 - (l-1)/2019){
	cout<<0;
}
else{
	ll mi = 2018;
	for(ll i=l;i<=r;i++){
		for(ll j=i+1;j<=r;j++){
			mi=min(mi,((i%2019)*(j%2019))%2019);
		}
	}
	cout<<mi;
}
return 0;
}

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

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
        
    long long res = 0;
    for (int d = 60; d >= -1; --d) { // d = -1 は X = K の場合
        if (d != -1 && !(K & (1LL<<d))) continue;
        
        long long tmp = 0;
        for (int e = 60; e >= 0; --e) {
            long long mask = 1LL<<e;
            int num = 0;
            for (int i = 0; i < N; ++i) if (A[i] & mask) ++num;
            
            if (e > d) {
                if (K & mask) tmp += mask * (N - num);
                else tmp += mask * num;
            }
            else if (e == d) {
                tmp += mask * num;
            }
            else {
                tmp += mask * max(num, N - num);
            }
        }
        res = max(res, tmp);
    }
    cout << res << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> c(n+1);
    c[0] = 3;
    ll ans = 1;
    rep(i, n) {
        if(!c[a[i]]) {
            puts("0");
            return 0;
        }
        ans = ans * c[a[i]] % mod;
        --c[a[i]];
        ++c[a[i]+1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define fi first
#define se second
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 1e6 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7;
int n, idx[N];
string s[N];
pii p[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	for(int i=1; i<=n; i++) 
	{
		cin >> s[i];
		int pre = 0, mn = INF;
		for(int j=0; j<sz(s[i]); j++)
		{
			if(s[i][j]=='(') pre++;
			else pre--;
			if(pre<mn) mn = pre;
		}
		p[i] = {mn, pre};
	}
	iota(idx+1, idx+n+1, 1);
	sort(idx+1, idx+n+1, [](int a, int b) {
		if(p[a].se>=0&&p[b].se>=0) return p[a].fi>p[b].fi;
		else if(p[a].se>=0&&p[b].se<0) return true;
		else if(p[a].se<0&&p[b].se>=0) return false;
		else return mp(p[a].fi-p[a].se,-p[a].se)<mp(p[b].fi-p[b].se,-p[b].se);
	});
	bool ok = 1;
	int pre = 0;
	string res;
	for(int i=1; i<=n; i++) res += s[idx[i]];
	for(int i=0; i<sz(res); i++)
	{
		if(res[i]=='(') pre++;
		else pre--;
		if(pre<0) ok = 0;
	}
	if(pre) ok = 0;
	if(ok) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 48256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int N, M, L[100000], R[100000];
    int mL = 0, mR = 100000;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
      cin >> L[i] >> R[i];
      if (L[i] > mL) mL = L[i];
      if (R[i] < mR) mR = R[i];
    }
    if (mR < mL) cout << 0 << endl;
    else cout << mR - mL + 1 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i < n; i++)
#define ALL(n) begin(n), end(n)

string s;
string ans;

int main()
{
  cin >> s;

  if(s[2] == s[3] && s[4] == s[5]) ans = "Yes";
  else ans = "No";

  cout << ans << endl;
}

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

typedef long long LL;
const int N = 4e3 + 10;
const int Mod = 924844033;
int n, K, ans, tot, g[N], ed[N], fac[N], vis[N][2], f[N][N][2];

inline int mls(int x) {return x < 0 ? x + Mod : x;}
inline int pls(int x) {return x >= Mod ? x - Mod : x;}
template <class T> inline void in(T &x) {
	x = 0; int f = 1; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + ch-'0', ch = getchar();
	x *= f;
}

int main() {
	int x, y;
	in(n), in(K), fac[0] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= 1; ++j) {
			if (vis[i][j]) continue;
			for (x = i, y = j; x <= n; x += K, y ^= 1)
				vis[x][y] = 1, ++tot;
			ed[tot] = 1;
		}
		
	f[1][0][0] = 1;
	for (int i = 1; i <= tot; ++i)
		for (int j = 0; j <= n; ++j) {
			f[i + 1][j][0] = pls(f[i][j][0] + f[i][j][1]);
			if (!ed[i]) f[i + 1][j + 1][1] = f[i][j][0];
		}
	for (int i = 0; i <= n; ++i)
		g[i] = pls(f[tot][i][0] + f[tot][i][1]);
	for (int i = 1; i <= n; ++i) fac[i] = 1LL * fac[i - 1] * i % Mod;
	
	ans = fac[n];
	for (int i = 1; i <= n; ++i)
		if (i & 1) ans = mls(ans - 1LL * fac[n - i] * g[i] % Mod);
		else ans = pls(ans + 1LL * fac[n - i] * g[i] % Mod);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 124672
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
int a[maxn],b[maxn],c[maxn];
ll sum[maxn];
int main()
{
    int n;
    ll ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    for(int i=0;i<n;i++) scanf("%d",&b[i]);
    for(int i=0;i<n;i++) scanf("%d",&c[i]);
    sort(b,b+n);
    sort(c,c+n);
    memset(sum,0,sizeof(sum));
    for(int i=n-1;i>=0;i--)
    {
        int pos=lower_bound(c,c+n,b[i]+1)-c;
        int s=0;
        if(pos>=0&&pos<n) s=n-pos;
        ll ss=(ll)s;
        sum[i]=sum[i+1]+ss;
    }
    for(int i=0;i<n;i++)
    {
        int pos=lower_bound(b,b+n,a[i]+1)-b;
        if(pos>=0&&pos<n) ans+=sum[pos];
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 2176
#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()


def main():
    r, d, x = map(int, input().split())

    for i in range(10):
        x = (r * x) - d
        print(x)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        if self.buffer.tell():
            return self.buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 28780
from datetime import datetime
h1, m1, h2, m2, k = list(map(int, input().split()))
t1 = datetime(2000, 1, 1, h1, m1, 0)
t2 = datetime(2000, 1, 1, h2, m2, 0)
t = (t2 - t1).seconds // 60
ans = t - k
print(ans)

Measured memory_bytes: 9436
import numpy as np
N=int(input())
V=list(map(int, input().split()))
C=list(map(int, input().split()))
V=np.array(V)
C=np.array(C)
X= V-C
Y = [False]*(len(V))
for i in  range(len(V)):
    if X[i] >=0:
        Y[i]=True
    else:
        Y[i]=False

Xnatural = X[np.array(Y)]
print(np.sum(Xnatural))


Measured memory_bytes: 12420
import bisect
a, b, q = map(int, input().split())
s = [int(input()) for _i in range(a)]
t = [int(input()) for _i in range(b)]
s.append(float('inf'))
s.insert(0, -float('inf'))
t.append(float('inf'))
t.insert(0, -float('inf'))
x = [int(input()) for _i in range(q)]

for i in x:
    n = bisect.bisect_right(s, i)
    m = bisect.bisect_right(t, i)
    print(min([abs(max([s[n], t[m]])-i), min([abs(i-s[n-1]), abs(i-t[m])])+abs(s[n-1]-t[m]), min([abs(i-s[n]), abs(i-t[m-1])])+abs(s[n]-t[m-1]), abs(i-min(s[n-1], t[m-1]))]))

Measured memory_bytes: 105304
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 #include<memory>
 
 using namespace std;
 
 
 
 int main()
 {
   int a,b,c;
   while(cin>>a>>b>>c)
   {
     if(a==b) cout<<c<<endl;
     else if(a==c) cout<<b<<endl;
     else cout<<a<<endl;
   } 
   return 0;
 }
 

        

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

int main (){
	int n;
	while(cin>>n && n){
		vector<int> v(n);
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			v[i]=s.size();
		}

		for(int i=0;i<n;i++){
			int count=0;
			int j=i;
			vector<bool> ok(5,false); 
			while(j<=n-1){
				count+=v[j];
				j++;
				if(count==5)ok[0]=true;
				if(ok[0] && count==12)ok[1]=true;
				if(ok[1] && count==17)ok[2]=true;
				if(ok[2] && count==24)ok[3]=true;
				if(ok[3] && count==31)ok[4]=true;
				if(ok[4]){
					cout<<i+1<<endl;
					goto END;
				}
			}
		}
		END:;
	}
}


Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
int n;
ll a[10005],b[10005];
int main(void){
   cin>>n;
   for(int i=0;i<n;i++){
       cin>>a[i];
   }
   for(int i=0;i<n;i++){
       cin>>b[i];
   }
   ll s=0,ap=0,bp=0;
   while(1){
       if(s==n){
           if(ap<=bp)cout<<"Yes\n";
           else cout<<"No\n";
           return 0;
       }
       if(a[s]>b[s]){
          ll e=a[s]-b[s];
          ap+=e;
       }else if(b[s]>a[s]){
           ll e=b[s]-a[s];
           bp+=e/2;
       }
       s++;
   }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    string s;
    cin >> s;
    rep(i, 1<<3){
        int tmp = s[0]-'0';
        rep(j, 3){
            if(i & (1<<j)){
                tmp += s[j+1]-'0';
            }
            else{
                tmp -= (s[j+1]-'0');
            }
        }
        if(tmp == 7){
            rep(j, 3){
                cout << s[j];
                if(i & (1<<j)) cout << '+';
                else cout << '-';
            }
            cout << s[3] << "=7" << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;

int N, M;

Graph G;

// dp[v] := ノード v を始点としたときの、GG の有効パスの長さの最大値
int dp[100100];

int rec(int v) {
    if (dp[v] != -1) return dp[v];

    int res = 0;
    for (auto nv : G[v]) {
        chmax(res, rec(nv) + 1);
    }
    return dp[v] = res;
}

int main()
{
    cin >> N >> M;
    G.assign(N, vector<int>());
    for (int i = 0; i < M; i++) {
        int x, y; cin >> x >> y;
        --x, --y;
        G[x].push_back(y);
    }

    for (int v = 0; v < N; v++) dp[v] = -1;

    int res = 0;
    for (int v = 0; v < N; v++) chmax(res, rec(v));
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 8192
class Combi():
    def __init__(self, N, mod):
        self.power = [1 for _ in range(N+1)]
        self.rev = [1 for _ in range(N+1)]
        self.mod = mod
        for i in range(2, N+1):
            self.power[i] = (self.power[i-1]*i) % self.mod
        self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
        for j in range(N, 0, -1):
            self.rev[j-1] = (self.rev[j]*j) % self.mod

    def C(self, K, R):
        if K < R:
            return 0
        else:
            return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod

    def P(self, K, R):
        if K < R:
            return 0
        else:
            return (self.power[K])*(self.rev[K-R]) % self.mod

mod  = 10**9 + 7
def main():
    # start coding here...
    N = int(input())
    c = Combi(10000,mod)
    ans = 0

    for i in range(10000):
        if N-2*i-1 >= i-1>=0:
            ans +=c.C(N-2*i-1,i-1)
    print(ans%mod)    


if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    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;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Test | diff Test.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Test.cpp && ./a.out

/*
 
 5/5/2020
 
 21:37-
 
 */

const int MAX_N=1e6+1;
int A[MAX_N];
int N;

void solve() {
  /*
  REP(i,N)FORE(j,i+1,N) {
    LL a=accumulate(A+i,A+j,0LL);
    LL b=0;
    FOR(k,i,j) b^=A[k];
    if(a==b) dump(i,j);
  }*/
  LL res=0;
  int cur=0,l=0,r=0;
  while(l<N) {
    while(r<N&&(cur&A[r])==0) {
      cur|=A[r];
      ++r;
    }
    res+=r-l;
    cur^=A[l++];
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


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

using namespace std;


map<string,int>cjt;
int main(){
    int a;
    string s;
    cin>>a;
    for (int i = 0; i < a; i++)
    {
        cin>> s;
        cjt[s]++;
    }
    int maxx;

    for(auto x : cjt){
        int v = x.second;

        if( v > maxx) maxx = v;
    }
    
    for (auto it = cjt.begin(); it != cjt.end(); ++it){
        if(it->second == maxx) cout<<it->first<<"\n";

    }

    
    

    
    
    

    return 0;
}

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

#define ___ ios::sync_with_stdio(0),  cin.tie(0);
#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

int main(){___
  int a[5];
  int ans;
  for (int i = 0; i < 5; ++i){
    cin >> a[i];
    if(a[i]==0){
      ans = i+1;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
def main():
    n, k = map(int, input().split())
    x = [0]*n
    count = 0
    for i in range(k):
        d = int(input())
        a = list(map(int, input().split()))
        for j in a:
            x[j-1] += 1
    for i in x:
        if i == 0:
            count += 1
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9208
import sys

p = [True] * (55000)
p[0] = p[1] = False
for i in range(2, 55000):
    if p[i]:
        for j in range(i * 2, 55000, i):
            p[j] = False

for s in sys.stdin.read().rstrip().split('\n'):
    n = int(s)
    for i in range(n-1, 0, -1):
        if p[i]:
            m1 = i
            break
    for i in range(n+1, len(p)):
        if p[i]:
            m2 = i
            break
    print m1, m2

Measured memory_bytes: 7112
#include <iostream>

using namespace std;

int main()
{
    int n, m;
    int a_sum = 0;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a;
        cin >>  a;
        a_sum += a;
    }
    if (a_sum <= n) {
        cout << n - a_sum << endl;
    }
    else {
        cout << "-1" << endl;
    }
    return 0;
}

Measured memory_bytes: 3160
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int A, B;
	cin >> A >> B;
	if (A == 1) A += 13;
	if (B == 1) B += 13;
	if (A == B) cout << "Draw" << endl;
	else if (A < B) cout << "Bob" << endl;
	else cout << "Alice" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;

typedef vector<int> VI;

int size[13] = {1, 2, 4, 2, 1, 4, 4, 4, 1, 2, 4, 2, 1};
int move[13][4] = {
  {2},
  {2, 5},
  {0, 1, 6, 3},
  {2, 7},
  {5},
  {1, 4, 6, 9},
  {2, 5, 7, 10},
  {3, 6, 8, 11},
  {7},
  {5, 10},
  {6, 9, 11, 12},
  {7, 10},
  {10}
};

VI v;
map<VI, int> mp;
map<VI, int> mp2;

void make(){
  VI goal;
  for(int i = 0 ; i < 13 ; i++){
    if(i == 0 || i == 12) goal.push_back(0);
    else goal.push_back(i);    
  }
  
  queue<VI> que;
  que.push(goal);
  mp2[goal] = 0;
  
  while(!que.empty()){
    VI q = que.front(); que.pop();    
    if(mp2[q] > 12) continue;
    for(int i = 0 ; i < 13 ; i++){
      if(q[i] != 0) continue;
      for(int j = 0 ; j < size[i] ; j++){
	VI t = q;
	swap(t[i], t[ move[i][j] ]);
	if(mp2.find(t) != mp2.end()) continue;	
	mp2[t] = mp2[q] + 1;	
	que.push(t);
      }
    }
  }
}
    


int bfs(){
  queue<VI> que;
  que.push(v);
  mp[v] = 0;  
  while(!que.empty()){
    VI q = que.front(); que.pop();    
    if(mp2.find(q) != mp2.end()){
      return mp2[q] + mp[q];
    }
    
    if(mp[q] > 9) continue;
    for(int i = 0 ; i < 13 ; i++){
      if(q[i] != 0) continue;      
      for(int j = 0 ; j < size[i] ; j++){
	VI t = q;
	swap(t[i], t[ move[i][j] ]);
	if(mp.find(t) != mp.end()) continue;
	mp[t] = mp[q] + 1;
	que.push(t);
      }
    }
  }
  return -1;
}

void init(){
  v.clear();
  mp.clear();  
}

int main(){
  make();
  int n;
  while(cin >> n){
    if(n == -1) break;
    
    init();
    
    v.push_back(n);
    for(int i = 0 ; i < 12 ; i++){ cin >> n; v.push_back(n); }
    
    int ans = bfs();
    if(ans == -1 || ans > 20) cout << "NA" << endl;
    else cout << ans << endl;
  }
  

  return 0;
}

Measured memory_bytes: 15544
d,g=map(int,input().split())
num=[0 for _ in range(d)]
com=[0 for _ in range(d)]
hum=[100*(i+1) for i in range(d)]
ans=10**9+7
for i in range(d):
    num[i],com[i]=map(int,input().split())
for i in range(2**d):
    tmp_get=0
    tmp_ans=0
    for j in range(d):
        if((i>>j)&1):
            tmp_get+=num[-j-1]*hum[-j-1]
            tmp_get+=com[-j-1]
            tmp_ans+=num[-j-1]
    for j in range(d):
        if tmp_get>=g:
            break        
        if not((i>>j)&1):
            tmp_cnt=min(-(-(g-tmp_get)//hum[-j-1]),num[-j-1])
            tmp_ans+=tmp_cnt
            tmp_get+=tmp_cnt*hum[-j-1]
            if tmp_cnt==num[-j-1]:
                tmp_get+=com[-j-1]
    ans=min(ans,tmp_ans)
print(ans)

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

int main(){
	char s[1001];
	while(cin >> s){
		int sum = 0;
		if(s[0]=='0') break;
		for(int i=0; i<strlen(s); i++){
			sum +=s[i]-'0';
		}

		cout << sum << "\n";
	}
}

Measured memory_bytes: 1140
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var a = s.ToCharArray();
        var ans = Min(getAns(a, '1', '0'), getAns(a, '0', '1'));
        Console.WriteLine(ans);
    }
    static int getAns(char[] a , char c1 , char c2)
    {
        var count = 0;
        var aL = a.Length;
        var p = 0;
        while (true)
        {
            if (a[p++] == c1) count++;
            if (p == aL) break;
            if (a[p++] == c2) count++;
            if (p == aL) break;
        }
        return count;
    }
}

Measured memory_bytes: 13176
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N,K;
    cin>>N>>K;
    map<int,int> mp;
    REP(i,N) {
        int a,b;
        cin>>a>>b;
        if(a>K) continue;
        mp[a]+=b;
    }
    map<int,vector<int>> zero;
    FORE(x,mp) {
        REP(i,31) {
            if(!(x.first&(1<<i))) {
                zero[i].push_back(x.first);
            }
        }
    }
    int ans=0;
    FORE(x,mp) {
        int X=x.first;
        bool cont=1;
        REP(i,30) {
            if(!(K&(1<<i))) {
                if(X&(1<<i)) {
                    cont=0;
                    break; 
                }
            }
        }
        if(cont) {
            ans+=x.second;
        }
    }

    int mask=0;
    REPR(i,30) {
        if(K&(1<<i)) {
            int tmp=0;
            FORE(x,zero[i]) {
                if(x&mask) continue;
                tmp+=mp[x];
            }
            chmax(ans,tmp);
        } else {
            mask|=(1<<i);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
vector<int> vec(2000000);
void maxHeapify( int i,int n){
  int l,r,largest;
  l=2*i;
  r=2*i+1;
  if(l<=n && vec[l]>vec[i]){
    largest= l;
  }
  else largest = i;

  if(r<= n && vec[r]> vec[largest]){
    largest =r;
  }

  if(largest != i){
    swap(vec[i],vec[largest]);
    maxHeapify(largest, n);
  }
}

int main(){
  int n;
  cin>> n;
  for(int i=1;i<= n;i++){
    cin>> vec[i];
  }
  for(int i=n/2; i >=1 ; i--){
    maxHeapify(i,n);
  }

  for(int i=1;i<=n;i++){
    cout<<" "<<vec[i];
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 10564
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

struct mint {
    ll v;
    ll mod;
    mint() : v(0) {}
    mint(signed v, ll mod = MOD) : v(v), mod(mod) {}
    mint(ll t, ll mod = MOD) : mod(mod) {
        v = t % mod;
        if (v < 0)
            v += mod;
    }

    mint pow(ll k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }

    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }

    mint inv() { return pow(mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += mod - a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = 1LL * v * a.v % mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(MOD - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};

int main() {
    int n, m;
    cin >> n >> m;
    vi s(n), t(m);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> t[i];
    }
    vector<vector<mint>> dp(n + 1, vector<mint>(m + 1, mint(0)));
    vector<vector<mint>> sum(n + 1, vector<mint>(m + 1, mint(0)));

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = sum[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = 0;
            }
            sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
        }
    }
    cout << sum[n][m].v + 1 << "\n";
    return 0;
}

Measured memory_bytes: 125568
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define db(x) cerr << #x << " is " << x << '\n'
#define FL freopen("in", "r", stdin),freopen("out", "w", stdout);
#define time cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x) double(x * acos(-1) / 180.0)
using namespace std;
typedef unsigned long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e6 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int POW(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1)
            ans *= a;
        a *= a;
        b >>= 1;
    }
    return ans;
}
int main(){
    //FL;
    fin;
    int n, m;
    cin >> n >> m;
    int v[n + 2];
    cls(v, -1);
    bool flag = 1;
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        x--;
        if(v[x] == -1)
            v[x] = y;
        else{
            if(v[x] != y)
                flag = 0;
        }
    }
    if(n == 1 && flag){
        if(v[0] == 0){
            cout << 0 << '\n';
            return 0; 
        }
    }
    if(n == 1 && m == 0){
        cout << 0 << '\n';
        return 0;
    }
    if(flag){
        for(int i = POW(10, n - 1); i <= POW(10, n) - 1; i++){
            string nm = to_string(i);
            
            bool sw = 1;
            fore(j, 0, sz(nm)){
                if(v[j] != -1){
                    if(v[j] != nm[j] - '0'){
                        sw = 0;
                        break;
                    }
                }
            }
            if(sw){
                cout << i << '\n';return 0;
            }
        }
        cout << -1 << '\n';
            
    }else cout << "-1\n";
    time;
    return 0;
}       


Measured memory_bytes: 256
import math
import itertools
import statistics
#import collections
#x = int(input())
k, n = (map(int, input().split()))
#A= (map(int, input().split()))
A =  list(map(int, input().split()))

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

if A[0] > 0:
    if A[0]+(k-A[-1]) >= dif:
       dif =  A[0]+(k-A[-1])

else :
    if k-A[-1] >= dif:
        dif = k-A[-1] 
        dif_index = 0

print(k-dif)




Measured memory_bytes: 28536
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define ld long double
int const M=2e5+10,M2=1e7+10,mod=1e9+7,inf=1e18+10;
int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int x,y;
	cin>>x>>y;
	if(x%y)cout<<x;
	else cout<<-1;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(all(l));
  int tmp = 0;
  rep(i, n - 1) tmp += l[i];
  cout << (tmp > l[n - 1] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#define int_inf 1000000000 //1e9
#define ll_inf  1000000000000000000 //1e18

using namespace std;

int StringToInt(string s){
	int ret=0;	if(s.size()>9||s.size()==0) return 0;
	for(int i=0; i<s.size(); i++)
		if(s[i]<'0' && s[i]>'9') return 0;
	ret=s[0]-'0';
	for(int i=1; i<s.size(); i++){ret*=10; ret+=s[i]-'0';}
	return ret;
}
string ExtString(string s, int begin, int end){ // [beg, end)
	string t;
	for(int i=begin; i<end; i++) t+=s[i];
	return t;
}
int main(){
	string s; cin>>s;
	int y,m,d;
	y=StringToInt(ExtString(s,0,4));
	m=StringToInt(ExtString(s,5,7));
	d=StringToInt(ExtString(s,8,10));
	
	if(y<=2019&&m<=4&&d<=30) cout<<"Heisei"<<endl;
	else cout<<"TBD"<<endl;
	
	
	return 0;
}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n,k=0;
    cin>>n;
    if(n>100||n<1){
        return 0;
    }

    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==n){
                k=1;
                cout<<"Yes"<<endl;
                return 0;
            }
            if(k==1){
                return 0;
            }
        }
    }

        if(k==0){
            cout<<"No"<<endl;
        }
    return 0;
}

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  else return 0;
}

// 文字列から数値へ変換して key を生成する
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ) {
    sum += p*(getChar(str[i])); // p* 1~4
    p *= 5; // 5倍し続ける
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for ( i = 0;; i++ ) {
    h = (h1(key) + i * h2(key)) % M;
    if ( strcmp(H[h], str) == 0 ) return 1; // 比較する
    else if ( strlen(H[h]) == 0 ) return 0; // 長さ
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for ( i = 0; ; i++ ) {
    h = (h1(key) + i * h2(key)) % M;
    if ( strcmp(H[h], str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    scanf("%s %s", com, str); // より高速なscanfを使用

    if ( com[0] == 'i' ) {
      insert(str);
    } else {
      if ( find(str) ) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}



Measured memory_bytes: 17476
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    int n, m;
    cin >> n >> m;
    map<int, vector<int>> v;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }
    priority_queue<int> que;
    LL ans = 0;
    for (int i = 0; i <= m; i++) {
        for (auto x :v[i]) {
            que.push(x);
        }

        if (que.empty()) continue;
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 998244353
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    int N,S; cin>>N>>S;
    vector<int> A(N); rep(i,N)cin>>A[i];
    vector<vector<ll>> dp(N+10,vector<ll>(S+10,0));
    dp[0][0] = 1;
    rep(i,N){
        rep(s,S+1){
            dp[i+1][s] = 2*dp[i][s];
            dp[i+1][s] %= MOD;
            if(A[i]<=s) dp[i+1][s] += dp[i][s-A[i]];
            dp[i+1][s] %= MOD;
        }
    }
    cout<<dp[N][S]<<endl;
}


Measured memory_bytes: 74164
from bisect import *
n, m, k = map(int, input().split())
A, B = [0], [0]
for x in map(int, input().split()): A.append(A[-1]+x)
for x in map(int, input().split()): B.append(B[-1]+x)
ans, j = 0, m
for i in range(n+1):
    if A[i] > k: break
    while A[i] + B[j] > k: j -= 1
    ans = max(ans, i+j)
print(ans)


Measured memory_bytes: 45824