akhauriyash/Code-Regression huggingface dataset:
# Problem https://atcoder.jp/contests/abc082/tasks/abc082_a
# Python 1st Try


def orginalCeil(a, b):
    c = (a + b + 1) // 2
    return c


if __name__ == "__main__":
    a, b = map(int, input().split(' '))
    answer = orginalCeil(a, b)
    print(answer)
exit

Measured memory_bytes: 2940
import sys
from collections import defaultdict
    
sys.setrecursionlimit(10**9)
    
n, m = map(int, input().split())
adj = defaultdict(list)
radj = defaultdict(list)

for i in range(m):
    s, e = map(int, input().split())
    adj[s].append(e)
    
dp = [-1]*(n+1)

def dfs(e):
    if dp[e] != -1:
        return dp[e]
    
    temp = 0
    for i in adj[e]:
        temp = max(temp, 1+dfs(i))
        
    dp[e] = temp
    return temp
    
    
for i in range(1, n+1):
    dfs(i)
    
print(max(dp))

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second


int main(){
    ll a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    
    ll memo1 = (f/100/a)*a*100,memo2 = 0;
    double memo3 = 0.0;
    rep(i,0,31){
        rep(j,0,31){
            rep(k,0,3001){
                rep(l,0,3001){
                    if(i+j+k+l == 0) continue;
                    if(100*(a*i+b*j)+c*k+d*l > f) break;
                    if((a*i+b*j)*e < c*k+d*l) break;

                    if(100.0*(double)(c*k+d*l)/(100.0*(a*i+b*j)+c*k+d*l) > memo3){
                        memo3 = 100.0*(double)(c*k+d*l)/(100.0*(a*i+b*j)+c*k+d*l);
                        memo1 = 100*(a*i+b*j);
                        memo2 = c*k+d*l;
                    }
                }
            }
        }
    }
    cout << memo1+memo2 << " " << memo2 << endl;
    return 0;
}


Measured memory_bytes: 3588
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 20005;
const int K = 50;
vector < int > g[N];
double b[N], a[N], dp[N];
int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
int solve1(int hb, int r, int c){
    int b = c;
    int res = 0;
    for (int i = hb - 1; i >= 0; i--){
        if ((1LL << i) & r){
            res = (res + binpow(2, b) * binpow(3, i)) % mod;
            b++;
        }
    }
    res = (res + binpow(2, b)) % mod;
    return res;
}
int solve2(int hb, int l){
    int b = 0;
    int res = 0;
    for (int i = hb - 1; i >= 0; i--){
        if (!((1LL << i) & l)){
            res = (res + binpow(2, b) * binpow(3, i)) % mod;
            b++;
        }
    }
    res = (res + binpow(2, b)) % mod;
    return res;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int l, r;
    cin >> l >> r;
    int res = 0;
    if (l == r){
        cout << 1;
        return 0;
    }
    int hbl, hbr;
    for (int i = 60; i >= 0; i--){
        if ((1LL << i) & r){
            hbr = i;
            break;
        }
    }
    for (int i = 60; i >= 0; i--){
        if ((1LL << i) & l){
            hbl = i;
            break;
        }
    }
    int ans = 0;
    int k1 = 0;
    int k2 = 0;
    int f = 1;
    int q = 1;
    if (hbr == hbl){
        for (int i = 60; i >= 0; i--){
            int b1 = ((1LL << i) & r);
            int b2 = ((1LL << i) & l);
            if (b1 != b2){
                if (b1 < b2){
                    cout << ans;
                    return 0;
                }
                ans = (ans + solve1(i, r - k1, 0) + solve2(i, l - k2)) % mod;
            }
            k1 = k1 + b1;
            k2 = k2 + b2;

        }
        cout << (ans + 1) % mod;
        return 0;
    }
    ans = solve1(hbr, r, 0);
    //cout << ans << endl;
    ans = (ans + solve2(hbl, l)) % mod;
   // cout << ans << " " << hbl << " " << hbr << " " << ((1 << 7) & r) << endl;
    for (int i = hbl + 1; i < hbr; i++){
        ans = (ans + binpow(3, i)) % mod;
    }
    cout << ans;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[]a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();
		int[]color = new int[N + 1];
		int k = a[0] - 1;
		color[1] = 1;
		int cnt = 1;
		for(int i = 0; i < N; i++) {
			if(k == 1) {
				System.out.println(cnt);
				System.exit(0);
			}else {
				cnt++;
				k = a[k] - 1;
			}
		}
		System.out.println(-1);
	}
}

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

#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N = 1000 * 1000 + 1, MOD = 998244353;

int fp(int a, int p) {
    ll ans = 1, c = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = ans * c % MOD;
        c = c * c % MOD;
    }   
    return ans;
}   

int inv[N];
vector <int> d[N];
int cnt[N], dp[N];
ll sum[N];
int solve(int x) {
    ll ans = 0;
    for (int y : d[x]) {
        dp[y] = sum[y];
        for (int add : d[x/y]) {
            if (add != 1) {
                dp[y] -= dp[y * add];
                if (dp[y] < 0)
                    dp[y] += MOD;
            }   
        }   
        ans = (ans + (ll)dp[y] * inv[y]) % MOD;
    }   
    return (ans * x) % MOD;
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    for (int i = 0; i < N; ++i)
        inv[i] = fp(i, MOD - 2);
    for (int i = 1; i < N; ++i)
        for (int j = i; j < N; j += i)
            d[j].app(i);
    for (int i = 0; i < N; ++i)
        reverse(all(d[i]));

    #ifdef HOME
    cout << Time << endl;
    #endif

    int n;
    cin >> n;
    while (n--) {
        int x;
        cin >> x;
        ++cnt[x];
    }   
    for (int i = 1; i < N; ++i) {
        for (int j = i; j < N; j += i)
            sum[i] += (ll)cnt[j] * j;
        sum[i] %= MOD;
    }
    ll ans = 0;
    for (int i = 1; i < N; ++i)
        if (cnt[i]) {
            ll add = solve(i) - i;
            if (add < 0)
                add += MOD;
            ans += add * cnt[i];
            ans %= MOD;
        }   
    cout << (ans * inv[2]) % MOD << endl;            

    #ifdef HOME
    cout << Time << endl;
    #endif
}

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

int main(){



   int a[100005];
   int n, k, i;
   cin >> n >> k;
   for(i = 0; i < n; i++)
    cin >> a[i];
   int res = 0;
   for(i = 0; i < n; i++)
   {
       if(a[i] >= k)
       {
           res ++;
       }
   }
   cout << res;
  return 0;
}

Measured memory_bytes: 640
def set_matrix (num,matrix):
    for i in xrange(num):
        x = map(int,raw_input().split(" "))
        matrix.append(x)

n,m,l = map(int, raw_input().split())

a = []
b = []
set_matrix(n,a)
set_matrix(m,b)

b_t = list(map(list,zip(*b)))

for i in xrange(n):

    result = []
    for j in xrange(l):
        result.append( sum([x*y for x,y in zip(a[i], b_t[j]) ]))
    print " ".join(map(str,result))

Measured memory_bytes: 7192
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int a[10];
	int v1,v2;
	while(scanf("%d",a)!=EOF){
		for(int i=1;i<10;i++){
			scanf(",%d",&a[i]);
			a[i] += a[i-1];
		}
		scanf(",%d,%d\n",&v1,&v2);
		int ans;
		for(int i=9;i>=0;i--){
			if(v1*a[9] <= a[i]*(v1+v2))ans=i;
		}
		cout<<ans+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
vector<long long> vec;
int main(){
	string s;
	cin >> s;
	int co = 1;
	for (int i = 0; i < s.size(); i++) {
		if (i == s.size() - 1 || s[i] != s[i + 1]) {
			vec.emplace_back(co);
			co = 1;
		}
		else {
			co++;
		}
	}
	vec.emplace_back(0);
	long long ans = 0;
	if (s[0] == '>') {
		ans += vec[0] * (vec[0] + 1) / 2;
		vec.erase(vec.begin());
	}
	for (int j = 1; j < vec.size(); j += 2) {
		long long a = max(vec[j], vec[j - 1]);
		long long b = min(vec[j], vec[j - 1]);
		ans += a * (a + 1) / 2;
		ans += (b - 1) * b / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3068
#include <stdio.h>

int main(){
  int x,y,k,i,j;

  scanf("%d%d",&x,&y);

  if(x > y){
    i = x;
    j = y;
  }
  else {
    i = y;
    j = x;
  }

  while(j != 0){
    k = j;
    j = i%j;
    i = k;
  }

  printf("%d\n",i);

  return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
int main()
{
  int i,j,k,n,x,y;
  char str[1000];
  char rev[1000];
  char command[10];
  int length;
 
  i=0;
  while(1)
    {
      scanf("%c",&str[i]);
      if(str[i]=='\n') break;
      i++;
    }
  length=i;
 
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      j=0;
      while(1)
    {
      scanf("%c",&command[j]);
      if((j==0)&&(command[j]=='\n')) j--;
      if(command[j]==' ') break;
      j++;
    }
      switch(command[2])
    {
    case 'p':
      scanf("%d %d ",&x,&y);
      for(j=x;j<=y;j++) scanf("%c",&str[j]);
      break;
    case 'v':
      scanf("%d %d",&x,&y);
      for(j=x;j<=y;j++) rev[j]=str[j];
      for(j=x;j<=y;j++) str[j]=rev[x+y-j];
      break;
    case 'i':
      scanf("%d %d",&x,&y);
      for(j=x;j<=y;j++) printf("%c",str[j]);
      printf("\n");
    }
    }
  return 0;
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair <int,int> PAIR;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
int p[maxn];

int main()
{	
	int n,x;
	ll ans = 0;
	scanf("%d",&n);
	memset(p,0,sizeof(p));
	for(int i = 1;i <= n;++i){
		scanf("%d",&x);
		ans += x;
		p[x]++;
	}
	
	int q,u,v;
	scanf("%d",&q);
	while(q--){
		scanf("%d%d",&u,&v);
		if(!p[u]) printf("%lld\n",ans);
		else{
			ans -= (ll)p[u]*(ll)u;
			ans += (ll)p[u]*(ll)v;
			p[v] += p[u];
			p[u] = 0;
			printf("%lld\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 4200
#include <iostream>
#include <math.h>

int main() {

    int N;
    std::cin >> N;

    unsigned long int power = 1;
    for (int i = 0; i < N; i++) {
        power *= i + 1;
        power %= ((1000000000 + 7));
    }

    std::cout << power;
    return 0;
}




Measured memory_bytes: 256
'''
以下解説を参考に回答
https://qiita.com/drken/items/dc53c683d6de8aeacf5a
'''

N = int(input())
H = list(map(int, input().split()))

# DPテーブル
dp = [10 ** 9] * N

# 初期条件
dp[0] = 0
dp[1] = abs(H[1] - H[0])

# ループ
for i in range(1, N):
    dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]))

# 解を出力
print(dp[N - 1])

Measured memory_bytes: 13976
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=2e5+1;
const ll INF=4e18;
void solve()
{
	string s;
	cin>>s;
	ll N=s.length()-1;
	ll h=0;
	for(ll i=0,l=N;i<l;i++,l--)
	{
		if(s[i]!=s[l]) h++;
	}
	cout<<h<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=0;
	//cin>>T;
	do
	{
		solve();
		p++;
	}while(p<T);
	return 0;
}



Measured memory_bytes: 256
/*input
7 11
1 2 2
1 3 1
2 4 2
2 5 2
2 6 1
3 4 1
3 5 1
3 6 1
4 7 2
5 7 2
6 7 1
*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 1505
#define bit(x,y) ((x>>y)&1LL)

int n, m;
vector<vector<pair<int, int> > > a(N);
int dis[N][N];

bool inqueue[N];
deque<int> q;
int mxans = 0;
int mx[N];
int suminQueue = 0;
void SPFA(int root) {
#define f dis[root]
	f[root] = 0;
	q.push_back(root); inqueue[root] = true;
	while (!q.empty()) {
		while (f[q.front()]*q.size() > suminQueue) {
			q.push_back(q.front());
			q.pop_front();
		}
		int u = q.front(); q.pop_front(); inqueue[u] = false; suminQueue -= f[u];
		for (auto v : a[u]) {
			if (f[v.fi] > f[u] + v.se) {
				f[v.fi] = f[u] + v.se;
				if (!inqueue[v.fi]) {
					inqueue[v.fi] = true;
					if (!q.empty() && f[v.fi] < f[q.front()]) {
						q.push_front(v.fi);
					}
					else q.push_back(v.fi);
					suminQueue += f[v.fi];
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) mxans = max(mxans, dis[root][i]);
}

bool visited[N]; bool mark[N];
void dfs(int u, int root) {
	if (visited[u]) return;
	visited[u] = true;
	mx[u] = dis[root][u];
	for (auto v : a[u]) {
		if (dis[root][v.fi] == dis[root][u] + v.se) {
			dfs(v.fi, root); mx[u] = max(mx[u], mx[v.fi]);
		}
	}
	if (mx[u] == mxans)
		mark[u] = 1;
}

vector<int> order;
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef in1code
	freopen("1test.inp", "r", stdin);
#endif
	memset(dis, 127, sizeof(dis));
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int u, v, c;
		cin >> u >> v >> c;
		a[u].push_back(mp(v, c));
		a[v].push_back(mp(u, c));
	}
	for (int i = 1; i <= n; i++) SPFA(i);
	for (int i = 1; i <= n; i++) {
		memset(visited, 0, sizeof(visited)); dfs(i, i);
	}
	for (int i = 1; i <= n; i++) {
		if (!mark[i]) order.push_back(i);
	}
	cout << order.size() << endl;
	for (auto it : order) cout << it << endl;
}


Measured memory_bytes: 21120
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    long long N, K, R, S, P, i, i2, count, ans=0, Rdec=0, Sdec=0, Pdec=0, check[1000000];
    char T[1000000], U;

    cin >> N >> K >> R >> S >> P >> T;

    for(i=0; i<N; i++){
        check[i] = 0;
    }

    for(i=0; i<N; i++){
        i2 = i;

        if(T[i] == T[i+K]){
            count = 0;

            while(i+K < N && T[i] == T[i+K] && check[i] == 0){
                U = T[i];

                check[i] = 1;

                i += K;

                count++;
            }

            if(count % 2 == 0){
                if(U == 'r'){
                    ans -= P*count/2;
                }
                else if(U == 's'){
                    ans -= R*count/2;
                }
                else{
                    ans -= S*count/2;
                }
            }
            else{
                if(U == 'r'){
                    ans -= P*(count/2+1);
                }
                else if(U == 's'){
                    ans -= R*(count/2+1);
                }
                else{
                    ans -= S*(count/2+1);
                }
            }
        }

        i = i2;
    }

    for(i=0; i<N; i++){
        if(T[i] == 'r'){
            ans += P;
        }

        else if(T[i] == 's'){
            ans += R;
        }

        else{
            ans += S;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4864
P,L="+<"
p=print
r=range
p(6652,P,0,1,3,L,2,3,3)
for x in 0,1:p(P,x,3,x);[p(P,v:=x+4,v,v,P,v,3,6,*[P,6,6,6]*(38-t),L,6,x,T:=x*60+t,P,v,T,v)for t in r(9,60)]
for t in r(60):p(P,2,2,2);[p(P,8+t-s,69+s,6,L,3,6,6,P,2,6,2)for s in r(t)]

Measured memory_bytes: 9348
#include<bits/stdc++.h>
#define MAX 105
using namespace std;
 
int main(){
  int n, t, a[MAX], b = 0, c, k;
  scanf("%d%d", &n, &t);
  for(int i = 0; i < n; i++){
    scanf("%d%d", &c, &k);
    if(k <= t) a[b++] = c;
  }
  if(b == 0) printf("TLE\n");
  else{
    sort(a, a+b);
    printf("%d\n", a[0]);
  }
}


Measured memory_bytes: 256
import math
ans = 0
K = int(input())
keta = math.floor(math.log10(K)) + 1
for i in range(1,keta+1):
    if i!= keta:
        if i%2:#桁数が奇数
            ans += 10**i - 10**(i-1)
    if i==keta:
        if i%2:
            ans += K - 10**(keta-1) + 1
print(ans)

Measured memory_bytes: 3060
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	int n = kbd.nextInt();
	while(n>0){
	    solve();
	    n--;
	}
    }

    static void solve(){
	int[] r = {0, 0};
	int[] max = {0, 0};
	int maxd = 0;


	int x = kbd.nextInt();
	int y = kbd.nextInt();
	int d = 0;
	while(! (x==0 && y==0)){
	    r[0] += x;
	    r[1] += y;
	    d = r[0]*r[0] + r[1]*r[1];
	    //System.out.println(max[0]+" "+max[1]);
	    if(d > maxd){
		maxd = d;
		max[0] = r[0];
		max[1] = r[1];
	    }
	    else if(d==maxd && r[0]>max[0]){
		maxd = d;
		max[0] = r[0];
		max[1] = r[1];
	    }
	    x = kbd.nextInt();
	    y = kbd.nextInt();
	}

	System.out.println(max[0]+" "+max[1]);
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n;
ll x[55],y[55];

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

  cin>>n;
  rep(i,n)cin>>x[i]>>y[i];

  if(n==1){
    cout<<1<<endl;
    return 0;
  }

  ll res=INF;
  rep(i,n)rep(j,n){
    if(i==j)continue;
    ll p=x[j]-x[i];
    ll q=y[j]-y[i];
    ll sum=n;
    rep(k,n)repl(l,k+1,n){
      if((x[k]-x[l]==p&&y[k]-y[l]==q)||(x[l]-x[k]==p&&y[l]-y[k]==q))sum--;
    }
    minch(res,sum);
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i< (n); ++i)
const int INF = 1001001001;

/*
 *  桁数が大きいほど大きい数になるので、桁数を大きくしたいが
 *  N本使うという制約があるため、貪欲法ではできない。
 *  ➡　動的計画法を使う(i <= i-1 のような一つずつの遷移とか限らない事に注意したい)
 *
 *  dp[ i ] := マッチ棒を i 本使って作れる数値の最大値
    とする。これに対し、各 a = A1,A2,…,AM に対して、
    chmax(dp[ i + match[ a ] ], dp[ i ] の末尾に "a" を加えたもの)
    という感じの遷移を実施すれば OK。match[ a ] は a を作るのに必要なマッチ棒の本数を表す。
 * */

long long match[10] = {2,5,5,4,5,6,3,7,6};
string dp[11000];
const string MINUSINF = "-";

void chmax(string &a, string b) {
    if (a == MINUSINF) a = b;
    else if (a.size() < b.size()) a = b;
    else if (a.size() == b.size()) {
        if (a < b) a = b;
    }
}

int main() {
    int N, M; cin >> N >> M;
    int A[M];
    for (int i = 0; i < M; ++i) cin >> A[i];

    // 初期化
    rep(i,11000) dp[i] = MINUSINF;

    // 初期条件
    dp[0] = "";

    // DP ループ
    for (int i = 0; i <= N; ++i) {
        if (dp[i] == MINUSINF) continue;
        rep(j,M) {
            chmax(dp[i+match[A[j]-1]], dp[i] + (char)('0' + A[j]));
        }
    }
    cout << dp[N] << endl;
    return 0;
}


Measured memory_bytes: 43776
import numpy as np
N, M, C = map(int, input().split(' '))
B = np.array(list(map(int, input().split(' '))))
ans = 0
for i in range(N):
    A = np.array(list(map(int, input().split(' '))))
    if(sum(A*B)+C > 0):
        ans += 1
print(ans)

Measured memory_bytes: 20988
/*input 
4 8
3 1 4 1
3 1 4 1
*/

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

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
const ld PI = 4*atan((ld)1);

ll modpow(ll x, ll p) {
	return !p ? 1 : modpow((x * x) % MOD, p / 2) * (p & 1 ? x : 1) % MOD;
}

ll pre[401][401];
ll N, C;
vi A, B;
ll dp[401][401];
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> N >> C;
	A.pb(0);
	FOR(i, 1, N + 1) {
		A.pb(0); cin >> A[i];
	}
	B.pb(0);
	FOR(i, 1, N + 1) {
		B.pb(0); cin >> B[i];
	}

	F0R(i, 401) {
		FOR(j, 1, 401) {
			pre[i][j] = (pre[i][j - 1] + modpow(j, i)) % MOD;
		}
	}

	FOR(i, 1, N + 1) {
		F0R(j, C + 1) {
			if (i == 1) {
				dp[i][j] = (pre[j][B[i]] - pre[j][A[i] - 1]) % MOD; 
				while (dp[i][j] < MOD) dp[i][j] += MOD;
			}
			F0R(k, j + 1) {
				ll tmp = (pre[k][B[i]] - pre[k][A[i] - 1]) % MOD;
				tmp = (tmp * (dp[i - 1][j - k] % MOD)) % MOD;
				while (tmp < 0) tmp += MOD;
				dp[i][j] = (dp[i][j] + tmp) % MOD;
			}
			//cout << dp[i][j] << " ";
		}
		//cout << '\n';
	}
	cout << dp[N][C] << '\n';
}




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

int main() {
	long long int W, H, x, y;
	cin >> W >> H >> x >> y;
	bool flag = false;
	
	if (W % 2 == 0 && H % 2 == 0) {
		if (x == W / 2 && y == H / 2) flag = true;
	}

	long double S;
	S = (long double)((W * H) / 2.0);
	cout << S << ' ';
	if (flag) cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
def solve(n, d, x):
    x = np.asarray(x)
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            y = x[i]
            z = x[j]
            d = np.linalg.norm(y-z)
            if abs(int(d)**2 - d**2) < 1e-5:
                ans += 1
    return ans

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
print(solve(n, d, x))

Measured memory_bytes: 12496
/*
	Behind every successful man 
	there's a lot of unsuccessful years
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define E endl
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n,k;
		cin >> k >> n;
		int ans =0;
		fn{
			cin >> ar[i];
			ans+=ar[i];
		}
		cout <<(ans>=k ?"Yes" :"No");
	
	}
	
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{
    int n,m,k;
    cin>>n>>m>>k;


    for(int i=0;i<=n;i++)
    {
        
        for(int j=0;j<=m;j++)
        {
            int b =i*m;
            b-= j*i;
            b+= (n-i)*j;

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


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int,int,int> Team;
int AC[50][10],WA[50][10];
int main() {
    int  M,T,P,R;
    while(cin>>M>>T>>P>>R,M) {
        memset(AC,-1,sizeof(AC));
        memset(WA,0,sizeof(WA));
        for(int i=0;i<R;i++) {
            int m,t,p,j;
            cin>>m>>t>>p>>j;
            t--;p--;
            if(j==0) {
                AC[t][p]=m;
            }else {
                WA[t][p]++;
            }
        }
        vector<Team> v;
        for(int i=0;i<T;i++) {
            int solved=0,penalty=0;
            for(int j=0;j<P;j++) {
                if(AC[i][j]!=-1) solved++,penalty+=AC[i][j]+WA[i][j]*20;
            }
            v.push_back(make_tuple(-solved,penalty,-(i+1)));
        }
        sort(v.begin(),v.end());
        printf("%d",-get<2>(v[0]));
        for(int i=1;i<v.size();i++) {
            if(get<0>(v[i-1])<get<0>(v[i])||get<1>(v[i-1])<get<1>(v[i])) putchar(',');
            else putchar('=');
            printf("%d",-get<2>(v[i]));
        }
        putchar('\n');
    }
}

Measured memory_bytes: 3208
import bisect
n=int(input())
la=sorted(map(int,input().split()))
lb=sorted(map(int,input().split()))
lc=sorted(map(int,input().split()))
countb=[]
count1=0
for i in range(n):
  index=bisect.bisect_left(la,lb[i])
  countb.append(index)
countb2=[]
sum=0
for i in range(n):
  sum+=countb[i]
  countb2.append(sum)
ans=0
for i in range(n):
  index=bisect.bisect_left(lb,lc[i])
  if index==0:
    pass
  else:
    ans+=countb2[index-1]
print(ans)

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

using namespace std;
string s;
int main() {
    ios_base::sync_with_stdio(false);
    int n = 0, k;
    cin >> n;
    cin >> s;
    s = ' ' + s;
    int q;
    cin >> q;
    for (int it = 1; it <= q; it++) {
        int k;
        int cntm = 0, cntc = 0;
        long long ans = 0, cur =0;
        cin >> k;
        k = min(n, k);
        for (int i = k; i >= 1; i--) {
            if (s[i] == 'M') {
                cur += cntc;
                cntm++;
            }
            else if (s[i] == 'C') {
                cntc++;
            }
        }
        for (int i = 1; i <= n; i++) {
            if (s[i] == 'D') ans += cur;
            if (s[i] == 'M') {
                cur -= cntc;
                cntm--;
            }
            if (s[i] == 'C') {
                cntc--;
            }
            if (i + k <= n) {
                if (s[i + k] == 'M') {
                    cntm++;
                }
                if (s[i + k] == 'C') {
                    cur += cntm;
                    cntc++;
                }
            }
        }
        cout << ans << "\n";
    }
    return 0;
}

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

int main(){
    int n;
    while(cin>>n,n){
            vector<int> isprime(2*n+1,1);
            isprime[0]=0;
            isprime[1]=0;
                    for(int i=1;i<=2*n;i++)
                        if(isprime[i]){
                            for(int j=i*2;j<=2*n;j+=i)
                                isprime[j]=0;


                        }

                    int cnt=0;
                    for(int i=n+1;i<=2*n;i++)
                    cnt+=isprime[i];
            cout<<cnt<<endl;}


}

Measured memory_bytes: 4252
#include <iostream>

using namespace std;

int main(){
    int N; //1~10**5
    int K;
    int h;
    int num=0;

    //入力
    cin >> N >> K;

    for(int i=0; i<N; i++){
        cin >> h;
        if(h>=K)    num++;
    }

    //処理
    cout << num << endl;

    return 0;
}

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

using namespace std;

int main() {
  long long N;
  cin >> N;
  if (N % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }
  long long target = 1;
  long long count = 0;
  while (target <= N) {
    target *= 5;
    count += N / target / 2;
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
            #define REP(i, n) for(int i = 0;i < n;i++)
            using namespace std;
            int main()
            {
            int n;
            cin>>n; int cnt=1;
            vector<int> h(n,0);
            REP(i,n)
            {
                cin >> h[i];
            }
                int d=h[0];
            for(int i=0; i<n-1; i++)
            {
               d=max(d,h[i]);
               if(d<=h[i+1]) ++cnt;
            }
            cout<<cnt<<endl;
            }

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
	ll x, k, i, j;
	cin >> x >> k;
	vl r(k);
	for (i = 0; i < k; i++) {
		cin >> r[i];
	}
	r.push_back(inf);
	ll q;
	cin >> q;
	vl t(q), a(q);
	for (i = 0; i < q; i++) {
		cin >> t[i] >> a[i];
	}
	t.push_back(inf);
	vector<pii> ta(k + q + 1);
	i = 0; j = 0;
	while (i < k || j < q) {
		if (r[i] <= t[j]) {
			ta[i + j + 1].first = r[i];
			ta[i + j + 1].second = -1;
			i++;
		}
		else {
			ta[i + j + 1].first = t[j];
			ta[i + j + 1].second = a[j];
			j++;
		}
	}
	ll n = k + q;
	/*
	for (i = 0; i <= n; i++) {
		printf("(%d, %d)\n", ta[i].first, ta[i].second);
	}
	//*/
	ll a1 = 0, a2 = x;
	ll b1 = 0, b2 = x;
	bool up = true;
	ll dif = 0;
	for (i = 1; i <= n; i++) {
		if (up) {
			dif -= ta[i].first - ta[i - 1].first;
			b1 -= ta[i].first - ta[i - 1].first;
			b2 -= ta[i].first - ta[i - 1].first;
		}
		else {
			dif += ta[i].first - ta[i - 1].first;
			b1 += ta[i].first - ta[i - 1].first;
			b2 += ta[i].first - ta[i - 1].first;
		}
		if (dif <= -x) {
			dif = -x;
		}
		if (dif >= x) {
			dif = x;
		}
		a1 = max(a1, -dif);
		a2 = min(a2, x - dif);
		b1 = min(x, max(b1, 0LL));
		b2 = min(x, max(b2, 0LL));

		if (ta[i].second == -1) {
			up = !up;
		}
		else {
			if (ta[i].second <= a1) {
				cout << b1 << endl;
			}
			else if (ta[i].second >= a2) {
				cout << b2 << endl;
			}
			else {
				cout << ta[i].second + dif << endl;
			}
		}
	}
}

Measured memory_bytes: 5872
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n;
    cin >> n;
    vector<li> as(n);
    for (int i = 0; i < n; ++i) {
        cin >> as[i];
    }
    const li a = as[0];
    const li b = as[1];
    const li s = a + b;

    li x = 0;
    for (int i = 2; i < n; ++i) {
        x ^= as[i];
    }

    const li bits = 50;
    vector<vector<vector<li>>> dp(bits, vector<vector<li>>(2, vector<li>(2, -1)));

    for (li bit = 0; bit < bits; ++bit) {
        const li ma_bit = (a >> bit) & 1;
        const li s_bit = (s >> bit) & 1;
        const li x_bit = (x >> bit) & 1;
        for (li carry = 0; carry < 2; ++carry) {
            for (li cond = 0; cond < 2; ++cond) {

                for (li prev_carry = 0; prev_carry < 2; ++prev_carry) {
                    for (li prev_cond = 0; prev_cond < 2; ++prev_cond) {
                        li prev;
                        if (bit == 0) {
                            prev = (prev_carry == 0) ? 0 : -1;
                        } else {
                            prev = dp[bit - 1][prev_carry][prev_cond];
                        }
                        if (prev == -1) {
                            continue;
                        }

                        for (li a_bit = 0; a_bit < 2; ++a_bit) {
                            li b_bit = a_bit ^ x_bit;
                            li digit_bit = a_bit ^ b_bit ^ prev_carry;
                            if (digit_bit != s_bit) {
                                continue;
                            }
                            li actual_carry = (a_bit + b_bit + prev_carry) / 2;
                            if (carry != actual_carry) {
                                continue;
                            }
                            li actual_cond = (prev_cond && (a_bit <= ma_bit)) || (a_bit < ma_bit);
                            if (cond && !actual_cond) {
                                continue;
                            }
                            dp[bit][carry][cond] = max(dp[bit][carry][cond], prev + (1LL << bit) * a_bit);
                        }

                    }
                }

            }
        }

    }


    if (dp[bits - 1][0][1] <= 0) {
        cout << -1 << endl;
    } else {
        cout << a - dp[bits - 1][0][1] << endl;
    }

    return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S; cin >> S;
  int N = S.size();
  int ans = 1e9;
  REP(i, N-2){
    ans = min(ans, abs(stoi(S.substr(i, 3))-753));
  }
  cout << ans << endl; 
}

Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())
cost=0
if a+b<=2*c:
  print(a*x+b*y)
else:
  if x>y:
    cost+=2*y*c
    if a>2*c:
      print(cost+2*c*(x-y))
    else:
      print(cost+a*(x-y))
  else:
    cost+=2*x*c
    if b>2*c:
      print(cost+2*c*(y-x))
    else:
      print(cost+b*(y-x))
    
  

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

using namespace std;
const int MAXN=310;
double dp[MAXN][MAXN][MAXN];

int a,b,c,n;

int main()
{
	cin>>n;
	for(int i=1,x;i<=n;++i)
	{
		cin>>x;
		if(x==1) ++a;
		if(x==2) ++b;
		if(x==3) ++c;
	}
	
	for(int k=0;k<=n;++k)
		for(int j=0;j<=n;++j)
			for(int i=0;i<=n;++i)
			{
				if(i||j||k)
				{
					if(i) dp[i][j][k]+=dp[i-1][j][k]*1.0*i/(i+j+k);
					if(j) dp[i][j][k]+=dp[i+1][j-1][k]*1.0*j/(i+j+k);
					if(k) dp[i][j][k]+=dp[i][j+1][k-1]*1.0*k/(i+j+k);
					dp[i][j][k]+=(double)n/(i+j+k);
				}

			}
		  
	cout<<fixed<<setprecision(11)<<dp[a][b][c]<<endl;
	
	
	
	return 0;
}


Measured memory_bytes: 224332
#include<map>
#include<queue>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=3100;
int n;
ll a[maxn],mx[maxn][maxn],mn[maxn][maxn]; 
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
		mx[i][i]=a[i],mn[i][i]=-a[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j+i<=n;j++){
			int x=j,y=j+i;
			mn[x][y]=mx[x][y-1]-a[y];
			mn[x][y]=min(mn[x][y],mx[x+1][y]-a[x]);
			mx[x][y]=mn[x][y-1]+a[y];
			mx[x][y]=max(mx[x][y],mn[x+1][y]+a[x]);
		}
	printf("%lld\n",mx[1][n]);
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, M;
  IN(N,M);
  vpll ba(M);
  REP(i,M){
    IN(ba[i].second, ba[i].first);
  }
  sort(ALL(ba));

  ll ans = 0;
  ll b_min = 0;
  REP(i,M){
    if(b_min>ba[i].second) continue;
    b_min = ba[i].first;
    ans++;
  }

  OUT(ans);

  return 0;
}

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

using namespace std;

int f(long long a)
{
    int i=0;
    while(a%2==0)
    {
        i++;
        a/=2;
    }
    return i;
}

int main()
{
    long long n,an=0,t;
    cin>>n;
    for(long long i=0;i<n;i++)
    {
        cin>>t;
        an+=f(t);
    }
    cout<<an;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

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

signed main() {
    int n; cin >> n;

    int dp[100010];
    dp[0] = 0;

    for(int i = 1; i <= 100000; i++) {
        dp[i] = INF;
        int power = 1;
        while(power <= i) {
            dp[i] = min(dp[i], dp[i - power] + 1);
            power *= 6;
        }
        power = 1;
        while(power <= i) {
            dp[i] = min(dp[i], dp[i - power] + 1);
            power *= 9;
        }
    }

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


Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	int K; cin >> K;
	
	int N = (1 << K);
	
	multiset<int> data;
	
	F0R(i, N) {
		int cur; cin >> cur; data.insert(cur*-1);
	}
	
	vi vals;
	vals.pb(*data.begin());
	data.erase(data.begin());
	
	F0R(iteration, K) {
		vi newVals;
		F0R(i, sz(vals)) {
			if (data.upper_bound(vals[i]) == data.end()) {
				cout << "No" << endl; return 0;
			}
			newVals.pb(*(data.upper_bound(vals[i])));
			data.erase(data.upper_bound(vals[i]));
		}
		
		F0R(i, sz(newVals)) {
			vals.pb(newVals[i]);
		}
		sort(all(vals));
	}
	
	cout << "Yes" << endl; return 0;	
	
	return 0;
}

Measured memory_bytes: 13984
N,M=map(int,input().split())
PS=[]
for i in range(M):
    PS.append(input().split())
    PS[i][0]=int(PS[i][0])

ac=[False for i in range(N)]
wa=[0 for i in range(N)]


AC=0
WA=0

for i in range(M):
    if ac[PS[i][0]-1]:
        continue
    else:
        if PS[i][1]=="AC":
            ac[PS[i][0]-1]=True
            WA+=wa[PS[i][0]-1]
            AC+=1
        else:
            wa[PS[i][0]-1]+=1
            
print("{} {}".format(AC,WA))


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

using namespace std;

using ll = long long;

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

const double EPS = 1e-5;
const int MOD = 1e9+7;

const int N = 100;

int a[N];
int b[N];
int n;

int main(){

  cin >> n;

  for(int i = 1; i < n; i++){
    cin >> b[i];
  }

  a[0] = b[1];
  for(int i = 1; i < n; i++){
    a[i] = b[i];
  }

  //条件を満たさない要素を検出
  for(int i = 0; i < n - 1; i++){
    int max_elem = max(a[i], a[i+1]);
    if(b[i+1] < max_elem){
      //小さい方に統一
      if(a[i] < a[i+1]){
        a[i + 1] = a[i];
      }else{
        a[i] = a[i + 1];
      }
    }
  }

  int res = 0;
  for(int i = 0; i < n; i++){
    res+=a[i];
  }

  cout << res << endl;

  return 0;
}


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

typedef long long ll;
ll INF = 1LL << 60;

int 
main() 
{

  int n, y; cin >> n >> y;
  
  repe(i, 0, n){
    repe(j, 0, n - i){
      if(y == 10000 * i + 5000 * j + 1000 * (n - i - j)){
        cout << i << " " << j << " " << n - i - j << endl;
        return 0;
      }
    }
  }

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

  return 0;
}




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

#define int long long

int modexp(int a , int n ,int mod){
	if(n == 0) return 1 ;
	if(n == 1) return a ;
	int x = modexp(a , n / 2 , mod) ;
	x = (x*x) % mod ;
	if(n&1) x = (x*a) % mod ;
	return x ;
}

int solve(int x){
	if(!x) return 0 ;
	return 1 + solve(x%__builtin_popcount(x)) ;
}

int32_t main(){
	int n;
	cin >> n ;
	string s ;
	cin >> s; 
	int cnt = count(s.begin() , s.end() , '1') ;
	if(cnt == 0){
		for(auto i : s) cout << 1 << '\n' ;
		return 0 ;
	}
	if(cnt == 1){
		if(s.back() == '1'){
			for(int i = 0 ; i < n - 1 ; i++) cout << 2 << '\n' ;
			cout << 0 << '\n' ;
		} else {
			for(int i = 0 ; i < n - 1 ; i++){
				if(s[i] == '1') cout << 0 << '\n' ;
				else cout << 1 << '\n' ;
			}
			cout << 2 << '\n' ;
		}
		return 0 ;
	}
	int b = 0 , c = 0 ;
	for(int i = 0 ; i < n ; i++){
		int x = s[i] - '0' ;
		b += x*modexp(2 , n-i-1, cnt+1) ;
		c += x*modexp(2 , n-i-1, cnt-1) ;
		b %= (cnt+1) ;
		c %= (cnt-1) ;
	}
	for(int i = 0 ; i < n ; i++){
		int x = s[i] - '0' ;
		int val ;
		if(x){
			val = (c - modexp(2 , n-i-1 , cnt-1) + cnt - 1 ) % (cnt-1) ;
		} else {
			val = (b + modexp(2 , n-i-1 , cnt+1)) % (cnt + 1) ;
		}
		cout << solve(val) + 1 << '\n' ;
	}

	return 0 ;
}



Measured memory_bytes: 3752
#include <iostream>
#include <cmath>
#include <algorithm>
#include <deque>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
// #define mp make_pair
// #define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
#define show(x) cout << #x << " = " << x << endl;

int memo[301];

ll gcd(ll a, ll b){
  if(b==0){
    return a;
  }else{
    return gcd(b, a%b);
  }

}


int main(){
  ll n, m;
  cin >> n >> m;
  ll ans = 1;
  FORD(i,n,1){
    ans = ans * i % 1000000007;
  }
  FORD(i,m,1){
    ans = ans * i % 1000000007;
  }
  if(n == m){
    cout << ans * 2 % 1000000007 << endl;
  }else if(n == m + 1 || m == n + 1){
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Node[] heap = new Node[n + 1];
		heap[0] = new Node();
		for (int i = 1; i < n + 1; i++) {
			heap[i] = new Node();
			heap[i].id = i;
			heap[i].key = sc.nextInt();
		}

		for (int i = 1; i < n + 1; i++) {
			heap[i].p = heap[i / 2].key;
			if (2 * i > n) continue;
			else heap[i].l = heap[2 * i].key;
			if (2 * i + 1 > n) continue;
			else heap[i].r = heap[2 * i + 1].key;
		}

		for (int i = 1; i < n + 1; i++) {
			System.out.print("node " + heap[i].id + ": key = " + heap[i].key + ", ");
			if (heap[i].p != Integer.MIN_VALUE) System.out.print("parent key = " + heap[i].p + ", ");
			if (heap[i].l != Integer.MIN_VALUE) System.out.print("left key = " + heap[i].l + ", ");
			if (heap[i].r != Integer.MIN_VALUE) System.out.print("right key = " + heap[i].r + ", ");
			System.out.println();
		}
	}
}

class Node {
	int id;
	int key;
	int p;
	int l;
	int r;

	Node() {
		id = Integer.MIN_VALUE;
		key = Integer.MIN_VALUE;
		p = Integer.MIN_VALUE;
		l = Integer.MIN_VALUE;
		r = Integer.MIN_VALUE;
	}
}

Measured memory_bytes: 26976