akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt(),f=1,bf=1;
    char[] ch=sc.next().toCharArray();
    for(int i=0;i<n;i++){
      if(ch[i]=='a'){
        if(f<=a+b){
          System.out.println("Yes");
          f++;
        }else{
          System.out.println("No");
        }
      }else if(ch[i]=='b'){
        if(f<=a+b&&bf<=b){
          System.out.println("Yes");
          f++;
          bf++;
        }else{
          System.out.println("No");
        }
      }else{
        System.out.println("No");
      }
    }
  }
}


Measured memory_bytes: 36916
N, K = map(int, input().split())
def Base_10_to_n(N, K):
    if (int(N/K)):
        return Base_10_to_n(int(N/K), K)+str(N%K)
    return str(N%K)

x10 = 35
x2 = Base_10_to_n(N, K)
x2 = str(x2)
print(len(x2))

Measured memory_bytes: 3060
#  --*-coding:utf-8-*--

N = int(input())
A = list(int(input()) for _ in range(N))

s = 0
s2 = 0

for a in A:
    if a != 0:
        s2 += a
    else:
        s += s2//2
        s2 = 0

s += s2//2

print(s)


Measured memory_bytes: 7084
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::{fastout, input, marker::*};
use std::collections::*;
//use std::cmp::*;
//use std::num;
//use petgraph::unionfind::UnionFind;

#[fastout()]
fn main() {
    input! {
      mut N:usize
    }

    let mut ans = vec![0usize; N + 1];
    for x in 1..=100 {
        if N <= x * x {
            break;
        }
        for y in 1..=(N - x * x) {
            if N <= x * x + y * y {
                break;
            }
            for z in 1..=(N - x * x - y * y) {
                let t = x * x + y * y + z * z + x * y + y * z + z * x;
                if t <= N {
                    ans[t] += 1;
                }
            }
        }
    }

    for i in 1..=N {
        println!("{}", ans[i]);
    }
}


Measured memory_bytes: 2156
#include<iostream>
#include<cmath>
#include<stdio.h>

using namespace std;

int main(){
  string a,b; cin >> a >> b; string d  = a + b;  int c = stoi(d);
  
  int root = (int)sqrt((double) c);
  
  if(root * root == c){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
  
  return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1'000'100, mod = 1'000'000'007;
int add(int a, int b){
	a += b;
	if(a >= mod) a -= mod;
	return a;
}
int sub(int a, int b){
	return add(a, mod - b);
}
int mul(long long a, long long b){
	return a * b % mod;
}
int pwr(long long a, long long b){
	int r = 1;
	for(; b; b >>= 1, a = mul(a, a)) if(b&1) r = mul(r, a);
	return r;
}
int fat[maxn], ifat[maxn];
void init(){
	fat[0] = 1;
	for(int i = 1; i < maxn; i++) fat[i] = mul(i, fat[i - 1]);
	ifat[maxn - 1] = pwr(fat[maxn - 1], mod - 2);
	for(int i = maxn - 2; i >= 0; i--) ifat[i] = mul(i + 1, ifat[i + 1]);
}
int ncr(int n, int r){
	if(n < r) return 0;
	return mul(fat[n], mul(ifat[r], ifat[n - r]));
}
int main(){
	init();
	int n; cin >> n;
	int ans = 0, comp = 0;
	for(int i = 1; i <= n - 1; i++){
		int ways = mul(ncr(i - 1, n - 1 - i), mul(fat[i], mul(fat[n - 1 - i], 1)));
		ans = add(ans, mul(sub(ways, comp), i));
		comp = ways;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8064
# https://atcoder.jp/contests/abc158/tasks/abc158_d
from collections import deque

S = input()
Q = int(input())

is_reverse = False
text = deque(S)
for _ in range(Q):
    query = input()
    if query[0] == '1':
        is_reverse = not is_reverse
    else:
        if query[2] == '1':
            if is_reverse:
                text.append(query[4])
            else:
                text.appendleft(query[4])
        else:
            if is_reverse:
                text.appendleft(query[4])
            else:
                text.append(query[4])

if is_reverse:
    print(''.join(text)[::-1])
else:
    print(''.join(text))


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

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

    int a;
    string s;

    cin >> a >> s;

    if (a >= 3200) {
        cout << s;
    } else {
        cout << "red";
    }

}

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

typedef long long LL;
const int MAXN=1e5+5;
const int MAXM=1e5+5;
const int mod=1e9+7;
const int INF=1e9+7;

int n,m;

int main(){
	cin>>n>>m;
	int num=1<<m;
	cout<<num*(1900*m+(n-m)*100)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  string s, t;
  cin >> s;
  cin >> t;
  
  for (int i=0; i< s.length(); i++){
    if(s[i] != t[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#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++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  long double W,H,x,y;
  cin >> W >> H >> x >> y;

  int flag = 0;
  if(W/2.0==x&&H/2.0==y){
    flag = 1;
  }

  cout << fixed << setprecision(10) << W*H/2.0 << " " << flag << endl; 
}

Measured memory_bytes: 256
import sys

def CountingSort(A,B,k,n):

	C = [0] * k

	for i in range(n):
		C[A[i]] += 1

	for i in range(1,k):
		C[i] = C[i] + C[i-1]

	for i in range(n-1,-1,-1):
		B[C[A[i]]-1] = A[i]
		C[A[i]] -= 1


def test():

	n = int(sys.stdin.readline())
	A = list(map(int,sys.stdin.readline().split()))

	B = [0] * n

	max = 0
	for i in range(n):
		if max < A[i]:
			max = A[i]

	CountingSort(A,B,max+1,n)
	
	for i in range(n-1):
		print(f"{B[i]} ",end='')
	print(B[n-1])


if __name__ == "__main__":
	test()



Measured memory_bytes: 225716
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()
 
const int MOD = 1000000007;
 
int main() {
  char x;
  cin >> x;
  
  int y = (int)x-(int)('a');
    
  if(0<=y&&y<26) cout << 'a' <<endl;
  
  else cout << 'A' << endl;
  
 
return 0;
 
}

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

const int N=400005;
int id,b[25];
long long n,a[25],now;

int main()
{
	scanf("%lld",&n);
//	cout<<n<<endl;
	for(int i=1;i<=20;i++)
	{
		a[i]=a[i-1]*26+26;
//		cout<<a[i]<<endl;
		if(a[i]>=n)
		{
			id=i;
			break;
		}
	}
	n-=a[id-1]+1;
	while(n)
	{
		b[++b[0]]=n%26;
		n/=26;
	}
	for(int i=1;i<=id;i++) printf("%c",'a'+b[id-i+1]);
}

Measured memory_bytes: 3684
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {

    int a,b;
    cin >> a >> b;
    if(a==b){
        cout << a+b << endl;
    }else{
        int c = max(a,b);
        cout << 2*c - 1 << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;
int sum[1010];

int c[1000000];

int main(){
	for (int i = 0; i <= 1000; i++){
		sum[i] = i;
	}
	for (int i = 0; i < 1000; i++){
		sum[i + 1] += sum[i];
	}

	for (int i = 0; i <= 1000; i++){
		for (int j = i+1; j <= 1000; j++){
			int k = sum[j] - sum[i];
			if (k != i&&k != j){
				c[k]++;
			}
		}
	}

	while (cin >> n&&n){
		cout << c[n] << endl;
	}
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const ll mod=1e9+7;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	for(ll i=k;i<=n+1;i++)
	{
		ll z = (i*(i-1))/2;
		ll a = (n*(n+1))/2-((n-i)*(n-i+1))/2;
		ans=(ans+a-z+1)%mod;
	}
	cout<<ans<<"\n";
	return 0;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int h, w, d;
    cin >> h >> w >> d;
    vint need(h * w, 0);
    vector<pint> pos(h * w);
    rep(i, h) rep(j, w)
    {
        int a;
        cin >> a;
        --a;
        pos[a] = make_pair(i, j);
    }

    rep(i, h * w - d)
    {
        int cost = abs(pos[i + d].first - pos[i].first) + abs(pos[i + d].second - pos[i].second);

        need[i + d] = need[i] + cost;
    }

    int q;
    cin >> q;
    rep(i, q)
    {
        int l, r;
        cin >> l >> r;
        --l;
        --r;
        ll ans = need[r] - need[l];
        cout << ans << endl;
    }
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 2176
#include<iostream>

using namespace::std;
#define int long long int
#define MOD 1000000007
int dp[3005][3005],pre[3005][2];

main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int j=1;j<n;j++)
		dp[0][j]=1;

	for(int i=1;i<n;i++){
		for(int j=1;j<=i+1;j++)
			if(s[i-1]=='<')
				dp[i][j]=dp[i-1][j-1];
			else dp[i][j]=(dp[i-1][i]-dp[i-1][j-1]+MOD)%MOD;
		for(int j=1;j<=n;j++)
			dp[i][j]=(dp[i][j]+dp[i][j-1])%MOD;
	}
	// int ans=0;
	// for(int i=1;i<=n;i++)
	// 	ans=(ans+dp[n-1][i])%MOD;
	// cout<<ans<<'\n';
	cout<<dp[n-1][n]<<'\n';
	// for(int j=n;j>0;cout<<'\n',j--)
	// 	for(int i=0;i<n;i++)
	// 		cout<<dp[i][j]<<' ';
}

Measured memory_bytes: 70656
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;

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

void Main()
{
	int n; cin >> n;
	VI d(n);
	REP(i, n) cin >> d[i];

	LL sum = 0;
	REP(i,n){
		FOR(j,i+1,n){
			sum += d[i] * d[j];
		}
	}

	cout << sum << endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

long long n, t, ans = 1, c[1005];
int main()
{
    int i, j;
    cin >> n;
    for (i = 2; i <= n; i++) {
        t = i;
        for (j = 2; t > 1; j++) {
			while (t % j == 0) {
				t /= j;
				c[j]++;
			}
        }
    }
    for (i = 2; i <= n; i++) ans = ans * (c[i] + 1) % 1000000007;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*
*
*Problem Link : https://atcoder.jp/contests/dp/tasks/dp_l
*Platform: atcoder
*Status: correct
*Author: Mayukh Chakrabarti
*
*/

#include<bits/stdc++.h>
#define speed ios_base::sync_with_stdio(false)
#define boost cin.tie(NULL)
#define booster cout.tie(NULL)
#define endl "\n"
typedef long long int lld;

#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;

using namespace std;


const int x = 3005;
lld dp[x][x];

int main() {
    int n;
    cin>>n;
    
    vector<int> a(n);
    
    F(a,n);
 
    for(int L = n - 1; L >= 0; --L) {
        for(int R = L; R < n; ++R) {
            if(L == R) {
                dp[L][R] = a[L];
            }
            else {
                dp[L][R] = max(a[L] - dp[L+1][R], a[R] - dp[L][R-1]);
            }
        }
    }
    
   	cout<<dp[0][n-1];
   	
   	return 0;
}


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

//ノード
struct node{
  unsigned int key;
  struct node *next;//ノードの接続先
  struct node *prev;//ノードの接続元
};


typedef struct node * NodePointer;

//ノード列
NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
}

//nilの初期化
void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

//リストの表示
void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

//void deleteNode(NodePointer t){
/* your code */
//}

void deleteFirst(){
  NodePointer t = nil->next;
  //printf("first in\n");
  if ( t == nil ){
    return;
  }else{
    t->prev->next = t->next;
    t->next->prev = t->prev;
  }
  //printf("first out\n" );
}

void deleteLast(){
  NodePointer t = nil->prev;
  //printf("last in\n" );
  if ( t == nil ){
    return;
  }else{
    t->prev->next = t->next;
    t->next->prev = t->prev;
  }
  //printf("last out\n" );
}

void delete(int key){
  NodePointer x=nil;
  while(1){
    x = x->next;
    if (x->key == key) {
      x->prev->next = x->next;
      x->next->prev = x->prev;
      break;
    }
    if (x->next==nil) {
      break;
    }
  }
}

void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];//命令 insert or delete
  int np = 0, nd = 0;
  //命令数の入力
  scanf("%d", &n);
  init();
  //命令数分だけ命令を入力する
  for ( i = 0; i < n; i++ ){
    //printf("roop[%d]\n",i );
    scanf("%s %d", com, &key);
    //printf("scan[%d]\n",i );
    if ( com[0] == 'i' ){
      insert(key);
      np++;
      size++;
    }
    else if ( com[0] == 'd' ){
      if (strlen(com) > 6){
        if ( com[6] == 'F' ){
          deleteFirst();
          //printf("back from first\n");
        }else if ( com[6] == 'L' ){
          //printf("delete last now\n" );
          deleteLast();
          //printf("last\n" );
        }
      }else {
        delete(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}



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

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

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


#define MAXM 100010
vl fact(MAXM);
vl C(MAXM);

ll mod_pow(ll x, ll p, ll M) {
	ll a = 1;
	while (p) {
		if (p % 2)
			a = a*x%MOD;
		x = x*x%MOD;
		p /= 2;
	}
	return a;
}

ll mod_inverse(ll a, ll m) {
	return mod_pow(a, m - 2, m);
}

ll nCr(ll n, ll r) {
	ll ret = fact[n];
	ret = (ret*mod_inverse(fact[r], MOD)) % MOD;
	ret = (ret*mod_inverse(fact[n - r], MOD)) % MOD;
	return ret;
}


int main() {
	ll n, m, i, j;
	cin >> n >> m;
	
	fact[0] = fact[1] = 1LL;
	for (i = 2; i < max(n, m) + 1; i++) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	vl x(n), y(m);
	for (i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (j = 0; j < m; j++) {
		cin >> y[j];
	}
	vl sx(n - 1);
	ll sumx = 0;
	for (i = 0; i < n - 1; i++) {
		sx[i] = x[i + 1] - x[i];
		sx[i] = sx[i] * (i + 1) % MOD * (n - i - 1) % MOD;
		sumx += sx[i];
		sumx %= MOD;
	}

	vl sy(m - 1);
	ll ans = 0;
	for (i = 0; i < m - 1; i++) {
		sy[i] = y[i + 1] - y[i];
		sy[i] = sy[i] * (i + 1) % MOD * (m - i - 1) % MOD;
		ans += sy[i] * sumx % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String S = sc.next();
		int[] K = new int[S.length()];
		for (int i = 0; i < K.length; i++) {
			K[i] = S.charAt(i) - '0';
		}
		int D = sc.nextInt();

		final long MOD = 1000000007;

		sc.close();

		// 上限ぴったり
		long[][] dpj = new long[D][K.length];
		// 上限未満
		long[][] dps = new long[D][K.length];

		// 初期化
		dpj[K[0] % D][0] = 1;

		for (int i = 0; i < K[0]; i++) {
			dps[i % D][0]++;
		}

		// 配るdp
		for (int i = 0; i < K.length - 1; i++) {
			// ぴったりからぴったりへ遷移
			for (int j = 0; j < D; j++) {
				dpj[(j + K[i + 1]) % D][i + 1] += dpj[j][i];
				dpj[(j + K[i + 1]) % D][i + 1] %= MOD;
			}

			// ぴったりから未満へ遷移
			for (int j = 0; j < D; j++) {
				for (int k = 0; k < K[i + 1]; k++) {
					dps[(j + k) % D][i + 1] += dpj[j][i];
					dps[(j + k) % D][i + 1] %= MOD;
				}
			}

			// 未満から未満へ遷移
			for (int j = 0; j < D; j++) {
				for (int k = 0; k <= 9; k++) {
					dps[(j + k) % D][i + 1] += dps[j][i];
					dps[(j + k) % D][i + 1] %= MOD;
				}
			}
		}

		long ans = dps[0][K.length - 1] + dpj[0][K.length - 1] - 1; // 0が含まれているので、1つ引く
		out.println((ans + MOD) % MOD);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 52948
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()
    pre = [None] * n

    ans = 0
    for i, j in enumerate(t):
        if i < k or j != pre[i-k]:
            pre[i] = j
            if j == 'r':
                ans += p
            elif j == 's':
                ans += r
            else:
                ans += s
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4084
program  ABC_083_A_Libra
   implicit none
   integer A, B, C, D, L, R
   read(*, *) A, B, C, D
   L = A + B
   R = C + D
   if( L > R ) then
       write(*, *) 'Left'
   else if( L == R ) then
       write(*, *) 'Balanced'
   else
       write(*, *) 'Right'
   end if
end program  ABC_083_A_Libra

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			
			String s = sc.next();
			if("0".equals(s)){
				break;
			}
			char[] chars = s.toCharArray();
			int sum = 0;
			for(char c : chars){
				sum += (int)c - 3 * 16;
			}
			System.out.println(sum);
		}
	}
}



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

#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 << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long LL;

const int INF = 0x3f3f3f3f;
const int maxn = 1e6+5;
const int MOD = 1e9+7;


LL binpow(LL x, LL n, LL p) {
    x %= p;
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % p;
        x = x * x % p;
        n >>= 1;
    }
    return res;
}

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

    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    vector<int> sp(maxn, 0);
    unordered_map<int, int> m;

    for (int i = 2; i < maxn; i+=2) sp[i] = 2;
    for (LL i = 3; i < maxn; i+=2) {
        if (!sp[i]) {
            sp[i] = i;
            for (LL j = i; (j*i) < maxn; j+=2) {
                if (!sp[j*i]) {
                    sp[j*i] = i;
                }
            }
        }
    }

    for (auto x : a) {
        unordered_map<int, int> cur_m;
        while (x > 1) {
            ++cur_m[sp[x]];
            x /= sp[x];
        }

        for (const auto& item : cur_m) {
            m[item.first] = max(m[item.first], item.second);
        }
    }

    LL lcm = 1;
    for (const auto& item : m) {
        for (int i = 0; i < item.second; ++i) {
            lcm *= item.first;
            lcm %= MOD;
        }
    }

    LL ans = 0;
    for (auto x : a) {
        ans += (lcm * binpow(x, MOD-2, MOD));
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4608
#include <iostream>
using namespace std;
int main(){
  int x, i;
  cin >> x;
  if(x == 2){
    cout << 2 << endl;
    return 0;
  }
  if(x % 2 == 0){
    i = x + 1;
  }else{
    i = x;
  }
  bool prime = false;
  while(1){
    prime = true;
    for(int j = 3; j * j <= i; j += 2){
      if(i % j == 0){
        prime = false;
        break;
      }
    }
    if(prime){
      cout << i << endl;
      return 0;
    }
    i += 2;
  }
  return 0;
}

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

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    if((100*r + 10*g + b) % 4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# 出てきた順に辞書に追加してインクリメント
# N<=10^5なので余裕
n = gets.to_i
table = {}
gets.chomp.split.map(&:to_i).each do |i|
  if table[i].nil?
    table[i] = 1
  else
    table[i] += 1
  end
end

c = 0 
table.each do |k, v|
  if !(v.zero?)
    if k<v
      c += v-k
    elsif v<k
      c += v
    end
  end
end

puts c

Measured memory_bytes: 15492
n,m = map(int,input().split())
h = list(map(int,input().split()))
A = []
B = []
h_new = [0]*n
c = 0
for i in range(m):
    a,b = map(int,input().split())
    A += [a]
    B += [b]
    
for i in range(m):
    h_new[A[i]-1] = max(h[B[i]-1],h_new[A[i]-1])
    h_new[B[i]-1] = max(h_new[B[i]-1],h[A[i]-1])
    
for i in range(n):
    if h[i] > h_new[i]:
        c += 1
print(c)

Measured memory_bytes: 22952
# author:  Taichicchi
# created: 29.09.2020 22:54:27

import sys

N, K = map(int, input().split())

x = list(map(int, input().split()))


ans = 10 ** 18

for i in range(N - K + 1):
    ans = min(ans, min(abs(x[i]) + abs(x[i] - x[i + K - 1]),
                       abs(x[i + K - 1]) + abs(x[i] - x[i + K - 1])))

print(ans)


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

int main() {
  int n;
  cin>>n;
  int cnt = 0;
  for (int i=9; i<=n; i+=2) {
    int nd = 0;
    for (int j=1; j<=i; j++) {
      if (i % j == 0) {
        ++nd;
      }
    }
    if (nd == 8) {
      ++cnt;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll n;
    cin >> n;
    vector<ll> ans(n, n*(n-1)/2);
    vector<int> sub(n, 1), cnt(n);
    vector<int> C(n);
    for (auto &&i : C) scanf("%d", &i), i--, ans[i]++;
    vector<vector<int>> G(n);
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    int up = 0;
    auto dfs = [&](int i, int par, auto &&f) -> void {
        int tmp = cnt[C[i]];
        for (auto &&j : G[i]) {
            if(j == par) continue;
            ll x = -(up-cnt[C[i]]);
            f(j, i, f);
            sub[i] += sub[j];
            x += up-cnt[C[i]];
            ans[C[i]] -= x*(x-1)/2;
        }
        up++;
        cnt[C[i]] = tmp+sub[i];
    };
    dfs(0, -1, dfs);
    for (int i = 0; i < n; ++i){
        printf("%lld\n", ans[i]-(n-cnt[i])*(n-cnt[i]-1)/2);
    }
    return 0;
}

Measured memory_bytes: 36848
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

ll gcd(ll x, ll y) {
  if(x > y)
    return gcd(y, x);
  else if(x == 0)
    return y;
  else
    return gcd(y % x, x);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  ll ans = A[0];
  rep(i, n) ans = gcd(A[i], ans);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3996
import java.util.Scanner;
class Main  {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a <= c && c <= b) {
			System.out.println("Yes");	
		}
		else {
			System.out.println("No");
		}  
	}	
}

Measured memory_bytes: 24020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

llint n;
string s[10005];
vector<int> veca, vecb, vecba, vec;

int main(void)
{
	cin >> n;
	for(int i = 0; i < n; i++) cin >> s[i];
	
	int acnt = 0, bcnt = 0;
	for(int i = 0; i < n; i++){
		if(s[i][s[i].size()-1] == 'A' && s[i][0] == 'B') vecba.push_back(i);
		else if(s[i][0] == 'B') vecb.push_back(i);
		else if(s[i][s[i].size()-1] == 'A') veca.push_back(i);
		else vec.push_back(i);
	}
	
	string S;
	if(veca.size() > 0) S += s[veca.back()], veca.pop_back();
	for(int i = 0; i < vecba.size(); i++) S += s[vecba[i]];
	
	while(veca.size() || vecb.size()){
		if(vecb.size()) S += s[vecb.back()], vecb.pop_back();
		if(veca.size()) S += s[veca.back()], veca.pop_back();
	}
	for(int i = 0; i < vec.size(); i++) S += s[vec[i]];
	
	//cout << S << endl;
	
	llint ans = 0;
	for(int i = 1; i < S.size(); i++){
		if(S[i-1] == 'A' && S[i] == 'B') ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

ll BASE_NUM = 1000000007;
ll my_pow(ll x,ll y){
    if (y == 0){
        return 1LL;
    }else if(y == 1){
        return x;
    }else{
        ll y_2 =my_pow(x,y/2) % BASE_NUM;
        ll yy = (y_2 * y_2) % BASE_NUM;
        if (y % 2 == 0){
            return yy;
        }else{
            return (yy * x) % BASE_NUM;
        }
    }
}

int main()
{
    // 整数の入力
    ll N;
    vector<ll> A;
    cin >> N;
    for(int i = 0;i<N;i++){
        ll a;
        cin >> a;
        A.push_back(a);
    }
    ll value = 0;
    for(int i = 0;i<60;i++){
        ll ones = 0;
        ll zeros = 0;
        for(int j = 0;j<N;j++){
            if (A[j] & (1LL<<i)){
                ones++;
            }else{
                zeros++;
            }
        }
        // cout << ones << " " << zeros << endl;
        ll patterns = ones * zeros % BASE_NUM;
        ll current_sum = patterns * my_pow(2,i) % BASE_NUM;
        value = (value + current_sum) % BASE_NUM;
    }

    cout << value << endl;

    return 0;
}

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

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

using namespace std;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dx[4]={1, 0, -1, 0};
int dy[4]={0, -1, 0, 1};

int main()
{
  int h, w;
  cin >> h >> w;

  char maze[h][w];
  for(int i=0; i<h; i++)
    for(int j=0; j<w; j++)
      cin>>maze[i][j];

  ll d[h][w];
  for(int i=0; i<h; i++)
    for(int j=0; j<w; j++)
      d[i][j] = -1;
  
  d[0][0]=1;
  
  queue<P> q;
  q.push(P(0, 0));
    
  while(!q.empty())
    {
      P tmp = q.front();
      q.pop();
      ll cx = tmp.first;
      ll cy = tmp.second;

      if(cx==w-1 && cy==h-1)
	break;
      
      for(int i=0; i<4; i++)
	{
	  ll tx=cx+dx[i];
	  ll ty=cy+dy[i];

	  if(-1<tx && tx<w && -1<ty && ty<h && maze[ty][tx]=='.' && d[ty][tx]==-1)
	    {
	      d[ty][tx] = d[cy][cx]+1;
	      q.push(P(tx, ty));
	    }
	}
    }

  if(d[h-1][w-1]==-1)
    {
      cout << -1 << endl;
      return 0;
    }

  ll count = -d[h-1][w-1];


  for(int i=0; i<h; i++)
    for(int j=0; j<w; j++)
      {
	if(maze[i][j]=='.')
	  {
	    maze[i][j]='#';
	    count++;
	  }
      }

  cout << count << endl;
  

  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,k,s;
  while(1){
    cin>>n>>k>>s;
    if(n==0 && k==0 && s==0)break;
    int ans=0,bit;
    rep(bit,1<<n){
      int tmp=0,sum=0;
      rep(i,n)
        if(bit&1<<i){//i?????????bit????????£???????????°            
          tmp++;
          sum+=i+1;
        }
      if(tmp==k && sum==s)ans++;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 2984
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =2e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
//ai/aj!=0(1=<j<=n) 
int need[1000005];
int a[MAXN];
int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	if(y>=x*2&&y<=x*4&&y%2==0) printf("Yes\n");
	else printf("No\n");
	return 0;
} 

Measured memory_bytes: 3764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt(), b = in.nextInt();
		int total = b * 2;
		if (total >= a)
			System.out.println(0);
		else
			System.out.println(a - total);
	}
}

Measured memory_bytes: 23508
using System;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
           while(true)
           {

                string Date = Console.ReadLine();
                string[] date = Date.Split(' ');
                int H = int.Parse(date[0]);
                int W = int.Parse(date[1]);

                if (H == 0 && W == 0)       //H,W??±???0????????????
                {
                    break;
                }
                for(int i = 1; i <= H; i++)
                {
                    for (int n = 1; n < W; ++n)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine("#");
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 8780
using System;
class Program
 {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            for(int i = 0; i < str.Length; i++) {
                string tmp = str[i].ToUpper();
                Console.Write(tmp[0]);
            }
            Console.WriteLine();
        }
 }

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S1,S2,S3;
  char c1,c2,c3;
  cin >> S1 >> S2 >> S3;
  c1 = S1.at(0);
  c2 = S2.at(0);
  c3 = S3.at(0);
  cout << c1 << c2 << c3;
}

Measured memory_bytes: 3568
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

int main(){
    long long n, m;
    map<long long, long long> D;

    cin >> n;

    long long d;
    for(long long i = 0; i < n; i++){
        cin >> d;
        if(D.find(d) == D.end()){
            D[d] = 1;
        }
        else{
            D[d] += 1;
        }
    }

    cin >> m;

    bool flag = true;

    long long t;
    for(long long i = 0; i < m; i++){
        cin >> t;
        if(D.find(t) == D.end()){
            flag = false;
            break;
        }
        else{
            D[t] -= 1;
            if(D[t] == 0){
                D.erase(t);
            }
        }
    }

    if(flag == true){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 12800
#include<iostream>
using namespace std;
int main() {
	int x, y;
	while (cin >> x >> y && (x != 0 || y != 0)) {
		if (x < y) {
			cout << x << " " << y << endl;
		}
		else {
			cout << y << " " << x << endl;
		}
	}
	return 0;
}


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

int main()
{
  string s;
  cin>>s;
  
  bool juge = true;
  
  string first = s.substr(0,1);
  if(first!="A"){
    juge = false;
   }
  
  int cnt=0;
  for(int i=2;i<s.length()-1;i++)
  {
   

    if(s[i]=='C'){
      cnt++;
    }
  }
  
  if(cnt !=1)
  {
      juge = false;
  }
  
  for(int i=0;i<s.length();i++)
  {
       string v = s.substr(i,1);
    
      if(v!="A"&&v!="C"&&v<"Z")
      {
          juge = false;
      }
    
  }
  
  
  if(juge)
  {
       cout<<"AC"<<endl;
  }
  else
  {
       cout<<"WA"<<endl;
  }
  
  return 0;
}
  
  
  


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

#define int long long

void solve(int tt)
{
    int n,k;
    cin>>n>>k;
    int a[n+5],vis[n+5]={0};
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int temp=1;
    vector<int> v;
    v.push_back(1);
    temp=a[1];
    vis[1]=1;
    while(!vis[temp])
    {
        v.push_back(temp);
        vis[temp]=1;
        temp=a[temp];
    }
    int idx;
    for(int i=0;i<v.size();i++)
    {
        if(v[i]==temp)
        {
            idx=i;
            break;
        }
    }
    if(k<v.size())
    {
        cout<<v[k];
        return;
    }
    k-=(v.size()-1);
    int sz=(v.size()-idx);
    k%=sz;
    if(k==0)
    {
        cout<<v[v.size()-1];
        return;
    }
    cout<<v[idx+k-1];
}

int32_t main()
{
    int t=1;
    //cin>>t;
    for(int i=1;i<=t;i++)
        solve(i);
}

Measured memory_bytes: 8492
#include <iostream>
using namespace std;
int main()
{
	long long a, b, c, d;
	cin>>a>>b>>c>>d;
	long long e;
	e=max(a*c, b*c);
	e=max(e, a*d);
	e=max(e, b*d);
	cout<<e;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  int sum = 0;
  vector<int> num(101, 0);
  
  for (int i = 0; i < N; i++) {
    num.at(vec.at(i))++;
  }
  
  for (int i = 0; i < 101; i++) {
    if (num.at(i) > 0) sum++;
  }
  cout << sum;
}


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

int main(void) {
	int M1, D1, M2, D2;
	cin >> M1 >> D1 >> M2 >> D2;
	int ans;
	if (M1 != M2) ans = 1;
	else ans = 0;

	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

#define INF (1 << 30)

int main() {
	int n, k, a;
	
	while (cin >> n >> k && n != 0) {
		int ans = 0;
		bool card[100001] = { false };

		for (int i = 0; i < k; ++i) {
			cin >> a;
			card[a] = true;
		}

		if (card[0]) {
			for (int i = 1, bk, cnt = 0, wh = 0; i <= n; ++i) {
				if (card[i])
					cnt++;
				else {
					if (wh == 0) {
						wh = 1;
						bk = i;
						cnt++;
					}
					else {
						cnt = 0;
						i = bk;
						wh = 0;
					}
				}
				ans = max(ans, cnt);
			}
		}
		else {
			for (int i = 1, cnt = 0; i <= n; ++i) {
				if (card[i])
					cnt++;
				else {
					ans = max(ans, cnt);
					cnt = 0;
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

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

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

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

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

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

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

void factorize(ll n, map<ll, ll>& out){
    out.clear();
    for(ll p = 2; p <= n; ++p){
        while(n % p == 0){
            out[p]++;
            n /= p;
        }
    }
}

int main(){
    ll n, m;
    cin >> n >> m;
    map<ll, ll> f;
    factorize(m, f);
    mint ans = 1;
    for(auto p : f){
        ans *= mint::comb(n - 1 + p.second, p.second);
    }
    cout << ans.v << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int num_A = scan.nextInt();
		int num_B = scan.nextInt();
		int num_K = scan.nextInt();
		scan.close();
		
		int cnt = 0;
		while (cnt < num_K) {
//			操作回数の偶奇から髙橋君と青木君のどちらの操作なのか判断する
			if(cnt % 2 == 0) {
				if(num_A % 2 == 0) {
					num_A = Even(num_A);
				} else {
					num_A = Odd(num_A);
				}
				num_B = num_B + num_A;
			} else {
				if(num_B % 2 == 0) {
					num_B = Even(num_B);
				} else {
					num_B = Odd(num_B);
				}
				num_A = num_A + num_B;
			}
			cnt++;
		}
		
		System.out.println(num_A + " " + num_B);
		
	}
	
	// 入力値が偶数の場合
	public static int Even(int num) {
		int kai = num/2;	
		return kai;
	}
	
	// 入力値が奇数の場合
	public static int Odd(int num) {
		int kai = (num - 1) / 2;
		return kai;
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int n;
vector<ll> a;

const int N = 2020;
const ll INF = LLONG_MAX/3;
ll dp[N][2];

ll dfs(int d, int t){
    if(dp[d][t]<INF) return dp[d][t];

    ll ret = abs(a[n-1]-a[d-1]);
    for(int i=d; i<n-1; ++i){
        if(t==0) ret = max(ret, dfs(i+1,!t));
        else ret = min(ret, dfs(i+1,!t));
    }
    return dp[d][t] = ret;
}

int main(){
    int z,w;
    cin >>n >>z >>w;
    a.pb(w);
    rep(i,n){
        int x;
        cin >>x;
        a.pb(x);
    }

    n = a.size();

    fill(dp[0],dp[N],INF);
    cout << dfs(1,0) << endl;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int larger(int a,int b){
  if(a>b){
    return a;
  }
  else{
    return b;
  }
}

int round(int a,int b){
  if(a%b==0){
    return 0;
  }
  else{
    return 1;
  }
}


int main(){
  int jpn,mth;
  int jj,jm;
  int day;
  int ans;
  int jday,mday;

  scanf("%d",&day);
  scanf("%d",&jpn);
  scanf("%d",&mth);
  scanf("%d",&jj);
  scanf("%d",&jm);

  jday=jpn/jj+round(jpn,jj);
  mday=mth/jm+round(mth,jm);

  ans=day-larger(jday,mday);

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

  return 0;
}

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

inline long int c() {
  long int N, M;
  cin >> N >> M;
  if (N < M) swap(N, M);
  if (N == 1 and M == 1) return 1;
  if (N >= 2 and M == 1) return N - 2;
  if (M == 2) return 0;
  return (N - 2) * (M - 2);
}

inline long int d() {
  long int N;
  long int K;
  cin >> N >> K;
  if (K == 0) return N * N;
  long int count = 0;
  for (long int b = K + 1; b <= N; ++b) {
    long int x = (N - K) / b;
    long int y = (N - b + 1) / b;
    if (x != y) {
      count += (b - K) * (x+1) - ((2 + y) * b - N - 1);
    } else {
      count += (b - K) * (x+1);
    }
  }
  return count;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << d() << endl;
  return 0;
}

Measured memory_bytes: 384
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define MSB(bm) ((bm==0)?-1:(63-__builtin_clzll((bm))))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}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;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
// #define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
// #define degug(...) 663
#define cerr if(0)cout
#endif
#warning "// FOR has been inclusive now!!!!"

int main()
{
	int n; cin >> n;
	cout << n * n * n;
}

Measured memory_bytes: 256