akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<queue>
using namespace std;
typedef long long ll;

inline ll read() {
	char ch = getchar(); ll x = 0; int op = 1;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') op = -1;
	for(; isdigit(ch); ch = getchar()) x = x*10+ch-'0';
	return x*op;
}
inline void write(ll a) {
	if(a < 0) putchar('-'), a = -a;
	if(a >= 10) write(a/10); putchar('0'+a%10);
}

const int N = 100010;
int n, m;
ll fa[N], d[N];

inline int getfa(int x) {
	if(fa[x] == x) return x;
	int tmp = getfa(fa[x]);
	d[x] += d[fa[x]];
	fa[x] = tmp; return tmp;
}
int main() {
	n = read(); m = read();
	for(int i = 1; i <= n; i ++) fa[i] = i, d[i] = 0;
	for(int i = 1; i <= m; i ++) {
		int x = read(), y = read(), z = read(), fx, fy;
		//d[y]-d[x]=z
		fx = getfa(x), fy = getfa(y);
		if(fx != fy) {
			fa[fy] = fx; d[fy] = d[x]+z-d[y];
		} else {
			if(d[y]-d[x] != z) { puts("No"); return 0; }
		}
	} puts("Yes");
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;

//vector<vector<ll>> vec(100000,vector<ll>(3,0));
vector<ll> vec[(ll)2e5];
vector<ll> depth((ll)2e5,INFLONG);
vector<ll> ans((ll)2e5,0);
void dps(ll num,ll dep){
  // cout << num << " " << dep << endl;
  if(depth[num] < dep){return;}
  depth[num] = dep;
  for(auto itr:vec[num]){
    dps(itr,dep+1);
  }
}
void calc(ll num,ll dep,ll pre){
  //cout << depth[num] << " " << dep << endl;
  if(depth[num] != dep){return;}
  ans[num] += pre;
  for(auto itr:vec[num]){
    calc(itr,dep+1,ans[num]);
  }
}

int main(){
  ll n,q;
  ll tmp1,tmp2,tmp;
  cin >> n >> q;
  rep(i,n-1){
    cin >> tmp1 >> tmp2;
    tmp1--;tmp2--;
    vec[tmp1].push_back(tmp2);
    vec[tmp2].push_back(tmp1);
  }
  dps(0,0);
  // rep(i,n){
  //   cout << depth[i] << " ";
  // }
  // cout << endl;
  rep(i,q){
    cin >> tmp1 >> tmp2;
    //calc(tmp1-1,depth[tmp1-1],tmp2);
    ans[tmp1-1] += tmp2;
  }
  calc(0,0,0);
  rep(i,n){
    cout << ans[i] << " ";
  }
}


Measured memory_bytes: 25856
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
vector<vector<int>> perm;
int n, m, q;
void f(int i, int cur, vector<int> acc) {
    if (i == n) {
        perm.push_back(acc);
    } else {
        acc.push_back(cur);
        for (int j = cur; j <= m; j++) {
            f(i + 1, j, acc);
        }
    }
}
int main() {
    cin >> n >> m >> q;
    perm.clear();
    vector<int> as(q), bs(q), cs(q), ds(q);
    rep(i, q) cin >> as[i] >> bs[i] >> cs[i] >> ds[i];

    f(0, 1, vector<int>());

    int64_t maxi = 0;
    for (auto v: perm) {
        int64_t sum = 0;
        rep(i, q) {
            if (v[bs[i] - 1] - v[as[i] - 1] == cs[i]) {
                sum += ds[i];
            }
        }
        maxi = max(maxi, sum);
    }
    cout << maxi << endl;

    // for (auto v: perm) {
    //     for (auto x: v) {
    //         cout << x  << " ";
    //     }
    //     cout << endl;
    // }
}


Measured memory_bytes: 9332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    vector<int> a(3);
    for(int i=0; i<3; i++) cin >> a[i];
    sort(a.begin(), a.end());
    int k; cin >> k;
    for(int i=0; i<k; i++) a[2] *= 2;

    cout << a[0]+a[1]+a[2] << endl;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(): x(0) {}
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

Mod naive[100005];

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n, k; cin >> n >> k;

    for (int i = 1; i <= k; i++) {
        naive[i] = Mod(k / i) ^ n;
    }

    for (int i = k; i >= 1; i--) {
        for (int j = i * 2; j <= k; j += i) {
            // not naive
            naive[i] = naive[i] - naive[j];
        }
    }

    Mod ans = 0;
    // for (int i = 1; i <= k; i++) cout << i << ": " << naive[i].x << endl;
    for (int i = 1; i <= k; i++) ans = ans + naive[i] * i;
    cout << ans.x << endl;
}

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

# 1以外の要素n-1個を、k-1で割る(1項ずつ重複させるため)。余りは1回と数えるので、切り上げる
print(-((-n+1) // (k-1)))

Measured memory_bytes: 52652
dd = [(-1, 0), (0, -1), (1, 0), (0, 1)]
while 1:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    C = [list(input() + "#") for i in range(n)] + ["#"*(m+2)]

    used = [[0]*m for i in range(n)]
    def move(x0, y0, x1, y1, d):
        x = x0; y = y0
        moved = 0; cnt = 0
        history = []
        while x != x1 or y != y1:
            cnt += 1
            rx, ry = dd[d-3]
            dx, dy = dd[d]
            while C[y+dy][x+dx] != '#' and C[y+ry][x+rx] == '#':
                x += dx; y += dy
                history.append([x, y])
                moved = 1
            if C[y+dy][x+dx] == '#' and C[y+ry][x+rx] == '#':
                d = (d - 1) % 4
            elif C[y+ry][x+rx] != '#':
                d = (d + 1) % 4
                x += rx; y += ry
                history.append([x, y])
            if (moved or cnt > 4) and x == x0 and y == y0:
                return 0
        for x, y in history[:-1]:
            C[y][x] = '#'
        return 1
    if move(0, 0, 0, n-1, 3) and move(0, n-1, m-1, n-1, 2) and move(m-1, n-1, m-1, 0, 1) and move(m-1, 0, 0, 0, 0):
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 7840
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		String s;
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();

		for (int i = 3; i <= n; i++) {
			if ((i % 3) == 0) {
				System.out.print(" " + i);
			} else if ((i % 10) == 10) {
				System.out.print(" " + i);
			} else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		}
		System.out.println();

	}

}

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def is_prime(n):
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True


def main():
    X = int(readline())
    while not is_prime(X):
        X += 1
    print(X)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=505;
int mp[MAXN][MAXN],n,m,A,B;
int main()
{
	n=read();m=read();
	A=read();B=read();
	if(!(n%A)&&!(m%B))return puts("No"),0;
//	puts("Yes");
	int d=2000;
	int cnt=n*m*d;
	for(int i=1;i*A<=n;i++)for(int j=1;j*B<=m;j++)
		mp[i*A][j*B]=-(A*B-1)*d-1,cnt-=(A*B-1)*d+d+1;
	if(cnt<=0)return puts("No"),0;
	puts("Yes");
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)pr1(!mp[i][j]?d:mp[i][j]);
		puts("");
	}
	return 0;
}


Measured memory_bytes: 2432
#include<stdio.h>
#include<math.h>

int main(void){
  double n,n1,a,b;
  int c;
  
  scanf("%lf",&n);
  n1 = (double)n / 1.08;
  a = ceil(n1);
  b = floor(n1);
  
  if(a != b){
      if(floor(a * 1.08) == n)
        printf("%d\n",(int)a);
      else if(floor(b * 1.08) == n)
        printf("%d\n",(int)b);
      else
        printf(":(\n");
  }  
  else
    printf("%d\n",(int)n1);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;

const ll MOD = 1e9 + 7;

int main() {
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1, 0);
    vector<int> b(m + 1, 0);
    for(int i = 1; i <= n; i ++)
        cin >> a[i];
    for(int j = 1; j <= m; j ++)
        cin >> b[j];

    vector<vector<ll>> dp(n + 1, vector<ll> (m + 1, 0));
    dp[0][0] = 1;
    for(int i = 1; i <= n; i ++)
        dp[i][0] = 1;
    for(int j = 1; j <= m; j ++)
        dp[0][j] = 1;
    for(int i = 1; i <= n; i ++) {
        for(int j = 1; j <= m; j ++) {
            if(a[i] == b[j])
                dp[i][j] = dp[i - 1][j - 1];
            dp[i][j] = (dp[i][j] + MOD + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % MOD;
        }
    }
    cout << dp[n][m];

    return 0;
}


Measured memory_bytes: 31616
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys

def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    a,b,c,k = _ia()
    r = min(k,a)
    if k > a+b:
        r -= (k-a-b)
    return r

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


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

int main(){
    int n, m, a, b;
    vector<vector<int>> adj;

    cin >> n >> m;
    adj.assign(n+1,vector<int>());
    for(int i=0;i<m;i++){
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    vector<int> visited(n+1,0);
    vector<int> last(n+1,0);
    queue<int> q; 
    int u, cnt=n;

    q.push(1), visited[1] = true;
    
    while(q.size()){
        u = q.front(); q.pop();
        cnt--;
        for(auto v: adj[u]){
            if(!visited[v]){
                visited[v] = visited[u]+1;
                last[v] = u;
                q.push(v);
            }
        }
    }

    if(cnt==0){
        cout << "Yes\n";
        for(int i=2;i<=n;i++){
            cout << last[i] << '\n';
        }
    }
    else{
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 10636
#include <iostream>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len=s.size(),cnt=0;
    for(int i=0;i<len/2;i++)
    {
        if(s[i]!=s[len-1-i])
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<int(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef double ld;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=2005;
int a[N],vis[N],in[N],n;
priority_queue<int> Q;
vi e[N],t[N];

void dfs(int x){
	vis[x]=1;
	sort(e[x].begin(),e[x].end());
	for(auto y:e[x]){
		if(vis[y]) continue;
		dfs(y);
		t[x].pb(y);
		in[y]++;
	}
}

int main(){
	read(n);
	rep(i,1,n) read(a[i]);
	sort(a+1,a+n+1);
	rep(i,1,n) rep(j,i+1,n)
		if(__gcd(a[i],a[j])>=2) e[i].pb(j),e[j].pb(i);
	rep(i,1,n) if(!vis[i]) dfs(i);
	rep(i,1,n) if(!in[i]) Q.push(i);
	while(!Q.empty()){
		int x=Q.top(); Q.pop();
		printf("%d ",a[x]);
		for(auto y:t[x]) if(!(--in[y])) Q.push(y);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 17792
import numpy as np
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)
def rec(start, p):
    if ans[start] != -1:
        return p
    ans[start] = C[p]
    p += 1
    for node in tree[start+1]:
        p = rec(node-1, p)
    return p

N = int(input())
tree = defaultdict(list)
degree = [0 for i in range(N)]
edges = [0 for i in range(N-1)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[i] = (a, b)
    tree[a].append(b)
    tree[b].append(a)
for k, v in tree.items():
    degree[k-1] = len(v)
# print(degree)
sort_i = np.argsort(degree)[::-1]
# max_di = sort_i[-1]
# print(sort_i)
C = list(map(int, input().split()))
C = sorted(C, reverse=True)
# C = list(sorted(zip(sorted(C), list(sort_i)),key=lambda x: x[1]))
# print(C[sort_i])
ans = 0
visited_e = []
# start = max_di + 1
visited = [False for i in range(N)]
p = 0
ans = [-1 for i in range(N)]
M = 0

rec(sort_i[0], p)

for e in edges:
    M += min(ans[e[0]-1], ans[e[1]-1])
    # print(ans)
print(M)
print(' '.join(list(map(lambda x: str(x), ans))))


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

int main(){
    int A,B,C;
    cin >> A >> B;
    if(A+B<A-B){
        C=A-B;
    }
    else{
        C=A+B;
    }
    if(C<A*B){
        C=A*B;
    }
    cout << C << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  
      string a[H+2][W+2];
  	  string b[H][W];
  
  for ( int i = 0 ; i < H+2 ;i++){
	for ( int j = 0; j < W+2 ; j++){
    	a[i][j] = '#';
      }
  }
  
  for ( int i = 0; i < H; i++){
  cin >> b[i][0];
  }
  
      for ( int i = 0 ; i < H ;i++){
	for ( int j = 0; j < W ; j++){
      a[i+1][j+1] = b[i][j];
      }
  }
  
  
   for ( int i = 0 ; i < H+2 ;i++){
	for ( int j = 0; j < W+2 ; j++){
    cout <<	a[i][j];
      }
     cout << endl;
  }
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;
#define split 1000000007
#define N_MAX 2e5
//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

int N;

int main(void){
  cin >> N;
  vector<int> C(N);
  int i,j,pre=-1;
  REP(i,N){
    cin >> C[i];
    if(pre==C[i]){
      i--;
      N--;
    }else{
      pre = C[i];
    }
  }
  vector<ll> dp(N+1,0);
  vector<ll> L(N_MAX,0);
  dp[0] = 1;
  REP(i,N){
    dp[i+1] = (dp[i]+L[C[i]])%split;
    L[C[i]] += dp[i];
  }
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 4096
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  ll A, B, C; cin >> A >> B >> C;

  if (4*A*B < (C-A-B) * (C-A-B) && C - A - B > 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

using i64 = int64_t;

int imos[100000]={0};

void init(){
    for(int i=0;i<100000;++i)imos[i] = 0;
}

int main(){
    int n;
    while(cin >> n, n != 0){
        init();
        for(int i=0;i<n;++i){
            int sh, sm, ss, eh, em, es;
            scanf("%d:%d:%d %d:%d:%d",&sh,&sm,&ss,&eh,&em,&es);
            imos[sh*3600+sm*60+ss]++;
            imos[eh*3600+em*60+es]--;
        }
        int cnt = 0, ans = 0;
        for(int i=0;i<=86399;++i){
            cnt += imos[i];
            ans = max(ans, cnt);
        }
        cout << ans << endl;
    }

    return 0;
}



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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n,x,t;
	scanf("%d %d %d",&n,&x,&t);
	int ans = ((n+(x-1))/x)*t;
	printf("%d\n",ans);
	
	return 0;
};

Measured memory_bytes: 3812
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    double d,t,s;
    cin>>d>>t>>s;
    if(d/s<=t){cout<<"Yes";}
    else{cout<<"No";}

    return 0;
}


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

using namespace std;

#define all(c)	(c).begin(),(c).end()
#define rall(c)	(c).rbegin(),(c).rend()
#define rep(i,N)	for(int i=0;i<N;++i)
#define pb	push_back
#define eb	emplace_back

using ll = long long;

constexpr ll INF = 0x0fffffffffffffff;
constexpr int inf = 0x1fffffff;
constexpr double inf_l = 1e18;
constexpr ll MOD = 1000000007LL;
constexpr int mod = 1000000007;

int main()
{
	string s;
	cin >> s;
	string ans = "";
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'B'&&!ans.empty()) {
			ans.pop_back();
		}
		else if(s[i]!='B')ans.push_back(s[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <queue>
char S[400][400];

typedef struct index {
        int i;
        int j;
}index;

index search(int H,int W){
        index a;
        a.i=H; a.j=W;
        for(int i=0; i<H; i++) {
                for(int j=0; j<W; j++) {
                        if(S[i][j]=='.') {
                                a.i=i; a.j=j;
                                return a;
                        }
                }
        }
        return a;
}

long long pairNum(index a,int H,int W){
        long long black=0,white=0;
        index next;
        std::queue<index> q;
        q.push(a);
        while(!q.empty()) {
                a = q.front();
                q.pop();
                if(S[a.i][a.j]==0) continue;
                if(0<=a.i-1&&S[a.i][a.j]!=S[a.i-1][a.j]&&S[a.i-1][a.j]!=0) {
                        next.i=a.i-1;
                        next.j=a.j;
                        q.push(next);
                }
                if(a.i+1<H&&S[a.i][a.j]!=S[a.i+1][a.j]&&S[a.i+1][a.j]!=0) {
                        next.i=a.i+1;
                        next.j=a.j;
                        q.push(next);
                }
                if(0<=a.j-1&&S[a.i][a.j]!=S[a.i][a.j-1]&&S[a.i][a.j-1]!=0) {
                        next.i=a.i;
                        next.j=a.j-1;
                        q.push(next);
                }
                if(a.j+1<W&&S[a.i][a.j]!=S[a.i][a.j+1]&&S[a.i][a.j+1]!=0) {
                        next.i=a.i;
                        next.j=a.j+1;
                        q.push(next);
                }
                if(S[a.i][a.j]=='.') black++;
                else if(S[a.i][a.j]=='#') white++;
                S[a.i][a.j]=0;
        }
        return black*white;
}

int main(){
        int H,W;
        long long result=0;
        std::cin >> H >> W;
        for(int i=0; i<H; i++)
                std::cin >> S[i];

        index position=search(H,W);
        do {
                result+=pairNum(position,H,W);
                position=search(H,W);
        } while(position.i<H&&position.j<W);

        std::cout <<result;

        return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    string s = to_string(i);
    ll tmp = 0;
    rep(j, s.size()) tmp += ctoi(s.at(j));
    if (a<=tmp && tmp<=b) ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    s = input() # 暗号
    t = input() # 含まれる文字

    s_len = len(s)
    t_len = len(t)
    flg = False

    for i in range(s_len - t_len,-1,-1):
        flg = True
        for j in range(t_len):
            if s[i+j] != t[j] and s[i+j] != "?":
                flg = False
                break
        if flg == True:
            trial = i
            break

    if flg == False:
        print("UNRESTORABLE")
        exit()

    ans = ""
    for i in s[:trial]:
        if i == "?":
            ans = ans + "a"
        else:
            ans = ans + i
    ans = ans + t

    for i in s[(trial+t_len):]:
        if i == "?":
            ans = ans + "a"
        else:
            ans = ans + i

    print(ans)














if __name__=="__main__":
    main()


Measured memory_bytes: 9372
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
//#define int long long
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	string s;
	cin >> s;
	int n = s.size();
	int ng = 0, ok = n;
	while (ok - ng > 1) {
		int mid = (ng + ok) / 2;
		string t = s;
		reverse(all(t));
		t += '0';
		int idx = 0;
		int tmp = mid;
		while (tmp > 0) {
			int d = tmp % 10;
			tmp /= 10;
			int x = idx;
			while (t[x] - '0' + d >= 10) {
				t[x] += d - 10;
				x++; d = 1;
			}
			t[x] += d;
			idx++;
		}
		int cnt = 0, pl = 0;
		bool first = true;
		rep(i, n) {
			if (first && t[i] == '0') continue;
			if (t[i] < t[i + 1]) {
				cnt++;
				first = true;
			}
			else if (t[i] == t[i + 1]) {
				if (first) {
					cnt++;
					first = true;
				}
			}
			else {
				first = false;
			}
		}
		if (cnt < mid) ok = mid;
		else ng = mid;
	}
	cout << ok << '\n';
}

Measured memory_bytes: 1820
#!python
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    P = [int(input()) - 1 for i in range(N)]
    counter = [0 for i in range(N + 1)]

    max_ = 0
    for p in P:
        counter[p] = counter[p - 1] + 1
        if max_ < counter[p]:
            max_ = counter[p]

    print(N - max_)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18884
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Papers, Please
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);

    if (! (ai & 1) && ai % 3 != 0 && ai % 5 != 0) {
      puts("DENIED");
      return 0;
    }
  }

  puts("APPROVED");
  return 0;
}


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

void Z_algo(string &S, vector<int> &v) {
    int N = S.size();
    v = vector<int>(N, 0);
    v[0] = N;
    int i = 1, j = 0;
    while (i < N) {
        while (i+j < N && S[j] == S[i+j]) {
            j++;
        }
        v[i] = j;
        //cout << i << " " << j << endl;
        int k = 1;
        while (i+k < N && k+v[k] < v[i]) {
            v[i+k] = v[k];
            k++;
        }
        i += k;
        j = max(j-k, 0);
    }
    
    return;
}

int main() {
    string s, t;
    cin >> s >> t;
    int N = s.size(), M = t.size();
    
    string u = t;
    u += "$";
    for (int i = 0; i < (2*M+2*N)/N; i++) {
        u += s;
    }
    vector<int> table;
    Z_algo(u, table);
    
    vector<int> pre(N);
    for (int i = 0; i < N; i++) {
        pre[i] = table[M+1+i];
    }
    
    vector<bool> use(N, false);
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (use[i]) continue;
        if (pre[i] == M) {
            continue;
        }
        use[i] = true;
        int j = (i+M)%N;
        while (j != i && pre[j] < M && !use[j]) {
            use[j] = true;
            j += M;
            j %= N;
        }
        if (j == i) continue;
        int cnt = 0;
        while (j != i && pre[j] == M && !use[j]) {
            cnt++;
            use[j] = true;
            j += M;
            j %= N;
        }
        ans = max(ans, cnt);
    }
    if (count(use.begin(), use.end(), true) != N) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 16932
N,M = map(int,input().split())
d = {}
for _ in range(N):
    a,b = map(int,input().split())
    if a in d.keys():
        d[a] += b
    else:
        d[a] = b

count = M
ans = 0
for i in sorted(list(d.keys())):
    if d[i] < count:
        count -= d[i]
        ans += i*d[i]
    else:
        ans += i*count
        break

print(ans)

Measured memory_bytes: 17884
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    x1,y1,x2,y2 = map(int, input().split())
    x3 = y1-y2+x2
    y3 = y2-x1+x2
    x4 = x1+x3-x2
    y4 = y1+y3-y2
    print(x3, y3, x4, y4)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import numpy as np
from copy import deepcopy
ans = 0
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
c = np.array(c)
c = (c == '#') * 1
for i in range(2 ** (h + w)):
    d = deepcopy(c)
    i = bin(i)
    i = "0" * (h + w - len(i) + 2) + i[2:]
    for j in range(h + w):
        if i[j] == "1" and j < h:
            d[j] = 0
        elif i[j] == "1":
            d[:,j - h] = 0
    if np.sum(d) == k:
        ans += 1
print(ans)

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

static const int N = 100;
int p[N+1];
int m[N+1][N+1];

int main(){
    int h;
    cin >> h;
    for(int i = 0; i < h; i++){
        cin >> p[i] >> p[i+1];
    }

    for(int i = 1; i <= h; i++) m[i][i] = 0;

    // lはこれから計算する行列積を成す行列の数2->h(DP)
    for(int l = 2; l <= h; l++){
        // iはこれから計算する行列積の先頭の行列
        for(int i = 1; i <= h-l+1; i++){
            // jはこれから計算する行列積の末尾の行列(これを含む)
            int j = i + l -1;
            m[i][j] = 1<<30;
            for(int k = i; k < j; k++){
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }

    cout << m[1][h] << endl;
    return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
std::string S;
int cnt[10][10];

int manhattan(P p, P q){
    int x1, y1, x2, y2;
    std::tie(x1, y1) = p;
    std::tie(x2, y2) = q;

    return std::abs(x1 - x2) + std::abs(y1 - y2);
}

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

    std::cin >> N >> S;

    for(int i=0;i+1<N;++i){
        cnt[S[i] - '0'][S[i+1] - '0'] += 1;
    }

    std::vector<int> order(9);
    std::iota(order.begin(), order.end(), 1);

    int minCost = 1001001001;
    std::vector<int> eff;

    while(true){
        std::vector<P> ps(10);
        for(int i=0;i<9;++i){
            ps[order[i]] = std::make_tuple(i / 3, i % 3);
        }

        int cost = 0;
        for(int i=1;i<=9;++i){
            for(int j=1;j<=9;++j){
                cost += manhattan(ps[i], ps[j]) * cnt[i][j];
            }
        }

        if(cost < minCost){
            minCost = cost;
            eff = order;
        }

        unless(std::next_permutation(order.begin(), order.end())){
            break;
        }
    }

    for(int i=0;i<3;++i){
        for(int j=0;j<3;++j){
            std::cout << eff[i * 3 + j];
        }
        std::cout << std::endl;
    }
}



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

int main(void)
{
    int n, c[52] = {0};
    
    cin >> n;
    for (int i = 0; i < n; ++i) {
        char a;
        int b;
        cin >> a >> b;
        switch (a) {
            case 'S':
                c[b - 1] = 1;
                break;
            case 'H':
                c[b + 13 - 1] = 1;
                break;
            case 'C':
                c[b + 26 - 1] = 1;
                break;
            case 'D':
                c[b + 39 - 1] = 1;
                break;
        }
    }
    
    for (int i = 0; i < 52; ++i) {
        if (i < 13 && c[i] == 0)
            cout << "S " << i + 1 << endl;
        else if (i < 26 && c[i] == 0)
            cout << "H " << i - 13 + 1 << endl;
        else if (i < 39 && c[i] == 0)
            cout << "C " << i - 26 + 1 << endl;
        else if (c[i] == 0)
            cout << "D " << i - 39 + 1 << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3112
def main():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    dp=[False]*(k+1)
    for j in range(1,k+1):
      for i in a:
        if 0<=j-i and dp[j-i]==False:
          dp[j]=True
    if dp[k]:
      print('First')
    else:
      print('Second')
main()

Measured memory_bytes: 39920
#include <bits/stdc++.h>
#include <functional>
#include <iostream>
#define  pb push_back
#define  xx first
#define  yy second
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;
char a[1001][1001];
 int main(){

    string s,t,u;
     cin >> s;
     for(int i = 0; i<s.size(); i++) cout << "x";
     cout << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>


int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > A(N);
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  std::sort(A.rbegin(), A.rend());
  long long ans = 0;
  ans += 0;
  ans += A[0];
  int index = 2;
  std::priority_queue<int > queue;
  queue.push(A[1]);
  queue.push(A[1]);
  while (index<N){
    int fp = queue.top();
    queue.pop();
    queue.push(A[index]);
    queue.push(A[index]);
    ans += (long long)fp;
    index++;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 4696
#include<bits/stdc++.h>
#define MaxN 100000+100
int a[MaxN];
void swap(int q,int b)
{
	int c=a[q];
	a[q]=a[b];
	a[b]=c;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int sum=0;
	for(int i=1,next=i;i<=n;i=next+1,next=i)
	{
		if(a[i]==i)
		{
		//	printf("%d\n",i);
			while(next+1<=n && a[next+1]==next+1)
				next++;
			sum+=(next-i+1)/2+((next-i+1)%2);
		}	
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 640
import Control.Monad
import Data.List

rmNeg _ [] = []
rmNeg 0 vs = vs
rmNeg k (v:vs) = if v>0 then (v:vs) else rmNeg (k-1) vs


main :: IO ()
main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]
  vs <- map read . words <$> getLine :: IO [Int]

  let ans = maximum [sum . rmNeg (k-l-r) . sort $ take l vs ++ take r (reverse vs) | l<-[0..n], r<-[0..n], l+r<=n, l+r<=k]

  print $ max 0 ans
  


Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<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;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int H,N; cin >> H >> N;
    int sum=0;
    rep(i,N){
        int a; cin >> a;
        sum+=a;
    }
    if(sum>=H) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>

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

using namespace std;

int n,m[20];
int memo[20][(1<<13)+1];	// memo[player][stone] : whether team 1 win in a condition [player][stone]

bool solve1(int player,int stone);
bool solve2(int player,int stone);

// return true if team 1 win
bool solve1(int player,int stone){
	int &ans=memo[player][stone];
	if(~ans)		return ans;
	if(stone==0)	return ans=1;

	int nextplayer=(player+1)%(2*n);
	for(int i=1;i<=m[player];i++){
		if(stone-i<0)	break;
		if(!solve2(nextplayer,stone-i))	return ans=1;
	}
	return ans=0;
}

// return true if team 2 win
bool solve2(int player,int stone){
	int &ans=memo[player][stone];
	if(~ans)		return ans;
	if(stone==0)	return ans=1;

	int nextplayer=(player+1)%(2*n);
	for(int i=1;i<=m[player];i++){
		if(stone-i<0)	break;
		if(!solve1(nextplayer,stone-i))	return ans=1;
	}
	return ans=0;
}

int main(){
	for(int s;scanf("%d%d",&n,&s),n;){
		rep(i,2*n){
			scanf("%d",m+i);
			rep(j,s+1)	memo[i][j]=-1;
		}
		printf("%d\n",solve1(0,s));
	}
	return 0;
}

Measured memory_bytes: 0
List=list(map(int,input().split()))
cnt=0
while(all(i%2==0 for i in List)):
    if List[0]==List[1]==List[2]:
        print(-1)
        exit()
    old_list=[List[0]//2,List[1]//2,List[2]//2]
    List[0]=old_list[1]+old_list[2]
    List[1]=old_list[0]+old_list[2]
    List[2]=old_list[0]+old_list[1]
    cnt+=1
print(cnt)

Measured memory_bytes: 9148
n = int(input())
luk = input()

keys = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
a = 0
for key in keys:
  s = 0
  for st in luk:
    if st == key[s]:
      s += 1
    if s == 3:
      a += 1
      s = 0
      break
print(a)

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

int main(void){
  int n, i, cnt, lpos, rpos, tmp;
  string move;
  while(1){
    cin >> n;
    if(n == 0) break;
    lpos = 0;
    rpos = 0;
    cnt = 0;
    tmp = 0;
    for(i=0;i<n;i++){
      cin >> move;
      if(move == "lu") lpos = 1;
      if(move == "ld") lpos = 0;
      if(move == "ru") rpos = 1;
      if(move == "rd") rpos = 0;
      if(lpos == 1 && rpos == 1 && tmp == 0){
        cnt++;
        tmp = 1;
      }
      if(lpos == 0 && rpos == 0 && tmp == 1){
        cnt++;
        tmp = 0;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
priority_queue<pair<ll,int> > q;
vector<int> g[maxn],w[maxn];
bool vis[maxn];
ll d[maxn];
int main()
{
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++)d[i] = 1LL<<60;
	for(int i=1;i<=m;i++){
		int l,r,c;scanf("%d%d%d",&l,&r,&c);
		g[l].pb(r);
		w[l].pb(c);
	}
	for(int i=2;i<=n;i++){
		g[i].pb(i-1);
		w[i].pb(0);
	}
	d[1] = 0;
	q.push(mp(0,1));
	while(!q.empty()){
		int x = q.top().second;q.pop();
		if(vis[x])continue;
		for(int i=0;i<g[x].size();i++){
			int y = g[x][i];
			if(d[y]>d[x]+w[x][i]){
				d[y] = d[x] + w[x][i];
				q.push(mp(-d[y],y));
			}
		}
	}
	if(d[n]==1LL<<60)cout<<-1<<endl;
	else cout << d[n] << endl;
}


Measured memory_bytes: 17660
import numpy as np
from sys import stdin


def get_result(data):
    N = data[0]
    ans = []
    for i in range(N):
        val = i + 1
        _, q_3 = divmod(val, 3)
        _, q_5 = divmod(val, 5)
        if q_3 != 0 and q_5 != 0:
            ans.append(val)
    ans = np.array(ans)
    return sum(ans[ans <= N])


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)


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



bool IsTruth(int y){
    if(y==1) return true;
    return false;
}

int main(){
    int n;
    cin>>n;
    vector<bool> honest(n);
    vector<int> a(n);
    vector<vector<int>> x(n),y(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        x[i].resize(a[i]);
        y[i].resize(a[i]);
        for(int j=0;j<a[i];j++){
            cin>>x[i][j]>>y[i][j];
            x[i][j]--;
        }
    }
    //計算
    int max=0;
    for(int bit=0;bit<(1<<n);bit++){
        int cnt=0;
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                honest[i]=true;
                cnt++;
            }
            else honest[i]=false;
        }
        //矛盾チェック
        for(int i=0;i<n;i++){
            if(honest[i]){
                for(int j=0;j<a[i];j++){
                    if(IsTruth(y[i][j])){
                        if(!honest[x[i][j]]) cnt=0; //矛盾
                    }else{
                        if(honest[x[i][j]]) cnt=0;
                    }
                }
            }
        }
        if(max<cnt) max=cnt;
    }
    cout<<max<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        string s;
        cin >> n >> s;
        if(n == 0)
            return 0;

        int len = s.size();
        int ret = INT_MIN;
        int cut;
        bool rejected;
        for(int i=0; i<(1<<(len-1)); ++i){
            bitset<5> bs(i);
            int a = s[0] - '0';
            int b = 0;
            for(int j=0; j<len-1; ++j){
                if(bs[j]){
                    b += a;
                    a = 0;
                }
                a *= 10;
                a += s[j+1] - '0';
            }
            b += a;

            if(b <= n){
                if(b > ret){
                    ret = b;
                    cut = i;
                    rejected = false;
                }else if(b == ret){
                    rejected = true;
                }
            }
        }

        if(ret == INT_MIN){
            cout << "error" << endl;
        }else if(rejected){
            cout << "rejected" << endl;
        }else{
            cout << ret << ' ';
            bitset<5> bs(cut);
            for(int i=0; i<len-1; ++i){
                cout << s[i];
                if(bs[i])
                    cout << ' ';
            }
            cout << s[len-1] << endl;
        }
    }
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
 
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))
 
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  float h,a;
  cin>>h>>a;
  cout<<ceil(h/a);
  
  return 0;
}

Measured memory_bytes: 256
mod = 10 ** 9 + 7
n, k = map(int, input().split())

a = [1] * (k+1)
b = [ i for i in range(k+1) ]
a[0] = 0
b[0] = 0

for i in range(k//2,0,-1):
  cnt = pow( k // i , n, mod )
  for j in range(i*2,k+1,i):
    # if i == 2:
    #   print(a[j]) 
    cnt = ( cnt - a[j] ) % mod
  a[i] = cnt
  b[i] = i * cnt % mod

# print(a)
# print(b)

ans = 0
for i in range(1,k+1):
  ans = (ans + b[i]) % mod

print(ans)

Measured memory_bytes: 74640
#include<stdio.h>

int main(){
    int N,K,count=0;
    scanf("%d %d ",&N,&K);
    int h[N],a[K],b[K],q[N];
    for(int i=0;i<N;i++){
        scanf("%d ",&h[i]);
        q[i]=0;
    }
    for(int i=0;i<K;i++){
        scanf("%d %d ",&a[i],&b[i]);
    }
    for(int i=0;i<K;i++){
        if(h[a[i]-1] <= h[b[i]-1]){
            q[a[i]-1]+=1;
        }
        if(h[b[i]-1] <=h[a[i]-1]){
            q[b[i]-1]+=1;
        }
    }
    for(int i=0;i<N;i++){
        if(q[i]==0) count+=1;
    }
    printf("%d",count);
    
    return 0;
}

Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	int max = std::max(A, std::max(B, C));
	int min = std::min(A, std::min(B, C));
	int mid = A + B + C - max - min;

	int ans = max - mid;
	ans += (mid - min) / 2;
	if ((mid - min) % 2 == 1)
	{
		ans += 2;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string s;
    int n;
    cin >> s >> n;

    deque<char> deq;
    for(auto c : s){
        deq.push_back(c);
    }
    
    int on = 0;
    rep(i, n){
        int t;
        cin >> t;
        if(t == 1){
            on ^= 1;
        }
        else{
            int f; 
            char c;
            cin >> f >> c;
            if(on ^ (f == 1)){
                deq.push_front(c);
            }
            else{
                deq.push_back(c);
            }
        }
    }

    string ans;
    for(auto d : deq){
        ans.push_back(d);
    }
    if(on){
        reverse(all(ans));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1368
N, M = gets.chomp.split(" ").map(&:to_i);
P = []
A = gets.chomp.split(" ").map(&:to_i);
A.each{|i| P << [1, i]}
M.times{|i|
  P << gets.chomp.split(" ").map(&:to_i);
}

cnt = N
s = 0
P.sort_by{|p| p[1]}.reverse.each{|i|
  b, c = i
  if cnt > b then
    s += b * c
    cnt -= b
  else
    s += cnt * c
    break
  end
}

puts s


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

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

int main() {
    int n;
    cin >> n;
    vector<int> arr(n);
    rep(i, n) cin >> arr[i];

    int ans = 0;
    bool div_by_2 = true;
    while(div_by_2){
        rep(i, n) {
            if (arr[i] % 2 == 1) {
                div_by_2 = false;
                break;
            } else {
                arr[i] /= 2;
            }
        }
        if(div_by_2) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var first = int.Parse(S[0].ToString() + S[1].ToString());
            var second = int.Parse(S[2].ToString() + S[3].ToString());

            if ((0 < first && first < 13 )&&( 0 < second && second < 13))
            {
                Console.WriteLine("AMBIGUOUS");
                return;
            }
            if ((0 >= first || first >= 13 )&& (0 >= second || second >= 13))
            {
                Console.WriteLine("NA");
                return;
            }
            if (0 < first && first < 13)
            {
                Console.WriteLine("MMYY");
                return;
            }
            Console.WriteLine("YYMM");
        }
    }
}


Measured memory_bytes: 13140