akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;
const long INF = 2000000000;

int main() {
  int n,m,L[110000],R[110000];
  cin >> n >> m;
  int LL = 1;
  int RR = n;
  for(int i = 0; i < m; i++) {
    cin >> L[i] >> R[i];
    LL = max(LL,L[i]);
    RR = min(RR, R[i]);
  }
  
  int cnt = 0;
  for(int i = 1; i <= n; i++)
    if(i >= LL & i <= RR) cnt++;
  
  cout << cnt << endl;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,x,y,cnt=0,xx=0,yy=0;
int32_t main(){
CODE_START;
cin>>n;
for(ll i=1;i<=n;i++)
{
    cin>>x>>y;
if(x==y){
    cnt++;
}else {
if(cnt>=3){
        rc("Yes");
}
cnt=0;
}
}
if(cnt>=3){
    rc("Yes");
}
cout<<"No"<<endl;
}


Measured memory_bytes: 3648
S=input()
a=int(S[:2])
b=int(S[2:])
if 1<=a<=12 and 1<=b<=12:
    print("AMBIGUOUS")
elif 1<=a<=12 and (b>=13 or b==0):
    print("MMYY")
elif a>=13 and (b>=13 or b==0):
    print("NA")
elif a>=13 and 1<=b<=12:
    print("YYMM")
elif a==0 and (b>=13 or b==0):
    print("NA")
elif a==0 and (1<=b<=12):
    print("YYMM")

Measured memory_bytes: 3064
N, Q = map(int,input().split())
S = input()
Q_lst = []
for i in range(Q):
    Q_lst.append(list(map(int,input().split())))

ruiseki_lst = [0 for i in range(N)]

ruiseki_lst[0] = 0
for i in range(1,N):
    if S[i] == 'C' and S[i-1] == 'A':
        ruiseki_lst[i] = ruiseki_lst[i-1] + 1
    else:
        ruiseki_lst[i] = ruiseki_lst[i - 1]

for q in Q_lst:
    left = q[0]-1
    right = q[1]-1
    print(ruiseki_lst[right] - ruiseki_lst[left])

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

int n,k,x;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    vector <int> sol(n+1,0);
    int d;
    for (int i=0; i<k; i++){
        cin>>d;
        for (int j=1; j<=d; j++){
            cin>>x;
            sol[x]=1;
        }
    }
    
    int res=0;
    
    for (int i=1; i<=n; i++){
        if (sol[i]==0) res++;
    }
    
    cout<<res;
    
    
    
    
    
    
    return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  cout << (n&1 ? n*2 : n) << endl;

  return 0;
}


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

int main(){
    string s;
    cin >> s;
//    int y = stoi(s.substr(0,4));
    int m = stoi(s.substr(5,2));
//    int d = stoi(s.substr(8,2));

    if(m < 5) cout << "Heisei" << endl;
    else cout << "TBD" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;
const int mod = 1e9+7;
int ad(int x,int y) { x+=y; return x>=mod?x-mod:x; }
int sb(int x,int y) { x-=y; return x<0?x+mod:x; }
int mu(int x,int y) { return 1ll*x*y%mod; }
int ksm(int a,int b) {
	int ans = 1;
	for(;b;b>>=1,a=mu(a,a))
		if(b&1) ans = mu(ans,a);
	return ans;
}
int n,k;
int mk[605];
int cnt[605][605];
int dp[605][605];
int g[605];
int main() {
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++) {
		int x,y; scanf("%d%d",&x,&y);
		mk[x] = y;
		mk[y] = x;
	}
	g[0] = 1;
	for(int i=2;i<=2*n;i+=2) {
		g[i] = 1;
		for(int j=1;j<i;j+=2) {
			g[i] = mu(g[i],j);
		}
	}
	for(int i=1;i<=2*n;i++) {
		for(int j=i;j<=2*n;j++) {
			cnt[i][j] = cnt[i][j-1] + (!mk[j]);
		}
	}
	for(int i=1;i<=2*n;i++) {

		for(int j=i;j<=2*n;j++) {
			bool fk = 0;
			for(int k=i;k<=j;k++) {
				if(mk[k]&&(mk[k]>j||mk[k]<i) ) {
					fk = 1;
					break;
				}
			}
			if(fk) continue;
			dp[i][j] = g[cnt[i][j]];
			for(int k=i+1;k<=j-1;k++) {
				dp[i][j] = sb(dp[i][j],mu(dp[i][k],g[cnt[k+1][j]]));
			}
		}
	}
	int ans = 0;
	for(int i=1;i<=2*n;i++) {
		for(int j=i;j<=2*n;j++) {
			ans = ad(ans,mu(dp[i][j],g[ 2*n - 2*k - cnt[i][j] ]));
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 3072
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int v = n/500;
    if(n-(500*v)<=a) System.out.println("Yes");
    else System.out.println("No");
  }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
 
int no[10] = {};
 
bool isOK(int n){
    while(n > 0){
        if(no[n%10] == 1){
            return false;
        }
        n /= 10;
    }
    return true;
}
 
int main(){
    int n, k;
    cin >> n >> k;
 
    int t;
    for(int i = 0;i < k;i++){
        cin >> t;
        no[t] = 1;
    }
 
    int i = n;
    while(1){
        if(isOK(i)){
            cout << i << endl;
            return 0;
        }else{
            i++;
        }
    }
 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lli long long int
#define f(i,a,b) for(i=a;i<b;i++)
#define ff first
#define sc second
#define pb push_back
#define full(v) v.begin(),v.end()
#define ms(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define mod2 998244353
#define msb(b) memset(b,true,sizeof(b))
#define msf(b) memset(b,false,sizeof(b))
#define MAXN 100005
#define PI 3.14159265358979323846264338327950L
// bool prime[1000000]; // 10**6
// lli pri[100000],x=0;
/*void sieve()
{
  msb(prime);
  prime[0]=prime[1]=false;
  for(int p=2;p*p<=1000000;p++)
  {
    if(prime[p])
    {
      for(int i=p*2;i<=1000000;i+=p)
        prime[i]=false;
      // a[x++]=p;
    }
  }
} */

int main()
{
    fio;
    int t,n,i,a,b,h,m;
    cin >> a >> b >> h >> m;
    long double rad = PI * 2 * ((long double)h/ 12.0 + ((long double)m/ 60.0) / 12.0 - (long double)m / 60.0);
    long double req = (long double)(a*a + b*b) - (long double)(2*a*b)*cosl(rad);
    printf("%20.20Lf\n",sqrtl(req));
}


Measured memory_bytes: 4176
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N,K=LI()

if K == 1:
    print(0)
else:
    print(N-K)


Measured memory_bytes: 38384
#include <algorithm>
#include <array>
#include <complex>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
  int N;
  cin >> N;
  double valM1 = -1;
  int valm1 = 10000000;
  double valM2 = -1;
  int valm2 = 10000000;
  int prea = -1;
  int pret = -1;
  int pref = 0;
  int prex, prey;
  for(int i = 0; i < N; ++i) {
    int f, a, t, x, y;
    cin >> f >> a >> t >> x >> y;
    if(pret == t && prea != a){
      double d = (x - prex) * (x - prex) + (y - prey) * (y - prey);
      if(t == 0){
        if(valM1 < d){
          valM1 = d;
          valm1 = f - pref;
        }else if(valM1 == d){
          valm1 = min(valm1, f - pref);
        }
      }else{
        if(valM2 < d){
          valM2 = d;
          valm2 = f - pref;
        }else if(valM2 == d){
          valm2 = min(valm2, f - pref);
        }
      }
    }
    pref = f;
    prea = a;
    pret = t;
    prex = x;
    prey = y;
  }
  if(valM1 == -1){
    printf("%.10f %.10f\n", -1.0, -1.0);
  }else{
    printf("%.10f %.10f\n", sqrt(valM1), (double)valm1 / 60);
  }
  if(valM2 == -1){
    printf("%.10f %.10f\n", -1.0, -1.0);
  }else{
    printf("%.10f %.10f\n", sqrt(valM2), (double)valm2 / 60);
  }

}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n); for (int i=0; i<(n); i++)//第一引数の変数をカウンタ変数としてn回回す
using veci = vector<int>;
using vecl = vector<long long>;
using vecd = vector<double>;
using vecs = vector<string>;
int main(){//まずabc...に数字を振り、最後までfalseだったもののうち最初のものを出力する
    string a = "abcdefghijklnmopqrstuvwxyz";
    string b;
    cin >> b;
    veci e(26, 0);
    for (int i=0; i<b.size(); i++){
      for (int j=0; j<a.size(); j++){
        if (b.at(i) == a.at(j)){
          e.at(j) +=1;
        }
      }
    }
    for (int i=0; i<26; i++){
      if (!e.at(i)){
        cout << a.at(i) << endl;
        return 0;
      }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
int main(){
	int x, y;
	cin >> x >> y;
	if (x == 1 && y == 1) {
		cout << 1000000 << endl;
	}
	else {
		cout << 800000 - min(400000, x * 100000) - min(400000, y * 100000) << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

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

int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); ++i){
        if(i % 2 == 0){
            cout << s[i];
        }
    }
    cout << endl;
    return 0;
}

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

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

    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    for (int i = 0; i < N; i++) cin >> P[i];
    for (int i = 0; i < N; i++) cin >> Q[i];
    vector<int> perm(N);
    for (int i = 0; i < N; i++) perm[i] = i + 1;
    int n = 0;
    int a, b;
    do {
        if (perm == P) a = n;
        if (perm == Q) b = n;
        n++;
    } while (next_permutation(perm.begin(), perm.end()));
    cout << abs(a - b) << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N+1);
  vector<long long> B(N);
  long long ans=0;
  for(int i=0; i<N+1; i++){
    cin >> A.at(i);
    ans+=A.at(i);
  }
  for(int i=0; i<N; i++) cin >> B.at(i);
  for(int i=0; i<N; i++){
    if(B.at(i)<=A.at(i)){
      A.at(i)-=B.at(i);
    }
    else{
      A.at(i+1)-=min(A.at(i+1),(B.at(i)-A.at(i)));
      A.at(i)=0;
    }
  }
  for(int i=0; i<N+1; i++){
    ans-=A.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

N,= map(int, sys.stdin.readline().rstrip().split(" "))
bs = map(int, sys.stdin.readline().rstrip().split(" "))

countdict = collections.defaultdict(list)
for i, b in enumerate(bs):
    countdict[b].append(i+1)


def find_one():
    for i in range(101, 0, -1):
        if i in countdict:
            for j in range(len(countdict[i])):
                if countdict[i][j] == i:
                    del countdict[i][j]
                    return i

def change_pos(pos):
    for counts in countdict.values():
        for i in range(len(counts)):
            if counts[i] > pos:
                counts[i] -= 1

results = []
while True:
    res = find_one()
    if res is None:
        break
    results.append(res)
    change_pos(res)

rest = sum(len(counts) for counts in countdict.values())
if rest > 0:
    print(-1)
else:
    for i in reversed(results):
        print(i)

exit(0)


Measured memory_bytes: 3444
from collections import deque
import sys
input = sys.stdin.readline

def bfs(s_l, sy, sx, h, w):
    visited = [ [-1]*w for i in range(h)]
    q = deque([[sy,sx]])
    visited[sy][sx] = 0
    last_dist = -1
    while q:
        y, x = q.popleft()
        # if [y, x] == [gy, gx]:
        #     return visited[gy][gx]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            n_y, n_x = y+j, x+k
            if n_y >= h or n_x >= w or n_y < 0 or n_x < 0:
                continue
            if s_l[n_y][n_x] == '.' and visited[n_y][n_x] == -1:
                visited[n_y][n_x] = visited[y][x] + 1
                last_dist = visited[n_y][n_x]
                q.append([n_y,n_x])
    return last_dist

def main():
    h, w = map(int, input().split()) 
    s_l = []
    all_dot_cnt = 0
    for i in range(h):
        row = list(input())
        s_l.append(row)
        all_dot_cnt += row.count('.')
    
    curr_ans = -1
    visited = [ [-1]*w for i in range(h)]
    for i in range(h):
        for j in range(w):
            if s_l[i][j] == '.':
                res = bfs(s_l, i, j, h, w)
                if res > curr_ans:
                    curr_ans = res
    print(curr_ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define fs first
#define sc second
using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;

const D EPS = 1e-8;

namespace std{
  bool operator<(const P &a,const P &b){
    return EQ(real(a),real(b))?imag(a)<imag(b):real(a)<real(b);
  }
  bool operator==(const P &a, const P &b){return EQ(a,b);}
}

inline D dot(P x, P y){return real(conj(x)*y);}
inline D cross(P x, P y){return imag(conj(x)*y);}

int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;   //counter clockwise
  if (cross(b,c)<-EPS) return -1; //clockwise
  if (dot(b, c)<-EPS) return 2;   //c--a--b on line
  if (abs(b)+EPS<abs(c)) return -2;   //a--b--c on line
  return 0;                       //on segment
}

inline bool para(L a,L b){return abs(cross(a.fs-a.sc,b.fs-b.sc))<EPS;}

inline bool is_cp(L a,L b){
  if(para(a,b))return false;
  if(ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0)
    if(ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0)return true;
  return false;
}

inline P line_cp(L a,L b){
  return a.fs+(a.sc-a.fs)*cross(b.sc-b.fs,b.fs-a.fs)/cross(b.sc-b.fs,a.sc-a.fs);
}

vector<P> p[2];
inline D len(D x, int id){
  L l = L( P(x,-1000), P(x,1000) );
  vector<P> res;
  rep(i,p[id].size()){
    L a = L( p[id][i], p[id][(i+1)%p[id].size()] );
    if(is_cp(a,l)){
      P cp = line_cp(a,l);
      if(!EQ(cp,p[id][i]))res.push_back(cp);
    }else if(para(a,l) && ccw(l.fs,l.sc,a.sc)==0){
      res.push_back(a.sc);
    }
  }

  if(res.size()<2)return 0;
  return abs(res[0]-res[1]);
}

inline D f(D x){
  return len(x/2,0) * len(x/2,1);
}

int main(){
  int m,n;
  while(cin >> m >> n, m){
    int minx[2], maxx[2];
    p[0].resize(m); p[1].resize(n);
    minx[0] = minx[1] = 1000;
    maxx[0] = maxx[1] = -1000;

    rep(i,m){
      int x,y;
      cin >> x >> y;
      p[0][i] = P(x,y);
      minx[0]=min(minx[0],x);
      maxx[0]=max(maxx[0],x);
    }

    rep(i,n){
      int x,z;
      cin >> x >> z;
      p[1][i] = P(x,z);
      minx[1]=min(minx[1],x);
      maxx[1]=max(maxx[1],x);
    }

    D ans = 0;
    for(D i=-199;i<200;i+=2){
      if(2*minx[0]<=i && i<=2*maxx[0]){
	if(2*minx[1]<=i && i<=2*maxx[1]){
	  ans += f(i-1)+4*f(i)+f(i+1);
	}
      }
    }
    cout << fixed << setprecision(9) << ans/6 << endl;
  }
}

Measured memory_bytes: 1284
import math
from decimal import *

n = int(input())
nos = list(map(int, input().split()))
arr = [0 for i in range(n)]
if(n>1):
    arr[1] = abs(nos[1]-nos[0])
for i in range(2, n):
    a ,b = abs(nos[i]-nos[i-1])+arr[i-1], abs(nos[i]-nos[i-2])+arr[i-2]
    if(a>b):
        arr[i]=b
    else:
        arr[i] = a
print(arr[n-1])

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

void search(int **a, int n, int *d, int *f, int u, int *t) {
  int i;
  d[u] = *t;
  (*t)++;
  for (i = 0; i < n; i++) {
    if(a[u][i] == 1 && d[i] == 0) {
      search(a,n,d,f,i,t);
      (*t)++;
    }
  }
  f[u] = *t;
}

int main()
{
  int i,j,n,**a,u,k,v;
  scanf("%d",&n);
  a = (int**)malloc(sizeof(int*) * n);
  for (i = 0; i < n; i++) {
    a[i] = (int*)malloc(sizeof(int) * n);
    for(j = 0; j < n; j++) a[i][j] = 0;
  }
  for (i = 0; i < n; i++) {
    scanf("%d",&u);
    scanf("%d", &k);
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      a[u-1][v-1] = 1;
    }
  }

  int *d,*f,t;
  d = (int*)calloc(n,sizeof(int));
  f = (int*)calloc(n,sizeof(int));
  t = 1;

  for (i = 0; i < n; i++) {
    if(d[i] == 0) {
      search(a,n,d,f,i,&t);
      t++;
    }
  }


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

  free(a);
  free(d);
  free(f);
  return 0;
}

Measured memory_bytes: 652
#include<iostream>
using namespace std;
#include<string.h>
#include<string>

// study of Hash table.

#define M 1020001  // large prime number. 
#define L 14       // length of term.

char H[M][L];     // Hash table.

int getnum(char ch)  // character to number.
{
    if(ch == 'A'){ return 1; }
    else if(ch == 'C'){ return 2; }
    else if(ch == 'G'){ return 3; }
    else{ return 4; }
    return 0;
}

long long getkey(char word[])   // string to key.
{
    int sum = 0, p = 1, i;
    for(i = 0; word[i]; i++){
        sum = sum + p * getnum(word[i]);
        p = p * 5;
    }
    return sum;
}

int h1(int k){ return k % M; }   
int h2(int k){ return 1 + (k % (M - 1)); }  

int insert(char str[])
{
    int key, h, i;
    key = getkey(str);

    for(i = 0; ; i++){
        h = (h1(key) + i * h2(key)) % M;    // hash.
        if(strcmp(H[h], str)){  
            if(strlen(H[h]) == 0){ strcpy(H[h], str); return 1; }
        }else{ return 0; }
    }
    return 0;
}

int find(char str[])
{
    int key, h, i;
    key = getkey(str);

    for(i = 0; ; i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str)){
            if(strlen(H[h]) == 0){ return 0; } continue; }
            else{ return 1; }
    }
    return 0;
}

int main()
{
    char com[9], word[14];
    int NumOfCom;
    cin >> NumOfCom;

    for(int i = 0; i < M; i++) H[i][L] = '\0';  // initialize.

    while(NumOfCom){
        cin >> com >> word;
        if(com[0] == 'i'){ insert(word); }
        else{
            if(find(word)){ cout << "yes" << endl; }
			else{ cout << "no" << endl; }
        }
        NumOfCom--;
    };
    return 0;
}

Measured memory_bytes: 15108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define ALL(n) begin(n), end(n)

int main()
{
  int H, W;
  cin >> H >> W;
  vector<vector<char>> v(H, vector<char>(W));
  rep(i, H) rep(j, W) cin >> v[i][j];

  //横を確認
  rep(i, H)
  {
    bool white = true;
    rep(j, W)
    {
      if (v[i][j] == '#')
        white = false;
    }
    if (white)
      rep(j, W) v[i][j] = 'x';
  }

  //縦を確認
  rep(j, W)
  {
    bool white = true;
    rep(i, H)
    {
      if (v[i][j] == '#')
        white = false;
    }
    if (white)
      rep(i, H) v[i][j] = 'x';
  }

  rep(i, H)
  {
    bool isLine = false;
    rep(j, W) if (v[i][j] != 'x')
    {
      cout << v[i][j];
      isLine = true;
    }
    if (isLine)
      cout << endl;
  }
}

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

#define REP(i, x) for (int i = 0, i##_len = (int)(x); i < i##_len; i++)
#define REP1(i, x) for (int i = 1, i##_len = (int)(x); i <= i##_len; i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
const int MOD = (int)1e9 + 7;
const int INF = 1145141919;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
using d_d = pair<double, double>;
using vint = vector<int>;
using vll = vector<ll>;
using vbool = vector<bool>;

string getans(int N) {
    if (N == 0) {
        return "0";
    } else {
        string ans = "";
        while (N != 0 && N != 1) {
            if (N % -2 == 0) {
                ans = "0" + ans;
            } else {
                N -= 1;
                ans = "1" + ans;
            }

            N /= -2;
        }
        return "1" + ans;
    }
}

int main() {
    int N;
    cin >> N;
    cout << getans(N);
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
ll p=1e9+7;

int main(){
    ll n,k;cin>>n>>k;
    ll ans=0;
    ll gn[100001];
    for(int i=k;i>0;i--){
        gn[i]=modpow(k/i,n,p);
        ll cnt=2;
        ll t=i*cnt;
        while(t<=k){
            gn[i]-=gn[t];
            if(gn[k]<0)gn[i]+=p;
            cnt++;
            t=i*cnt;
        }
    }
    for(ll i=1;i<k+1;i++){
        ans=(ans+gn[i]*i)%p;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 4348
import java.util.Scanner;

/**
 * Created by akensho on 2015/11/23.
 */
public class Main {
    static int n, q;
    static int[] S, T;
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        while (read()){
            System.out.println(linerSearch(S, T));
        }
    }

    static boolean read(){
        if( !sc.hasNext() ) return false;
        n = sc.nextInt();
        S = new int[n];
        for (int i = 0; i < S.length; i++){
            S[i] = sc.nextInt();
        }
        q = sc.nextInt();
        T = new int[q];
        for (int i = 0; i < T.length; i++){
            T[i] = sc.nextInt();
        }
        return true;
    }

    static int linerSearch(int[] target, int[] values){
        int res = 0;
        for (int key : values) {
            for (int elements : target) {
                if (elements == key) {
                    res++;
                    break;
                }
            }
        }
        return res;
    }
}

Measured memory_bytes: 40808
#include<iostream>
#define size(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
int main(void){
    int a,b,c,d;
    cin >> a >> b >> c;
    d = a * 100 + b * 10 + c;
    if(d % 4 == 0){
        cout << "YES";
    }else{
        cout << "NO";
    }
}

Measured memory_bytes: 256
from math import sqrt, pi, cos, sin
a,b,h,m = map(int, input().split())

thetah = (h+(m/60))/12*2*pi
thetam = m/60*2*pi

theta = thetah - thetam
mx, my = a, 0
hx, hy = b*cos(theta), b*sin(theta)
ans = sqrt((mx-hx)**2+(my-hy)**2)
print(ans)


Measured memory_bytes: 9396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}
 
const int N=50+10;
 
struct edge { int v,nxt; } e[N];
int head[N];
void addEdge(int u,int v) {
    static int cnt=0;
    e[++cnt]=(edge){v,head[u]},head[u]=cnt;
}
 
int n,X,d;
struct node { ll v; int w,id; } a[N];
int operator <(node a,node b) { return a.w*b.v>b.w*a.v; }
ll dp[N*N*N];
 
void dfs(int u) {
    a[u].w=1,a[u].id=u;
    for (int i=head[u];i;i=e[i].nxt)
        dfs(e[i].v),a[u].v+=a[e[i].v].v,a[u].w+=a[e[i].v].w;
}
 
int main() {
    n=read(),X=read(),d=read();
    a[1].v=read();
    for (int i=2;i<=n;++i)
        a[i].v=read(),addEdge(read(),i);
    dfs(1); int mx=n*n*n,L=min(n,d);
    memset(dp,0x3f,sizeof(dp)),dp[0]=0;
    for (int i=1;i<=n;++i) {
        int x=L;
        for (int j=0;1<<j<=x;++j) {
            int w=a[i].w*(1<<j); ll v=a[i].v*(1<<j);
            for (int k=mx;k>=w;--k) dp[k]=min(dp[k],dp[k-w]+v);
            x-=1<<j;
        }
        if (x) {
            int w=a[i].w*x; ll v=a[i].v*x;
            for (int j=mx;j>=w;--j) dp[j]=min(dp[j],dp[j-w]+v);
        }
    }
    sort(a+1,a+n+1);
    while (a[n].id!=1) --n;
    ll ans=0;
    for (int i=0;i<=mx;++i) {
        if (dp[i]>X) continue;
        ll w=i,v=dp[i];
        for (int j=1;j<n;++j) {
            ll c=min((ll)d-L,(X-v)/a[j].v);
            w+=c*a[j].w,v+=c*a[j].v;
        }
        ll c=(X-v)/a[n].v;
        w+=c*a[n].w,v+=c*a[n].v;
        ans=max(ans,w);
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 5412
import java.util.Scanner;

public class Main {

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

		String S = sc.next();   ///標準入力
		int [] a = new int[26];
		for (char c: S.toCharArray()) {
			a[c-97] += 1;
		}
		String ans = "None";
		for (int i = 0; i < 26; i++) {
			if (a[i] == 0) {
				ans = Character.toString((char) (i+97));
				break;
			}
		}
		System.out.println( ans );
	}
}

Measured memory_bytes: 25808
# ウィンドウをスライドさせる際に，期待値の全体を再計算するのをやめた
N,K = map(int, input().split())
P = [int(i) for i in input().split()]
 
expect = (sum(P[0:K])+K)/2
ma = expect
for i in range(K,N):
  expect += (P[i]-P[i-K])/2
  if ma < expect:
    ma = expect
print(ma)

Measured memory_bytes: 25188
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,MAX=100,S=0;cin>>N;int s[N];
  for(int i=0;i<N;i++){
    cin>>s[i];S+=s[i];
    if(s[i]%10!=0)MAX=min(MAX,s[i]);
  }
  if(S%10!=0)cout<<S<<endl;
  else if(MAX!=100)cout<<S-MAX<<endl;
  else cout<<"0"<<endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N, M, Q := sc.NextInt(), sc.NextInt(), sc.NextInt()

	A := make([][]int, N+1)
	for i := 0; i < len(A); i++ {
		A[i] = make([]int, len(A))
	}
	for i := 0; i < M; i++ {
		L, R := sc.NextInt(), sc.NextInt()
		A[L][R]++
	}

	for i := 1; i < len(A); i++ {
		for j := 1; j < len(A); j++ {
			A[i][j] += A[i][j-1]
		}
	}

	for i := 0; i < Q; i++ {
		p, q := sc.NextInt(), sc.NextInt()

		ans := 0
		for j := p; j <= q; j++ {
			ans += A[j][q]
		}
		fmt.Println(ans)
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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


int main(){
  int d; cin >> d;
  
  string s = "Christmas";
  
  if( d <= 24){ s += " Eve";}
  if( d <= 23){ s += " Eve";}
  if( d <= 22){ s += " Eve";}
  
  cout << s << endl;
  
  return 0;
} 

Measured memory_bytes: 256
/**
 *  author:   TakeruOkuyama
 *  created:  2020-04-15 11:17:28
**/
#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>;

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
    int N, T, A;
    cin >> N >> T >> A;
    vector<int> H(N);
    vector<double> X(N);
    double min = INF;
    int min_num;
    rep(i, N){
        cin >> H[i];
        X[i] = T - H[i] * 0.006;
        if(abs(A - X[i]) < min){
            min = abs(A - X[i]);
            min_num = i;
        }
    }
    cout << min_num + 1 << endl;
    
return 0;
}
/**
 * g++ code.cpp
 * ./a.out
 * shift + ctrl + i
**/ 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
#include <numeric>
using namespace std;

#define INF 1e18
#define int long long

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

    string week[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    for(int i = 0; i < 7; i++) {
        if(week[i] == s) {
            cout << 7 -i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()
P = {'r':P, 's':R, 'p':S}
score = [-1 for _ in range(N)]

for i,t in enumerate(T):
	if i < K:
		score[i] = P[t]
	else:
		if t == T[i-K] and score[i-K] != 0:
			score[i] = 0
		else:
			score[i] = P[t]
			
print(sum(score))

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
#define PB push_back
#define MP make_pair
const int maxn = 200009;
const int MOD = 1e9 + 7;
int64_t X[1<<15][15],Y[1<<15][15];
int64_t AX[15],AY[15],AP[15],ans[16];
int main(){
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int n;cin>>n;
  for(int i=0;i<n;++i)cin>>AX[i]>>AY[i]>>AP[i];
  for(int i=0;i<(1<<n);++i){
    for(int j=0;j<n;++j){
      X[i][j]=abs(AX[j]);
      for(int k=0;k<n;++k)if(i>>k&1)X[i][j]=min(X[i][j],abs(AX[k]-AX[j]));
      Y[i][j]=abs(AY[j]);
      for(int k=0;k<n;++k)if(i>>k&1)Y[i][j]=min(Y[i][j],abs(AY[k]-AY[j]));
    }
  }
  for(int i=0;i<=n;++i)ans[i]=1e18;
  for(int i=0;i<(1<<n);++i){
    int c=__builtin_popcount(i);
    for(int j=i;;j=(j-1)&i){
      int64_t tmp=0;
      for(int a=0;a<n;++a){
        tmp+=min(X[j][a],Y[j^i][a])*AP[a];
      }
      ans[c]=min(ans[c],tmp);
      if(j==0)break;
    }
  }
  for(int i=0;i<=n;++i)cout<<ans[i]<<'\n';
  
  return 0;
}
//2020.07.25 21:54:09


Measured memory_bytes: 11332
#1
s=input()
lists=[0,0,0]
for i in range(len(s)):
    if s[i]=="a":
        lists[0]+=1
    elif s[i]=="b":
        lists[1]+=1
    elif s[i]=="c":
        lists[2]+=1
length=len(s)//3
if min(lists[0],lists[1],lists[2])>=length  and max(lists[0],lists[1],lists[2])<=length+1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include<cstdio>
#include<algorithm>
using namespace std;
int S1[4010][4010], S2[4010][4010], K, n, res;
int Get1(int x, int y) {
	return S1[x + K][y + K] - S1[x][y + K] - S1[x + K][y] + S1[x][y];
}
int Get2(int x, int y) {
	return S2[x + K][y + K] - S2[x][y + K] - S2[x + K][y] + S2[x][y];
}
int main() {
	int i, j, x, y;
	char p[3];
	scanf("%d%d", &n,&K);
	for (i = 0; i < n; i++) {
		scanf("%d%d%s", &x, &y, p);
		if (p[0] == 'W')S1[x % (2 * K)][y % (2 * K)]++;
		else S2[x % (2 * K)][y % (2 * K)]++;
	}
	for (i = 0; i <= 4 * K; i++)for (j = 0; j <= 4 * K; j++) {
		S1[i][j] = S1[i % (2 * K)][j % (2 * K)];
		S2[i][j] = S2[i % (2 * K)][j % (2 * K)];
	}
	for (i = 1; i <= 4 * K; i++)for (j = 1; j <= 4 * K; j++)S1[i][j] += S1[i - 1][j] + S1[i][j - 1] - S1[i - 1][j - 1], S2[i][j] += S2[i - 1][j] + S2[i][j - 1] - S2[i - 1][j - 1];
	for (i = 0; i < 2 * K; i++) {
		for (j = 0; j < 2 * K; j++) {
			int t = Get1(i, j) + Get1(i + K, j + K) + Get2(i,j+K) + Get2(i+K,j);
			res = max(res, t);
		}
	}
	printf("%d\n", res);
}

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

using namespace std;

int const maxn = 1010;
int const mod = 1e9l + 7;    

char v[maxn][maxn];
int dp[maxn][maxn];

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

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> v[i][j];
        }
    }

    dp[n-1][m-1] = 1;
    for (int i = n-1; i >= 0; i--) {
        for (int j = m-1; j >= 0; j--) {
            if (i + 1 < n and v[i+1][j] != '#') {
                dp[i][j] = dp[i+1][j];
            }
            if (j + 1 < m and v[i][j+1] != '#') {
                dp[i][j] += dp[i][j+1];
            }
            if (dp[i][j] >= mod) {
                dp[i][j] -= mod;
            }
        }
    }

    cout << dp[0][0] << "\n";
}

Measured memory_bytes: 5248
/*
ID: jerrywcy
LINK: https://atcoder.jp/contests/abc127/tasks/abc127_e
LANG: C++
STATUS:
*/
#include <bits/stdc++.h>

#define int long long
#define init(array,x) memset(array,x,sizeof(array))

using namespace std;

const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxnm=2e5+10;

int n,m,k;
int fac[maxnm],inv_fac[maxnm];
int ans;

int p(int x,int y){
	long long ret=1,mul=x;
	while (y){
		if (y&1)ret=(ret*mul)%mod;
		mul=(mul*mul)%mod;
		y>>=1;
	}
	return ret;
}

void pre(){
	fac[0]=1;
	for (int i=1;i<=n*m;i++)fac[i]=(fac[i-1]*i)%mod;
	inv_fac[n*m]=p(fac[n*m],mod-2);
	for (int i=n*m-1;i>=0;i--)inv_fac[i]=(inv_fac[i+1]*(i+1))%mod;
	return ;
}

int C(int x,int y){
	if (y==0 || y==x)return 1;
//	cout<<fac[x]<<' '<<inv_fac[y]<<' '<<inv_fac[x-y]<<endl;
	return ((inv_fac[y]*inv_fac[x-y])%mod*fac[x])%mod;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m>>k;
	pre();
//	for (int i=1;i<n;i++){
//		long long tmp=1ll*i*(i+1)/2%mod;
//		tmp=tmp*m*m%mod;
//		ans=(ans+tmp)%mod;
//	}
//	for (int i=1;i<m;i++){
//		long long tmp=1ll*i*(i+1)/2%mod;
//		tmp=tmp*n*n%mod;
//		ans=(ans+tmp)%mod;
//	}
//	cout<<p(m,2*n-2)<<' '<<p(n,2*m-2)<<endl;
	long long ans=((m*m%mod)*(((n-1)*n*(2*n-1)/6%mod+n*(n-1)/2%mod)%mod)%mod)*(500000004)%mod+
	              ((n*n%mod)*(((m-1)*m*(2*m-1)/6%mod+m*(m-1)/2%mod)%mod)%mod)*(500000004)%mod;
//	cout<<ans<<endl;
//	cout<<C(n*m-2,k-2)<<endl;
	ans=(ans*C(n*m-2,k-2))%mod;

	cout<<ans<<endl;

	return 0;
}


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

typedef long long ll;

ll a[100050], b[100050];
map<ll, ll> dp;

int main() {
	/* freopen("input.in", "r", stdin);
	freopen("output.o", "w", stdout); */
	ll N, K;
	scanf("%lld %lld", &N, &K);
	for (ll i = 1; i <= N; i++) {
		scanf("%lld %lld", &a[i], &b[i]);
		dp[a[i]] += b[i];
	}
	ll idx = 1;	
	ll cur = 0;
	for (map<ll, ll>::iterator it = dp.begin(); it != dp.end(); it++) {
		cur += it->second;
		if (cur >= K) {
			printf("%lld", it->first);
			return 0;
		}
	}
}

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

using namespace std;

int main(){
  int A, B;
  string S;
  cin >> A >> B >> S;
  bool ans = true;
  for(int i=0;i<A+B+1;++i){
    if(i < A){
      if(S[i]=='-'){
        ans = false;
        break;
      }
    }else if(i==A){
      if(S[i]!='-'){
        ans = false;
        break;
      }
    }else{
      if(S[i]=='-'){
        ans = false;
        break;
      }
    }
  }
  
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<List<Integer>> sw = new ArrayList<>();
        for (int i = 0; i < m; ++i) sw.add(new ArrayList<>());

        for (int i = 0; i < m; ++i) {
            int k = sc.nextInt();
            for (int j = 0; j < k; ++j) {
                sw.get(i).add(sc.nextInt() - 1);
            }
        }

        int[] p = new int[m];
        for (int i = 0; i < m; ++i) p[i] = sc.nextInt();

        int res = 0;
        for (int bit = 0; bit < (1<<n); ++bit) {
            boolean flag = true;
            for (int i = 0; i < m; ++i) {
                int cnt = 0;
                for (Integer id : sw.get(i)) {
                    if ((bit & (1<<id)) != 0) ++cnt;
                }
                if (cnt % 2 != p[i]) flag = false;
            }
            if (flag) ++res;
        }

        System.out.println(res);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <numeric>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll X, ll Y) {
  ll ans{};
  if(X%Y==0) {
    ans = -1;
  } else {
    ans = X;
  }
  
  cout << ans << endl;
}

int main() {
  ll X;
  cin >> X;
  ll Y;
  cin >> Y;
  solve(X, Y);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll u[10];
vector<ll>x,y;

int main()
{

    ll n,m,i,j,k,p,q,o,l,s,t;
    for(i=0;i<10;i++)
    {
        x.push_back(i+1);
        y.push_back(i+1);
    }
    u[0]=1;
    for(i=1,k=1;i<=8;i++)
    {
        k*=i;
        u[i]=k;
    }
   cin>>n;
   k=0;
  for(i=1;i<=n;i++)
  {
      cin>>o;
      for(j=0;j<10;j++)
      {
          if(x[j]==o){p=j+1;x.erase(x.begin()+j);break;}
      }
      k+=(p)*u[n-i];

  }
  l=0;
   for(i=1;i<=n;i++)
  {
            cin>>o;
      for(j=0;j<10;j++)
      {
          if(y[j]==o){p=j+1;y.erase(y.begin()+j);break;}
      }
      l+=(p)*u[n-i];

  }
  cout<<abs(k-l)<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	char table[8][9];

	for(int i=0; i < 8; i++){
		scanf("%s",table[i]);
	}

	printf("90\n");

	for(int i = 0; i <= 7; i++){
		for(int k=7; k>= 0; k--){
			printf("%c",table[k][i]);
		}
		printf("\n");
	}

	printf("180\n");

	for(int i=7; i >=0; i--){
		for(int k=7; k>=0;k--){
			printf("%c",table[i][k]);
		}
		printf("\n");
	}

	printf("270\n");

	for(int i=7; i >= 0; i--){
		for(int k=0; k <= 7; k++){
			printf("%c",table[k][i]);
		}
		printf("\n");
	}


    return 0;
}

Measured memory_bytes: 2536
n = int(input())
l = []
m1, m2 = 0, 0

for i in range(n):
    a = int(input())
    l.append(a)
    if a >= m1:
        m1, m2 = a, m1
    elif a >= m2:
        m2 = a


for e in l:
    if e != m1:
        print(m1)
    else:
        print(m2)

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

int main() {
  int n; cin >> n;
  vector<int> js(n);
  for (int i = 0; i < n; i++) cin >> js[i];
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int c; cin >> c;
    if (js[i] - c > 0) ans += js[i] - c;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint h(n);
  rep(i,n){
    cin>>h[i];
  }
  int min=INF;
  for(int i=n-1;i>=0;i--){
    chmin(min,h[i]);
    if(min<h[i]-1){
      cout<<"No"<<'\n';
      return(0);
    }
  }
  cout<<"Yes"<<'\n';
  return(0);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  double x=0;
  
  double A[n];
  for(int i=0;i<n;i++){
    cin >> A[i];
  }
  
  
  
  for(int i=0;i<n-1;i++){
    sort(A,A+n);
    A[0] = (A[0]+A[1])/2;
    A[1] = 10000;
  }
  
    
  
  
  cout << A[0] <<endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 2e5 + 7;
int n, L, pref[N], post[N], a[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> L >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) pref[i + 1] = pref[i] + 2 * a[i];
    for (int i = n - 1; i >= 0; --i) post[i] = post[i + 1] + 2 * (L - a[i]);
    int ans = 0;
    //first left
    for (int i = 0; i < n; ++i) {
        int hl = i + 1;
        int hr = n - i - 1;
        int l = min(hl, hr + 1), r = min(hr, hl);
        if (l >= r) {
            ans = max(ans, pref[i + 1] - pref[i + 1 - l] + post[i + 1] - post[i + 1 + r] - a[i]);
        }
        else {
            ans = max(ans, pref[i + 1] - pref[i + 1 - l] + post[i + 1] - post[i + 1 + r] - (L - a[i + 1]));
        }   
    }   
    //first right
    for (int i = 0; i < n; ++i) {
        int hl = i + 1;
        int hr = n - i - 1;
        int l = min(hl, hr), r = min(hr, hl + 1);
        if (r >= l) {
            ans = max(ans, pref[i + 1] - pref[i + 1 - l] + post[i + 1] - post[i + 1 + r] - (L - a[i + 1]));
        }
        else {
            ans = max(ans, pref[i + 1] - pref[i + 1 - l] + post[i + 1] - post[i + 1 + r] - a[i]);
        }   
    }   
    cout << ans << '\n';
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int k;
  cin >> k;
  ll sum = 0;
  for (int a = 1; a <= k; ++a)
  {
    for (int b = 1; b <= k;++b)
    {
      for (int c = 1; c <= k;++c)
      {
        sum += gcd(a, gcd(b, c));
      }
    }
  }
  cout << sum << endl;

  return 0;
}


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

using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1){
            res = res*x%mod;
        }
        x = x*x%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}

void pre(){
   
}


void solve(){

    ll n;
    cin >> n;
    ll d = n%10;
    if(d==3){
        cout << "bon";
    }
    else if( d==0 or d==1 or d==6 or d==8 ){
        cout << "pon";
    }
    else cout << "hon";
    
}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;   
    //cin>>T;
    ll tt=1;
    while(T--){
        //cout << "Case #" << tt << ": ";
        tt++;
        solve();
    }
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>

int main(void){
    char c,S[300010];
    int i,N;
    scanf("%d",&N);
    for(i = 1;i <= N;i++){
        scanf("%c",&c);
        if(c == 'W'||c == 'E'){
            S[i] = c;
            }else{
            i--;
            }
        }

    int Reader = 1;
    int countb = 0;
    for(i = 1;i < Reader;i++){
        if(S[i] == 'W') countb++;
    }
    
    for(i = N;Reader < i;i--){
        if(S[i] == 'E') countb++;
    }

    int ans = countb;
    for(i = 2;i <= N;i++){
        if(S[i] == 'E') countb--;
        if(S[i - 1] == 'W') countb++;

        if(countb <= ans) ans = countb; 
    }

    printf("%d",ans);

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
int a[200100];
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	while (cin >> n)
	{		
		int count = 0;

		for (int i = 0;i < n;i++)
			cin >> a[i];
		sort(a, a + n);
		count = a[n / 2] - a[n / 2 - 1];
		cout << count << '\n';
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int64_t n, m, a[102], s, cnt;
int main() {
    DAU
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        s += a[i];
    }
    for (int i = 1; i <= n; ++i)
        cnt += (a[i] * 4LL * m >= s);
    if (cnt >= m)
        cout << "Yes";
    else cout << "No";
    PLEC
}


Measured memory_bytes: 256