akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define int ll

typedef pair<int,int> pi;
typedef vector<int> vi;
 
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define pb push_back

template<typename T> void max_self(T &a, T b) { a = max(a,b); return;}
template<typename T> void min_self(T &a, T b) { a = min(a,b); return;}
 
const int nax = 1e6 + 5;
const int mod = 1e9 + 7;

int modExpo(int a,int b,int c){
	if(b == 0) return 1;
	int answer = 1;
	while(b){
		if(b & 1) answer = ((answer % c) * (a % c)) % c;
		a = ((a % c) * (a % c)) % c;
		b /= 2; 
	}
	
	return answer;
}

signed main(){
	
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int t = 1;
	//cin >> t;
	while(t--){
		int n;
		cin >> n;
		
		map<string,int> m;
		
		for(int i = 0; i < n; ++i){
			string s;
			cin >> s;
			++m[s];
		}
		
		cout << "AC x " << m["AC"] << "\n";
		cout << "WA x " << m["WA"] << "\n";
		cout << "TLE x " << m["TLE"] << "\n";
		cout << "RE x " << m["RE"] << "\n";
	}	
	return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+9;
int arr[maxn];
int main(){
    int a,b,c,d,e,f,g,h;
    ios::sync_with_stdio(0);
    int n,m;
    while(cin>>n>>m){
        memset(arr,-1,sizeof(arr));
        for(int i=1;i<=m;i++){
            cin>>e>>f;
            if(arr[e]==-1){
                if(arr[f]==-1){
                    arr[e]=f;
                    arr[f]=e;
                }
                else{
                    h=arr[f];
                    arr[e]=h;
                    arr[h]=e;
                    arr[f]=-1;
                }
            }
            else{
                if(arr[f]==-1){
                    h=arr[e];
                    arr[h]=f;
                    arr[f]=h;
                    arr[e]=-1;
                }
                else{
                    if(e==arr[f]){
                        arr[e]=-1;
                        arr[f]=-1;
                    }
                    g=arr[f];
                    h=arr[e];
                    arr[g]=h;
                    arr[h]=g;
                    arr[e]=arr[f]=-1;
                }
            }
        }
        g=1;
        for(int i=1;i<=n;i++){
            if(arr[i]>-1){
                g=0;break;
            }
        }
        if(g)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
    cin >> N;
  
  int a=N/1000,b=N%1000/100,c=N%1000%100/10,d=N%1000%100%10;
    
    if (((a==b)&&(b==c))||((b==c)&&(c==d))){
      cout << "Yes" <<endl;
    }
  else {
    cout << "No" <<endl;
  }
}


Measured memory_bytes: 256
N, M = map(int, input().split())

diffs = [False] * N

a = 1
b = N
for _ in range(M):
    while True:
        diff0 = b-a
        diff1 = (N+a-b)
        if not diffs[diff0] and not diffs[diff1]:
            break
        b-=1
    diffs[diff0] = True
    diffs[diff1] = True
    print(str(a) + ' ' + str(b))
    a += 1
    b -= 1
    if b-a == (N+a-b):
        b-=1



Measured memory_bytes: 76052
#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 <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc045/tasks/arc061_a

int main() {
    string S; cin >> S;
    int len = S.length();
    ll ans = 0;

    for (int msk = 0; msk < 1 << (len - 1); msk++) {

        ll num = S[0] - '0';
        for (int i = 0; i < len -1; i++) {
            if (msk & 1 << i) {
                ans += num;
                num = 0;
            }
            num = num * 10 + (S[i + 1] - '0');
        }
        ans += num;
    }

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


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

template<uint32_t mod>
struct ModInt{
	uint32_t a;
	ModInt& s(uint32_t vv){
		a=vv<mod?vv:vv-mod;
		return *this;
	}

	ModInt(int64_t x=0){s(x%mod+mod);}

	ModInt& operator+=(const ModInt &x){return s(a+x.a);}
	ModInt& operator-=(const ModInt &x){return s(a+mod-x.a);}
	ModInt& operator*=(const ModInt &x){
		a=uint64_t(a)*x.a%mod;
		return *this;
	}
	ModInt& operator/=(const ModInt &x){
		*this*=x.inv();
		return *this;
	}

	ModInt operator+(const ModInt &x)const{return ModInt(*this)+=x;}
	ModInt operator-(const ModInt &x)const{return ModInt(*this)-=x;}
	ModInt operator*(const ModInt &x)const{return ModInt(*this)*=x;}
	ModInt operator/(const ModInt &x)const{return ModInt(*this)/=x;}
	bool operator==(const ModInt &x)const{return a==x.a;}
	bool operator!=(const ModInt &x)const{return a!=x.a;}
	bool operator<(const ModInt &x)const{return a<x.a;}

	ModInt operator-()const{return ModInt()-*this;}
	ModInt pow(int64_t n)const{
		ModInt res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}

	ModInt inv()const{return pow(mod-2);}
};

template<uint32_t mod>
istream& operator>>(istream& in,ModInt<mod>& a){
	return (in>>a.a);
}
template<uint32_t mod>
ostream& operator<<(ostream& out,const ModInt<mod>& a){
	return (out<<a.a);
}
using mint=ModInt<998244353>;

template<class Mint,int32_t lg>
struct ModIntTable{
	int N;
	vector<Mint>facts,finvs,invs;
	ModIntTable():N(1<<lg),facts(N),finvs(N),invs(N){
		const uint32_t mod=Mint(-1).a+1;
		invs[1]=1;
		for(int i=2;i<N;i++)invs[i]=invs[mod%i]*(mod-mod/i);

		facts[0]=1;
		finvs[0]=1;
		for(int i=1;i<N;i++){
			facts[i]=facts[i-1]*i;
			finvs[i]=finvs[i-1]*invs[i];
		}
	}
	inline Mint fact(int n)const{return facts[n];}
	inline Mint finv(int n)const{return finvs[n];}
	inline Mint inv(int n)const{return invs[n];}
	inline Mint binom(int n,int k)const{return facts[n]*finvs[k]*finvs[n-k];}
	inline Mint perm(int n,int k)const{return facts[n]*finvs[n-k];} 
};
ModIntTable<mint,19>mtable;

int N,A,B,K;

signed main(){
	cin>>N>>A>>B>>K;

	mint ans;
	for(int i=0;i<=N;i++){
		if(i*A>K)continue;
		if((K-i*A)%B)continue;
		int j=(K-i*A)/B;
		if(j>N)continue;
		ans+=mtable.binom(N,i)*mtable.binom(N,j);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6400
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

m = {}

for i in range(N):
    s = input()
    if s[0] not in "MARCH":
        continue

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

ans = 0
for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            ans += m.get("MARCH"[i], 0) * m.get("MARCH"[j], 0) * m.get("MARCH"[k], 0)

print(ans)

Measured memory_bytes: 9664
point1 = 0
point2 = 0

gets.to_i.times do
  str1, str2 = gets.chomp.split
  if str1 > str2
    point1 += 3
  elsif str2 > str1
    point2 += 3
  else 
    point1 += 1
    point2 += 1
  end
end

puts "#{point1} #{point2}"

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

using namespace std;

typedef long long int lli;

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

    int n, a[22][22];
    const lli mod = 1000000007;
    
    cin >> n;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            cin >> a[i][j];
        }
    }

    vector<lli> dp(1<<n, 0), bitnum(1<<n, 0);
    dp[0] = 1;
    for (lli i=1; i<(1LL<<n); i++) {
        for (int j=0; j<n; j++) {
            lli mask = 1LL<<j;
            bitnum[i] += (i&mask) ? 1 : 0;
        }
    }

    for (lli bit=1; bit<(1LL<<n); bit++) {
        for (int i=0; i<n; i++) {
            lli mask = 1LL<<i;
            if (!(bit&mask)) continue;
            dp[bit] += (a[i][bitnum[bit]-1]) ? dp[bit-mask] : 0;
            dp[bit] %= mod;
        }
    }

    cout << dp[(1LL<<n)-1] << endl;

    return 0;
}


Measured memory_bytes: 33024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
int N,M;

struct CAKE{
  long x;
  long y;
  long z;
};

vector<CAKE> cake;
vector<long> cake_abs;

void solve(){
  int check[8][3];
  long maxabs = -1;

  for(int i = 0; i <= 7; i++){
    //make bit 000 ~ 111
    int tmp = i;
    if(tmp - 4 >= 0) {check[i][2] = 1; tmp -= 4;} else check[i][2] = 0;
    if(tmp - 2 >= 0) {check[i][1] = 1; tmp -= 2;} else check[i][1] = 0;
    if(tmp - 1 >= 0) {check[i][0] = 1; } else check[i][0] = 0;


    for(int j = 0; j < N; j++){
      cake_abs.push_back( pow(-1,check[i][2]) * cake[j].x + pow(-1,check[i][1]) *cake[j].y + pow(-1,check[i][0])*cake[j].z) ;
    }

    sort(cake_abs.begin(), cake_abs.end(), std::greater<long>());

    long res = 0;
    for(int j = 0; j < M; j++) res += cake_abs[j];
    maxabs = max(maxabs,res);
    cake_abs.clear();
  }

  cout << maxabs << endl;
  return ;
}

int main(){
  cin >> N >> M;
  CAKE input;
  for(int i = 0; i < N; i++){
    cin >> input.x >> input.y >> input.z;
    cake.push_back(input);
  }

  solve();
  return 0;
}


Measured memory_bytes: 256
def actual(s):
    is_palindrome = lambda x: x == x[::-1]

    N = len(s)

    idx1 = int((N - 1) / 2)
    s1 = s[:idx1]

    idx2 = int((N + 3) / 2) - 1
    s2 = s[idx2:]

    if is_palindrome(s) and is_palindrome(s1) and is_palindrome(s2):
        return 'Yes'

    return 'No'

s = input()
print(actual(s))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define M 1000000
bool marked[M];



void sieve(int n)
{
    for (int i = 3; i * i <= n; i += 2)
    {
        if (marked[i] == false)
        {
            for (int j = i * i; j <= n; j += i + i)
            {
                marked[j] = true;
            }
        }
    }
}
bool isPrime(int n)
{
    if (n < 2)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;
    if (marked[n] == false) return true;
    else return false;
}
int main()
{
    int i,j,k,n,m;
    sieve(M);
    cin>>n;
    for(i=n; ; i++)
    {
        if(isPrime(i))
        {
            cout<<i;
            break;
        }
    }
}


Measured memory_bytes: 1280
n = int(input())
n1 = list(map(int,input().strip().split(' ')))
n2 = list(map(int,input().strip().split(' ')))

path = []
path.append(n1)
path.append(n2)

sum_list = []

for i in range(n):
    sum = 0
    for j in range(i+1):
        sum += path[0][j]

    for k in range(i,n):
        sum += path[1][k]
    
    sum_list.append(sum)
    
print(max(sum_list))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void solve()
{
    int k;cin>>k;
    string s;
    cin>>s;
    int n=s.length();
    if(n<=k) cout<<s<<endl;
    else
    {
        for(int i=0;i<k;i++) cout<<s[i];
        cout<<"..."<<endl;
    }
}
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3644
A = int(input())
B = int(input())
C = int(input())
X = int(input())


cnt = 0
sumc = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            sumc = 500*i + 100*j + 50 *k
            if sumc == X:
                cnt = cnt+1
print(cnt)
            

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)

int		main(void)
{
	int a, b, c, ans = 0;
	cin >> a >> b >> c;
	for (int i = a; i <= b; i++)
		if (c % i == 0)
			ans++;
	cout << ans << endl;
	return (0);
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
const string YES = "Yes";
const string NO = "No";
void solve(long long N){
  bool ans=false;
  string a = to_string(N);
  for (int i = 0; i < 3; i++) {
    if(a[i] == '7')ans = true;
  }
  cout << (ans ? YES:NO) << endl;
}

int main(){
    long long N;
	scanf("%lld",&N);
    solve(N);
}


Measured memory_bytes: 3764
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ldouble = long double;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;


int main()
{
	ll a, b;

	cin >> a >> b;

	println((a - 1) * (b - 1));
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    int n;
    cin >> n;
    vector<vector<LL>> g(n, vector<LL>(n));
    vector<vector<LL>> cnt(n, vector<LL>(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> g[i][j];
        }
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == k || j == k) continue;
                if (g[i][j] > g[i][k] + g[k][j]) {
                    cout << -1 << endl;
                    return 0;
                } else if (g[i][j] == g[i][k] + g[k][j]) cnt[i][j]++;
            }
        }
    }

    LL ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (cnt[i][j] == 0) ans += g[i][j];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1664
def main():
  K=int(input())
  A,B=map(int, input().split())
  for i in range(A,B+1):
    sTgt=i
    if(i%K==0):
      print('OK')
      break
    elif(i==B):
      print('NG')
  
if __name__=='__main__':
  main()

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

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

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    cin >> n;
    
    cout<<"ABC"<<n<<endl;
    return 0;
}

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



int main()
{
    ios_base::sync_with_stdio(false);
    /*cin.tie(NULL);
    cout.tie(NULL);*/

    long long int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

    cin>>n;

    a=0;
    b=0;
    c=0;
    d=0;
    while(n--)
    {
        string s1;
        cin>>s1;
        if(s1=="AC")
            a++;
        else if(s1=="WA")
            b++;
        else if(s1=="TLE")
            c++;
        else
            d++;
    }
    cout<<"AC x "<<a<<"\n";
    cout<<"WA x "<<b<<"\n";
    cout<<"TLE x "<<c<<"\n";
    cout<<"RE x "<<d<<"\n";
    return 0;


}


Measured memory_bytes: 3640
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#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()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  FOR(i,1,10)FOR(j,1,10){
    if(N==i*j){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
'''
所要時間は、分位であった。
'''


# ライブラリのインポート
#import re
import sys
input = sys.stdin.readline
import heapq
#import bisect
#import collections
#import math
inf = 10000*100000*10
def main():
    v, e, r = map(int, input().split())
    E = [[] for _ in range(v)]
    for line in sys.stdin:
        tmp = list(map(int,line.strip().split()))
        E[tmp[0]].append([tmp[1],tmp[2]])
    
    D = [inf] * v
    D[r] = 0
    Q = []
    heapq.heappush(Q,(D[r],r))
    while(Q):
        d, u  = heapq.heappop(Q)
        for v,w in E[u]:
            if D[v] > D[u] + w:
                D[v] = D[u] + w
                heapq.heappush(Q, (D[v],v))

    for d in D: print(d) if d < inf else print("INF")


    
if __name__ == '__main__':
    main()



Measured memory_bytes: 96968
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    H,W=MI()
    s=[[] for _ in range(H+2)]
    s[0]="#"*(W+2)
    for i in range(H):
        s[i+1]="#"+input()+"#"
    s[-1]="#"*(W+2)
            
            
    dx=[0,1]
    dy=[1,0]
    
    inf=10**7
    #dp[i][j]はますi,jにたどり着くときの最小コスト，コストは色が変わった数
    dp=[[inf]*(W+2) for _ in range(H+2)]
    
    if s[1][1]==".":
        dp[1][1]=0
    else:
        dp[1][1]=1
        
    for i in range(1,H+1):
        for j in range(1,W+1):
            for k in range(2):
                ii=i+dx[k]
                jj=j+dy[k]
                if s[ii][jj]==s[i][j]:
                    a=0
                else:
                    a=1
                dp[ii][jj]=min(dp[ii][jj],dp[i][j]+a)
    
    print((dp[H][W]+1)//2)
    

main()


Measured memory_bytes: 40688
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstdio>
using namespace std;
#define EPS 1e-10
int equals(double a, double b) { return fabs(a - b) < EPS; };
class Point {
public:
	double x, y;
	Point(double x=0, double y=0) :x(x), y(y) { };
	Point operator + (Point& p) {
		return Point(p.x + x, p.y + y);
	}
	Point operator - (Point& p) {
		
		return Point(x - p.x, y - p.y);
	}
	Point operator * (double k) {
		return Point(k*x, k*y);
	}
	double abs() {					//向量长度;
		return sqrt(x * x + y * y);
	}
};
typedef Point Vector;
double dot(Vector a, Vector b) {			//内积 x1*x2 + y1*y2
	return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b) {		  //外积  x1*y2 - x2*y1
	return a.x * b.y - a.y * b.x;
}
struct Segment           //线段
{
	Point a, b;
};
typedef Segment Line;   //线段表示直线；
class Circle {
public:
	Point c;
	double r;
	Circle(Point c = Point(), double x = 0) :c(c), r(x) {};
};
void Parallel_Orthogonal() {				//判断平行或正交
	Point a, b,c,d;
	Point e, f;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a.x >> a.y >> b.x >> b.y>>c.x>>c.y>>d.x>>d.y;
		e = a - b;
		f = c - d;
		if (equals(dot(e, f), 0)) cout << "1" << endl;
		else if (equals(cross(e, f), 0))cout << "2" << endl;
		else cout <<"0" <<endl;
	}
}
Point Projection(Point& a, Point& b, Point& c) {
	Point p;
	Vector v1 = b - a;
	Vector v2 = c - a;
	double len = dot(v1, v2);
	double len2 = len/ v1.abs();
	p.x = a.x + len2 / v1.abs() * v1.x;
	p.y = a.y + len2 / v1.abs() * v1.y;
	return p;
}
int main(void) {
	Point a, b, c,d;
	cin >> a.x >> a.y >> b.x >> b.y;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c.x >> c.y;
		d=Projection(a, b, c);
		printf("%.10f %.10f\n", d.x, d.y);
	}
}


Measured memory_bytes: 3292
import java.util.Scanner;

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

		String x = sc.next();
		int n = x.length();
		int countS = 0;
		int pairCount = 0;

		for (int i=0; i<n; i++) {
			if (x.charAt(i)=='T') {
				if (countS > 0) {
					countS--;
					pairCount++;
				}
			} else if (x.charAt(i)=='S') {
				countS++;
			}
		}

		n = n - pairCount*2;

		sc.close();

		System.out.println(n);
	}
}


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

#define pb push_back
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define sz(s) (ll) s.size()
#define deb(i) cout << "Aqui " << (ld) i << "\n";



int main(){
		
	ll n; cin >> n;
	cout << (1000-(n%1000))%1000 << "\n";
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  
  int n,k ;
  cin >>n>>k ;

  int ans = 1 ;

  for (int i = 1; i <=n ; i++)
  {
      ans = ((ans*2)<(ans+k)) ? ans*2 : ans+k ;
  }
  
  cout << ans << endl ;  
  
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    a = ['R', 'U', 'D']
    b = ['L', 'U', 'D']
    for i in range(len(s)):
        if i%2 == 0:
            if not s[i] in a:
                print('No')
                exit()
        else:
            if not s[i] in b:
                print('No')
                exit()
    print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define print(n) std::cout << n << std::endl
#define FOR(i,n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    int x,y;
    cin >> x >> y;
    vector<int> num = {0,1,3,1,2,1,2,1,1,2,1,2,1};
    if(num[x] == num[y])print("Yes");
    else print("No");
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var s = Console.ReadLine();

			var sum = 0;
			var max = 0;

			foreach(var c in s)
			{
				if(c == 'I')
				{
					sum++;
					max = Math.Max(max, sum);
				}
				else
				{
					sum--;
				}
			}

			Console.WriteLine(max);
		}
	}
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mkp make_pair
#define mod 1000000007
#define F first
#define S second
#define ld long double
#define f(i,l,f,n) for(i=(l); i<(n) && !(f); i++)
#define endl "\n"

int dp[3001][3001];

int lcs(string s, string t, int n, int m)
{
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=m; j++)
        {
            if(i==0 || j==0)
            dp[i][j]=0;
            else if(s[i-1]==t[j-1])
            dp[i][j]=dp[i-1][j-1]+1;
            else
            dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
        }
    }

    /*if(n==0 || m==0)
    return 0;
    else if(dp[n][m]!=-1)
    return dp[n][m];
    else if(s[n-1]==t[m-1])
    dp[n][m]= lcs(s,t,n-1,m-1)+1;
    else
    dp[n][m]=max(lcs(s,t,n-1,m), lcs(s,t,n,m-1));*/

    return dp[n][m];
}

void solve()
{
    string s, t;
    cin>>s>>t;
    int n = s.length();
    int m = t.length();
    memset(dp, -1, sizeof(dp));
    int l = lcs(s,t,n,m);

    char ans[l+1];
    ans[l]='\0';
    int i=n, j=m;
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
            ans[l-1]=s[i-1];
            l--;
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
        i--;
        else
        j--;
    }
    cout<<ans;

}


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

    int t=1, i=0;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<i++<<": "<<solve()<<endl;
        solve();
    }
}

/*
AGGTAB
GXTXAYB
*/


Measured memory_bytes: 35456
function Main(input) {
    var N = parseInt(input[0], 10);
    var P = input.slice(1).map(a => parseInt(a, 10));

    var no = 0;

    for (var i = 0; i < N; i++) {
        if (i + 1 !== P[i]) {
            no++;
        }
    }

    console.log(no <= 2 ? 'YES' :'NO');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 21956
if __name__ == '__main__':
  n = int(input())
  heights = map(int, input().split(' '))

  prev = -100
  answer = 'Yes'

  for height in heights:
    if (height >= prev + 1):
      height = height -1
    elif height == prev:
      height = height
    else:
      answer = 'No'
    prev = height
  
  print(answer)

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

int main(){
  int n, t, i, dr;

  cin>>n;
  int r[n];
  for (t = 0; t < n; t++) {
    cin>>r[t];
  }

  int mx = r[1] - r[0];
  int mx_el = 0;
  int min_el;


  for(t = n-1; t > 1; t--){
    if(r[t] > mx_el){
      mx_el = r[t];
      min_el = r[0];
      for(i = 0; (i < t); i++){
        if(r[i] <= min_el){
          min_el = r[i];
          dr = r[t] - r[i];
          if(dr > mx) mx = dr;
        }
      }
    }
  }

  cout<<mx<<endl;
}

Measured memory_bytes: 1940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int a, b; cin >> a >> b;
	cout << 100 << " " << 100 << endl;
	vector<string> ans(100);
	rep(i,100)rep(j,100) {
		if (i < 50)ans[i] += '#';
		else ans[i] += '.';
	}
	rep(i,a-1) {
		ans[i / 50*2 + 1][i % 50*2 + 1] = '.';
	}
	rep(i,b-1) {
		ans[i / 50*2 + 51][i % 50*2 + 1] = '#';
	}
	rep(i,100) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;

struct edge {LL to;LL cost;};
vector<edge> v[100001];
LL x[100001];
bool check[100001];

void dfs(int s,int t){
    check[s]=true;
    x[s]=t;
    for(int i=0;i<v[s].size();i++){
        edge e;
        e=v[s][i];
        if(check[e.to]==false){
            dfs(e.to,x[s]+e.cost);
        }
    }
}

int main(){
    int N,M;
    cin >> N >> M;
    for(int i=0;i<M;i++){
        LL l,r,d;
        cin >> l >> r >> d;
        v[l].push_back({r,d});
        v[r].push_back({l,-d});
    }
    memset(x,0,sizeof(x));
    memset(check,false,sizeof(check));
    for(int i=1;i<=N;i++){
        if(check[i]==false){
            dfs(i,0);
        }
    }
    for(int i=1;i<=N;i++){
        for(int j=0;j<v[i].size();j++){
            edge e=v[i][j];
            if(x[e.to]-x[i]!=e.cost){
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define fail(s) assert(!s)
#define ULL unsigned long long
const int INF = 0x3f3f3f3f;
const int EPS = 1e-6;
const int MAXN = 100010;
int prel[MAXN], prer[MAXN], sufl[MAXN], sufr[MAXN], ans[MAXN];
int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'L'){
			prel[i] = prel[i - 1] + 1;
			prer[i] = 0;
		}
		else {
			prer[i] = prer[i - 1] + 1;
			prel[i] = 0;
		}
	}
	for (int i = s.length() - 1; i >= 0; i--) {
		if (s[i] == 'L') {
			sufl[i] = sufl[i + 1] + 1;
			sufr[i] = 0;
		}
		else {
			sufr[i] = sufr[i + 1] + 1;
			sufl[i] = 0;
		}
	}
	for (int i = 0; i < s.length() - 1; i++) {
		if (s[i] == 'R' && s[i + 1] == 'L') {
			ans[i] = (prer[i] + 1) / 2 + sufl[i + 1] / 2;
			ans[i + 1] = (prer[i]) / 2 + (sufl[i + 1] + 1) / 2;
		}
	}
	for (int i = 0; i < s.length(); i++)cout << ans[i] << ' ';
	cout << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pi acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define ps(s) printf("%s",s.c_str())
#define	inf (ll)1e15
#define mod 1000000007
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

using namespace __gnu_pbds;
using namespace std;

inline string str_inp(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string line_inp(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;


const int S=100100;
int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
	int n,m;
	while(~sf("%d %d",&n,&m))
	{
		vector<int>g[n+5];
		for(int i=1;i<=m;i++)
		{
			int u,v;
			sf("%d %d",&u,&v);
			g[u].push_back(v);
			g[v].push_back(u);
		}

		queue<int>q;
		q.push(1);

		bool visit[n+5];
		memset(visit,false,sizeof visit);
		visit[1]=true;

		int par[n+5];
		while(!q.empty())
		{
			int u=q.front();
			q.pop();
			visit[u]=true;

			for(int v:g[u])
			{
				if(!visit[v])
				{
					par[v]=u;
					visit[v]=true;
					q.push(v);
				}
			}
		}

		puts("Yes");
		for(int i=2;i<=n;i++)pf("%d\n",par[i]);
	}
    return 0;
}
 






































Measured memory_bytes: 10796
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    D =[int(i) for i in input().split()]
    #count = 0
    D.sort()
    D.reverse()
    center = D[int(N/2)]
    print(D[int((N/2))-1]-center)
if __name__ == '__main__':
    main()

Measured memory_bytes: 14396
#include<iostream>
#include<stdio.h>
#include<algorithm>
#define MAX 100000
using namespace std;

int A[MAX], n;

int Partition(int p, int r)
{
	int i, x, j,t;
	x = A[r];
	i = p - 1;
	for (j = p; j < r; j++) {
		if (A[j] <= x) {
			i++;
			t = A[i]; A[i] = A[j]; A[j] = t;
		}
	}
	t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
	return i + 1;
}

int main()
{

	int j;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}

	j=Partition(0, n-1);

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


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

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;

typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

typedef vector<double> VD;
typedef vector<VD> VVD;

typedef vector<string> VS;
typedef vector<VS> VVS;

typedef vector<bool> VB;
typedef vector<VB> VVB;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) (x).begin(), (x).end()
#define RANGE(xx,y,mx,my) (0<=(x)&&0<=(y) && (x)<(mx) && y<(my))
#define REP(i, init, N) for(int i = (init); i < (int)(N); i++)

const int INF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

inline int fromString(const string &s) {
    int res;
    istringstream iss(s);
    iss >> res;
    return res;
}

int N;
VI as;

const int Q = 1000 * 1000 * 1000 + 7;

bool x_twice() {
    REP(i, 0, N - 1) {
        if (as[i] == as[i + 1]) {
            return true;
        }
    }
    return false;
}

PII solve() {
    if (x_twice()) { return MP(2, 0); }

    PII xs(-1000 * 1000 * 1000 - 3, 1000 * 1000 * 1000 + 3);

    REP(i, 0, N) {
        if (as[i] == Q) {
            if ((i + 1) % 2) { // ?\???°
                if (i - 1 >= 0) {
                    xs.snd = min(xs.snd, as[i - 1] - 1);
                }
                if (i + 1 <= N - 1) {
                    xs.snd = min(xs.snd, as[i + 1] - 1);
                }
            } else {
                if (i - 1 >= 0) {
                    xs.fst = max(xs.fst, as[i - 1] + 1);
                }
                if (i + 1 <= N - 1) {
                    xs.fst = max(xs.fst, as[i + 1] + 1);
                }
            }

        } else if (i != 0 && as[i - 1] != Q) {
            if ((i + 1) % 2) {
                if (as[i] >= as[i - 1]) {
                    return MP(2, 0);
                }
            } else {
                if (as[i] <= as[i - 1]) {
                    return MP(2, 0);
                }
            }
        }

        if (xs.fst > xs.snd) {
            return MP(2, 0);
        }
    }

    if (xs.fst != xs.snd) {
        return MP(1, 0);
    } else {
        return MP(0, xs.fst);
    }
}

int main(void) {
    while (cin >> N, N) {
        as = VI(N);
        REP(i, 0, N) {
            string s;
            cin >> s;
            if (s == "x") {
                as[i] = Q;
            } else {
                int n = fromString(s);
                as[i] = n;
            }
        }

        PII ans = solve();
        if (ans.fst == 0) {
            cout << ans.snd << endl;
        } else if (ans.fst == 1) {
            cout << "ambiguous" << endl;
        } else if (ans.fst == 2) {
            cout << "none" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1232
c=[[],[],[]]
for i in range(3):
    c[i]=list(map(int,input().split()))

if c[0][0]-c[0][1]==c[1][0]-c[1][1] and c[2][0]-c[2][1]==c[0][0]-c[0][1]:
    if c[0][1]-c[0][2]==c[1][1]-c[1][2] and c[2][1]-c[2][2]==c[0][1]-c[0][2]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

using Graph = vector<vector<int>>;


int main() {
  int n, m;
  cin >> n >> m;
  Graph G(n, vector<int>());

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;

    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> distance(n, -1);
  vector<int> previous(n, -1);
  queue<int> que;
  que.push(0);
  distance[0] = 0;

  while (!que.empty()) {
    int v = que.front();
    que.pop();

    for (auto u: G[v]) {
      if (distance[u] == -1) {
        distance[u] = distance[v] + 1;
        previous[u] = v;
        que.push(u);
      }
    }
  }

  cout << "Yes" << endl;
  for (int i = 1; i < n; ++i) {
    cout << previous[i] + 1 << endl;
  }
}

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


typedef long long ll;
typedef pair<ll, ll> P;

struct edge {int to, cost; };

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

ll GCD(ll a, ll b){
  if(b==0) return a;
  else return GCD(b, a%b);
}

ll LCM(ll a, ll b){
  if(a<b) swap(a,b);
  return a/GCD(a,b)*b;
}

int par[200005];
int rank_[200005];
void init(int n){
  for(int i=0; i<n; i++){
    par[i] = i;
    rank_[i] = 1;
  }
}

int find(int x){
  if(x==par[x]){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x==y) return;
  if(rank_[x]<rank_[y]){
    par[x]=y;
    rank_[y] += rank_[x];
    rank_[x] = rank_[y];
  }else{
    par[y]=x;
    rank_[x] += rank_[y];
    rank_[y] = rank_[x];
  }
}

int main(){
  int n, m;
  cin >> n >> m;
  init(n);
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    unite(a, b);
  }
  int ans = 0;
  for(int i=0; i<n; i++){
    ans = max(ans, rank_[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5196
import io
import sys


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
30
384 8895
1725 9791
170 1024
4 11105
2 6
578 1815
702 3352
143 5141
1420 6980
24 1602
849 999
76 7586
85 5570
444 4991
719 11090
470 10708
1137 4547
455 9003
110 9901
15 8578
368 3692
104 1286
3 4
366 12143
7 6649
610 2374
152 7324
4 7042
292 11386
334 5720
'''


def MAIN():
  # T_IN()
  if A():
    print("Yes")
  else:
    print("No")


def A():
  n = IN_I()
  # [[a, b]]
  md = list([IN_L_I() for i in range(0, n)])
  md.sort(key=lambda x: (x[1]))
  total = 0
  for item in md:
    total += item[0]
    if total > item[1]:
      return False


  return True


def B():
  return None


def C():
  return None


MAIN()


Measured memory_bytes: 55288
#abc084c

n=int(raw_input())
l=[0 for i in xrange(n)]
for i in xrange(n-1):
 c,s,f=map(int,raw_input().split())
 for j in xrange(i+1):
  l[j]=max(s,(l[j]+f-1)/f*f)+c
for i in xrange(n):
 print l[i]


Measured memory_bytes: 2692
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  map<char, pii> p = {
    {'N', mp(0, 1)},
    {'S', mp(0, -1)},
    {'E', mp(1, 0)},
    {'W', mp(-1, 0)},
  };
  while (cin >> n, n) {
    vvi t(21, vi(21));
    while (n--) {
      int x, y;
      cin >> x >> y;
      t[y][x] = 1;
    }
    int m;
    cin >> m;
    int x = 10, y = 10;
    while (m--) {
      char d;
      int l;
      cin >> d >> l;
      while (l--) {
        x += p[d].fi;
        y += p[d].se;
        t[y][x] = 0;
      }
    }
    vi v(t.size());
    transform(all(t), v.begin(), [](vi xs) { return accumulate(all(xs), 0); });
    cout << (all_of(all(v), [](int x) { return x == 0; })
               ? "Yes"
               : "No")
         << endl;
  }
}

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

using namespace std;


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

   long long int x,k,d,mini,p,l,no;
   cin>>x>>k>>d;
   p=(long long int)abs((long double)x);
   if(p/d>=k)
   {
       mini=p-k*d;
   }
   else
   {
      l=p%d;
      no=p/d;
      k=k-no;
      if(k%2==0)
        mini=l;
      else
        mini=(long long int)abs((long double)(l-d));
   }
   cout<<mini;

    return 0;
}





Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  constexpr int mod = 998244353;
  int n, s = 0; cin >> n;
  vector<int> a(n);
  REP(i, n){
    cin >> a[i];
    s += a[i];
  }

  auto dp = make_v(n+1, s+1, 0LL);
  auto dp2 = make_v(n+1, s+1, 0LL);

  dp[0][0] = 1; dp2[0][0] = 1;
  REP(i, n)REP(j, s+1){
    if(j + a[i] <= s){
      (dp[i + 1][j + a[i]] += dp[i][j]) %= mod;
      (dp2[i + 1][j + a[i]] += dp2[i][j]) %= mod;
    }
    (dp[i + 1][j] += dp[i][j] * 2) %= mod;
    (dp2[i + 1][j] += dp2[i][j]) %= mod;
  }

  ll cnt = 0;
  REP(i, s+1){
    if(i * 2 >= s){
      (cnt += dp[n][i]) %= mod;
    }
  }

  ll ans = 1;
  REP(i, n) (ans *= 3) %= mod;
  ans -= cnt * 3;

  if(s % 2 == 0)(ans += 3 * dp2[n][s / 2]) %= mod;
  
  while(ans < 0) ans += mod;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 423744
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]

xl.sort()

ans = N
rpre = xl[0][0] + xl[0][1]

for x, l in xl[1:]:
    ll = max(x - l, 0)
    rr = x + l
    if ll < rpre:
        ans -= 1
        if rr < rpre: rpre = rr
    else:
        rpre = rr

print(ans)


Measured memory_bytes: 28248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n; cin>>n;
    vector<vector<ll>> tree(n+1);
    rep(i,n-1){
        ll a,b; cin>>a>>b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<ll> c(n);
    vector<bool> used(n+1, false);
    ll M=0;
    rep(i,n){
        cin>>c[i];
        M+=c[i];
    }
    sort(c.begin(), c.end(), greater<ll>());
    cout<<M-c[0]<<endl;
    vector<ll> res(n+1);
    queue<ll> que;
    que.push(1);
    ll tmp=0;
    while(!que.empty()){
        ll x=que.front();
        used[x]=true;
        res[x]=c[tmp];
        tmp++;
        que.pop();
        for(ll y:tree[x]){
            if(used[y]) continue;
            used[y]=true;
            que.push(y);
        }
    }
    for(ll i=1; i<=n; i++) cout<<res[i]<<' ';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define int long long 
#define double long double 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
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__) << "] "

int32_t main(){
        IOS;
        int n ;
        cin >> n ;
        vector<int>arr(n);
        for(int& i : arr) cin >> i ;
        vector<vector<int>>dp(n+2,vector<int>(n+2,0));
        for(int i=n-1;i>=0;i--){
                for(int j=i;j<n;j++){
                        if(i==j){
                                dp[i][j] = arr[i];
                        }else{
                                dp[i][j] = max(arr[i] - dp[i+1][j],arr[j] - (j>0?dp[i][j-1]:0));
                        }
                } 
        }
        cout << dp[0][n-1] << endl;
        return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	
	vector<int> v(n);
	for (auto &&e : v)
		cin >> e;
	
	int result = 0;
	for (int i = 0; i < n; ++i) {
		int c;
		cin >> c;
		
		if (v[i] - c > 0)
			result += v[i] - c;
	}
	
	cout << result << endl;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll b;
int f(ll l) {
	if ((2 * b - l * (l - 1)) % (2 * l) == 0) {
		ll a = (2 * b - l * (l - 1)) / (2 * l);
		if (a >= 1)return a;
		return -1;
	}
	return -1;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (cin >> b, b) {
		ll ans = 0;
		int a = -1;
		for (ll i = 1; i*(i+1)/2 <= b; ++i) {
			int tmp = f(i);
			if (tmp != -1) {
				ans = i;
				a = tmp;
			}
		}
		cout << a << " " << ans << endl;
	}
}


Measured memory_bytes: 3096
#include <cstdio>

int main()
{
  int n;
  int a;

  scanf("%d %d", &n, &a);
  int max = a;
  int max2 = 0;
  int max_at = 0;
  for (int i = 1; i < n; ++i)
  {
    scanf("%d", &a);
    if (max < a)
    {
      max2 = max;
      max = a;
      max_at = i;
    }
    else if (max2 < a)
    {
      max2 = a;
    }
  }
  for (int i = 0; i < n; ++i)
  {
    printf("%d\n", i == max_at ? max2 : max);
  }
  return 0;
}


Measured memory_bytes: 1536