akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


bool isOK(vector<ll> &a, ll index, ll key) {
    if (a[index] >= key) return true;
    else return false;
}

ll binary_search(vector<ll> &a, ll key) {
    ll ng = -1;
    ll ok = (int)a.size();

    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if (isOK(a, mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> asum(n+1,0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        asum[i+1] = asum[i] + a[i];
    }
    ll ans = 9900000000000000;
    for(int i = 2; i < n-1; i++){
        ll leftsum = asum[i];
        ll rightsum = asum[n]-asum[i];
        ll leftidx = binary_search(asum, leftsum/2);
        ll rightidx = binary_search(asum, rightsum/2 + asum[i]);

        if(leftidx == 0){leftidx = 1;}
        else if(leftidx == i){leftidx = i-1;}
        if(rightidx == i){rightidx = i+1;}
        else if(rightidx >= n){rightidx = n-1;}

        for(int lm = 0; lm < 3; lm++){
            if(leftidx-(lm-1) != 0 && leftidx-(lm-1) != i){
                for(int rm = 0; rm < 3; rm++){
                    if(rightidx-(rm-1) != i && rightidx-(rm-1) < n){
                        ll p,q,r,s;
                        p = asum[leftidx-(lm-1)];
                        q = asum[i] - asum[leftidx-(lm-1)];
                        r = asum[rightidx-(rm-1)] - asum[i];
                        s = asum[n] - asum[rightidx-(rm-1)];
                        ll max4 = max(p,max(q,max(r,s)));
                        ll min4 = min(p,min(q,min(r,s)));
                        ans = min(abs(max4-min4),ans);
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 3328
n,m,l=map(int,input().split())
inf=100000000000
wf=[[inf]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    wf[a-1][b-1]=c
    wf[b-1][a-1]=c
for i in range(n):
    wf[i][i]=0
for k in range(n):
    for i in range(n):
        for j in range(n):
            wf[i][j]=min(wf[i][j],wf[i][k]+wf[k][j])
for i in range(n):
    for j in range(n):
        if i!=j:
            wf[i][j]=1 if wf[i][j]<=l else inf
for k in range(n):
    for i in range(n):
        for j in range(n):
            wf[i][j]=min(wf[i][j],wf[i][k]+wf[k][j])
q=int(input())
for i in range(q):
    s,t=map(int,input().split())
    x=wf[s-1][t-1]
    print(-1 if x==inf else wf[s-1][t-1]-1)

Measured memory_bytes: 78620
#include<cstdio>
#include<algorithm>
const int N=1000007;
char s[N],t[N];int n,ans,sum[N];
int main()
{
    scanf("%d%s%s",&n,s+1,t+1);
    if(s[1]^t[1]) return !printf("-1");
    for(int i=n,f=0,k=0,p=n;i;--i)
    {
	f+=sum[i+k];
	if(p>i||t[i]^s[p])
        {
	    for(;p>0&&(p>i||t[i]^s[p]);--p);
	    if(p==i) continue;
	    if(p<=0) return !printf("-1");
	    ++k,++f,sum[i+k-1]=0,--sum[p+k-1];
        }
	ans=std::max(ans,f);
    }
    printf("%d",ans);
}


Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    int n;
    cin>>n;

    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int m=1,c=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==m)
        {
            c++;
            m++;
        }
    }
    if(c==0)
        cout<<"-1\n";
    else
        cout<<n-c<<"\n";
return 0;
}


Measured memory_bytes: 4404
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        int s=100000000;
        for(int i=1;i<n;i++)
        {
            int a=i,b=n-i,sum=0;
            while(a)
            {
                sum+=a%10;
                a=a/10;
            }
            while(b)
            {
                sum+=b%10;
                b=b/10;
            }
            s=min(s,sum);
        }
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    ll N;
    cin >> N;
    if(N%2==1) {
        cout << 0 << '\n';
        return 0;
    }

    ll ans = 0;
    for(ll i=10;i<(ll)1e18+7;i*=5){
        ans+=(N/i);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    ll n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>a>>b;

    ll res = 0;

    if(a)a--;

    for(ll i=a/4*4;i<=a;i++)
            res^=i;
    for(ll i=b/4*4;i<=b;i++)
            res^=i;

    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
#二分探索をつくる
L = -1
R = 10**12 +1 
while R-L>1:
    Mid = (L+R)//2
    tmp = 0
    for a,f in zip(A,F):
        tmp += max(0, a-Mid//f)
    if tmp<=K:
        R = Mid
    else:
        L = Mid
print(R)

Measured memory_bytes: 123340
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#define ll long long
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pi(n) prllf("%d",n)
#define pl(n) prllf("%d",n)
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  char arr[n][m];
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> arr[i][j];
    }
  }
  bool ok = true;
  for(int i=0;i<n;i++){
    for(int j=0;j <m;j++){
      int t = 0;
      if(arr[i][j]=='#'){
        if(i-1>=0 && arr[i-1][j]!='#')
          t+=1;
        if(i+1<n && arr[i+1][j]!='#')
          t+=1;
        if(j-1>=0 && arr[i][j-1]!='#')
          t+=1;
        if(j+1<n && arr[i][j+1]!='#')
          t+=1;
      }
      if(t==4){
        ok=false;
        break;
      }
    }
    if(!ok)
      break;
  }
  if(ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
char a[102];
bool yes=false;
int main()
{
    cin>>n;
    for (int i=0;i<n;i++)
        {
            cin>>a[i];
            if (a[i]=='Y')
                yes=true;
        }
    if (yes==true)
    {
        cout<<"Four";
    }
    else
    {
        cout<<"Three";
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 1666666
int arr[N];
signed main(){
    
    string str;
    cin>>str;
    set<char> s;
    for(int i=0;i<str.size();i++) s.insert(str[i]);
    if(s.size()!=1) cout<<"Yes";
    else  cout<<"No";
    return 0;
}

/*
))((())(

*/

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

int main() {
    ll t,n,k,a1=0,a2=0,a3=0,a4=0,a5=0;
    cin>>n;
    ll a[10005]={0};
    for(int i=1;i<150;i++)
        for(int j=1;j<150;j++)
            for(int k=1;k<150;k++){
                ll s = i*i+j*j+k*k+i*j+j*k+k*i;
                if(s<10005){
                    a[s]++;
                }
            }
    for(int i=1;i<=n;i++)
        cout<<a[i]<<endl;
    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int H, W, D;
	cin >> H >> W >> D;

	vector<pair<int, int>> v(H * W);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int n;
			cin >> n;
			v.at(n - 1) = { i,j };
		}
	}

	//for (int i = 0; i < H * W; i++) {
	//	cout << v.at(i).first << ' ';
	//	cout << v.at(i).second << endl;
	//}

	vector<int> d(H * W);
	for (int i = D; i < d.size(); i++) {
		d.at(i) = d.at(i - D);
		d.at(i) += abs(v.at(i).first - v.at(i - D).first)
			+ abs(v.at(i).second - v.at(i - D).second);
	}

	//for (int i = 0; i < d.size(); i++) cout << d.at(i) << endl;

	int Q;
	cin >> Q;

	for (int i = 0; i < Q; i++) {
		int L, R;
		cin >> L >> R;
		cout << d.at(R - 1) - d.at(L - 1) << endl;
	}
}

Measured memory_bytes: 4300
#include<bits/stdc++.h>
using namespace std;
#define ar array
#define endl '\n'
#define ll long long
#define in insert
#define pb push_back
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(ll i=a;i>=b;i--)
#define FOR(m) Rep(i,1,m)
#define For(m) Rep(i,0,m-1)
#define Rbl(x,a) for(auto &x : a)
#define FIO ios::sync_with_stdio(0);   cin.tie(0);
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpii vector<pii>
#define vpll vector<pll>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define mod 1000000007
 
const int mxN = 2e5 + 1;
//ll a[mxN];
ll d;
string k;

void add(ll &a, ll b)
{
    a = (a + b) % mod;
}
 
int main()
{
FIO

    cin >> k >> d;
    vt<vt<ll>> dp(d, vt<ll>(2, 0));
    dp[0][0] = 1;
    int len = k.length();
    for(int i = 0; i < len; i++)
    {
        vt<vt<ll>> new_dp(d, vt<ll>(2, 0));
        for(int sum = 0; sum < d; sum++)
        {
            for(bool small : {0, 1})
            {
                for(int digit = 0; digit < 10; digit++)
                {
                    if(digit > k[i] - '0' && !small)
                        break;
                    add(new_dp[(sum + digit) % d][small || (digit < k[i] - '0')], dp[sum][small]);
                }
            }
        }
        dp = new_dp;
    }

    ll ans = mod - 1;
    add(ans, dp[0][0] + dp[0][1]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3688
import java.io.*;
public class Main {
	public static void main(String [] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] str=br.readLine().split(" ");
		int a=Integer.parseInt(str[0]);
		int b=Integer.parseInt(str[1]);
		System.out.println(a*b+" "+2*(a+b));
		}}

Measured memory_bytes: 16892
#!/usr/bin/env python3
import collections

N = int(input().split()[0])
d_list = list(map(int, input().split()))
counter = collections.Counter(d_list)
max_d = max(counter.keys())
w = 0
mod = 998244353

if d_list[0] != 0 or counter[0] >= 2:
    w = 0
else:
    for d in range(1, max_d + 1):
        if d not in counter.keys():
            w = 0
            break
        if d == 1:
            w += 1
            continue
        x = counter[d - 1] ** counter[d]  # D=iとなるルートのパターン数
        w = (w % mod) * x
w = w % mod
ans = w
print(ans)


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

int main() {
    string s;
    cin >> s;
    vector<char> a(s.size());
    for(int i = 0; i < s.size(); i++) {
        a[i]=s[i];
    }

    int b=0;
    for(int i = 0; i < s.size(); i++) {
        if(s[s.size()-1-i]=='B'){
            b++;
        }
        else{
            if(b>0){
                a[s.size()-1-i]='A';
                b--;
            }
        }
    }

    for(int i = 0; i < s.size(); i++) {
        if(a[i]=='1') cout << 1;
        if(a[i]=='0') cout << 0;
    }
    cout << endl;

    return 0;
}

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

int main() {
    int N; std::cin >> N;
    std::vector<int> a(N, 0);
    std::map<int, long long> c;
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
        c[a[i]]++;
    }

    long long s = 0;
    for (const auto cc : c) {
        s += cc.second * (cc.second - 1) / 2;
    }

    for (int i = 0; i < N; i++) {
        std::cout << s - (c[a[i]] - 1) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 11008
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<set>
typedef long long ll;
using namespace std;

int main(void) {
	int a, b;
	cin >> a >> b;
	if (a % 2 == 0 || b % 2 == 0)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int retValue = 0;
        int n = int.Parse(Console.ReadLine());
        var listP = new List<int>();

        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            listP.Add(int.Parse(input[i]));
        }

        for (int i = 0; i < (n - 2); i++)
        {
            int p1 = listP[i];
            int p2 = listP[i + 1];
            int p3 = listP[i + 2];

            if ((p1 < p2 && p2 < p3) || (p1 > p2 && p2 > p3))
            {
                retValue++;
            }
        }


        //出力
        Console.WriteLine(retValue);

    }
}

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

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int[] a= {1,1,1,1,-1,-1,-1,-1};
		int[] b= {1,1,-1,-1,1,1,-1,-1};
		int[] c= {1,-1,1,-1,1,-1,1,-1};

		long kati=Long.MIN_VALUE;
		long tmp=Long.MIN_VALUE;
		int N=sc.nextInt();
		int M=sc.nextInt();
		long[] x=new long[N];
		long[] y=new long[N];
		long[] z=new long[N];

		long[] maxes=new long[N];
		for(int i=0; i<N; i++) {
			x[i]=sc.nextLong();
			y[i]=sc.nextLong();
			z[i]=sc.nextLong();
		}

		for(int i=0; i<8; i++) {
			tmp=0;
			for(int j=0; j<N; j++) {
				maxes[j]=x[j]*a[i]+y[j]*b[i]+z[j]*c[i];
			}
			Arrays.sort(maxes);
			for(int k=0; k<M; k++) {
				tmp+=maxes[N-1-k];
			}
			kati=Math.max(kati, tmp);
		}
		System.out.println(kati);
	}
}

Measured memory_bytes: 26888
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N, X;
int S[200];

ll dp[201][100001];
void solve(){
	sort(S, S + N, greater<int>());
	dp[0][X] = 1;
	rep(i, N){
		reps(j, X){
			dp[i + 1][j] += dp[i][j] * (N - i - 1);
			dp[i + 1][j] %= MOD;
			dp[i + 1][j % S[i]] += dp[i][j];
			dp[i + 1][j % S[i]] %= MOD;
		}
	}
	ll ans = 0;
	reps(i, X){
		ans += dp[N][i] * i;
		ans %= MOD;
	}
	cout << ans << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> X;
	rep(i, N) {
		cin >> S[i];
	}
		solve();
	return 0;
}


Measured memory_bytes: 156544
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep1(i, n) for (int i = 1; i < int(n); ++i)
#define repx(i, x, n) for (int i = int(x); i < int(n); ++i)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) ((a) <= (x) && (x) < (b))
#define OUT(a, x, b) ((x) < (a) || (x) < (b))
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const ll MOD = 1000000007;

int main()
{
    ll h, w, n, a, b;
    cin >> h >> w >> n;
    ll ans[10] = {0}, sum = 0;
    map<pair<int, int>, ll> mp;

    rep(i, n)
    {
        cin >> a >> b;
        a--;
        b--;
        for (int dy = -1; dy <= 1; ++dy)
        {
            for (int dx = -1; dx <= 1; ++dx)
            {
                ll x = b + dx, y = a + dy;
                if (IN(1, x, w - 1) && IN(1, y, h - 1))
                {
                    mp[make_pair(x, y)]++;
                }
            }
        }
    }
    for (auto iter = mp.begin(); iter != mp.end(); iter++)
    {
        ans[iter->second]++;
        sum++;
    }
    ans[0] = (h - 2) * (w - 2) - sum;

    rep(i, 10)
    {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 56448
package main

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

var b2i = map[bool]int{false: 0, true: 1}

func main() {
	io := newIo()
	N := io.nextInt()
	dic := map[int]int{}

	for range make([]struct{}, N) {
		a := io.nextInt()
		dic[a]++
	}

	ans := 0
	for k, v := range dic {
		ans += v - k*b2i[v >= k]
	}
	fmt.Println(ans)
}

type io struct {
	reader    *bufio.Reader
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
	}
}

func (io *io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) nextString() string {
	for io.nextToken >= len(io.tokens) {
		line := io.nextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) nextInt() int {
	i, _ := strconv.Atoi(io.nextString())
	return i
}


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

int main()
{
   int a,b;
   cin>>a>>b;
   if(a<=b){
    for(int i=0;i<b;i++){
        cout<<a<<"";
    }

   }
   if(a>b){
    for(int i=0;i<a;i++){
        cout<<b<<"";
    }
   }
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;

const ll MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1.0);
const db ERR = 1e-8;
const int MAXN = 1e7;

ll n,ans,k;
ll a[MAX_SIZE];

ll solve(){
    if(k==0)
        ans=n*n;
    else
    {
        for(int b=k+1;b<=n;b++)
        {
            ans+=(n/b)*(b-k);
            if(n%b>=k)
                ans+=n%b-k+1;
        }
    }
    return ans;
}
int main(int argc, char const *argv[])
{
    ans=0;
    scanf("%lld%lld",&n,&k);
    ll re=solve();
    printf("%lld\n",re);
    return 0;
}


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

int main() {
    int n, m;

    cin >> n >> m;
    
    int A[n][m];
    int b[m];
         
    for (int i = 0; i < n; i++) {
        for (int k = 0; k < m; k++) {
            int o;

            cin >> o;

            A[i][k] = o;
        }
    }
    for (int q = 0; q < m; q++) {
        int a;
        cin >> a;
        b[q] = a;
    }

    for (int d = 0; d < n; d++) {
        long long B, C, T = 0;
        for (int e = 0; e < m; e++) {
            B = A[d][e];
            C = b[e];
            T += B * C;
        }
         
        cout << T << endl;
    }

    return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> mp;
	rep(i, n) {
		cin >> a[i];
		mp[a[i]]++;
	}
	vector<pll> v(n + 1);
	for (auto p : mp) {
		ll t = p.first;
		ll u = p.second;
		v[t].first = u * (u - 1) / 2;
		v[t].second = (u - 1) * (u - 2) / 2;
	}
	ll s = 0;
	rep(i, n + 1) s += v[i].first;
	rep(i, n) {
		ll ans = s - v[a[i]].first + v[a[i]].second;
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)

int main(){
  int N,M,X,Y;cin>>N>>M>>X>>Y;
  vector<ll> x(N),y(M);
  rep(i,N){
    cin>>x[i];
  }
  rep(i,M){
    cin>>y[i];
  }

  sort(all(x));
  sort(all(y));

  FOR(z,X+1,Y+1){
    if(y[0]>=z&&x[N-1]<z){
      cout<<"No War"<<endl;
      return 0;
    }
  }
  cout<<"War"<<endl;
}

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

#define int long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

const unsigned int M = 1e9 + 7;

int32_t main() {
	fastio;

	int n;
	cin >> n;
	int i = 0;
	while(i < n) i += 1000;
	cout << i - n;

	return 0;
}


Measured memory_bytes: 3536
// {{{
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)x.size())
#define FOR(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
using LL=long long;
using PII=pair<int,int>;
using VI=vector<int>;

#ifdef FEI
template<typename T>
void _dump(const char* s, T&& head) { cerr<<s<<"="<<head<<endl; }
template<typename T, typename... Args>
void _dump(const char* s, T&& head, Args&&... tail) {
    int c=0;
    while (*s!=',' || c!=0) {
        if (*s=='(' || *s=='[' || *s=='{') c++;
        if (*s==')' || *s==']' || *s=='}') c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1, tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, ##__VA_ARGS__); \
} while(0);

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<'[';
    for (auto it=b; it!=e; it++) s<<(it==b?"":",")<<*it;
    s<<']';
    return s;
}

template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) { return s<<"("<<p.first<<","<<p.second<<")";}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &x) { return _out(s,ALL(x)); }
template<typename T, size_t N>
ostream& operator <<(ostream &s, const array<T,N> &x) { return _out(s,ALL(x)); }
template<typename T>
ostream& operator <<(ostream &s, const set<T> &x) { return _out(s,ALL(x)); }
template<typename A, typename B>
ostream& operator <<(ostream &s, const map<A,B> &x) { return _out(s,ALL(x)); }
#else
#define dump(...)
#endif

template<typename T>
void _R(T &x) { cin>>x; }
void _R(int &x) { scanf("%d",&x); }
void _R(LL &x) { scanf("%" PRId64,&x); }
void _R(double &x) { scanf("%lf",&x); }
void _R(char &x) { scanf(" %c",&x); }
void _R(char *x) { scanf("%s",x); }

void R(){}
template<typename T, typename... X>
void R(T& head, X&... tail) { _R(head); R(tail...); }

const int MOD = 1e9+7;
// }}}

int main() {
    LL n, m;
    R(n, m);
    if (abs(n-m) >= 2) {
        cout << 0 << endl;
        return 0;
    }

    LL a=1, b=1;

    for (int i=1; i<=n; i++)
        a = a*i % MOD;
    for (int i=1; i<=m; i++)
        b = b*i % MOD;

    cout << a * b * (n==m?2:1) % MOD << endl;


    return 0;
}


Measured memory_bytes: 256
function main(input) {
  input=input.trim();
  const a = parseInt(input.split(" ")[0], 10);
  const b = parseInt(input.split(" ")[1], 10);
  const s = input.split("\n")[1];

  var tuna=s.substr(0,a)+s.substr(a+1);

  function isNumber(val){
    var regex = new RegExp(/^[0-9]+$/);
    return regex.test(val);
  }
  if(s.substr(a,1)==("-")){
    if(isNumber(tuna)==true){
      console.log("Yes");
    }else{
      console.log("No");
    }
  }else{
    console.log("No");
  }
}



main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  int a;
  cin >> a;
  while(true){
      if(a%111 == 0){
          cout << a << endl;
          break;
      }else{
          a++;
          if(a%111 == 0){
              cout << a << endl;
              break;
          }
      }
  }
  
  
  
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc176/tasks/abc176_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

pair<int, int> mv[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const int INF = 1e15;

void solve() {
    int H, W, CH, CW, DH, DW;
    cin >> H >> W >> CH >> CW >> DH >> DW;
    CH--, CW--, DH--, DW--;
    vector<string> v(H);
    REP(i, H) { cin >> v[i]; }
    // ワープ回数の最小値を記録
    vector<vector<int>> dist(H, vector<int>(W, INF));
    // 歩いた場所を記録（ワープ先では記録しない）
    // vector<vector<bool>> visited(H, vector<bool>(W));
    // visited[CH][CW] = true;
    dist[CH][CW] = 0;
    // ワープ回数、H, W,
    priority_queue<tuple<int, int, int>> q;
    q.push({0, CH, CW});

    while (!q.empty()) {
        auto now = q.top();
        q.pop();
        int from_h, from_w, from_wp;
        tie(from_wp, from_h, from_w) = now;
        from_wp = -from_wp;
        if (from_h == DH && from_w == DW) {
            cout << from_wp << endl;
            return;
        }
        for (auto x : mv) {
            int next_h = from_h + x.first;
            int next_w = from_w + x.second;
            // 範囲外なら処理しない
            if (next_h < 0 || next_h >= H || next_w < 0 || next_w >= W) {
                continue;
            }
            // if (abs(DH - next_h) > abs(DH - from_h) ||
            //     abs(DW - next_w) > abs(DW - from_w)) {
            //     continue;
            // }
            // 壁ならワープする
            if (v[next_h][next_w] == '#') {
                FOR(r, max(0LL, from_h - 2), min(H, from_h + 3)) {
                    FOR(c, max(0LL, from_w - 2), min(W, from_w + 3)) {
                        if (r == from_h && c == from_w) {
                            continue;
                        }
                        // 宛先のワープ回数
                        int wp_to = dist[r][c];
                        // ワープ先が壁ではない
                        if (v[r][c] != '#' && from_wp + 1 < wp_to) {
                            dist[r][c] = from_wp + 1;
                            q.push({-(from_wp + 1), r, c});
                        }
                    }
                }
            } else {
                // ワープ回数が現在地より多い
                if (dist[next_h][next_w] > from_wp) {
                    // 壁以外なら普通に進む
                    q.push({-from_wp, next_h, next_w});
                    dist[next_h][next_w] = from_wp;
                }
            }
        }
    }
    if (dist[DH][DW] == INF) {
        cout << "-1\n";
    } else {
        cout << dist[DH][DW] << endl;
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 12708
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = 0, b = 0;
		for (int i = 0; i < 4; i++) a += s.nextInt();
		for (int i = 0; i < 4; i++) b += s.nextInt();
		if (a > b) {
			System.out.println(a);
		} else {
			System.out.println(b);
		}
	}
}

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

int const mxn = 1e7+10;
long long dp[mxn],hajm[mxn],arz[mxn];

int main(){
	int n,w;
	cin>>n>>w;
	for (int i =0;i<n;i++)
		cin>>hajm[i]>>arz[i];
	for (int i =0;i<n;i++){
		for (int j =w;j>=0;j--){
			if (j >= hajm[i]){
				dp[j] = max (dp[j - hajm[i]] + arz[i], dp[j]);
			}
		}
	}
	cout<<dp[w];
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int cmpAscStrings(const void* a, const void* b){
    return strcmp(*(char**)a, *(char**)b);
}

void initStrArray(char** p, int n, int len){
    for(int i=0; i<n; i++){
        *(p + i) = (char*)malloc(sizeof(char) * (len + 1));
    }
}

int main(){
    int n;
    scanf("%d", &n);
    char* w[n];
    initStrArray(w, n, 11);
    rep(i, 0, n){
        scanf("%s", w[i]);
    }
    qsort(w, n, sizeof(char*), cmpAscStrings);
    int len = 0, buf = 1;
    rep(i, 1, n){
        if(strcmp(w[i-1], w[i]) == 0){
            buf++;
        }else{
            buf = 1;
        }
        if(len < buf){
            len = buf;
        }
    }
    if(len < buf){
        len = buf;
    }
    int x = 0;
    while(x < n){
        int cnt = 0;
        int y = x;
        rep(i, x, n){
            y = i;
            if(strcmp(w[x], w[i]) == 0){
                cnt++;
            }else{
                y--;
                break;
            }
        }
        if(y-x+1 == len){
            printf("%s\n", w[x]);
        }
        x = y + 1;
    }

    return 0;
}

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

int main() {
    int k, n;
    cin >> k >> n;
    vector<int> vec(n);
    int dis;
    int max_dis = 0;
    for (int i=0; i<n; i++) {
        cin >> vec.at(i);
    }
    for (int i=0; i<n; i++) {
        if (i == n-1) {
            dis = vec.at(0) + (k - vec.at(i));
        } else {
            dis = abs(vec.at(i+1) - vec.at(i));
        }
        if (dis > max_dis) {
            max_dis = dis;
        }
    }
    cout << k - max_dis;
}

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

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

#define loop(i, n) for(int i = 0;i < n;i++)
#define IINF 2e9
#define MOD 1e9+7

int main(void){

    int n;
    cin >> n;

    if(n < 600) cout << 8 << endl;
    else if(n < 800) cout << 7 << endl;
    else if(n < 1000) cout << 6 << endl;
    else if(n < 1200) cout << 5 << endl;
    else if(n < 1400) cout << 4 << endl;
    else if(n < 1600) cout << 3 << endl;
    else if(n < 1800) cout << 2 << endl;
    else if(n < 2000) cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
int max = -1000000000,min = 1000000000;
for(int i = 0; i<n; i++){
    cin>>a[i];
    if(max<a[i]){
        max = a[i];
    }
    
    if(min>a[i]){
        min = a[i];
    }
}

cout<<max-min<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define rrep(i , n , a) for (int i = n - 1 ; i >= a ; i--)
#define ms(arr , val) memset(arr , val , sizeof(arr))
#define siz(temp) temp.size()
#define len(temp) temp.length()
#define timepass 1073741824
#define int ll

signed main()
{
    int n;
    cin >> n;
    vector<int> arr(n , 0);
    rep(i , 0 , n)
        cin >> arr[i];
    ll dp[n + 1];
    ms(dp , 0);
    dp[1] = abs(arr[1] - arr[0]);
    for (int i = 2 ; i < n ; i++)
        dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]) , dp[i - 2] + abs(arr[i] - arr[i - 2]));
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
N = int(input())
abc = []
for _ in range(N):
	a, b, c = map(int, input().split())
	abc.append([a,b,c])
dp = [[0, 0, 0] for _ in range(N+1)]
# print(abc)
for i in range(1,N+1):
	dp[i][0] = max(dp[i][0], dp[i-1][1]+abc[i-1][0])
	dp[i][0] = max(dp[i][0], dp[i-1][2]+abc[i-1][0])
	dp[i][1] = max(dp[i][1], dp[i-1][0]+abc[i-1][1])
	dp[i][1] = max(dp[i][1], dp[i-1][2]+abc[i-1][1])
	dp[i][2] = max(dp[i][2], dp[i-1][0]+abc[i-1][2])
	dp[i][2] = max(dp[i][2], dp[i-1][1]+abc[i-1][2])
	# print(dp)

print(max(dp[N]))


Measured memory_bytes: 42532
n, k = map(int, input().split())

answer = 0
for c in range(1, n + 1):
    coin_num = 0
    while c < k:
        c *= 2
        coin_num += 1
    prob = (1 / n) * (1 / 2) ** coin_num
    answer += prob

print(answer)


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

using namespace std;

int main(int argc, const char *argv[]) {
  int r;
  cin >> r;
  if (r < 1200) {
    cout << "ABC" << '\n';
  } else if (r < 2800) {
    cout << "ARC" << '\n';
  } else {
    cout << "AGC" << '\n';
  }

  return 0;
}

Measured memory_bytes: 3624
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]

# 最強の魔法の特定
a_max = max(a for a, b in ab)
# 動的計画法用の配列の定義及び初期化
dp = [0]*(h + a_max)

for i in range(1, h + a_max):
	dp[i] = min(dp[i - a] + b for a, b in ab)

print(min(dp[h:]))

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

int main() {
	string s;
  	cin>>s;
  
  if(s=="SUN"){
  	cout<<7<<endl;
  }
  
  else if(s=="MON"){
  	cout<<6<<endl;
  }
  
  
  else if(s=="TUE"){
  	cout<<5<<endl;
  }  

  
  else if(s=="WED"){
  	cout<<4<<endl;
  }  
  
  
  else if(s=="THU"){
  	cout<<3<<endl;
  }

  
  else if(s=="FRI"){
  	cout<<2<<endl;
  }
  
  else{
  	cout<<1<<endl;
  }
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#define INF 10000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
	ll n, m;
	cin >> n >> m;
	if(2 * n > m) cout << m / 2 << endl;
	else cout << n + ((m - 2 * n) / 4) << endl;
	return 0;
}


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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

struct query {
    int a, b;
};

bool comp(query& q1, query& q2) {
    return q1.b < q2.b;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<query> v;

    rep(i, m) {
        query q;
        cin >> q.a >> q.b;
        v.push_back(q);
    }

    sort(v.begin(), v.end(), comp);
    int ans = 0;

    int before = -1;
    for (auto q : v) {
        if (before <= q.a) {
            ans++;
            before = q.b;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1400
K,S=map(int,input().split())
count=0
for i in range(0,K+1):
        if max(S-2*i,0)<=2*K:
            for j in range(0,K+1):
                if (S-i-j<=K)&(0<=S-i-j):
                    count=count+1
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <string>
using namespace std;
int main(){
    int n;
    cin >> n;
    int p;
    map<int,int> b;
    int c[n];
    for(int i = 0;i<n;i++){
        cin >> p;
        b[i+1] = p;
        c[i] = p;
    }
    bool flag = true;
    bool flag2 = false;
    int q = 0;
    int ans[n];
    while(q<n){
        for(int i = 0;i<n;i++){
            if(b[n-i] == n-i){
                for(int j = n-i+1;j<n+1;j++){
                    b[j]++;
                }
                ans[q] = c[n-i-1];
                b[n-i] = 120;
                flag2 = true;
                break;
            }
        }
        if(flag2 == false){
            flag = false;
            break;
        }
        else{
            q++;
            flag2 = false;
        }
    }
    if(flag != true){
        cout << -1 << endl;
    }
    else{
        for(int i = 0;i<n;i++){
            cout << ans[n-1-i] << endl;
        }
    }
}

Measured memory_bytes: 888
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n,a[5];
  cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  ll min_val = *min_element(a,a+5);
  cout << (n+min_val-1)/min_val + 4 << endl;
  return 0;
}


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

using namespace std;

int main() {
    
    int m,n;
    cin >> n >> m;
    vector<double> v(n);
    
    double sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        sum += v[i];
    }

    double cur = sum / (4 * m);
    
    int cnt = 0;

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

    if(cnt >= m) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


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

int main()
{

        int N;
        cin >> N;
        int P[N];
        for (int i = 0; i < N; ++i) {
                cin >> P[i];
        }
        int cnt = 1;
        int min = P[0];
        int ng = 0;
        for (int i = 1; i < N; ++i) {
                if (min < P[i]) {
                        ng++;
                }
                else {
                        min = P[i];
                }
        }
        cout << N-ng << endl;



}


Measured memory_bytes: 1024
#include<stdio.h>
#define N 100
int main(){
  int i,j,A[N],minj,a,n,count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }

    for(i=0;i<n;i++){
        minj = i;
        for(j=i;j<n;j++){
          if(A[j]<A[minj])   minj=j;
        }
          a=A[i];
          A[i]=A[minj];
          A[minj]=a;
          if(A[i]!=A[minj]) count++;

    }

     for(j=0;j<n-1;j++){
        printf("%d ",A[j]);
    }
    printf("%d\n",A[n-1]);
    printf("%d\n",count);
    return 0;

}



Measured memory_bytes: 2124
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int N;
    char s[3*100000 + 1];
    scanf("%d%s", &N, s);

    vs32 L(N + 1, 0);
    L[0] = 0;
    rep (i, N)
    {
        L[i + 1] = L[i];
        if (s[i] == 'W') ++L[i + 1];
    }

    int ans = N;
    rep (i, N)
    {
        ans = MIN(N - i - 1 - L[N] + L[i + 1] + L[i], ans);
    }

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



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

int main()
{
  int a,b,c;
  int count=0;

  cin >> a >> b >> c;

  for(int i=a; i<=b; i++){
    if(c%i==0){
      count++;
    }
  }
  cout << count << endl;
  
  return 0;
} 

Measured memory_bytes: 1164
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
	string s;
	cin >> s;

	s[5] = ' ';
	s[13] = ' ';

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt

  let d1 = n `mod` 10

      ans | d1 == 2 || d1 == 4 || d1 == 5 || d1 == 7 || d1 == 9 = "hon"
          | d1 == 0 || d1 == 1 || d1 == 6 || d1 == 8 = "pon"
          | otherwise = "bon"

  putStrLn ans




Measured memory_bytes: 3776
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>


using namespace std;
int main() {
    int H,W;
    cin >> H >> W;
    int count[30];
    for(int i = 0; i < 30; i++){
        count[i] = 0;
    }
    for(int i = 0; i < H * W; i++){
        char tmp;
        cin >> tmp;
        count[tmp - 'a']++;
    }
    int odd = 0;
    if(H % 2 == 1 && W % 2 == 1){
        odd++;
    }
    int even = 0;
    if(H % 2 == 1){
        even += W / 2;
    }
    if(W % 2 == 1){
        even += H / 2;
    }
    int mod4 = 0;
    mod4 += H / 2 * W / 2;
    for(int i = 0; i < 30; i++){
        switch (count[i] % 4){
            case 0:
                break;
            case 1:
                odd--;
                break;
            case 2:
                even--;
                break;
            case 3:
                odd--;
                even--;
                break;
        }
    }
    if(odd >= 0 && even >= 0 && mod4 >= 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long int X,A,B;
    cin>>X>>A>>B;
    if(B<=A)
    {
        cout<<"delicious"<<endl;
    }
    else if(B>A && B<=(X+A))
    {
        cout<<"safe"<<endl;
    }
    else if(B>(X+A))
    {
        cout<<"dangerous"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int n,a[3],b[3],ans,dp[3450502];
ll ndp[25079968];
int main() {
  int i,j;
  scanf("%d",&n);
  for (i=0;i<3;++i) scanf("%d",a+i);
  for (i=0;i<3;++i) scanf("%d",b+i);
  for (i=0;i<=n;++i) {
    dp[i]=max(dp[i],i);
    for (j=0;j<3;++j)
      if (i-a[j]>=0) dp[i]=max(dp[i],dp[i-a[j]]+b[j]);
  }
  for (i=0;i<=dp[n];++i) {
    ndp[i]=max(ndp[i],(ll)i);
    for (j=0;j<3;++j)
      if (i-b[j]>=0) ndp[i]=max(ndp[i],ndp[i-b[j]]+a[j]);
  }
  printf("%lld\n",ndp[dp[n]]);
}

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

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a;
    cin>>a;
    int n=a.length();
    vector<string> v;
    string ans="";
    for(int i=0;i<n-1;i++)
    {
        if(a[i]=='B'&&a[i+1]=='C')
        {
            ans+="t";
            i++;
        }
        else
        {
            ans+=a[i];
        }
    }

    int m=ans.length();

    int res=0,x=0,ind=m-1;

    for (int i = m-1; i >=0 ; --i) {
        if(ans[i]=='t')
        {
            while(ans[i]=='A'||ans[i]=='t')
            {
                if(ans[i]=='A')
                {
                    res+=ind-i-x;
                    x++;
                }
                i--;
                if(i==-1)
                    break;
//                i++;
            }
            i++;
        }
        else
        {
            x=0;
            ind=i-1;
        }
    }

    cout<<res;
}


Measured memory_bytes: 916
import java.util.Scanner;

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

        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();

            if (h == 0 && w == 0) break;

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (i == 0 | i == h - 1 | j == 0 | j == w - 1) {
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }

                }
                System.out.println("");
            }
            System.out.println("");
        }

        sc.close();
    }
}


Measured memory_bytes: 33036
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string S;
  cin >> S;
  
  bool flag=0;
  if((S[0]==S[1] && S[2]==S[3] && S[1]!=S[2])||(S[0]==S[3] && S[1]==S[2] && S[0]!=S[1]) || (S[0]==S[2] && S[1]==S[3] && S[0]!=S[1]) ) flag=!flag;

  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
	
}


Measured memory_bytes: 256