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

void solve(){
    int n;
    cin>>n;
    
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    
    vector<vector<long long>> dp(n, vector<long long>(n));
    
    for(int i=n-1 ; i>=0; i--){
        for(int j =i; j<n; j++){
            if(i == j){
                dp[i][j] = a[i];
            }
            else{
                dp[i][j] = max(a[i]-dp[i+1][j], a[j]-dp[i][j-1]);
            }
            
        }
    }
    
    cout<<dp[0][n-1]<<endl;
    
return;

}
int main() {
	// your code goes here

        solve();
    
    return 0;
}



Measured memory_bytes: 73736
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

int min(int a,int b){
    return a < b ? a : b;
}
int main(void){
    int N,M;
    cin >> N >> M;
    bool good_place[N+1];
    int H[N+1];
    for(int i=1;i<=N;i++)good_place[i] = true;
    for(int i=1;i<=N;i++){
        cin >> H[i];
    }
    for(int i=1;i<=M;i++){
        int A,B;
        cin >> A >> B;
        if(H[A] < H[B]){
            good_place[A] = false;
        }
        if(H[A] > H[B]){
            good_place[B] = false;
        }
        if(H[A] == H[B]){
            good_place[A] = good_place[B] = false;
        }
    }
    int ans = 0;
    for(int i=1;i<=N;i++){
        if(good_place[i]){
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 4112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll ans,x;
bool y;
int main(){
	cin >> s;
	for(int i=0;i<s.size();i++){
		if(y){
			if(s[i]=='A')x=1;
			if(s[i]=='B')x=0;
			if(s[i]=='C')ans+=x;
			y=false;
		}
		else{
			if(s[i]=='A')x++;
			if(s[i]=='B')y=true;
			if(s[i]=='C')x=0;
		}
	}
	cout << ans;
	return 0;
}

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

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n);
    vector<int> b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    ll t = 0;
    rep(i, m) t += b[i];
    int j = m;
    int ans = 0;
    rep(i, n+1) {
        while (j > 0 && t > k) {
            --j;
            t -= b[j];
        }
        if (t > k) break;
        ans = max(ans, i+j);
        if (i == n) break;
        t+= a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4848
import java.util.*;
import java.io.*;

class Main{
    public static void main(String args[])throws IOException{
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
          String[] input = br.readLine().split("");
          int num = 0;

          if(input.length == 1){
            num = Integer.parseInt(input[0]);
          }else if(input.length == 2){
            num = Integer.parseInt(input[1]);
          }else if(input.length == 3){
            num = Integer.parseInt(input[2]);
          }

          if(num == 3){
            System.out.println("bon");
          }else if(num == 0 || num == 1 || num == 6 || num == 8){
            System.out.println("pon");
          }else{
            System.out.println("hon");
          }
        }

    }
}

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


void min_self(int & a, int b){
	if(b<a)
		a=b;
}

int main(){
	int h,w;
	cin >> h >> w;
	string grid[h];
	for(int i =0;i<h;i++)
		cin >> grid[i];

	int dp[h][w];
	dp[0][0] = 0;
	for(int i =0;i<h;i++){
		for(int j = 0;j<w;j++){
			if(i+j==0)
				dp[0][0] = (grid[0][0]=='#');
			else{
				dp[i][j] = INT_MAX;
				if(i>0){ // could have come from the top cell
					min_self(dp[i][j],dp[i-1][j]+(grid[i][j]=='#' && grid[i-1][j]=='.'));
				}
				if(j>0)
					min_self(dp[i][j],dp[i][j-1]+(grid[i][j]=='#' && grid[i][j-1]=='.'));
			}
		}
	} 

	cout << dp[h-1][w-1] << endl;

}

Measured memory_bytes: 256
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7

def main():
  a,b,x = map(int,input().split())
  print(b//x - (a-1)//x)
if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner a=new Scanner(System.in);
		int b=a.nextInt();
		int c=b/3600;
		int d=(b%3600)/60;
		int e=(b-(c*3600)-(d*60));
		
		System.out.println(c+":"+d+":"+e);	
	}

}

Measured memory_bytes: 17164
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t A,B;
  cin>>A>>B;
  int ans=0;
  for(int i=1;i<=B;i++){
    if((A*i)%B==0){
      cout<<A*i<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3648
/**
 * File              : c.cpp
 * Author            : recurze
 * Date              : 22:40 18.01.2019
 * Last Modified Date: 22:41 18.01.2019
 */
#include <stdio.h>

void readInput();
void solve();
void printAns();

int main() {
    int t = 1;
    //scanf("%d", &t);

    for (int tc = 1; tc <= t; ++tc) {
        readInput();
        solve();
        printAns();
    }
}

const int N = 1010101;

long long n = 0;
void readInput() {
    scanf("%lld", &n);
}

int ans = 0;
void dfs(long long x, int mask) {
    //fprintf(stderr, "%d", x);
    if (x > n) return;
    ans += (mask == 7);
    dfs(10*x+3, mask|1);
    dfs(10*x+5, mask|2);
    dfs(10*x+7, mask|4);
}
void solve() {
    dfs(0, 0);
}

void printAns() {
    printf("%d\n", ans);
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;



void solve()
{
    int n;
    scanf("%d", &n);
    printf("%d\n", (n+1)/2);



    return;
}


int main(int argc, char* argv[])
{
#if 1
	solve();
#else
	int T; scanf("%d", &T);
	while (T--) {
		solve();
	}
#endif
	return 0;
}


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

using namespace std;

int main(){
    int n, k, ans = 0;
    cin >> n >> k;
    vector<int> a(n + 1), b;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        a[x]++;
    }
    for(int i = 1; i <= n; i++){
        b.emplace_back(a[i]);
    }
    sort(begin(b), end(b));
    for(int i = 0; i < b.size() - k; i++){
        ans += b[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2168
#include <stdio.h>

int main (int argc, char *argv[]) {
    int a;
    int b;
    int c;
    int temp;

    scanf("%d %d %d", &a, &b, &c);

    temp = a;
    a = b;
    b = temp;
    temp = a;
    a = c;
    c = temp;
    
    printf("%d %d %d", a, b, c);

    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	long long int n,j,x,y,heikin;
	n<=100000;
	x<=1000000;
	scanf("%lld",&n);
	//while(n!=0) {
		y=0;
		for(j=1;j<=n;j++) {
			scanf("%lld",&x);
			y+=x;
		}
		heikin=y/n;
		printf("%lld\n",heikin);
	//scanf("%lld",&n);
	//}
	return 0;
}

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

const bool DEBUG = false;

int main(int argc, char const *argv[]) {
  string s, t;
  cin >> s >> t;

  long long counter = 0;
  long long position, prev_position = s.size() - 1;
  for (auto &&c : t) {
    if (DEBUG) cout << "substr: " << s.substr(prev_position + 1) << endl;
    if ((position = s.substr(prev_position + 1).find(c)) != string::npos) {
      if (DEBUG)
        cout << "found: " << prev_position << ", "
             << prev_position + position + 1 << endl;
      position += prev_position + 1;
      prev_position = position;
    } else if ((position = s.find(c)) != string::npos) {
      if (DEBUG)
        cout << "found next: " << prev_position << ", " << position << endl;
      prev_position = position;
      counter++;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << (counter - 1) * s.size() + position + 1 << endl;
  return 0;
}

Measured memory_bytes: 640
/*
文字列の配列の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
 */
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        int a=sc.nextInt();
        int X=a;
        int[] x=new int[n+1];
        for (int i = 1; i <= n; i++) {
            x[i]=sc.nextInt();
            X=max(x[i],X);
            x[i]-=a;
        }
        long[][] dp=new long[n+1][2*n*X+1];
        dp[0][n*X]=1;
        for (int i = 1; i <= n; i++) {
            for (int t = 0; t <= 2*n*X; t++) {
                if(t-x[i]<0||t-x[i]>2*n*X)dp[i][t]=dp[i-1][t];
                else if(0<=t-x[i]&&t-x[i]<=2*n*X)dp[i][t]=dp[i-1][t]+dp[i-1][t-x[i]];
            }
        }
        out.println(dp[n][n*X]-1);
    }
}

Measured memory_bytes: 24148
#include <fstream>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <cassert>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <regex>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

//#define LOCAL_DEBUG
string a[50];
string b[50];

int main() {
#ifdef LOCAL_DEBUG
	freopen("input1.txt","r", stdin);
#endif
	int N, M; cin >> N >> M;
	REP(i, N) {
		cin >> a[i];
	}
	REP(i, M) {
		cin >> b[i];
	}
	bool check = false;
	REP(i, N - M + 1) {
		REP(j, N - M + 1) {
			bool c = true;
			REP(ii, M) {
				REP(jj, M) {
					if (a[i + ii][j + jj] != b[ii][jj]) {
						c = false;
					}
				}
			}
			if (c) {
				check = true;
			}
		}
	}
	if (check) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

 	return 0;
}


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

int main() {
  int h, a;
  cin >> h >> a;
  
  int ans = 0;
  
  while(h > 0) {
    int i = 0;
    h -= a;
    ans++;
    i++;
  }
  cout << ans << endl; 
}

Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, P = MI()
    s = list(map(int, S()[::-1]))
    ans = 0
    sum_of_d = 0
    cnts = [0] * P
    cnts[0] = 1
    A = [0] * N
    D = [0] * N

    if P == 2 or P == 5:
        for i in range(N):
            if s[i] % P == 0:
                ans += N - i
        print(ans)
        return

    for i in range(N):
        d = s[i] * pow(10, i, P)
        A[i] = d % P
        if i == 0:
            D[i] = A[i]
        else:
            D[i] = (D[i-1] + A[i]) % P
        # sum_of_d = (sum_of_d + d) % p
        # cnts[sum_of_d] += 1

    for d in D:
        cnts[d] += 1

    for i in cnts:
        ans += i * (i - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 49832
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

typedef struct info
{
	ll y;
	ll x;
	ll depth; // 今回は魔法の回数
}t_info;

ll h, w, ch, cw, dh, dw;
vector<vector<ll>> table(1010, vector<ll>(1010, -1)); // 壁は-1で初期化
queue<t_info> Q1; // 歩き
queue<t_info> Q2; // 魔法
vector<ll> y_vec = {1, -1, 0, 0};
vector<ll> x_vec = {0, 0, 1, -1};

void	bfs()
{
	while (!Q1.empty())
	{
		ll y, x, depth;
		t_info now = Q1.front(); Q1.pop();
		y = now.y; x = now.x; depth = now.depth;
		// お隣さんチェック
		for (ll i = 0; i < 4; i++) 
		{
			t_info next = {y+y_vec[i], x+x_vec[i], depth};
			if (table[next.y][next.x] != -1 && table[next.y][next.x] > next.depth)
			{
				table[next.y][next.x] = next.depth;
				Q1.push(next);
			}
		}
		// 魔法
		for (ll i = -2; i <= 2; i++)
		{
			for (ll j = -2; j <= 2; j++)
			{
				t_info next = {y+i, x+j, depth+1};
				if (table[next.y][next.x] != -1 && table[next.y][next.x] > next.depth)
				{
					table[next.y][next.x] = next.depth;
					Q2.push(next);
				}
			}
		}
	}
	if (!Q2.empty()) // Q1をQ2で上書きしてもう一度
	{
		Q1 = Q2;
		queue<t_info> tmp;
		Q2 = tmp;
		bfs();
	}
}

int		main(void)
{
	cin >> h >> w >> ch >> cw >> dh >> dw;
	ch+=1; cw+=1; dh+=1; dw+=1;

	for (ll i = 2; i <= h+1; i++)
		for (ll j = 2; j <= w+1; j++)
		{
			char a;
			cin >> a;
			if (a == '.')
				table[i][j] = LLONG_MAX; // 床はLLONG_MAXで初期化
		}
	table[ch][cw] = 0; // 床を魔法回数で塗り替えていく。スタート地点は0
	Q1.push({ch, cw, 0});
	bfs();
	if (table[dh][dw] == LLONG_MAX)
		table[dh][dw] = -1;
	cout << table[dh][dw] << endl;
}



Measured memory_bytes: 139200
#include <bits/stdc++.h>
#define inf 1000000000

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <ll, ll> ii;
typedef vector <ii> vii;
typedef vector <vii> graph;

bool comp(ll a, ll b) {
	return a > b;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
 
    ll n = 0;
    cin >> n;
    ll i, j;
    ll temp1, temp2;
    for (i = -100; i <= 200; i++) {
        temp1 = i * i * i * i * i;
        bool band = false;
        for (j = -100; j <= 200; j++) {
            temp2 = j * j * j * j * j;
            if (temp1 - temp2 == n) {band = true; break;}
        }
        if (band) {
            cout << i << " " << j << "\n";
            break;
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
	return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
long a,i,k=0,l,m,n;
int main()
{
    scanf("%ld",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%ld",&m);
        for(l=2,a=0; l<=sqrt(m); l++)
        {
            if(m%l==0)
            {
                a=1;
                break;
            }
        }
        if(a==0)
            k++;
    }
    printf("%ld\n",k);
    return 0;
}

Measured memory_bytes: 1812
def circumcenter(vert1, vert2, vert3):
    # H/T: wikipedia.org/wiki/Circumscribed_circle
    # refer from https://gist.github.com/dhermes/9ce057da49df63345c33
    Ax, Ay = vert1
    Bx, By = vert2
    Cx, Cy = vert3

    D = 2 * (Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay - By))
    norm_A = Ax**2 + Ay**2
    norm_B = Bx**2 + By**2
    norm_C = Cx**2 + Cy**2

    Ux = norm_A * (By - Cy) + norm_B * (Cy - Ay) + norm_C * (Ay - By)
    Uy = -(norm_A * (Bx - Cx) + norm_B * (Cx - Ax) + norm_C * (Ax - Bx))

    r = (Ax - Ux/D)*(Ax - Ux/D) + (Ay - Uy/D)* (Ay - Uy/D)
    r = float(r)**0.5
    return [Ux/D, Uy/D, r]

n  = int(input())
for i in range(n):
  xs = list(map(float, input().split()))
  a = circumcenter(xs[0:2], xs[2:4], xs[4:6])
  print(' '.join(map(lambda x:f'{x:0.03f}', a)))


Measured memory_bytes: 5688
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll qpow(ll a,ll b){ll res=1;while(b){if(b&1) res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll inv(ll a,ll p){return qpow(a,p-2);}
int main()
{
    std::ios::sync_with_stdio(false);
    ll n,x;
    while(cin>>n>>x)
    {
       ll a[N],ans=0;
       for(int i=1;i<=n;i++)
            cin>>a[i];
       for(int i=2;i<=n;i++)
       {
           if(a[i]+a[i-1]>x)
           {
               int t=a[i]+a[i-1]-x;
               ans+=t;
               if(t>a[i])
               {
                   a[i]=0;
                   a[i-1]-=(t-a[i]);
               }
               else
                a[i]-=t;
           }
       }
       cout<<ans<<endl;
    }
    return 0;
}

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

using namespace std;

#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define f(n) for(int i=0;i<n;++i)
#define f2(n) for(int j=0;j<n;++j)
#define f3(n) for(int k=0;k<n;++k)
#define F(i,x,n,y) for(int i=x;i<n;i+=y)
#define FF(i,x,n,y) for(int i=x;i>=n;i-=y)
#define fa(x,y) for(auto x:y)

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;

//Warsaw debug template
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1,debug&>::type operator<<(c i){
sim > struct rge {c b,e;};
sim > rge<c> range(c i, c j) {return rge<c>{i,j};}
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug{
#ifdef LOCAL
~debug() {cerr<<endl; }
eni(!=) cerr<< boolalpha << i; ris;}
eni(==) ris <<range(begin(i),end(i)); }
sim, class b dor(pair<b,c> d){
ris<<"("<<d.first<<","<<d.second<<")";
}
sim dor(rge<c> d){
    *this << "[";
    for(auto it=d.b;it!=d.e;++it)
        *this <<"," +(it==d.b)<< *it;
    ris<<"]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) "["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"
//End of debug template

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll multipleOfC=b/c-(a-1)/c;
    ll multipleOfD=b/d-(a-1)/d;
    ll intersection=(c*d)/__gcd(c,d);
    ll multipleOfGCD=b/intersection-(a-1)/intersection;
    //debug()<<imie(multipleOfC) imie(multipleOfD) imie(intersection) imie(multipleOfGCD);
    cout<<b-a+1-(multipleOfC+multipleOfD-multipleOfGCD);

    return 0;
}



Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define ll long long
const int N = 2e5 + 5;
int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int f = 1;
	while(1){
		if(f == 1){
			c -= b;
			if(c <= 0){
				cout << "Yes" << endl;
				return 0;
			}
			f = 2;
		}else{
			a -= d;
			if(a <= 0){
				cout << "No" << endl;
				return 0;
			}
			f = 1;
		}
	}
}


Measured memory_bytes: 3636
A, B, C, X, Y = map(int, input().split())
if 2*C < A+B:
    if X < Y:
        ans = 2*C*X+(Y-X)*min(B, 2*C)
    else:
        ans = 2*C*Y+(X-Y)*min(A, 2*C)
else:
    ans = A*X+B*Y
print(ans)


Measured memory_bytes: 3060
N = int(input())
 
CAKE_PRICE = 4
DONUT_PRICE = 7
 
flag = 0
for cake_num in range(N//CAKE_PRICE + 1):
  for donut_num in range(N//DONUT_PRICE + 1):
    sum_price = CAKE_PRICE * cake_num + DONUT_PRICE * donut_num
    if sum_price == N:
   		flag = 1
  
if flag == 0:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3060
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

factmod=[0 for i in range(100000)]
factmod[0]=1
for i in range(100000-1):
    factmod[i+1]=factmod[i]*(i+2)%mod
n,m=MI()
if n>m+1 or m>n+1:
    print(0)
    sys.exit()
elif n==m:
    ans=2*factorial(n)**2
else:
    if m>n:
        m,n=n,m
    ans=factorial(n)*factorial(m)
print(ans%mod)

Measured memory_bytes: 9408
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>
#include <math.h>
#include <string> 
#include <bits/stdc++.h>
using namespace std;

int main(){
    long long MOD;
    MOD = 1000000007;
    int n,k;
    cin >> n >> k;
    vector<long long> min(n+1);
    vector<long long> max(n+1);
    min[0]=0;
    max[0]=0;
    for(int i=1;i<n+2;i++){
        min[i] = min[i-1]+i-1;
        max[i] = max[i-1]+(n+1-i);
    }
    int ans;
    ans=0;
    for(int i=k;i<n+2;i++){
        ans = ans + (max[i]-min[i]+1)%MOD;
        ans = ans%MOD;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 6428
#include <iostream>

using namespace std;

int main() {
    int n, a, b;
    cin >> n;
    cin >> a;
    cin >> b;
    if (abs(a - b) % 2)
    {
        cout << "Borys" << endl;
    }
    else
    {
        cout << "Alice" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int F[50];

int fibonacci(int n){
    if ( n == 0 || n == 1 ) 
        F[n] = 1;
    if ( F[n] != NULL ) return F[n];
    return F[n] = fibonacci(n-2) + fibonacci(n-1);
}

int main(){
    int N;
    scanf("%d\n",&N);
    fibonacci(N);
    printf("%d\n",F[N]);
    return 0;
}


Measured memory_bytes: 2048
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    K, X = map(int, input().split())
    low = max(-1000000, X - K + 1)
    up = min(1000000, X + K - 1)

    ans = []
    for i in range(low, up + 1):
        ans.append(str(i))
    print(' '.join(ans))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>


#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define len(a) (int)a.size()
#define all(a) (a).begin(), (a).end()
#define pqueue priority_queue

using namespace std ;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr<<"LINE ("<< __LINE__ << ") : [" << #__VA_ARGS__ << "] -> ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

class A753 {
public:
    void solveOne(std::istream& in, std::ostream& out){
        int a ;
        in >> a ;
        if(a == 3 || a == 5 || a == 7) out << "YES" ;
        else out << "NO";
    }
	void solve(std::istream& in, std::ostream& out) {
	    int T = 1 ;
	    for(int id = 1 ; id <=  T ; ++id){
	        solveOne(in, out) ;
	    }
	}
};


int main() {
    ios::sync_with_stdio(false) ;
    cin.tie(0) ;
	A753 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3656
abcd = str(input())
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])

for i in range(2 ** 3):
    op = ['+', '+', '+']
    ans = a
    for j in range(3):
        if ((i >> j) & 1):
            op[j] = '-'
            ans -= int(abcd[j + 1])
        else:
            ans += int(abcd[j + 1])
    if ans == 7:
        print(str(a) + str(op[0]) + str(b) + str(op[1]) + str(c) + str(op[2]) + str(d) + '=7')
        exit()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
int main() {
 double ax,ay,bx,by,cx,cy,dx,dy;
   
   while(cin>>ax>>ay>>bx>>by>>cx>>cy>>dx>>dy){
       if(cx > bx || ax > dx || cy > by || ay > dy){
           cout<<"NO"<<endl;
       }
       else{
           cout<<"YES"<<endl;
       }
   }
  return 0;
}


Measured memory_bytes: 3204
#include<stdio.h>

int main() {
	int n, x, count = 0, i, j, k;
	while(1) {
		scanf("%d %d", &n, &x);
		if(n == 0) break;
		if(n * 3 - 3 < x) {
			puts("0");
			continue;
		}
		for(i = n; i >= 3; --i) {
			for(j = i - 1; j >= 2; --j) {
				for(k = j - 1; k >= 1; --k) {
					if(i + j + k == x) ++count;
				}
			}
		}
		printf("%d\n", count);
		count = 0;
	}
	return 0;
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(i=0;i<n;i++)
#define test(a) cout << "*" << a << endl
int main(){
  string s;
  int i,j;
  int sLongMax=0;
  int sLong=0;
  
  cin >> s;
  
  
  rep0(i,s.size()){
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
      sLong++;
      if(i==s.size()-1&&sLongMax<sLong){/*超注意*/
        sLongMax = sLong; 
      }
    }
    else{
      if(sLongMax<sLong){
        sLongMax = sLong;
      }
      sLong = 0;
    }
  }
  cout << sLongMax << endl;
    
      
      
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

char copy(const char c){return c;}

int main(){
	int n;cin>>n;
	string s;cin>>s;
	int k;cin>>k;
	k--;
	char x = copy(s[k]);
	for(int i = 0; i < s.size(); i++) {
		if (s[i] != x)s[i] = '*';
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 26.05.2018 15:08:50       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cur = 0;
  for (int i = 0; i < n; i++) {
    cur += (s[i] == 'E');
  }
  int ans = cur;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'E') {
      cur--;
    } else {
      cur++;
    }
    ans = min(ans, cur);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int n,a[100005];
bool vis[100005];
int main()
{
    cin>>n;
        long long ans=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            if(a[i])vis[i]=true;
            ans+=a[i]/2;
            a[i]%=2;
        }
        for(int i=1; i<n; i++)
        {
            if(a[i]&&a[i-1])
            {
                a[i]=0;
                a[i-1]=0;
                ans++;
            }
            else if(a[i]==0&&a[i-1])
                if(vis[i]) a[i]++,a[i-1]--;
        }
        printf("%lld\n",ans);
}

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

using namespace std;

vector<int> pn;
vector<bool> is_p;

void enum_prime()
{
  is_p.resize(1<<15, true);
  is_p[0] = is_p[1] = false;
  for(int i = 2; i < 1<<15; i++) {
    if(!is_p[i]) continue;
    pn.push_back(i);
    for(int j = i+i; j < 1<<15; j+=i) is_p[j] = false;
  }
}

int main()
{
  int n;
  enum_prime();
  while(cin >> n, n) {
    int cnt = 0;
    for(int i = 0; i < pn.size() && pn[i] < n; i++) {
      for(int j= i; j < pn.size() && pn[i] + pn[j] <= n; j++) {
	if(pn[i] + pn[j] == n) cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		
		// A C G T
		// 1 2 3 4
		// ACGTACGTACGTACGT
		// 最大値は4 + 4^2 + 4^3 + ... + 4^12 = 4(4^12 - 1) / (4 - 1) = ? 
		int max = 4 * ((1 << 24) - 1) / (4 - 1);
		boolean[] dic = new boolean[max + 1];
		
		for (int i = 0; i < n; i++) {
			String cmd = sc.next();
			String str = sc.next();
		
			if (cmd.equals("insert")) {
				dic[getHashNum(str)] = true;
			} else {
				if (dic[getHashNum(str)]) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}
	}
	
	public static int getHashNum(String str) {
		int hashNum = 0;
		for (int j = 0; j < str.length(); j++) {
			hashNum += getValueOfChar(str.charAt(j)) * Math.pow(4, str.length() - (j + 1));
		}
		return hashNum;
	}
	
	public static int getValueOfChar(char c) {
		switch (c) {
		case 'A':
			return 1;
		case 'C':
			return 2;
		case 'G':
			return 3;
		case 'T':
			return 4;
		default:
			return 0;
		}
	}
}

Measured memory_bytes: 189112
# coding: utf-8
# Your code here!

import bisect

A, B, Q = map(int, input().rstrip().split(' '))

X = [-int(1e12)] + sorted([int(input()) for _ in range(A)]) + [int(1e12)]
Y = [-int(1e12)] + sorted([int(input()) for _ in range(B)]) + [int(1e12)]

i = 1
j = 1
pos = []
near = []
if X[1] > Y[1]:
    pos.append(Y[1])
    near.append(X[1] - Y[1])
    j = 2
else:
    pos.append(X[1])
    near.append(Y[1] - X[1])
    i = 2
while True:
    if X[i] > Y[j]:
        pos.append(Y[j])
        near.append(min(X[i] - Y[j], Y[j] - X[i-1]))
        j += 1
    else:
        pos.append(X[i])
        near.append(min(Y[j] - X[i], X[i] - Y[j-1]))
        i += 1
        
    if i >= (A + 1) and j >= (B + 1):
        break

pos = [-int(1e12)] + pos + [int(1e12)]
near = [int(1e12)] + near + [int(1e12)]
    
for _ in range(Q):
    x = int(input())
    insert_index = bisect.bisect_left(pos, x)
    if pos[insert_index] - x + near[insert_index] > x - pos[insert_index-1] + near[insert_index-1]:
        print(x - pos[insert_index-1] + near[insert_index-1])
    else:
        print(pos[insert_index] - x + near[insert_index])
    

Measured memory_bytes: 25488
#include <cstdio>
#include <math.h>
using namespace std;
int main() {
	double r;
	double m, e;
	scanf("%lf", &r);
	m = r * r * M_PI;
	e = 2 * r * M_PI;
	printf("%lf %lf\n", m, e);
}


Measured memory_bytes: 2668
#include<iostream>
#include <iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

ll n,h[100010],g[100010],a,b;

bool can(ll x){
    ll s=a-b,cnt=0;
    rep(i,n){
        g[i]=h[i];
        g[i]-=b*x;
        if(g[i]>0){
            cnt+=g[i]/s+bool(g[i]%s);
        }
    }
    if(cnt<=x) return true;
    else return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    rep(i,n)cin>>h[i];
    sort(h,h+n);
    ll M=1e9+1,m=0; 
    while(M>m){
        ll mid=(M+m)/2;
        if(can(mid)) M=mid;
        else m=mid+1;
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int x,a,b; cin>>x>>a>>b;
	int u=abs(x-a),v=abs(x-b);
	if (u>v) cout<<"B";
	else cout<<"A";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lim 200005
#define pb push_back
#define S second
#define pb push_back
#define mp make_pair
#define INF 1e16
#define fr(i,j,k) for(ll i=j;i<=k;i++)
#define frd(i,j,k) for(ll i=j;i>=k;i--)
#define F first
#define sd(n) scanf("%lld",&n)
#define pd(n) printf("%lld\n",n)
#define db double
#define mod 1000000007
#define pii pair<ll,ll>
int main()
{
    ll n;
    cin>>n;
    ll o=0,e=0;
    ll x;
    
    while(n--)
    {
        sd(x);
        if(x&1)
            o++;
        else e++;
    }

    if(o&1)
    {
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;

    

}

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

int main() {
	// your code goes here


	
	ll x;
	cin>>x;
	for(int a=0;a<1000;a++)
	{
		for(int b=-1000;b<1000;b++)
		{
			ll A=pow(a,5);
			ll B=pow(b,5);
			if(A-B==x)
			{
				cout<<a<<" "<<b;
				return 0;
			}
		}
	}

	
	return 0;
}

Measured memory_bytes: 4088
#include <stdio.h>

int main(void) {
    char s[4];

    scanf("%s", s);
    for (int i = 0; i < 3; i++) {
        if (s[i] == '1')
            printf("9");
        else if (s[i] == '9')
            printf("1");
        else
            printf("%c", s[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
SIZE=5*10**3; MOD=10**9+7 #998244353 #ここを変更する

SIZE += 1
inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
fac = [0]*SIZE  # fac[j] = j! mod MOD
finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE):
    fac[i] = fac[i-1]*i%MOD
finv[-1] = pow(fac[-1],MOD-2,MOD)
for i in range(SIZE-1,0,-1):
    finv[i-1] = finv[i]*i%MOD
    inv[i] = finv[i]*fac[i-1]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0

def chofuku(ball,box): # nHk mod MOD の計算
    return choose(box+ball-1,box)

# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

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



dp = [0]*(n+1) # i まで見て、x人グループが決まっている
dp[0] = 1


#for i in range(b,a-1,-1):
for i in range(a,b+1):
    invmod = [1]
    for p in range(1001//i+2): invmod.append(invmod[-1]*finv[i]%MOD)
    coeff = [fac[i*p]*invmod[p]%MOD*finv[p]%MOD for p in range(1001//i+2)]    
    
    ndp = dp[:]
    for j in range(n+1):
        for p in range(c,d+1):
            if j+i*p > n: break
            ndp[j+i*p] += coeff[p]*dp[j]%MOD*choose(n-j,i*p)
            ndp[j+i*p] %= MOD

    #print(invmod,i)
    #print(coeff)
    dp = ndp
    #if i < 100:break
    #print(dp,i)    
print(dp[n]%MOD)    
    






    
    
    
    

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

int main() {
  int a = 0;
  int b = 0;
  int c = 0;
  int ans = 0;
  cin >> a >> b >> c;
  ans = b / a;
  if(ans >= c){
    cout << c << endl;
  }
  if(ans < c){
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
def popcount(x):
    return bin(x)[2:].count("1")

def f(x):
    cnt=0
    while(x>0):
        x%=popcount(x)
        cnt+=1
    return cnt

n=int(input())
s=input()
d=s.count("1")
if d==0:
    for i in range(n):
        print(1)
elif d==1:
    if s[-1]=="1":
        for i in range(n-1):
            print(2)
        else:
            print(0)
    else:
        for i in range(n-1):
            if s[i]=="1":
                print(0)
            else:
                print(1)
        print(2)
else:
    s=s[::-1]
    toaddm=1
    toaddM=1
    m=0
    M=0
    for i in range(n):
        if s[i]=="1":
            m+=toaddm
            M+=toaddM
            m%=d-1
            M%=d+1
        toaddm*=2
        toaddm%=d-1
        toaddM*=2
        toaddM%=d+1
    toaddm=-1
    toaddM=1
    res=[None for i in range(n)]
    for i in range(n):
        if s[i]=="1":
            res[i]=f((m+toaddm)%(d-1))+1
        else:
            res[i]=f((M+toaddM)%(d+1))+1
        toaddm*=2
        toaddm%=d-1
        toaddM*=2
        toaddM%=d+1
    for i in res[::-1]:
        print(i)


Measured memory_bytes: 82376
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define pb         push_back

vector<int> edge[26];
vector<int> out[26];

void dfs(int now,bool *vis){
  if (vis[now])return;
  //cout <<(char)('a'+now) << endl;
  vis[now]=true;
  rep(i,edge[now].size()){
    dfs(edge[now][i],vis);
  }
}

bool iseul(){
  //  rep(i,26){
  //    cout << (char)('a'+i)  <<" " <<out[i].size()+ edge[i].size() <<endl;
  //  }

  rep(i,26){
    if ((out[i].size()+edge[i].size())%2 == 1)return false;
    if (out[i].size() != edge[i].size())return false;
  }

  bool vis[26]={false};
  int last=0;
  rep(i,26)if (out[i].size() != 0 || edge[i].size() != 0){
    //cout <<"call " << (char)('a' + i) << endl;
    dfs(i,vis);
    last=i+1;
    break;
  }
  REP(i,last,26){
    if (!vis[i] && (out[i].size()!=0|| edge[i].size() != 0)){
      return false;
    }
  }
  return true;
}

main(){
  int n;
  while(cin>>n && n){
    rep(i,26)edge[i].clear(),out[i].clear();
    int cnt=0;
    rep(i,n){
      string a;
      cin>>a;
      int st=a[0]-'a',ed=a[a.size()-1]-'a';
      edge[st].pb(ed);
      out[ed].pb(st);
    }

    if (iseul())cout <<"OK"<<endl;
    else cout <<"NG"<<endl;
  }
}

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

if n == 0:
    if a[0] == 1:
        print(1)
    else:
        print(-1)
    exit()
if a[0] != 0:
    print(-1)
    exit()

s = sum(a)
ans = 1
m = 1
flag = True
for i in range(1, n+1):
    if flag:
        m *= 2
        if m > s:
            m = s
            flag = False
    ans += m
    if a[i] > m:
        print(-1)
        exit()
    m -= a[i]
    s -= a[i]

print(ans)

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

int main() {
    int h,w;
    while (cin>>h>>w,h!=0&&w!=0)
    {
        for (int i = 0; i < h; ++i) {
            if (i % 2 == 0)
            {
                for (int j = 0; j < w; ++j)
                {
                    if (j % 2 == 0)
                        cout << "#";
                    else
                        cout<<".";
                }
                cout << endl;
            }
            else
            {
                for (int j = 0; j < w; ++j) {
                    if (j % 2 == 1)
                        cout << "#";
                    else
                        cout << ".";
                }
                cout << endl;
            }
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int op(int a, int b) {
  return max(a, b);
}

int e() {
  return 0;
}

int main2() {
  int N = nextLong();
  int K = nextLong();

  const int L = 300000;
  atcoder::segtree<int, op, e> seg(L + 10);

  vector<int> A(N);
  vector<int> dp(N+1);
  REP(i, N) A[i] = nextLong();

  for (int i = 0; i < N; i++) {
    ll val = seg.prod(
      max(0, A[i] - K),
      min(L, A[i] + K) + 1
    );

    dp[i] = val + 1;

    if (seg.get(A[i]) < dp[i]) {
      seg.set(A[i], dp[i]);
    }
  }

  ll ans = *max_element(ALL(dp));
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 9656
<?php
  list($h,$w) = explode(" ", trim(fgets(STDIN)));

  $s = [];
  for($i=0;$i<$h;$i++){
    list($a) = explode(" ", trim(fgets(STDIN)));
    $s[] = str_split($a);
  }

  $x=[];
  for($i=0;$i<$h;$i++){
    $b=true;
    for($j=0;$j<$w;$j++){
      if($s[$i][$j] == '#'){
        $b=false;
        break;
      }
    }
    if($b){
      $x[$i]=true;
    }
  }

  $y=[];
  for($i=0;$i<$w;$i++){
    $b=true;
    for($j=0;$j<$h;$j++){
      if($s[$j][$i] == '#'){
        $b=false;
        break;
      }
    }
    if($b){
      $y[$i]=true;
    }
  }
  for($i=0;$i<$h;$i++){
    if(isset($x[$i])){
      continue;
    }
    for($j=0;$j<$w;$j++){
      if(isset($y[$j])){
        continue;
      }
      echo $s[$i][$j];
    }
    echo PHP_EOL;
  }

Measured memory_bytes: 16904
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
int factorial(int n)
{
    int x = 1; // 0! = 1

    for (int i = 1; i <= n; ++i)
        x *= i;

    return x;
}

int main()
{
    int N;
    ll pnum=0;
    ll qnum=0;
    cin>>N;
    int P[N]={0};
    int Q[N]={0};

    for(int i=0;i<N;i++)
    {
        cin>>P[i];
    }
    for(int i=0;i<N;i++)
    {
        cin>>Q[i];
    }
    int keta=N-1;
    for(int i=0;i<N;i++)
    {
        int pcount=0;
        int qcount=0;
        for(int j=0;j<i;j++)
        {
            if(P[j]<P[i])pcount++;
            if(Q[j]<Q[i])qcount++;

        }
        int pscore=P[i]-1-pcount;
        int qscore=Q[i]-1-qcount;
        if(pscore<0)pscore=0;
        if(qscore<0)qscore=0;
        pnum+=pscore*factorial(keta);
        qnum+=qscore*factorial(keta);
        
        keta-=1;
    }
    pnum++;
    qnum++;

    cout<<abs(pnum-qnum)<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  }
  int ans = INF;
  rep(i,N) {
    int cnt = 0;
    while(A[i]&&A[i]%2==0) {
      A[i] >>= 1;
      cnt++;
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;

  return 0;
}

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

int main(){
  long long n;
  long long s=0;
  cin >> n;
  for(long long i=1;i<=n;i++){
    if(i%5!=0 && i%3!=0){
      s+=i;
    }
  }
  cout << s;
  return 0;
}


Measured memory_bytes: 3576
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        Deque<Integer> stack = new ArrayDeque<Integer>();

        while(sc.hasNext()) {
            String n = sc.next();
            if (n.equals("+")){
                int a = stack.pop()+stack.pop();
                stack.push(a);
            } else if (n.equals("-")){
                int x = stack.pop();
                int y = stack.pop();
                int a = y-x;
                stack.push(a);
            } else if (n.equals("*")) {
                int a = stack.pop()*stack.pop();
                stack.push(a);
            } else {
                stack.push(Integer.parseInt(n));
            }
            
        }
        System.out.println(stack.pop());
        
    }
}



Measured memory_bytes: 26268
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
int main() {
	string s;
	cin >> s;

	int n = s.size();

	int zero = 0;
	int one = 0;
	rep(i, n) {
		if (s[i] == '1') {
			one++;
		}
		else {
			zero++;
		}
	}
	cout << 2 * min(zero, one) << endl;
}

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

int64_t cal(int64_t n){
	return n*(n-1)/2;
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>a(n),c(n,0);
	for(auto&i:a){
		cin>>i;
		++c.at(--i);
	}
	int64_t ans=0;
	for(auto&i:c)ans+=cal(i);
	for(auto&i:a){
		cout<<ans-cal(c.at(i))+cal(c.at(i)-1)<<"\n"s;
	}
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    if (n<=k){
        cout<<x*n<<endl;
    }else{
        cout<<x*k+(n-k)*y<<endl;
    }
    return 0;

}

Measured memory_bytes: 256