akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int h,w;
char room[101][101];
int book1[101],book2[101];
int main()
{
    cin>>h>>w;
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            cin>>room[i][j];
    memset(book1,0,sizeof(book1));
    memset(book1,0,sizeof(book1));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(room[i][j]=='#'){
                book1[i]=1;
                break;
            }
        }
    }
    for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
            if(room[j][i]=='#'){
                book2[i]=1;
                break;
            }
        }
    }
    for(int i=0;i<h;i++){
            bool f=false;
        for(int j=0;j<w;j++){
            if(book1[i]==1&&book2[j]==1){
                cout<<room[i][j];
                f=true;
            }
        }
        if(f)
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n=int(input())
B=list(map(int,input().split()))
flag=True
ans=[]
while flag and len(B):
    for i in range(len(B)-1,-1,-1):
        if B[i]==i+1:
            del B[i]
            ans.append(i+1)
            break
    else:
        flag=False
        break
if not flag:
    print(-1)
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i])


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<cstring>
//#define Mfc_Tanzim
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ff first
#define ss second
#define all(v) (v.begin(), v.end())
#define pi acos(-1.0)
#define FastRead ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define bug(a) cerr << #a << " : " << a << endl
using namespace std;

ll posx[] = {1,-1, 0, 0};
ll posy[] = {0, 0, 1,-1};

int main()
{
    FastRead

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

    ll n;
    cin >> n;
    string x;
    map<string, ll>mp;

    for(ll i=0; i<n; i++){
        cin >> x;
        mp[x]++;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 9 * 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

int main() {
    int N;
    cin >> N;
    map<int,int> ma;
    for(int i = 0;i < N;i++) {
        int A;
        cin >> A;
        ma[A]++;
    }
    int M;
    cin >> M;
    bool ret = true;
    for(int i = 0;i < M;i++) {
        int A;
        cin >> A;
        if(ma[A] == 0) {
            ret = false;
        }
        else {
            ma[A]--;
        }
    }
    if(ret == true) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define int long long
#define N 500005

using namespace std;

const int Mod=1e9+7;
int B,W,a[N],b[N],fac[N],bin[N],inv[N];

inline int C(int n,int m){return 1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;}

inline int ksm(int x,int y){
    int ans1=1;while (y){
        if (y&1) ans1=1ll*ans1*x%Mod;
        y>>=1;x=1ll*x*x%Mod;
    }return ans1;
}
signed main(){
    int inv2=ksm(2,Mod-2);
	scanf("%lld%lld",&B,&W);fac[0]=bin[0]=1;
    for (int i=1;i<N;i++) bin[i]=1ll*bin[i-1]*2%Mod,fac[i]=1ll*fac[i-1]*i%Mod;
    inv[N-1]=ksm(fac[N-1],Mod-2);
    for (int i=N-2;~i;i--) inv[i]=1ll*inv[i+1]*(i+1)%Mod;
    for (int i=W;i<=B+W;i++) a[i]=1ll*C(i-1,W-1)*ksm(bin[i],Mod-2)%Mod;
    for (int i=B;i<=B+W;i++) b[i]=1ll*C(i-1,B-1)*ksm(bin[i],Mod-2)%Mod;
    int ans=0;for (int i=1;i<=B+W;i++){
        ans+=a[i-1]-b[i-1];
        ans%=Mod;ans=(ans+Mod)%Mod;
        printf("%lld\n",1ll*(ans+1)*inv2%Mod);
    }
    return 0;
}

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

int main(){
	int K, S;
	cin>>K>>S;
	int ret = 0;
	for(int i=0; i<=K;i++){
		for(int j=0;j<=K;j++){
			if(0 <= S - i - j && S - i - j <= K){
				ret++;
			}
		}
	}
	cout<<ret<<endl;
}

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

int main() {
double A,B,H,M;
  cin >> A >> B >> H >> M;
  double pi = 3.14159265358979;
double a = 0;
  double b = 0;
  a = H * pi / 6 + M * pi / 360;
  b = M * pi / 30;
  double c = a - b;
  if(c < 0)c += 2 * pi;
cout << fixed << setprecision(15) << sqrt(A * A + B * B - (2 * A * B * cos(c))) << endl;  
}


Measured memory_bytes: 4248
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    int n, k;
    cin >> n >> k;
    --k;

    string s;
    cin >> s;

    s[k] = s[k] - 'A' + 'a';

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
string = str(input())
res = ''
for i in range(len(string)):
	temp = ''
	# print(ord(string[i])+N)
	x = ord(string[i])-ord('A')
	x = (x+N)%26
	temp = chr(x+ord('A'))
	res += temp
print(''.join(res))

Measured memory_bytes: 40540
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        
    	int x = sc.nextInt();
    	int y = sc.nextInt();
    	int z = sc.nextInt();
    	int j=0;
    	while(x<=y){
    		if(z%x==0){
    						j++;
    					}
    					x++;
    				

    		}
    		 System.out.println(j);
        sc.close();
}
}



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


int main(){
  int a,b;
  cin >> a >> b;
  if(a+b==15)cout << "+" << endl;
  else if(a*b==15)cout << "*" << endl;
  else cout << "x" << endl;

  return 0;
}


Measured memory_bytes: 3564
from collections import deque

Y, X = map(int, input().split())
Map = list(input() for _ in range(Y))

def bfs(sy, sx, gy, gx):
    seen = list([-1]*X for _ in range(Y))
    queue = deque()
    queue.append((sy, sx))
    seen[sy][sx] = 0
    while queue:
        y, x = queue.popleft()
        search_around(y, x, seen, queue)
        if seen[gy][gx] > 0:
            return seen[gy][gx]

def search_around(y, x, seen, queue):
    count = seen[y][x]
    for u,t in [(y-1,x), (y+1,x), (y,x-1), (y,x+1)]:
        if u < 0 or t < 0 or u >= Y or t >= X:
            continue
        elif Map[u][t] == '#' or seen[u][t] != -1:
            continue
        queue.append((u, t))
        seen[u][t] = count + 1
        
cnt = 0
for M in Map:
    for m in M:
        if m == '#':
            cnt += 1

b = bfs(0,0,Y-1,X-1)
if b == None:
    print(-1)
else:
    print(Y*X - cnt - b - 1)

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


int main(){
	int n, ans = INF;
	cin >> n;
	rep(i, n + 1) {
		int k = n - i;
		int c = 0;
		for (int j = i; j; j /= 6) c += j % 6;
		for (int j = k; j; j /= 9) c += j % 9;
		ans = min(ans, c);
	}
	cout << ans << endl;
}



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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Int32.Parse(Console.ReadLine());
            var aArray = Console.ReadLine().Split(' ');
            var result = Int32.MaxValue;
            var count = 0;
            foreach(string str in aArray)
            {
                var a = Int32.Parse(str);
                count = 0;
                while (a % 2 == 0)
                {
                    a /= 2;
                    count++;
                }
                if (result > count) result = count;
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 27840
/*
 *
 * Author: r3gz3n
 * 
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define endl '\n'


class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
        int a, b, x, y, ans;
        in >> a >> b;
        x = (a * 25) / 2 + (a % 2);
        y = b * 10;
        ans = max(x, y);
        if ((ans * 2) / 25 != a or (ans / 10) != b) out << -1 << endl;
        else out << ans << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int ans = 0;

void a(int count){
    if (count > ans){
        ans = count;
    }
}

int main(){
    char str[12];
    
    scanf("%s", &str);
    
    int idx = 0;
    
    int count = 0;

    while(str[idx] != '\0'){
        switch(str[idx]){
            case 'A':
            case 'C':
            case 'T':
            case 'G':
                count++;
                break;
            default:
                a(count);
                count = 0;
        }
        idx++;
    }
    
    if (count > ans){
        ans = count;
    }
    
    printf("%d", ans);
        
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	string s,t,u;
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if(s==u)
	   a--; 
	else
	    b--;
	cout<<a<<" "<<b;
	return 0;
}


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

using namespace std;

int main(){
	int n, q, x;
	cin >> n >> q;
	string res = "kogakubu10gokan";
	for(int i = 0;i < n;i++){
		cin >> x;
		if(x > q){
			cout << res << endl;
			return 0;
		}
	    cin >> res;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1204
N, Q = map(int, input().split())
S=input()
S1=S.split("AC")
#print(S1)
C=[]
SC=[0]*len(S)
i=0
ac=0
for a in S1:
    #SC[i]=
    #i+=len(a)
    C.append(len(a))

    #SC[i]=ac
    #SC[i+1]=ac+1
    #i+=2
    #ac+=1
    #C.append(2)

for c in C:
    for j in range(i,i+c):
        SC[j]=ac
    i+=c
    try:
        SC[i]=ac
        SC[i+1]=ac+1
    except:
            break
    ac+=1
    i+=2


#print(i,ac)
#print(C)
#print(SC)


for i in range(Q):
    l, r = map(int, input().split())
    x=SC[r-1]-SC[l-1]
    #x=
    print(x)

Measured memory_bytes: 9932
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using P = pair<int,int>;
using Graph =vector<string>;
Graph field;
queue<P> q;


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    long long N;
    ll ans=0;
    cin >> N;
    for(int i=1;i<N;i++){
      const auto pf = prime_factorize(i);
      long long res = 1;
      for (auto p : pf) res *= p.second + 1;
      ans=ans+res;

    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3632
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	int i,j=1;
Scanner scan=new Scanner(System.in);
	while(true)
	    {
		
		
		i=scan.nextInt();
		if(i==0)break;
		System.out.println("Case "+j+": "+i);
		j++;
	    }
    }
}

Measured memory_bytes: 31348
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
a.sort()

if n == 1:
    print(0)
    exit()

fac = [1] * (n + 1)
inv = [1] * (n + 1)
def COMinit():
    for j in range(1, n + 1):
        fac[j] = fac[j - 1] * j % mod

    inv[n] = pow(fac[n], mod - 2, mod)
    for j in range(n - 1, -1, -1):
        inv[j] = inv[j + 1] * (j + 1) % mod

def comb2(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod

COMinit()
ans = 0
for i in range(n):
    if k != 1:
        x = comb2(n-1-i, k-1)
        ans = (ans - a[i]*x % mod) % mod
        ans = (ans + a[-1-i]*x % mod) % mod
print(ans%mod)



Measured memory_bytes: 87912
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main()
{
  ll n,k,q;
  cin >> n >> k >> q;
  vector<ll> a;
  for(ll i = 0;i < q;i++)
  {
    ll A;
    cin >> A;
    a.push_back(A);
  }
  // cout << endl;
  // for(ll i = 0;i < q;i++)
  // {
  //   cout << a[i] << endl;
  // }

  ll ans[n];
  for(ll i = 0;i < n;i++)
  {
    ans[i] = q;
  }

  for(ll i = 0;i < q;i++)
  {
    ans[a[i]-1] -= 1;
  }
  // cout << endl;
  // for(ll i = 0;i < n;i++)
  // {
  //   cout << ans[i] << endl;
  // }
  for(ll i = 0;i < n;i++)
  {
    if(ans[i] < k)
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 2292
#include <iostream>
#include <vector>
#include <iomanip>
#include <ios>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

signed main() {
    int W, H, x, y;
    cin >> W >> H >> x >> y;
    
    cout << fixed << setprecision(10) << H * W / 2.0 << " ";
    if (x * 2 == W && y * 2 == H) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LiangJiaJun main
using namespace std;
int k,ne,h[100004];
struct edge{
    int to,nt,w;
}e[500004];
queue<int>q;
int dis[100004];
void add(int u,int v,int w){
     e[++ne].to = v;e[ne].nt = h[u];
     e[ne].w=w;
     h[u]=ne;
}
int LiangJiaJun(){
    scanf("%d",&k);
    for(int i=0;i<k;i++){
        add(i,(i+1)%k,1);
        add(i,(i*10)%k,0);
    }
    q.push(1);
    memset(dis,127/3,sizeof(dis));
    dis[1]=0;
    while(!q.empty()){
        int x=q.front();q.pop();
        for(int i=h[x];i;i=e[i].nt){
            if( dis[e[i].to]>dis[x]+e[i].w){
                dis[e[i].to]=dis[x]+e[i].w;
                q.push(e[i].to);
            }
        }
    }
    printf("%d\n",dis[0]+1);
    return 0;
}


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

int main() {
  long i,o,t,j,l,s,z;
  cin >> i >> o >> t >> j >> l >> s >> z;
  if((i>0&&j>0)&&(l>0&&i%2+j%2+l%2>=2)) {
    cout << o+3+(i-1)/2*2+(j-1)/2*2+(l-1)/2*2 << endl;
  } else {
    cout << o+i/2*2+j/2*2+l/2*2 << endl;
  }
}

Measured memory_bytes: 3628
from collections import deque


def main():
    n, q = map(int, input().split())

    edges = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        edges[a-1].append(b-1)
        edges[b-1].append(a-1)

    operations = [0] * n
    for i in range(q):
        p, x = map(int, input().split())
        operations[p-1] += x

    counter = [-1] * n
    d = deque([(-1, 0, 0)])
    while len(d) > 0:
        p, i, v = d.pop()
        total = operations[i] + v
        for c in edges[i]:
            if c != p:
                d.append((i, c, total))
        counter[i] = total

    print(*counter)


main()

Measured memory_bytes: 118036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  string k;
  int d;
  cin >> k;
  cin >> d;
  vector<vector<vector<ll>>> dp(k.size()+1,vector<vector<ll>>(d,vector<ll>(2,0)));
  dp[0][0][0] = 1;
  for(int i=1;i<=k.size();i++){
    int kd = k.at(i-1) -'0';
    for(int j=0;j<d;j++){
      rep(g,10){
        int ch = (j-g+g*d)%d ;
        //cout << ch << endl;
        if(kd > g){
          dp.at(i).at(j).at(1) = (dp.at(i).at(j).at(1) + dp.at(i-1).at(ch).at(0))%MOD;
        }else if(kd == g){
          dp.at(i).at(j).at(0) = (dp.at(i).at(j).at(0) + dp.at(i-1).at(ch).at(0))%MOD;
        }
        dp.at(i).at(j).at(1) = (dp.at(i).at(j).at(1) + dp.at(i-1).at(ch).at(1))%MOD;
      }
    }
  }
  ll ans = (dp.at(k.size()).at(0).at(0) + dp.at(k.size()).at(0).at(1) - 1 + MOD) %MOD;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 55296
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b;
    cin>>a>>b;
    if(a==b)cout<<"Draw"<<endl;
    else if(a==1||b==1){
        if(a==1)cout<<"Alice"<<endl;
        else cout<<"Bob"<<endl;
    }
    else {
        if(a>b)cout<<"Alice"<<endl;
        else cout<<"Bob"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
 
int main(void){
  char str[4];
  int flag=0;
  scanf("%s",&str);
  
  for (int i=0;i<3;i++){
    if(str[i]==str[i+1]){
      flag=1;
    }
  }
  
  if(flag==0){
    printf("Good");
  }else{
    printf("Bad");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int main(){
    ll a,b;
    cin >> a >> b;
    if(a==1||b==1){
        cout << 1<<endl;
        return 0;
    }

    if(a%2==0||b%2==0){
        ll ans = a*b/2;
        cout << ans << endl;
    }
    else{
        ll ans =a*b/2+1;
        cout << ans << endl;
    }
}
  


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int temp = 0, result = 0;
        Set set = new HashSet();
        for (int i = 0; i < n; i++) {
            temp = scanner.nextInt();
            if (set.contains(temp)) {
                set.remove(temp);
                result--;
            } else {
                set.add(temp);
                result++;
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 62772
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  int x, a, b;
  cin >> x >> a >> b;
  x -= a;
  x %= b;
  cout << x;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        a,b=map(int,input().split())
        a-=1
        b-=1
        E[a].append(b)
        E[b].append(a)

    # 0 から出発し、2方向にpathを伸ばす
    used=[0]*n
    used[0]=1
    Q=[0]
    front=[0]
    while(Q):
        v=Q.pop()
        for nv in E[v]:
            if(used[nv]): continue
            used[nv]=1
            front.append(nv)
            Q.append(nv)
            break

    back=[]
    Q=[0]
    while(Q):
        v=Q.pop()
        for nv in E[v]:
            if(used[nv]): continue
            used[nv]=1
            back.append(nv)
            Q.append(nv)
            break

    ans=back[::-1]+front
    print(len(ans))
    print(*map(lambda x:x+1,ans))
resolve()

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

#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 

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

    int ans = 0;
    rep(i,N-2){
        if(S[i] == 'A' &&  S[i+1] == 'B' && S[i+2] == 'C'){
            ans +=1;
        }
    }
    cout << ans << endl;

}



Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>
using namespace std;
#define INF 1<<20

struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int TO,int V,vector<vector<edge> > graph) {
	priority_queue<Node> q;
	vector<int> d(V);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
		for (int i = 0;i < graph[pos].size();i++) {
			int to = graph[pos][i].to;
			int cost = graph[pos][i].cost;
			if (d[pos] + cost < d[to]) {
				d[to] = d[pos] + cost;
				q.push(Node(to, d[to]));
			}

		}
	}
	cout << d[TO] << endl;
}
int partition(int A[],int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
		swap(A[i + 1], A[r]);
		return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[],int n,int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >=0  ) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n,int* v,int* ww) {
	int W[101][10001];
		for (int j = 0;j <= w;j++) {
			W[0][j] = 0;
		}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++){
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int fib(int n) {
	vector<int> v(n+1);
	v[0] = 1;
	v[1] = 1;
	for (int i = 2;i < n+1;i++) {
		v[i] = v[i - 2] + v[i - 1];
	}
	return v[n];
}
int isPrime(int x) {
	if (x <= 1) return false;
	if (x>2 && x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}
int main() {
	int num;
	double w, h;
	char cum;
	vector<int> v;
	while(cin>>num >> cum >> w >> cum >> h) {
		double BMI = w / (h*h);
		if (BMI >= 25) v.push_back(num);
	}
	for (int i = 0;i < v.size();i++) {
		cout << v[i] << endl;
	}

	}

Measured memory_bytes: 1256
a,b,m=gets.split.map(&:to_i)
aa=gets.split.map(&:to_i)
bb=gets.split.map(&:to_i)
mm=[]
m.times{i=gets.split.map(&:to_i)
mm<<aa[i[0]-1]+bb[i[1]-1]-i[2]}
p [mm.min,aa.min+bb.min].min

Measured memory_bytes: 19228
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <stack>

using namespace std;

typedef long long ll;
#define mem(a) (memset(a,0,sizeof(a)))
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define MAX(a, b) ((a)>(b)?(a):(b))
#define MIN(a, b) ((a)<(b)?(a):(b))

const int maxn = static_cast<const int>(1e5 + 5);
const int mod = static_cast<const int>(1e9);

int a[maxn];

int main() {
    int n, k,s;
    ll sum = 1;
    scanf("%d%d", &n, &k);
    rep(i,n-1){
        sum*=(k-1);
    }
    sum*=k;
    printf("%lld\n",sum);

    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = int(input())
    ans = 0
    j = 1

    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]

    for i in range(2, 3000 + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    def cmb(n, r, mod):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return fact[n] * factinv[r] * factinv[n - r] % mod

    while S-3*j>=0:
        a = S-j*3
        ans += cmb(a+j-1,a,MOD)
        ans %= MOD
        j += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9468
# coding: utf-8

import sys
import math

import array
import bisect
import collections
from collections import Counter, defaultdict
import fractions
import heapq
import re

sys.setrecursionlimit(1000000)


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

def argsort(l, reverse=False):
    return sorted(range(len(l)), key=lambda i: l[i], reverse=reverse)

def argmin(l):
    return l.index(min(l))

def YESNO(ans, yes="YES", no="NO"):
    print([no, yes][ans])

II = lambda: int(input())
MI = lambda: map(int, input().split())
MIL = lambda: list(MI())
MIS = lambda: input().split()


def main():
    N, M = MI()
    lr = [0] * (N + 1)
    rr = [0] * (N + 1)
    for i in range(M):
        l, r = MI()
        lr[l] += 1
        rr[r] += 1
    c = 0
    ans = 0
    for i in range(N + 1):
        c += lr[i]
        if c == M: ans += 1
        c -= rr[i]
    return ans


if __name__ == "__main__":
    print(main())


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

int main(){
	map<int, int> m;
	map<int, int> r;
	int a[6], n, x, y;
	int d[6][6]={{0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},
		{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0}};
	for(int i = 0;i < 6;i++){cin >> a[i];m[a[i]] = i;r[i] = a[i];}
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> x >> y;
		int f = m[x];
		int t = m[y];
		//cout << "     *" << f << t << "*" << d[f][t] << endl;
		int tmp = d[f][t];
		cout << r[tmp-1] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3104
import java.util.*;
 
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int f=0;
		
		for(int i=1;i<=9;i++) {
			for(int j=1;j<=9;j++) {
				if(i*j==a&&f==0) {
					System.out.println("Yes");
					f=1;
				}else {
					if(i==9&&j==9&&f==0) {
						System.out.println("No");
					}
				}

			}

		}

 
		sc.close();
	}
}

Measured memory_bytes: 23892
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		
		if (a + b >= c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21716
#include<stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if((a<b)&&(b<c))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
		return 0;

}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void){


    string s;	cin >> s;
    if(s == "Sunny")  SCOUT("Cloudy")<< endl;
    if(s == "Cloudy")  SCOUT("Rainy")<< endl;
    if(s == "Rainy")  SCOUT("Sunny")<< endl;

return 0;
}


Measured memory_bytes: 256
N, K, T, U, V, L = gets.split.map(&:to_f)
stock = 0
restTime = 0.0
time = 0.0
distance = 0.0
N.to_i.times do
  d = gets.to_f
  if restTime > 0.0 || stock > 0
    t = (d - distance) / V
    while true do
      break if restTime >= t || stock == 0
      restTime += T
      stock -= 1
    end
    if restTime >= t
      restTime -= t
      time += t
    else
      time += restTime
      time += (d - distance - V * restTime) / U
      restTime = 0.0
    end
    distance = d
  else
    time += (d - distance) / U
    distance = d
  end
  if stock < K
    stock += 1
  else
    restTime = T
  end
end

if restTime > 0.0 || stock > 0
  t = (L - distance) / V
  while true do
    break if restTime > t || stock == 0
    restTime += T
    stock -= 1
  end
  if restTime >= t
    restTime -= t
    time += t
  else
    time += restTime
    time += (L - distance - V * restTime) / U
    restTime = 0.0
  end
  distance = L
else
  time += (L - distance) / U
  distance = L
end

p time

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

  int n,m,i,j,count[10001],carin,carout,in,out,box,zero = 1;

  scanf("%d",&n);
  scanf("%d",&m);

  for( i = 1 ; i <= n ; i++ ){
    
    scanf("%d %d",&in,&out);

    if( i == 1){
      count[i] = m + in - out;
    }
    else count[i] = count[i - 1] + in - out;

    if( count[i] < 0 ){
      zero = 0;
    } 

    if( i == 1 && m >= count[i]) box = m;
    else if ( i == 1) box = count[i];

    if( i > 1 && box <= count[i] ) box = count[i];
    else box = box;

  }

  if( zero == 0 ) printf("0\n");
  else  if( box > 0 ) printf("%d\n",box);

  return 0;

}

Measured memory_bytes: 628
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int count = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];

int main(){
    int T, X;
    cin >> T >> X;
    cout << (double) T / X << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  int N, M, x, sum;
  cin >> N >> M;
  sum = 0;
  for (int i = 0; i < M; i++) {
    cin >> x;
    sum += x;
  }
  cout << max(N - sum, -1) << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	long long int N, A;
	cin >> N >> A;
	if ((A + N) % 2 == 0)cout << (A+N) / 2;
	else cout << "IMPOSSIBLE";
}


Measured memory_bytes: 888
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N,M = map(int,readline().split())

c = [1]*N
r = [0]*N
r[0] = 1

for _ in range(M):
    x,y = map(int,readline().split())
    x,y = x-1,y-1
    if r[x]:
        if c[x] == 1:
            r[x] = 0
        r[y] = 1
    c[x] -= 1
    c[y] += 1

print(sum(r))

Measured memory_bytes: 4596
#include<iostream>
using namespace std;
int main(){
    char mark;
    int n,num,card[4][14]={};
    cin >> n;
    for (int i = 0;i < n;i++){
        cin >> mark >> num;
        if (mark == 'S') card[0][num] = 1;
        if (mark == 'H') card[1][num] = 1;
        if (mark == 'C') card[2][num] = 1;
        if (mark == 'D') card[3][num] = 1;
    }
    for (int i = 0;i < 4;i++){
        for(int j = 1;j < 14;j++){
            if (i == 0) mark = 'S';
            if (i == 1) mark = 'H';
            if (i == 2) mark = 'C';
            if (i == 3) mark = 'D';
            if (card[i][j] == 0){
                cout << mark << " " << j <<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, a, b) for(auto (i)=a;i<b;i++)
#define list(i, N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

template<class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int p, q, r; cin >> p >> q >> r;
    vi arr = {p, q, r};
    sort(arr.begin(),arr.end());
    cout << arr[0] + arr[1] << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T=ll>
using v =vector<T>;
template<typename T=ll>
using vv = vector<v<T>>;
template<typename T=ll,typename U=ll> using p = pair<T,U>;
const ll INF = (ll)1e9;
const ll MOD = INF+7;
template<typename T> T chmin(T &a,T b){a=min(a,b);}
template<typename T> T chmax(T &a,T b){a=max(a,b);}

struct modint
{
    ll a;
    modint():a(0){}
    modint(ll t){
        a=t%MOD;
        if(a<0) a+=MOD;
    }
    //operator long long() const{return a;}
    bool operator==(const modint & x)const{return a==x.a;}
    bool operator!=(const modint & x)const{return a!=x.a;}
    modint operator-() const {return modint(a?(MOD-a):0);}
    modint operator~() const {return modint(MOD -2);}
    modint operator+(const modint &x) const{return modint(*this)+=x;}
    modint operator-(const modint &x) const{return modint(*this)-=x;}
    modint operator*(const modint &x) const{return modint(*this)*=x;}
    modint operator/(const modint &x) const{return modint(*this)/=x;}
    modint &operator+=(const modint &x){
        a+= x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint &operator-=(const modint &x){
        a-= x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    
    modint &operator*=(const modint &x){
        a=a*x.a %MOD;
        return *this;
    }
    modint &operator/=(const modint &x){
        a=a*(~x).a %MOD;
        return *this;
    }

    friend ostream &operator<<(ostream &os,const modint &x){
        return os << x.a;
    }

    friend istream &operator>>(istream &is,modint &x){
        ll t;
        x=modint(t);
        return is;
    }

    modint pow(ll x)const{
        modint ret = 1,tmp=a;
        for(;x;tmp*=tmp,x>>=1){
            if(x&1) ret*=tmp;
        }
        return ret;
    }

};

modint nCr(int n,int r){
    modint ans=1;
    for(int i=1;i<=r;i++) ans*=modint(n-i+1)/modint(i);
    return ans;
}

int main(){
    string s; cin >> s;
    map<char,int> m;
    for(auto i:s){
        m[i]++;
    }
    if(m.size()==4){
        cout << "Yes" << endl;
    }else if(m.size()%2){
        cout << "No" << endl;
    }else{
        if((m['S']&&m['N'])||(m['W']&&m['E'])){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N, V, P;
  ll M;
  cin >> N >> M >> V >> P;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  sort(all(A));
  vector<ll> sum(N+1);
  rep(i, N) sum[i+1] = sum[i] + A[i];
  int cnt = 0;
  rep(i, N) {
    ll val = A[i]+M;
    int j1 = upper_bound(all(A), A[i]) - A.begin();
    int j2 = upper_bound(all(A), val) - A.begin();
    int j3 = N-P+1;
    j1 = min(j3, j1);
    j2 = min(j3, j2);
    ll margin = M*j1 + (val*(j2-j1)-(sum[j2]-sum[j1])) + (N-j3)*M;
    int pos = N-j2+1;
    if(margin >= M*V && pos <= P) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b;
    cin>>a>>b;
    ll x=min(a,b);
    ll y=max(a,b);
    if(x==1 && y==2)
    {
        cout<<3<<endl;
    }
    else if(x==1 && y==3)
    {
        cout<<2<<endl;
    }
    else if(x==2 && y==3)
    {
        cout<<1<<endl;
    }

    return 0;
}


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

const int ALPHABETE = 26;

int possible(int H, int W, vector<int>n)
{
    int c4 = (H / 2) * (W / 2); // 4個必要な文字
    int c2 = (H % 2) * (W / 2) + (W % 2) * (H / 2); // 2個必要な文字
    int c1 = (H % 2) * (W % 2); // 1個だけ必要な文字
    int i, use;

    for(i = 0; i < ALPHABETE; i++) {
        if(n[i] >= 4 && c4 >= 1) {
            use = min(c4, n[i] / 4);
            c4 -= use;
            n[i] -= 4 * use;
        }
        if(n[i] >= 2 && c2 >= 1) {
            use = min(c2, n[i] / 2);
            c2 -= use;
            n[i] -= 2 * use;
        }
        if(n[i] >= 1 && c1 >= 1) {
            use = min(c1, n[i]);
            c1 -= use;
            n[i] -= 1 * use;
        }
    }
    if(c4 == 0 && c2 == 0 && c1 == 0) {
        return true;
    } else {
        return false;
    }
}

int main()
{
    int H, W;
    int i, j, k;
    cin >> H >> W;
    vector<int> n = vector<int>(ALPHABETE, 0);
    string s;
    char c;

    for(i = 0; i < H; ++i) {
        cin >> s;
        for(j = 0; j < W; ++j) {
            c = s[j];
            n[c - 'a']++;
        }
    }

    if(possible(H, W, n)) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;
unordered_map<string, ll> memo;
string AND(string s, string t){
	string ret;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='1' && t[i]=='1') ret+='1';
		else ret+='0';
	}
	return ret;
}
ll solve(string s){
	int n=s.size();
	if(n==1){
		if(s[0]=='0') return 1;
		else return 2;
	}
	auto itr=memo.find(s);
	if(itr!=memo.end()) return itr->second;
	string s1=s; reverse(s1.begin(), s1.end());
	auto itr1=memo.find(s1);
	if(itr1!=memo.end()) return itr1->second;
	ll ans=solve(s.substr(1, n-1));
	if(s[0]=='1') ans=ans*2%MOD;
	string t=s;
	for(int i=1; i<=n; i++){
		string t=s.substr(0, i);
		for(int j=i; j+i<=n; j+=i){
			t=AND(t, s.substr(j, i));
			if(j+i<n) ans=(ans+solve(t)*solve(s.substr(j+i)))%MOD;
			else ans=(ans+solve(t))%MOD;
		}
	}
	return memo[s]=ans;
}

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

Measured memory_bytes: 4876
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int A, B, C, D; cin >> A >> B >> C >> D;
  if (A + B > C + D) cout << "Left" << endl;
  else if (A + B == C + D) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}


Measured memory_bytes: 256
A, B, Q = gets.split.map(&:to_i)
s = []
t = []
A.times do
  s << gets.chomp.to_i
end
B.times do
  t << gets.chomp.to_i
end
s.sort!
t.sort!

x = 0
temp_index = 0
Q.times do
  x = gets.chomp.to_i
  # 各近傍値を取る
  tmp = s.bsearch_index { |v| v >= x }
  sl, su = tmp ? (tmp == 0 ? [nil, s[0]] : [s[tmp-1], s[tmp]]) : [s[A - 1], nil]
  tmp = t.bsearch_index { |v| v >= x }
  tl, tu = tmp ? (tmp == 0 ? [nil, t[0]] : [t[tmp-1], t[tmp]]) : [t[B - 1], nil]
  m = 2 * (10 ** 10) + 1
  if sl
    if tl
      m = [[x - sl, x - tl].max, m].min
    end
    if tu
      m = [(tu - sl) + [x - sl, tu - x].min, m].min
    end
  end
  if su
    if tl
      m = [(su - tl) + [su-x, x-tl].min , m].min
    end
    if tu
      m = [[su-x, tu-x].max, m].min
    end
  end
  puts m
end

Measured memory_bytes: 5996
/* 実行時間1s制限の場合10^6 1,000,000 : 余裕をもって間に合う10^7
  10,000,000 : おそらく間に合う10^8 100,000,000 : 非常にシンプルな処理
  でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

const ll INF = LONG_MAX;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    //std::ifstream in(string(argv[0]) + ".txt");
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int s, w;
    cin >> s >> w;

    if (s <= w) cout << "unsafe";
    else cout << "safe";


    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 3632