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

/*
各ブロックをM色で塗る
隣り合うブロックで同じ色で塗られているのがK組以下
各遷移では、
i) 現在の色と同じ色で塗る
ii) 違う色で塗る
の二通りしかない

dp[N][K]みたいのができるけどO(N * K)だと計算量が大きい
後ろから見ると
dp[N]->[K, K]
dp[N-1]->[K-1, K]
...
となるけど結局O(K ^ 2)なので根本的な解決にはならない

for (int i = 0; i <= k; i++)
{
	dp[next][i] += dp[now][i] * (M - 1);
	dp[next][i + 1] += dp[now][i];
}
みたいな感じになる
つまり、漸化式で書くと dp[x][y] = (M - 1) * dp[x - 1][y] + dp[x - 1][y - 1];
dp[x][y] = (M - 1) * ((M - 1) * dp[x - 2][y] + dp[x - 2][y - 1]) + (M - 1) * dp[x - 2][y - 1] + dp[x - 2][y - 2];
dp[x][y] = (M - 1) ^ 2 * dp[x - 2][y] + 2 * (M - 1) * dp[x - 2][y - 1] + dp[x - 2][y - 2];
なんか二項定理でいけそう？
x = 0とすればy = 0しか値存在しないので、掛ける項はたかだか一つ
nCk * (M - 1)^(n - k) な気がする
*/

int mod = 998244353;

long long modpow(long long x, long long y){
    if (y == 0) return 1;
    if (y % 2) return x * modpow(x, y - 1) % mod;
    long long res = modpow(x, y / 2);
    return res * res % mod;
}

int	main(void)
{
	int n, m, k;
	cin >> n >> m >> k;
	vector<long long> inv(n + 1, 1);
	for (int i = 2; i <= n; i++) inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
	vector<long long> cmb(n + 1, 1);
	for (int i = 1; i < n; i++) cmb[i] = (cmb[i - 1] * (n - i) % mod) * inv[i] % mod;
	long long ans = 0;
	for (int i = 0; i <= k; i++)
	{
		//cout << i << " " << cmb[i] << " " << modpow(m - 1, n - i - 1) << " " << ((m * modpow(m - 1, n - i - 1)) % mod) * cmb[i] % mod << endl;
		ans += ((m * modpow(m - 1, n - i - 1)) % mod) * cmb[i] % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return (0);
}


Measured memory_bytes: 6352
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<numeric>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const ll MOD = 1000000007;
 
using namespace std;

vector<int> dp(100001,1000000);
void solve(){
    dp[0] = 0;
    dp[1] = 1;
    int tmp;
    for(int i=2; i<100001; i++){
        tmp = 1;
        for(int j=0; j<6; j++){
            if(tmp <= i)    dp[i] = min(dp[i], dp[i-tmp]+1);
            tmp *= 9;
        }
        tmp = 1;
        for(int j=0; j<9; j++){
            tmp *= 6;
            if(tmp <= i)    dp[i] = min(dp[i], dp[i-tmp]+1);
        }
    }
}

int main(){
    int N;  cin >> N;
    solve();
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX = 1e5+5;


int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        LL n,w;
        cin >> n >> w;
        LL a[n+2][2];
        for(int i = 1 ; i <= n ; i++)
        {
                cin >> a[i][0] >> a[i][1];
        }
        LL MAX = 1e5+5;
        LL dp[n+2][100005];
        for(int i = 0 ; i <= n ; i++)
        {
                for(int j = 0 ; j < MAX ; j++)
                {
                        if( j == 0) dp[i][j] = 0;
                        else dp[i][j] = 1e10;
                }
        }
        for(int i = 1 ; i <= n ; i++)
        {
                for(int j = 1 ; j < MAX ; j++)
                {
                        dp[i][j] = dp[i-1][j];
                        if(j - a[i][1] >= 0)
                        {
                                dp[i][j] = min(dp[i][j] , dp[i-1][j - a[i][1]] + a[i][0]);
                        }
                }
        }
        LL ans = 0;
        for(int j = MAX-1 ; j >= 0 ; j--)
        {
                if(dp[n][j] <= w)
                {
                        ans = j;
                        break;
                }
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 79744
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class UnionFind {
private:
	struct SubSet {
		SubSet() : parent(0), rank(0) {
		}
		int parent;
		int rank;
	};
	vector<SubSet> vSubSet;
public:
	UnionFind(int n): vSubSet(n) {
		for (int i = 0; i < n; i++) {
			vSubSet[i].parent = i;
		}
	}

	int root(int i) {
		while (vSubSet[i].parent != i) {
			vSubSet[i].parent = vSubSet[vSubSet[i].parent].parent;
			i = vSubSet[i].parent;
		}

		return i;
	}

	void connect(int i, int j) {
		int rooti = root(i);
		int rootj = root(j);

		if (vSubSet[rooti].rank < vSubSet[rootj].rank) {	
			vSubSet[rooti].parent = rootj;
		}
		else if (vSubSet[rootj].rank < vSubSet[rooti].rank) {
			vSubSet[rootj].parent = rooti;
		}
		else {
			vSubSet[rooti].parent= rootj;
			vSubSet[rooti].rank++;
		}
	}

	bool find(int i, int j) {
		return root(i) == root(j);
	}
};

class Graph {
private:
	struct Edge {
		Edge(): src(0), dst(0), weight(0) {
		}
		Edge(int src, int dst, int weight): src(src), dst(dst), weight(weight) {
		}
		int src;
		int dst;
		int weight;
	};
	struct EdgeComp
	{
		bool operator() (const Edge &e1, const Edge &e2) {
			return e1.weight < e2.weight;
		}
	} edgeComp;
	int V;
	int E;
	vector<Edge> vEdge;
public:
	Graph(int v, int e): V(v), E(e), vEdge() {
	}

	void addEdge(int src, int dst, int weight) {
		Edge e(src, dst, weight);
		vEdge.push_back(e);
	}

	int kruskal() {
		vector<Edge> vResult;
		UnionFind uf(V+1);
		
		sort(vEdge.begin(), vEdge.end(), edgeComp);

		int i = 0;
		int result = 0;
		while (vResult.size() < V - 1) {
			const Edge &e = vEdge[i];
			if (!uf.find(e.src, e.dst)) {
				vResult.push_back(e);
				uf.connect(e.src, e.dst);
				result += e.weight;
			}
			i++;
		}

		return result;
	}
};

int main() {
	int V, E;
	cin >> V >> E;
	Graph g(V,E);

	for(int i = 0; i < E; i++) {
		int src, dst, weight;
		cin >> src >> dst >> weight;
		g.addEdge(src ,dst, weight);
	}

	cout << g.kruskal() << endl;

	return 0;
}

Measured memory_bytes: 2704
public class Main{
   public static void main(String[] args){
      int i;
      int j;
      
      for(i = 1; i <= 9; i++){
         for(j = 1; j <=9; j++){
            System.out.println(i + "x" + j + "=" + i*j);
         }//for(j)
      }//for(i)
      
   }//main method
}//class

Measured memory_bytes: 23808
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a[100];
    int n,s;
    cin>>n>>s;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++)cout<<a[i];
}

Measured memory_bytes: 256
from collections import defaultdict


def main():
    N, M = list(map(int, input().split(' ')))
    adj_nodes = defaultdict(list)
    edges = list()
    for _ in range(M):
        a, b = list(map(int, input().split(' ')))
        a -= 1
        b -= 1
        edges.append((a, b))
        adj_nodes[a].append(b)
        adj_nodes[b].append(a)
    ans = 0
    for removed_edge in edges:
        a, b = removed_edge
        visited = [0 for _ in range(N)]
        frontier = [0]
        # dfs
        while len(frontier) > 0:
            node = frontier.pop()
            visited[node] = 1
            for next_node in adj_nodes[node]:
                if visited[next_node] == 1:
                    continue
                if (node, next_node) in [(a, b), (b, a)]:
                    continue
                frontier.append(next_node)
        if min(visited) == 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
x,k,d = map(int, input().split())
if x < 0:
    x = -x
x_min = x
if x//d >= k:
    x_min -= k * d
else:
    x_min -= x//d * d
    k -= x//d
    if k % 2 == 1:
        x_min = abs(x_min - d)
print(x_min)
#xが更新されてる！！

Measured memory_bytes: 61848
# -*- coding: utf-8 -*-
MOD = 10**9+7

class BiCoeff(object):
    def __init__(self, MAX, m):
        super(BiCoeff, self).__init__()
        fac = [0]*MAX
        finv = [0]*MAX
        inv = [0]*MAX

        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2,MAX):
            fac[i] = (fac[i-1]*i)%m
            inv[i] = m - (inv[m%i] * (m//i))%m
            finv[i] = (finv[i-1] * inv[i])%m

        self.MAX = MAX
        self.m = m
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def calc(self,n,k):
        if n<k:
            return 0
        if n<0 or k<0:
            return 0
        return (self.fac[n] * (self.finv[k]*self.finv[n-k])%self.m)%self.m

bi = BiCoeff(2001, MOD)

n,k = map(int, input().split())

for i in range(1,k+1):
    a = (bi.calc(n-k+1, i) * bi.calc(k-1, i-1)) % MOD
    print(a)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  ll n;
  cin>>n;
  ll ans;
  ll cnt=0;
  for(int i=1;i<=sqrt(n);i++){
    if(n%i==0){
      cnt=n/i;
    }
  }
  int i=n/cnt;
  ans=i-1+cnt-1;
  cout<<ans<<endl;
}

Measured memory_bytes: 3672
#include<stdio.h>
int main(void)
{
	int n,t[4][13]={0};
	int i,j;
	char m;
	scanf("%d",&n);
		for(i=0;i<n*2;i++){
			scanf("%c %d",&m,&j);
			if(m=='S'){
				t[0][j-1]=1;
			}else if(m=='H'){
				t[1][j-1]=1;
			}else if(m=='C'){
				t[2][j-1]=1;
			}else if(m=='D'){
				t[3][j-1]=1;
			}
		}
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			if(t[i][j]==0){
				if(i==0){
					printf("S");
				}else if(i==1){
					printf("H");
				}else if(i==2){
					printf("C");
				}else if(i==3){
					printf("D");
				}
				printf(" %d\n",j+1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1748
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	int cnt=0;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			int k=(x-500*i-100*j)/50;
			if(k>c) continue;
			if(k<0) break;
			cnt++;
          //cout<<i<<j<<k<<endl;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    Ps = list(map(int, input().split()))

    lowest = Ps[0]
    total = 0

    for p in Ps:
        if p <= lowest:
            total += 1
            lowest = p

    print(total)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24436
def resolve():
    N, M = [int(i) for i in input().split()]
    while N + M != 0:
        A = [int(input()) for _ in range(N)]
        preSum = [0] * (N + 1)
        for i in range(N):
            preSum[i + 1] = preSum[i] + A[i]
        maxA = -10000 * M - 1
        for i in range(M, N):
            maxA = max(maxA, preSum[i] - preSum[i - M])
        print(maxA)
        N, M = [int(i) for i in input().split()]


resolve()



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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (c >= a && c <= b)
    {
        cout << "Yes" << "\n";
    }
    else
    {
        cout << "No" << "\n";
    }

    return 0;
}


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

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

    cout << (str.at(0) == 'a' || str.at(0) == 'i' || str.at(0) == 'u' || str.at(0) == 'e' || str.at(0) == 'o' ? "vowel" : "consonant") << endl;
}


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

int main(void){
    long long int i, j, n, x, t, ans=0, po=0;
    scanf("%lld %lld %lld", &n, &x, &t);
    ans += n/x;
    if(n%x != 0) ans++;
    ans = ans*t;
    printf("%lld", ans);
    
}

Measured memory_bytes: 1728
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int isSpy(set<int> &s, set<int> &L) {
  int cnt = 0;
  for(int a : s) for(int b : L) if(a == b) ++cnt;
  return cnt == L.size();
}

int solve(vector< set<int> > &S, set<int> &L) {
  int ans = -1;
  REP(i, S.size()) {
    if(isSpy(S[i], L)) {
      if(ans != -1) return -1;
      else ans = i + 1;
    }
  }
  return ans;
}

int main() {
  int N, n;
  while(cin >>N && N) {
    vector< set<int> > S(N);
    REP(i, N) {
      int M; cin >>M;
      REP(j, M) { cin >>n; S[i].insert(n); }
    }

    int K; cin >>K;
    set<int> L;
    REP(i, K) { cin >>n; L.insert(n); }

    cout <<solve(S, L) <<endl;
  }
  return 0;
}

Measured memory_bytes: 3504
#include <iostream>
#define MAXN 110
using namespace std;

int a[MAXN];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int j = 0; j < n; j++) {
		cout << a[j];
		if (j != n - 1) cout << ' ';
		else cout << endl;
	}
	for (int i = 1; i < n; i++) {
		int key = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > key) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = key;
		for (int j = 0; j < n; j++) {
			cout << a[j];
			if (j != n - 1) cout << ' ';
			else cout << endl;
		}
	}
    return 0;
}


Measured memory_bytes: 3124
#include <cstdio>
#include <algorithm>
#include <utility>

const int maxn = 2e5 + 10, mod = 1e9 + 7;

int n, hsh[maxn], dp[maxn];
std::pair<int, int> pnt[maxn], rng[maxn];

inline int lowbit(int i) {
	return i & (-i);
}

inline void M(int i, int x) {
	for (; i <= n; i += lowbit(i)) {
		dp[i] = (dp[i] + x) % mod;
	}
	return;
}

inline int Q(int i) {
	if(i < 0) {
		return 0;
	}
	int x = 0;
	for (; i; i ^= lowbit(i)) {
		x = (x + dp[i]) % mod;
	}
	return x;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		pnt[i] = std::make_pair(x, y);
		hsh[i] = y;
	}
	std::sort(hsh, hsh + n);
	for (int i = 0; i < n; ++i) {
		pnt[i].second = std::lower_bound(hsh, hsh + n, pnt[i].second) - hsh + 1;
	}
	std::sort(pnt, pnt + n);
	int mx = 0, mn = n + 1;
	for (int i = 0; i < n; ++i) {
		mx = std::max(mx, pnt[i].second);
		rng[i].second = mx;
	}
	for (int i = n - 1; ~i; --i) {
		mn = std::min(mn, pnt[i].second);
		rng[i].first = mn;
	}
	std::sort(rng, rng + n);
	for (int i = 0; i < n; ++i) {
		int l = rng[i].first, r = rng[i].second;
		M(r, (Q(r) - Q(l - 2) + (l == 1)) % mod);
	}
	printf("%d\n", (Q(n) - Q(n - 1) + mod) % mod);
	return 0;
}


Measured memory_bytes: 4864
#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;
    li ans = 0;
    for (int i = 0; i < n; ++i) {
        li idx = i + 1;
        li a;
        cin >> a;
        if (idx % 2 == 1 && a % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
const int MN=100000;
int N,K;
vector<int> G[MN];
int val[MN];
typedef pair<int,int> P;
P len[MN];
int inf=1e9;
P fre(-inf,inf);
void change(P& x,P y){
	if(y==fre) return;
	chmax(x.fs,y.fs-1);
	chmin(x.sc,y.sc+1);
}
void dfs(int v,int p,bool even){
	if(val[v]!=-1){
		if((val[v]%2==0)^even){
			puts("No");
			exit(0);
		}
		len[v]=P(val[v],val[v]);
	}else{
		len[v]=fre;
	}
	for(int u:G[v]) if(u!=p) dfs(u,v,!even);
	for(int u:G[v]) if(u!=p){
		change(len[v],len[u]);
	}
	if(len[v].fs>len[v].sc){
		puts("No");
		exit(0);
	}
}
bool in(P p,int now){
	return p.fs<=now && now<=p.sc;
}
int ans[MN];
void dfs2(int v,int p,int now){
	if(!in(len[v],now)) now+=2;
	assert(in(len[v],now));
	ans[v]=now;
	for(int u:G[v]) if(u!=p){
		dfs2(u,v,now-1);
	}
}
int main(){
	cin>>N;
	int r;
	bool reven;
	rep(i,N-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	rep(i,N) val[i]=-1;
	cin>>K;
	rep(i,K){
		int v,p;
		cin>>v>>p;
		v--;
		val[v]=p;
		r=v;
		reven=(val[v]%2==0);
	}
	dfs(r,-1,reven);
	puts("Yes");
	dfs2(r,-1,val[r]);
	rep(i,N) cout<<ans[i]<<endl;
}


Measured memory_bytes: 15744
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const ll MAX_N = 100000;

// vector<int> dp(100000, 1e9);

int main()
{
    string S,T,U;
    ll A, B;
    cin >> S >> T;
    scanf("%lld%lld", &A,&B);
    cin >> U;
    if(S==U)
        A--;
    else
        B--;
    printf("%lld %lld",A,B);

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
#include <cmath>
#define mp make_pair
#define pii pair<int,int> 
#define ff first
#define ss second
#define ll long long 
#define vi vector<int>

using namespace std;

int paper[12][12];

int x,y,d,hasil,maxs;

/*int small()
{
	printf("small ");
	if(x-1>=0)
	paper[x-1][y]++;
	if(x+1<10)
	paper[x+1][y]++;
	if(y-1>=0)
	paper[x][y-1]++;
	if(y+1<10)
	paper[x][y-1]++;
}
int medium()
{
	printf("medium ");
	if(x-1>=0&&y-1>=0)
	paper[x-1][y-1]++;
	if(x+1<10&&y+1<10)
	paper[x+1][y+1]++;
	if(x-1>=0&&y+1<10)
	paper[x-1][y+1]++;
	if(x+1<10&&y-1>10)
	paper[x+1][y-1]++;
}
int large()
{
	printf("large ");
	if(x-2>=0)
	paper[x-2][y]++;
	if(x+2<10)
	paper[x+2][y]++;
	if(y-2>=0)
	paper[x][y-2]++;
	if(y+2<10)
	paper[x][y-2]++;
}*/

int main()
{
	memset(paper, 0, sizeof(paper[0][0]) *12 *12);
	hasil=0;
	maxs=0;
	while(scanf("%d,%d,%d",&x,&y,&d)!=EOF)
	{
		/*if(x==0&&y==0&&d==0)
		{
			break;
		}*/
		if(d==1)
		{
			//printf("s");
			//small;
			paper[x][y]++;
			if(x-1>=0)
			paper[x-1][y]++;
			if(x+1<10)
			paper[x+1][y]++;
			if(y-1>=0)
			paper[x][y-1]++;
			if(y+1<10)
			paper[x][y+1]++;
		}
		else if(d==2)
		{
			//printf("m");
			//small;
			//medium;	
			paper[x][y]++;
			if(x-1>=0)
			paper[x-1][y]++;
			if(x+1<10)
			paper[x+1][y]++;
			if(y-1>=0)
			paper[x][y-1]++;
			if(y+1<10)
			paper[x][y+1]++;
			if(x-1>=0&&y-1>=0)
			paper[x-1][y-1]++;
			if(x+1<10&&y+1<10)
			paper[x+1][y+1]++;
			if(x-1>=0&&y+1<10)
			paper[x-1][y+1]++;
			if(x+1<10&&y-1>=0)
			paper[x+1][y-1]++;
		}
		else if(d==3)
		{
			//printf("l");
			//small;
			//medium;
			//large;
			paper[x][y]++;
			if(x-1>=0)
			paper[x-1][y]++;
			if(x+1<10)
			paper[x+1][y]++;
			if(y-1>=0)
			paper[x][y-1]++;
			if(y+1<10)
			paper[x][y+1]++;
			if(x-1>=0&&y-1>=0)
			paper[x-1][y-1]++;
			if(x+1<10&&y+1<10)
			paper[x+1][y+1]++;
			if(x-1>=0&&y+1<10)
			paper[x-1][y+1]++;
			if(x+1<10&&y-1>=0)
			paper[x+1][y-1]++;
			if(x-2>=0)
			paper[x-2][y]++;
			if(x+2<10)
			paper[x+2][y]++;
			if(y-2>=0)
			paper[x][y-2]++;
			if(y+2<10)
			paper[x][y+2]++;
		}
		/*for(int b=0;b<10;b++)
		{
		for(int k=0;k<10;k++)
		{
			printf("%d ",paper[k][b]);
		}
		printf("\n");
		}*/
	}
	for(int b=0;b<10;b++)
	{
		for(int k=0;k<10;k++)
		{
			if(paper[k][b]==0)
			{
				hasil++;	
			}
			maxs=max(maxs,paper[k][b]);
			//printf("%d ",paper[k][b]);
		}
		//printf("\n");
	}
	printf("%d\n%d\n",hasil,maxs);
	return 0;
}

Measured memory_bytes: 1188
n, k = map(int, input().split())
d = list(map(int, input().split()))

c = list(range(10))
#num = list(filter(lambda x: x not in d, c))

while n:
    a = list(str(n))
    if list(filter(lambda x: int(x) in d, a)) == []:
        break
    n += 1
print(n)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main() {
	long long int a, b, ans;
	cin >> a >> b;
	ans = b;
	a--; b--;
	for (int i = 0; i < a; i++)ans *= b;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <math.h>
#define lli long long int
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

void solve()
{
    lli h, n;
    cin>>h>>n;
    lli s = 0;
    for(int i = 0; i < n; i ++ ){
        lli x;
        cin>>x;
        s += x;
    }
    if(s >= h) {
        cout<<"Yes";
    }
    else {
        cout<<"No";
    }
    cout<<'\n';
    return ;
}



/*
*/

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

    int t = 1;
    //cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];

  sort(a.begin(), a.end());

  int c = a[0], r = a[n - 1];
  int h2 = (r % 2 == 0) ? r / 2 : r / 2 + 1;

  int d = INF;
  REP(i, n - 1) {
    if(abs(h2 - a[i]) <= d) d = abs(h2 - a[i]), c = a[i];
  }

  cout << r << " " << c << endl;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int a[200005];
int b[200005];

int main(int argc, char *argv[])
{
	int N;

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}
	int cnt = 0;
	for (int i = N; i >= 1; i--) {
		int s = 0;
		for (int j = 2; j <= N; j++) {
			if (i * j > N) {
				break;
			}
			s += b[i * j];
		}
		if ((a[i] == 1 && s % 2 == 0)
			|| (a[i] == 0 && s % 2 == 1)) {
			b[i] = 1;
			cnt++;
		}
	}

	cout << cnt << endl;

	for (int i = 1; i <= N; i++) {
		if (b[i] == 1) {
			printf("%d ", i);
		}
	}
	puts("");
	
	return 0;
}

Measured memory_bytes: 2432
$n, $m = gets.chomp.split(' ').map(&:to_i)

$graph = {}
$path_list = []

$m.times do
  s, t = gets.chomp.split(' ').map(&:to_i)
  $path_list << [s, t]
  $graph[s] = [] unless $graph[s]
  $graph[s] << t

  $graph[t] = [] unless $graph[t]
  $graph[t] << s
end

def dfs(point, remove_path)
  stack = [point]

  until stack.empty?
    current_point = stack.pop
    next if $visited[current_point]

    $visited[current_point] = true

    $graph[current_point].each do |next_point|
      stack << next_point unless [[current_point, next_point], [next_point, current_point]].include?(remove_path)
    end
  end
end

res = 0
$path_list.each do |remove_path|
  $visited = {}
  count = 0
  $graph.keys.each do |point|
    next if $visited[point]
    dfs(point, remove_path)
    count += 1
    if count > 1
      res += 1
      break
    end
  end
end

puts res

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
 #define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
int main(){
    int n,t,a;
    cin>>n>>t>>a;
    vector<double> h(n);
    rep(i,n){
        cin>>h[i];//高さ
    }
    int place;
    double min = 10000;
    rep(i,n){
        double sa = t-h[i]*0.006;
        //cout<<sa<<endl;
        if(abs(sa-a)<min){
            min = abs(sa-a);
            place = i;
        }
    }
    cout<<place+1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;
typedef long long ll;
typedef vector<long> vl;
typedef vector<string> vs;

int main(){
  int n;
  c(n);
  int a[n],b[n],c[n];
  int d=0;
  rep(i,0,n) cin>>a[i];
  rep(i,0,n) cin>>b[i];
  rep(i,0,n) c[i]=a[i]-b[i];
  rep(i,0,n){
    if(c[i]>=0) d+=c[i];
  }
  co(d);
    
  return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(i - 1 for i in map(int, input().split()))
now = 0
loop_start = 0
load_list = [-1] * N
Y = - 1
while loop_start < K:
    if load_list[now] == -1:
        load_list[now] = loop_start
        now = A[now]
        loop_start += 1
    else:
        start = load_list[now]
        end = loop_start - load_list[now]
        Y = start + (K - loop_start) % end
        break

if Y == -1:
    print(now + 1)
else:
    print(load_list.index(Y) + 1)

Measured memory_bytes: 32344
fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        x: i64,
        ca_ss: [(i64, [i64; m]); n],
    }
    let mut min_cost = std::i64::MAX;
    for i in 1..1 << n {
        let mut arr = [0; 12];
        let mut cost = 0;
        for j in 0..n {
            if ((1 << j) & i) != 0 {
                for k in 0..m {
                    arr[k] += ca_ss[j].1[k];
                }
                cost += ca_ss[j].0;
            }
        }
        if arr.iter().take(m).all(|item| *item >= x) {
            min_cost = std::cmp::min(min_cost, cost);
        }
    }
    let ans = if min_cost == std::i64::MAX {
        -1
    } else {
        min_cost
    };
    println!("{}", ans);
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ans,n,r,g,b;
string s;
int main()
{
   cin>>n>>s;
   for(int i=0;i<n;i++)
   {
   	  if(s[i]=='R')r++; 
	  if(s[i]=='G')g++; 
	  if(s[i]=='B')b++; 
   }
  ans=r*g*b;  //满足了条件1 
for(int i=0;i<n;i++)  //枚举i j 确定符合条件2的K   
    for(int j=i+1;j<n,2*j-i<n;j++)  //   
    {
    	if(s[i]!=s[j]&&s[j]!=s[2*j-i]&&s[i]!=s[2*j-i])  
    	   ans--;
	}
cout<<ans;
return 0;
}


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(){
int N;
  cin>>N;
  if((N%10==2)||(N%10==4)||(N%10==5)||(N%10==7)||(N%10==9)){
  cout<<"hon"<<endl;
  }
  else if(N%10==3){
    cout<<"bon"<<endl;
  }
  else{
  cout<<"pon"<<endl;
  }
}


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

int main() {
    int N, A, B; cin >> N >> A >> B;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int sum = 0;
        string s = to_string(i);
        for (int j = 0; j < s.size(); j++) {
            sum += s[j] - '0';
        }
        if (sum >= A && sum <= B) {
            ans += i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3744
#include <stdio.h>
int main(void){
   int i, j,H,W;
   while(scanf("%d %d",&H,&W)!=EOF){
    if(H==0&&W==0){
        break;
    }
    for ( i = 0; i < H; i++ ){
    for ( j = 0; j < W; j++ ){
        if(j==0||j==W-1||i==0||i==H-1){
            printf("#");
        } else {
            printf(".");
        }
    }
    printf("\n");
}
    printf("\n");
}
 return(0);// Your code here!
    
}


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

typedef long long ll;

int a, b;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b;
    if (a >= 1 && a <= 9 && b >= 1 && b <= 9) {
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <set>
using namespace std;
int main() {
  int n,m,x; cin>>n>>m>>x;
  int a[m],st=0,go=0;
  for(int i=0;i<m;i++) cin>>a[i];
  for(int i=0;i<m;i++){
    if(a[i]>x) go++;
    else st++;
  }
  cout<<min(st,go)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 20011
# define INF 0x3f3f3f3f3f
vector<vector<ll>> size(405 , vector<ll> (405));
vector<vector<ll>> dp(405 , vector<ll> (405));


int main() {

    fastio;

    ll n,cost=LLONG_MAX , a ,b;

    cin >> n;

    for(ll i = 1 ; i <= n ; i++)
    {
        cin >> size[i][i];
        dp[i][i] = 0;
    }

    for( ll i = 1 ; i <= n-1 ; i++)
    {
        for( ll j = i+1 ; j <= n ; j++)
        {
            size[i][j] = size[i][j-1] + size[j][j];
        }
    }

    for( ll j = 2 ; j <= n ; j++)
    {
        ll t = j;

        for( ll i = 1 ; i <= n-j+1 ; i++)
        {
            for( ll v = i ; v+1 <= t ; v++)
            {
                cost = min( cost , dp[i][v] + dp[v+1][t] + size[i][v] + size[v+1][t]);

                if(cost ==  dp[i][v] + dp[v+1][t] + size[i][v] + size[v+1][t])
                {
                    a = size[i][v];
                    b = size[v+1][t];
                }

            }

            dp[i][t] = cost;
            cost = LLONG_MAX;
            t++;
        }
    }

    
    cout << dp[1][n];

    return 0;
}




Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int N , K; 
long long h[100010];
long long dp[100010];
int main(){
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];
for (int i = 0; i < N; ++i) dp[i] = INF;
dp[0] = 0;
for (int i = 0; i < N; ++i){
    for (int j = 1; j <= K; ++j){
        chmin(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
    } 
}
cout << dp[N - 1] << endl;

}

Measured memory_bytes: 1792
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
      long[] a = new long[n+1];
      long[] b = new long[n];
      for(int i=0;i<n+1;i++){
        a[i] = scan.nextLong();
      }
      for(int i=0;i<n;i++){
        b[i] = scan.nextLong();
      }
      
      long result=0;
      for(int i=n-1;i>=0;i--){
        long x = a[i+1]>b[i]?b[i]:a[i+1];
        a[i+1] -= x;
        b[i]-=x;
        result +=x;
        if(b[i]>0){
          long y = a[i]>b[i]?b[i]:a[i];
          a[i] -= y;
          b[i]-=y;
          result +=y;
        }
      }
      System.out.println(result);
	}
}

Measured memory_bytes: 88548
#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,a[10005];
int main()
{
    double W,H,x,y;
    scanf("%lf %lf %lf %lf",&W,&H,&x,&y);
    printf("%f %d",W*H/2,(x==W/2&&y==H/2));
    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    
    max_num = max(a)
    dif = 10**10
    ansnum = 0
    for num in a:
        if(num != max_num and dif > abs((max_num/2) - num)):
            dif = abs((max_num/2) - num)
            ansnum = num
            
    print("{} {}".format(max_num, ansnum))
        
if __name__=="__main__":
    main()

Measured memory_bytes: 14052
n = int(input())
s = input()

ans = 0
for i in range(1, n):
    x = s[:i]#最初のi文字
    y = s[i:]

    setX = set(x)
    setY = set(y)
    
    ans = max(ans, len(setX & setY))#積

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
// vector<int> vec(3); = vector<int> vec={0,0,0}
// vec.at()
// sort(num.begin(),num.end(), greater<int>());
// reverse(num.begin(),num.end());

// 切り上げ　a/b+1
 
int main() {
  int N;
  cin >> N;
  int j = 0;
  for(int i=1;i<=N;i++){
  	j+=i;
  }
  
  cout << j << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<P> x(n), p(n);
    rep(i, n){
        cin >> x[i].first >> x[i].second;
        p[i] = {x[i].first+x[i].second, x[i].first-x[i].second};
    }
    sort(all(p));
    ll ans = 0, end = -inf;
    rep(i, n){
        if(end <= p[i].second){
            ans++;
            end = p[i].first;
        }
    }
    cout << ans << endl;
}

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

int main() {
	int i, n,a;
	cin >> n;
	for (i = 1; i <= n; i++) {
		a = i;
		if (a % 3 == 0) {
			cout << " " << i;
		}
		else {
			while (a != 0) {
				if (a % 10 == 3) {
					cout << " " << i;
					if (a % 10 == 3) {
						break;
					}
				}
				a /= 10;
			}
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3112
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest=arguments,v=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<v)v=rest[i];return v}
function max(){var rest=arguments,v=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>v)v=rest[i];return v}
function gcd(){var rest=arguments,v=rest[0],temp=(a,b)=>b?temp(b,a%b):a;for(var i=1;i<rest.length;i++)v=temp(v,rest[i]);return v}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split(' ');
	var a = toInt(input[0]);
	var b = toInt(input[1]);
	var ans = b%a===0? a+b : b-a;

	console.log(ans);

	return 0;
}



Measured memory_bytes: 22076
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val x = sc.nextInt()
    val y = sc.nextInt()
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val p = Array(a) { sc.nextInt() }.sortedDescending()
    val q = Array(b) { sc.nextInt() }.sortedDescending()
    val r = Array(c) { sc.nextInt() }.sortedDescending()
    var ans = 0L
    var i = 0
    var j = 0
    var k = 0
    while (i + j + k < x + y) {
        val n1 = if (i < a) p[i] else -1
        val n2 = if (j < b) q[j] else -1
        val n3 = if (k < c) r[k] else -1
        if (n1 >= n2 && n1 >= n3 && i < x) {
            ans += n1
            i++
        } else if (n2 >= n1 && n2 >= n3 && j < y) {
            ans += n2
            j++
        } else if (n3 >= n1 && n3 >= n2) {
            ans += n3
            k++
        } else if (i == x && j < y && n2 >= n3) {
            ans += n2
            j++
        } else if (j == y && i < x && n1 >= n3) {
            ans += n1
            i++
        } else {
            ans += n3
            k++
        }
    }
    println(ans)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


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

int math[300000]; //素数であるものをチェックする
int n;




int main(){
 /*    for(int h=0;h<10;h++){
            cout<<math[h];
        }*/
math[0]=-1;
math[1]=-1;
for(int i=2;i<300000;i++){
    if(!math[i]){
        math[i]=1;
        for(int j=i+i;j<300000;j+=i)math[j]=-1;//倍数の計算をしている
    }
         /*   for(int h=0;h<10;h++){
            cout<<math[h];
        }*/
        //cout<<"##"<<endl;
}

while(true){
int anser=0;
cin>>n;
if(n==0){break;}
for(int i=n+1;i<=n*2;i++){
    if(math[i]==1)anser++;
}


cout<<anser<<endl;
}
    return 0;
}


Measured memory_bytes: 4232
## coding: UTF-8
#from itertools import permutations, combinations,combinations_with_replacement,product
N = int(input())
nokori = N #残金
uresisa = 0 #嬉しさ

a = 0 #500の枚数
b = 0 #5の枚数

a = int(N/500)
nokori -= a * 500
uresisa += a * 1000

#print(a)
#print(nokori)
#print(uresisa)

b = int(nokori/5)
nokori -= b * 5
uresisa += b * 5

#print()
#print(b)
#print(nokori)
print(uresisa)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define MAXN 500010  
#define LL long long 
#define pi acos(-1)
#define MOD 100000007

using namespace std;

int n,a[MAXN];

bool cmp(int a,int b){return a>b;}

int main() {
    cin >> n;
    for (int i = 1; i <= n ;i++) cin >> a[i];
    sort(a+1,a+n+1);
    int l=2,r=n;
    int ll,rr;
    ll=rr=a[1];
    int p=1;
    LL ans=0;
    while(l<=r){
    	if (p==0){
    		ans+=abs(ll-a[l]);
    		ll=a[l++];
    		if (l<=r) ans+=abs(rr-a[l]),rr=a[l++];
    	}else{
    		ans+=abs(ll-a[r]);
    		ll=a[r--];
    		if (l<=r) ans+=abs(rr-a[r]),rr=a[r--];
    	}
    	p=p^1;
    }
    sort(a+1,a+n+1,cmp);
    l=2,r=n;
    ll,rr;
    ll=rr=a[1];
    p=1;
    LL tmp=0;
    while(l<=r){
    	if (p==0){
    		tmp+=abs(ll-a[l]);
    		ll=a[l++];
    		if (l<=r) tmp+=abs(rr-a[l]),rr=a[l++];
    	}else{
    		tmp+=abs(ll-a[r]);
    		ll=a[r--];
    		if (l<=r) tmp+=abs(rr-a[r]),rr=a[r--];
    	}
    	p=p^1;
    }
    if (tmp>ans) ans=tmp;
    cout << ans<< endl;
}


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

using ll = long long;
static const int MAX = 100000;

ll n, a, b;
vector<ll> h(MAX);

// x回の爆発で全滅させられるかどうか
bool judge(ll x) {
  ll y, count = 0;
  for(int i = 0; i < n; i++){
    if(h.at(i) > b * x){
      y = h.at(i) - b * x;
      count += (y + (a - b) - 1) / (a - b);
    }
  }
  
  if(count <= x) return true;
  else return false;
}

int main() {
  cin >> n >> a >> b;
  
  for(int i = 0; i < n; i++) cin >> h.at(i);
  
  // 解を二分探索
  ll l = 0, r = 1000000000, mid;
  while(l < r){
    mid = (l + r) / 2;
    if(judge(mid)) r = mid;
    else l = mid + 1;
  }
  
  cout << r << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int dpH[8005], dpV[8005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string s;
	cin >> s;
	int x, y;
	cin >> x >> y;
	while(s[0] == 'F') x--, s = s.substr(1, (int)(s.size() - 1));
	//first we need to get the segments
	int totH = 0, totV = 0;
	vi hor, vert;
	int ori = 1;
	int sz = 0;
	rep(i, s.size()){
		if(s[i] == 'T'){
			if(ori && sz) hor.pb(sz), totH += sz;
			else if(sz) vert.pb(sz), totV += sz;
			sz = 0;
			ori ^= 1;
		}
		else sz++;
	}
	if(ori && sz) hor.pb(sz), totH += sz;
	else if(sz) vert.pb(sz), totV += sz;
	memset(dpH, 0, sizeof(dpH));
	memset(dpV, 0, sizeof(dpV));
	dpH[0] = 1;
	rep(i, hor.size()) for(int j = 8000 - hor[i]; j >= 0; j--) dpH[j + hor[i]] |= dpH[j];
	dpV[0] = 1;
	rep(i, vert.size()) for(int j = 8000 - vert[i]; j >= 0; j--) dpV[j + vert[i]] |= dpV[j];
	int cnt = 0, cnt1 = 0;
	rep(i, 8001){
		if(dpH[i] && (i - (totH - i)) == x) cnt = 1;
		if(dpV[i] && (i - (totV - i)) == y) cnt1 = 1;
	}
	if((cnt + cnt1) == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.*;
public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        String s = reader.readLine();
        
        String arr[]=s.split(" ");
        
        int a = Integer.valueOf(arr[0]);
        int b = Integer.valueOf(arr[1]);
        
        System.out.println((a+b) % 2==0 ? (a+b) / 2 : "IMPOSSIBLE");
        
        
    }

}





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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    vector<ll> x(4);
    REP(i, 4) cin >> x[i];
    sort(x.begin(), x.end());
    cout << abs(x[0]+x[3]-x[1]-x[2]) << endl;
    return 0;
}


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

int vis[25][25];
char s[25][25];
int x[4] = {0, 1, 0, -1};
int y[4] = {1, 0, -1, 0};
struct node { int x, y; } q[25 * 25];
int h, w;

int Solve(int a, int b, int c, int d) {
    if (s[a][b] == '#' || s[c][d] == '#') return 0;
    memset(vis, 0, sizeof(vis));
    vis[a][b] = 1;
    int head = 1, tail = 0;
    q[++tail] = (node){a, b};
    while (head <= tail) {
        node t = q[head++];
        for (int i = 0; i < 4; ++i) {
            if (t.x + x[i] >= 1 && t.x + x[i] <= h && t.y + y[i] >= 1 && t.y + y[i] <= w)
                if (!vis[t.x + x[i]][t.y + y[i]] && s[t.x + x[i]][t.y + y[i]] != '#')
                    vis[t.x + x[i]][t.y + y[i]] = vis[t.x][t.y] + 1, q[++tail] = (node){t.x + x[i], t.y + y[i]};
        }
    }
    return vis[c][d] - 1;
}

int main() {
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> h >> w;
    for (int i = 1; i <= h; ++i)
        cin >> (s[i] + 1);
    int ans = 0;
    for (int i = 1; i <= h; ++i)
        for (int j = 1; j <= w; ++j)
            for (int k = 1; k <= h; ++k)
                for (int l = 1; l <= w; ++l)
                    ans = max(ans, Solve(i, j, k, l));
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
typedef complex<double> P;

int n;
double x,y,xx,yy,xxx,yyy;
P a,b,c;

double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

P insect(P a1, P a2, P b1, P b2) {
  P a = a2 - a1; P b = b2 - b1;
  return a1 + a * cross(b, b1-a1) / cross(b, a);
}

int main(){
	cin>>n;
	while(n--){
		cin>>x>>y>>xx>>yy>>xxx>>yyy;
		P a=P(x,y),b=P(xx,yy),c=P(xxx,yyy);
		P ab=(a+b)*0.5,bc=(b+c)*0.5;
		P ab2=ab+(a-ab)*P(0,1),bc2=bc+(b-bc)*P(0,1);
		P p=insect(ab,ab2,bc,bc2);
		printf("%.3f %.3f %.3f\n",p.real(),p.imag(),abs(p-a));
	}
}

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

int main() {
  int N, R; cin >> N >> R;
  cout << (N >= 10 ? R : R+100*(10-N)) << 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)
using ll = long long;
using P = pair<int, int>;

int main(){
  int n;
  cin >> n;
  cout << (~n & 0x1) << endl;
  return 0;
}

Measured memory_bytes: 3632
S = input()
T = input()
dp = [[-1 for i in range(len(S)+1)] for j in range(len(T)+1)]
sub = [["" for i in range(len(S)+1)] for j in range(len(T)+1)]
for a in range(len(S)+1):
	dp[0][a] = 0
for b in range(len(T)+1):
	dp[b][0] = 0
for p in range(1, len(T)+1):
	for q in range(1, len(S)+1):
		if T[p-1] == S[q-1]:
			dp[p][q] = 1 + dp[p-1][q-1]
			sub[p][q] = "c"
		else:
			if dp[p-1][q] > dp[p][q-1]:
				dp[p][q] = dp[p-1][q]
				sub[p][q] = "u"
			else:
				dp[p][q] = dp[p][q-1]
				sub[p][q] = "l"
t = len(T)
s = len(S)
out = ""
while sub[t][s] != "":
	if sub[t][s] == "c":
		out = S[s-1] + out
		t -= 1
		s -= 1
	elif sub[t][s] == "u":
		t -= 1
	else:
		s -= 1
print(out)


Measured memory_bytes: 191752
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.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;
}

const ll INF = LONG_LONG_MAX / 2;

vector<vector<int>> board; // 0 is white, 1 is black
vector<vector<ll>> dp;

ll solve(const int cur_h, const int cur_w, const int H, const int W) {
    if (dp[cur_h][cur_w] != -1) {
        return dp[cur_h][cur_w];
    }

    int cur_color = board[cur_h][cur_w];
    if (cur_color == 0) {
        // white
        dp[cur_h][cur_w] = min(solve(cur_h + 1, cur_w, H, W), solve(cur_h, cur_w + 1, H, W));
    } else {
        // black
        ll cand_up = INF, cand_left = INF;
        {
            // up
            if (cur_h + 1 <= H) {
                cand_up = solve(cur_h + 1, cur_w, H, W);
                if (board[cur_h + 1][cur_w] == 0) {
                    cand_up++;
                }
            }
        }
        {
            // left
            if (cur_w + 1 <= W) {
                cand_left = solve(cur_h, cur_w + 1, H, W);
                if (board[cur_h][cur_w + 1] == 0) {
                    cand_left++;
                }
            }
        }
        dp[cur_h][cur_w] = min(cand_up, cand_left);
    }

    return dp[cur_h][cur_w];
}

int main(void) {
    int H, W;
    cin >> H >> W;

    board.resize(H + 3, vector<int>(W + 3, 1));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char c;
            cin >> c;
            if (c == '.') {
                board[i + 1][j + 1] = 0;
            } else {
                board[i + 1][j + 1] = 1;
            }
        }
    }


    dp.resize(H + 3, vector<ll>(W + 3, -1));
    for (int i = 0; i < H; i++) {
        dp[i][0] = INF;
        dp[i][W + 1] = INF;
    }
    for (int i = 0; i < W; i++) {
        dp[0][i] = INF;
        dp[H + 1][i] = INF;
    }
    dp[H][W] = (board[H][W] == 0) ? 0 : 1;

    cout << solve(1, 1, H, W) << endl;

    return 0;
}


Measured memory_bytes: 384