akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

const int N = 8;
array<int, N> row;
array<bool, N> col;
array<bool, 2*N-1> dpos;
array<bool, 2*N-1> dneg;
array<array<bool, N>, N> X;

void print_board() {
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            if (X[i][j] && row[i] != j)
                return;
        }
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            auto c = row[i] == j ? "Q" : ".";
            cout << c;
        }
        cout << endl;
    }
}

void solve(int i) {
    if (i == N) {
        print_board();
        return;
    }

    for (int j = 0; j < N; ++j) {
        // (i, j)????????????????????????????????????????????????
        if (col[j] || dpos[i+j] || dneg[i-j+N-1]) {
            continue;
        }
        // (i, j)??????????????????????????????
        row[i] = j;
        col[j] = dpos[i+j] = dneg[i-j+N-1] = true;
        solve(i+1);
        // (i, j)?????????????????????????????????
        row[i] = 0;
        col[j] = dpos[i+j] = dneg[i-j+N-1] = false;
    }
}

int main() {
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
        int r, c;
        cin >> r >> c;
        X[r][c] = true;
    }

    fill(row.begin(), row.end(), -1);
    solve(0);

    return 0;
}

Measured memory_bytes: 3096
N = int(input())
H = [int(i) for i in input().split()]

for n in reversed(range(1,N)):
    if H[n] >= H [n-1]:
        continue
    elif H[n] == H[n-1]-1:
        H[n-1] -= 1
    else:
        print('No')
        exit()

print('Yes') 

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

int main() {
int h,n,x,i;
int sum=0;
cin>>h>>n;
for( i=0 ;i<n;i++)

{
  cin >>x;
  sum+=x;
}   

if (sum>=h)
cout<< "Yes";
else
cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <map>

using namespace std;

int solve(int R, int W, int C, int G){
    int count = 0;
    while(1){
        // cout<<(R + G * count) / C <<endl;
        if( (R + G * count) / C >= W)break;
        count++;
    }
    return count;
}

int main(void){
    int R,W,C,G;
    vector<int>ans;
    while(1){
        cin>>R>>W>>C>>G;
        if(!R && !W && !C && !G)break;
        ans.push_back(solve(R, W, C, G));
    }

    for(int a:ans )cout<<a<<endl;
}


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int POW(int a,int n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  LL A,B,K,i,ans=0;
  scanf("%lld%lld%lld",&A,&B,&K);
  if(K<A)A-=K;
  else if(K<A+B)B=A+B-K,A=0;
  else A=0,B=0;

  printf("%lld %lld\n",A,B);
	return 0;
}


Measured memory_bytes: 128
n = int(input())
s = input()
s = s.split(" ")
for i in range(n):
    s[i] = int(s[i])
flag = 1
count = 0
while flag:
    flag = 0
    for i in range(1,n):
        if s[i] < s[i-1]:
            v = s[i]
            s[i] = s[i-1]
            s[i-1] = v
            flag = 1
            count += 1
for i in range(n-1):
    print(s[i],end = " ")
print(s[n-1])
print(count)


Measured memory_bytes: 5608
a = [int(input()) for i in range(5)]
k = int(input())

ans = 0
for i in range(5):
    for j in range(i+1,5):
        if abs(a[i]-a[j]) <= k:
            ans += 1
if ans == 10:
    print("Yay!")
else:
    print(":(")

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

int main() {
	int M;
	cin >> M;
	cout << 48 - M;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、12月31日になるまでの残り時間は24-Mで求められる
また、12月31日になってから次の年になるまでの残り時間は24時間である
よって(24-M)+24=48-Mが答え
*/

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int max=101010;
  vector<int> a(max,1);
  a[0]=0;
  a[1]=0;
  for(int i=2;i<max;++i){
    for(int j=i*2;j<max;j+=i) a[j]=0;
  }
  vector<int> b(max,0);
  for(int i=0;i<max;i++){
    if(a[i]==1&&a[(i+1)/2]) b[i]=1;
  }
  
  vector<int> s(max+1,0);
  for(int i=0;i<max;i++) s[i+1]=b[i]+s[i];
  
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int l,r;
    cin>>l>>r;
    r++;
    cout<<s[r]-s[l]<<endl;
  }
  return 0;
}


Measured memory_bytes: 1792
n,m=map(int,input().split())
arr=[]
for i in range(n):
    s1=str(input())
    arr.append(s1)
row1=[]
col1=[]
for i in range(n):
    if(arr[i].count('.')<m):
        row1.append(i)
for j in range(m):
    for i in range(n):
        if(arr[i][j]!='.'):
            col1.append(j)
            break
for i in row1:
    s1=""
    for j in col1:
        s1+=arr[i][j]
    print(s1)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int streak = 0, ans = -1;
    string s;
    cin >> s;
    for(int i=0; i<(int)s.length(); i++){
        s[i]=='R'?streak++: streak=0;
        ans = max(streak, ans);
    }
    cout << ans;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;

int a[3],n;

int main()
{
    cin>>a[0]>>a[1]>>a[2];
    cin>>n;
    int ans = 0;
    for (int i=0; i<=n; ++i)
        for (int j=0; j<=n; ++j)
        {
            int now=a[0]*i+a[1]*j;
            int rem = n-now;
            if (rem>=0 && (rem%a[2]==0))
                ans+=1;
        }
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;


int main() {
 long long int a,b,c,d[100010],e[100010];
  
  cin >> a >>b;
  
  if(a -2*b >0){
    cout << a -2*b << endl;
  }
  else {
    cout << "0" << endl;
  }
}

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

const int tanka[] = {5, 7, 5, 7, 7};

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> len(n);
        for (int i = 0; i < n; i++) {
            string s; cin >> s;
            len[i] = s.size();
        }

        for (int i = 0; i < n; i++) {
            int idx = i;
            bool flag = true;
            for (int j = 0; flag && j < 5; j++) {
                int x = 0;
                while(idx < n && x < tanka[j]) {
                    x += len[idx];
                    idx++;
                }
                if (x != tanka[j]) flag = false;
            }
            if (flag) {
                cout << i + 1<< endl;
                break;
            }
        }
    }
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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;}

using PDI = pair<double, int32>;

const int64 mod = 1e9+7;

int main(void){
	int32 N;
	int32 A;
	cin >> N >> A;
	vector<int32> x(N);
	REP(i, N){
		cin >> x[i];
	}
	int64 dp[100][5000] = {};
	dp[0][0] = 1;

	REP(i, N){
		for(int32 j = N-1;j >= 0;j--){
			for(int32 k = 3000;k >= 0;k--){
				dp[j+1][k+x[i]] += dp[j][k];
			}
		}
	}
	int64 res = 0;
	REP(i, N){
		res += dp[i+1][(i+1)*A];
	}
	cout << res << endl;
}

Measured memory_bytes: 4096
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}



int main(){
	ll N;
	cin >> N;
	cout << N * (N-1) /2 << endl;
}



Measured memory_bytes: 3584
#include<bits/stdc++.h>
// #include<string.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define mkp make_pair
#define pi pair<int,int>
#define push push
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" "<< "endl";}}}
#define print1d(mat,n){for(int i=0;i<(int)(n);i++)cout<<mat[i]<<" ";cout<<endl;}
#define clr(a,x) memmultiset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<endl;
#define init(v,x) for (auto &itr:v){itr=x;}
#define minpq(x) x,vector<x>,greater<x>
#define ln length()
#define sz size()
#define inf 1e18;
int32_t main()
{
    fastIO
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    // #endif
    int n, a, b;
    cin >> n >> a >> b;
    int x = n / (a+b);
    int y = n % (a+b);
    cout << x * a + (y <= a ? y : a) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 10000
int A[2000001],C[N],B[2000001];
int main(){

  
  int n, i, j;
  scanf("%d", &n);

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

  for (i=0;i<n;i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }

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

  for (j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for (i=1;i<=n;i++){
    if (i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A, B, C; cin >> A >> B >> C;
    cout << min(B/A, C) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repf(i, j, n) for (int i = (j); i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)

signed main() {
  int n;
  cin >> n;
  int x, y;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(begin(a), end(a));
  int p = lower_bound(begin(a), end(a), 0) - begin(a);
  int m = 0;
  for (auto&& u : a) m += abs(u);

  if (a[0] <= 0 && a[n - 1] >= 0) {
    cout << m << endl;
    x = a[0];
    int j = n - 2;
    for (j = n - 2; j > 0 && a[j] >= 0; j--) {
      y = a[j];
      cout << x << " " << y << endl;
      x = x - y;
    }

    cout << a[n - 1] << " " << x << endl;
    x = a[n - 1] - x;
    for (j = 1; a[j] < 0; j++) {
      y = a[j];
      cout << x << " " << y << endl;
      x = x - y;
    }
  } else if (a[0] > 0) {
    cout << m - 2 * a[0] << endl;
    x = a[0];
    repf(i, 2, n) {
      y = a[i];
      cout << x << " " << y << endl;
      x = x - y;
    }
    cout << a[1] << " " << x << endl;
  } else {
    cout << m + 2 * a[n - 1] << endl;
    x = a[n - 1];
    rep(i, n - 1) {
      y = a[i];
      cout << x << " " << y << endl;
      x = x - y;
    }
  }
}


Measured memory_bytes: 2688
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int A[510][510];
int main()
{
	int k;cin>>k;
	if(k==1) return puts("1 1"),0;
	int n=(k+1)/2;
	if(n&1) n++;
	printf("%d\n",n);
	for(int i=1;i<=n;i+=2)
		for(int j=1;j<=n+1;j++)
			A[i][j]=(i+j-1-1)%n+1;
	for(int i=2;i<=n;i+=2)
		for(int j=1;j<=n;j++)
		{
			A[i][j]=A[i-1][j]+n;
			if(A[i][j]>k) A[i][j]=A[i-1][j+1];
		}
	for(int i=1;i<=n;i++,puts(""))
		for(int j=1;j<=n;j++)
			printf("%d ",A[i][j]);
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
ll mod=1e9+7;
ll kaizyou(ll a){
    if(a>1)return a*kaizyou(a-1)%mod;
    else return 1;
}
ll rep_pow(ll a,ll n){
    ll tmp;
    if(n==0)return 1;
    if(n%2==0){
        tmp=rep_pow(a,n/2);
        return tmp*tmp%mod;
    }
    return a*rep_pow(a,n-1)%mod;
}
int main(){
    ll n,a,b,ans=1,tmp,c_a,c_b;
    cin >> n >> a >> b;
    ans=rep_pow(2,n);
    c_a = 1LL;
    c_b = 1LL;
    rep(i,a){
        c_a=(c_a*(n-i))%mod;
    }
    rep(i,b){
        c_b=(c_b*(n-i))%mod;
    }
    c_a=(c_a*rep_pow(kaizyou(a),mod-2))%mod;
    c_b=(c_b*rep_pow(kaizyou(b),mod-2))%mod;
    tmp=(c_a+c_b)%mod;
    if(ans<tmp)ans=ans-tmp+mod;
    else ans-=tmp;
    cout << ans-1 << endl;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

void MAIN() {
  int n; cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int t; cin >> t;
    m[t]++;
  }
  int ans = 0;
  for (auto &i : m) {
    if (i.sc >= i.fi) ans += i.sc - i.fi;
    else ans += i.sc;
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 9576
#include <iostream>

#include <string>

using std::cin;
using std::cout;
using std::endl;

using std::string;

static long
calc(long fixed, long acc, string const &S, size_t index)
{
  if (index == S.size())
  {
    return fixed + acc;
  }
  return (calc(fixed + acc, S[index] - '0', S, index + 1)
          + calc(fixed, acc * 10 + S[index] - '0', S, index + 1));
}

static long
solve(string const &S)
{
  return calc(0, S[0] - '0', S, 1);
}

int
main()
{
  string S;
  cin >> S;
  cout << solve(S) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n; int const N = 5000;
  while(cin >> n){
    if(n == 0){return 0;}
    int  a[N],s,num,st,tmp;
    for(int i=0;i<n;i++)
      cin >> a[i];
    tmp=a[0];
    for(st = 0;st<n;st++){
      s = 0;
      for(int i = st;i<n;i++){
	s = s+a[i];
	tmp =max(s,tmp);
      }
    }
    cout << tmp<<endl;
  }
}
    

Measured memory_bytes: 0
N, X = map(int, input().split())

Ls = []
Ls.append(input().split())
# print(Ls)

Zahyo = [0]
for i in range(N) :
    Zahyo.append(int(Zahyo[i])+int(Ls[0][i]))
# print(Zahyo)

ans = []
for j in range(N+1) :
    if int(Zahyo[j]) <= X :
        ans.append("0")
print(len(ans))

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main()
{
	int A, B, X;

	cin >> A >> B >> X;

	if (A <= X && X <= A + B)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		char c;
		char cc;
		int sum[] = new int[26];
		try {
			while((str=br.readLine()) !=null){
				for(int i=0;i<str.length();i++){
					c=str.toLowerCase().charAt(i);
					cc='a';
					for(int j=0 ; j<sum.length;j++){
						if(c==cc){
							sum[j]++;
						}
						cc++;
					}
				}
			}
			cc='a';
			for(int i = 0 ; i < sum.length;i++){
				System.out.println(cc+" : "+sum[i]);
				cc++;
			}
		} catch (Exception e) {
			System.err.println(e);
		}
	}

}

Measured memory_bytes: 28432
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define PB push_back
#define MP make_pair
#define PF first
#define PS second
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;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 10e9;
const ld PI = 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

unsigned GetDigit(unsigned num){
    return std::to_string(num).length();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(str,K);IN(ll,D);
  ll dp[K.size()+1][D][2];
  REP(i,K.size()+1){
    REP(j,D){
      REP(k,2){
        dp[i][j][k] = 0;
      }
    }
  }
  dp[0][0][0] = 1;
  for(ll i = 1;i < K.size()+1; i++){
      ll z = K[i-1] - '0';
    REP(j,z){
        REP(k,D){
            dp[i][(j+k)%D][1] = (dp[i][(j+k)%D][1] + dp[i-1][k][0])%MOD;
        }
    }
    REP(j,10){
        REP(k,D){
            dp[i][(j+k)%D][1] = (dp[i][(j+k)%D][1] + dp[i-1][k][1])%MOD;
        }
    }
    REP(k,D){
        dp[i][(k+z)%D][0] = dp[i-1][k][0];
    }
  }
  if(dp[K.size()][0][0] + dp[K.size()][0][1] == 0){
    OUT(MOD-1);
    return 0;
  }
  OUT(dp[K.size()][0][0] + dp[K.size()][0][1] - 1);
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
int last[2050];
long long a[2050],f[2050][2050],mn[2050];
const long long inf=1e18;
int n;
long long x,ans;
int main(){
    scanf("%d%lld",&n,&x);
    rep(i,1,n) scanf("%lld",&a[i]),last[i]=i,mn[i]=a[i],ans+=a[i];
    rep(i,1,n){
        long long sum=x*i;
        rep(j,1,n) {
            last[j]--;
            if (last[j]==0) last[j]=n;  
            mn[j]=min(mn[j],a[last[j]]);
            sum+=mn[j];
        }
        ans=min(ans,sum);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
def prime_factorize(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
n = int(input())
ls = prime_factorize(n)
for i in range(len(ls)):
  ans = []
  pair = n // ls[i]
  ans.append(ls[i] + n // ls[i] - 2)
 
ans.sort()
print(ans[0])

Measured memory_bytes: 3272
//============================================================================
// Name        : c.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n;cin>>n;
	vector<string> s(n);
	for(int i=0;i<n;i++){
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
	}
	sort(s.begin(),s.end());
	long long ans=0;
	string ex=s[0];
//	for(int i=0;i<n;i++){
//		cout<<s[i]<<endl;
//	}
	long long count=1;
	for(int i=1;i<n;i++){
		if(i==n-1){
			if(ex==s[i]){
				count++;
			}
			ans+=count*(count-1)/2;
			break;
		}
		if(ex!=s[i]){
			ans+=count*(count-1)/2;
			count=1;
			ex=s[i];
		}else{
			count++;
		}
//		cout<<ans<<' '<<count<<' '<<ex<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 7296
/*
  AtCoder Beginner Contest 107
  C - Candles

  方針
    効率が良いろうそくの回るには、連続するK個のろうそくを回ればよい。
    先にK個の周るろうそくが決まっていた場合を考える。正の位置にあるろ
    うそくを回る場合も、負のろうそくを回る場合も、0に近い方から回るの
    が良く、移動距離は現在いる位置から最も遠くの位置にあるろうそくまで
    の距離に等しい。

    ここで正の位置にあるろうそくのうち、最も遠くにあるろうそくまでの
    距離をmaxpos、負の位置にあるろうそくのうち、最も遠くにあるろう
    そくまでの距離をmaxnegとすると、
    (1) 正のろうそくを先に回る場合
        distance = maxpos + (maxpos + maxneg)
                 = 2 * maxpos + maxneg
    (2) 負のろうそくを先に回る場合
        distance = maxneg + (maxneg + maxpos)
                 = 2 * maxneg + maxpos
    となる。
    以上から、最も遠くにあるろうそくがより近くにある方向（正 or 負）
    に先に回る方が良いことがわかる。

  実装
    連続するK個のろうそくを回るすべてのパターンを試す。

*/

#include<iostream>
#include<vector>
#include<limits>
using namespace std;

int N, K;

int main() {
  scanf("%d%d", &N, &K);
  vector<int> x(N);

  for (int n = 0; n < N; ++n) scanf("%d", &x[n]); 
  
  int minval = numeric_limits<int>::max();
  for (int n = 0; n + K <= N; ++n) {
    int l = x[n], r = x[n + K - 1];
    int maxpos = max(0, max(l, r));
    int maxneg = max(0, max(-l, -r));
    minval = min(minval, maxpos + maxneg + min(maxpos, maxneg));
  }

  printf("%d\n", minval);
  return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);

		int N = sc.nextInt();
		int Y = sc.nextInt();

		int r10 = -1;
		int r5 = -1;
		int r1 = -1;

		for (int x = 0; x <= N; x++) {
			for (int y = 0; y + x <=N; y++) {
				int z = N - x - y;
				int total = 10000*x + 5000*y + 1000*z;
				if (total == Y) {
					r10 = x;
					r5 = y;
					r1 = z;
				}
			}
		}

		System.out.println(r10 + " " + r5 + " " + r1);

	}


	static class FastScanner {

		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;

	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }


	}

}


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

int main(){
    long ans = 0;
    vector<long> x(5);
    for(int i=0; i<5; i++){
        cin >> x.at(i);
    }

    for(int i=0; i<5; i++){
        if(x.at(i)==0) ans =i+1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3624
n, a, b = [int(i) for i in input().split()]
hs = [None]*n
kill_b = [None]*n
for i in range(n):
    hs[i] = int(input())
max_hp = max(hs)
ret = 0
ab = a - b
right = max_hp // b
if((max_hp % b) != 0):
    right += 1
left = 1
while right != left:
    middle = (right + left) // 2
    # print([left, right, middle])
    all_a = 0
    for x in hs:
        nokori = x - (b * middle)
        if(nokori > 0):
            num_a = nokori // ab
            if(x > num_a * a + (middle - num_a) * b):
                num_a += 1
            all_a += num_a
    if(all_a <= middle):
        right = middle
    else:
        left = middle + 1
ret = right
print(ret)


Measured memory_bytes: 7924
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String S = sc.next();
		char[] s=S.toCharArray();

		long[][] rest = new long [3][n];

		for( int i=0 ; i<3 ; i++) {
			Arrays.fill(rest[i], -1);
		}
		long[] countRGB = {0,0,0};
		for( int i=n-1 ; i>=0 ; i--) {
			int c = "RGB".indexOf(s[i]);
			countRGB[c]++;
			rest[0][i]= countRGB[0];
			rest[1][i]= countRGB[1];
			rest[2][i]= countRGB[2];
		}
		long count=0;
		for( int i=0 ; i<n-2 ; i++) {
			for( int j=i+1 ; j<n-1 ; j++) {
				if( s[i]==s[j] )continue;
				int rgb =restIndex(s, i, j);
				
				count += rest[rgb][j+1];
				if( j+(j-i)<n && "RGB".indexOf(s[j+(j-i)]) == rgb ) {
					count--;
				}
			}
		}
		
		System.out.println(count);
	}

	private static int restIndex(char[] s, int i, int j) {
		if( s[i]=='R' && s[j]=='G') return 2;
		if( s[i]=='G' && s[j]=='R') return 2;
		if( s[i]=='R' && s[j]=='B') return 1;
		if( s[i]=='B' && s[j]=='R') return 1;
		if( s[i]=='B' && s[j]=='G') return 0;
		if( s[i]=='G' && s[j]=='B') return 0;
		return 0;
	}
	
}


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

double ans[3000][3000]={0};

int main(){
	int N;
	double p,sum=0;
	cin>>N>>p;
	ans[0][0]=1-p;
	ans[0][1]=p;
	for(int i=1;i<N;i++){
		cin>>p;
		ans[i][0]=ans[i-1][0]*(1-p);
		for(int j=1;j<=N;j++)ans[i][j]=ans[i-1][j-1]*p+ans[i-1][j]*(1-p);
	}
	for(int i=(N+1)/2;i<=N;i++)sum+=ans[N-1][i];
	cout<<std::setprecision(12)<<sum<<endl;
	return 0;
}


Measured memory_bytes: 70528
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

int main(){
	int x,a,b;
	cin >> x >> a >> b;
	if(abs(a - x) > abs(b - x)){
		cout << "B";
	}
	else cout << "A";
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
double pi = acos(-1.0);
const double EPS=1e-9;
#define MOD ll(1e9L+7)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define t() ll tt;cin>>tt;while(tt--) 
#define t2() ll tt2; cin>>tt2; for(ll tti=1;tti<=tt2;tti++)
#define printcj "Case #"<<tti<<": "
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cout << #x << " = " << x << "   " << #y << " = " << y << "=>";
#define debugarray(arr,n,x) { cout << "[" ; for(ll i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"] , "<<#x<<" = "<<x<<'\n';}

int main()
{
    fastio;
    int n;
    cin>>n;
    vector<ll>a(n),pre(n);
    vector<vector<ll>>dp(n,vector<ll>(n));
    
    cin>>a[0];
    pre[0]=a[0];
    for(ll i=1;i<n;i++){
        cin>>a[i];
        pre[i] =a[i]+pre[i-1];
    }

    //dp[i][j] = minimum total cost of combining interval [i,x] and [x+1,j] into [i,j]
    // dp[i][j] = min(dp[i][x]+dp[x+1][j]) + sum_of_interval[i,j]


    for(ll i=n-1;i>=0;i--)
    {
        dp[i][i] = 0; //base case
        for(ll j=i+1;j<n;j++)
        {
            dp[i][j] = pre[j] - (i?pre[i-1]:0); //current combining cost
            ll curmin=LLONG_MAX;
            for(ll x=i;x<j;x++) curmin = min(curmin,dp[i][x]+dp[x+1][j]);
            dp[i][j] += curmin;
        }
    }
    cout<<dp[0][n-1];



    
}


Measured memory_bytes: 4504
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if(b==0 && a%500!=0)
        cout<<"No";
    else if(b==0 && a%500==0)
        cout<<"Yes";
    else if(a<b)
        cout<<"Yes";
    else if(b<a && a%500!=0 && b>=(a%500))
        cout<<"Yes";
    else if(b==a)
        cout<<"Yes";
    else if(b<a && a%500!=0 && b<(a%500))
        cout<<"No";
    else if(a%500==0){
        cout<<"Yes";
    }
    return 0;
}

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

// ------------------
// Integer modulo MOD
// ------------------
const int64_t MOD = 1e9 + 7;
struct mint
{
    int64_t x;
    mint(int64_t x = 0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += MOD - a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(int64_t n) const
    {
        if (n == 0)
            return 1;
        mint t = pow(n >> 1);
        t *= t;
        if (n & 1)
            t *= *this;
        return t;
    }
    mint inv() const { return pow(MOD - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

// ---------------------------------------
// Number of combinations (nCk) modulo MOD
// ---------------------------------------
vector<mint> fac;
vector<mint> fac_inv;
vector<mint> inv;
void init_comb(int mx)
{
    fac = vector<mint>(mx + 1), fac_inv = vector<mint>(mx + 1), inv = vector<mint>(mx + 1);
    fac.at(0) = fac.at(1) = 1;
    fac_inv.at(0) = fac_inv.at(1) = 1;
    inv.at(1) = 1;
    for (int i = 2; i <= mx; i++)
    {
        fac.at(i) = fac.at(i - 1) * i;
        inv.at(i) = -inv.at(MOD % i) * (MOD / i);
        fac_inv.at(i) = fac_inv.at(i - 1) * inv.at(i);
    }
}
mint comb(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac.at(n) * fac_inv.at(k) * fac_inv.at(n - k);
}

mint f(int r, int c)
{
    return comb(r + c, c);
}

mint g(int r, int c)
{
    mint res = 0;
    for (int i = 1; i <= r + 1; i++)
    {
        res += f(i, c);
    }
    return res;
}

int main()
{
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    init_comb(2e6 + 1);
    cout << g(r2, c2) - g(r1 - 1, c2) - g(r2, c1 - 1) + g(r1 - 1, c1 - 1) << endl;
    return 0;
}


Measured memory_bytes: 47104
#include <iostream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

template <class Container>
bool check_all_elements_in_distance(Container begin, Container end, size_t distance)
{
    for (auto a = begin; a != end; ++a) {
        for (auto b = a+1; b != end; ++b) {
            // cout << "a:" << *a << " " << "b:" << *b << " " << "diff:" << std::abs(*a - *b) << endl;
            if (std::abs(*a - *b) > distance) { return false; }
        }
    }
    return true;
}

void echo_result (bool result)
{
    if (result) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
}

void test()
{
    vector<int64_t> array1 = {1,2,4,8,9};
    size_t distance1 = 15;
    echo_result(check_all_elements_in_distance(array1.begin(), array1.end(), distance1));

    vector<int64_t> array2 = {15,18,26,35,36};
    size_t distance2 = 18;
    echo_result(check_all_elements_in_distance(array2.begin(), array2.end(), distance2));

    vector<int64_t> array3 = {15,18,26,35,36};
    size_t distance3 = 20;
    echo_result(check_all_elements_in_distance(array3.begin(), array3.end(), distance3));

    vector<int64_t> array4 = {15,18,26,35,36};
    size_t distance4 = 21;
    echo_result(check_all_elements_in_distance(array4.begin(), array4.end(), distance4));

    vector<int64_t> array5 = {15,18,26,35,36};
    size_t distance5 = 22;
    echo_result(check_all_elements_in_distance(array5.begin(), array5.end(), distance5));
}

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

    vector<int64_t> elements(5, 0);
    size_t distance = 0;

    for(size_t i = 0; i < 5; ++i)
    {
        cin >> elements[i];
    }
    cin >> distance;

    bool result = check_all_elements_in_distance(elements.begin(), elements.end(), distance);
    echo_result(result);

    //test();
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll a;
long double b;
cin>>a>>b;
long double ans=a*b;
cout<<(ll)floor(ans)<<endl;
return 0;
}

Measured memory_bytes: 3744
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
signed main(){
	string s;
	cin>>s;
	rep(0,i,3){
		if(s[i]==s[i+1]){
			c("Bad")
			return 0;
		}
	}
	c("Good")
}			

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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

	
	int N;
	cin >> N;

	int kotae = 0;
	rep1(i, N) {
		kotae += i;
	}
	co(kotae);

	Would you please return 0;
}

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

int lcs (string x, string y) {
	int m = x.length();
	int n = y.length();
	int maxl = 0;
	vector<vector<int>> c(m + 1, vector<int>(n + 1, 0));

	x = ' ' + x;
	y = ' ' + y;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (x[i] == y[j]) {
				c[i][j] = c[i-1][j-1] + 1;
			} else {
				c[i][j] = max(c[i-1][j], c[i][j-1]);
			}
			maxl = max(maxl, c[i][j]);
		}
	}

	return maxl;
}

int main() {
	int q; cin >> q;
	for(int cnt = 0; cnt < q; cnt++){
		string x, y;
		cin >> x >> y;
		cout << lcs(x, y) << endl;
	}
	return 0;
}



Measured memory_bytes: 6832
fun main(args: Array<String>) {
    val scanner = System.`in`.bufferedReader()
    val input = scanner.readLine().split(" ").map(Integer::parseInt)
    val n = input[0]
    val m = input[1]
    val gates = Array(m) {
        scanner.readLine().split(" ").map(Integer::parseInt)
    }
    val min = gates.map { it[0] }
        .max() ?: 0
    val max = gates.map { it[1] }
        .min() ?: 0
    val ans = (1..n).filter { card ->
        card in min..max
    }.count()
    println(ans)
}

Measured memory_bytes: 60616
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string.h>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

enum Type{
	lunch,
	dinner,
	midnight,
	other,
};

struct Info{
	Type type;
	bool isOK;
};

Info func(char print_time[6],char serve_time[3]){

	Info ret;

	int print_hour = 10*(print_time[0]-'0')+print_time[1]-'0';
	int print_minute = 10*(print_time[3]-'0')+print_time[4]-'0';

	int serve_minute = 10*(serve_time[0]-'0')+serve_time[1]-'0';

	if(print_hour >= 11 && print_hour <= 14){
		ret.type = lunch;
	}else if(print_hour >= 18 && print_hour <= 20){
		ret.type = dinner;
	}else if((print_hour >= 21 && print_hour <= 23) || (print_hour >= 0 && print_hour <= 1)){
		ret.type = midnight;
	}else{
		ret.type = other;
		ret.isOK = false;
		return ret;
	}

	if(print_minute > serve_minute){
		serve_minute += 60;
	}

	if(serve_minute-print_minute <= 8){
		ret.isOK = true;
	}else{
		ret.isOK = false;
	}

	return ret;
}


int main(){

	int ok[3] = {0,0,0},total[4] = {0,0,0,0},N;

	char print_time[6],serve_time[3];

	Info tmp;

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

		for(int i = 0; i < 3; i++)ok[i] = 0;
		for(int i = 0; i < 4; i++)total[i] = 0;

		for(int loop = 0; loop < N; loop++){
			scanf("%s %s",print_time,serve_time);

			tmp = func(print_time,serve_time);

			total[tmp.type]++;
			if(tmp.isOK){
				ok[tmp.type]++;
			}

		}

		if(total[lunch] == 0){
			printf("lunch no guest\n");
		}else{
			printf("lunch %d\n",100*ok[lunch]/total[lunch]);
		}

		if(total[dinner] == 0){
			printf("dinner no guest\n");
		}else{
			printf("dinner %d\n",100*ok[dinner]/total[dinner]);
		}

		if(total[midnight] == 0){
			printf("midnight no guest\n");
		}else{
			printf("midnight %d\n",100*ok[midnight]/total[midnight]);
		}
	}

   return 0;
}

Measured memory_bytes: 2572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  string ans = "Yes";

  int n = s.size();
  for (int i = 0; i < n; ++i) {
    if (s[i] != s[n-i-1]) {
      ans = "No";
      break;
    }
  }

  int n2 = (n - 1) / 2;
  for (int i = 0; i < n2; ++i) {
    if (s[i] != s[n2-i-1]) {
      ans = "No";
      break;
    }
  }

  int n3 = (n + 3) / 2 - 1;
  for (int i = n3; i < n; ++i) {
    if (s[i] != s[n-i-1]) {
      ans = "No";
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int a,b,ans=0;
    cin >> a >> b;
    while(true){
        if(ans*2/25==a && ans/10==b){
            cout << ans << endl;
            break;
            }
        ans++;
        if(ans>=10000){
            cout << -1 << endl;
            break;
            }
    }
    return 0;
}

Measured memory_bytes: 3540
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = A.copy()


# 最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


while len(A) > 1:
    A.append(gcd(A.pop(), A.pop()))
if K % A[0] == 0 and any(map(lambda x: x >= K, B)):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 14224
#include<iostream>
#include<memory.h>

using namespace std;

int mat[301][301];

int main()
{
    int a,b;

    while(cin>>a>>b&&!(a==0&&b==0))
    {
        memset(mat,0,sizeof(mat));

        for(int i=0;i<b;i++)
        {
            mat[0][i]=mat[a-1][i]=1;
        }
        for(int i=0;i<a;i++)
        {
            mat[i][0]=mat[i][b-1]=1;
        }
        for(int i=0;i<a;i++)
        {
            for(int j=0;j<b;j++)
            {
                if(mat[i][j]==1)
                {
                    cout<<'#';
                }else
                {
                    cout<<'.';
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }

    return 0;
}



Measured memory_bytes: 3444
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

// Data :
type Data struct {
	a, b int
}

// Datas :
type Datas []Data

func (p Datas) Len() int {
	return len(p)
}

func (p Datas) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Datas) Less(i, j int) bool {
	if p[i].b == p[j].b {
		return p[i].a < p[j].a
	}
	return p[i].b < p[j].b
}

func main() {
	sc.Split(bufio.ScanWords)
	_, M := getInt(), getInt()
	n := make(Datas, M)
	for i := 0; i < M; i++ {
		a, b := getInt(), getInt()
		n[i] = Data{a, b}
	}

	sort.Sort(n)
	// out(n, N)

	cut := -1
	ans := 0
	for i := 0; i < M; i++ {
		// out(n[i], cut)
		if n[i].a > cut {
			// out("cut", n[i].b)
			cut = n[i].b - 1
			ans++
		}
	}
	out(ans)
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

ll N, x, ans = infll, sum;

int main()
{
    cin >> N >> x;
    vector<ll> a(N), b(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];

    for (int i = 0; i < N; i++, sum = 0LL)
    {
        for (int j = 0; j < N; j++)
        {
            sum += (b[j] = i == 0 ? a[j] : min(b[j], a[(N + j - i) % N]));
        }
        ans = min(sum + x * i, ans);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    H = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    n = 0
    while (True):
        n += 1
        H = H // 2
        if H == 0:
            break

    print(sum([2**(i - 1) for i in range(1, n + 1)]))


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4"""
        output = """7"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1000000000000"""
        output = """1099511627775"""
        self.assertIO(input, output)


Measured memory_bytes: 6372
#include<bits/stdc++.h>
using namespace std;
const int N=110000;
char a[N];
int but[N];
int n;
void outa()
{
  int pos=-1;
  for(int i=25;i>=0;i--) if(!but[i]) pos=i;
  printf("%s",a);
  printf("%c\n",(char)(pos+'a')); 
  return; 
}
void outb()
{
  int pos=-1;
  for(int i=1;i<n;i++) if(a[i-1]<a[i]) pos=i-1;
  for(int i=0;i<pos;i++) printf("%c",a[i]);
  for(int i=pos;i<n;i++) but[a[i]-'a']--;
  int las=-1;
  for(int i=25;i>=0;i--) if(!but[i]&&i>a[pos]-'a') las=i;
  printf("%c\n",(char)('a'+las));
  return;
}
int main()
{
  scanf("%s",a);
  n=strlen(a);
  for(int i=0;i<n;i++) but[a[i]-'a']++;
  int flag=0;
  for(int i=1;i<n;i++) if(a[i-1]-1!=a[i]) flag=1;
  if(!flag&&n==26) return printf("-1\n"),0;
  if(n==26) outb();
  else outa();
  return 0;
}

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

long long h, n;
vector<long long> a;

int main() {
  cin >> h >> n;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) h -= a[i];
  if(h <= 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1024
#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> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

struct Segmenttree{
    int n;
    vector<long long> node;

    Segmenttree(vector<long long> v){
        n = (int)(v.size());
        node.resize(2*n);
        for(int i=0;i<n;i++) node[i+n] = v[i];
        for(int i=n-1;i>=0;i--) node[i] = max(node[i<<1],node[i<<1|1]);
    }
    //i番目の要素をxに変更する
    void update(int i,long long x){
        i += n;
        node[i] = x;
        while(i>1){
            i >>= 1;
            node[i] = max(node[i<<1],node[i<<1|1]);
        }
    }
    //[l,r)の要素のmaxを求める
    long long query(int l,int r){
        long long res = 0;
        l += n; r += n;
        while(l<r){
            if(l&1) res = max(res,node[l++]);
            if(r&1) res = max(res,node[--r]);
            l >>= 1; r >>= 1;
        }
        return res;
    }
    //i番目の要素にアクセス
    long long getval(int i){
        return node[i+n];
    }
};

int main(){
    ll h,w,m;
    cin >> h >> w >> m;
    vector<P> hw(m);
    rep(i,m) cin >> hw[i].first >> hw[i].second;
    rep(i,m) --hw[i].first,--hw[i].second;
    vector<set<int>> st(h);
    Segmenttree seg(vector<ll>(w,0));
    rep(i,m){
        st[hw[i].first].insert(hw[i].second);
        ll p = seg.getval(hw[i].second);
        seg.update(hw[i].second,p+1);
    }
    ll ans=0;
    rep(i,h){
        ll res = (ll)(st[i].size());
        for(int j:st[i]){
            ll p = seg.getval(j);
            seg.update(j,p-1);
        }
        res += seg.query(0,w);
        ans = max(ans,res);
        for(int j:st[i]){
            ll p = seg.getval(j);
            seg.update(j,p+1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 38488