akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int A, B, water;
	cin >> A >> B >> water;
	int ans = (water / 1000) * min(A, B * 2) + (water % 1000 > 500 ? min(A, B * 2) : water % 1000 == 0 ? 0 : min(A, B));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;

vector<int> ra(MX,0);
vector<int> par(MX,0);
using P = pair<int, int>;
using ll = long long;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int find(int x) {
    if(par[x] == 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(ra[x]<ra[y]) {
        par[x] = y;
    }else {
        par[y] = x;
        if(ra[x]==ra[y]) {
            ra[x]++;
            
        }
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

signed main(){
    double l;
    cin >> l;
    
    double a = l/3.0;
    cout << setprecision(20)<< a*a*a << endl;
}



Measured memory_bytes: 8064
# D - Wizard in Maze
from collections import deque
import sys
INF = 10000000

H,W = map(int,input().split())
Ch,Cw = map(int,input().split())
Dh,Dw = map(int,input().split())
S = [input() for _ in range(H)]
C = [[INF]*W for _ in range(H)]
C[Ch-1][Cw-1] = 0
que = deque([(Ch,Cw)])
now = set()
tmp = 0

while True:
    while len(que)>0:
        i,j = que.popleft()
        now.add((i,j))
        for (h,w) in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:
            if 1<=h<=H and 1<=w<=W and S[h-1][w-1]=='.' and C[h-1][w-1]>tmp:
                C[h-1][w-1] = tmp
                que.append((h,w))
    for i,j in now:
        for h in range(i-2,i+3):
            for w in range(j-2,j+3):
                if 1<=h<=H and 1<=w<=W and S[h-1][w-1]=='.' and C[h-1][w-1]>tmp+1:
                    C[h-1][w-1] = tmp+1
                    que.append((h,w))
    now = set()
    tmp += 1
    if C[Dh-1][Dw-1]!=INF:
        print(C[Dh-1][Dw-1])
        break
    if len(que)==0:
        print(-1)
        break

Measured memory_bytes: 95056
#include <cstdio>

const char f[] = "CODEFESTIVAL2016";

int main()
{
  char s[17];
  scanf("%s", s);
  int ans = 0;
  for (int i = 0; i < 16; ++i)
  {
    if (s[i] != f[i]) ++ans;
  }
  printf("%d\n", ans);
  return 0;
}

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

string s;

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

    int n;
    cin>>n>>s;

    int sol=1;

    for(int i=1;i<n;i++)
        if(s[i]!=s[i-1])
            sol++;

    cout<<sol;
}



Measured memory_bytes: 512
H, W, K = map(int, input().split())
init_kuro = 0
HW = []
for i in range(H):
    t = list(input())
    k = t.count('#')
    HW.append(t)
    init_kuro += k

#print(HW)
#print(init_kuro)
import itertools

tate = list(itertools.product([0, 1], repeat=H))
yoko = list(itertools.product([0, 1], repeat=W))

ans = 0


def solve(T, Y):
    tmp = 0
    for i, t in enumerate(T):
        if t == 1:
            for j, h in enumerate(HW[i]):
                if h == '#' and Y[j] == 0:
                    tmp += 1

    for i, y in enumerate(Y):
        if y == 1:
            for hw in HW:
               if hw[i] == '#':
                   tmp +=1

    if init_kuro - tmp == K:
        return 1
    else:
        return 0


ans = 0
for T in tate:
    for Y in yoko:
        ans += solve(T, Y)
print(ans)


Measured memory_bytes: 9236
N=int(input())
Q=[None]*N
for i in range(N):
  s,t=input().split()
  Q[i]=[s,t]
X=input()
countable=False
ans=0
for i in range(len(Q)):
  if countable:
    ans+=int(Q[i][1])
  if Q[i][0]==X:
    countable=True
print(ans)

Measured memory_bytes: 3064
# library
from string import ascii_lowercase as a

# input
S = input()
T = input()

# solution
s = ''.join([a[n] for n in sorted([a.index(e) for e in S])])
t = ''.join([a[n] for n in sorted([a.index(e) for e in T], reverse = True)])

# output
if s < t: res = 'Yes'
else: res = 'No'
print(res)

Measured memory_bytes: 3768
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n, m; cin>>n>>m;
    priority_queue<P, vector<P>, greater<P>> ab;
    for(int i=0; i<n; i++){
        int a, b; cin>>a>>b;
        ab.emplace(a, b);
    }

    priority_queue<int> jobs;
    int ans = 0;
    for(int i=1; i<=m; i++){
        while(ab.size() && ab.top().first <= i){
            jobs.emplace(ab.top().second);
            ab.pop();
        }

        if(jobs.size()){
            ans += jobs.top();
            jobs.pop();
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1908
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
ll cnt[10][10]={0};
int main(){
  ll n;
  cin>>n;
  for(int i=1;i<=n;i++){
    ll t=i%10,s=t;
    ll ni=i;
    while(ni>0){
      s=ni%10;
      ni/=10;
    }
    if(t!=0){
      cnt[s][t]++;
    }
  }
  ll ans=0;
  for(int i=1;i<=n;i++){
    ll t=i%10,s=t;
    ll ni=i;
    while(ni>0){
      s=ni%10;
      ni/=10;
    }
    if(t!=0){
      ans+=cnt[t][s];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
($h,$w)=glob<>;
@s=map[/./g],grep/#/,<>;
for$j(0..$w-1){
	$f=0;
	$f|=$$_[$j]=~"#"for@s;
	push@b,$f
}
for$s(@s){
	$b[$_]&&print$$s[$_]for 0..$w-1;
	print$/
}


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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define maxn 100
#define int long long int
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

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

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0)
    {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x)
{ //bit計算
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void)
{
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++)
    {
        if (!prime[i])
        {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i)
        {
            prime[j] = false;
        }
    }
}

signed main()
{
    int N;
    vector<int> A, B, cp;
    cin >> N;
    int all_A, all_B;
    int minus = 0;
    int ans = 0;
    all_A = all_B = 0;

    rep(i, N)
    {
        int a;
        cin >> a;
        A.push_back(a);
        all_A += a;
    }
    rep(i, N)
    {
        int b;
        cin >> b;
        B.push_back(b);
        all_B += b;
    }
    rep(i, N)
    {
        cp.push_back(A[i] - B[i]);
    }
    if (all_A < all_B)
    {
        cout << "-1" << endl;
        return 0;
    }
    sort(cp.begin(), cp.end());

    rep(i, N)
    {
        if (cp[i] < 0)
        {
            minus += cp[i];
            ans++;
        }
        else
        {
            break;
        }
    }
    sort(cp.begin(), cp.end(), greater<int>());
    rep(i, N)
    {
        if (minus >= 0)
        {
            break;
        }
        minus += cp[i];
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3316
#include<cstdio>
#define mod 1000000007
#define N 611
int dp[N][N],A[N],B[N],G[N],cnt[N][N],pd[N],n,k,nn,all,ans;
int main()
{
	scanf("%d%d",&n,&k);nn=n<<1;all=(n-k)<<1;
	for (int i=1;i<=k;++i) scanf("%d%d",&A[i],&B[i]),pd[A[i]]=B[i],pd[B[i]]=A[i];
	G[0]=1;for (int i=2;i<=nn;i+=2) G[i]=1ll*G[i-2]*(i-1)%mod;
	for (int i=1;i<=nn;++i)
		for (int j=i;j<=nn;++j)
			cnt[i][j]=cnt[i][j-1]+(!pd[j]);
	for (int i=1;i<=nn;++i)
		for (int j=i+1;j<=nn;j+=2)
		{
			for (int k=i;k<=j;++k) if (pd[k]&&(pd[k]>j||pd[k]<i)) goto C;
			dp[i][j]=G[cnt[i][j]];
			for (int k=i+1;k<j;k+=2)
				dp[i][j]=(dp[i][j]-1ll*dp[i][k]*G[cnt[k+1][j]]%mod+mod)%mod;
			C:;
		}
	for (int i=1;i<=nn;++i)
		for (int j=i+1;j<=nn;j+=2) ans=(ans+1ll*dp[i][j]*G[all-cnt[i][j]]%mod)%mod;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define PI acos(-1)
#define EPS 1e-12
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bitCount __builtin_popcount
#define forn(i, n) for(i = 0; i < (ll)n; i++)
#define for1(i, n) for(i = 1; i <= (ll)n; i++)
#define forv(i, v) for(i = 0; i < v.size(); i++)
#define forab(i, a, b) for(i = a; i <= (ll)b; i++)
#define Sort(v) sort(v.begin(), v.end())
#define bend(v) v.begin(), v.end()
#define sz(v) v.size()
#define trace(x) cout<<"x = "<<x<<"\n"
#define trace2(x, y) cout<<"x = "<<x<<" y = "<<y<<"\n"
#define trace3(x, y, z) cout<<"x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define trace4(w, x, y, z) cout<<"w = "<<w<<" x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define ln "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef set<int>::iterator sit;
typedef set<ll>::iterator sllt;
typedef set<char>::iterator sct;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
typedef multiset<int>::iterator msit;
const int maxn = 1e5+5;
const ll mod = 1e9+7;
const int alphabet = 26;
const int inf = INT_MAX;
const ll linf = 1e18+9;
namespace util{
	inline ll cnm(char ch){ return (ch-'0'); }
	inline ll cap(char ch){ return (ch-'a'); }
	inline void instr(string& s, ll& n){ cin>>s;    n = s.length(); }
	inline void instr(string& s){ cin>>s; }
	template<typename T> T gcd(T a, T b){ if(a==0) return b; return gcd(b%a, a); }
	template<typename T> bool min(T a, T b, T c){
		return  std::min(a, std::min(b, c));
	}
}
using namespace util;

map<ll, ll> cache;
ll a, b, c, d;

ll f(ll n){
	if(n == 0) return 0;
	if(n == 1) return d;

	if(cache.count(n)) return cache[n];
	ll l2 = (n/2)*2;
	ll r2 = ((n+1)/2) *2;
	ll l3 = (n/3)*3;
	ll r3 = ((n+2)/3)*3;
	ll l5 = (n/5)*5;
	ll r5 = ((n+4)/5)*5;

	ll res = 1e18;
	if(n < res/d) res = n*d;
	res = min(res, llabs(l2-n)*d + a + f(l2/2));
	res = min(res, llabs(r2-n)*d + a + f(r2/2));

	res = min(res, llabs(l3-n)*d + b + f(l3/3));
	res = min(res, llabs(r3-n)*d + b + f(r3/3));

	res = min(res, llabs(l5-n)*d + c + f(l5/5));
	res = min(res, llabs(r5-n)*d + c + f(r5/5));

	cache[n] = res;
	return res;
}

void solve(int tc)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	ll i, j, k, m, n;
	cache.clear();
	cin>>n;
	cin>>a>>b>>c>>d;
	cout<<f(n)<<ln;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int t = 1;
	int i = 1;
	cin>>t;
	while(i <= t){
		solve(i);
		i++;
	}

	return 0;
}



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

int depth_rec(int* type, int* parent, int* depth, int id) {
    if (type[id] == 0) {
        return 0;
    } else {
        if (depth[parent[id]] == -1) {
            depth[parent[id]] = depth_rec(type, parent, depth, parent[id])+1;
        }
        return depth[parent[id]];
    }
}

int height_rec(int* type, int* deg, int* left, int* right, int* height, int id) {
    if (deg[id] == 0) {
        return 0;
    } else {
        if (left[id] >= 0) { //left exists
            if (right[id] >= 0) { //right exists
                if (height[left[id]] == -1) {
                    height[left[id]] = height_rec(type, deg, left, right, height, left[id]);
                }
                if (height[right[id]] == -1) {
                    height[right[id]] = height_rec(type, deg, left, right, height, right[id]);
                }
                if (height[left[id]]>height[right[id]]) {
                    height[id] = height[left[id]] + 1;
                } else {
                    height[id] = height[right[id]] + 1;
                }
            } else {
                if (height[left[id]] == -1) {
                    height[left[id]] = height_rec(type, deg, left, right, height, left[id]);
                }
                height[id] = height[left[id]] + 1;
            }
        } else {
            if (height[right[id]] == -1) {
                height[right[id]] = height_rec(type, deg, left, right, height, right[id]);
            }
            height[id] = height[right[id]] + 1;
        }
        return height[id];
    }
}

std::string typef(int i) {
    if (i==0) {
        return "root";
    } else if (i==1) {
        return "internal node";
    } else if (i==2) {
        return "leaf";
    }
}

int main() {
    int n;
    int left[25], right[25], type[25], depth[25], height[25], deg[25]={}, parent[25], sibling[25];
    std::cin >> n;
    for (int i=0; i<n; i++) {
        parent[i] = -1;
        sibling[i] = -1;
        type[i] = 1;
        depth[i] = -1;
        height[i] = -1;
    }
    for (int i=0; i<n; i++) {
        int id;
        std::cin >> id;
        std::cin >> left[id] >> right[id];
        if (left[id] >= 0) {
            deg[id]+=1;
            parent[left[id]] = id;
        }
        if (right[id] >= 0) {
            deg[id]+=1;
            parent[right[id]] = id;
        }
        if (deg[id] == 2) {
            sibling[left[id]] = right[id];
            sibling[right[id]] = left[id];
        } else if (deg[id] == 0) {
            type[id] = 2;
        }
    }
    for (int i=0; i<n; i++) {
        if (parent[i] == -1) {
            type[i] = 0;
        }
    }

    for (int i=0; i<n; i++) {
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", i, parent[i], sibling[i], deg[i], depth_rec(type, parent, depth, i), height_rec(type, deg, left, right, height, i), typef(type[i]).c_str());
    }

    return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define rep(i, n) for(int i=1;i<(int) n;i++)
using namespace std;
int main(){
  int n;
  int64_t c=0;
  cin >> n;
  int a[n];
  cin  >> a[0];
  rep(i, n){
    cin >> a[i];
    if(a[i-1]<=a[i]){
      //cout << a[i] << endl;
      continue;
    }
    else {
      c=c+a[i-1]-a[i];
      a[i]=a[i-1];
      //cout << a[i] << endl;
    }
  }
  
  cout << c << endl;
}

    


Measured memory_bytes: 4420
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int P=1e9+7,maxn=2e3+10;
int n,k,dp[maxn],tot;
inline void upd(int &x,int y){x+=y;(x>=P)&&(x-=P);}
inline int ksm(int a,int b){
	int ans=1;if(b<0) return 1;
	for(;b;b>>=1,a=1ll*a*a%P) if(b&1) ans=1ll*ans*a%P;
	return ans;
}
int main(){
	scanf("%d%d",&n,&k);dp[n+1]=1;
	rep(i,1,k-1) per(j,n-i+1,2) upd(dp[j],dp[j+1]);
	rep(i,2,n-k+2) upd(tot,dp[i]);
	printf("%lld\n",1ll*tot*ksm(2,n-k-1)%P);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s=sc.nextInt(),w=sc.nextInt();
    if(w>=s) {
    	System.out.println("unsafe");
    }else {
    	System.out.println("safe");
    }
    
  }
}


Measured memory_bytes: 35828
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
using namespace std;

int32_t main()
{   
    int t;
    cin >> t;
    int a, b;
    cin >> a >> b;
    b = (b/t)*t ;
    if(a <= b)
    cout << "OK";
    else 
    cout << "NG";
   return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int result = 0;
		for(int i=1;i<=n;i++){
			result += i;
		}
		System.out.println(result);
	}

}


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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

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

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

vector<int>f(int n){
  vector<int>r;
  for(;n;n/=10)r.push_back(n%10);
  sort(all(r));
  return r;
}

int g(vector<int>r){
  int n=0;
  for(int x:r)n=n*10+x;
  return n;
}

int main() {

  int n;cin>>n;
  rep(i,n){
    int m; cin >> m;
    auto r=f(m);
    int x=g(r);
    reverse(all(r));
    int y=g(r);
    cout <<abs(x-y)<<endl;
  }

  return 0;
}

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

using namespace std;

// input
int n,x;
int l[100000];

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

  cin >> n >> x;
  rep(i,n) {
    cin >> l[i];
  }

  int total = 0;
  int ans = 1;

  rep(i,n) {
    total += l[i];
    if (total > x){
      break;
    }
    ans += 1;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int x;

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

    cin >> x;
    cout << (x/500)*1000+((x%500)/5)*5 << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c)<=d||max(abs(a-b),abs(b-c))<=d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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


int main(){
    string s;
    cin >> s;
    string res;
    for(int i=0; i<s.size();i++){
        if((i+1)%2 != 0){
            res += s[i];
        }

    }
    cout << res << endl;



}

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

int main() {
    int n, w;
    cin >> n >> w;
    vector<long> weight(n), value(n), dp(w + 1);
    for(int i = 0; i < n; ++i){
        cin >> weight[i] >> value[i];
    }   
    for(int i = 0; i <= w; ++i){
        if(weight[0] > i){
            dp[i] = 0;
        }else{
            dp[i] = value[0];
        }
    }
    for(int i = 1; i < n; ++i){
        vector<long> curr(w + 1);
        for(int j = 0; j <= w; ++j){
            if(weight[i] > j){
                curr[j] = dp[j];
            }else{
                curr[j] = max(dp[j], dp[j - weight[i]] + value[i]);
            }
        }
        dp = curr;
    }
    cout << dp[w] << endl;
	return 0;
}

Measured memory_bytes: 1804
"use strict";
function main(input) {
    let line = input.split(/\r?\n/g);
    let arr = line[0].split(" ");
    const H = arr[0], N = arr[1];
    let A = line[1].split(" ");
    let accum = 0;
    for (let i in A)
        accum += parseInt(A[i]);
    console.log(accum < H ? "No" : "Yes");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<vector<pair<int, int>>> g(n);
        for (int i = 0; i < n - 1; i ++) {
                int a, b, c;
                scanf("%d%d%d", &a, &b, &c);
                g[a].push_back({b, c});
                g[b].push_back({a, c});
        }
        if (n == 1) {
                printf("0\n");
                return 0;
        }
        vector<vector<int>> d(n);
        vector<int> far(n);
        function<void (int, int)> dfs = [&](int u, int prev) {
                for (auto e : g[u]) if (e.first != prev) {
                        int v = e.first;
                        dfs(v, u);
                        far[u] = max(far[u], far[v] + e.second);
                        d[u].push_back(far[v] + e.second);
                }
        };
        dfs(0, -1);
        vector<vector<int>> left(n), right(n);
        auto build = [&](int u) { //d is prepared
                left[u].resize(g[u].size());
                right[u].resize(g[u].size());
                left[u].front() = d[u].front(), right[u].back() = d[u].back();
                for (int i = 0; i < (int) g[u].size() - 1; i ++) left[u][i + 1] = max(left[u][i], d[u][i + 1]);
                for (int i = (int) g[u].size() - 1; i >= 1; i --) right[u][i - 1] = max(right[u][i], d[u][i - 1]);
                return;
        };
        build(0);
        function<void (int, int)> dfs2 = [&](int u, int prev) {
                int idx = 0;
                for (auto e : g[u]) if (e.first != prev) {
                        int v = e.first;
                        int ma = 0;
                        if (idx - 1 >= 0) ma = max(ma, left[u][idx - 1]);
                        if (idx + 1 < (int) right[u].size()) ma = max(ma, right[u][idx + 1]);
                        d[v].push_back(ma + e.second);
                        build(v);
                        dfs2(v, u);
                        idx ++;
                }
        };
        dfs2(0, -1);
        int ans = 0;
        for (int i = 0; i < n; i ++) {
                /*
                for (auto it : d[i]) {
                        cerr << it << ' ';
                }
                cerr << endl;
                */
                if (d[i].size() >= 2) {
                        sort(d[i].rbegin(), d[i].rend());
                        ans = max(ans, d[i][0] + d[i][1]);
                }
        }
        printf("%d\n", ans);
        return 0;
}




Measured memory_bytes: 36028
#include<bits/stdc++.h>
using namespace std;
#define ll  long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
ll cnt =0,ans=0;
const int MAX = 510000;

int main(){
   int n;   cin >> n;
   string s;    cin >> s;
   int l = s.size();
   
   if(l>n){
       for(int i=0;i<n;i++){
       cout << s.at(i);
   }
   cout << "..." << endl;
}
else cout << s << endl;
}
       


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

void solve(){
    int a, b; cin >> a >> b;
    if (a < 10 && b < 10) cout << a * b << endl;
    else cout << -1 << endl;    
}

int main(){
    ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//const ll mod=1000000007;
int GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(5);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    ll n;
    cin>>n;
    bool able=false;
    V<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>=n)able=true;
    }
    if(!able){
        cout<<0<<"\n";
        return 0;
    }
    ll bfo=0,inc=0;
    ll ans=0;
    while(1){
        bfo=inc;
        inc=0;
        able=false;
        for(int i=0;i<n;i++){
            if(bfo+a[i]>=n){
                able=true;
               ll d=(bfo+a[i])/n;
               inc+=d;
               a[i]=(bfo+a[i])%n;
               a[i]-=d;
            }else{
                a[i]+=bfo;
            }
        }
        ans+=inc;
        if(!able)break;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
N,K = map(int,input().split())
p = list(map(lambda x: int(x)+1,input().split()))
ans = sum(p[0:K])
s = ans
for i in range(1,N-K+1):
    s += p[i+K-1]-p[i-1]
    ans = max(ans,s)
print(ans/2)

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

int main() {
    int N;
    cin >> N;
    double ave = 0;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        ave += (double)A[i];
    }
    
    ave /= (double)N;
    
    double dis = 1000;
    int ans = -1;
    for (int i = 0; i < N; i++) {
        double res = ave-A[i]; if (res < 0) res *= (-1);
        if (res < dis) { ans = i; dis = res; }
    }
    
    cout << ans << 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;

int main()
{
    string s;
    cin >> s;
    if (s == "SSS") 
        cout << 0 << endl;
    else if (s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR")
        cout << 1 << endl;
    else if (s == "RRS" || s == "SRR")
        cout << 2 << endl;
    else
        cout << 3 << endl; 
    return 0;
}


Measured memory_bytes: 3624
def choose(D, c, s, d, last, depth, p):
    maxpoint = -999999999
    maxnum = 0
    if depth > 0 and d < D:
        for i in range(26):
            point = p
            point += s[d][i]
            point += changepoint(c, d, i, last)*1
            nlast = []
            nlast.extend(last)
            nlast[i] = d
            z, point = choose(D, c, s, d+1, nlast, depth-1, point)
            if point > maxpoint:
                maxpoint = point
                maxnum = i
        return maxnum, maxpoint
    return 0, p


def changepoint(c, d, num, last):
    point = 0
    for j in range(26):
        if j != num:
            point -= c[j]*(d-last[j])
    return point


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    last = [-1]*26
    for _ in range(D):
        s.append(list(map(int, input().split())))
    point = 0
    for i in range(D):
        num, point = choose(D, c, s, i, last, 1, 0)
        last[num] = i
        print(num+1)


main()


Measured memory_bytes: 68628
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;

typedef long long ll;

int n, ans;
char s[N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%s",s + 1);
	n = strlen(s + 1);
	for(int i = 1; i <= n; i++)
		ans += ((s[i] - '0') != i%2);
	printf("%d\n", min(ans, n - ans));
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>

using namespace std;

int main(void){
  int a,b,c,y,ans;
  
  scanf("%d%d%d%d", &a, &b, &c, &y); 
  ans = 0;
  for (int i=0; i<=a; i++){
    for (int j=0; j<=b; j++){
      int k = (y - i*500 - j*100)/50;
      if (k>=0 && k<=c) ans++;
    }
  }
  printf("%d\n", ans);
  
  return 0;
}


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

int f(int r, int xi, int D){
    return r*xi - D;
}
int main(){
    int x, r, D, i;
    scanf("%d %d %d", &r, &D, &x);
    for(i=0; i < 10; i++){
        x = f(r, x, D);
        printf("%d\n", x);
    }
    return 0;
}

Measured memory_bytes: 128
from collections import Counter
from functools import reduce
from operator import and_
n, *S = open(0).read().split()
keys = reduce(and_, map(set, S))
d = {c:10**6 for c in keys}
for counter in map(Counter, S):
    for c in keys:
        if c in counter:
            d[c] = min(d[c], counter[c])
ans = ''
for k, v in sorted(d.items()):
    ans += k * v
print(ans)

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

int main()
{
    //input

    long N;
    bool even = 0;
    vector<int> A(N);
    long sum = 0;
    long min = 1000000000;

    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if (abs(A[i]) < min)
        {
            min = abs(A[i]);
        }
        if (A[i] < 0)
        {
            even = 1 - even;
        }
    }

    //ope
    if (even == 0)
    {
        for (int i = 0; i < N; i++)
        {
            sum += abs(A[i]);
        }
    }
    else
    {
        for (int i = 0; i < N; i++)
        {
            sum += abs(A[i]);
        }
        sum -= min * 2;
    }
    cout << sum << endl;

    return 0;
}

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

int n, a, b[200005];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 2; i <= n; ++i) {
		cin >> a;
		++b[a];
	}
	for(int i = 1; i <= n; ++i) {
		cout << b[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 4368
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int x,y,z;
    cin >> x >> y >> z;
    if (x%(y + z) >= z) {
        cout << x / (y + z) << endl;
    }else{
        cout << x / (y + z) - 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 764
#include <cstdio>
#include <cmath>

int n;
int a[110];
double sum;
double avg;
double minAvg;
int mini;

int main()
{
	scanf("%d", &n);
	
	sum = 0;
	
	for (int i = 0 ; i < n ; i++)
	{
		scanf("%d", &(a[i]));
		sum += a[i];
	}
	
	avg = sum / n;
	minAvg = fabs(a[0] - avg);
	mini = 0;
	
	double curAvg;
	for (int i = 0 ; i < n ; i++)
	{
		curAvg = fabs(a[i] - avg);
		
		if (minAvg > curAvg)
		{
			minAvg = curAvg;
			mini = i;
		}
	}
	
	printf("%d\n", mini);
	
	
	return 0;
}

Measured memory_bytes: 128
import sys;input=sys.stdin.readline
class UnionFindNode:
    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.rank_ = 1
        self.member_num_ = 1

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()

        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                n_root, child = root, unite_root
            else:
                n_root, child = unite_root, root
            child.parent_ = n_root
            n_root.rank_ = max(n_root.rank_, child.rank_ + 1)
            n_root.member_num_ = n_root.member_num_ + child.member_num_

mod = 10**9+7
NNN = (10**6)
g1 = [1, 1]
for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
N, = map(int, input().split())
P = list(map(int, input().split()))
K = P.count(-1)

nodes = [UnionFindNode(i) for i in range(N)]
for i, p in enumerate(P):
    p-=1
    if p >= 0:
        nodes[p].unite(nodes[i])

rs = []
X = [0] * N
for i in range(N):
    if nodes[i].is_root():
        rs.append(i)
    if P[i] == -1:
        X[nodes[i].find()] = 1

M = len(rs)
R = N*pow(N-1, K, mod)%mod

Y = []
for i in range(M):
    if X[rs[i]]:
        Y.append(nodes[rs[i]].member_num_)
        R = (R-(nodes[rs[i]].member_num_-1)*pow(N-1, K-1, mod))%mod
    else:
        R = (R-pow(N-1, K, mod))%mod
nY = len(Y)
dp = [[0]*(nY+1) for _ in range(nY+1)]
dp[0][0] = 1
for i in range(nY):
    for j in range(nY):
        dp[i+1][j] = (dp[i][j] * Y[i] + (dp[i][j-1] if j > 0 else 0)) % mod
for i in range(nY):
    if nY-i == 1:
        continue
#    print(nY-i, dp[-1][i])
    R -= pow(N-1, K-(nY-i), mod) * g1[nY-i-1] * dp[-1][i]
    R %= mod
print(R)


Measured memory_bytes: 273052
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S; ll K;
    cin >> S >> K;

    int d = 1;
    int i = 0;
    REP(j, S.size()) {
        int sd = S[j] - '0';
        if (sd != 1) {
            d = sd;
            i = j;
            break;
        }
    }

    if (d == 1) {
        print(1);
        return 0;
    }

    if (i <= K - 1) {
        print(d);
    } else {
        print(1);
    }

    return 0;


}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main(){
    
    while(true){
        int h,w;
        int m[50][50];
        bool used[50][50]={0};
        int dx[]={-1,0,1};
        int dy[]={-1,0,1};
        int ans=0;
        
        cin >> w>>h;
        if(h==0&&w==0)break;
        
        rep(i,h){
            rep(j,w){
                cin >> m[i][j];
            }
        }
        
        rep(i,h){
            rep(j,w){
                if(m[i][j]==1&&!used[i][j]){
                    ans++;
                    queue<P> que;
                    que.push(P(i,j));
                    while(!que.empty()){
                        P p=que.front();que.pop();
                        int x = p.second,y=p.first;
                        rep(a,3){
                            rep(b,3){
                                int nx=x+dx[a],ny=y+dy[b];
                                if(nx>=0&&nx<w&&ny>=0&&ny<h&&m[ny][nx]==1&&!used[ny][nx]){
                                    que.push(P(ny,nx));
                                    used[ny][nx]=true;
                                }
                            }
                        }
                    }
                }
            }
        }
        cout << ans<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3076
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int p=1000000007;
const int N=2000;
long long f[N*2+10][N*2+10],x,y,ans,step[200005],finv[8005];
long long n,a[200005],b[200005],amax=2002,bmax=2002,d[8005];
void cou(int num)
{
	step[num]=d[a[num]+b[num]];
	step[num]=(step[num]*finv[a[num]])%p;
	step[num]=(step[num]*finv[b[num]])%p;
}
long long cheng(long long a,long long b)
{
	long long now=a,ans=1;
	while(b)
	{
		if(b&1)
			ans=(now*ans)%p;
		b>>=1;
		now=(now*now)%p;
	}
	return ans;
}
void chuli()
{
	d[1]=1;
	for(int i=2;i<=8000;i++)
		d[i]=(d[i-1]*i)%p;
	finv[8000]=cheng(d[8000],p-2);
	for(int i=7999;i>=1;i--)
		finv[i]=(finv[i+1]*(i+1))%p;
}
int main()
{
	scanf("%lld",&n);
	chuli();
	for(int i=1;i<=n;i++)
	{
		scanf("%lld %lld",&a[i],&b[i]);
		a[i]*=2;b[i]*=2;
		cou(i);
		a[i]/=2;b[i]/=2;
	}
	for(int i=1;i<=n;i++)
	{
		f[amax-a[i]][bmax-b[i]]++;
		a[i]=amax+a[i];
		b[i]=bmax+b[i];
	}
	x=2*amax;y=2*bmax;
	for(int i=1;i<=x;i++)
	{
		for(int j=1;j<=y;j++)
		{
			f[i][j]+=f[i-1][j]+f[i][j-1];
			f[i][j]%=p;
		}
	}
	for(int i=1;i<=n;i++)
	{
		ans+=f[a[i]][b[i]]-step[i];
		ans%=p;
	}
	ans=(ans+p)%p;
	x=cheng(2,p-2);
//	printf("x=%d\n",x);
	ans=(ans*x)%p;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 130432
#include <iostream>
#include <string>
#include <cctype>
#include <cmath>

using namespace std;

int main() {
  int W, a, b;
  cin >> W >> a >> b;
  if (b + W < a) cout << a - b - W;
  else if (a + W < b) cout << b - a - W;
  else cout << 0;
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
/*
      author : nishi5451
      created: 11.08.2020 00:09:41
*/

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


int main(){
    string s;
    cin >> s;
    s[5]=' ';
    s[13]=' ';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3572
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

a, b, ab, x, y = map(int, input().split())

ans = float('inf')
for i in range(max(x, y)+1 ):
    price = i * 2 * ab + max(0, x-i)*a + max(0, y-i)*b
    ans = min(ans, price)

print(ans)


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

using namespace std;

#define gettime printf("\nTime : %0.3lf\n",clock()*1.0/CLOCKS_PER_SEC);
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repp(i,a,b) for(int i=a;i>=b;i--)
#define Set(x,a) memset(x,a,sizeof(x));

#define vs vector<string>
#define vi vector<int>
#define ll long long
#define ff first
#define ss second

struct comp {
       bool operator() (int a,int b) {
            return a>b;
       }
};

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //std::ios::sync_with_stdio(false);
    bool status = true;
    int lastX = 0;
    int lastY = 0;
    int lastT = 0;
    int x;
    int y;
    int t;
    int n;

    scanf("%d", &n);
    rep(i,1,n) {
        scanf("%d %d %d", &t, &x, &y);
        if (status) {
            int diff = abs(lastX - x) + abs(lastY - y);
            if (!(diff <= t - lastT && (t - lastT - diff) % 2 == 0)) status = false;
        }
    }

    if (status) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

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

    if (abs(A - B) % 2 == 0)
    {
        cout << "Alice" << endl;
    }
    else
    {
        cout << "Borys" << endl;
    }
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<queue>
#include<functional>
using namespace std;

constexpr int INF = 1e9;

struct edge {
	int from, to, cost;
	bool operator>(const edge& other)const {
		return cost > other.cost;
	}
};

using edges = vector<edge>;
using graph = vector<edges>;

void add_edge(graph& g, int from, int to, int cost) {
	g[from].push_back(edge{ from,to,cost });
	g[to].push_back(edge{ to,from,cost });
}


edges prim(const graph& g) {
	const int N = g.size();
	vector<bool>used(N);
	used[0] = true;
	priority_queue<edge, vector<edge>, greater<edge>>p_que;
	for (auto e : g[0]) {
		p_que.push(e);
	}
	edges mst;
	while (!p_que.empty()) {
		auto e = p_que.top();
		p_que.pop();
		if (used[e.to]) {
			continue;
		}
		mst.push_back(e);
		used[e.to] = true;
		for (auto new_e : g[e.to]) {
			p_que.push(new_e);
		}

	}
	return mst;
}

int main() {
	int V, E;
	cin >> V >> E;
	graph g(V);
	for (int i = 0; i < E; i++) {
		int from, to, cost;
		cin >> from >> to >> cost;
		add_edge(g, from, to, cost);
	}
	const auto mst = prim(g);
	int ans = 0;
	for (auto& e : mst) {
		ans += e.cost;
	}
	cout << ans << endl;
	return 0;
}










Measured memory_bytes: 10124
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
ans = 0
for i in range(N):
    l,r = I()
    ans += r-l+1
print(ans)

Measured memory_bytes: 77692
n = int(input())
selection=list(map(int,input().split()))
count = 0

for i in range(len(selection)):
    minj = i
    for j in range (i,len(selection)):
        if selection[j] < selection[minj]:
            minj = j
    if i != minj:
        count = count+1      
        selection[i],selection[minj] = selection[minj],selection[i]
print(*selection)
print(count)


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

int main(){
    int D, N;
    cin >> D >> N;
    vector<int> a;
    for (int i = 1; i < 100000000; i++){
        int count = 0;
        int use_i;
        use_i = i;
        while (use_i % 100 ==0){
            count++;
            use_i /= 100;
        }
        if (count == D){
            a.push_back(i);
        }
        if (a.size() > 100){
            break;
        }
    }
    cout << a.at(N - 1) << endl;

}

Measured memory_bytes: 256
from fractions import Fraction
n, k = map(int, input().split())
ans = Fraction(0)
for i in range(1, n + 1):
    d = i
    p = 0
    while d < k:
        d = d << 1
        p += 1
    ans += Fraction(1, pow(2, p) * n)
print('{:.12f}'.format(float(ans)))


Measured memory_bytes: 5476
#![allow(unused_macros, unused_imports, dead_code)]

use std::io;
use std::process;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! reads {
    ($($t:ty),+) => {
        {
            let line = read_line();
            let mut it = line.trim().split_whitespace();
            let result = (
                $(it.next().unwrap().parse::<$t>().unwrap(),)+
            );
            assert!(it.next().is_none());
            result
        }
    };
}

fn read_vec() -> Vec<i64> {
    let line = read_line();
    let it = line.trim().split_whitespace();
    it.map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let INF: i64 = 10i64.pow(10);

    let (N, M) = reads!(usize, usize);
    let mut edges = vec![vec![]; N];

    for _ in 0..M {
        let (mut L, mut R, D) = reads!(usize, usize, i64);
        L = L-1; R = R-1;
        edges[L].push((R, D));
        edges[R].push((L, -D));
    }

    let mut visited = vec![false; N];
    let mut place = vec![0; N];

    fn walk(i: usize, mut visited: &mut Vec<bool>, mut place: &mut Vec<i64>, edges: &Vec<Vec<(usize, i64)>>) {
        if visited[i] {
            return;
        }
        visited[i] = true;
        for &(j, d) in &edges[i] {
            if visited[j] && (place[j] != place[i] + d) {
                println!("No");
                process::exit(0);
            }
            place[j] = place[i] + d;
            walk(j, &mut visited, &mut place, &edges);
        }
    }

    for i in 0..N {
        if !visited[i] {
            place[i] = 0;
            walk(i, &mut visited, &mut place, &edges);
        }
    }

    println!("Yes");
}

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

int main(){
    string S;
    cin >> S;
    int N;
    N = S.size();
    int count = 0;
    for ( int i = 0; i < N; ++i ){
        if ( S[i] != S[N-1-i] ){
            count = count + 1;
        }
    }
    
    cout << count / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val a = Array<Int>(101, { 0 })
    for (i in 1..n) {
        var d = scanner.nextInt()
        a[d] = 1
    }
    val answer = a.reduce { n1, n2 -> n1 + n2 }
    println(answer)
}

Measured memory_bytes: 31384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	vector<bool > hr(n);
	vector<int >ct(n,1);
	hr[0]=true;
	for(int i=0,from,to;i<m;i++){
		cin>>from>>to;
		from--;
		to--;
		if(hr[from]){
			hr[to]=true;
			ct[from]--;
			ct[to]++;
			if(ct[from]==0)hr[from]=false;
		}
		else{
			ct[from]--;
			ct[to]++;
		}
	}
	int fina=0;
	for(int i=0;i<n;i++)if(hr[i])fina++;
	cout<<fina<<'\n';
}

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

int main() {

    int a, b;
    char s[10];
    char t[10];
    char u[10];

    scanf("%s %s", s, t);
    scanf("%d%d", &a, &b);
    scanf("%s", u);

    if (strcmp(u, s) == 0) {
        printf("%d %d", a - 1, b);
    } else {
        printf("%d %d", a, b - 1);
    }

    return 0;

}


Measured memory_bytes: 128
n = int(input())
a,b = list(map(int,input().split()))
p = list(map(int ,input().split()))
q1 = []
q2 = []
q3 = []
for i in p:
  if i <= a:
    q1.append(i)
  elif i <= b:
    q2.append(i)
  else:
    q3.append(i)
print(min(len(q1),len(q2),len(q3)))

Measured memory_bytes: 3064