akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Info{
	Info(int arg_count,int arg_loc){
		count = arg_count;
		loc = arg_loc;
	}
	int count,loc;
};

void func(int MAX,int N){

	int min_Count_Base[N+2];
	int min_Count_Work[N+2];
	int instruction[N+2];

	for(int i = 1; i <= N; i++){
		scanf("%d",&instruction[i]);
		min_Count_Base[i] = BIG_NUM;
	}

	min_Count_Base[0] = 0;
	min_Count_Base[N+1] = BIG_NUM;

	instruction[0] = 0;
	instruction[N+1] = 0;

	int next_loc;

	queue<Info> Q;
	Q.push(Info(0,0));

	while(!Q.empty()){

		if(Q.front().loc == N+1){
			Q.pop();
		}else if(Q.front().count > min_Count_Base[Q.front().loc]){
			Q.pop();
		}else{

			for(int i = 1; i <= MAX; i++){
				next_loc = Q.front().loc+i;

				if(next_loc > N+1){
					next_loc = N+1;
				}else if(next_loc < 0){
					next_loc = 0;
				}

				next_loc += instruction[next_loc];

				if(next_loc > N+1){
					next_loc = N+1;
				}else if(next_loc < 0){
					next_loc = 0;
				}

				if(min_Count_Base[next_loc] > Q.front().count+1){
					min_Count_Base[next_loc] = Q.front().count+1;
					Q.push(Info(Q.front().count+1,next_loc));
				}
			}

			Q.pop();
		}
	}

	if(min_Count_Base[N+1] == BIG_NUM){
		printf("NG\n");
		return;
	}

	bool FLG = true;

	for(int start = 1; start <= N; start++){
		if(min_Count_Base[start] != BIG_NUM){

			for(int i = 0; i <= N+1; i++){
				min_Count_Work[i] = BIG_NUM;
			}

			min_Count_Work[0] = 0;

			Q.push(Info(0,start));

			while(!Q.empty()){

				if(Q.front().loc == N+1){
					Q.pop();
				}else if(Q.front().count > min_Count_Work[Q.front().loc]){
					Q.pop();
				}else{

					for(int i = 1; i <= MAX; i++){
						next_loc = Q.front().loc+i;

						if(next_loc > N+1){
							next_loc = N+1;
						}else if(next_loc < 0){
							next_loc = 0;
						}

						next_loc += instruction[next_loc];

						if(next_loc > N+1){
							next_loc = N+1;
						}else if(next_loc < 0){
							next_loc = 0;
						}

						if(min_Count_Work[next_loc] > Q.front().count+1){
							min_Count_Work[next_loc] = Q.front().count+1;
							Q.push(Info(Q.front().count+1,next_loc));
						}
					}

					Q.pop();
				}
			}

			if(min_Count_Work[N+1] == BIG_NUM){
				FLG = false;
				break;
			}
		}
	}


	if(!FLG){
		printf("NG\n");
	}else{
		printf("OK\n");
	}
}

int main(){

	int MAX,N;
	while(true){
		scanf("%d",&MAX);
		if(MAX == 0)break;

		scanf("%d",&N);
		func(MAX,N);
	}

	return 0;
}

Measured memory_bytes: 2716
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    const lint mod = 1e9 + 7;
    lint dp[n+1][13];
    rep(i, n+1)rep(j, 13) dp[i][j] = 0;
    dp[0][0] = 1;
    rep(i, n)rep(j, 13)if(dp[i][j]){
        if(s[i] == '?'){
            rep(k, 10) dp[i+1][(j+k)*10%13] = (dp[i+1][(j+k)*10%13] + dp[i][j]) % mod;
        }
        else dp[i+1][(j+(s[i]-'0'))*10%13] = (dp[i+1][(j+(s[i]-'0'))*10%13] + dp[i][j]) % mod;
    }
    printf("%lld\n", dp[n][11]);
}

Measured memory_bytes: 10624
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef long long llint;
typedef vector<long long int> vint;
typedef vector< vector<int> > vvint;
typedef vector<string> vstr;


int main(void) {
	llint N, wcou, ans1, ans2, bcou,ans3,mi,poi;
	mi = 200001;
	
	ans3 = 0;
	bcou = 0;
	ans1 = 0;
	ans2 = 0;
	wcou = 0;
	string S;
	cin >> N >> S;
	vint n(N);
	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == '.')wcou++;
		else {
			ans1 += wcou;
			wcou = 0;
		}
	}
	for (int i = 0; i < N; i++) {
		if (S[i] == '#')bcou++;
		else {
			ans2 += bcou;
			bcou = 0;
		}
	}
	wcou = 0;
	bcou = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == '#') {
			bcou++;
			n[i] = bcou;
		}
		else {
			bcou--;
			n[i] = bcou;
		}
		mi = min(mi, n[i]);
		if (mi == n[i])poi = i;
	}
	for (int i = 0; i <= poi; i++) {
		if (S[i] == '#')ans3++;
	}
	for (int i = poi + 1; i < N; i++) {
		if (S[i] == '.')ans3++;
	}
	cout << min (min(ans1,ans2),ans3 ) << endl;
}


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

using namespace std;
long long INF = 1LL << 40;
template <class T>
bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    else
        return false;
}

template <class T>
bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    else
        return false;
}
long long dp[3][100010];

int main()
{

    int N;
    cin >> N;

    int a[3][N];

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

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
            {
                if (j == k)
                    continue;
                chmax(dp[j][i + 1], (dp[k][i] + a[j][i]));
            }
        }
    }

    long long ans = 0;
    for (int i = 0; i < 3; i++)
        chmax(ans, dp[i][N]);

    cout << ans << endl;
}

Measured memory_bytes: 3712
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    l, r, d = LI()
    ans = r//d - (l-1) //d 
    print(ans)
main()



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

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define all(a) (a).begin(), (a).end()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    cout << (n + max(h, w) - 1) / max(h, w);
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {

	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	result := "No"
	for i := 0; i < 100; i++ {
		if c-b <= 0 {
			result = "Yes"
			break
		} else {
			c -= b
		}
		if a-d <= 0 {
			result = "No"
			break
		} else {
			a -= d
		}
	}

	fmt.Println(result)
}


Measured memory_bytes: 1752
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
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; }
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;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {

    ll N;
    cin >>N;
    ll flag = 0;
    ll num;
    rep(i,10000){
        if(N==i*(i-1)/2){
            flag = 1;
            num = i;
        }
    }
    if(flag == 0){
        cout<<"No"<<endl;
        return 0;
    }else{
        cout<<"Yes"<<endl;
        cout<<num<<endl;
        rep(i,num-1){
            cout<<num-1<<" ";
            ll ans = 1;
            rep(j,i){
                ans += j+1;
            }
            
            rep(j,i+1){
                cout<<ans<<" ";
                ans++;
            }
            ans--;


            rep3(j,i,num-2){
                ans +=j+1;
                cout<<ans<<" ";
                
            }
            cout<<endl;
        }
        cout<<num-1<<" ";
        rep(i,num-1){
            cout<<(i+1)*(i+2)/2<<" ";
        }
        cout<<endl;
    }




    return 0;
    

}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int i=n;i<=999;i++){
    int temp=i;
    vector<int>vec;
    while(temp!=0){
      vec.push_back(temp%10);
      temp/=10;
    }
    if(vec[0]==vec[1]&&vec[1]==vec[2]){
      cout<<i<<endl;
      return(0);
    }
  }
  return(0);
}


Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

a = gets.chomp
puts (a == "ABC")? "ARC" : "ABC"

Measured memory_bytes: 14396
//
//  main.cpp
//  B
//
//  Created by 曾憲揚 on 2020/8/19.
//  Copyright © 2020 曾憲揚. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;
const int maxM=1e4+4;

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m; cin>>n>>m;
    int a; int sum=0;
    for(int i=0; i<m; i++){
        cin>>a; sum+=a;
    }
    if(sum>n){
        cout<<-1<<endl;
    } else{
        cout<<n-sum<<endl;
    }
    return 0;
}


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

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

def main():
    mod=10**9+7
    sx,sy,tx,ty=MI()
    ans=[]
    
    for i in range(ty-sy):
        ans.append("U")
    for i in range(tx-sx+1):
        ans.append("R")
    for i in range(ty-sy+1):
        ans.append("D")
    for i in range(tx-sx+1):
        ans.append("L")
    ans.append("U")
    ans.append("L")
    for i in range(ty-sy+1):
        ans.append("U")
    for i in range(tx-sx+1):
        ans.append("R")
    for i in range(ty-sy+1):
        ans.append("D")
    for i in range(tx-sx):
        ans.append("L")
        
    print(''.join(map(str, ans)))
    

main()


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const double INF=1e20;

int N;
int T[222];
int V[222];

double dp[222][222];

signed main(){
    cin>>N;
    rep(i,N)cin>>T[i];
    rep(i,N)cin>>V[i];

    fill_n(*dp,222*222,-INF);
    dp[0][0]=0;
    rep(i,N){
        rep(j,V[i]+1){
            rep(k,min(V[i],V[i+1])+1){
                if(abs(j-k)>T[i])continue;
                double tmp=dp[i][j];
                int d=abs(j-k);
                int M=max(j,k);
                int m=min(j,k);
                tmp+=(j+k)*0.5*d;

                d=T[i]-d;
                if((V[i]-M)*2>d)tmp+=d*d*0.25+M*d;
                else tmp+=(V[i]+M)*(V[i]-M)+(d-(V[i]-M)*2)*V[i];
                chmax(dp[i+1][k],tmp);
            }
        }
    }

    printf("%.20f\n",dp[N][0]);
    return 0;
}


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

int main (){
  int N;
  cin >> N;
  int A[N];
  
  int flg =0;
  
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  
  int cnt =0;
  
  for(;;){
    flg=0;
    for(int i=0;i<N;i++){
    	if(A[i]%2==0)
      flg++;
    }
    if(flg < N)
      break;
    else{    
      for(int i=0;i<N;i++){
    	A[i]= A[i]/2;
        //cout << A[i]<<endl;
    	}
      cnt++;
    }
  }
  
  cout <<cnt<<endl;
  
}



Measured memory_bytes: 256
#coding: utf-8

import math

N = int(input())
A = [int(n) for n in input().split()]
for i in range(len(A)):
    A[i] -= (i+1)
A.sort()

med = 0
if N % 2 == 0:
    m1 = N // 2
    m2 = m1 - 1
    med = round((A[m1] + A[m2]) / 2)
else:
    m1 = (N+1) // 2
    med = A[m1-1]

sad = sum([abs(a-med) for a in A])

print(sad)



Measured memory_bytes: 32140
package main
import (
  "fmt"
  "strings"
)
func main() {
  var n,m,xa,bx,ba int
  var s string
  fmt.Scan(&n)
  for i:=0;i<n;i++ {
    fmt.Scan(&s)
    m += (len(s)-len(strings.Replace(s,"AB","",-1)))/2
    if s[0:1] == "B" && s[len(s)-1:len(s)] == "A" {
      ba++
    } else if s[len(s)-1:len(s)] == "A"{
      xa++
    } else if s[0:1] == "B" {
      bx++
    }
  }
  if ba > 0 {
    m += ba-1
    if xa > 0 {
      m++
      xa--
    }
    if bx > 0 {
      m++
      bx--
    }
    m += min(xa,bx)
  } else {
    m += min(xa,bx)
  }
  fmt.Println(m)
}
func min(n,m int) int {
  if n < m { return n }
  return m
}

Measured memory_bytes: 1152
n = int(input())
def dfs(s,n):
  count = 0
  if s > n:
    return count
  if str(3) in list(str(s)) and str(5) in list(str(s)) and str(7) in list(str(s)):
    count += 1
  count += dfs(10*s + 3,n)
  count += dfs(10*s + 5,n)
  count += dfs(10*s + 7,n)
  return count


print(dfs(3,n) + dfs(5,n) + dfs(7,n))

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

int main() {
  int N, M, ans = 0;
  cin >> N >> M;
  if (N > 1) {
    ans += N * (N - 1) / 2;
  }
  if (M > 1) {
    ans += M * (M - 1) / 2;
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
using namespace std;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int N) : par(N){
        for (int i = 0; i < N; i++) par[i] = i;
    }
    
    int root (int x){
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }
    
    bool same (int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    
    UnionFind tree(N);
    
    vector<int> p(N);
    rep(i, 0, N) cin >> p.at(i);
    vector<int> x(M), y(M);
    rep(i, 0, M){
        int x, y;
        cin >> x >> y;
        tree.unite(x - 1, y - 1);
    }
    int cnt = 0;
    rep(i, 0, N){
        if (tree.same(i, p.at(i) - 1)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int MAXN = 1e5 + 10, INF = 1e9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
string a, b;
int main() {
    cin >> a >> b;
    int N = a.length();
    if(N != b.length()) {puts("No"); return 0;}
    a = a + a;
    if(a.find(b) != string::npos) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;

int main() {
    int l, k;
    cin >> l >> k; k--;
    ll sm = 0;
    auto C = [](int n, int k) {
        ll c = 1;
        for (int i = 0; i < k; i++) {
            c *= (n - i);
            c /= (i + 1);
        }
        return c;
    };
    for (int u = 1; u <= 1000; u++) {
        //black:u
        //white:u-1
        int base = u + (u-1);
        if (l < base) break;
        int l2 = l - base;
        for (int f = 0; f <= u; f++) {
            if (l2 < f * k) break;
            sm += C(u, f);
        }
    }
    cout << sm << endl;
    return 0;
}

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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	ll N, K;
	ll ans;
	
	cin >> N >> K;
	
	ans = K * pow(K-1, N-1);
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int N = input.nextInt();
		int A = input.nextInt();
		int B = input.nextInt();

		int max = Math.min(A, B);
		int big = A;
		int small = B;
		if (big <= small) {
			big = B;
			small = A;
		}

		int min = Math.max(0, small - ( N - big ));

		System.out.println(max + " " + min);

	}

}


Measured memory_bytes: 21716
#include <stdio.h>
#include <cmath>

using namespace std;

double count(int sum, int init) {
  double log_count = ceil(double(log2(double(sum/init))));
  return log_count;
}

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  double ans = 0.0;
  for (int i = 1; i <= n; i++) {
    if (i >= k) {
      ans += (double) 1.0 / (double) n;
    } else {
      ans += pow((double)0.5, ceil((double)log2((double)k/(double)i))) / (double)n;
    }
  }

  printf("%.12f", ans);
}

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

int main() { 
  string S;
  cin >> S;
  ll K;
  cin >> K;
  int N = S.length();

  ll ans = 0;
  vector<pair<char, ll>> a;
  for (int i = 0; i < N-1; i++) {
    ll temp = 0;
    char x = S[i];
    while (S[i] == S[i+1] && i < N-1) {
      temp++;
      i++;
    }
    a.push_back(make_pair(x, temp+1));
    ans += (temp+1)/2;
  }
  if (N == 1) {
    a.push_back(make_pair(S[0], 1));
  }
  
  if (a.size() == 1) {
    ans = a.front().second*K/2;
  } else {
    ans *= K;
    if (a.front().first == a.back().first) {
      ans += ((a.front().second+a.back().second)/2 - a.front().second/2 - a.back().second/2) * (K - 1);
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

bool f(const string& s) {
	bool v=1;
	if(s.size()%2==1) return false;
	REP(i, s.size()/2) if(s[i]!=s[i+s.size()/2]) v=0;
	return v;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>s) {
		ll N=s.size();
		ll ans = -1;
		RANGE(i, 1, N) {
			if(f(s.substr(0, N-i))) {ans=N-i;break;}
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

int main() {
  int year = 0;
  int month = 0;
  int day = 0;
  
  string str;
  cin >> str;
  
  int slash = 0;
  for(int i = 0; i < str.size(); ++i) {
    if(str[i] == '/') {
      slash += 1;
      continue;
    } else if(slash == 0) {
      year = year * 10 + (str[i] - '0');
    } else if(slash == 1) {
      month = month * 10 + (str[i] - '0');
    } else if(slash == 2) {
      day = day * 10 + (str[i] - '0');
    }
  }
  
  if((year < 2019) || 
     (year == 2019 && month < 4) || 
     (year == 2019 && month == 4 && day <= 30)) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
  return 0;
}
    


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

#define FAST ios_base:: sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define sz(a) ll((a).size())
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

int main(){
	FAST;
	string s;
	cin >> s;
	ll ans = 0;
	ll cnt = 0;
	ll p = s.length();
	for(auto X : s){
		if(X=='o')	ans++;
	}
	if(ans+ 15 - s.length() >=8 )	cout << "YES";
	else		cout << "NO";
}





Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, A, B = map(int, readline().split())
H = list(map(int,read().split()))
H = sorted(H,reverse = True)
t = A-B

def solve(x):
    cnt = 0
    for i in range(N):
        rem = H[i]-x*B
        if rem <= 0:
            break
        else:
            cnt += -(-rem // t)
    if cnt <= x:
        return True
    else:
        return False 
    

left = 0
right = 10**9+5
while right - left > 1:
    x = (left + right) // 2
    flag = solve(x)
    if flag:
        right = x
    else:
        left = x
        
print(right)

Measured memory_bytes: 90072
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    B = sorted(A)
    m = B[-1]
    mm = B[-2]

    if m == mm:
        for _ in range(N):
            print(m)

    else:
        for a in A:
            if a != m:
                print(m)
            else:
                print(mm)


main()


Measured memory_bytes: 14112
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N, L;
	cin >> N >> L;
	int minimum = L;
	int sum = 0;
	rep(i,L, L+N){
		sum += i;
		if (abs(minimum) > abs(i)){
			minimum = i;
		}
	}
	cout << sum-minimum << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int x,y;
    while(true){
        cin >> x;
        cin >> y;
        if(x == 0 && y == 0){
            break;
        }
        if(x < y){
            cout << x << " " << y << endl;
        }
        else{
            cout << y << " "  << x << endl; 
        }
    }

}



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)

const string op = "+-*";

string S(int x) {
    stringstream ss;
    ss << x;
    return ss.str();
}

int calc(int a, char op, int b) {
    if (op == '+') return a + b;
    if (op == '-') return a - b;
    return a * b;
}

string solve(vector<int> a) {
    sort(a.begin(), a.end());
    do {
        rep(i,3) rep(j,3) rep(k,3) {
            if (calc(calc(calc(a[0], op[i], a[1]), op[j], a[2]), op[k], a[3]) == 10) {
                return "((" + S(a[0]) + " " + op[i] + " " + S(a[1]) + ")" + " " + op[j] + " " + S(a[2]) + ")" + " " + op[k] + " " + S(a[3]);
            }
            if (calc(calc(a[0], op[i], a[1]), op[j], calc(a[2], op[k], a[3])) == 10) {
                return "(" + S(a[0]) + " " + op[i] + " " + S(a[1]) + ")" + " " + op[j] + " " + "(" + S(a[2]) + " " + op[k] + " " + S(a[3]) + ")";
            }
        }
    } while (next_permutation(a.begin(), a.end()));
    return "0";
}

int main() {
    vector<int> a(4);
    while (cin >> a[0] >> a[1] >> a[2] >> a[3], a[0]) {
        cout << solve(a) << endl;
    }
    return 0;
}

Measured memory_bytes: 1248
x, y = map(int, input().split())
ans = 0
if x == 1:
    ans += 300000
elif x == 2:
    ans += 200000
elif x == 3:
    ans += 100000

if y == 1:
    ans += 300000
elif y == 2:
    ans += 200000
elif y == 3:
    ans += 100000

if x == 1 and y == 1:
    ans += 400000
    
print(ans)

Measured memory_bytes: 9188
from heapq import heappush, heappop
INF = 10**10

def dijkstra(n, G, s):
  dist = [INF] * n 
  que = [(0, s)]   
  dist[s] = 0
  last = [[] for _ in range(n)]
    
  while que:
    c, v = heappop(que)
    if dist[v] < c:
      continue
    for t, cost in G[v]: 
      if dist[v] + cost < dist[t]:
        dist[t] = dist[v] + cost
        heappush(que, (dist[t], t))                
        last[t].append(v)                        

  return dist,last

n,m = map(int,input().split())
G = [[]*n for _ in range(n)]
for i in range(m):
  a,b = map(int,input().split())
  G[a-1].append((b-1,1))
  G[b-1].append((a-1,1))
  
ans,last = dijkstra(n,G,0)

if max(ans) > m:
  print('No')
else:
  print('Yes')
  for i in range(1,n):    
    print(last[i][-1]+1)
    pass

Measured memory_bytes: 73532
#include <iostream>

using namespace std;

int main() {

  double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;

  while(cin >> xa1 >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2) {

    if(xa1>xb2 || xa2<xb1 || ya1>yb2 || ya2<yb1) goto NO;

    else goto YES;

  YES:
    cout << "YES" << endl;
    continue;

  NO:
    cout << "NO" << endl;

  }

  return 0;

}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	ll N;
	cin >> N;
	if (N % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	ll d = 5;
	N /= 10;
	ans += N;
	while (d <= N) {
		ans += N / d;
		d *= 5;
	}
	cout << ans << endl;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

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

const ull mod = 1000000007;

int main(void)
{
	ll n;
	cin >> n;
	vector<ll> vs(n);
	rep(i, n)
	{
		cin >> vs[i];
		vs[i] *= -1;
	}
	vector<ll> s;
	ll color = 0;
	rep(i, n) {
		auto item = vs[i];
		auto u = upper_bound(s.begin(), s.end(), item);
		if (u == s.end()) {
			color++;		
			s.insert(u, item);
		}
		else {
			s.erase(u);
			s.insert(u, item);
		}
	}
	cout << color << endl;
	return 0;
}


Measured memory_bytes: 2168
/*
author: Apoorv Singh
*/

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

using namespace std;
using namespace __gnu_pbds;

typedef vector <int> vi;
typedef vector <long long> vl;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define ll long long
#define pb push_back   
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second

ll modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

ll fpow(ll a, ll n)
{
    ll ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x;
    cin >> x;
    if (x == 3 or x == 5 or x == 7)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
# Bite Eating
import numpy as np

# input
N, L = map(int, input().split())

def taste(i, L=L):
    return L + i -1

T = [taste(i) for i in range(1, N+1)]

# solve
diff_value = np.inf
diff_total = np.inf

for i in range(N):
    if diff_value > abs(T[i]) and diff_total > abs(sum(T) - (sum(T) - T[i])):
        diff_value = abs(T[i])
        diff_total = abs(sum(T) - (sum(T) - T[i]))
        res = sum(T) - T[i]

# output
print(res)

Measured memory_bytes: 12408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Volume0021
{
    class Program
    {
        static void Main(string[] args)
        {
            int numOfDataset = int.Parse(Console.ReadLine());
            for (int i = 0; i < numOfDataset; ++i)
            {
                decimal[] pointsInfo = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
                if (Coordinate.Parallelism(pointsInfo))
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }
            }
        }
    }
    class Coordinate
    {
        internal static bool Parallelism(decimal[] PointABCD)
        {
            decimal xA = PointABCD[0];
            decimal yA = PointABCD[1];
            decimal xB = PointABCD[2];
            decimal yB = PointABCD[3];
            decimal xC = PointABCD[4];
            decimal yC = PointABCD[5];
            decimal xD = PointABCD[6];
            decimal yD = PointABCD[7];
            decimal slopeAB = 0;
            decimal slopeCD = 0;

            if (xB - xA == 0 && xD - xC == 0)
            {
                return true;
            }
            else if (xB - xA != 0 && xD - xC != 0)
            {
                slopeAB = (yB - yA) / (xB - xA);
                slopeCD = (yD - yC) / (xD - xC);
                if (slopeAB == slopeCD)
                {
                    return true;
                }
            }
            return false;
        }
    }
}



Measured memory_bytes: 16344
h,w=map(int,input().split())
C=[list(input()) for i in range(h)]
import copy
D=copy.deepcopy(C)
for i in range(h):
    for j in range(w):
        cnt=0
        if C[i][j]=="#":
            D[i][j]="#"
        else:
            if i>0 and j>0 and  C[i-1][j-1]=="#":
                cnt+=1
            if i>0 and  C[i-1][j]=="#":
                cnt+=1
            if i>0 and j<w-1 and C[i-1][j+1]=="#":
                cnt+=1
            if j>0  and C[i][j-1]=="#":
                cnt+=1
            if j<w-1 and C[i][j+1]=="#":
                cnt+=1
            if i<h-1 and j>0 and  C[i+1][j-1]=="#":
                cnt+=1
            if i<h-1 and  C[i+1][j]=="#":
                cnt+=1
            if i<h-1 and j<w-1 and  C[i+1][j+1]=="#":
                cnt+=1
            D[i][j]=str(cnt)
for k in range(h):
    mojiretu = ''.join(D[k])
    print(mojiretu)

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

using namespace std;

int W, H, N;

int solve(int fx, int fy, int tx, int ty) {
	int lenX, lenY;

	lenX = abs(fx - tx);
	lenY = abs(fy - ty);

	if ( (fx <= tx && fy >= ty) || (fx >= tx && fy <= ty) ) {
		return lenX + lenY;
	}
	return min(lenX, lenY) + abs(lenX - lenY);
}

int main() {
	int fromX, fromY, toX, toY, cnt;

	cnt = 0;
	cin >> W >> H >> N;
	cin >> fromX >> fromY;
	for (int i = 1; i < N; ++i) {
		cin >> toX >> toY;
		cnt += solve(fromX, fromY, toX, toY);
		fromX = toX;
		fromY = toY;
	}
	cout << cnt << endl;

	return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

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


int main()
{
    int n;
    string s;
    cin>>n>>s;
    bool ok=true;
    if(n%2!=0) ok=false;
    if(ok)
    {
        for (int i = 0; i < n/2; i++)
        {
            if(s[i]!=s[i+n/2])
            {
                ok=false;
                break;
            }
        }
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int a[MAXN];
int G[105][105];

int main()
{
    int h,w;
    while(scanf("%d%d",&h,&w)!=EOF)
    {
        int t;
        scanf("%d",&t);
        for(int i=1;i<=t;++i)
            scanf("%d",&a[i]);
        int cnt=1;
        for(int i=1;i<=h;++i)
        {
            if(i&1)
            {
                for(int j=1;j<=w;++j)
                {
                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }else
            {
                for(int j=w;j>=1;--j)
                {
                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }
        }
        for(int i=1;i<=h;++i)
        {
            for(int j=1;j<=w;++j)
            {
                if(j!=w) printf("%d ",G[i][j]);
                else printf("%d\n",G[i][j]);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>

using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	bool p[90001];
	p[0] = p[1] = 0;
	rep2(i,2,90001) {
		p[i] = 1;
	}
	rep2(i,2,301) {
		if(p[i]) {
			for(int j = 2; i * j < 90001; j++) {
				p[i * j] = 0;
			}
		}
	}
	int n;
	while(cin >> n) { 
		int k = n - 1;
		while(!p[k]) {
			k--;
		}
		cout << k << " ";
		k = n + 1;
		while(!p[k]) {
			k++;
		}
		cout << k << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n-1; i >= 0; i--)

int main() {
    int n, k;
    cin >> n >> k;
    
    vector<int> p(n);

    for (auto& item : p) {
        cin >> item;
    }

    sort(p.begin(), p.end());
    ll sum = 0;
    rep(i, k) {
        sum += p[i];
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <set>

using namespace std;

typedef long long int tint;

int main()
{ 
	string s;
	tint N;
	cin >> s >>N;
	tint cant = 0;
	if((int)s.size()==1)
	{
		cant =N/2;
	}else{
		int iguales=1;
		for(int i=1;i<(int)s.size(); i++)
		{
			if(s[i]==s[i-1] && iguales%2==1)
			{
				iguales++;
				cant++;
			}else if(s[i]==s[i-1] && iguales%2==0)
			{
				iguales++;
			}else
			{
				iguales=1;
			}
		}
		cant=cant*N;
		if(s[(int)s.size()-1]==s[0] && iguales%2==1)
		{			
			int igualesAlPrimero=1;
			for(int i=1;i<(int)s.size(); i++)
			{
				if(s[0]==s[i])
				{
					igualesAlPrimero++;
				}else 
				{
					break;
				}
			}
			if(igualesAlPrimero%2==1 && (int)s.size()!=igualesAlPrimero)
			{
				cant+= N-1;
			}else if(igualesAlPrimero%2==1 && (int)s.size()==igualesAlPrimero)
			{
				cant+= N/2;
			}
		}
	}

	cout<<cant<<endl;
}


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

using namespace std;

typedef long long ll;

const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();
const int MOD = 1000000007;

ll modpow(ll x, ll n) {
        ll ans = 1;
        while(n) {
                if(n & 1) ans = (ans * x) % MOD;
                x = (x * x) % MOD;
                n>>=1;
        }
        return ans;
}

ll COM(int n, int k) {
	ll ret = 1;
	ll div = 1;
	for (int i=0; i<k; i++) {
		ret = (ret * (n - i)%MOD)%MOD;
		div = (div * (i + 1)) % MOD;
	}
	div = modpow(div, MOD-2)%MOD;
	return (ret * div)%MOD;
}

int main(int, char**) {
	ll n, a, b;
	cin >> n >> a >> b;
	ll ret = modpow(2, n) - 1;
	ret += MOD - COM(n, a);
	ret %= MOD;
	ret += MOD - COM(n, b);
	ret %= MOD;

	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000009
#define mod 1000000007
#define int long long

int n, k, ans;

signed main()
{
    cin >> n >> k;
    int m = 0;
    int a = n / k;
    ans += a * a * a;
    if(k % 2 == 0){
        m = k / 2;
        if(n % k >= m){
            a++;
        }
        ans += a * a * a;
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
    vector<int> p;
    bool nonp[1000000] = {};
    nonp[0] = nonp[1] = true;
    for(int i = 2; i < 1000000; i++){
        if(nonp[i]) continue;
        p.push_back(i);
        for(int j = i+i; j < 1000000; j += i)   nonp[j] = true;
    }
    int l, r;
    cin >> l >> r;
    vector<int> v(r-l+1), cnt(r-l+1, 0);
    for(int i = 0; i <= r-l; i++){
        v[i] = l+i;
    }
    for(int x : p){
        int pos = (l+x-1)/x*x - l;
        while(pos <= r-l){
            while(v[pos]%x == 0)    v[pos] /= x, cnt[pos]++;
            pos += x;
        }
    }
    for(int i = 0; i <= r-l; i++)   if(v[i] != 1)   cnt[i]++;
    int ans = 0;
    for(int i = 0; i <= r-l; i++)   ans += !nonp[cnt[i]];
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    LL n;
    string s;
    cin>>n>>s;
    LL r=0,g=0,b=0;
    for(LL i=0;i<n;i++)
    {
        if(s[i]=='R')r++;
        if(s[i]=='G')g++;
        if(s[i]=='B')b++;
    }
    LL ans=r*g*b;
    set<char>st;
    for(LL j=0;j<n;j++)
    {
        for(LL i=j;i<n-j;i++)
        {
            st.clear();
            st.insert(s[i-j]);
            st.insert(s[i]);
            st.insert(s[i+j]);
            if(st.size()==3)
                ans--;

        }

    }
    cout<<ans;

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
const static int NMAX = 105;
const static int WMAX = 10005;
const static int DIAGONAL = 1;
const static int TOP = 0;

struct Item{
    int value, weight;
};

int N, W;
Item items[NMAX + 1];
int C[NMAX + 1][WMAX + 1], G[NMAX + 1][WMAX + 1];

void compute(int &maxValue, std::vector<int> &selection){
    for(int w = 0; w <= W; w++){
        C[0][w] = 0;
        G[0][w] = DIAGONAL;
    }

    for(int i = 1; i <= N; i++) C[i][0] = 0;

    for(int i = 1; i <= N; i++){
        for(int w = 1; w <= W; w++){
            C[i][w] = C[i-1][w];
            G[i][w] = TOP;
            if(items[i].weight > w) continue;
            if(items[i].value + C[i-1][w - items[i].weight] > C[i-1][w]){
                C[i][w] = items[i].value + C[i-1][w-items[i].weight];
                G[i][w] = DIAGONAL;
            }
        }
    }

    maxValue = C[N][W];
    selection.clear();

    for(int i = N, w = W; i >= 1; i--){
        if(G[i][w] == DIAGONAL){
            selection.push_back(i);
            w -= items[i].weight;
        }
    }

    reverse(selection.begin(), selection.end());
}

void input(){
    std::cin >> N >> W;
    for(int i = 1; i <= N; i++){
        std::cin >> items[i].value >> items[i].weight;
    }
}

int main(){
    int maxValue;
    std::vector<int> selection;
    input();
    compute(maxValue, selection);

    std::cout << maxValue << std::endl;

    return 0;
}


Measured memory_bytes: 11012
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

vector<string> foo;

void dfs(int rest, int cnt3 = 0, int cnt5 = 0, int cnt7 = 0, string s = ""){
    if(rest == 0){
        if(s.length() != 0){
            if(cnt3 == 0 || cnt5 == 0 || cnt7 == 0) return;
            foo.push_back(s);
        }
        return;
    }

    dfs(rest - 1, cnt3 + 1, cnt5, cnt7, s + '3');
    dfs(rest - 1, cnt3, cnt5 + 1, cnt7, s + '5');
    dfs(rest - 1, cnt3, cnt5, cnt7 + 1, s + '7');

    return;
}

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

    string s;
    cin >> s;
    int n = s.length();
    int N = stoi(s);
    for(int i = 1; i <= n; ++i) dfs(i);
    int ans = 0;
    for(string str : foo){
        int bar = stoi(str);
        if(bar <= N)    ++ans;
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string ans[] = {"First", "Second"}, s;
  cin >> s;
  if (s[0] == s[s.size()-1]) {
    cout << ans[s.size() % 2] << "\n";
  } else {
    cout << ans[1 - s.size() % 2] << "\n";
  }
}


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

int main()
{
    int N;
    cin >> N;

    int t, x, y;
    int prev_t = 0, prev_x = 0, prev_y = 0;

    for (int i = 0; i < N; i++)
    {
      	cin >> t >> x >> y;
        int d = abs(x - prev_x) + abs(y - prev_y);
        if ((t - prev_t) % 2 == d % 2 && d <= t - prev_t)
        {
            continue;
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }

        prev_t = t;
        prev_x = x;
        prev_y = y;
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256