akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
typedef pair<int, P> PP;

int mx[2][6] = {
  {-1, 0, 1, 0, -1, -1},
  {0, 1, 1, 1, 0, -1}
};
int my[2][6] = {
  {-1, -1, 0, 1, 1, 0},
  {-1, -1, 0, 1, 1, 0}
};

int W, H, S, T;

void update(int sy, int sx, vector< vector<int> > &v){
  queue<PP> open;
  open.push(PP(0, P(sy, sx)));
  v[sy][sx] = 0;
  while(!open.empty()){
    PP pp = open.front(); open.pop();
    int y = pp.second.first, x = pp.second.second, n = pp.first, t = (y % 2 == 0);
    REP(i, 6){
      int ny = y + my[t][i], nx = x + mx[t][i];
      if(ny <= 0 || nx <= 0 || ny > H || nx > W || v[ny][nx] <= n + 1) continue;
      v[ny][nx] = n + 1;
      open.push(PP(n + 1, P(ny, nx)));
    }
  }
}

int countC(int sy, int sx, vector< vector<int> > &v){
  queue<PP> open;
  open.push(PP(0, P(sy, sx)));
  vector< vector<bool> > visited(H + 1, vector<bool>(W + 1, 0));
  visited[sy][sx] = 1;
  int res = 0;
  while(!open.empty()){
    PP pp = open.front(); open.pop();
    int y = pp.second.first, x = pp.second.second, n = pp.first, t = (y % 2 == 0);
    if(v[y][x] > n) ++res;
    REP(i, 6){
      int ny = y + my[t][i], nx = x + mx[t][i];
      if(ny <= 0 || nx <= 0 || ny > H || nx > W || v[ny][nx] <= n + 1 || visited[ny][nx]) continue;
      visited[ny][nx] = 1;
      open.push(PP(n + 1, P(ny, nx)));
    }
  }
  return res;
}

int main() {
  while(cin >>W >>H && W && H){
    vector< vector<int> > v(H + 1, vector<int>(W + 1, 1e9));
    cin >>S;
    REP(s, S){
      int x, y; cin >>x >>y;
      update(y, x, v);
    }
    cin >>T;
    int ans = 0;
    REP(t, T){
      int x, y; cin >>x >>y;
      ans = max(ans, countC(y, x, v));
    }
    cout <<ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i < n; i++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;

char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<ll,ll> P;

ll n;
ll a[100000];
ll b[100000];
ll ans[100000];
vector<int> x;

int main(){
    L(n);
    rep(i,n) L(a[i]);
    rep(i,n) b[i] = a[i];
    ll now = -1;
    for(int i = 0; i < n; i++){
        if(now < a[i]){
            x.push_back(i);
            now = a[i];
        }
    }
    ll sum = 0;
    ll it = 0;
    ll sam = 0;
    sort(b,b+n,greater<ll>());
    for(int i = x.size()-1; i >= 1; i--){
        ans[x[i]] += sam*(a[x[i]]-a[x[i-1]]);
        for(;it < n; it++){
            if(b[it] > a[x[i-1]]){
                ans[x[i]] += b[it]-a[x[i-1]];
                sam++;
                continue;
            } else if(b[it] == a[x[i-1]]){
                sam++;
                continue;
            }
            break;
        }
        sum += ans[x[i]];
    }
    rep(i,n) ans[0] += a[i];
    ans[0] -= sum;
    rep(i,n){
        cout << ans[i] << endl;
    }
}
































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

public class Main{

	public static void main(String[] args){
		solve();
	}

	public static void solve(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0){
				break;
			}
			String[] s = new String[n];
			for(int i=0;i<n;i++){
				s[i] = sc.next();
			}
			String[] t = new String[n];
			for(int i=0;i<n;i++){
				for(int j=0;j<s[i].length();j++){
					if(j==0){
						t[i] = s[i].substring(j,j+1);
					}
					if(j!=s[i].length()-1 && (s[i].charAt(j)=='a' || s[i].charAt(j)=='i' ||
						s[i].charAt(j)=='u' || s[i].charAt(j)=='e' ||
						s[i].charAt(j)=='o')){
						t[i] = t[i] + s[i].substring(j+1,j+2);
					}
				}
			}
			int max = 0;
			for(int i=0;i<n;i++){
				//System.out.println(t[i]);
				max = Math.max(max,t[i].length());
			}
			boolean judge = true;
			for(int k=1;k<=max;k++){
				judge = true;
				for(int i=0;i<n;i++){
					for(int j=i+1;j<n;j++){
						String a = t[i].substring(0,Math.min(k,t[i].length()));
						String b = t[j].substring(0,Math.min(k,t[j].length()));
						if(a.compareTo(b)==0){
							judge = false;
						}
					}
				}
				if(judge){
					System.out.println(k);
					break;
				}
				else if(k==max){
					System.out.println(-1);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 67704
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(void){
  int N;
  double sum = 0;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a[i];
    sum += a[i];
  }
  sum /= (double)N;
  int ans = 0;
  for(int i=1;i<N;i++){
    if(abs(a[i]-sum)<abs(a[ans]-sum)){
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
const int maxn = 1e5+10;
typedef long long ll;
ll a[maxn];
map<int,int>tot;
set<int>side;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n)
	{
		tot.clear();
		side.clear();
		int x;
		for(int i=0;i<n;i++)
		{
			cin>>x;
			tot[x]++;
		}
		map<int,int>::iterator it;
		long long maxrec=0;
		for(it = tot.begin();it!=tot.end();it++)
		{
			if(it->second>=2)
			{
				side.insert(it->first);
			}
			if(it->second>=4)
			{
				long long tmp = it->first;
				maxrec = max(maxrec,tmp*tmp);
			}
		}
		if(side.size()<2&&maxrec==0)
		{
			puts("0");
			continue;
		}
	    set<int>::reverse_iterator itt;
	    long long ans = 1;
	    int cnt = 0;
		for(itt=side.rbegin();itt!=side.rend();itt++)
		{
			ans *= *itt;
			cnt++;
			if(cnt==2)
				break;
		}
		maxrec = max(maxrec,ans);
		cout<<maxrec<<endl;
	 } 
	return 0;
 } 

Measured memory_bytes: 4992
import java.util.Scanner;

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

	int a = scan.nextInt();
	int b = scan.nextInt();

	int n = b-a;
	int h = n*(n+1)/2;
	System.out.println(h-b);
    }
}


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

int main() {
  int n;
  cin >> n;
  int cntb = 0, cnta = 0, both = 0, ab = 0;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    int l = s.size();
    for(int j = 0; j < l-1; j++){
      if(s.at(j) == 'A' && s.at(j+1) == 'B') ab++;
    }
    if(s.at(0) == 'B'){
      if(s.at(l-1) == 'A') both++;
      else cntb++;
    }
    else if(s.at(l-1) == 'A') cnta++;
  }
  
  if(both == 0) ab += min(cnta, cntb);
  else if(cnta + cntb == 0) ab += both - 1;
  else ab += min(cnta, cntb) + both;
  cout << ab << endl;
}

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

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

    int N, count = 0;
    cin>>N;  //データの数の入力
    int a[N];
    for(int i = 0; i < N; i++) cin>>a[i];  //データの入力

    //バブルソート
    for(int i = 0; i < N; i++) {
        for(int j = N-1; j > i; j--) {
            if(a[j] < a[j-1]) {
                int s = a[j-1]; //入れ替えのための値保持
                a[j-1] = a[j];
                a[j] = s;
                count++;  //カウント
            }
        }
    }

    //出力
    for(int i = 0; i < N-1; i++) cout<<a[i]<<' ';
    cout<<a[N-1]<<endl;
    cout<<count<<endl;
    return 0 ;
}



Measured memory_bytes: 3148
from collections import Counter
N = int(input())
S = input()
#c = Counter(S)
#print (c.most_common())
#ls = list(c.values())
ans = S.count('R') * S.count('G') * S.count('B')


for i in range(N):
    for j in range(1,N):
        a = i + j
        b = i + j + j
        if (b >= N):
            break
        else:
            l = S[i]
            m = S[a]
            r = S[b]
            if l!=m and m!=r and r!=l:
                ans -= 1
        # if (i-j<0 or i+j>=N):
        #     break
        # l = S[i-j]
        # m = S[i]
        # r = S[i+j]
        # if l!=m and m!=r and r!=l:
        #     ans -= 1
print (ans)


Measured memory_bytes: 9460
import itertools

N=int(input())
march='MARCH'
S=[]
counter={'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(N):
    s=input()
    if s[0] in march:
        counter[s[0]]+=1
        S.append(s)
ans=0
if len(S)>=3:
    select=list(itertools.combinations(march,3))
    for i in range(len(select)):
        key=[]
        key.append(select[i][0])
        key.append(select[i][1])
        key.append(select[i][2])
        ans+=counter[key[0]]*counter[key[1]]*counter[key[2]]
print(ans)

Measured memory_bytes: 9908
#include <stdio.h>
using namespace std;
int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((x >= r && x <= W-r) && (y >= r && y <= H-r))
		printf("Yes\n");
	else{
		printf("No\n");
	}
}


Measured memory_bytes: 2696
# include <cstdio>
# include <vector>
# include <algorithm>
# define REP(i, n) for (int i = 1; i <= n; ++ i)

using namespace std;
int n, K;
vector <int> e[2010];

int dfs (int x, int fa, int d) {
	if (d > K) return 0;
	int sz = 1;
	for (int v : e[x]) if (v != fa) sz += dfs (v, x, d + 1);
	return sz;
}

int main () {
	scanf ("%d%d", &n, &K); int t1, t2;
	REP (i, n - 1) 
		scanf ("%d%d", &t1, &t2), e[t1].push_back (t2), e[t2].push_back (t1);
	if (K % 2 == 0) {
		int ans = n; K /= 2;
		REP (i, n) ans = min (ans, n - dfs (i, 0, 0));
		printf ("%d\n", ans);
	} else {
		int ans = n; K /= 2;
		REP (x, n) for (int v : e[x]) ans = min (ans, n - dfs (x, v, 0) - dfs (v, x, 0));
		printf ("%d\n", ans);
	}
	return 0;
}


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;

const int mod = 1000000007;
ll dp[100005];

int main() 
{
    int n, m;
    cin >> n >> m;

    int a[n] = {0};
    rep(i,m) {
        int idx;
        cin >> idx;
        idx--;
        a[idx]++;
    }

    dp[0] = 1;
    for(int i=1; i<=n; i++) {
        if (a[i-1] == 1) {
            dp[i] = 0;
            continue;
        }
        dp[i] += dp[i-1];
        dp[i] %= mod;
        if (i>=2) {
            dp[i] += dp[i-2];
            dp[i] %= mod;
        }

    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1408
import numpy as np

a = list(map(int,input().split()))
pi = np.pi
s = a[0]
l = a[1]
shi = a[2]
lon = a[3]
shi = shi * 30
shi = shi + 0.5*lon
lon = lon * 6
shi = shi*pi/180
lon = lon*pi/180
x_s = np.cos(shi)*s
y_s = np.sin(shi)*s
x_l = np.cos(lon)*l
y_l = np.sin(lon)*l
x = abs(x_s-x_l)
y = abs(y_s-y_l)
z = (x**2 + y**2)**(1/2)

print(z)

Measured memory_bytes: 27172
import heapq

N, M  = [int(x) for x in input().split()]
l = [-int(x) for x in input().split()]
heapq.heapify(l)
for i in range(M):
  h = heapq.heappop(l)
  h = -h // 2
  heapq.heappush(l, -h)
print(-sum(l))

Measured memory_bytes: 14180
import java.util.*;

public class Main {

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

        String[] sArr = s.split("/");
        int yyyy = Integer.valueOf(sArr[0]);
        int mm = Integer.valueOf(sArr[1]);
        int dd = Integer.valueOf(sArr[2]);

        String ans = "Heisei";

        Date border = new Date(2019, 4, 30);
        Date targetDate = new Date(yyyy, mm, dd);

        if (targetDate.compareTo(border) > 0) ans = "TBD";

        System.out.println(ans);
    }
}


Measured memory_bytes: 23248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
const ll mo=1000000007;
const ll INF=1<<30;
ll ans=0;
bool v[16020];
bool vv[16020];

int main()
{ 
string s;
cin >> s; 
ll x,y;
cin >> x>>y;
vector<ll> xx;
vector<ll> yy;
ll temp=0;
bool xy=0;
rep(i,s.size()){
    if(s[i]=='F')temp++;
    else break;
}
x=x-temp;
ll a=temp;
temp=0;
for(ll i = a; i < (ll)(s.size()); i++){
    if(s[i]=='F')temp++;
    else{
        if(xy){
            if(temp!=0)yy.push_back(temp);
            xy=0;
            temp=0;
        }
        else{
            if(temp!=0)xx.push_back(temp);
            xy=1;
            temp=0;
        }
    }
} 
if(temp!=0){
    if(xy)yy.push_back(temp);
    else xx.push_back(temp);
}

if(xx.size()==0){
    if(x!=0){
        cout << "No" << endl;
        return 0;
    }
}
else{
    rep(i,16020){
        v[i]=false;
        vv[i]=false;
    }
    v[0+8010]=true;
    rep(i,xx.size()){rep(j,16020){
        if(v[j]){
            vv[j+xx[i]]=true;
            vv[j-xx[i]]=true;
        }
    }
    rep(j,16020){
        v[j]=vv[j];
        vv[j]=false;
    }
    }
    if(!v[x+8010]){
        cout << "No" << endl;
        return 0;
    }
}

if(yy.size()==0){
    if(y!=0){
        cout << "No" << endl;
        return 0;
    }
}
else{
    rep(i,16020){
        v[i]=false;
        vv[i]=false;
    }
    v[0+8010]=true;
    rep(i,yy.size()){rep(j,16020){
        if(v[j]){
            vv[j+yy[i]]=true;
            vv[j-yy[i]]=true;
        }
    }
    rep(j,16020){
        v[j]=vv[j];
        vv[j]=false;
    }
    }
    if(!v[y+8010]){
        cout << "No" << endl;
        return 0;
    }
}


cout << "Yes" << endl;
return 0;
} 

Measured memory_bytes: 384
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout]
fn main() {
    input! {
        N: usize, W: usize,
        wv: [(usize, i64); N]
    }

    let mut ans = 0;
    for k in 1..=N {
        let w0 = wv[0].0;
        if W < k * w0 {
            continue;
        }
        let W = min(W - k * w0, 3 * k);
        let wv = wv.iter().map(|&(w, v)| (w - w0, v)).collect_vec();

        let mut dp = vec![vec![-1<<60; 3 * k + 1]; k + 1];
        dp[0][0] = 0;
        for (w, v) in wv.into_iter() {
            for count in (0..k).rev() {
                for prev_w in (0..=3*k-w).rev() {
                    let prev_v = dp[count][prev_w];
                    dp[count+1][prev_w+w] = max(dp[count+1][prev_w+w], prev_v+v);
                }
            }
        }
        for w in 0..=W {
            ans = max(ans, dp[k][w]);
        }
    }
    println!("{}", ans);
}


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

bool a[8],b[4];
bool ue(int n)
{
	int pos = 128;
	for(int i=0;i<8;i++){
		if(n/pos==1){
			a[i] = 1;
			n %= pos;
		}else{
			a[i] = 0;
		}
		pos/=2;
	}
	if(n==0)
		return true;
	else
		return false;
}

bool sita(double n)
{
	double pos = 0.5;
	for(int i=0;i<4;i++){
		if(n-pos >= 0){
			b[i] = 1;
			n -= pos;
		}else{
			b[i] = 0;
		}
		pos/=2;
	}
	if(n==0)
		return true;
	else
		return false;
}

int main()
{
	double n;
	while(cin >> n){
		if(n < 0)
			break;
		if(ue(static_cast<int>(n)) && sita(n-static_cast<int>(n))){
			for(int i=0;i<8;i++){
				cout << a[i];
			}
			cout << ".";
			for(int i=0;i<4;i++){
				cout << b[i];
			}
			cout << endl;
		}else{
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

#define SWAP(type, a, b) { type work = a; a = b; b = work; }

using namespace std;

void my_qsort(int *array, size_t size);
void qsort_rec(int *array, int begin, int end);
inline int select_pivot(const int *array, int begin, int end);

int main() {
    int n, k;
    int index[200000];
    unsigned long int ans = 0;

    cin >> n >> k;
    for (int i = 0; i < n ;i++) {
        cin >> index[i]; 
    }
    my_qsort(index, n);
    for (int i = 0; i < (n-k) ;i++) {
        ans += index[i];
    }
    cout << ans << "\n"; 

    return 0;
}

void my_qsort(int *array, size_t size)
{
    qsort_rec(array, 0, (int)(size - 1));
}
void qsort_rec(int *array, int begin, int end)
{
    int pivot = select_pivot(array, begin, end);
    int i = begin;
    int j = end;
    
    while(1) {
        while(array[i] < pivot) { ++i; }
        while(array[j] > pivot) { --j; }
    
        if (i >= j) { break; }
        SWAP(int, array[i], array[j]);
        i++;
        j--;
    }

    if (i - begin >= 2) {
        qsort_rec(array, begin, i-1);
    }
    
    if (end - j >= 2) {
        qsort_rec(array, j + 1, end);
    }
}
inline int select_pivot(const int *array, int begin, int end)
{
    return array[(begin + end) / 2];
} 

Measured memory_bytes: 1024
/*input
314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, sum = 0; cin >> n;
    int m; cin >> m;
    for(int i = 0; i < m; i++)
    {
    	int a; cin >> a;
    	sum += a;
    }
    cout << (n >= sum ? n - sum : -1);

    return 0;
}

Measured memory_bytes: 3648
program main
  implicit none

  integer :: n, i
  integer(16) :: inf
  integer(16), allocatable :: h(:), dp(:)

  read(*,*) n
  allocate(h(n))
  allocate(dp(n))
  read(*,*) h

  inf = 1000000000000_16
  do i = 1, n
     dp(i) = inf
  end do

  dp(1) = 0
  dp(2) = abs(h(2) - h(1))

  do i = 3, n
     dp(i) = min(dp(i), dp(i-1)+abs((h(i) - h(i-1))))
     dp(i) = min(dp(i), dp(i-2)+abs((h(i) - h(i-2))))
  end do

  write(*,*) dp(n)

end program main


Measured memory_bytes: 3840
#include<stdio.h>
int main(){

  int n,i,max,min,a[10000];
  long long int sum;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  max=a[0];
  min=a[0];
  for(i=0;i<n;i++){
    if(min>a[i]){
      min=a[i];
    }
    if(max<a[i]){
      max=a[i];
    }
    sum+=a[i];
  }
  printf("%d %d %lld\n",min,max,sum);
 
  return 0;
}

Measured memory_bytes: 636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long MOD = 1000000007;

        public void Run()
        {
            N = Input.ReadInt();
            var ps = new List<int>();
            var cs = new List<int>();
            for (int i = 0; i < N; i++)
            {
                ps.Add(Input.ReadInt());
            }

            for (int i = 0; i < N; i++)
            {
                cs.Add(Input.ReadInt());
            }

            ps.Sort();
            cs.Sort();

            var pi = 0;
            var ci = 0;
            int p = 0;
            int c = 0;
            long ret = 1;

            while (true)
            {
                if (ci == N || (pi != N && ps[pi] < cs[ci]))
                {
                    pi++;
                    p++;
                }
                else
                {
                    ci++;
                    c++;
                }

                if (c > 0 && p > 0)
                {
                    ret *= (c * p);
                    ret %= MOD;
                    c--;
                    p--;
                }

                if (pi == N && ci == N) break;
            }

            Console.WriteLine(ret);
        }
    }
    
    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 17116
import javax.management.MXBean;
import java.io.*;
import java.util.*;

public class Main {
    void run() {
        int W = readInt();
        int H = readInt();
        int X = readInt();
        int Y = readInt();
        int R = readInt();
        if (X - R >= 0 && Y - R >= 0 && X + R <= W && Y + R <= H) {
            sysout.println("Yes");
        } else {
            sysout.println("No");
        }
    }

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

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = null;

    String readLine() {
        buffer = null;
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    String read() {
        if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }
}

Measured memory_bytes: 17056
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#define F first
#define S second
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30, MAX_N = int(1e6);


int main(){

  int n, i, j, maxin = 2;
  bool jud;
  vector <int> vec;
  for(i = 2;i <= MAX_N; i++){
        jud = 0;
        for(j = 0;  j < vec.size() ; j++){
          if(vec[ j ] * vec[ j ] > i) break;
          if( !( i % vec[ j ] ) ){
            jud = 1;
            break;
          }
        }
        if(!jud)
          vec.push_back( i );
      }
  while(cin >> n){
    cout << upper_bound(vec.begin(), vec.end(), n) - vec.begin()   <<endl;
  }
}

Measured memory_bytes: 1588
#!python3

# input
A, B, N = list(map(int, input().split()))


def f(x):
    ret = int(A * x / B) - A * int(x / B)
    return ret


def main():
    ans = f(min(B - 1, N))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9036
#include<stdio.h>
int IP(int);
  
int main()
{
  int a[10001],N,i,j,num=0;
  scanf("%d",&N);
  for(i=0;i<N;i++)
    {
      scanf("%d",&a[i]);
      if(IP(a[i])==1)num++;
    }

  printf("%d\n",num);
  
    return 0;  
}
int IP(int n){
  int m;
  if(n<2)return 0;
  else if(n==2)return 1;
  if(n%2==0)return 0;
  
  for(m=3;m<=n/m;m+=2)
    {
      if(n%m==0)return 0;
    }
  return 1;
}
      

Measured memory_bytes: 628
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
const int MAXN = 2e5+1;
const int MOD = 1e9+7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}
#define YES {cout << "Yes\n"; return 0;}

int N;
int A[MAXN];
int B[MAXN];
int cnt;

vector<int> multiples[MAXN];

void sieve(int n) {
    for (int p=1; p<=n; p++) {
        for (int k=2; k*p<=n; k++) {
            multiples[p].pb(k*p);
        }
    }
}

 
int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> A[i];

    sieve(N);

    for (int n = N; n; n--) {
        int c = 0;
        for (int m: multiples[n]) {
            c = (c + B[m]) % 2;
        }

        if (c != A[n]) B[n] = 1;
        if (B[n]) cnt++;
    }

    cout << cnt << '\n';
    for (int i = 1; i <= N; i++) if (B[i]) cout << i << ' ';
    cout << endl;
    return 0;
}


Measured memory_bytes: 20340
n = int(input())

def factorize(n):
    fct = []  
    b, e = 2, 0  
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append([b, e])
        b, e = b + 1, 0
    if n > 1:
        fct.append([n, 1])
    return fct

aoinsu = factorize(n)

kaijo = [1]
b = 1
for i in range(2,10):
    b = b+i
    kaijo.append(b)

#print(kaijo)    

#print(aoinsu)

ans = 0
for i in range(len(aoinsu)):
    a = aoinsu[i][1]
    for j in range(10):
        if a < kaijo[j]:
            ans += j
            break


print(ans)

Measured memory_bytes: 9232
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-10;
const vi emp;

int sum;

int main(){
	for(int i=0;i<5;i++){
		int num;
		cin>>num;
		if(num<40) num=40;
		sum+=num;
	}
	cout<<sum/5<<endl;
}

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

void Main() {
  int n;
  std::cin >> n;

  std::priority_queue<
    double,                // 要素の型はint
    std::vector<double>,   // 内部コンテナはstd::vector (デフォルトのまま)
    std::greater<double>   // 昇順 (デフォルトはstd::less<T>)
  > q;

  int tmp;
  for (int i = 0; i < n; i++) {
    std::cin >> tmp;
    q.push(tmp);
  }

  for (int i = 0; i < n - 1; i++) {
    double a = q.top(); q.pop();
    double b = q.top(); q.pop();
    q.push((a + b) / 2.0);
  }

  std::cout << q.top() << std::endl;

}

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

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
string s;
int main(){
    cin>>s;
    if (s.find("AC")!=-1) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int n;
const int N = 1e6+5;
vector<int> s;
vector<int> s2,s3;
vector<int> g[N];

bool vis[N];
void adde(int u,int v){
	if(u&&v)printf("%d %d\n",u,v);
}
int B[N], bs[N];

inline void gen(int sum){
	for(int i=1;i<=n;i++)if(!vis[i]){
		int sum=i;
		for(int j=20;~j;j--){
			if(1&(sum>>j)){
				if(!bs[j]){bs[j]=sum,B[j]=i;break;}
				else sum^=bs[j];
			}
		}
	}
	// for(int i=0;i<20;i++)cout << B[i] << " " << bs[i] << endl;
	for(int i=0;i<1<<20;i++){
		int cur=0;
		for(int j=0;j<20;j++)if(1&(i>>j))cur^=B[j];
		if(cur==sum){
			for(int j=0;j<20;j++)if(1&(i>>j))
				if(B[j])s2.push_back(B[j]);
			break;
		}
	}
	for(size_t i=0;i<s2.size();i++)vis[s2[i]]=1;
	for(int i=1;i<=n;i++)if(!vis[i])s3.push_back(i);
}

inline void prt(vector<int> s){
	for(size_t i=0;i+1<s.size();i++)adde(s[i],s[i+1]),adde(s[i]+n,s[i+1]+n);
}

int main()
{
	cin >> n;
	int l=0;while(1<<l<n)++l;
	if(1<<l==n){
		puts("No");return 0;
	}
	int Xorsum=0;
	for(int j=1;j<=n;j++){
		Xorsum^=j;
	}
	if(n==6) s.push_back(1),s.push_back(6),vis[1]=vis[6]=1;
	else for(int d=0;1<<d<=Xorsum;++d){
		if(1&(Xorsum>>d))s.push_back(1<<d),vis[1<<d]=1;
	}
	puts("Yes");
	if(Xorsum==0){
		for(int i=1;i<n*2;i++)adde(i,i+1);
		return 0;
	}
	// for(size_t i=0;i<s.size();i++)cout << s[i] << " ";puts("|");
	gen(Xorsum);
	// cout << Xorsum << " ::\n";
	// for(size_t i=0;i<s2.size();i++)cout << s2[i] << " ";puts("|");
	// for(size_t i=0;i<s3.size();i++)cout << s3[i] << " ";puts("|");
	prt(s),prt(s2),prt(s3);
	adde(s2.back(),s[0]);
	adde(s.back(),s2[0]+n);
	adde(s.back(),s3[0]+n);
	adde(s3.back(),s[0]);
	adde(s2.back()+n,s[0]+n);
	return 0;
}

Measured memory_bytes: 31864
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

int main() {
	int n;

	while(cin >> n, n) {
		set<int> s;
		vector<int> v0;
		vector<int> v1;

		v1.resize((n+1) / 2);
		for(int i = 0; i < v1.size(); i++)
			v1[i] = 0;

		for(int i = 1; i < n; i++) {
			s.insert(i*i % n);
		}
		for(set<int>::iterator iter = s.begin(); iter != s.end(); iter++) {
			v0.push_back(*iter);
		}
		for(int i = 0; i < v0.size(); i++) {
			for(int j = 0; j < v0.size(); j++) {
				if(i != j) {
					int tmp = (v0[i] - v0[j] + n) % n;
					if(tmp > (n - 1) / 2) {
						tmp = n - tmp;
					}
					v1[tmp]++;
				}
			}
		}
		for(int i = 1; i < (n + 1) / 2; i++)
			cout << v1[i]<< endl;
	}
}

Measured memory_bytes: 1520
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
#include <fstream>
#include <sstream>
#include <time.h>
#include <queue>
#include <set>
#include <iomanip>
#include <cmath>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 924844033  //1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
#define next _next
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 200005
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}


int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}

vector<vi>f;
int dp[2002][2002][2][2],p[2002],h[2002];
int main(){
    //freopen("1.txt","w",stdout);
    //cout<<setprecision(3)<<fixed;
    int T,i,j,k,n,m=0,K;
    scanf("%d%d",&n,&K);
    p[0]=1;
    rep(i,1,n+1)p[i]=1LL*p[i-1]*i%mod;
    rep(i,1,K+1){
        m=(n-i)/K+1;int v;
        rep(j,0,m+1)rep(k,0,m+1)rep(l,0,2)rep(r,0,2)dp[j][k][l][r]=0;
        dp[0][0][0][0]=1;
        rep(j,0,m)rep(k,0,j+1){
            rep(x,0,2)rep(y,0,2)if(v=dp[j][k][x][y]){
                if(x==0&&j)add(dp[j+1][k+1][y][0],v);
                if(j<m-1)add(dp[j+1][k+1][y][1],v);
                add(dp[j+1][k][y][0],v);
            }
        }
        vi q(m+1);
        rep(k,0,m+1){
            int v=0;
            rep(l,0,2)rep(r,0,2)add(v,dp[m][k][l][r]);
            q[k]=v;
            //cerr<<k<<" "<<v<<"\n";
        }
        f.pb(q);
    }
    m=SZ(f);h[0]=1;
    rep(i,0,m){
        vi &v=f[i];
        per(j,1,n+1){
            int r=min(SZ(v)-1,j);
            rep(k,1,r+1)add(h[j],1LL*h[j-k]*v[k]%mod);
        }
    }
    //rep(i,0,n+1)cerr<<i<<" "<<h[i]<<"..\n";
    ll ans=0;
    rep(i,0,n+1){
        if(i&1)ans-=1LL*h[i]*p[n-i]%mod;
        else ans+=1LL*h[i]*p[n-i]%mod;
    }
    ans%=mod;if(ans<0)ans+=mod;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 62848
#include "bits/stdc++.h"
using namespace std;
int g(int x){
    int r = 0;
    while(x) r += x % 10, x /= 10;
    return r;
}
int MAIN(){
    int n;
    if(!~scanf("%d", &n)) return 0;
    int ans = 1<<30;
    for(int e = 1; e < n; e++){
        int a = e, b = n - e;
        ans = min(ans, g(a) + g(b));
    }
    cout << ans << endl;
    return 1;
}
int main(){
    while(MAIN());
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<long>L(N);
  for(int i=0;i<N;i++)cin>>L[i];
  sort(L.begin(),L.end());
  long ans=0;
  for(int i=2;i<N;i++){
    for(int j=1;j<i;j++){
		for(int k=0;k<j;k++){
          if(L[k]+L[j]>L[i])ans++;
          
        }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
O = str(input())
E = str(input())
st = ''
if len(O) == len(E):
    for i in range(len(O)):
        st += O[i]
        st+= E[i]
    print(st)
else:
    for i in range(len(O)-1):
        st += O[i]
        st+= E[i]
    
    print(st+O[-1])
        

Measured memory_bytes: 8984
#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print(""); 
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

void Main(){
 
	ll H, W, K;
	cin >> H >> W >> K;
	vs v(H);
	rep(i, H) cin >> v[i];

	ll ans = INF;	
	rep(div, 1 << (H - 1)){
		ll g = 0;
		vl id(H);
		rep(i, H){
			id[i] = g;
			if(div >> i & 1) g++;
		}
		
		g++;
		vvl c(H, vl(W));
		rep(i, H) rep(j, W) c[id[i]][j] += (v[i][j] - '0');

		ll cnt = g - 1;
		vl now(g);
		auto add = [&](ll j){
			rep(i, g) now[i] += c[i][j];
			rep(i, g) if(now[i] > K) return false;
			return true;
		};

		rep(j, W){
			if(!add(j)){
				cnt++;
				now = vl(g);
				if(!add(j)){
					cnt = INF;
					break;
				}
			}
		}
		chmin(ans, cnt);

	}
	
	print(ans);
	
}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	Main();
	return 0;
	
}





Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
ll dp[51][51][2525];
	
int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n,A; cin>>n>>A;
	ll a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];
	
	for(int i=0;i<=n;i++)
	{
	    for(int j=0;j<=i;j++)
	    {
	        if(i==0 || j==0){ dp[i][j][0]=1; continue; }
	        for(int k=0;k<=n*50;k++)
	        {
	            if(k>=a[i])
	            {
	                dp[i][j][k] = dp[i-1][j-1][k-a[i]];
	            }
	            dp[i][j][k] += dp[i-1][j][k];
	           // if(k<=20)
	           //     cout<<i<<":"<<j<<":"<<k<<":"<<dp[i][j][k]<<'\n';
	        }
	    }
	}
	ll ans = 0;
	for(int i=1;i<=n;i++)
	{
	    //cout<<i<<":"<<dp[n][i][A*i]<<'\n';
	    ans += dp[n][i][A*i];
	}    
	cout<<ans;    
	
	return 0;
}


Measured memory_bytes: 49536
#include <stdio.h>

int main(){
    int h[10];
    int a,i,j;
    for (i=0; i<10; i++) {
        scanf("%d",&h[i]);
    }
    for (i=0; i<3; i++) {
        for (j=i+1; j<10; j++) {
            if (h[i]<h[j]) {
                a=h[j];
                h[j]=h[i];
                h[i]=a;
            }
        }
    }
    for(i=0; i<3; i++){
        printf("%d\n",h[i]);
    }
    
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define iter vector<int>::iterator
#define mod 998244353



int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s,t;
    cin>>s>>t;

    int n=s.size();
    int m=t.size();

    int dp[n+1][m+1];
    string ans;
    for(int i=0;i<n+1;i++)
    {
    	for(int j=0;j<m+1;j++)
    	{
    		if(i==0 || j==0)
    		{
    			dp[i][j]=0;
    			continue;
    		} 
    		if(s[i-1]==t[j-1])
    		{
    			dp[i][j]=1+dp[i-1][j-1];
    		}
    		else
    		{
    			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    		}
    	}
    }

    int i=n,j=m;

    while(i>=1 && j>=1)
    {
    	if(s[i-1]==t[j-1])
    	{
    		ans+=s[i-1];
    		i--;
    		j--;
    	}
    	else
    	{
    		if(dp[i-1][j]>dp[i][j-1])
    		{
    			i--;
    		}
    		else
    		{
    			j--;
    		}
    	}
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<"\n";
    
}

Measured memory_bytes: 70656
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A1 = scanner.nextInt();
        int A2 = scanner.nextInt();
        int A3 = scanner.nextInt();
        Black(A1,A2,A3);

    }
    public static void Black(int A1, int A2, int A3){
        if(A1 + A2 + A3 >= 22)
            System.out.println("bust");
        else System.out.println("win");
    }
}

Measured memory_bytes: 21844
//文字列を使うとスマート
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string s;
	int i = 1;
	bool good = true;
	cin >> s;
	while (i<=3)
	{
		if (s[i] == s[i - 1])good = false;
		i++;
	}
	if (good)cout << "Good";
	else cout << "Bad";

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define mod 1000000007

int main () {
  ll n;
  cin >> n;
  ll a[n];
  vector<ll> ans;
  ans.push_back(0);
  map<ll, ll> box;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    if (i != 0) {
      if (a[i] != a[i - 1]) {
        ans.push_back(a[i]);  
      }  
    }
    else {
      ans.push_back(a[i]);  
    }
  }  
  ll dp[ans.size()];
  for (ll i = 0; i < ans.size(); i++) {
    dp[i] = 0;  
  }
  dp[0] = 1;
  for (ll i = 1; i < ans.size(); i++) {
    if (box[ans[i]] == 0) {
      dp[i] = dp[i - 1];
      box[ans[i]] = i;  
    }     
    else {
      dp[i] = (dp[i - 1] + dp[box[ans[i]]]) % mod;
      box[ans[i]] = i;  
    }
  }
  cout << dp[ans.size() - 1] << endl;


}

Measured memory_bytes: 17392
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.EducationalDP
{
    class N
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            long[] array = ReadLongs();
            long[,] dp = new long[n, n];
            for(int i = n - 1; i >= 0; i--)
            {
                for (int j = i + 1; j < n; j++)
                {
                    long minCost = long.MaxValue;
                    long sum = 0;
                    for (int k = i; k + 1 <= j; k++)
                    {
                        minCost = Math.Min(minCost,
                            dp[i, k] + dp[k + 1, j]);
                        sum += array[k];
                    }
                    sum += array[j];
                    dp[i, j] = minCost + sum;
                }
            }
            Console.WriteLine(dp[0, n - 1]);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

signed main() {
    int N, M;
    cin >> N >> M;
    int K = lcm(N, M);

    string S, T;
    cin >> S >> T;

    int n = K / N;
    int m = K / M;
    int L = n * m;

    for (int l = 0; l < K; l += L) {
        if (S[l/n] != T[l/m]) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << K << endl;

    return 0;
}

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

using namespace std;
int dp[3001][3001];

int main()
{
        ios::sync_with_stdio(false);
        cin.tie(0);
        string s, t;
        cin >> s >> t;
        int ls = s.size(), lt = t.size();
        memset(dp,0,sizeof(dp));
        string ans = "";
        for (int i=0; i<ls; i++)
        {
                for (int j=0; j<lt; j++)
                {
                        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
                        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
                        if (s[i]==t[j])
                                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
                }
        }
        while (ls>0 && lt>0)
        {
                if (dp[ls][lt] == dp[ls-1][lt]) ls--;
                else if (dp[ls][lt] == dp[ls][lt-1]) lt--;
                else 
                {
                        ans = s[ls-1] + ans;
                        lt--;
                        ls--;
                }
        }
        cout << ans;
        return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
#include <math.h>
#include <cstdlib> 
using namespace std;
#define ll long long 
int main() {

int a,b,c;
cin>>a>>b>>c;
if((a>=1&&a<=9)&&(b>=1&&b<=9)&&(c>=1&&c<=9))
{
    if((a==b&&b==c&&a==c)||(a!=b&&b!=c&&a!=c))
        cout<<"No";
    else
        cout<<"Yes";
}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int n = 32;
int a[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int k; cin >> k;
    return cout << a[k] << endl, 0;
}

Measured memory_bytes: 256
#include <iostream>
#define MAX(X,Y) ((X)>(Y)?(X):(Y))
using namespace std;

const int NMAX=100, WMAX=10000;
int dp[NMAX+1][WMAX+1];

int main(void){
  int n,w;
  int vi[NMAX+1], wi[WMAX+1];
  
  cin >> n >> w;
  for (int i=1; i<=n; i++){
    cin >> vi[i] >> wi[i];
  }
  
  // dp
  for (int i=0; i<=n; i++) dp[i][0] = 0;
  for (int i=0; i<=w; i++) dp[0][i] = 0;
  for (int i=1;i<=n; i++){
    for (int j=1; j<=w; j++){
      if (wi[i]<=j){
        dp[i][j] = MAX(dp[i-1][j],
                       dp[i-1][j-wi[i]]+vi[i]);
      } else {
        dp[i][j] = dp[i-1][j];
      }
    }
  }
  
  cout << dp[n][w] << endl;
  return 0;
}


Measured memory_bytes: 7060
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n; cin >> n;
    vector<string> w(n);

    rep(i,n) cin >> w[i];

    bool jud = true;
    bool jud2 = true;

    rep(i,n-1){
        int a = w[i].size();
        if(w[i][a-1] != w[i+1][0]) jud = false;
    }

    sort(all(w));
    
    rep(i,n-1){
        if(w[i] == w[i+1]) jud2 = false;
    }

    if(jud){
        if(jud2){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int n;
  cin >> n;

  int x = 800 * n;
  int y = (n / 15) * 200;

  cout << x - y << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
    int N;
    cin>> N;
    int R= N % 10;
    if(R == 3){
        cout<< "bon";
    }else if((R == 0) || (R == 1) || (R == 6) || (R == 8)){
        cout<< "pon";
    }else if(R == 2||4||5||7||9){
        cout<< "hon";
    }
    

    return 0;
}


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

#define int long long

using namespace std;

signed main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> h(n), dp(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; i++){
        dp[i] = min (dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 4836