akhauriyash/Code-Regression huggingface dataset:
# def rleify(s: str) -> List[Tuple[str, int]]:
def rleify(s):
    if not len(s):
        return []
    i = 0
    rle = []
    for j in range(len(s) + 1):
        if j == len(s) or s[i] != s[j]:
            rle.append((s[i], j - i))
            i = j
    return rle


s = input()
X, Y = map(int, input().split())
rle = rleify(s)
if rle[0][0] == "F":
    X -= rle[0][1]
    rle = rle[1:]
S = []
P = []
iss = True
for c, n in rle:
    if c == "T":
        if n % 2 == 1:
            iss = not iss
    else:
        if iss:
            S.append(n)
        else:
            P.append(n)

cand = {0}
for n in S:
    ncand = set()
    for c in cand:
        ncand.add(c - n)
        ncand.add(c + n)
    cand = ncand
if X not in cand:
    print("No")
    exit()

cand = {0}
for n in P:
    ncand = set()
    for c in cand:
        ncand.add(c - n)
        ncand.add(c + n)
    cand = ncand
if Y not in cand:
    print("No")
    exit()
print("Yes")


Measured memory_bytes: 48604
#include <iostream>
using namespace std;
long sum=0;
void merge(int A[],int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    int L[n1+1],R[n2+1];
    for(int i=0;i<n1;i++){
        L[i]=A[left+i];
    }
    for(int i=0;i<n2;i++){
        R[i]=A[mid+i];
    }
    L[n1]=10000000000;
    R[n2]=10000000000;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        if(L[i]<=R[j]){
            A[k]=L[i];
            i++;
        }
        else{
            A[k]=R[j];
            j++;
            sum=sum+(n1-i);
        }
    }
}

void mergesort(int A[],int left,int right){
    if(left+1<right){
        int mid=(left+right)/2;
        mergesort(A,left,mid);
        mergesort(A,mid,right);
        merge(A,left,mid,right);
    }
}
int main(){
    int n;
    cin>>n;
    int A[n];
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    mergesort(A,0,n);
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 4656
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    K = ii()
    q = [1, 2, 3, 4, 5, 6, 7, 8, 9]

    for k in range(0, K):
        x = q[k]
        mod = x % 10
        if mod != 0:
            q.append(10 * x + mod - 1)
        q.append(10 * x + mod)
        if mod != 9:
            q.append(10 * x + mod + 1)

    print(q[K-1])


if __name__ == '__main__':
    main()


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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define INF bit(60)
#define pb push_back
#define mod 1000000007

using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

#define FACSIZE 200002

ll invfac[FACSIZE];
ll fac[FACSIZE];

template <class T>
bool chmax(T &, const T &);
template <class T>
bool chmin(T &, const T &);
ll gcd(ll, ll);
ll powLL(ll x, ll y);

ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
ll comb(ll, ll);
void make_fact(ll);
void make_invfact(ll);
void fact_init();

int main(void)
{
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> city(n + 1, vector<ll>());

  rep(i, m)
  {

    ll a, b;
    cin >> a >> b;
    city[a].push_back(b);
    city[b].push_back(a);
  }

  rep1(i, n)
  {
    cout << city[i].size() << endl;
  }

  return 0;
}

ll mod_pow(ll x, ll r)
{
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % mod;
  else if (r % 2 == 0)
  {
    ll t = mod_pow(x, r / 2) % mod;
    return mod_mul(t, t);
  }
  else
  {
    ll t = mod_pow(x, r / 2) % mod;
    ll k = mod_mul(t, t);
    return (k % mod) * (x % mod);
  }
}
ll mod_add(ll a, ll b)
{
  return ((a % mod) + (b % mod)) % mod;
}

ll mod_mul(ll a, ll b)
{
  return ((a % mod) * (b % mod)) % mod;
}

ll mod_div(ll a, ll b)
{
  return mod_mul(a, mod_pow(b, mod - 2));
}

void fact_init()
{
  make_fact(FACSIZE - 1);
  make_invfact(FACSIZE);
}

void make_fact(ll n)
{
  fac[0] = 1;
  rep(i, n)
  {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}

void make_invfact(ll n)
{
  invfac[n] = mod_pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
  {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}

ll comb(ll n, ll r)
{

  return mod_mul(mod_mul(fac[n], invfac[r]), invfac[n - r]);
}
template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return 1;
  }
  return 0;
}

ll qp(ll a, ll b)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * mod_mul(ans, a) % mod;
    a = 1LL * mod_mul(a, a) % mod;
  } while (b >>= 1LL);
  return ans;
}
ll qp(ll a, ll b, ll mo)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * (ans % mo) * (a % mo);
    a = 1LL * (a % mo) * (a % mo);
  } while (b >>= 1LL);
  return ans;
}
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
ll powLL(ll x, ll y)
{
  ll ans = 1LL;
  for (ll i = 0LL; i < y; i++)
    ans *= x;
  return ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;

#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795


typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector< pii >   vpii;

int tc;

#define MAXV 100500
#define INF  2000000000
ll f[MAXV];

int n, v, w, W;

int main() {
    scanf("%i%i", &n, &W);
    fill(f + 1, f + MAXV, INF);

    for(int i = 0; i < n; ++i) {
        scanf("%i%i", &w, &v);
        for(int j = MAXV - 1; j >= v; --j)
            if (f[j] > f[j - v] + w) f[j] = f[j - v] + w;
    }

    for(int j = MAXV - 1; j >= 0; --j)
        if (f[j] <= W) {
            printf("%i\n", j);
            break;
        }


    return 0;
}

Measured memory_bytes: 1152
function tenchi(x)
    h=length(x)
    w=length(x[1])
    k=[[x[j][i]for j=1:h] for i=1:w]
    return k
end
function hantei(x)
  return unique(x)!=['.']
end
function main()
  h,w=parse.(split(readline()))
  a=[[j for j=chomp(readline())] for i=1:h]
  a=[i for i in a if hantei(i)]
  a=tenchi(a)
  a=[i for i in a if hantei(i)]
  a=tenchi(a)
  for i in a
    for j in i
      print(j)
    end
  println()
  end
end
main()

Measured memory_bytes: 188152
#include<bits/stdc++.h>
using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
#define PI 3.141592653589793
struct node{
    list <int> to;
};
int BPS(int i ,node a[],bool b[]){
  queue<int> q1;
  q1.push(1);
  if(b[i]){//巡回済み

  }else{
    b[i]=true;
    for(int aa: a[i].to){
      if(b[aa])
        BPS(aa,a,b);
    }
  }

}
  int main()
{
  node a[100010];
  bool b[200000]{};
  int c[200000]{};
  a[0].to.push_back(0);
  int A,B,N,M;
  cin>>N>>M;

  for(int i=0;i<M;i++){
    cin>>A>>B;
    a[A].to.push_back(B);
    a[B].to.push_back(A);
  }
  queue<int> q1;
  int count=0;
  q1.push(1);
  b[1]=true;
  while(!q1.empty()){
    for(int num:a[q1.front()].to){
      if(!b[num]){
        b[num]=true;
        q1.push(num);
        c[num]=q1.front();
        count++;
      }
    }
    q1.pop();
  }
  if(count>=N-1){
    cout<<"Yes\n";
  }else{
    cout<<"No\n";
  }
  for(int i=2;i<N+1;i++){
    cout<<c[i]<<"\n";
  }
  return 0;
}


Measured memory_bytes: 19368
N,Q=map(int,input().split())
S=input()
L=[0 for i in range(N)]
tmp=0
for i in range(1,N):
    if S[i]=="C" and S[i-1]=="A":
        tmp+=1
    L[i]=tmp
for i in range(Q):
    l,r=map(int,input().split())
    l-=1;r-=1
    print(L[r]-L[l])

Measured memory_bytes: 6232
#include <bits/stdc++.h>
using namespace std;
 int sa(string s){
    int n0=0,n1=0;
    for(int i=0; i<s.size();i++){
        if(s[i]=='1') n1++;
        if(s[i]=='0') n0++;
    }
    return abs(n1-n0);
}
int main(void){
    int i;
    string s;
    cin>>s;
    cout << s.size()-sa(s)<<endl;
}

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

using namespace std;

#define pb push_back
const int maxi = 1e6+10;
int a[110][110], b[110][110];
string s;
int n, m;
vector<int> v[maxi];
set<pair<int,int>> st;
int c[110][110];
int cnt[110][110];

int calc(int x)
{
    int val = x/m;
    if (x%m!=0) val++;
    return val;
}
int main()
{
    cin>>n>>m;

    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
            scanf("%d",&a[i][j]);
            b[i][j] = a[i][j];
        }

     for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
     {
           int val = calc(b[i][j]);
           cnt[j][val]++;
     }


    int nula = 0;
    while(true)
    {
        for (int i=1;i<=n;i++)
        {
            for (int j=1;j<=m;j++)
                for (int k=j+1;k<=m;k++)
                if (cnt[j][calc(b[i][j])]>1 && cnt[k][calc(b[i][j])]==0)
                {
                   // cout<<"USAO :"<<i<<" "<<j<<" "<<k<<endl;
                    cnt[j][calc(b[i][j])]--;
                    cnt[k][calc(b[i][k])]--;
                    cnt[j][calc(b[i][k])]++;
                    cnt[k][calc(b[i][j])]++;
                    swap(b[i][j], b[i][k]);
                    nula++;

                }
        }

        if (!nula) break;
        nula = 0;
    }

    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
    {
        int val = calc(b[i][j]);
        c[val][j] = b[i][j];
    }

    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
            printf("%d ",b[i][j]);
        printf("\n");
    }


    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
            printf("%d ",c[i][j]);
        printf("\n");
    }

    return 0;
}


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

int h,A1[500001];

int left(int i){ return i*2;}
int right(int i) { return i*2+1;}

void maxHeapify(int i){
    int largest;
    int l = left(i);
    int r = right(i);
    if(l<=h && A1[l]>A1[i])
        largest = l;
    else
        largest = i;
    if(r<=h && A1[r]>A1[largest])
        largest = r;
    
    if(largest!=i){
        int tmp = A1[i];
        A1[i] = A1[largest];
        A1[largest] = tmp;
        maxHeapify(largest);
    }
}

int main(){
    cin >> h;
    
    for(int i=1; i<=h; i++){
        cin >> A1[i];
    }
    for(int i=h/2; i>=1; i--){
        maxHeapify(i);
    }
    
    for(int i=1; i<=h; i++){
        cout << " " << A1[i];
    }
    cout << endl;
}

Measured memory_bytes: 5028
import sys
INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())
sys.setrecursionlimit(10 ** 9)


def main():
    A, B = MAP()

    cnt = 0
    while 1:
        if cnt*(A-1) + 1 >= B:
            print(cnt)
            break
        cnt += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 40516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<vector<double>> vvd;
typedef vector<double> vd;

#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_LOG = 21;
const int MAX_N = 12800;

#define forn(i, n) for(int i = 0; i < n; i++)
#define forsn(i, s, n) for(int i = s; i < n; i++)
#define all(x) x.begin(), x.end()

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	char ch;
	cin >> ch;
	cout << char(int(ch) + 1) << endl;
}		


Measured memory_bytes: 256
from itertools import combinations as comb

N = int(input())

S = list("MARCH")
A = {}
for i in range(N):
    s = input()[0:1]
    if(s not in S):
        continue

    A[s] = A.get(s, 0) + 1

if(len(A) < 3):
    print(0)
else:
    ans = 0
    c = list(comb(list(A.values()), 3))
    for a1, a2, a3 in c:
        ans += a1 * a2 * a3
    # print(c)
    print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main{
	static int [][]map = new int[9][9];
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = 1;
		while(c<=n){
			System.out.println("Data " + c++ + ":");

			
			for(int i=1; i<=8; i++){
				String s = sc.next();
				for(int k=1; k<=s.length(); k++)
					map[i][k] = Integer.parseInt(s.substring(k-1, k));
			}
			int x = sc.nextInt();
			int y = sc.nextInt();
			solve(y, x);
			ans();
		}
	}
	

	static void solve(int y, int x){
		map[y][x] = 0;
		for(int a=x-3; a<=x+3; a++)
			if(a>=1 && a<=8 && map[y][a]==1)
				solve(y, a);
		for(int b=y-3; b<=y+3; b++)
			if(b>=1 && b<=8 && map[b][x]==1)
				solve(b, x);
	}

	static void ans(){
		for(int i=1; i<=8; i++){
			for(int k=1; k<=8; k++)
				System.out.print(map[i][k]);
			System.out.println();
		}
	}
}

Measured memory_bytes: 26484
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	if (ci - cn + 16 > cm) {
		int A = getcha() - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
		return A;
	}
	else {
		int A = *ci++ - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
		return A;
	}
}

int to[200001], ne[200001], he[100001];
bool d[100001], D[100001];
void dfs(int A, int prev, bool B) {
	D[A] = B;
	for (int i = he[A]; i; i = ne[i]) {
		if (prev != to[i]) dfs(to[i], A, B ^ d[i >> 1]);
	}
}

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


	int N = getint();
	int k = 2;
	rep1(i, N - 1) {
		int x = getint();
		int y = getint();
		bool z = getint() & 1;
		to[k] = y;
		ne[k] = he[x];
		he[x] = k++;
		to[k] = x;
		ne[k] = he[y];
		he[y] = k++;
		d[i] = z;
	}

	dfs(1, 0, 0);
	const int dm = 1 << 18;
	char dn[dm], * di = dn;
	rep1(i, N) {
		*di++ = '0' + D[i];
		*di++ = '\n';
	}
	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define stoi stoll
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define INF MAX/2
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#define REP(i,n) for (int i=0; i < (n); ++i)
#define FOR(i,a,b) for (int i=(a); i < (b); ++i)
using namespace std;

int pow(int x, int n) {int res=1; while(n){if(n&1)res*=x;x*=x;n>>=1;} return res;}
int get_gcd(int a, int b) {while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b) {return a * b / get_gcd(a, b);}
bool chmin(int &a, int b) {if(a>b){a=b; return true;} else return false;}
bool chmax(int &a, int b) {if(a<b){a=b; return true;} else return false;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//-------------------------テンプレここまで-------------------------//

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

  int N;
  cin >> N;
  static int h[100000];
  REP(i,N) cin >> h[i];

  // dp[i] ... 足場i番目(0-index)にいるときの最小コスト
  static int dp[100000];
  REP(i,N) dp[i] = INF;
  dp[0] = 0;

  // 配るdp
  REP(i,N-1) {
    // 1つ飛ぶとき
    chmin(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
    // 2つ飛ぶとき
    if (i+2 < N) chmin(dp[i+2], dp[i]+abs(h[i+2]-h[i]));
  }

  cout << dp[N-1] << endl;

  return 0;
}


Measured memory_bytes: 1792
module Main where

import Control.Applicative
import Text.Printf
import Numeric

main :: IO ()
main = loop

loop :: IO ()
loop = do
   { [h, w] <- getInts
   ; if h == 0 && w == 0 then return ()
     else do
       { let oneline = replicate w '#'
       ; let rect    = replicate h oneline
       ; putStr $ unlines rect 
       ; putStrLn ""
       ; loop
       }
    }  

--

getInts :: IO [Int]
getInts = map read . words <$>getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$>getLine


putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble x = showFFloat Nothing x ""

readInt :: String -> Int 
readInt = read 

getStrings :: IO [String]
getStrings = words <$> getLine


Measured memory_bytes: 4232
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int A, B, C, K;
    int cnt;
    string res;
    cin >> A >> B >> C;
    cin >> K;
    
    while(A >= B){
        B *= 2;
        cnt++;
    }
    
    while(B >= C){
        C *= 2;
        cnt++;
    }
    
    if(cnt <= K){
        res = "Yes";
    }else{
        res = "No";
    }
    
    cout << res;
    return 0;
}


Measured memory_bytes: 3528
#include <iostream>
using namespace std;
int main(void){

    int a ,b ,c = 0;
    cin >> a >> b;
    
    c = (a * b) % 2;
    
    if(c == 1){
        cout << "Odd";
    }
    
    else{
        cout << "Even";
    }
    
}


Measured memory_bytes: 3568
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog
 
BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)
 
 
class Type(Enum):
    UNKOWN = 0
    OK = 1
    NOT = 2
 
class Info:
    def __init__(self,arg_a,arg_b,arg_c):
        self.work = [arg_a,arg_b,arg_c]
 
 
while True:
    A,B,C = map(int,input().split())
    if A == 0 and B == 0 and C == 0:
        break
 
    table = [Type.UNKOWN]*((A+B+C)+1)
 
    N = int(input())
    info = []
 
    for _ in range(N):
        a,b,c,result = map(int,input().split())
        if result == 1:
            table[a] = Type.OK
            table[b] = Type.OK
            table[c] = Type.OK
 
        else:
            info.append(Info(a,b,c))
 
    for i in range(len(info)):
        count = 0
        tmp = -1
        for k in range(3):
            if table[info[i].work[k]] == Type.OK:
                count += 1
            elif table[info[i].work[k]] == Type.UNKOWN:
                tmp = info[i].work[k]
        if count != 2 or tmp == -1:
            continue
        table[tmp] = Type.NOT
 
    for i in range(1,(A+B+C)+1):
        if table[i] == Type.OK:
            print("1")
        elif table[i] == Type.NOT:
            print("0")
        else:
            print("2")


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

int n, x, y, ans, k = -1;
bool f[101];
pair<int, int> R[101], B[101];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> x >> y;
		R[i] = make_pair(x, y);
	}
	rep(i, n) {
		cin >> x >> y;
		B[i] = make_pair(x, y);
	}
	sort(R, R + n);
	sort(B, B + n);
	rep(i, n) {
		rep(j, n) {
			if (B[i].first > R[j].first && B[i].second > R[j].second) {
				if (f[j] == 0) {
					if (k == -1) k = j;
					else if (R[k].second < R[j].second) k = j;
				}
			}
		}
		if (k != -1) {
			f[k] = 1;
			ans++;
		}
		k = -1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
A.sort()
from collections import Counter
A=Counter(A)
ret=0
for i in A.most_common():
  if i[0]>i[1]:
    ret+=i[1]
  else:
    ret+=i[1]-i[0]
print(ret)

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

const int N = 3e5 + 5;
typedef long long LL;

int n;
LL a, b, c, d, e, ans, k, mod = 998244353, fac[N], inv[N];

LL calc(LL a, LL b) {
	return fac[a]*inv[b]%mod*inv[a - b]%mod;
}

LL fsp(LL a, LL b) {
	LL res = 1;
	while(b) {
		if(b&1) res = res*a%mod;
		b /= 2;
		a = a*a%mod;
	}
	return res;
}

int main() {
	cin>>n>>a>>b>>k;
	c = a + b;
	fac[0] = inv[0] = 1;
	for(int i = 1; i <= n; i++) {
		fac[i] = fac[i - 1]*i%mod;
		inv[i] = fsp(fac[i], mod - 2);
	}
	for(int i = 0; i <= n && i*a <= k; i++) {
		if((k - a*i)%b != 0) continue;
		LL j = (k - a*i)/b;
		if(j > n) continue;
		ans = (ans + calc(n, i)*calc(n, j))%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8272
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 100000
using namespace std;
ll v[LIM];
int main() {
  int n;
  string s, t;
  cin >> n;
  cin >> s >> t;
  for (int i = 0; i < n; i++) {
    int tmp = i;
    int k = 0;
    while (tmp < n && s[tmp] == t[k]) {
      k++;
      tmp++;
    }
    if (tmp == n) {
      cout << n * 2 - (n - i) << endl;
      return 0;
    }
  }
  cout << n * 2 << endl;
  return 0;
}


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

struct card { char suit, value; };
void input(card* T, int num)
{
	for(int i=0;i<num;i++)
	{
		cin >> T[i].suit >> T[i].value;
	}
}
void copy(card* T1,card* T2,int num)
{
	for(int i=0;i<num;i++)
	{
		T2[i].suit = T1[i].suit;
		T2[i].value = T1[i].value;
	}
}
void output(card* T,int num)
{
	for(int i=0;i<num;i++)
	{
		cout << T[i].suit << T[i].value << (i==num-1 ? '\n' : ' ');
	}
}
void bubblesort(card* T,int num)
{
	for(int i=0;i<num;i++)
	{
		for(int j=num-1;j>i;j--)
		{
			if(T[j].value<T[j-1].value)
				swap(T[j], T[j - 1]);
		}
	}
}

void selectsort(card* T,int num)
{
	for(int i=0;i<num;i++)
	{
		int minj = i;
		for(int j=i;j<num;j++)
		{
			if (T[j].value < T[minj].value)
				minj = j;
		}
		swap(T[i], T[minj]);
	}
}

void ifstable(card T1[],card T2[],int num)
{
	for(int i=0;i<num;i++)
	{
		if(T1[i].suit!=T2[i].suit)
		{
			cout << "Not stable" << endl;
			break;
		}
		if (i == num - 1)
			cout << "Stable" << endl;
	}
}

int main()
{
	int num;
	cin >> num;
	card* T1 = new card[num];
	input(T1, num);
	card* T2 = new card[num];
	copy(T1,T2,num);
	bubblesort(T1, num);
	output(T1, num);
	cout << "Stable" << endl;
	selectsort(T2, num);
	output(T2, num);
	ifstable(T1, T2, num);
}


Measured memory_bytes: 3116
#include <algorithm>
#include <set>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()

string L;
bool input() {
    string _;
    getline(cin, _);
    if (cin.eof()) return false;
    L.clear();
    for (int i = 0; i < _.size(); i++) {
        if (isalpha(_[i])) {
            L.push_back(toupper(_[i]));
        }
    }
    return true;
}

#define ML 1024
int dp[ML][ML];

bool isPalindrome(int from, int to) {
    if (dp[from][to] >= 0) return dp[from][to];
    if (from >= to) return 1;
    if (L[from] == L[to]) {
        return dp[from][to] = isPalindrome(from + 1, to - 1);
    }
    return dp[from][to] = 0;
}

set<string> Ans;
set<string> Dup;

void AddDup(int from, int to) {
    if (to - from <= 1) return;
    Dup.insert(L.substr(from, to - from + 1));
    AddDup(from + 1, to - 1);
}

bool used[ML][ML];
void dfs(int from, int to) {
    if (to - from <= 1) return;
    if (used[from][to]) return;
    //cerr << "(" << from << ", " << to << ")" << endl;
    string X = L.substr(from, to - from + 1);
    if (isPalindrome(from, to) && !Dup.count(X)) {
        //cerr << from << " " << to << endl;
        Ans.insert(X);
        AddDup(from + 1, to - 1);
    }
    dfs(from + 1, to);
    dfs(from, to - 1);
    used[from][to] = true;
}

void solve() {
    Ans.clear();
    Dup.clear();
    memset(dp, -1, sizeof(dp));
    memset(used, 0, sizeof(used));
    dfs(0, int(L.size()) - 1);
    if (Ans.empty()) {
        cout << endl;
        return;
    }
    set<string> RealAns;
    set<string>::iterator it = Ans.begin();
    for (; it != Ans.end(); it++) {
        if (!Dup.count(*it)) RealAns.insert(*it);
    }
    it = RealAns.begin();
    cout << *it;
    for (it++; it != RealAns.end(); it++) {
        cout << " " << *it;
    }
    cout << endl;
}

int main() {
    while (input()) solve();
    return 0;
}

Measured memory_bytes: 6424
using System;
using System.Collections.Generic;
using System.Linq;
using static Constans;

public static class Constans
{
    public const long Mod = 998244353;
}

public struct ModInt
{
    public long Num;

    public ModInt(long num)
    {
        Num = num;
    }

    public override string ToString()
    {
        return Num.ToString();
    }

    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Num += r.Num;
        if (l.Num >= Mod)
        {
            l.Num -= Mod;
        }
        return l;
    }

    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Num -= r.Num;
        if (l.Num < 0)
        {
            l.Num += Mod;
        }
        return l;
    }

    public static ModInt operator *(ModInt l, ModInt r)
    {
        return new ModInt(l.Num * r.Num % Mod);
    }

    public static implicit operator ModInt(long n)
    {
        n %= Mod;
        if (n < 0)
        {
            n += Mod;
        }
        return new ModInt(n);
    }
}

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var A = vals[0];
        var B = vals[1];
        var C = vals[2];
        var D = vals[3];

        var dp = new ModInt[C + 1, D + 1, 2];
        for (int i = A; i <= C; i++)
        {
            for (int j = B; j <= D; j++)
            {
                if (i == A && j == B)
                {
                    dp[A, B, 0] = 1;
                    continue;
                }

                dp[i, j, 0] = dp[i, j - 1, 0] * i + dp[i, j - 1, 1];
                dp[i, j, 1] = (dp[i - 1, j, 0] + dp[i - 1, j, 1]) * j;
            }
        }

        var answer = dp[C, D, 0] + dp[C, D, 1];
        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 168840
#include<stdio.h>
int main(void){
  char b;
  int i;
  scanf("%s",&b);
  if(b=='A'){
    printf("T");
  }
  if(b=='T'){
    printf("A");
  }
  if(b=='C'){
    printf("G");
  }
  if(b=='G'){
    printf("C");
  }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define x first
#define y second
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'


int main()
{
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	vector<int> v(n),vv(m);
	for(auto &x:v)cin>>x;
	for(auto &x:vv)cin>>x;
	for(int z=x+1;z<=y;z++){
		bool f=1;
		for(auto x:v){
			if(x>=z){
				f=0;
				break;
			}
		}
		for(auto x:vv){
			if(x<z){
				f=0;
				break;
			}
		}
		if(f){
			printf("No War\n");
			return 0;
		}
	}
	printf("War\n");
	return 0;
}

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

int main(){

  int a,b;

  cin>>a>>b;

  if(a>=13){
	cout<<b<<endl;
  }else if(a>=6){
	cout<<b/2<<endl;
  }else{
	cout<<0<<endl;
  }
 
  
  return 0;
}


Measured memory_bytes: 256
from itertools import combinations

class unionfind:
    def __init__(self,n):
        self.par=[i for i in range(n)]
        self.rank=[1]*n

    def root(self,a):
        if self.par[a]==a : return a
        parent=self.root(self.par[a])
        self.par[a]=parent
        return parent

    def unite(self,a,b):
        ra,rb=self.root(a),self.root(b)
        if ra==rb : return
        if self.rank[ra]>self.rank[rb]:
            ra,rb=rb,ra
        self.par[rb]=ra
        self.rank[ra]+=1

    def same(self,a,b):
        return self.root(a)==self.root(b)


def main():
    n,m=map(int,input().split())
    edges=[tuple(map(int,input().split())) for _ in range(m)]

    sm=0
    for e_remove in edges:
        uf=unionfind(n)
        for e in edges:
            if e==e_remove : continue
            uf.unite(e[0]-1,e[1]-1)

        for a in combinations(range(n),2):
            if not uf.same(a[0],a[1]):
                break
        else : continue
        sm+=1

    print(sm)

main()

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

int main()
{
    int X, A, B, sum=0, tmp=0;

    cin >> X>>A>>B;

    tmp = X - A;
    sum = tmp;

    for (int i = 0; i < 10000; i++)
    {
        if(sum>=B){
            sum -= B;
        }
    }

    cout << sum << endl;
}

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

int main(){
  int i;
  double N,K;
  double p=0;
  int tmp;
  
  cin >> N >> K;
  
  for(i=1;i<=min(N,K);i++){
    tmp = ceil( log2(K/i) );
    //cout << tmp << endl;
    //p += 1/pow(2,tmp);
    p += pow(0.5,tmp);
  }
  //cout << p/N << endl;
  if(K<N) p += N-K;
  
  p /= N;
  
  cout << setprecision(12) << p << endl;
  
  return 0;
}

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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 3;

void solve() {
    cout << setprecision(10);

    long double a, b, x;
    cin >> a >> b >> x;
    long double total = a * a * b;
    long double half = total / 2.0;
    if(x >= half){
        long double ans = atan(2.0 * (a * a * b - x) / (a * a * a)) * 180.0 / M_PI;
        cout << ans  << endl;
    }
    else{
        long double tmp = atan(2.0 * x / (a * b * b)) * 180.0 / M_PI;
        long double ans = 90.0 - tmp;
        cout << ans << endl;
    }
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n,m; cin >> n >> m;
    vvint g(n);
    rep(i,m){
        int u,v; cin >> u >> v;
        u--; v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    vint dist(n,INF);
    queue<int> que;
    que.push(0);
    dist[0]=0;
    while(!que.empty()){
        int v=que.front(); que.pop();
        for(auto nv:g[v]){
            if(dist[nv]!=INF) continue;
            dist[nv]=dist[v]+1;
            que.push(nv);
        }
    }  
    cout<<(dist[n-1]<=2?"POSSIBLE":"IMPOSSIBLE")<<endl;
}

Measured memory_bytes: 18168
#include <stdio.h>

typedef struct dice{
  int men[6];
} Dice;
  
int main(void)
{
  Dice dice, dice_memo;
  char s[101];
  int i, j;
  
  for(i = 0; i < 6; i++)
    scanf("%d", &dice.men[i]);

  for(j = 0; j < 6; j++)
    dice_memo.men[j] = dice.men[j];
  
  scanf("%s", s);

  i = 0;
  
  while(s[i]){
    switch(s[i]){
    case 'N' : dice_memo.men[0] = dice.men[1]; dice_memo.men[1] = dice.men[5]; dice_memo.men[5] = dice.men[4]; dice_memo.men[4] = dice.men[0]; break; 
    case 'E' : dice_memo.men[0] = dice.men[3]; dice_memo.men[3] = dice.men[5]; dice_memo.men[5] = dice.men[2]; dice_memo.men[2] = dice.men[0]; break;
    case 'W' : dice_memo.men[0] = dice.men[2]; dice_memo.men[2] = dice.men[5]; dice_memo.men[5] = dice.men[3]; dice_memo.men[3] = dice.men[0]; break;
    case 'S' :  dice_memo.men[0] = dice.men[4]; dice_memo.men[4] = dice.men[5]; dice_memo.men[5] = dice.men[1]; dice_memo.men[1] = dice.men[0]; break;
    }

    for(j = 0; j < 6; j++)
      dice.men[j] = dice_memo.men[j];

    i++;
  }

  printf("%d\n", dice.men[0]);
  
  return 0;
}

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

string divide[4] = {"dream","dreamer","erase","eraser"};

int main(){
  string s;
  cin >> s;
  
  reverse(s.begin(),s.end());
  for(int i = 0;i<4;i++) reverse(divide[i].begin(),divide[i].end());
  
  bool flag = true;
  for(int i = 0;i<s.size();){
    bool flag1 = false;
    for(int j = 0;j<4;j++){
      if(s.substr(i,divide[j].size())==divide[j]){
        flag1 = true;
        i += divide[j].size();
      }
    }
    if(flag1 == false){
      flag = false; 
      break;
    }
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main() {

	int n, x; cin >> n >> x;
	vector<int> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	int ans = 1;
	int prev = 0;
	for (int i = 0; i < n; i++) {
		int now = prev + l[i];
		if (now <= x) ans++;
		prev = now;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

int n,m;
int a[50],b[50];

bool graph[50][50];
bool visited[50];

void dfs(int v){
  visited[v] = true;
  for(int i = 0; i < n; i++){
    if(graph[v][i]==false) continue;
    else if(visited[i]==true) continue;
    dfs(i);
  }
}

int main(){
  cin>>n>>m;
  for(int i = 0; i < m; i++){
    cin>>a[i]>>b[i];
    a[i]--; b[i]--;
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  int ans = 0;
  for(int i = 0; i < m; i++){
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false; //ある辺について省く
    for(int j = 0; j < n; j++) visited[j] = false;
    dfs(0);
    //もし取り除いた辺が橋であれば、visited[j]==falseなる辺が存在するはず（非連結であるため）
    int flag = false;
    for(int j = 0; j < n; j++) {
      if(visited[j] == false) flag = true;
    }
    if(flag) ans++;

    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true; 
    }
    cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <limits>
using ll = long long;
constexpr int INF = std::numeric_limits<int>::max() / 2;
constexpr ll LNF = std::numeric_limits<ll>::max() / 2;

#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    ll T;
    cin >> N >> T;

    ll p   = 0;
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        ll t;
        cin >> t;
        sum += min(t - p, T);
        p = t;
    }
    sum += T;
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
matrix = []
for i in range(n):
    M = list(map(int, input().split()))
    matrix.append(M)
#print(matrix)
colum = []
for i in range(m):
    colum.append(int(input()))
#print(colum)

for i in range(n):
    sum = 0
    for j in range(m):
        sum += matrix[i][j] * colum[j]
        #print(matrix[i][j])
    print(sum)


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

 int main() {
   int N;
   cin >> N;
   vector<int> a(N + 1);
   rep(i, N) cin >> a.at(i + 1);

   int pos = 1, count = 1;
   while (pos <= N) {
     if (a.at(pos) == count) count++;
     pos++;
   }
   if (count == 1) cout << -1 << endl;
   else cout << N - count + 1 << endl;
 }


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    vector<ll> a(N); rep(i, N){cin >> a.at(i);}
    ll tmp = 0;
    rep(i, N){if (a.at(i) % 2 == 0){tmp++;}}
    if (tmp == N){
        cout << "second" << endl;
    } else {
        cout << "first" << endl;
    }
}

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


Measured memory_bytes: 3916
# include<iostream>
 using namespace std;
 int main ()
 {
 	  string s1;
 	  string s2;
 	  cin>>s1;
 	  cin>>s2;
 	  int sum =0;
 	  for(int i=0;i<3;i++)
 	  {
 	  	 if(s1[i]==s2[i])
 	  	 {
 	  	 	 sum++;
			}
	   }
	   cout<<sum<<endl;
 }

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int enum_div(int n)//nの約数を列挙
{
    int ans = 0;
	vector<int> ret;
	for(int i=1 ; i*i<n ; ++i)
	{
		if(n%i == 0)
		{
			ans += n / i - 1;
		}
	}
    return ans;
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>> N;
    int ans = 0;
    // REP(m, 1, N) {
    //     if (N % m == N / m) {
    //         cout << m << " " << N % m << " " << N / m << endl;
    //         ans += m;
    //     }
    // }
    for(int i = 1; i * i <= N; i++) {
        int m = (N - i) / i;
        if (m == 0) continue;
        if (N % m == N / m) {
            ans += m;
            //cout << m << " " << N / m << " " << N % m << endl;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::input;

#[proconio::fastout]
pub fn main() {
    const M: i64 = 1000000007;
    input! {
    n:usize,
    k:usize,
    a:[i64;n],
    }
    let mut apos: Vec<i64> = a.iter().filter(|&x| x >= &0).cloned().collect();
    let mut aneg: Vec<i64> = a.iter().filter(|&x| x <= &0).cloned().collect();
    let ans = if n == k {
        a.iter().fold(1, |pr, v| (pr * v).rem_euclid(M))
    } else if apos.len() == 0 && k % 2 == 1 {
        //必ず非正。絶対値を最小化したい
        aneg.sort_by_key(|&x| std::cmp::Reverse(x));
        aneg.iter().take(k).fold(1, |pr, v| (pr * v).rem_euclid(M))
    } else {
        //必ず非負
        apos.sort();
        let mut tmp = 1;
        if k % 2 == 1 {
            tmp *= apos.pop().unwrap();
        }
        aneg.sort_by_key(|&x| std::cmp::Reverse(x));
        if apos.len() % 2 == 1 { apos.remove(0); }
        if aneg.len() % 2 == 1 { aneg.remove(0); }
        let mut apos: Vec<i64> = apos.chunks(2).map(|c| c[0] * c[1]).collect();
        let mut aneg: Vec<i64> = aneg.chunks(2).map(|c| c[0] * c[1]).collect();
        for _ in 0..k / 2 {
            if apos.last() > aneg.last() {
                tmp *= apos.pop().unwrap().rem_euclid(M);
            } else {
                tmp *= aneg.pop().unwrap().rem_euclid(M);
            }
            tmp = tmp.rem_euclid(M);
        }
        tmp
    };
    println!("{}", ans);
}


Measured memory_bytes: 8188
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

const int mod = 1e9+7;
#define ll long long int
const double epsilon = 1e-7;

ll ma(ll x, ll y){
    if(x>y)return x;
    return y;
}
int a[100000];
int d[100000];
struct hoge
{
    int b, c;
};
struct hoge arr[100000];

int compare_inth(const void *a, const void *b){
	struct hoge *A = (struct hoge *)a;
	struct hoge *B = (struct hoge *)b;
    return (B->c) - (A->c);
}
int compare_int(const void *a, const void *b){
	int *A = (int *)a;
	int *B = (int *)b;
    return *A - *B;
}
int main(void){
    int n, m;
    scanf("%d %d", &n, &m);
    for(int i = 0;i < n;i++)scanf("%d", &a[i]);
    for(int i = 0;i < m;i++)scanf("%d %d", &arr[i].b, &arr[i].c);
    qsort(a, n, sizeof(int), compare_int);
    qsort(arr, m, sizeof(struct hoge), compare_inth);
    for(int i = 0;i < n;i++)d[i] = 0;
    int j = 0;
    for(int i = 0;i < m && j < n;i++){
        while(arr[i].b > 0 && j < n){
            d[j] = arr[i].c;
            j++;
            arr[i].b--;
        }
    }
    ll sum = 0;
    for(int i = 0;i < n;i++){
        sum += ma(a[i], d[i]);
    }
    printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 2232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define SORT(v) sort(ALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;

#define HOGE COUT("HOGE")

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
int main() {
    IN(int, n);
    string s;
    switch (n%10) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            s="hon";
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            s = "pon";
            break;
        case 3:
            s = "bon";
            break;
    }
    COUT(s);
    
}


Measured memory_bytes: 3616
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

K = int(input())

val = 7
for n in range(1000010):
    val %= K
    if val == 0:
        print(n + 1)
        sys.exit(0)
    val *= 10
    val += 7

print(-1)




Measured memory_bytes: 10752
fun solve(N:Int, M:Int) {
    if (N == M) {
        println("Yes")
    } else {
        println("No")
    }
}

fun main() {
//    val S = readLine()!!
//    val N = readLine()!!.toInt()
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
//    val A = readLine()!!.split(" ").map { it.toInt() }
    solve(N, M)
}

Measured memory_bytes: 36276
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){

  char i[3];
  char j[3];
  scanf("%s", i);
  if(i[2] == 0) {
    printf("%s\n", i);
}else{
  j[0] = i[2];
  j[1] = i[1];
  j[2] = i[0];
  i[0] = j[0];
  i[2] = j[2];


    printf("%s\n", i);
}

  return 0;
}

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

using ll = long long;

int main(int argc, char const *argv[]){
	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);

  	int n,w;
  	cin >> n >> w;

  	vector<int> weight(n),value(n);
  	for(int i=0;i<n;i++){
  		cin >> weight[i] >> value[i];
  	}
  	vector<ll> dp(w+1);
  	for(int i=0;i<n;i++){
  		for(int j=w-weight[i];j>=0;j--){
  			dp[j+weight[i]] = max(dp[j+weight[i]],dp[j]+value[i]);
  		}
  	}

  	ll res = 0;

  	for(int i=0;i<=w;i++){
  		res = max(res,dp[i]);
  	}
  	cout << res << "\n";

  	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n; cin >> n;
    ll a = 1, b = 1;
    rep(i,n){
        int x, y; cin >> x >> y;
        ll n = max((a + x - 1) / x, (b + y - 1)/ y);
        a = x * n, b = y * n;
    }
    cout << a + b << endl;
}

Measured memory_bytes: 256