akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1e9 + 7;

int binpow (int a, int n) {
	if (n == 0)
		return 1;
	if (n % 2 == 1)
		return binpow (a, n-1) * a % MOD;
	else {
		int b = binpow (a, n/2) % MOD;
		return b * b % MOD;
	}
}

int inv(int x) {
 	return binpow(x, MOD - 2) % MOD;
}

int C(int n, int a) {
 	
	int up = 1;
	int down = 1;
	for (int i = 0; i < a; i++) up *= (n - i + MOD) % MOD, up %= MOD;

	for (int i = 1; i <= a; i++) down *= i, down %= MOD;

	return up * inv(down) % MOD;	
}


signed main() {
 	int n, a, b;
	cin >> n >> a >> b;

                                                                              
	int ans = binpow(2, n) - 1;
	ans %= MOD;

	ans -= C(n, a);
	ans += MOD;
	ans %= MOD;
	ans -= C(n, b);
	ans += MOD;
	ans %= MOD;
	cout << ans << '\n';	
}

Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())

K = I()
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[K-1])


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

int main(){
    int H,W;
    cin >> H >> W;
    int S1[H][W],S2[H][W],S3[H][W],S4[H][W];
    char s;
    for (int h = 0; h < H; h++)
    {
        for (int w = 0; w < W; w++)
        {
            cin >> s;
            if(s == '.'){
                S1[h][w] = 1;
                S2[h][w] = 1;
                S3[h][w] = 1;
                S4[h][w] = 1;
            }
            else{
                S1[h][w] = 0;
                S2[h][w] = 0;
                S3[h][w] = 0;
                S4[h][w] = 0;
            }
        }
        
    }
    for (int h = 1; h < H; h++)
    {
        for (int w = 0; w < W; w++)
        {
            if(S1[h][w] != 0){
                S1[h][w] += S1[h-1][w];
            }
        }
        
    }

    for (int h = 0; h < H; h++)
    {
        for (int w = 1; w < W; w++)
        {
            if(S2[h][w] != 0){
                S2[h][w] += S2[h][w-1];
            }
        }
        
    }

    for (int h = H-1; h >= 0; h--)
    {
        for (int w = W-2; w >= 0; w--)
        {
            if(S3[h][w] != 0){
                S3[h][w] += S3[h][w+1];
            }
        }
        
    }

    for (int h = H-2; h >= 0; h--)
    {
        for (int w = W-1; w >= 0; w--)
        {
            if(S4[h][w] != 0){
                S4[h][w] += S4[h+1][w];
            }
        }
        
    }

    int ans = 0;
    for (int h = 0; h < H; h++)
    {
        for (int w = 0; w < W; w++)
        {
            ans = max(S1[h][w]+S2[h][w]+S3[h][w]+S4[h][w]-3,ans);
        }

    }

    cout << ans << endl;

}


Measured memory_bytes: 62720
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  char a, b;
  cin >> a >> b;
  if (a == b)
    cout << 'H' << endl;
  else
    cout << 'D' << endl;
}

Measured memory_bytes: 256
import math

def A():
    a, b = [int(x) for x in input().split()]
    print(math.ceil((a + b)/2))

def B():
    a = ''.join(sorted(list(input()), key=lambda x:ord(x)))
    b = ''.join(sorted(list(input()), key=lambda x:-ord(x)))
    if a < b:
        print('Yes')
    else:
        print('No')

def C():
    N = input()
    A = [x for x in input().split()]
    counter = {}

    for a in A:
        if(a in counter):
            counter[a] += 1
        else:
            counter[a] = 1
    remove_count = 0
    for key in counter:
        if counter[key] - int(key) >= 0:
            remove_count += counter[key] - int(key)
        else:
            remove_count += counter[key]
    print(remove_count)

def E():
    s1 = input()
    s2 = input()
    if s1 == s2[::-1]:
        print('YES')
    else:
        print('NO')

def F():
    a = int(input())
    sqrt = math.floor(math.sqrt(a))
    print(sqrt*sqrt)
F()


Measured memory_bytes: 3064
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b, c int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)

	count := 0
	d := []int{a, b, c}
	sort.Ints(d)
	if 2 <= (d[1] - d[0]) {
		cnt := (d[1] - d[0]) / 2
		count = count + cnt
		d[0] = d[0] + cnt*2
	}

	sort.Ints(d)
	if 0 < (d[2] - d[1]) {
		cnt := d[2] - d[1]
		count = count + cnt
		d[0] = d[0] + cnt
		d[1] = d[1] + cnt
	}

	s := make([][]int, 0)
	s = append(s, d)

	for {
		isBreak := false
		for _, x := range s {
			if x[0] == x[1] && x[1] == x[2] {
				isBreak = true
				break
			}
		}
		if isBreak {
			break
		}

		t := make([][]int, 0)
		for _, x := range s {
			t = append(t, []int{x[0] + 1, x[1] + 1, x[2]})
			t = append(t, []int{x[0] + 1, x[1], x[2] + 1})
			t = append(t, []int{x[0], x[1] + 1, x[2] + 1})
			t = append(t, []int{x[0] + 2, x[1], x[2]})
			t = append(t, []int{x[0], x[1] + 2, x[2]})
			t = append(t, []int{x[0], x[1], x[2] + 2})
		}
		for _, x := range t {
			s = append(s, x)
		}

		count++
	}

	fmt.Printf("%d\n", count)
}


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
#define sq(n) (n)*(n)

using namespace std;
typedef long long ll;

int main() {
    FAST;
    ll n,x,t;
    cin>>n>>x>>t;
    ll ans=n/x;
    if(n%x!=0)ans=ans+1;
    cout<<ans*t<<endl;


    return 0;

}



Measured memory_bytes: 3648
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        //値を取得
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt();
        int[] c = new int[N];
        int[] t = new int[N];
        
        int min = 0;
        
        for (int i = 0; i < N; ++i){
            c[i] = sc.nextInt();
            t[i] = sc.nextInt();
            if (t[i] <= T){
                if (min > c[i] || min == 0){
                    min = c[i];
                }
            }
        }
        
        if (min == 0){  //すべてTより大きかった場合
             System.out.println("TLE");
        } else {
            System.out.println(min);
        }

    }
}

Measured memory_bytes: 36100
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define endl "\n"
#define fi first
#define se second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define sz size()
#define PQ priority_queue
#define len length()
#define mll map<ll,ll>
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
#define mp(x,y)  make_pair(x,y)
#define pb push_back
#define pf push_front
#define ALL(v) v.begin(),v.end()
#define LAPAK ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

const ll MOD = 1000000007;

int main() {
	ll n,k;
	cin>>n;
	ll a[n][3];
	For(i,0,n)cin>>a[i][0]>>a[i][1]>>a[i][2];
	ll dp[n][3];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	For(i,1,n){
	    dp[i][0]=max(dp[i-1][1],dp[i-1][2]) + a[i][0];
	    dp[i][1]=max(dp[i-1][0],dp[i-1][2]) + a[i][1];
	    dp[i][2]=max(dp[i-1][1],dp[i-1][0]) + a[i][2];
	}
	
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	
	return 0;
}

/*            *          *******        *       *     *
             * *            *          * *       *   *
coded by    *****           *         *****       * *
           *     *      *   *        *     *       *
          *       *      * *        *       *      *
*/


Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main() {
    long long n, sum, p3, p5, p15;
    cin >> n;   
    p3 = n / 3;
    p5 = n / 5;
    p15 = n / 15;
    sum = (n*(n+1))/2 - 3*(p3*(p3+1))/2 - 5*(p5*(p5+1))/2 + 15*(p15*(p15+1))/2;
    cout << sum << endl;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main() 
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if ((x - r < 0) || (x + r > W) || (y - r < 0) || (y + r > H))
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 1012
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	int n;
	int a[100];
	int b[100];
	int cnt=0;
	int ans=0;
	
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		b[i]=a[i];
	}
	
	for(int i=1;i<n;i++)
	{
		if(a[i-1]==a[i])
		{
			a[i]=9999;
			ans++;
		}
	}
	/*for(int i=n-2;i>0;i--)
	{
		if(b[i+1]==b[i])
		{
			b[i]=9999;
			cnt++;
		}
	}
	ans=min(cnt,ans);*/
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

long long sum = 0;
//char s[11];
string str;

void add(string s, int n)
{
	//long long sum = 0;
	s = s + str[n];
	if (n + 1 == str.size())
	{
		long long ans = 0;
		for (int i = 0; i < s.size(); ++i)
		{
			if (s[i] >= '1' && s[i] <= '9')
			{
				ans = ans * 10;
				ans = ans + s[i] - '0';
			}
			else
			{
				sum = sum + ans;
				ans = 0;
			}
		}
		sum = sum + ans;
		return;
	}
		//sum = sum + ans;
		//return;
	add(s , n + 1);
	s = s + '+';
	add(s, n + 1);
	return;
}

void init()
{
	//scanf("%s", s);
	//printf("%s\n", s + s[1]);
	cin >> str;
	string s;
	//int n = strlen(str);
	int n = 0;
	add(s, n);
	cout << sum << '\n';
	//s = s + s[0];
	//cout << "" << s + '+' << '\n';
}

int main()
{

	//#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	//#endif

	init();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
const int INF=1e9;
//const int MOD=998244353;
const long long LINF=1e18;
#define int long long
//template
int dp[10][700];
//main
signed main(){
  int K;cin>>K;
  dp[0][0]++;
  for(int k=1;k<=600;k++)for(int i=1;i<=8;i++)for(int j=0;j<=i;j++)dp[i][k]+=dp[j][k-1];
  string s="FESTIVA";
  reverse(s.begin(),s.end());
  string ans;
  for(int k=600;k>0;k--){
    int a=K/dp[8][k];ans+=string(a,'L');
    K-=dp[8][k]*a;
    ans+=s;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
}


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

int main(){
  int k,s,c=0,v;
  cin>>k>>s;
  for(int i=0;i<k+1;i++){
    for(int j=0;j<k+1;j++){
      v=s-(i+j);
      if(v<=k&&0<=v)c++;
    }
  }
  cout<<c;
}

Measured memory_bytes: 256
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	ll a, b, c, d, e, f, g;
	cin >> a >> b >> c >> d >> e >> f >> g;
	ll ans = b;
	ll x = a;
	ll y = d;
	ll z = e;
	ll res = (x / 2 + y / 2 + z / 2) * 2;
	if (x > 0 && y > 0 && z > 0)
		res = max(res, 3 + 2 * ((x - 1) / 2 + (z - 1) / 2 + (y - 1) / 2));
	cout << ans + res << endl;

	return 0;
}



Measured memory_bytes: 256
#include <vector>


struct BipartiteMatching {
	using size_type = std::size_t;
	
	BipartiteMatching(size_type x, size_type y) : x(x), y(y), g(x + y, std::vector<size_type>()) {}
	BipartiteMatching(size_type n) : BipartiteMatching(n, n) {}
	
	void add_edge(size_type a, size_type b) {
		g[a].push_back(b + x);
		g[b + x].push_back(a);
	}
	
	size_type build() {
		match.assign(y, -1);
		size_type res = 0;
		for (size_type i = 0; i < x; ++i) {
			visited.assign(y, 0);
			if (dfs(i)) ++res;
		}
		return res;
	}
	
	bool dfs(size_type u) {
		for (auto v: g[u]) {
			v -= x;
			if (!visited[v]) {
				visited[v] = true;
				if (!~match[v] || dfs(match[v])) {
					match[v] = u;
					return true;
				}
			}
		}
		return false;
	}
	
	
private:
	size_type x, y;
	std::vector<std::vector<size_type>> g;
	std::vector<size_type> match;
	std::vector<bool> visited;
};


#include <cstdio>

int main() {
	int X, Y, E;
	scanf("%d %d %d", &X, &Y, &E);
	BipartiteMatching bm(X, Y);
	while (E--) {
		int x, y;
		scanf("%d %d", &x, &y);
		bm.add_edge(x, y);
	}
	
	printf("%d\n", bm.build());
	
	return 0;
}



Measured memory_bytes: 2900
#include<iostream>
#include<algorithm>
using namespace std;
#define INFTY (1<<21)

static const int N = 100;

int p[N + 1];
int m[N + 1][N + 1];

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

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

	for (int l = 2; l <= n; ++l) {
		for (int i = 1; i <= n - l + 1; ++i) {
			int j = i + l - 1;
			m[i][j] = INFTY;
			for (int k = i; k <= j - 1; ++k) {
				m[i][j] = min(m[i][j],m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}

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


Measured memory_bytes: 3104
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef string ST;
 
 
#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
#define cmax(a,b) {if(a<b){a=b;}}
#define cmin(a,b) {if(a>b){a=b;}}
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 

 
LL modpow(LL a, LL n, LL mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

LL modinv(LL a, LL m) {
  LL b = m, u = 1, v = 0;
  while (b) {
    LL t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0){
     u += m;
  }
  return u;
}

bool isPrime(LL N)
{
  if (N < 2) {
    return false;
  }
  else if (N == 2) {
    return true;
  }
  else if (N % 2 == 0) {
    return false;
  }

  LD sqrtNum = sqrt(N);
  for (LL i = 3; i <= sqrtNum; i += 2)
  {
    if (N % i == 0)
    {
      return false;
    }
  }
  return true;
}

void func() {
  // dp[i][j] := 最初のi枚のコインを投げたときに、表がj枚となる確率
  LL N;
  cin >> N;
  vector<LD> P(N);
  REP(i,N){
    cin >> P[i];
  }

  vector<vector<LD>> dp(N+1,vector<LD>(N+1,0));
  dp[0][0]=1.0;
  for(LL i=0;i<N;i++){
    for(LL j=0;j<i+1;j++){
      //fprintf(stderr,"i=%lld, j=%lld\n ",i,j) ;     
      dp[i+1][j  ] += dp[i][j]*(1.0-P[i]);
      dp[i+1][j+1] += dp[i][j]*(    P[i]);
    }
  }
  for(LL i=0;i<N+1;i++){
    //PRINTSP(dp[i]);
  }
  LD p = 0.0;
  for(LL i=(N+1)/2;i<N+1;i++){
    p += dp[N][i];
  }
  //cout << p;
  printf("%.20f",(double)p);

  return;
}



int main()
{
  func();
  return 0;
}
 

Measured memory_bytes: 141056
#include <iostream>
#include <cmath>

using namespace std;

int main() {

  int n;

  int not_prime[104730];
  int s;

  int count;

  not_prime[0]=not_prime[1]=1;

  for(int i=2;i<=104730;i++) not_prime[i]=0;

  for(int i=2;i<=sqrt(104730);i++) {

    if(not_prime[i]==0) {

      for(int j=2*i;j<=104730;j+=i) {

	not_prime[j]=1;

      }

    }

  }

  //for(int i=2;i<104730;i++) if(not_prime[i]==0) cout << i << endl;

  while(cin >> n) {

    if(n==0) break;

    s=0;
    count=0;

    for(int i=2;count<n;i++) {

      if(not_prime[i]==0) {

	s+=i;
	count++;

      }

    }

    cout << s << endl;

  }
  
  return 0;

}

  

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    tot=0
    for a in A:
        tot^=a
    ans=[a^tot for a in A]
    print(*ans)





if __name__ == "__main__":
    main()

Measured memory_bytes: 115188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();

		int i = a.length();

		String c = Integer.toString(i - 2);

		String b = a.charAt(0) + c + a.charAt(i - 1);

		System.out.println(b);
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

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

long long factorial(long long i){ // 階乗
  if(i > 0)
    return i * factorial(i-1);
  else
    return 1;
}

// a^n mod
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n>0) {
    if(n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^(-1) mod
long long modinv(long long a, long long mod) {
  return modpow(a, mod-2, mod);
}

int main() {
  long long N, A, B, C;
  const long long mod = 1000000007;
  cin >> N >> A >> B >> C;

  // N!(mod 1000000007)をあらかじめ計算しておく
  vector<long long> factmod;
  factmod.push_back(1); // 0! = 1 と定義
  for(int i=1; i<2*N+10; i++) { // (2*N)! まで計算しておけば十分
    long long tmp = (factmod[i-1]*i) %mod;
    factmod.push_back(tmp);
  }

  long long invAplusB = modinv(A+B, mod);
  long long invFactorialNm1 = modinv(factmod[N-1], mod);
  long long invHandmC = modinv(100-C, mod);
  long long res = 0;
  
  long long mothA = modpow(A, N, mod)%mod * invFactorialNm1%mod * 100 %mod * invHandmC %mod;
  long long mothB = modpow(B, N, mod)%mod * invFactorialNm1%mod * 100 %mod * invHandmC %mod;
  
  rep(i, N) {   // AがN回勝ち，Bがi回勝ちで終了．
    // 通常の期待値
    //res += (N+i) * factorial(N-1+i) * pow(A, N) * pow(B, i)/ pow(A+B, N+i) / factorial(N-1) /factorial(i) * 100.0 /  (100.0-C);
    res += (N+i) * factmod[N-1+i]%mod  * modpow(B, i, mod)%mod * modpow(invAplusB, N+i, mod)%mod  * modinv(factmod[i], mod)%mod * mothA%mod;
    res = res % mod;
  }
  rep(i, N) {   // Aがi回勝ち，BがN回勝ちで終了．
    // 通常の期待値
    //res += (N+i) * factorial(N-1+i) * pow(B, N) * pow(A, i)/ pow(A+B, N+i) / factorial(N-1) /factorial(i) * 100.0 /  (100.0-C);
    res += (N+i) * factmod[N-1+i]%mod * modpow(A, i, mod)%mod * modpow(invAplusB, N+i, mod)%mod * modinv(factmod[i], mod)%mod * mothB % mod;
    res = res % mod;
  }

  cout << res << endl;
  return 0;
}



Measured memory_bytes: 2420
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

/**
 * Dijkstra's algorithm.
 * First, call add_edge() to add edges.
 * Second, call solve() to calculate the length of the shortest path from source to each vertex.
 * Header requirement: algorithm, queue, vector
 * Verified by AtCoder ARC026-C (http://arc026.contest.atcoder.jp/submissions/604231)
 */
 template<class Len = int>
class Dijkstra {
private:
  int n;
  std::vector<std::vector<std::pair<int, Len> > > edges;
public:
  /**
   * n: the number of vertices
   */
  Dijkstra(int n) : n(n), edges(n) {}
  /*
   * from: the source of edge to add
   * to: the target of edge to add
   * cost: the cost of edge to add
   */
  void add_edge(int from, int to, Len cost) {
    edges[from].push_back(std::pair<int, Len>(to, cost));
  }
  /*
   * This function returns an array consisting of the distances from vertex source.
   */
  std::vector<Len> solve(int source) {
    const Len inf = 1e16;
    typedef std::pair<Len, int> pi;
    std::vector<Len> d(n, inf);
    std::priority_queue<pi, std::vector<pi>, std::greater<pi> > que;
    que.push(pi(0, source));
    while (!que.empty()) {
      pi p = que.top(); que.pop();
      int idx = p.second;
      if (d[idx] <= p.first) {
	continue;
      }
      d[idx] = p.first;
      for(int j = 0; j < edges[idx].size(); ++j) {
	que.push(pi(p.first + edges[idx][j].second, edges[idx][j].first));
      }
    }
    return d;
  }
};


int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i, 0, h) {
    cin >> s[i];
  }
  Dijkstra<ll> dijk(h * w);
  int dx[4] = {0, 1, 0, -1};
  int dy[4] = {1, 0, -1, 0};
  int blk = 0;
  REP(i, 0, h) {
    REP(j, 0, w) {
      if (s[i][j] == '.') {
	REP(d, 0, 4) {
	  int nx = i + dx[d];
	  int ny = j + dy[d];
	  if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
	  dijk.add_edge(i * w + j, nx * w + ny, 1);
	}
      } else {
	blk++;
      }
    }
  }
  int dis = dijk.solve(0)[h * w - 1];
  if (dis >= h * w) {
    cout << -1 << endl;
  } else {
    cout << h * w - dis - 1 - blk << endl;
  }
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <time.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long  ll;
static const ll INF = (ll)1 << 62;
static const ll MOD = 1e9 + 7;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main() {
	ll r, d, x; cin >> r >> d >> x;

	repe(i, 1, 10) {
		ll p = r * x - d;
		cout << p << endl;
		x = p;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
ll s = 0;
int main(){
  cin >> N;
  for (int i = 1; i<=N; i++){
    if (i%3 != 0 && i%5!= 0){
      s += i;
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{

    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

//----------------------------------------------------------------

int main()
{
    ll n;
    cin >> n;
    ll a;
    ll cnt = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        while (a % 2 == 0)
        {
            a = a / 2;
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
map_lis = [list(input()) for _ in range(H)]

# M_lis上のi,j成分周囲のマスの＃の数を返す関数
def bom_n(M_lis,i,j):
    cnt = 0
    for x in range(i-1,i+2):
        for y in range(j-1,j+2):
            if x == i and y == j:
                continue
            if x<0 or x > H-1 or y < 0 or y > W-1:
                continue
            if M_lis[x][y] == '#':
                cnt += 1
    return cnt

for h in range(H):
    for w in range(W):
        if map_lis[h][w] == '#':
            print('#',end='')
            continue
        else:
            map_lis[h][w] = str(bom_n(map_lis,h,w))
            print(map_lis[h][w],end='')
    print()

Measured memory_bytes: 3572
N = int(input())
An = list(map(int, input().split()))
dp = [0 for x in range(N+10)]
dp[0] = 1000
for i in range(1, N):
    stock = dp[i-1] // An[i-1]
#     print(dp[i-1], An[i-1], stock)
    money = dp[i-1]
    money -= stock * An[i-1]
    money += stock * An[i]
#     print(money)
    dp[i] = max(dp[i-1], money)
print(dp[N-1])  

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

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;
constexpr ll mod = 1e9+7;

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

    int N;
    cin>>N;
    ll X;
    cin>>X;
    vector<ll> A(N);
    for (int n = 0; n < N; n++) cin>>A[n];

    ll ans = 0;
    for (int n = 0; n < N-1; n++) {
        if (A[n] + A[n+1] > X) {
            ans += A[n] + A[n+1] - X;
            if (A[n] > X) {
                A[n+1] = 0;
                A[n] = X;
            } else A[n+1] -= (A[n] + A[n+1] - X);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int N, A, B, C, D, judg = 0;
string S;

int main() {
	cin >> S;

	int i = 0, n = 0, j;
    long long Ans = 0;

	for (i = 0; i <= S.length(); i++) {
		if (S[i] == 'C')
			n = 0;
		if (S[i] == 'B')
			n = 0;
		if (S[i] == 'A') {
			n += 1;
			for (j = i + 1; j <= S.length() - 1; j += 2) {
				if (S[j] == 'B'&&S[j + 1] == 'C')
					Ans += n;
				else {
					i = j - 1;
					break;
				}
			}
		}
	}
	cout << Ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int X;
	cin >> X;
	if(X>=30) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const int INF=1e9;


int main(){
  int h,a;
  cin>>h>>a;
  int n=0;

  while(h>0){
    h -=a;
    n++;
  }

  cout<<n<<endl;
}


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

using namespace std;
using ll = long long int;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    while (true)
    {
        c -= b;
        if (c <= 0)
        {
            cout << "Yes" << endl;
            return 0;
        }

        a -= d;
        if (a <= 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3636
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"

using namespace std;
typedef long long ll;

//Bellman–Ford法
const int limit = 2010;
const ll inf = 123456789012345;

ll d[1010];	//sからの暫定最短距離
int v, e;//頂点と辺数 //頂点は1..v
//int s, g;//スタートとゴール
int from[limit];
int to[limit];
ll cost[limit];

ll shortest_path_normal(int s, int g)
{
  for (int i = 1; i < v + 1; i++)
  {
    d[i] = -1 * inf;
  }

  d[s] = 0;

  for (int loop = 0; loop < v + 1; loop++)
  {
    for (int i = 0; i < e; i++)
    {
      if (d[to[i]] < d[from[i]] + cost[i])	//最大なので逆
      {
        d[to[i]] = d[from[i]] + cost[i];
      }
    }
  }

  ll ans = d[g];

  for (int i = 0; i < e; i++)
  {
    if (d[to[i]] < d[from[i]] + cost[i])
    {
      d[to[i]] = d[from[i]] + cost[i];
    }
  }	//もう1回まわす

  if (ans < d[g])
  {
    ans = inf;	//イカレた値を出力してるだけ。mainに書くときはboolで修正
  }
  return ans;
}


int main()
{
  cin >> v >> e;
  for (int i = 0; i < e; i++)
  {
    cin >> from[i] >> to[i] >> cost[i];
  }
  if (shortest_path_normal(1, v) == inf)
  {
    cout << "inf" << "\n";
  }
  else
  {
    cout << shortest_path_normal(1, v) << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	while(1){
		int dt[101]={0},a,b;
		do{
			if(!(cin>>a>>b))return 0;
			dt[a]++;dt[b]++;
		}while(a||b);
		a=1;
		loop(i,3,101)if(dt[i]%2)a=0;
		cout<<(dt[1]%2 && dt[2]%2 && a?"OK":"NG")<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=2e6+4;
char a[M];
int cnt=1,vis[M];
ll x,y,ans=0;
vector<int>v[M];
void dfs(int u)
{
	if(vis[u]) return;
	vis[u]=1;
	if(a[u]=='.') x++;
	else if(a[u]=='#') y++;
	for(auto x:v[u])	dfs(x);
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			char ch;
			cin>>ch;
			a[cnt]=ch;
			if(cnt%m!=1 || m==1)
			{
				if(a[cnt-1]!=ch)
				{
					v[cnt].push_back(cnt-1);
					v[cnt-1].push_back(cnt);
				}
			}
			if(cnt>m)
			{
				if(a[cnt-m]!=ch)
				{
					v[cnt].push_back(cnt-m);
					v[cnt-m].push_back(cnt);
				}
			}
			cnt++;
		}
	}
	for(int i=1;i<=n*m;i++)
	{
		if(!vis[i])
		{
			x=y=0;
			dfs(i);
			//cout<<i<<" "<<x<<" "<<y<<endl;
			ans+=x*y;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 61440
#include<iostream>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0; i<s.length(); i++){
    if(s[i]=='7'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3624
import std;

long calc(long[] a) {
    long ans = 0;
    long[long] d;
    for (int i = 0; i < a.length; i++) {
        if (i + 1 >= a[i]) {
            ans += d.get(i + 1 - a[i], 0);
        }
        d[i + 1 + a[i]]++;
    }
    return ans;
}

void main() {
    readint;
    auto a = reads!long;
    writeln(calc(a));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 24656
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    long ans=0;
    for(int i=0;i<n&&i<k;i++)
        ans+=a[i];
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3640
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll>pll;

int main() {
	int H, W, a[500][500];
	cin >> H >> W;
	REP(i, H) {
		REP(j, W) {
			cin >> a[i][j];
		}
	}


	int f = 0, cnt = 0;

	REP(i, H) {
		REP(j, W) {
			int k, l;
			if (i % 2 == 0) {
				k = j;
				l = W - 1;
			}
			else if (i % 2 == 1) {
				k = W - 1 - j;
				l = 0;
			}

			if (f == 0 && a[i][k] % 2 == 1) {
				f = 1;
			}
			else if (f == 1) {
				cnt++;
				if (a[i][k] % 2 == 1) {
					f = 0;
				}
			}
		}
	}

	cout << cnt << endl;
	f = 0;
	int t = 0;
	REP(i,H) {
		REP(j, W) {
			int k, l, m;
			if (t == cnt) {
				return 0;
			}
			if (i % 2 == 0) {
				k = j;
				l = W - 1;
				m = 1;
			}
			else if (i % 2 == 1) {
				k = W - 1 - j;
				l = 0;
				m = -1;
			}

			if (f == 0 && a[i][k] % 2 == 1) {
				f = 1;
				if (k != l) {
					cout << i + 1 << " " << k + 1 << " " << i + 1 << " " << k + m + 1 << endl;
				}
				else {
					cout << i + 1 << " " << k + 1 << " " << i + 1 + 1 << " " << k + 1 << endl;
				}
				t++;
			}
			else if (f == 1) {
				if (a[i][k] % 2 == 1) {
					f = 0;
				}
				else {
					if (k != l) {
						cout << i + 1 << " " << k + 1 << " " << i + 1 << " " << k + m + 1 << endl;
					}
					else {
						cout << i + 1 << " " << k + 1 << " " << i + 1 + 1 << " " << k + 1 << endl;
					}
					t++;
				}
			}
			
		}
	}


	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

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

void solve() {
    lli n;
    cin >> n;
    vlli v(n), forward(n), backward(n);
    lli ans = 1;

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

    for (int i = 0; i < n; ++i) {
        if (i == 0) {
            forward[i] = v[i];
        }
        else {
            forward[i] = gcd(forward[i - 1],v[i]);
        }
    }

    for (auto i = n - 1; i >= 0; --i) {
        if (i == n - 1) {
            backward[i] = v[i];
        } else {
            backward[i] = gcd(backward[i + 1], v[i]);
        }
    }

    if (n == 2) {
        cout << max(v[0], v[1]) << '\n';
        return;
    }

    for (int i = 0; i < n; ++i) {
        if (i == 0) {
            ans = max(ans, backward[1]);
        } else if (i == n - 1) {
            ans = max(ans, forward[n - 2]);
        } else {
            ans = max(ans, gcd(forward[i - 1], backward[i + 1]));
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 2560
// ABC067A - 

#include <bits/stdc++.h>
using namespace std;

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

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

	if ((A % 3 == 0)||(B % 3 == 0)||((A + B)% 3 == 0)) {
		cout << "Possible" << endl;
	} else {
		cout << "Impossible" << endl;
	}

	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int N, M, Q;
pii T[200000];
int sum[501][501];

int main() {
    cin >> N >> M >> Q;
    int l, r;
    REP(i, M) {
        cin >> l >> r;
        sum[l][r]++;
    }

    FOR(i, 1, N + 1) FOR(j, 1, N + 1) {
        sum[i][j] += sum[i - 1][j];
        sum[i][j] += sum[i][j - 1];
        sum[i][j] -= sum[i - 1][j - 1];
    }

    int p, q;
    REP(i, Q) {
        cin >> p >> q; p--;
        cout << sum[q][q] - sum[p][q] - sum[q][p] + sum[p][p] << endl;
    }
    return 0;
}

Measured memory_bytes: 1920
n = gets.to_i
t = n.times.map{gets.chomp.split(" ").map(&:to_i)}.unshift([0,0,0])
for i in 1..n
  if t[i][0]-t[i-1][0] < (t[i][1]-t[i-1][1]).abs+(t[i][2]-t[i-1][2]).abs || (t[i][0]-t[i-1][0])%2 != (t[i][1]-t[i-1][1]+t[i][2]-t[i-1][2])%2
    puts "No"
    exit
  end
end
puts "Yes"

Measured memory_bytes: 9724
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

typedef tree<
        pair<int, int>,
        null_type,
        less<pair<int, int>>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;


const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}


mt19937 rnd(time(0));




/*
const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    if (n<k) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}
*/

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

    string s; int k;
    cin>>s>>k;

    k = min(k, (int)s.size());

    vector<int> a;

    int cur = 0;

    for (int i = 0; i<s.size(); i++)
    {
        if (s[i]=='1') cur++;
        else
        {
            a.push_back(cur);
            cur = 0;
        }
    }
    if (cur>0) a.push_back(cur);

    //for (auto it: a) cout<<it<<' ';

    const int N = 305;

    vector<vector<vector<int>>> dp(N, vector<vector<int>>(N, vector<int>(N)));

    int n = a.size();

    dp[n][k][0] = 1;

    for (int pos = n; pos>0; pos--)
        for (int left = k; left>=0; left--)
            for (int jumps = k; jumps>=0; jumps--) if (dp[pos][left][jumps]!=0)
            {
                for (int val = 0; val<=a[pos-1] + jumps; val++)
                {
                    int left1, jumps1;
                    if (val<a[pos-1])
                    {
                        left1 = left - (a[pos-1] - val); jumps1 = jumps + (a[pos-1] - val);
                    }
                    else
                    {
                        left1 = left;
                        jumps1 = jumps - (val - a[pos-1]);
                    }

                    if (left1<0 || jumps1<0) continue;

                    dp[pos-1][left1][jumps1] = add(dp[pos-1][left1][jumps1], dp[pos][left][jumps]);
                }
            }

    //dp[pos][left][jumps]

    int res = 0;
    for (int i = 0; i<=k; i++) res = add(res, dp[0][i][0]);

    cout<<res;



}



Measured memory_bytes: 117780
#include <bits/stdc++.h>
#define ll long long
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
using namespace std;
const int tINF = (int)INT_MAX;
const long long lINF = (long long)LLONG_MAX;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef DEBUG
			assert(freopen("inp", "r", stdin));
			assert(freopen("out", "w",stdout));
	#else
			#define cerr if(false)cerr
	#endif
    int n, k;
    cin >> n >> k;
    vector <ll> ar(n);
    for(auto &i : ar)
        cin >> i;
    sort(all(ar));
    ll ans = 0;
    for(int i= n - 1; i >= 0; --i){
        if(k){
            --k;
        }
        else
            ans += ar[i];
    }
    cout << ans << '\n';
   cerr << "Time execute: " << (double)clock() / (double)CLOCKS_PER_SEC 
    << " sec" << endl;
}

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

const int N = 2005;
int n, q, k;
ll a[N], b[N], c[N], cnt, tot;
int main() {
  scanf("%d%d%d", &n, &k, &q);
  for (int i = 1; i <= n; ++i)
    scanf("%lld", &a[i]);
  ll ans = 1ll << 60;
  for (int i = 1; i <= n; ++i) {
    tot = 0;
    a[n + 1] = -(1ll << 60);
    for (int j = 1; j <= n + 1; ++j)
      if (a[j] >= a[i])
        b[++cnt] = a[j];
      else {
        sort(b + 1, b + 1 + cnt);
        for (int i = 1; i <= cnt - k + 1; ++i)
          c[++tot] = b[i];
        cnt = 0;
      }
    sort(c + 1, c + 1 + tot);
    if (tot >= q)
      ans = min(ans, c[q] - a[i]);
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
 
 
 
using namespace std;
int main()
{
	int n,i,cnt=0;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]%2==1)
			cnt++;
	}
	if(cnt%2==1)
		cout<<"NO"<<endl;
		else
		cout<<"YES"<<endl;
}

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

max_d = 0

for i in range(n):
    d = a[(i + 1) % n] - a[i] #隣接する2軒の距離の最大値を算出
    if d < 0: #n番目-1番目の場合
        d += k
    max_d = max(max_d, d)

print(k - max_d) #一周から最長の隣接距離を引く

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
int n;
cin >> n;
cout << 800 * n - (n/15)*200 << endl;
}


Measured memory_bytes: 256
loop do
  h, w = gets.split.map(&:to_i)
  break if h.zero? and w.zero?
  st1 = ("#." * w)[0, w]
  st2 = ("." + st1)[0, w]
  h.times {|i| puts [st1, st2][i % 2]}
  puts
end


Measured memory_bytes: 6852
#include <iostream>
#include <algorithm>
#define MAX 100

using namespace std;

int main(void){

  while(1){

  int edge[MAX + 1] = {0};
  int a,b,mx = 0;
  while( cin >> a >> b , a || b ){
    edge[a]++;
    edge[b]++;
    mx = max(mx, max(a, b));
  }
  if( edge[1] == 0 && edge[2] == 0 ) goto end;

  if( edge[1] % 2 == 1 && edge[2] % 2 == 1 ){
    for( int i = 3 ; i <= mx ; i++ ){
      if( edge[i] % 2 != 0 )goto back;
    }
    cout << "OK" << endl;
  }else{
  back:
    cout << "NG" << endl;
  }
  }
 end:;
  return 0;
}

Measured memory_bytes: 1156
def main():
    n = int(input())
    a = []
    b = []
    for _ in range(n):
        a_,b_ = map(int,input().split())
        a.append(a_)
        b.append(b_)
    cnt = 0
    for i in reversed(range(n)):
        mod = (a[i]+cnt)%(b[i])
        if mod==0:
          pass
        else:
          cnt += b[i]-mod
    print(cnt)
if __name__ == "__main__":
    main()

Measured memory_bytes: 57816
import numpy as np
import itertools

H,W=map(int,input().split())
A=[list(map(int, input().split())) for _ in range(H*2)]
M=[[abs(A[i][j]-A[H+i][j]) for j in range(W)] for i in range(H)]
m=max(max(j for j in i) for i in M)
r=m*(H+W)+1
dp=np.zeros((H,W,r),dtype='bool')
dp[0][0][M[0][0]]=True
it = itertools.product(range(H),range(W))
next(it)
for h,w in it:
    m=M[h][w]
    dp[h][w][m:] |= dp[h][w-1][:r-m] | dp[h-1][w][:r-m]
    dp[h][w][:r-m] |= dp[h][w-1][m:] | dp[h-1][w][m:]
    dp[h][w][:m] |= dp[h][w-1][m:0:-1] | dp[h-1][w][m:0:-1]

for i in range(r):
    if dp[-1][-1][i]:
        print(i)
        break

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

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

using namespace std;
using lint=long long;

class union_find{
	int n;
	vector<int> p;
public:
	union_find(int n):n(n),p(n,-1){}
	int find(int u){ return p[u]<0?u:p[u]=find(p[u]); }
	void unite(int u,int v){
		u=find(u); v=find(v);
		if(u!=v){
			if(p[v]<p[u]) swap(u,v);
			p[u]+=p[v]; p[v]=u; n--;
		}
	}
	bool is_same(int u,int v){ return find(u)==find(v); }
	int size()const{ return n; }
	int size(int u){ return -p[find(u)]; }
};

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

	union_find U(n),V(2*n);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		U.unite(u,v);
		V.unite(u,n+v);
		V.unite(n+u,v);
	}

	lint c1=0,c2=0,c3=0;
	vector<bool> vis(n);
	rep(u,n){
		int r=U.find(u);
		if(!vis[r]){
			vis[r]=true;
			if     (U.size(u)==1)      c1++;
			else if(!V.is_same(u,n+u)) c2++;
			else                       c3++;
		}
	}
	printf("%lld\n",c1*n+(n-c1)*c1+c2*(2*c2+c3)+c3*(c2+c3));

	return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#define ll long long
#define INF 0x3f3f3f3f
#define N 100005
using namespace std;

struct node{
	int t,x,y;
	bool operator<(node a){
		return t<a.t;
	}
}a[N];

int main()
{
	ll n,t,x,y;
	bool flag=true;
	cin>>n;
	a[0].t=a[0].x=a[0].y=0;
	for(int i=1;i<=n;i++){
		cin>>a[i].t>>a[i].x>>a[i].y;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		int lenx=a[i].x-a[i-1].x;
		if(lenx<0) lenx=-lenx;
		int leny=a[i].y-a[i-1].y;
		if(leny<0) leny=-leny;
		int len=lenx+leny;
		int dt=a[i].t-a[i-1].t;
		if(dt<len){
			flag=false;
			break;
		}
		if(len&1){
			if(dt%2==0){
				flag=false;
				break;
			}
		}else{
			if(dt&1){
				flag=false;
				break;
			}
		}
	}
	if(flag)
	puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n, d, x;
  cin >> n >> d >> x;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  // i人目の参加者がt個をチョコレートを食べたとすると、
  // D<=ta[i]+1を満たす最大のtを求める

  vector<int> maisuu(n);
  for (int i = 0; i < n; i++) {
    maisuu[i] = (d - 1) / a[i] + 1;
    // cout << maisuu[i] << endl;
  }
  cout << x + accumulate(maisuu.begin(), maisuu.end(), 0) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char a[4]={0}, c=0;
	
	scanf("%s" ,&a[1]);
	
	for(int i=1; i<=3; i++)
		if(a[i]=='o') c++;
	
	printf("%d\n" ,700+c*100);
	return 0;
}

Measured memory_bytes: 128