akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split())
sc=set(tuple(map(int,input().split())) for i in range(m))

S=['1']+['0']*(n-1)
for s,c in sc:
    if s==1 and c==0 and n>1:
        print(-1)
        exit()
    elif s==1 and S[0]!='1':
        print(-1)
        exit()
    elif s>1 and S[s-1]!='0':
        print(-1)
        exit()
    S[s-1]=str(c)
    #print(S)
if n==1 and m==0:S='0'
print(*S,sep='')

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

// template {{{
using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))

using int64 = long long;

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

bool in_field(int W, int H, int x, int y) {
  return (0 <= x && x < W) && (0 <= y && y < H);
}

// pair
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

// }}}

// url: https://atcoder.jp/contests/abc088/tasks/abc088_d

int H, W;
char s[50][50];
int num[50][50];

typedef pair<int, int> P;

int main() {
  fill(num, 0);
  cin >> H >> W;
  rep(i, H) rep(j, W) { cin >> s[j][i]; }

  queue<P> que;
  que.push(P(0, 0));
  num[0][0] = 1;

  int white = 0;
  rep(i, H) rep(j, W) {
    if (s[j][i] == '.') {
      white++;
    }
  }
  // cout << "white:" << white << endl;
  while (que.size()) {
    P p = que.front();
    que.pop();
    // cout << p << endl;

    rep(i, 4) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];

      if (nx == W - 1 && ny == H - 1) {
        cout << white - (num[p.first][p.second] + 1) << endl;
        return 0;
      }

      if (in_field(W, H, nx, ny) && num[nx][ny] == 0 && s[nx][ny] == '.') {
        que.push(P(nx, ny));
        num[nx][ny] = num[p.first][p.second] + 1;
      }
    }
  }

  cout << -1 << endl;
  return 0;
}

// vim: foldmethod=marker


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

int a[100005];
int dp[100005];

int main()
{
   int n;
   cin >> n;
   for(int i=0;i<n;i++)
   {
       cin >> a[i];
   }

    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);

    for(int i=2;i<n;i++)
        dp[i] = min(dp[i-1] + abs(a[i]-a[i-1]), dp[i-2]+abs(a[i-2]-a[i]));
    
    cout << dp[n-1] << endl;
    return 0;


}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#define RANGE_1(e) (boost::irange(0,(e)))
#define RANGE_2(s,e) (boost::irange((s),(e)))
#define RANGE_3(s,e,step) (boost::irange((s),(e),(step)))
#define RANGE_SELECTER(_1,_2,_3,SELECT,...) SELECT
#define range(...) RANGE_SELECTER(__VA_ARGS__, RANGE_3, RANGE_2, RANGE_1) (__VA_ARGS__)
#define guard(x) if(x);
#define CINS(x) for(auto&& __E__:(x))cin>>__E__
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define CALL(x) (x).cbegin(),(x).cend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define BIT(n) (1LL<<(n))
#define MOD 1000000007

using namespace std;
using lint = long long;

// template<class T>class irange{private:struct I{T x;T operator*(){return x;}bool operator!=(I&lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;public:irange(T i,T n):i({i}),n({n}){}I&begin(){return i;}I&end(){return n;}};
// template<class T>class srange{private:struct I{T x,s;T operator*(){return x;}bool operator!=(I&lhs){if(s<(T)0)return x>lhs.x;return x<lhs.x;}void operator++(){x=x+s;}};I i,n;public:srange(T i,T n,T s):i({i,s}),n({n,s}){}I&begin(){return i;}I&end(){return n;}};
// template<class T>irange<T>range(T n){return irange(0,n);}template<class T>irange<T>range(T i,T n){return irange(i,n);}template<class T>srange<T>range(T i,T n,T s){return srange(i,n,s);}
template<class T>bool amax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool amin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

struct initialize{initialize(){cin.tie(nullptr);ios::sync_with_stdio(false);};}__ini__;

int main() {
    int x, n; // 与えられる整数, 禁止リストの長さ
    cin >> x >> n;
    vector<int> p(n); // 禁止リスト
    CINS(p);
    
    for (auto&& i : range(n + 1)) { // ループの回数が多すぎる気もするが, 見つかった時点で終了するので多すぎる分には問題ないと判断 考える時間のほうが惜しい
        if (!count(ALL(p), x - i)) { // 要約では省いたが, 小さい方を優先する
            cout << x - i << endl;
            return 0;
        } else if (!count(ALL(p), x + i)) { // どうでもいいが count と cout 紛らわしいな
            cout << x + i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3656
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
cnt1 = 0
cnt2 = 0
for i in range(N):
    if A[i]>B[i]:
        cnt1 += A[i]-B[i]
    elif A[i]<B[i]:
        cnt2 += (B[i]-A[i])//2
if cnt1<=cnt2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 74084
import numpy as np
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

k = int(input())

sum1 = 0.5 * k * (k + 1)
sum2 = 0
sum3 = 0
list2 = []

if k > 1:
    for i in range(k):
        for j in range(i+1,k):
            a = i + 1
            b = j + 1
            sum2 += gcd(a, b)
            list2.append(gcd(a, b))
    sum2 *= 6

if k > 2:
    sum2 /= 3
    for i in range(len(list2)):
        for j in range(k):
            c = j + 1
            sum3 += gcd(list2[i], c)
    sum3 *= 2

print(int(sum1 + sum2 + sum3))


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

h,w=map(int,input().split())
M=[list(input().strip()) for _ in range(h)]

def bfs(x,y):
    if M[x][y]=='#':
        return 0
    q=deque()
    q.append((x,y))
    count = [[-1]*w for _ in range(h)]
    count[x][y]=0

    while q:
        x,y=q.pop()
        for i,j in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
            if 0<=i<h and 0<=j<w and count[i][j]==-1 and M[i][j]=='.':
                count[i][j]=count[x][y]+1
                q.appendleft((i,j))

    return max([max(c) for c in count])
        
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,bfs(i,j))
print(ans)

 


Measured memory_bytes: 74664
#include<bits/stdc++.h>
using namespace std;
vector<int> val[123456];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;cin>>n>>m;
	for(int i=0;i<n;i++){
		int a,b;cin>>a>>b;
		val[a].push_back(b);
	}
	int ans=0;
	priority_queue<int> pq;
	for(int i=1;i<=m;i++){
		for(int j=0;j<val[i].size();j++)
			pq.push(val[i][j]);
		if(!pq.empty()){
			ans+=pq.top();
			pq.pop();
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6272
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K = map(int, read().split())

left = N // K
right = left + 1

ans = min(abs(N - K * left), abs(N - K * right))

print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=2e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }



int n,a[N],ans[N];
vi adj[N];

multiset<int> mt;

void dfs(int u,int p=0) {
	  
	  int d=-1;
	  mt.insert(a[u]);
	  auto it=mt.lb(a[u]);
	  
	  if(++it!=mt.end()) {
		     d=*it;
		     mt.erase(it);
		  }
	  ans[u]=sz(mt);
	  
	  for(auto to:adj[u]) {
		     if(to!=p) dfs(to,u);
		  }
		  
		if(d!=-1) mt.insert(d);
		mt.erase(mt.find(a[u]));	
}


	
void solve() {
   cin>>n;
   rep1(i,1,n)
     cin>>a[i];
   rep(i,1,n) {
	     int x,y;
	     cin>>x>>y;
	     adj[x].pb(y);
	     adj[y].pb(x);
	   } 
	   
     dfs(1);
     
     rep1(i,1,n)
        cout<<ans[i]<<endl;   
}

    
int32_t main() {
	cool;
	int t=1;	

	//cin>>t;
	while(t--)
	  solve();

return 0;	   
}


Measured memory_bytes: 31920
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  f80 density = -1;
  i64 sugar, sugarwater;

  for(int a = 0; a * 100 * A <= F; a++){
    for(int b = 0; b * 100 * B <= F - a * 100 * A; b++){
      if(a+b==0) continue;
      for(int c = 0;(a * 100 * A + b * 100 * B + c * C <= F) and (c * C <= (a * A + b * B) * E); c++){
        i64 d = min(F - a * 100 * A - b * 100 * B - c * C, (a * A + b * B) * E - c * C);
        d -= d % D;

        if(density < f80(c * C + d) / (a * A + b * B)){
          density = f80(c * C + d) / (a * A + b * B);
          sugar = c * C + d;
          sugarwater = c * C + d + a * A * 100 + b * B * 100;
        }

      }
    }
  }
  cout << sugarwater << " " << sugar << "\n";
}

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

Measured memory_bytes: 256
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N
for i, hi in enumerate(h):
  if i > 0:
    x = max(0, i - K)
    dp[i] = min([dpj + abs(hi - hj) for hj, dpj in zip(h[x:i], dp[x:i])])
print(dp[N - 1])


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

int main()
{
	int a, b, c, i, ans = 0;;
	scanf("%d %d %d", &a, &b, &c);
	int *quo = (int*)malloc(b * sizeof(int));

	for (i = 0; i < b; i++) {
		quo[i] = a*(i + 1) % b;
		if (quo[i] == c)ans++;
	}
	if (ans == 0)printf("NO\n");
	else printf("YES\n");

	free(quo);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>

#define FOR(i,a,b) for(long long int i =(a); i <(b);i++)
#define REP(i,N)   FOR(i,0,N)
using namespace std;

int main(void){

    int N;
    string str;
    cin >> N >> str;

    int x = 0;
    int ans = 0;
    
    REP(i,N){
        switch(str[i]){
        case 'I' : x++; break;
        case 'D' : x--; break;
        default  : break;
        }
        ans = max(ans,x);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <cmath>
#include <cstdio>
#include <iostream>
#include <cstring> 
#include<algorithm>
#include<numeric>
#include<vector>
#define lowbit(x) x&-x
#define il inline
#define mod 1000000007
#define inf 1000000000
#define maxn 10000005
#define maxprime 3000005
using namespace std;
typedef long long int ll;
ll n,k;
inline int read() {
    ll ress = 0;
    char cd = getchar();
    while(!isdigit(cd)) cd = getchar();
    while(isdigit(cd)) ress = (ress << 1) + (ress << 3) + (cd ^ 48), cd = getchar();
    return ress;
}
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=max(-1000000,b-a+1);i<=min(b+a-1,1000000);i++)printf("%d ",i);
}

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

using namespace std;

int main(int argc, char const *argv[]){
    string s;
    cin >> s;
    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy") {
        cout << "Rainy" << endl;
    } else if (s == "Rainy") {
        cout << "Sunny" << endl;
    }

    return 0;
}


Measured memory_bytes: 888
<?php
/**
 * @see: https://atcoder.jp/contests/abc051/tasks/abc051_b
 */

function getInput(): array
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

function calculate(int $K, int $S): int
{
    $numberOfTriples = 0;

    for ($X = 0; $X <= $K && $X <= $S; $X++) {
        for ($Y = 0; $Y <= $K && $Y <= $S - $X; $Y++) {
            $Z = $S - $X - $Y;

            if (0 <= $Z && $Z <= $K) {
                $numberOfTriples++;
            }
        }
    }

    return $numberOfTriples;
}

list($K, $S) = getInput();

$result = calculate($K, $S);

echo $result . PHP_EOL;


Measured memory_bytes: 4984
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, z;
    cin >> x >> y >> z;
    cout << x * y / 2 << endl;
    return 0;
}


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

int main() {
  int L, R, Y = 2019;
  cin >> L >> R;

  if (R - L > Y) return cout << 0 << "\n", 0;

  long ans = LONG_MAX;
  for (int i = L; i < R; i++) {
    for (int j = i + 1; j <= R; j++) {
      ans = min(ans, (long)i * j % Y);
    }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素



signed main(){
  int A,B;
  cin>>A>>B;

  cout<<A*B<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<bitset>
#include<string>
#include<cmath>
#include<vector>
#include<tuple>
using namespace std;
//# Functions for Vector/Matrix
template <typename T>
vector<T> zeros(int length){
    vector<T> vec(length, 0);
    return vec;
}
template <typename T>
vector<vector<T>> zeros(tuple<int, int> dim){
    vector<vector<T>> mat(get<0>(dim), vector<T>(get<1>(dim), 0));
    return mat;
}
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define VARNAME(VariableName) # VariableName
template <typename T>
void show(vector<T> &vec){
    cerr << VARNAME(vec) << ": " << endl;
    for (auto value : vec) {
        cerr << value << " ";
    }
    cerr << endl;
}
template <typename T>
void show(vector<vector<T>> &mat){
    for (auto vec : mat) {
        show(vec);
    }
}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(ALL(a))
#define RSORT(a) sort(RALL(a))
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; }
bool iseven(int x){ return x % 2 == 0; }
bool isodd(int x){ return !iseven(x); }
int dist(int x, int y) { return abs(x - y);}
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}
int main(){
	// cin.tie(0);
   	// ios::sync_with_stdio(false);
    int N; cin >> N;
    double total = 0.0;
    double rate = 380000.0;
    double value;
    string type;
    REP(i, N){
        cin >> value >> type;
        if(type == "BTC") total += value * rate;
        else total += value;
        dump(value); dump(type);
    }
    cout << total;
    return 0;
}



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

using namespace std;
using ll = long long;
#define N 1000000007
ll mypower(ll a, ll b, ll mod)
{
    ll ans = 1;
    while(b > 0)
    {
        if(b%2 == 1)
            ans = (ans*a)%mod;
        a = (a*a)%mod;
        b = b/2;
    }
    return ans;
}
int main() {
    ll n;
    cin >> n;
    int arr[n], i;
    for(i=0;i<n;i++)
        cin >> arr[i];
    int sum = 0;
    for(i=0;i<n;i++)
        sum = sum + arr[i];
    if(sum%n == 0)
    {
        int pt = sum/n;
        ll ans = 0;
        for(i=0;i<n;i++)
            ans = ans + (pt-arr[i])*(pt-arr[i]);
        cout << ans << '\n';   
    }
    else
    {
        int pt1 = sum/n;
        int pt2 = pt1+1;
        ll ans1 = 0;
        ll ans2 = 0;
        for(i=0;i<n;i++)
        {
            ans1 = ans1 + (pt1-arr[i])*(pt1-arr[i]);
            ans2 = ans2 + (pt2-arr[i])*(pt2-arr[i]);
        }
        cout << min(ans1,ans2)<<'\n';
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		firstInt = firstInt % 10;

		if(firstInt == 3) {
			System.out.println("bon");
		}else if(firstInt == 0 || firstInt == 1 || firstInt == 6 || firstInt == 8) {
			System.out.println("pon");
		}else {
			System.out.println("hon");
		}

	}

}

Measured memory_bytes: 27076
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
using namespace std;
int main(){
  int a,b,c=0;
  cin>>a>>b;
  if (b >= 10 <100)
  c=a * 100 + b;
  if (b < 10)
  c=a * 10 + b;
  if (b==100)
  c=a * 1000 + b;
  for (int i=0;i<=5000;i++)
  if (i * i == c){
  cout<<"Yes";
  system ("pause");
  return 0;
  }
  cout<<"No";
  system ("pause");
  return 0;
  }

Measured memory_bytes: 504
n, m = map(int, input().split())
h = list(map(int, input().split()))
t = [1 for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if h[a] > h[b]:
        t[b] = 0
    elif h[a] == h[b]:
        t[a] = 0
        t[b] = 0
    else:
        t[a] = 0
ans = 0
for i in t:
    if i==1:
        ans += 1
print(ans)

Measured memory_bytes: 91168
#include <stdio.h>
#include <stdbool.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int color[100];
int a[100][100] ;
int k;
int check=0;
int v2;
bool cycle = false;

void CLOSE(int x){
int i;
color[x] = GRAY;
for(int i = 0; i < v2; i++){
		if(a[x][i] == 0) continue;
		if(color[i] == GRAY){
				cycle = true;
				return;
		}
		if(color[i] == WHITE) CLOSE(i);
}
color[x] = BLACK;
}

int main(){

 int e,s,t,i,j;
		scanf("%d %d", &v2,&e);
		for(i=0; i<v2;i++){
			color[i] = WHITE;
			for(j=0; j<v2;j++){
				a[i][j]=0;
			}
		}
	for(i=0; i<e;i++){
		scanf("%d %d", &s,&t);
		a[s][t] = 1;
	}
	for( i = 0; i < s; i++){
			if(color[i] == WHITE) CLOSE(i);
			if(cycle){
					printf("1\n");
					return 0;
				}

		}
		printf("0\n");

				return 0;
}



Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

#define eps (1e-10)
struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
    Point operator+(Point p) {return Point(x+p.x,y+p.y);}
    Point operator-(Point p) {return Point(x-p.x,y-p.y);}
    Point operator*(double k){return Point(x*k,y*k);}
    double norm(){return x*x+y*y;}
    double abs(){return sqrt(norm());}
    bool operator == (const Point &p) const{
    return fabs(x-p.x)<eps && fabs(y-p.y)<eps;
  }
  double dot(Point p){return x*p.x+y*p.y;}
  double det(Point p){return x*p.y-y*p.x;}
};
struct Line{
  Point p1,p2;
  Line(){}
  Line(Point p1, Point p2):p1(p1),p2(p2){}
};
int ccw(Point a,Point b,Point c){
  Point t1=b-a,t2=c-a;
  if(t1.det(t2)> eps) return 1;//counter clockwise
  if(t1.det(t2)< -eps) return -1;//clockwise
  if(t1.dot(t2)< -eps) return 2;//c-a-b online
  if(t1.norm()<t2.norm()) return -2;//a-b-c online
  return 0;//a-c-b online
}
bool intersectSS(Point a,Point b,Point c,Point d){
  return (ccw(a,b,c)*ccw(a,b,d)<=0&&ccw(c,d,a)*ccw(c,d,b)<=0);
}
bool intersectSS(Line l1,Line l2){
  return intersectSS(l1.p1,l1.p2,l2.p1,l2.p2);
}
bool isOrthogonal(Point a,Point b){
  return fabs(a.dot(b))<eps;
}
bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
  return isOrthogonal(a1-a2,b1-b2);
}
bool isParallel(Point a,Point b){
  return fabs(a.det(b))<eps;
}
bool isParallel(Point a1,Point a2,Point b1,Point b2){
  return isParallel(a1-a2,b1-b2);
}
Point CrossPoint(Line l1,Line l2){
    double a=(l1.p2-l1.p1).det(l2.p2-l2.p1);
    double b=(l1.p2-l1.p1).det(l1.p2-l2.p1);
    if(fabs(a)<eps&&fabs(b)<eps) return l2.p1;
    return l2.p1+(l2.p2-l2.p1)*(b/a);
}
Point project(Line l,Point p){
  Point base=l.p2-l.p1;
  double r=(p-l.p1).dot(base)/base.norm();
  return l.p1+base*r;
}
Point reflect(Line l,Point p){
  return p+(project(l,p)-p)*2.0;
}
int main(){
    int q;
    double xp0,yp0,xp1,yp1,xp2,yp2;
    cin>>xp1>>yp1>>xp2>>yp2;
    Point p1(xp1,yp1),p2(xp2,yp2);
    Line l(p1,p2);
    cin>>q;
    while(q--){
        cin>>xp0>>yp0;
        Point p0(xp0,yp0);
        Point ans=reflect(l,p0);
        cout<<fixed<<setprecision(10)<<ans.x<<" "<<ans.y<<endl;
    }
    return 0;
}


Measured memory_bytes: 3292
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Nickname solver = new Nickname();
        solver.solve(1, in, out);
        out.close();
    }

    static class Nickname {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            out.println(in.next().substring(0, 3));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 32904
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  std::vector<int> x(n),y(n),h(n);
  int min_h=INT32_MAX;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>h[i];
    min_h=std::min(min_h,h[i]);
  }
  
  for(int cx=0;cx<=100;cx++){
    for(int cy=0;cy<=100;cy++){
      for(int ch=min_h;ch<=min_h+200;ch++){
        
        bool isok=true;
        for(int i=0;i<n;i++){
          int tmp_height=std::max(ch-std::abs(x[i]-cx)-std::abs(y[i]-cy),0);
          if(tmp_height!=h[i]){
            isok=false;
            break;
          }
        }
        if(isok){
          cout<<cx<<" "<<cy<<" "<<ch<<endl;
          return 0;
        }
        
      }
    }
  }



  return 0;
}

Measured memory_bytes: 384
/*

 Remember, Hope is a good thing... May be the best of things... and No Good thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
#define endl "\n"
#define MOD 1000000007
const ll inf=(1LL<<60)-1;
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
void solve()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ll n,x,t;
    cin>>n>>x>>t;
    if(n%x==0)
    {
        cout<<(n/x)*t<<endl;
    }
    else
        cout<<((n/x)+1)*t<<endl;
}
int main()
{
    IOS;
    //ll t;
    //cin>>t;
    //while(t--)
    solve();
    return 0;
}


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

#define MAX 200000

int prime[MAX + 1];

int main(){
  int x;
  int limit;
  int i,j;

  scanf("%d", &x);

  for(i = 2;i <= MAX;i++) prime[i] = 1;
  limit = sqrt(MAX);

  for(i = 2;i <= limit;i++){
    if(prime[i] == 1){
      for(j = i*2;j <= MAX;j++){
        if(j % i == 0) prime[j] = 0;
      }
    }
  }

  while(prime[x] != 1) x++;

  printf("%d\n", x);

  return 0;
}


Measured memory_bytes: 896
N = int(input())
a = list(map(int, input().split()))
dp = [[[float(0)] * (N+1) for _ in range(N+1)] for _ in range(N+2)]
ans = float(0)
count = [0]*3
for i in a:
    count[i-1] +=1

#print(count)

for k in range(N+1):
    for j in range(N+1):
        for i in range(N+1):
            if (i+j+k)<=N:
                if (i+j+k)!=0:
                    dp[i][j][k] =  N/(i+j+k)
                if i > 0:
                    dp[i][j][k] += dp[i - 1][j][k] * (i / (i + j + k))
                if j > 0:
                    dp[i][j][k] += dp[i + 1][j - 1][k] * (j / (i + j + k))
                if k > 0:
                    dp[i][j][k] += dp[i][j + 1][k - 1] * (k / (i + j + k))

ans = dp[count[0]][count[1]][count[2]]

print(ans)

Measured memory_bytes: 255368
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

int main(){
    int N;
    cin >> N;
    vint A;
    map<int,ll> mp;
    REP(i,N){
        int a;
        cin >> a;
        A.pb(a);
        mp[a]++;
    }

    ll total = 0;
    for(auto p:mp){
        total += func(p.second);
    }
    for(auto a : A){
        cout << total - (mp[a]-1) << endl;
    }
}

Measured memory_bytes: 10228
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {

  ll L;
  cin >> L;

  int r = 0;
  while (pow(2, r) <= L) r++;
  r--;

  vector<int> vr, vl, w;
  for (int i = r; i >= 0; i--) {
    if (L - pow(2, r) - pow(2, i - 1) >= 0) {
      vr.push_back(i);
      vl.push_back(r + 1);
      w.push_back(L - pow(2, i - 1));
      L -= pow(2, i - 1);
    }
  }

  // for (int i = 0; i != vr.size(); i++) {
  //   cout << vr[i] << vl[i] << w[i] << endl;
  // }
  for (int i = 1; i <= r; i++){
    vr.push_back(i);
    vr.push_back(i);
    vl.push_back(i + 1);
    vl.push_back(i + 1);
    w.push_back(pow(2, i - 1));
    w.push_back(0);
  }

  cout << (r + 1) << " " << vr.size() << endl;
  for (int i = 0; i != vr.size(); i++){
    cout << vr[i] << " " << vl[i] << " " << w[i] << endl;
  }



  return 0;
}


Measured memory_bytes: 256
import sys
Input = sys.stdin.readline

H, W, D = map(int, Input().split())
A = [list(map(int, Input().split())) for _ in range(H)]
Q = int(Input())
LR = [list(map(int, Input().split())) for _ in range(Q)]
num_pos = {}

for y, line in enumerate(A):
    for x, num in enumerate(line):
        num_pos[num] = (x, y)

cost_table = {}
for num in range(1, H*W+1):
    if num <= D:
        cost_table[num] = 0
    else:
        i, j = num_pos[num-D]
        x, y = num_pos[num]
        cost_table[num] = abs(i - x) + abs(j - y) + cost_table[num-D]

for l, r in LR:
    print(cost_table[r] - cost_table[l])

Measured memory_bytes: 61048
import sys #sys.stdin.readline()
import heapq #heap
from collections import defaultdict
fastinp = lambda: sys.stdin.readline().split(' ')
inp = lambda: input().split(' ')
ml = lambda x, y=int: list(map(y, x))
debug = lambda *args: print(*args, sep=' | ')
a, b, c = ml(inp())
if a == b and a != c:
    print('Yes')
elif b == c and a != b:
    print('Yes')
elif a == c and b != a:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3444
using System;
    using System.Text;
    using System.Collections.Generic;
    using static System.Math;
    using System.Linq;
    using static System.Array;

    namespace ConsoleApp2
    {
        class Program
        {


            static void Main(string[] args)
            {
            var K = long.Parse(Console.ReadLine());
            var AB = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var ans = "NG";
            for (long i = AB[0]; i <= AB[1]; i++)
            {
                if (i%K == 0)
                {
                    ans = "OK";
                    break;
                }
            }


                Console.WriteLine(ans);
            }
        }
    }


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

int main() {
	int n,k;
	
	cin>>n;
  	cin>>k;
	int arr[n],dp[n+1];
	for(int i=0;i<n;i++){
		cin>>arr[i];
		
	}
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
		dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
      for(int j=2;j<=k;j++){
        if(i-j>=0){
        dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
        }
      }
	}
	
	cout<< dp[n-1];
	return 0;
}


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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
} 

void solve()
{
    ll k,n;
    cin >> k >> n;
    vll a(n);
    for(ll i=0;i<n;i++) {
      cin >> a[i];
    }
    ll ans = a[n-1] - a[0];
    for(ll i=1;i<n;i++) {
      ans = min(ans, k + a[i-1] - a[i]);
    }
    cout << ans << "\n";
}

int main()
{
    // FAST_IO;
    // #ifndef ONLINE_JUDGE 
    //   OC;
    // #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

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

public class Hello
{
    public static void Main()
    {
        var w = "abcdefghijklmnopqrstuvwxyz";
        var d = new Dictionary<char, int>();
        for (int i = 0; i < 26; i++) d[w[i]] = i;
        var a = new int[26];
        var b = new int[10];
        var s = Console.ReadLine().Trim();
        for (int i = 0; i < s.Length; i++)
        {
            int tp;
            if (int.TryParse(s[i].ToString(), out tp)) b[tp]++;
            else a[d[s[i]]]++;
        }
        var ret = getAns(a);
        var ret2 = getAns(b);
        Console.WriteLine(ret + ret2);
    }
    public static int getAns(int[] a)
    {
        var asum = a.Sum();
        if (asum == 0) return 0;
        var aL = a.Length;
        var sumc = 0; var count = 0;
        while (true)
        {
            var nowL = 0;
            var discov = false;
            for (int i = 0; i < aL; i++)
            {
                if (a[i] >= 1) { nowL++; a[i]--; }
                else
                {
                    if (nowL >= 4) { count++; sumc += nowL; discov = true; }
                    nowL = 0;
                }
            }
            if (nowL >= 4) { count++; sumc += nowL; discov = true; }
            if (!discov) break;
        }
        return asum - (sumc - 3 * count);
    }
}


Measured memory_bytes: 10076
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main()
{
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S,T;
  cin>>S>>T;
  bool flag=true;
  map<char,char> ma1, ma2;
  for(int i=0;i<S.size();i++){
    if(ma1.count(S[i])&&ma1[S[i]]!=T[i]) flag=false;
    if(ma2.count(T[i])&&ma2[T[i]]!=S[i]) flag=false;
    ma1[S[i]]=T[i];
    ma2[T[i]]=S[i];
  }
  if(flag){
    puts("Yes");
  }else{
    puts("No");
  }

}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var s = int.Parse(Console.ReadLine());
        Func<int, int> f = x => x % 2 == 0 ? x / 2 : 3 * x + 1;

        var dic = new Dictionary<int, int>();
        var m = 1;
        var a = s;
        while (!dic.ContainsKey(a))
        {
            dic.Add(a, m);
            m++;
            a = f(a);
        }
        Console.WriteLine(m);
    }
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n, a, b, c, d;
string s;

bool check_reach(int start, int end) {
  for (int i = start; i <= end - 1; ++i) {
    if (s[i] == '#' && s[i + 1] == '#') {
      return false;
    }
  }
  return true;
}

bool check_triple() {
  bool ret = false;
  for (int i = b; i <= d; ++i) {
    if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') ret = true;
  }

  return ret;
}

int main(void) {
  // Here your code !
  scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);

  cin >> s;

  s = '#' + s + '#';

  if (!check_reach(a, c) || !check_reach(b, d)) {
    printf("No\n");
    return 0;
  }

  if (c < d) {
    printf("Yes\n");
    return 0;
  }

  if (check_triple()) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 772
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int key){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node*)malloc(sizeof(Node));
    z->key = key;
    z->left = NIL;
    z->right = NIL;

    while(x!= NIL){
        y = x;
        if(z->key < x->key) x = x->left;
        else x = x->right;
    }
    z->parent = y;
    if(y == NIL) root = z;
    else{
        if(z->key < y->key) y->left = z;
        else y->right = z;
    }
}

void inorder(Node *u){
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}
void preorder(Node *u){
    if(u==NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

Node *find(int key, Node* node){
    while(node!=NIL && key!=node->key){
        if(key < node->key) node = node->left;
        else node = node->right;
    }
    return node;
}

int main(){
    int n, x;
    string com;
    Node *u;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> com;
        if(com == "insert"){
            cin >> x;
            insert(x);
        }
        else if(com == "print"){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
        else if(com == "find"){
            cin >> x;
            u = find(x, root);
            if(u != NIL) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 21980
import Control.Monad
main=do
 [n,m]<-map read.words<$>getLine :: IO [Int]
 sl<-replicateM m (map read.words<$>getLine) :: IO [[Int]]
 let sp=foldl1(\x y->let p=if head x<head y then head y else head x;q=if last x>last y then last y else last x in [p,q])sl
 print$length$[head sp..last sp]

Measured memory_bytes: 135548
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <utility>
#include <valarray>
#include <vector>

#define rep(i, a, n) for(int i = (a);i < (n);i++)
#define REP(i, n)    rep(i, 0, n)
#define all(e)       (e).begin(), (e).end()

#ifdef LOCAL
#define show(x) cerr<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl;
#else
#define show() true
#endif

using namespace std;
using ll=long long;
template<class T> using V=vector<T>;

template<class T, class U>
void chmin(T &t, const U u) { if (t > u) t = u; }

template<class T, class U>
void chmax(T &t, const U u) { if (t < u) t = u; }

const int INF = (1 << 30) - 1;
const ll INFL = (ll) 5e15;
const int MOD = 1000000007;

using P=pair<int, int>;

class Solver {
public:
    bool solve() {
        cin >> W >> H;
        if (W == 0 && H == 0) return false;

        field.resize(W, V<int>(H));
        REP(y, H) {
            REP(x, W) {
                cin >> field[x][y];
            }
        }

        int c = 2;
        REP(y, H) {
            REP(x, W) {
                if (field[x][y] == 1) {
                    bfs(P(x, y), c);
                    ans++;
                }
            }
        }

        cout << ans << endl;
        return true;
    }

private:
    int H, W;
    V<V<int>> field;
    int ans = 0;

    int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

    void bfs(P s, int c) {
        queue<P> que;
        que.push(s);
        field[s.first][s.second] = c;
        while (que.size()) {
            P cur = que.front();
            que.pop();

            for (int i = 0; i < 8; ++i) {
                P next = {cur.first + dx[i], cur.second + dy[i]};
                if (check(next) && field[next.first][next.second] == 1) {
                    que.push(next);
                    field[next.first][next.second] = c;
                }
            }
        }
    }

    bool check(P p) {
        if (p.first < 0 || p.first >= W) return false;
        if (p.second < 0 || p.second >= H) return false;
        return true;
    }
};

int main() {

    while (Solver().solve());

    return 0;
}



Measured memory_bytes: 3068
#include <stdio.h>

int main()
{
	int i, N, a = 0, sw = 1;
	char S[100000], T;

	scanf("%d", &N);

	for (i = 0; i < N; i++) {
		scanf("%s", &S[i]);
		if (sw == 1) {
			T = S[i];
			sw = 0;
		}
		if (T != S[i]) {
			a++;
		}
		T = S[i];
	}
	printf("%d", a + 1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
  for (ll i = 0; i < v.size(); ++i) \
    cout << v[i] << " ";            \
  cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)
#define get(n) \
  ll n;        \
  cin >> n
#define getvec(v, n)         \
  vector<ll> v(n);           \
  for (ll i = 0; i < n; i++) \
    cin >> v[i];
#define getstr(s) \
  string s;       \
  cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void mainSolve()
{
  get(l);
  get(r);
  get(d);
  ll ans(0);
  for (int i = l; i <= r; i++)
  {
    if (i % d == 0)
      ++ans;
  }
  p1(ans);
}

int main()
{
  fio;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // get(t);
  ll t = 1;
  while (t--)
  {
    mainSolve();
  }
  return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,v,b,w,t;cin>>a>>v>>b>>w>>t;
  if(a>b) b-=w*t;else b+=w*t;
  bool isok=(abs(b-a)<=v*t);
  print(isok?"YES":"NO");
  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
#define lint long long
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  string s;cin>>s;
  int n=s.length();
  if(s[n-1]=='1'){
    cout<<-1<<endl;
    return 0;
  }
  if(s[0]=='0'){
    cout<<-1<<endl;
    return 0;
  }
  rep(i,n/2){
    if(s[i]!=s[n-2-i]){
      cout<<-1<<endl;
      return 0;
    }
  }
  int cur=1;
  int nxt=2;
  for(int i=0;i<n-1;++i){
    if(i>=n/2){
      s[i]='0';
    }
    if(s[i]=='0'){
      printf("%lld %lld\n",cur,nxt);
      ++nxt;
    }
    else{
      printf("%lld %lld\n",cur,nxt);
      cur=nxt;
      ++nxt;
    }
  }
  int no=nxt-1;
  while(nxt<=n){
    printf("%lld %lld\n",no,nxt);
    ++nxt;
  }
  return 0;
}
//111010011111100101110

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M=0,ans=0;
  cin >>N;
  vector<int> A(1e5+1,0);
  for(int i=0; i<N; i++){
    int a;
    cin >>a;
    if(a>1e5){
      ans++;
      continue;
    }
    else A[a]++;
    M=max(M,a);
  }  
  for(int i=0; i<=M; i++){
    if(A[i]<i) ans+=A[i];
    else ans+=A[i]-i;
  }
  cout <<ans <<endl;
}


Measured memory_bytes: 640