akhauriyash/Code-Regression huggingface dataset:
def main():
    N, M = map(int, input().split(" "))
    prices = []
    for i in range(N):
        tmp = list(map(int, input().split(" ")))
        prices.append(tuple(tmp))
    prices.sort(key=lambda x: x[0])
    cost = 0
    for price in prices:
        if M < 0:
            break
        cost += price[0] * min(M, price[1])
        M = max(0, M - price[1])
    print(cost)


if __name__ == '__main__':
    main()

Measured memory_bytes: 18108
while true do
	deck = STDIN.gets.chomp
	break if deck.eql?('-')
	
	shuffle_count = STDIN.gets.to_i

	0.upto(shuffle_count - 1) {
		shuffle_cards_num = STDIN.gets.to_i
		deck = deck[shuffle_cards_num..deck.size-1] + deck[0..shuffle_cards_num-1]
	}
	print deck, "\n"	
end



Measured memory_bytes: 6872
#include <iostream>

int main(){
    int n;
    std::cin >> n;
    int a=n/10;
    int ans=n-a*10;
    
    if(ans==2||ans==4||ans==5||ans==7||ans==9){
        std::cout << "hon" << std::endl;
    }else if(ans==3){
        std::cout << "bon" << std::endl;
    }else{
        std::cout << "pon" << std::endl;
    }
    return 0;
}


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

using namespace std;
using ll = long long;


int C[200005] = {};

int main() {
    int N, K;
    cin >> N >> K;

    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        ++C[x];
    }

    sort(C, C + N + 1);
    int ans = 0;
    for(int i = N - K; i >= 0; --i)
    {
        if(C[i] == 0)
            break;
        ans += C[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
  char s[5];
  scanf("%s",s);
  for(int i=0;s[i]!='\0';i++){
      if(s[i]=='A'&&s[i+1]=='C') {printf("Yes");return 0;}
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

mint factorial(ll n) {
  mint answer = 1;
  while (n > 1) {
    answer *= n;
    n--;
  }
  return answer;
}

mint combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

mint permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

// setprecision(8) 桁数指定
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

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

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

ll f(ll x, ll y, ll count) {
  x /= 2;
  count += y;
  y *= 2;

  return (x > 0 ? f(x, y, count) : count);
}

int main() {
  ll h;
  cin >> h;
  ll ans = f(h, 1, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <queue>

#define INF 922337203685477580
typedef long long ll;

using namespace std;

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

  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int count = 0;
  for (int i = 0; i < N; i++) {
    int mini = i;

    for (int j = i + 1; j < N; j++) {
      if (A[j] < A[mini]) {
        mini = j;
      }
    }

    if (mini != i) {
      int t = A[i];
      A[i] = A[mini];
      A[mini] = t;
      count++;
    }
  }

  for (int i = 0; i < N; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << A[i];
  }
  cout << endl << count << endl;
  return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

    int N=s.size();
    REP(i,N){
        if(s==t){
            cout<<"Yes"<<endl;
            return 0;
        }
        s=s.back()+s;
        s.erase(s.end()-1);
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
from typing import List


class DSU:
    def __init__(self, n: int) -> None:
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a <= self._n
        assert 0 <= b <= self._n
        x, y = self.leader(a), self.leader(b)
        if x == y:
            return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a <= self._n
        assert 0 <= b <= self._n
        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n
        if self.parent_or_size[a] < 0:
            return a
        while self.parent_or_size[a] >= 0:
            a = self.parent_or_size[a]
        return a

    def size(self, a: int) -> int:
        assert 0 <= a <= self._n
        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> List[List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]
        group_size = [0] * self._n
        for i in leader_buf:
            group_size[i] += 1
        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)
        result = [i for i in result if i]
        return result



n, q = map(int, input().split())
uf = DSU(n)
for i in range(q):
    t, u, v = map(int, input().split())
    if t:
        print(int(uf.same(u, v)))
    else:
        uf.merge(u, v)


Measured memory_bytes: 80228
#include<cstdio>

char maze[51][51];
bool mark[51][51];
int n,m;
int go[][2] = {0,1,0,-1,1,0,-1,0};
int cnt;
void DFS(int x, int y){
    for(int i = 0; i < 4; i++){
        int nx = x + go[i][0];
        int ny = y + go[i][1];
        if(nx < 0 || nx >= n || ny < 0 || ny >=m) continue;
        if(maze[nx][ny] == '.') continue;
        if(mark[nx][ny] == true) continue;
        cnt++;
        mark[nx][ny] = true;
        DFS(nx, ny);
    }
    return;
}

int main(){
  while(scanf("%d%d",&n,&m) == 2){
    for(int i = 0; i < n ; i++){
        for(int j = 0; j < m; j++){
            mark[i][j] = false;
        }
    }
    for(int i = 0; i < n ; i++){
        scanf("%s",maze[i]);
    }
    bool success = true;
    for(int i = 0; i < n ; i++){
        for(int j = 0; j < m; j++){
            if(maze[i][j] == '.') continue;
            if(mark[i][j] == true) continue;

            cnt = 1;
            DFS(i,j);
            if(cnt == 1) success = false;
        }
    }
    puts(success == true ? "Yes" : "No");
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<utility>
#define ul unsigned long long int
#define ll long long int
#define MAX 1000000+1
using namespace std;
#define F first
#define S second
#define pi 2*acos(0.0)
#define PB push_back
#define CL clear()

char s[] = {'+' , '-'};
int a, b, c, d;

bool isvalid(char i, char j, char k)
{
    int sum = 0;
    sum= a;
    if(i == '+')
        sum += b;
    else
        sum -= b;
    if(j == '+')
        sum += c;
    else
        sum -= c;
    if(k == '+')
        sum += d;
    else
        sum -= d;
    return sum == 7;

}



int main()
{
    string ss;
     cin >> ss;
     a = ss[0] - 48;
     b = ss[1] - 48;
     c = ss[2] - 48;
     d = ss[3] - 48;
    for(int i = 0; i < 2; i++)
        for(int j = 0; j < 2; j++)
            for(int k = 0; k < 2; k++)
                if(isvalid(s[i], s[j], s[k]))
                {
                    cout << a<<s[i] <<b<<s[j] <<c<<s[k] <<d<<'='<<7;
                    return 0;
                }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

int main(){
  int N; cin >> N;
  vector<long long> a(N);
  rep(i,N) cin >> a[i];
  
  vector<long long> s(N+1, 0);
  map<long long, long long> nums;
  rep(i,N) s[i+1] = s[i] + a[i];
  rep(i,N+1) nums[s[i]]++;
  
  long long res = 0;
  for(auto it : nums) {
    long long num = it.second;
    res += num * (num-1) / 2;
  }
  cout << res << endl;
}


Measured memory_bytes: 15872
#include<stdio.h>
int main(void){
	int a[3]={0};
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  if(a[0]==a[1])
    printf("%d",a[2]);
  else if(a[1]==a[2])
    printf("%d",a[0]);
  else
    printf("%d",a[1]);
    return 0;
}

Measured memory_bytes: 128
#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def main():
    a, b = map(int, input().split())
    if abs(a - b) % 2 == 1:
        print('IMPOSSIBLE')
    else:
        dif = abs(a - b) // 2
        print(min(a,b) + dif)

if __name__ == '__main__':
    main()


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

int main(){
    int x,y;
    while(1){
        cin >> x >>y;
        if(x == 0&& y==0) break;
        for(int j = 0; j < x; j++){
                for(int i = 0; i< y; i++){
                cout << "#";
            }cout << endl;
        }cout << endl;
    }
    return 0;
}


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

#define long long long int
using namespace std;

// @author: pashka

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

    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    if (p < 10) {
        vector<int> cnt(p);
        int cur = 0;
        long res = 0;
        cnt[0]++;
        for (int i = 0; i < n; i++) {
            vector<int> cnt2(p);
            for (int j = 0; j < p; j++) {
                cnt2[(j * 10) % p] += cnt[j];
            }
            cnt = cnt2;
            cur = (cur * 10 + (s[i] - '0')) % p;
            res += cnt[cur];
            cnt[cur]++;
        }
        cout << res << "\n";
        return 0;
    }

    int inv10 = 1;
    while ((inv10 * 10) % p != 1) inv10++;

    vector<int> cnt(p);
    int cur = 0;
    long res = 0;
    int inv10pow = 1;
    cnt[0]++;
    for (int i = 0; i < n; i++) {
        cur = (cur * 10 + (s[i] - '0')) % p;
        int xx = (cur * inv10pow) % p;
        res += cnt[xx];
        cnt[xx]++;
        inv10pow = (inv10pow * inv10) % p;
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


bool f(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a<b) return false;
  if(b>d) return false;
  if(c>=b) return true;
  if(c<b+(a%__gcd(b,d))-__gcd(b,d)) return false;

  return true;
}


int main(){
  int t;
  cin>>t;
  while(t--){
    if(f())
      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 a=sc.nextInt();
		int b[]=new int [a+1];
		for(int i=0;i<a;i++)
		{
			b[i]=sc.nextInt();
			//System.out.println(b[i]);
		}
		Arrays.sort(b);
		/*for(int k=0;k<a;k++)
		{
			System.out.println(b[k]);
		}*/
		int c=0;
		for(int j=0;j<a;j++)
		{
			c=c+b[j];
			//System.out.println("c is:"+c);
		}
		if(b[a]<c)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 23764
ss,tt = open(0).read().split()

from collections import defaultdict

d = defaultdict(str)
e = defaultdict(str)
ans = 'Yes'
for s,t in zip(ss,tt):
    if not d[s]:
        d[s] = t
    elif d[s] != t:
        ans = 'No'
        break
    if not e[t]:
        e[t] = s
    elif e[t] != s:
        ans = 'No'
        break

print(ans)

Measured memory_bytes: 77556
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
int n;
scanf("%d",&n);
(n>=30)?printf("Yes\n"):printf("No\n");



    return 0;
}


Measured memory_bytes: 3752
#include <cstdio>
#include <algorithm>

namespace Dinic {
	typedef long long LL;
	const LL Inf = 0x3f3f3f3f3f3f3f3f;
	const int MN = 200005, MM = 100005;
	
	int N, S, T;
	int h[MN], iter[MN], nxt[MM * 2], to[MM * 2], tot; LL w[MM * 2];
	
	inline void SetST(int, int);
	inline void Init(int _N) {
		N = _N, tot = 1;
		for (int i = 1; i <= N; ++i) h[i] = 0;
		SetST(_N - 1, _N);
	}
	inline void SetST(int _S, int _T) { S = _S, T = _T; }
	
	inline void ins(int u, int v, LL x) { nxt[++tot] = h[u], to[tot] = v, w[tot] = x, h[u] = tot; }
	inline void insw(int u, int v, LL w1 = Inf, LL w2 = 0) {
		if (!u) u = S; if (!v) v = T;
		ins(u, v, w1), ins(v, u, w2);
	}
	
	int lv[MN], que[MN], l, r;
	
	inline bool Lvl() {
		for (int i = 1; i <= N; ++i) lv[i] = 0;
		lv[S] = 1;
		que[l = r = 1] = S;
		while (l <= r) {
			int u = que[l++];
			for (int i = h[u]; i; i = nxt[i])
				if (w[i] && !lv[to[i]]) {
					lv[to[i]] = lv[u] + 1;
					que[++r] = to[i];
				}
		}
		return lv[T] != 0;
	}
	
	LL Flow(int u, LL f) {
		if (u == T) return f;
		LL d = 0, s = 0;
		for (int &i = iter[u]; i; i = nxt[i])
			if (w[i] && lv[to[i]] == lv[u] + 1) {
				d = Flow(to[i], std::min(f, w[i]));
				f -= d, s += d;
				w[i] -= d, w[i ^ 1] += d;
				if (!f) break;
			}
		return s;
	}
	
	inline LL Dinic() {
		LL Ans = 0;
		while (Lvl()) {
			for (int i = 1; i <= N; ++i) iter[i] = h[i];
			Ans += Flow(S, Inf);
		}
		return Ans;
	}
}

const int MN = 100005;
int N, A[MN], B[MN], cA[MN], cB[MN], Sum;

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]), ++A[i];
	for (int i = 1; i <= N; ++i) scanf("%d", &B[i]), ++B[i];
	for (int i = 1; i <= N; ++i) cA[i] = cB[i] = i;
	for (int i = 1; i <= N; ++i) {
		if (cA[i] == i) for (int x = A[i]; x != i; x = A[x]) cA[x] = i;
		if (cB[i] == i) for (int x = B[i]; x != i; x = B[x]) cB[x] = i;
	}
	for (int i = 1; i <= N; ++i) cB[i] += N;
	Dinic::Init(N + N + 2);
	for (int i = 1; i <= N; ++i) {
		if (A[i] != i && B[i] != i) {
			if (A[i] != B[i]) Dinic::insw(cB[i], cA[i], 1);
			else Dinic::insw(cB[i], cA[i], 1, 1);
		} else if (A[i] != i || B[i] != i) {
			if (A[i] == i) Dinic::insw(cB[i], 0, 1);
			else Dinic::insw(0, cA[i], 1);
		} else ++Sum;
	}
	printf("%lld\n", N - Dinic::Dinic() - Sum);
	return 0;
}

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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;


signed main() {
    string t = "yuiophjklnm";
    while(1) {
        string s;
        cin >> s;
        if (s == "#") return 0;
        bool F = false;
        int ans=0;
        for(int i=0; i<s.length(); i++){
            bool f = false;
            for(int j=0; j<t.length(); j++){
                if (s[i]==t[j]){
                    f = true;
                }
            }
            if(i==0) {
                if(f) F=true;
                else F=false;
                continue;
            }
            if(F != f) ans++;
            F = f;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3140
#include <iostream>
#include <algorithm>
using namespace std;
using ll=long long;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
//https://atcoder.jp/contests/abc073/tasks/abc073_c
int cnt_digits(ll n){

    int digits =0;
    while(n > 0){

        digits++;
        n /= 10;

    }
    return digits;
}

//最大公約数
ll gcd(ll a,ll b){
    if(b ==0) return a;
    else return gcd(b ,a % b);
}

//最小公倍数
ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return (a / g) * b;
}

int main() {
     
    int n;
    cin >> n;
    int a[100000]={0};
    int ptr = 0;
    for(int i=0;i < n;i++) cin >> a[i];
    sort(a,a + n);
    int cnt = 0;
    int ans = 0;
    while(ptr < n){
        int c = a[ptr];
        while(ptr < n && c == a[ptr]){
            cnt++;
            ptr++;
        }
        

        ans += cnt %2;
        cnt = 0;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
#define MAX 1000000
int main()
{
  bool b[MAX+1]={0};
  int i,j;
  b[0]=b[1]=1;
  for(i=4;i<=MAX;i+=2)b[i]=1;
  for(i=3;i*i<=MAX;i+=2)
    if(!b[i])for(j=i+i;j<=MAX;j+=i)b[j]=1;
  int n,x,price[30],dp[MAX+1];
  bool f;
  while(cin>>n>>x,n|x){
    for(i=0;i<n;i++)cin>>price[i];
    for(i=0;i<x+1;i++)dp[i]=(i==0);
    for(i=0;i<x+1;i++){
      if(!dp[i])continue;
      for(j=0;j<n;j++)if(i+price[j]<x+1)dp[i+price[j]]=true;
    }
    f=false;
    for(i=x;i>0;i--)if(dp[i]&!b[i]){f=true;break;}
    if(f)cout<<i<<endl;
    else puts("NA");
  }
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;

  int ans = 0;
  for (int i = 1; i < n; i ++) {
    if ((s[i] == 'O' && s[i-1] == 'X') || (s[i] == 'X' && s[i-1] == 'O')) {
      ans ++;
      i ++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3348
x1, y1, x2, y2 = map(int, input().split())
x = x2 - x1
y = y2 - y1
x3 = x2 - y
y3 = y2 + x
x4 = x3 - x
y4 = y3 - y
print(x3, y3, x4, y4)


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

int main() {
  
  int N;
  int A;
  
  cin >> N >> A;
 
  if ( N%500 == 0 || N%500 < A ){
    
    cout << "Yes" << endl;
  }
  
  if ( N%500 != 0 && N%500 > A ){
    
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i = 0; i < (n);++i)
#define repc(i,a,b) for(int i = (a);i <(b);++i)
#define repa(n,array) for(auto n :(array))

typedef long long ll ;
typedef vector<int> vi ;
typedef vector<ll> vl ;

constexpr int IMAX = ((1<<30)-1)*2+1 ;
constexpr int INF = 100000000;
double EPS = 1e-10 ;

int main(){
  int num,ans;
  while(cin >> num){
    ans = 0 ;
    for(int i = 0; i < 600;i+=num){
      ans += i*i*num ;
    }
    cout << ans << endl ;
  }
  return 0;
}

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

int main(){
    int a;
    cin >> a;
    vint monster(a+1);
    rep(i,a+1) cin >> monster[i];
    vint hunter(a);
    rep(i,a) cin >> hunter[i];
    hunter[a] = 0;
    ll ans = 0;
    rep(i,a+1){
        if(i == 0){
            if(monster[i] >= hunter[i]){
                ans += hunter[i];
                hunter[i] = 0;
                //cout << i << "1" << " " << ans << endl;
            }
            else{
                ans += monster[i];
                hunter[i] -= monster[i];
                //cout << i << "2" << " " << ans << endl;
            }
        }
        else{
            if(hunter[i-1] + hunter[i] >= monster[i]){
                ans += monster[i];
                if(hunter[i-1] >= monster[i]){
                    hunter[i-1] -= monster[i];
                    //cout << i << "3" << " " << ans << endl;
                }
                else{
                    hunter[i] -= monster[i] - hunter[i-1];
                    hunter[i-1] = 0;
                    //cout << i << "4" << " " << ans << endl;
                }
            } 
            else{
                ans += hunter[i] + hunter[i-1];
                hunter[i] = 0;
                hunter[i-1] = 0;
                //cout << i << "5" << " " << ans << endl;
            }
        }
    }
    //rep(i,a) cout << hunter[i] << endl;
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=2e5+50;

int n,top,a[N],s[N],L[N],R[N];
long long ans;

void solve(){
	top=0;
	rep(i,1,n){
		while(top&&a[i]<a[s[top]])--top;
		L[i]=s[top];
		s[++top]=i;
	}
	top=0; s[0]=n+1;
	dec(i,n,1){
		while(top&&a[i]<a[s[top]])--top;
		R[i]=s[top];
		s[++top]=i;
	}
	rep(i,1,n)ans+=1ll*a[i]*(i-L[i])*(R[i]-i);
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	scanf("%d",&n); 
	rep(i,1,n)scanf("%d",a+i); 
	solve(); 
	printf("%lld\n",ans);
	return 0;
}

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

int64_t max(int64_t a, int64_t b){
    int64_t ret;
    if(a > b){
        ret = a;
    }else{
        ret = b;
    }
    return ret;
}

void solve(){
    int64_t n, ans;
    cin >> n;
    int64_t a[n];
    for(int64_t i = 0; i < n; i++){
        cin >> a[i];
    }

    ans = -INF;
    int64_t dp[3][n+4];
    for(int64_t i = 0; i < 3; i++){
        for(int64_t j = 0; j < n + 4; j++){
            dp[i][j] = -INF;
        }
    }
    dp[0][2] = 0;

    for(int64_t i = 4; i < n + 4; i++){
        dp[2][i] = max(max(dp[2][i], dp[1][i-3] + a[i-4]), max(dp[0][i-4] + a[i-4], dp[2][i-2] + a[i-4]));
        dp[1][i] = max(max(dp[1][i], dp[0][i-3] + a[i-4]), dp[1][i-2] + a[i-4]);
        dp[0][i] = max(dp[0][i], dp[0][i-2] + a[i-4]);
    }
    if(n % 2 == 1){
        ans = max(ans, max(max(dp[0][n], dp[1][n+2]), dp[2][n+3]));
    }else{
        ans = max(ans, max(dp[0][n+2], dp[1][n+3]));
    }
    cout << ans << endl;
}

int main(){
    solve();
}

Measured memory_bytes: 9840
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

signed main(){
	int a, b;
	scanf("%lld%lld", &a, &b);
	printf("%lld\n", (a-1)*(b-1));
	return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, c, k; cin >> n >> c >> k;
    vi t(n);
    rep(i, n) cin >> t[i];
    sort(all(t));

    ll bus = 0, buspop = 0, bustime = -INFLL;
    rep(i, n){
        if(t[i] > bustime+k){
            bus++;
            bustime = t[i];
            buspop = 1;
        }
        else buspop++;
        if(buspop >= c) bustime = -INFLL;
    }
    cout << bus << endl;
}

Measured memory_bytes: 3964
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] HW = Console.ReadLine().Split(' ');
            string[] hw = Console.ReadLine().Split(' ');

            int H = int.Parse(HW[0]);
            int W = int.Parse(HW[1]);
            int h = int.Parse(hw[0]);
            int w = int.Parse(hw[1]);

            Console.WriteLine((H - h) * (W - w));
        }  
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#include<bitset>
#include<string>
using namespace std;
#include <numeric> 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using pi=pair<long long,long long>;
#define pii 3.1415926536
#define binary
#define mod 1000000007
typedef long long ll;
typedef long double ld;
bool sortbysec(const pair<long long,long long> &a, 
              const pair<long long,long long> &b) 
{ 
    return (a.first < b.first); 
}
bool compare(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll>&b)
{
    if(a.first.first==b.first.first)return (a.first.second<b.first.second);
    return (a.first.first < b.first.first); 
}
 int lcm(int a, int b)  
 {  
    return (a*b)/__gcd(a, b);  
 }  
 int Kad(ll dp[],ll n)
{
  ll curr_max=0,maxx=INT_MIN;
  for(int i=0;i<n;i++)
  {
    curr_max=curr_max+dp[i];
    if(curr_max>maxx)
      maxx=curr_max;

    if(curr_max<0)
      curr_max=0;
   
  }

  return maxx;
}

/*void dfs(int u)
{
    vis[u]=true;
    //cout<<u<<" ";
    std::vector<ll> ::iterator i;
     for (i = g[u].begin(); i != g[u].end(); ++i) 
        if (!vis[*i]) 
            dfs(*i); 
    for(int i=1;i<g[u].size();i++)
    {
        if(!vis[g[u][i]])
        {
            dfs(i);
        }
    }
}*/

class query
{
public:
    int fi,sec,in;
};
bool sortby(query a, query b)
{
    if(a.sec==b.sec)
        return (a.fi<b.fi);
    else
        return (a.sec<b.sec);
}
void update(int* bit,int ind,int val,int n)
{
    for(;ind<=n;ind+=(ind&(-ind)))
        bit[ind]+=val;
}
int value(int val,int *bit)
{
    ll sum=0;
    for(;val>0;val-=(val&(-val)))
        sum+=bit[val];
    return sum;
}
int main()
{
 #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
  #endif  
 
  IOS;
  ll n;
   ll q;
  cin>>n;
    cin>>q;
  ll a[n+1];
  for (int i = 1; i <=n; ++i)
  {
      cin>>a[i];
  }
 

  query* qu=new query[q];
  for(int i=0;i<q;i++)
  {
    cin>>qu[i].fi>>qu[i].sec;
    qu[i].in=i;
  }
  sort(qu,qu+q,sortby);
  int* bit=new int[n+1];
  int* ans=new int[q]();

  ll total=0;
  ll k=0;
  ll* last=new ll[1000002];
  for(int i=0;i<1000002;i++)
  {
    last[i]=-1;
  }
  for (int i = 1; i <=n; ++i)
  {
      if(last[a[i]]!=-1)
      {
        update(bit,last[a[i]],-1,n);
      }
      else
      {
        total++;
      }
      update(bit,i,1,n);
      last[a[i]]=i;
      while(k<q && qu[k].sec==i)
      {
        ans[qu[k].in]=value(qu[k].sec,bit)-value(qu[k].fi-1,bit);
        k++;
      }
  }
  for (int i = 0; i < q; ++i)
  {
      cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 25216
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
using namespace std;

int main(){
  int n;
  cin >> n;
  pair<int,int> r[n];
  pair<int,int> b[n];
  for(int i=0;i<n;i++) cin >> r[i].second >> r[i].first;
  for(int i=0;i<n;i++) cin >> b[i].first >> b[i].second;
  sort(r,r+n);
  sort(b,b+n);
  set<int> q;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(r[n-j-1].second < b[i].first && r[n-j-1].first < b[i].second){
        if (q.find(n-1-j) == q.end()){
          q.insert(n-1-j);
          break;
        }
        else continue;
      }
    }
  }
  cout << q.size() << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define NOT_ZERO 1
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long ll;
typedef unsigned short int usi;

int main()
{
    int n;
    int a, b;
    int i, j;
    int p[100];
    int x=0, y=0, z=0;

    scanf("%d %d %d",&n,&a,&b);
    for(i=0; i<n; i++) {
        scanf("%d",p+i);
        if(p[i]<=a) {
            x++;
        } else if(a<p[i] && p[i]<=b) {
            y++;
        } else if(b<p[i]) {
            z++;
        }
    }

    printf("%d",MIN3(x,y,z));


    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <bitset>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dcm(a) setprecision(a)<<fixed
#define MOD 1000000007
#define clr(memo, a) memset(memo,a,sizeof(memo))
#define PI acos(-1)
int const N=1e2+5;
int const M=1e5+5;
ll dp[N][M];
void solve(){
int n;
ll weghit;
cin>>n>>weghit;
vector<ll> v(n);
vector<ll> w(n);
for(int i=0;i<n;i++)
    cin>>w[i]>>v[i];
if(weghit-w[0]>=0)
    dp[0][weghit-w[0]]=v[0];
for(int i=1;i<n;i++){
    for(int j=0;j<=weghit;j++){
        dp[i][j]=dp[i-1][j];
        if(j-w[i]>=0)
        dp[i][j-w[i]]=max(dp[i-1][j]+v[i], dp[i][j-w[i]]);
        }

}
ll ans=0;
for(int i=0;i<=weghit;i++)
    ans=max(ans,dp[n-1][i]);
cout<<ans<<endl;
}

int main(){
    fast;

solve();

return 0;}


Measured memory_bytes: 79360
#include "bits/stdc++.h"
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int n;
    long long a[50];
    cin>>n;
    REP(i,n)cin>>a[i];
    long long ans=0;
    bool f=true;
    while(f){
        f=false;
        long long sum=0;
        long long b[n];
        REP(i,n){
            b[i]=a[i]/n;
            sum+=b[i];
            ans+=b[i];
            a[i]-=b[i]*n;
        }
        REP(i,n)a[i]+=sum-b[i];
        REP(i,n)if(a[i]>=n)f=true;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  string s;
  cin>>s;
  int n = s.size();
  int ans = 0;
  int t = (n-1)/2;
  for(int i = 0; i<=t; i++){
    if(s[i] == s[n-1-i]){
      continue;
    }
    ans++;
  }
  cout<<ans<<endl;
  return 0; 
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        n: usize, t: usize,
        t_vec: [usize; n],
    }

    let mut ans = 0;

    for i in 0..n {
        // 前回よりt秒立っていれば単純に加算
        if i == 0 { continue; }
        ans += std::cmp::min(t_vec[i] - t_vec[i-1], t); 
    }

    println!("{}", ans+t);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 5400
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, r;
    cin >> n >> r;

    if (n >= 10) {
        cout << r << endl;
    } else {
        cout << r + 100 * (10 - n) << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e3 + 5;
const double eps = 1e9;
typedef long long LL;
#define ls o<<1
#define rs o<<1|1
#define m(o) (q[o].l+((q[o].r-q[o].l)>>1))

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	LL ans = 0;
	if (n == 1 && m == 1) {
		printf("1\n");
	}
	else if (n == 1) {
		printf("%d\n", m - 2);
	}
	else if (m == 1) {
		printf("%d\n", n - 2);
	}
	else printf("%lld\n", 1LL * n*m - 2 * m - 2 * (n - 2));
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    int N;
    cin >> N;
    vector<vi> A(N, vi(N));
    rep(i, N) {
        rep(j, N)cin >> A[i][j];
    }

    vll pt(1 << N);
    rep(S, 1 << N) {
        rep(i, N)rep(j, i) {
            if ((S >> i & 1) && (S >> j & 1))pt[S] += A[i][j];
        }
    }

    vll dp(1 << N);
    const int U = (1 << N) - 1;
    rep(S, 1 << N) {
        int rS = S ^ U;
        int T = rS;
        do {
            smax(dp[S | T], dp[S] + pt[T]);
            T = (T - 1)&rS;
        } while (T != rS);
    }
    cout << dp.back() << endl;
}

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

Measured memory_bytes: 1280
#include <iostream>

using namespace std;
const int MAXQ = 100010;
const int MAXN = 100010;
int n;
int q;
string s;
int l[MAXQ], r[MAXQ];
int dp[MAXN];
void solve() {
  for (int i=0;i<n-1;i++) {
    if (s[i] == 'A' && s[i+1] == 'C') {
      dp[i+1] = dp[i] + 1;
    } else {
      dp[i+1] = dp[i];
    }
  }
  for (int i=0;i<q;i++) {
    int tot = dp[r[i]] - dp[l[i]];
    cout << tot << endl;
  }
}

int main() {
  cin >> n >> q;
  cin >> s;
  for (int i=0;i<q;i++) {
    cin >> l[i] >> r[i];
    l[i]--;r[i]--;
  }
  solve();
}


Measured memory_bytes: 2176
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

type cnt struct {
	v int64
	c int64
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]cnt, n+10)
	for i := int64(2); i <= n; i++ {
		if a[i].v == 1 {
			continue
		}
		for j := i; j <= n; j += i {
			if a[j].v == 0 {
				a[j].v = j
				a[j].c = 1
			}

			c := int64(0)
			for a[j].v%i == 0 {
				a[j].v /= i
				c++
			}
			a[j].c *= (c + 1)
		}
	}
	res := int64(1)
	for i := int64(2); i <= n; i++ {
		res += i * a[i].c
	}
	fmt.Println(res)
}


Measured memory_bytes: 163140
#include <iostream>
#include <cmath>

int main(void){
    int N, ans=0;
    double dT=1000.0, T, A;
    std::cin >> N >> T >> A;

    for (int i=0; i<N; ++i){
        double h, tmp;
        std::cin >> h;
        tmp = T - 0.006 * h;
        if (dT > std::abs(A - tmp)){
            dT = std::abs(A - tmp);
            ans = i + 1;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3772
import Data.List
import Debug.Trace

main = do
  n <- read <$> getLine :: IO Int
  ss <- getLine :: IO String
  print $ solve ss

solve :: String -> Int
solve ss =
  ans
  where
    cost = map (\s -> if s=='E' then 1 else (0-1)) ss
    cumsum = scanl1 (+) cost :: [Int]
    pos = case elemIndex (maximum  cumsum) cumsum of
      Just a -> a
    (l,r) = splitAt pos ss
    ans =
      --traceShow (l,r) $
      case length (filter (=='W') l) of
        0 -> 0 + length (filter (=='E') (tail r)) 
        otherwise -> length (filter (=='W') l)  + length (filter (=='E') (tail r)) 
      


Measured memory_bytes: 44412
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int cs[5];
    while( scanf( "%d,%d,%d,%d,%d", &cs[0], &cs[1], &cs[2], &cs[3], &cs[4] ) != -1 ) {
        sort( cs, cs + 5 );

        vector<int> uc( 5 );
        unique_copy( cs, cs+5, uc.begin() );

        int p[5] = {};
        for( auto const& c : uc ) {
            ++p[count( cs, cs + 5, c )];
        }
        
        bool const is_straight = [&]{
            bool const b = [&](){
                for( int i=1; i<5; ++i ) {
                    if ( cs[i-1] + 1 != cs[i] )
                        return false;
                }
                return true;
            }();

            return b
                   || ( cs[0] == 10 && cs[1] == 11 && cs[2] == 12 && cs[3] == 13 && cs[4] == 1 )
                   || ( cs[0] == 1 && cs[1] == 10 && cs[2] == 11 && cs[3] == 12 && cs[4] == 13 );
        }();

        
        cout <<
            ( ( p[4] == 1 )
              ? "four card"
              : ( p[3] == 1 && p[2] == 1 )
              ? "full house"
              : ( is_straight )
              ? "straight"
              : ( p[3] == 1 )
              ? "three card"
              : ( p[2] == 2 )
              ? "two pair"
              : ( p[2] == 1 )
              ? "one pair"
              : "null" )
            << endl;
    }
}

Measured memory_bytes: 1212
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val X, Y = Array.ofDim[Int](3)
    rep(3) { i =>
      X(i) = ni()
      Y(i) = ni()
    }

    val a = Array.ofDim[Double](3)
    def calcAngle(i: Int, j: Int, k: Int) = {
      abs(angle(X(j) - X(i), Y(j) - Y(i), X(k) - X(i), Y(k) - Y(i))) / 2
    }

    def calcR(i: Int, j: Int): Double = {
      import java.awt.geom.Point2D
      val L = Point2D.distance(X(i), Y(i), X(j), Y(j))
      val t1 = Math.tan(a(i))
      val t2 = Math.tan(a(j))
      L / (2 + 1 / t1 + 1 / t2)
    }

    a(0) = calcAngle(0, 1, 2)
    a(1) = calcAngle(1, 2, 0)
    a(2) = calcAngle(2, 0, 1)

//    a map (_ / Math.PI * 180) foreach System.err.println

    val r = Seq(calcR(0, 1), calcR(1, 2), calcR(0, 2))
    out.println(f"${r.max}%.12f")
  }

  /**
    * [-π, π]
    */
  def angle(x1: Int, y1: Int, x2: Int, y2: Int): Double = {
    val sin = -y1 * x2 + x1 * y2  // perp dot product
    val cos = x1 * x2 + y1 * y2   // dot product
    Math.atan2(sin, cos)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}


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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For (i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;

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

    int n, k;
    cin >> n >> k;
    vector<int> vec(n + 1);
    For (i, 1, n)
        cin >> vec[i], vec[i] += vec[i - 1];

    vector<int> li;
    rep (i, n)
        For (j, i + 1, n)
            li.pb(vec[j] - vec[i]);

    int ans = 0;
    Forr (i, 40, 0) {
        int cnt = 0, bit = ans + (1ll << i);
        repall (j, li)
            cnt += (j & bit) == bit;

        if (cnt >= k) ans = bit;
    }

    print(ans);

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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

ll conv3(ll x){
  return x * (x-1) * (x-2) / (6);
}

ll conv2(ll x){
  return x * (x-1) / (2);
}

int main() {

  ll N, A;
  cin >> N >> A;

  N %= 500;
  if(N<=A)cout << "Yes" << endl;
  else cout << "No" << endl;

 
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3536
n,m=[int(_) for _ in input().split()]

if n==1:
  ans=-1
  for i in range(m):
    s,c=[int(_)for _ in input().split()]
    if ans!=-1 and ans != c:
      print(-1)
      exit()
    ans=c
  else:
    print(max(ans,0))
    exit()

ans=[-1 for i in range(n)]



for i in range(m):
  s,c=[int(_)for _ in input().split()]
  if (ans[s-1]!=-1 and ans[s-1]!=c)or (s==1 and c==0):
    print(-1)
    exit()
  else:
  	ans[s-1]=c

ans[0]=max(1,ans[0])
ans.reverse()
t=0
d=1

for i in range(n):
  t+=max(0,ans[i])*d
  d*=10
#print(ans)
print(t)


Measured memory_bytes: 3064