akhauriyash/Code-Regression huggingface dataset:
#pragma region
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, a, n) for (int i = n; i >= a; --i)
namespace fastIO {
#define BUF_SIZE 100000
#define OUT_SIZE 100000
//fread->R
bool IOerror = 0;
//inline char nc(){char ch=getchar();if(ch==-1)IOerror=1;return ch;}
inline char nc() {
    static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
    if (p1 == pend) {
        p1 = buf;
        pend = buf + fread(buf, 1, BUF_SIZE, stdin);
        if (pend == p1) {
            IOerror = 1;
            return -1;
        }
    }
    return *p1++;
}
inline bool blank(char ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; }
template <class T>
inline bool R(T &x) {
    bool sign = 0;
    char ch = nc();
    x = 0;
    for (; blank(ch); ch = nc())
        ;
    if (IOerror) return false;
    if (ch == '-') sign = 1, ch = nc();
    for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 + ch - '0';
    if (sign) x = -x;
    return true;
}
inline bool R(double &x) {
    bool sign = 0;
    char ch = nc();
    x = 0;
    for (; blank(ch); ch = nc())
        ;
    if (IOerror) return false;
    if (ch == '-') sign = 1, ch = nc();
    for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 + ch - '0';
    if (ch == '.') {
        double tmp = 1;
        ch = nc();
        for (; ch >= '0' && ch <= '9'; ch = nc())
            tmp /= 10.0, x += tmp * (ch - '0');
    }
    if (sign)
        x = -x;
    return true;
}
inline bool R(char *s) {
    char ch = nc();
    for (; blank(ch); ch = nc())
        ;
    if (IOerror)
        return false;
    for (; !blank(ch) && !IOerror; ch = nc())
        *s++ = ch;
    *s = 0;
    return true;
}
inline bool R(char &c) {
    c = nc();
    if (IOerror) {
        c = -1;
        return false;
    }
    return true;
}
template <class T, class... U>
bool R(T &h, U &... t) { return R(h) && R(t...); }
#undef OUT_SIZE
#undef BUF_SIZE
};  // namespace fastIO
using namespace fastIO;
template <class T>
void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U>
void _W(const pair<T, U> &x) { _W(x.F), putchar(' '), _W(x.S); }
template <class T>
void _W(const vector<T> &x) {
    for (auto i = x.begin(); i != x.end(); _W(*i++))
        if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &... tail) { _W(head), putchar(sizeof...(tail) ? ' ' : '\n'), W(tail...); }
#pragma endregion
const int maxn = 1e5 + 5;
ll a[maxn], b[maxn];
int main() {
    ll D, T, S;
    R(D, T, S);
    W(T * S >= D ? "Yes" : "No");
}

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

class UnionFind(object):
    def __init__(self, N):
        # 初期状態を定義。ルートは -1から始まり、-X と負数でグループのサイズをもつ
        self.node = [-1] * N

    def root(self, x):
        if self.node[x] < 0:
            # それ自身がrootなら自分のポジションを返却
            return x
        else:
            # ルートを再帰で辿って、それぞれルートに直つなぎにする
            self.node[x] = self.root(self.node[x])
            # 自分がつながってるルートのポジションを返却
            return self.node[x]

    def size(self, x):
        # xが所属するグループのサイズを取得
        # サイズは負の数で管理されてるので、-1倍して返却
        return -self.node[self.root(x)]

    def connect(self, x, y):
        a = self.root(x)  # x のrootの位置
        b = self.root(y)  # y のrootの位置

        # もう同じグループなら何もしない
        if a == b:
            return

        # サイズが大きい方をaとして取り回す
        if self.size(a) < self.size(b):
            a, b = b, a

        # aのサイズをbのサイズを含む形に更新する（負数同士の足し算）
        self.node[a] += self.node[b]
        # bをaに連結する
        self.node[b] = a

        return

    def show_nodes(self):
        return self.node


def main():
    N, M, K = map(int, input().split())

    tree = UnionFind(N)

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

    for A, B in friends:
        tree.connect(A-1, B-1)

    ans = [tree.size(x) - 1 for x in range(N)]

    for A, B in friends:
        if tree.root(A-1) == tree.root(B-1):
            ans[A-1] -= 1
            ans[B-1] -= 1

    for _ in range(K):
        C, D = map(int,input().split())
        if tree.root(C - 1) == tree.root(D - 1):
            ans[C-1] -= 1
            ans[D-1] -= 1

    print(*ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38076
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

struct INFO {
	int x, k;
	INFO(int x=0,int k=0):x(x),k(k){}

	bool operator<(const INFO& r)const {
		return x < r.x;
	}
};

#define MOD (int)(1e9+7)

int main() {
	int N; cin >> N;
	vector<INFO>AB(2 * N);
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		AB[i] = INFO(a, 0);
	}
	for (int i = 0; i < N; i++) {
		int b; cin >> b;
		AB[N+i] = INFO(b, 1);
	}

	sort(AB.begin(), AB.end());

	long long ans = 1;
	int m = AB[0].k;
	int cnt = 0;
	for (int i = 0; i < 2*N; i++) {
		if (AB[i].k == m) {
			cnt++;
		}
		else {
			if (cnt == 0) {
				m = AB[i].k;
				cnt++;
				continue;
			}

			ans *= cnt;
			ans %= MOD;
			cnt--;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    long long a,b;
    cin>>a>>b;
    if(a+b>=a-b && a+b>=a*b){
        cout<<a+b<<endl;
    }
    if(a-b>a+b && a-b>=a*b){
        cout<<a-b<<endl;
    }
    if(a*b>a-b && a*b>a+b){
        cout<<a*b<<endl;
    }
}


Measured memory_bytes: 256
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int N;

  cin>>N;

  if(N%10==9||N/10==9){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;

}




Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]

a_sorted = sorted(a)
a_max1 = a_sorted[-1]
a_max2 = a_sorted[-2]
for a_i in a:
    if a_i == a_max1:
        print(a_max2)
    else:
        print(a_max1)


Measured memory_bytes: 19052
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int x,y,ans;
int main() {
	scanf("%d%d",&x,&y);
	if (x==1)ans+=300000;
	if (x==2)ans+=200000;
	if (x==3)ans+=100000;
	if (y==1)ans+=300000;
	if (y==2)ans+=200000;
	if (y==3)ans+=100000;
	if (x==1 && y==1)ans+=400000;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
wa = [0]*N
ac = [0]*N

for i in range(M):
  p, s = map(str, input().split())
  p = int(p)
  if (s=='WA') and (ac[p-1]==0):
    wa[p-1] += 1
  else:
    ac[p-1] = 1
    
    
ans_ac = 0
ans_wa = 0
for i in range(N):
  if ac[i] == 1:
    ans_ac += 1
    ans_wa += wa[i]
    
print(str(ans_ac), str(ans_wa))

Measured memory_bytes: 10140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int w;
  while (cin >> w, w != -1) {
    int cost = 1150;
    if (w > 30) {
      cost += (w - 30) * 160;
      w = 30;
    }
    if (w > 20) {
      cost += (w - 20) * 140;
      w = 20;
    }
    if (w > 10) {
      cost += (w - 10) * 125;
    }
    cout << 4280 - cost << endl;
  }

  return 0;
}


Measured memory_bytes: 3120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var total = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).Sum();

            var result = nm[0] - total;
            Console.WriteLine(result < 0 ? -1 : result);
        }
    }
}

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


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

  ll n, a, b; cin >> n >> a >> b;
  ll ans = 0;

  vi x(n);
  rep(i, n) cin >> x[i];

  rep2(i, 1, n-1) {
    ans += min(a * (x[i] - x[i-1]), b);
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3716
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    while 1:
        n = I()
        if n == 0:
            quit()
        a = LI()
        m = sum(a)/n
        c = 0
        for i in range(n):
            if a[i] <= m:
                c += 1
        print(c)
    return

#B
def B():
    while 1:
        n = I()
        if n == 0:
            quit()
        t = [0 for i in range(24*3600)]
        for i in range(n):
            x,y = input().split()
            x = list(map(int, x.split(":")))
            y = list(map(int, y.split(":")))
            l = x[0]*3600+x[1]*60+x[2]
            r = y[0]*3600+y[1]*60+y[2]
            t[l] += 1
            t[r] -= 1
        ans = 0
        for i in range(24*3600-1):
            t[i+1] += t[i]
            ans = max(ans, t[i])
        print(ans)
    return
#C
def C():
    n = I()
    if n == 0:
        print(1)
    elif n == 1:
        print(2)
    elif n == 2:
        print(1)
    else:
        print(0)
    return

#D
def D():
    def dijkstra(s):
        d = [float("inf") for i in range(n)]
        q = [[0,s]]
        d[s] = 0
        while q:
            dx,x = heappop(q)
            for y in v[x]:
                if dx+1 < d[y]:
                    d[y] = d[x]+1
                    heappush(q,[d[y],y])
        return d
    n,m,s,t = LI()
    s -= 1
    t -= 1
    v = [[] for i in range(n)]
    for i in range(m):
        x,y = LI()
        x -= 1
        y -= 1
        v[x].append(y)
        v[y].append(x)
    l = dijkstra(s)
    l2 = dijkstra(t)
    k = l[t]-2
    d = defaultdict(int)
    ans = 0
    for i in l2:
        d[i] += 1
    for i in l:
        ans += d[max(-1,k-i)]
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    D()



Measured memory_bytes: 41200
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
   string N;
   cin>> N;
    int S,x;
    S=0;
    x=0;
     for(unsigned int i=0;i<N.size();i++){
        S += N.at(i)-48;
         x += (N.at(i)-48)*pow(10,N.size()-i-1);
     }

 if(x%S==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
      
    }
    
 
   
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n;
	ll y;

	cin>>n;
	cin>>y;

	ll d=0;
	rep(i,y/10000+1){
		rep(j,y/5000+1){
			d=10000*i+5000*j;
			if(y==d&&i+j==n){
				cout<<i<<" "<<j<<" "<<"0"<<endl;
				return 0;
			}else if(i+j+((y-d)/1000)==n&&((y-d)/1000)>=0){
				cout<<i<<" "<<j<<" "<<((y-d)/1000)<<endl;
				return 0;
			}
		}
	}
	cout<<"-1"<<" "<<"-1"<<" "<<"-1"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end() 
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repr(i, a, b) for(int i = a - 1; i >= b; i--)
#define iter(m) for(auto it = m.begin(); it != m.end(); it++)
#define iterr(m) for(auto it = m.rbegin(); it != m.rend(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);

signed main(){
    speed;
    int n; cin >> n;
    stack<char> st;
    string s; cin >> s;
    rep(i, 0, s.size()) {
        char c; c = s[i];
        if(st.empty()) {
            st.push(c);
        } else {
            if(st.top() != c && st.top() == '(') {
                st.pop();
            } else {
                st.push(c);
            }
        }
    }
    int cnt1 = 0, cnt2 = 0;
    while(!st.empty()) {
        if(st.top() == '(') cnt2++;
        else cnt1++;
        st.pop();
    }
    rep(i, 0, cnt1) cout << '(';
    cout << s;
    rep(i, 0, cnt2) cout << ')';
    return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    
    int N, K;
    cin >> N >> K;
    for(int i = 1; i <= N; i++){
        char c;
        cin >> c;
        if(i != K)cout << c;
        else cout << char(c - 'A' + 'a');
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  char moji[1000];
  int i;
  gets(moji);
  for(i=0;i<strlen(moji);i++){
    if('a'<= moji[i] && moji[i]<='z'){
      moji[i]-=32;
    }
  }
  printf("%s\n",moji);
  return 0;
}

Measured memory_bytes: 524
/**
   Solution by Abil
**/
#include <bits/stdc++.h>

# define fr first
# define sc second
# define pb push_back
# define mk make_pair
# define ll long long
# define sz(s) s.size()
# define all(s) s.begin(),s.end()
# define int long long
using namespace std;
const long long N = (1e6 + 10);

main()
{
    int n, m;
    cin >> n >> m;
    if(n == 1)
    {
      cout << m;
      return 0;
    }
    for(int i = m/n;i >= 1; i--)
    {
      if(m % i == 0 && (m/i) >= n)
      {
        cout << i;
        return 0;
      }
    }
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int main()
{
	int r;
	cin>>r;
	printf("%.20lf\n",(double)r*2*3.1415926);
	return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N), B(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];

    vl AI(N), BI(N);
    iota(all(AI), 0ll), iota(all(BI), 0ll);
    sort(all(AI), [&](ll i, ll j) { return A[i] < A[j]; }), sort(all(BI), [&](ll i, ll j) { return B[i] < B[j]; });

    vl SA = A, SB = B;
    sort(all(SA)), sort(all(SB));
    rep(i, N){
        if(SA[i]>SB[i]){
            cout << "No" << endl;
            return 0;
        }
    }

    vl R(N);
    rep(i, N) R[AI[i]] = BI[i];

    vc<bool> T(N);
    ll cnt = 0, now = 0;
    while(!T[now]){
        T[now] = true;
        now = R[now];
        cnt++;
    }

    if(cnt<N){
        cout << "Yes" << endl;
        return 0;
    }

    rep(i, N - 1){
        if(A[AI[i + 1]] <= B[BI[i]]){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

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


int main(){ 
long long x;
  cin>>x;
  long long init=100;
  long long years=0;
  while(true){++years;
    init+=init/100;
    if(init>=x)
      break;
    
  }
  cout<<years;
    
  
  
    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
typedef pair<int,int> pii;

int imos[30][100003];

int main() {
  int n,C;
  while(cin>>n>>C) {
    memset(imos,0,sizeof(imos));
    for (int i=0;i<n;i++) {
      int s,t,c;
      scanf("%d %d %d",&s,&t,&c);
      c--;
      imos[c][s]++;
      imos[c][t]--;
      // cout << c << " "<< s << " " << t << endl;
    }
    int ans = 0;
    for (int i=0;i<=100001;i++) {
      int cnt = 0;
      REP(c, C) {
        imos[c][i+1] += imos[c][i];
        cnt += imos[c][i] || imos[c][i+1];
      }
      // cout << endl;
      // cout << cnt << endl;
      ans = max(ans, cnt);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 11904
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(lint ngtkana_is_a_genius=0; ngtkana_is_a_genius<(lint)k; ngtkana_is_a_genius++)
using lint=long long;
using ld=long double;
template<class T> using numr=std::numeric_limits<T>;
struct input_t {
    template<class T> operator T() {
        T t;
        std::cin>>t;
        return t;
    }
} input;
#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

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

    std::string s=input, t=input;
    std::cout << 
        (s == t.substr(0, s.length()) ? "Yes": "No") <<'\n';
}


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


int main(void){
  string S;
  long long K;
  cin >> S >> K;
  int temp = 0;
  while(K > 0){
    if(int(S[temp] - '0') > 1) {
      cout << S[temp];
      return 0;    
    }
    K--;
    temp++;
  }
  cout << S[temp - 1];
  return 0;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 305;

int dp[MAX_N][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        vector<int> vec(n);
        rep(i,n){
            cin >> vec[i];
        }
        rep(i,n){
            rep(j,n+1){
                dp[i][j] = 0;
            }
        }
        for(int i=2;i<=n;i++){
            rep(j,n-i+1){
                if(dp[j+1][j+i-1] == i-2 && abs(vec[j]-vec[j+i-1]) <= 1){
                    dp[j][j+i] = i;
                }
                for(int k=j+1;k<j+i;k++){
                    dp[j][j+i] = max(dp[j][j+i],dp[j][k]+dp[k][j+i]);
                }
            }
        }
        cout << dp[0][n] << endl;
    }
    return 0;
}

Measured memory_bytes: 3444
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
table = []
for i in range(N):
    table.append((A[i], 1))
for i in range(M):
    b, c = map(int, input().split())
    table.append((c, b))

table = sorted(table)
cnt = N
ans = 0
while cnt > 0:
    #print(ans,s)
    c, b = table.pop()
    if b >= cnt:
        ans += c*cnt
        break
    ans += c*b
    cnt -= b
print(ans)


Measured memory_bytes: 70936
//abc123 b 最後に注文するものを決める
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int d,n; cin>>d>>n;
    int a=1;
    //if(d==0) cout<<n<<endl;
    for(int i=0;i<d;i++){
        a*=100;
    }
    //nが100かそれ以外かで場合分けする
    if(n<100){
        cout<<a*n<<endl;
    }
    else cout<<a*101<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	ar := make([]int, n)
	br := make([]int, n)
	for i := range ar {
		fmt.Scan(&ar[i], &br[i])
	}
	sum := 0
	for i := n - 1; i >= 0; i-- {
		if md := (sum + ar[i]) % br[i]; md != 0 {
			sum += br[i] - md
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int n;
void maxheapify (vector<int> &a, int i) {
    int l = i * 2 + 1 < n ? i * 2 + 1 : i;
    int r = i * 2 + 2 < n ? i * 2 + 2 : i;
    int large;
    if (a[l] > a[i] && a[l] > a[r]) {
        large = l;
    } else if (a[r] > a[i] && a[r] > a[l]) {
        large = r;
    } else {
        large = i;
    }
    if (large != i) {
        swap (a[i], a[large]);
        maxheapify (a, large);
    }
}
int main() {
    cin >> n;
    vector<int> a (n);
    rep (i, n) cin >> a[i];
    for (int i = n / 2; i >= 0; i--) {
        maxheapify (a, i);
    }
    rep (i, n) cout << " " << a[i];
    cout << "\n";
}



Measured memory_bytes: 4604
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

int main () {
    
    ll n;
    cin >> n;

    vector<ll> a(5, 0);
    int mni = -1;
    ll mn = 10000000000000000;
    for(int i = 0; i < 5; i++)
    {
        cin >> a[i];
        if(mn > a[i]) {
            mn = a[i];
            mni = i;
        } 
    }

    ll ans = 0;
    if(n % mn == 0) {
        ans = n/mn;
    } else {
        ans = n/mn + 1;
    }
    ans += 4;

    cout << ans << endl;
    return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    ve<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) a[i]--;
    ve<int> s(n+1);
    s[0] = 0;
    rep(i,n) s[i+1] = (s[i] + a[i]) % k;
    map<int,int> mp;
    queue<int> q;
    ll ans = 0;
    rep(j,n+1){
        ans += mp[s[j]];
        mp[s[j]]++;
        q.push(s[j]);
        if(q.size() == k){
            mp[q.front()]--;
            q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15044
#include <stdio.h>

int main()
{
	int n=0,x=0,count,a,b,c;
	while(1)
	{
		scanf("%d %d",&n,&x);
		if((x==0)&&(n==0))
		{
			break;
		}
		count=0;
		for(a=1;a<=n-2;a++)
		{
			for(b=a+1;b<=n-1;b++)
			{
				for(c=b+1;c<=n;c++)
				{
					if((a+b+c)==x) count++;
				}
			}
		}
		printf("%d\n",count);
	}
	return  0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(){
	char x,fh[2]={'-','+'};
	int a[4],i,j,k,sum;
	for(i=0;i<4;i++)
	{
		cin>>x;
		a[i]=x-'0';
	}
	for(i=0;i<=1;i++)
	{
		for(j=0;j<=1;j++)
		{
			for(k=0;k<=1;k++)
			{
				sum=a[0];
				if(i)
				{
					sum+=a[1];
				}
				else
				{
					sum-=a[1];
				}
				if(j)
				{
					sum+=a[2];
				}
				else
				{
					sum-=a[2];
				}
				if(k)
				{
					sum+=a[3];
				}
				else
				{
					sum-=a[3];
				}
				if(sum==7)
				{
					cout<<a[0]<<fh[i]<<a[1]<<fh[j]<<a[2]<<fh[k]<<a[3]<<"=7"<<endl;
					return 0;
				}
			}
		}
	}
	return 0;
}


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

int main(){
  int X,Y;
  int t,k,temp;
  cin >> X >> Y;

  if(X<=100 && Y<=100){
    if(X>=1 && Y>=1){

      k = (Y - (X * 2))/2;
      if(k<0){
        k = 0;
      }
      t = X - k;
      if(t<0){
        t = 0;
      }

      temp = k*4 + t*2;

      if(temp == Y){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
    }
  }
}

Measured memory_bytes: 3676
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int a = Integer.parseInt(input[0]);
        int b = Integer.parseInt(input[1]);
        int gcd = 1;
        if (a > b) {
            int temp = b;
            b = a;
            a = temp;
        }
        int i = 2;
        while (i <= a) {
            if (a%i == 0 && b%i == 0) {
                gcd *= i;
                a /= i;
                b /= i;
            } else i++;
        }

        System.out.println(gcd);
    }
}

Measured memory_bytes: 24452
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int i=0, n;
	scanf("%d", &n);
	char s[10001];
	scanf("%s", s);
	while(s[i] != '\0'){
		if(s[i]+n > 'Z'){
			s[i] = (s[i] + n) - ('Z'+1) + 'A';
		}else{
			s[i] += n;
		}
		i++;
	}
	printf("%s", s);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
  int N;
  int H[200];
  scanf("%d", &N);
  for(int i=1;i<=N;i++)
    scanf("%d", H+i);
  int max=0, ans=N;
  for(int i=1;i<=N;i++){
    if(H[i]>=max){
      max=H[i];
    }else{
      ans--;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1732
# include <bits/stdc++.h>
# define ll long long
# define f first
# define s second
const ll N = 3e5 + 10 , mod = 1e9 + 7 , INF = 1e9 + 100;
using namespace std;
int main(){
	int n;
	string s;
	cin >> n >> s;
	string T = s.substr(0 , n / 2);
	T = T + T;
	if(T == s) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
computeMax :: Integral a => a -> a -> a
computeMax n d
    | odd n = 127 * (n - 1) + d
    | otherwise = 127 * n - d

main :: IO ()
main = do
    _ <- getLine
    putStr . unlines .
        fmap (show . (\[n, d] -> computeMax n d) .
            fmap (read :: String -> Int) . words) . lines =<< getContents


Measured memory_bytes: 1276
import java.util.Scanner;


public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		
		String sign;
		if(a < b && b< c)
			sign = "Yes";
		else 
			sign = "No";
		
		System.out.println(sign);
	}
}

Measured memory_bytes: 26128
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input!(n: i64);
    puts!("{}\n", 800 * n - 200 * (n / 15));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextInt();
		long B = sc.nextInt();
		long C = sc.nextInt();
		boolean can = false;

		for (int i = 0; i <= B; i++) {
			if (A * i % B == C) can = true;
		}

		if (can) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21716
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]



x,y,z = map(int, input().split())

ans = x // (y+z)

if (x % (y+z) < z):
    ans -= 1
print(max(0,ans))


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

using namespace std;

const int INF = 1 << 30;

int main()
{
  int N, A[100000], B[100000];
  cin >> N;
  int mx = -INF;
  for(int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    mx = max(mx, A[i]);
  }
  for(int i = 0; i < N; i++) {
    if(A[i] == mx) {
      cout << B[i] + A[i] << endl;
      return(0);
    }
  }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define PI 3.14159265358979323846264338327950288419716939937510
#define mp make_pair
#define vvl vector<vector<ll>>
#define vll vector<ll>
#define vpll vector<pll>
ll inf = 1e18;
ll p = 1e9 + 7;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(ll x, ll y)
{
    ll res = 1;
    x = x ;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) ;
        y = y >> 1;
        x = (x * x) ;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i, j, y, x,  z, w, g, key,  k, n, m, a, b, t, c, d;
    ll t2, t3, t4, t1, t5, t6;
    string s;
    cin >> n;
    ll num = power(10, n, p);
    t1 = power(8, n, p);
    t2 = power(9, n, p);
    t3 = power(9, n, p);
    ll ans = (num - t1 + p) % p;
    ll a2 = (num - t2 + p) % p;
    ll a3 = (num - t3 + p) % p;
    ans = (a2 + a3 - ans + 2 * p) % p;
    cout << ans;

    return 0;
}

Measured memory_bytes: 3648
n = int(input())
P = list(map(int, input().split()))
ans0 = 0
ans = 0
co = 0
for i in range(n):
    if P[i] == i+1:
        co = 1
        ans0 += 1
    else:
        if co == 1:
            co = 0
            #print("seisan")
            ans += -((-ans0) // 2)
            ans0 = 0

if co == 1:
    co = 0
    #print("seisan")
    ans += -((-ans0) // 2)

print(ans)


Measured memory_bytes: 14008
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))

n = II()
train = [list(MI()) for _ in range(n-1)]

for i in range(n-1):
    # 開通式が開始するまでの時間+次の駅に到着するまでの時間
    time = train[i][0] + train[i][1]
    for j in range(i+1, n-1):
        # 駅に着いた時まだ開通式後の最初の電車が駅を発車していない場合
        if time < train[j][1]:
            # 駅を出発する時刻は開通式の時刻になる
            time = train[j][1]
        elif time % train[j][2] == 0:  # そのまま出発可能
            pass
        else: # time % train[j][2] != 0 待ち時間を加算する必要がある
            time += (train[j][2] - (time % train[j][2]))

        time += train[j][0]  # 次の駅へ行くための時間

    print(time)
print(0)



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

int main() {
  double r,l;
  cin >> r;
  l=2*r*3.1415926535;
  printf("%.8lf",l);
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int n;
    lint d;
    scanf("%d%lld", &n, &d);
    lint x[n], y[n];
    int ans = 0;
    rep(i, n){
        scanf("%lld%lld", &x[i], &y[i]);
        ans += (x[i]*x[i] + y[i]*y[i] <= d*d);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 6932
import java.util.*;

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

    int r = sc.nextInt();
    int d = sc.nextInt();
    int x = sc.nextInt();
    int ans[] = new int[11];
    ans[0] = x;

    for(int i = 1; i < 11; i++){
      ans[i] = r * ans[i - 1] - d;
      System.out.println(ans[i]);
     }
  }
}


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

int main() 
{
    string S,T;
    cin >> S >> T;
    int ans = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3916
import collections

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

Atmp = 0
Btmp = 0

INF=10e18


C=collections.Counter(A)
D=collections.Counter(B)

currentC = 0
currentD = 0

rotation = 0



for n in range(N+1):

	if N < C[n] + D[n]:
		rotation = INF
		break

	currentC += C[n]
	rotation = max( rotation, currentC - currentD )
	currentD += D[n]

if rotation == INF:
	print("No")
else:
	print("Yes")
	
	print(" ".join(map(str,B[-rotation:] + B[:-rotation])))






Measured memory_bytes: 68284
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

k = int(input())

import functools
from fractions import gcd

cache = dict()

ab = []
for a in range(1, k + 1):
    for b in range(1, k + 1):
        i1, i2 = min(a, b), max(a, b)
        if (i1, i2) in cache:
            ab.append(cache[(i1, i2)])
            continue
        v = gcd(i1, i2)
        cache[(i1, i2)] = v
        ab.append(v)

ans = 0
for d in ab:
    for c in range(1, k + 1):
        i1, i2 = min(d, c), max(d, c)
        if (i1, i2) in cache:
            ans += cache[(i1, i2)]
            continue
        v = gcd(i1, i2)
        cache[(i1, i2)] = v
        ans += v

print(ans)


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

int main(){
  
  int a,b,x;
  
  cin >> a >> b >> x;
  
  if(a > x || a + b < x){
    cout << "NO" << endl;
    return 0;
  }
  
  cout << "YES" << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <bitset>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);

constexpr int64 MOD = 1000000007;




int main()
{
    int64 a, b, k;
    cin >> a >> b >> k;

    int64 decA = min(a, k);
    a -= decA;
    k -= decA;

    if (k == 0)
    {
        cout << a << " " << b << endl;
        return 0;
    }

    int64 decB = min(b, k);
    b -= decB;
    cout << a << " " << b << endl;

    return 0;
}


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

int main() {
  int W, H, n;
  cin >> W >> H >> n;
  vector<set<int>> a(4);
  a[0].insert(0);
  a[1].insert(W);
  a[2].insert(0);
  a[3].insert(H);
  rep(i,n) {
    int x, y, A;
    cin >> x >> y >> A;
    A--;
    if(A<=1) a[A].insert(x);
    else a[A].insert(y);
  }
  int w=*begin(a[1])-*rbegin(a[0]);
  int h=*begin(a[3])-*rbegin(a[2]);
  if(w<0||h<0) w=0;

  cout << w*h << endl;
}

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

int main(){
  string list[4] = {"dream","dreamer","erase","eraser"};
  string S;
  cin >> S;
  reverse(S.begin(),S.end());
  for(int i=0;i<4;++i){
    reverse(list[i].begin(),list[i].end());
  }
  bool rep = false;
  bool result = false;
  for(int i=0;i<S.size();){
    rep = false;
    for(int j=0;j<4;++j){
      if(S.substr(i,list[j].size()) == list[j]){
        i += list[j].size();
        rep = true;
        break;
      }
    }
    if(!rep){
      break;
    }
    if(i == S.size()){
      result = true;
    }
  }
  if(result){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char buf[1<<20],*p1,*p2;
#define GC (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
template<class T> inline void read(T &n){
	char ch=GC;T w=1,x=0;
	while(!isdigit(ch)){if(ch=='-') w=-1;ch=GC;}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=GC;}
	n=x*w;
}
const int maxn=200005;
int n,a[maxn],deg[maxn];
int vis[maxn],isc[maxn],link[maxn];
int cnt[maxn],ans=1;
const int mod=1e9+7;
inline int add(int x,int y){
	x+=y;return x>=mod?x-mod:x;
}
inline int mul(int x,int y){
	return 1ll*x*y%mod;
}
void solve(int x){
	int now=0,fir=0,firl=0,lst=0;
	for(;isc[x];x=a[x]){
		now++,isc[x]=0;
		if(link[x]){
			if(!fir) fir=lst=now,firl=link[x];
			else{
				int tmp=now-lst;
				if(tmp<link[x]) puts("0"),exit(0);
				if(tmp>link[x]) ans=add(ans,ans);
				lst=now;
			}
		}
	}
	if(!fir) cnt[now]++;
	else{
		int tmp=fir+now-lst;
		if(tmp<firl) puts("0"),exit(0);
		if(tmp>firl) ans=add(ans,ans);
	}
}
int f[maxn]={1};
int main(){
	read(n);
	for(int i=1;i<=n;i++) read(a[i]),deg[a[i]]++;
	for(int i=1,j;i<=n;i++){
		if(vis[i]) continue;
		for(j=i;!vis[j];j=a[j]) vis[j]=i;
		if(vis[j]!=i) continue;
		for(;!isc[j];j=a[j]) isc[j]=1;
	}
	for(int i=1;i<=n;i++)
		if((isc[i]&&deg[i]>2)||(!isc[i]&&deg[i]>1)) puts("0"),exit(0);
	for(int i=1,j;i<=n;i++){
		if(deg[i]) continue;
		int len=0;
		for(j=i;!isc[j];j=a[j]) len++;
		link[j]=len;
	}
	for(int i=1;i<=n;i++) if(isc[i]) solve(i);
	for(int i=1;i<=n;i++){
		if(!cnt[i]) continue;
		int flag=((i>1)&&(i&1));
		for(int j=1;j<=cnt[i];j++){
			flag?f[j]=add(f[j-1],f[j-1]):f[j]=f[j-1];
			if(j>1) f[j]=add(f[j],mul(f[j-2],mul(j-1,i)));
		}
		ans=mul(ans,f[cnt[i]]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4736
N = gets.to_i

a_list = []

gets.strip.split(/ /).each_with_index{|a, i|
	a = a.to_i
	a_list << [a - (i + 1), a, i]
}

#p a_list

a2, a, i = a_list.sort_by(){|x, y, z| x}[N / 2]
#p [a2, a, i]
b = a - (i + 1)

sadness = 0

a_list.each_with_index{|(a2, a, j), i|
	sadness += (a - (b + i + 1)).abs
}
puts sadness


Measured memory_bytes: 32120
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)
/**==Info==
*Program:
*Problem:
*Date:
*Algorithm:
*Stats:*/

bool debug=false;
template<typename T> struct pq_small{
	priority_queue<T,vector<T>,greater<T> > pq;
	void push(T x){
		pq.push(x);
	}

	void pop(){
		pq.pop();
	}

	int size(){
		return pq.size();
	}

	bool empty(){
		return pq.empty();
	}

	T top(){
		return pq.top();
	}
};

int n;
int k;
vector<int> nei[100005];
pq_small<pii> q;
int d[100005];

int main(int argc,char* argv[]){
	memset(d,-1,sizeof(d));
	
	qi;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		nei[a].push_back(b);
		nei[b].push_back(a);
	}
	cin>>k;
	for(int i=0;i<k;i++){
		int a,b;
		cin>>a>>b;
		a--;
		d[a]=b;
		q.push(make_pair(b,a));
	}
	
	while(!q.empty()){
		pii last=q.top();
		q.pop();
		for(int i=0;i<nei[last.second].size();i++){
			if(d[nei[last.second][i]]==-1){
				//cout<<"change"<<nei[last.second][i]<<"at"<<last.second<<endl;
				d[nei[last.second][i]]=d[last.second]+1;
				q.push(make_pair(d[nei[last.second][i]],nei[last.second][i]));
			}
		}
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<nei[i].size();i++){
			if(abs(d[nei[i][j]]-d[i])!=1){
				puts("No");
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	
	for(int i=0;i<n;i++){
		cout<<d[i]<<endl;
	}
	return 0;
}



Measured memory_bytes: 7924
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
		Array.Sort(a);
		if(a[0] == a[1] && a[2] == a[3]) Console.WriteLine("yes");
		else Console.WriteLine("no");
	}
}

Measured memory_bytes: 9452
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

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

	if (K <= 1e7){
		ll ans = 0;
		for (int ii = 0; ii < K; ++ii){
			ans = A[ans];
		}

		cout << ans + 1 << "\n";

	} else {
		map <ll, ll> m;
		vector <ll> v;
		ll idx = 0;
		ll cnt = 0;
		v.push_back(idx);
		while (true) {
			m[idx]++;
			if (m[idx] > 4){
				break;
			} else {
				idx = A[idx];
				v.push_back(idx);
			}
		}

		ll firstIdx = v.back();
		v.pop_back();

		vector <ll> ansv;
		int valid = 0;
		ll trashCnt = 0;
		int cntFlag = 1;
		for (int ii = 0; ii < v.size(); ++ii){
			if (v[ii] == firstIdx){
				valid = valid + 1;
				cntFlag = 0;
			}
			if (valid == 1){
				ansv.push_back(v[ii]);
			}
			if (cntFlag){
				trashCnt++;
			}
		}

		ll KK = K - trashCnt;
		ll priod = ansv.size();
		ll ans = ansv[KK % priod] + 1;
	
		cout << ans << "\n";
	}


	return 0;
}


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

int main()
{
  int n, m;
  cin >> n >> m;
  char c[n][n];
  char d[m][m];
  rep(i, n){
    rep(j, n) cin >> c[i][j];
  }
  rep(i, m){
    rep(j, m) cin >> d[i][j];
  }
  string ans = "No";
  int cnt = 0;
  for(int i = 0; i <= n - m; i++) {
    for(int j = 0; j <= n - m; j++) {
      for(int k = 0; k < m; k++) {
        for(int l = 0; l < m; l++) {
          if(c[i + k][j + l] == d[k][l]) cnt++;
        }
      }
      if(cnt == m * m) ans = "Yes";
      cnt = 0;
    }
  }
    
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  int t = 0;
  cin >> a >>b >>c;
    int d = a;
  while(a < c +0.5){
    t = t +b;
    a = a + d;
  }
  cout << t << endl;
}


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

int main()
{
	int x, y, temp;
	while(1)
	{
		cin >> x >> y;
		if ( x == 0 && y == 0)
		{
			break;
		}
		if ( x < y)
		{
			cout << x <<" "<< y <<endl;
		}
		else
		{
			cout << y <<" "<< x <<endl;
		}
	}
return 0;
}

Measured memory_bytes: 3064