akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define lol long long
int main(){
  int w1,h1,n,x,y,a,minw=0,minh=0;
  cin>>w1>>h1>>n;
  int w=w1,h=h1;
  for(int i=0;i<n;i++){
    cin>>x>>y>>a;
    if(a==2) if(w>x) w=x;
    if(a==1) if(minw<x) minw=x;
    if(a==4) if(h>y) h=y;
    if(a==3) if(minh<y) minh=y;
  }
  if(minw<w && minh<h)
  cout<<(w-minw)*(h-minh)<<"\n";
  else cout<<0<<"\n";
  return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}


int main() {
	int i, j, k;
	int N, M, K;

	string S;

	ll A;
	cin >> A;
	cin >> S;
	j = 2;
	ll B=0;
	for (i = 0; i < S.size(); i++) {
		if (i == 1)continue;
		B += (S[i] - '0') * pow(10, j);
		j--;
	}

	cout << (ll)(A * B)/100;


}

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

int n ;
int a[ 4 ] ;

void input ( ) {
    cin >> n ;
    string s ;
    while ( n -- ) {
        cin >> s ;
        if ( s == "AC" ) { ++ a[ 0 ] ; }
        if ( s == "WA" ) { ++ a[ 1 ] ; }
        if ( s == "TLE" ) { ++ a[ 2 ] ; }
        if ( s == "RE" ) { ++ a[ 3 ] ; }
    }
}

void solve ( ) {
    cout << "AC x " << a[ 0 ] << "\n" ;
    cout << "WA x " << a[ 1 ] << "\n" ;
    cout << "TLE x " << a[ 2 ] << "\n" ;
    cout << "RE x " << a[ 3 ] << "\n" ;
}



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


Measured memory_bytes: 3656
// #include <bits/stdc++.h>
// using namespace std;
// #define REP(i, n) for(int i = 0; i < (n); ++i)
// #define REPR(i, n) for (int i = n; i >= 0; --i)
// #define FOR(i, n, m) for (int i = m; i < n; i++)
// #define INF 1e9
// #define ALL(v) v.begin(), v.end()
#include <stdio.h>
#include <stdlib.h>
// typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/

#define MAX 2000001
#define VMAX 10000

int main()
{
    unsigned short *A, *B;
    int C[VMAX + 1];
    int n, i, j;
    scanf("%d", &n);
    A = malloc(sizeof(short) * n + 1);
    B = malloc(sizeof(short) * n + 1);
    for(i = 0; i <= VMAX; i++) C[i] = 0;

    for(i = 0; i < n; i++) {
        scanf("%hu", &A[i+1]);
        C[A[i + 1]]++;
    }

    for(i = 1; i <= VMAX; i++) C[i] = C[i] + C[i-1];

    for(j = 1; j <= n; j++) {
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }

    for(i = 1; i <= n; i++) {
        if (i > 1) printf(" ");
        printf("%d", B[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 9564
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
	int d, e;
	while (cin >> d >> e) {
		if (d == 0 && e == 0) {
			break;
		}
		double ans = 1000.0;
		for (int i = 0; i <= d; i++) {
			double x = i;
			double y = d - i;
			ans = min(ans, abs(sqrt(x*x + y*y)-e));
		}
		printf("%.5f\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

void dfs(string S, char mx, int &N)
{
    // ベースライン
    if (S.length() == N)
    {
        cout << S << endl;
        return;
    }

    // 今までに存在する文字の最大辞書数の更新
    char mx_dist = 'a';
    for (char c : S)
    {
        mx_dist = max(mx_dist, c);
    }
    mx = ++mx_dist;

    //再起ステップ
    //末尾に文字を付け足す・ただし今までに存在する文字の最大辞書数+1まで
    for (char i = 'a'; i <= mx; i++)
    {
        dfs(S + i, mx, N);
    }
}
int main()
{
    int N = 0;
    cin >> N;
    dfs("a", 'a', N);
    return 0;
}

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

int main()
{
  int A, B, ans;

  cin >> A >> B;

  ans = 0;

  if (A >= 13)
  {
    ans = B;
  }
  else if (A >= 6)
  {
    ans = B / 2;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,result=0,tmp=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];

  scanf("%lld",&n);
  rep(i,n) scanf("%d",&a[i]);
  
  rep(i,n-1){
    if(a[i]>=a[i+1]){
      tmp++;
    }else{
      result = max(result,tmp);
      tmp=0;
    }
  }
  result = max(result,tmp);
  printf("%lld",result);
  return 0;
}



Measured memory_bytes: 2176
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>

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

int main(void){
    int i;
    int N, sum = 0;
    scanf("%d",&N);

    int a[N], b[N], c[N-1];
    REP(i,N){
        scanf("%d",&a[i]);
    }
    REP(i,N){
        scanf("%d",&b[i]);
        sum += b[i];
    }
    REP(i,N-1){
        scanf("%d",&c[i]);
    }

    REP(i,N-1){
        if(a[i+1]==a[i]+1) sum += c[a[i]-1];
    }

    printf("%d",sum);
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
vector<ll> p, c;
ll result = MOD;
ll max;
ll g;
void saiki(ll sum, ll k, ll max, ll r){
  //cout << sum spa k spa max spa r << endl;
  if(k == 0){
    if(sum < g){
      ll z;
      for(z = 0; z < p[max - 1] && sum < g; z++){
        sum += max * 100;
        r++;
        //cout << sum spa z spa r spa g << endl;
      }
      if(z == p[max - 1])
        sum += c[max - 1];
    }
    if(sum >= g)
      chmin(result, r);
  }
  else{
    saiki(sum, k - 1, max, r);
    if(max == k)
      saiki(sum + 100 * p[k - 1] * k + c[k - 1], k - 1,max - 1, r + p[k - 1]);
    else
      saiki(sum + 100 * p[k - 1] * k + c[k - 1], k - 1, max, r + p[k - 1]);
  }
}
      
  
  
  
  
 
 
int main(){
  ll i, j;
  ll d;
  cin >> d >> g;
  ll a, b;
  for(i = 0; i < d; i++){
    cin >> a >> b;
    p.push_back(a);
    c.push_back(b);
  }
  saiki(0, d, d, 0);
  cout << result << endl;
    
        
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define N 10000000
int main() {
	int i, j, ans, *p, n;
	p = (int*)calloc(N, sizeof(int));
	for (i = 2; i <= (int)sqrt((double)N); ++i) if (!*(p + i)) for (j = 2; j*i < N; j++) *(p + i*j) = 1;
	while (fscanf(stdin,"%d", &n),n!=0) {
		ans = 0;
		for (i = n; i >= 13; i--) if (!*(p + i)&& !*(p + i - 2)&& !*(p + i - 6)&& !*(p + i - 8)) { ans = i; break; }
		fprintf(stdout,"%d\n", ans);
	}
	free(p);
	return 0;
}

Measured memory_bytes: 39532
import java.io.*;
import java.util.*;

@SuppressWarnings("unused")
class Main {

    // Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long M;
        M = sc.nextLong();

        PriorityQueue<Integer> A = new PriorityQueue<>(Comparator.reverseOrder());
        for(int i = 0 ; i < N ; i++){
            A.add(sc.nextInt());
        }
        solve(N, M, A);
    }

    static void solve(long N, long M, PriorityQueue<Integer> A){
        for (int i = 0; i < M; i++) {
            int max = A.poll();
            A.offer(max/2);
        }
        long ans = 0;
        for (int i : A) {
            ans += i;
        }
        System.out.println(ans);
    }
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll N, D;
    cin >> N >> D;
    vvll x(N, vll(D, 0));
    rep(i, N){
        rep(j, D){
            cin >> x[i][j];
        }
    }
    ll count = 0;
    rep(i, N){
        REP(j, i+1, N){
            ll sum = 0;
            rep(k, D){
                sum += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            ll sq = sqrt(sum);
            if(sq*sq==sum) ++count;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String[] args) {
	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	try {
		String line1 = reader.readLine();
		String line2 = reader.readLine();
		
		char c1[] = line1.toCharArray();
		char c2[] = line2.toCharArray();
		
		if(c1.length == c2.length) {
			for(int i=0;i<c1.length;i++) {
				System.out.print(c1[i]+""+c2[i]);
			}
		}
		else {
			for(int i=0;i<c1.length-1;i++) {
				System.out.print(c1[i]+""+c2[i]);
			}
			System.out.print(c1[c1.length-1]);
		}
		
		
	}catch(IOException e){
		System.out.println(e);
	}
	}
}

Measured memory_bytes: 21076
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

template<typename T>
map<T, ll> get_zaatu(vector<T> vals) {
  sort(all(vals));
  vals.erase(unique(all(vals)), vals.end());
  map<T, ll> res;
  rep(i, vals.size()) res[vals[i]] = i;
  return res;
}
template<typename T>
vector<T> zaatu(vector<T> vals) {
  map<T, ll> z = get_zaatu(vals);
  each(x, vals) x = z[x];
  return vals;
}

void solve() {
  ll h, w, n; cin >> w >> h >> n;
  vector<ll> X(n), Y(n);
  rep(i, n) {
    cin >> X[i] >> Y[i]; --X[i], --Y[i];
  }
  map<ll, vector<ll>> m;
  ll ans = w;
  rep(i, n) {
    if (Y[i] == 0) {
      chmin(ans, X[i]);
    }
    else {
      m[Y[i]].pb(X[i]);
    }
  }
  each(p, m) sort(all(p.second));
  ll x = 0, y = 0, step = 0;
  each(p, m) {
    ll ny = p.first-1;
    ll nx = x + (ny - y);
    step += ny - y;
    each(xx, p.second) {
      if (xx <= nx) continue;
      if (xx == nx+1) {
        ++nx;
        ++step;
      }
      else {
        break;
      }
    }
    ++nx, ++ny, ++step;
    ll xw = w;
    each(xx, p.second) {
      if (xx > nx) {
        xw = xx;
        break;
      }
    }
    chmin(ans, step + xw - nx);
    x = nx, y = ny;
    // cout << x << " " << y << " " << step << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 17024
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int A, B;
int main() {
  while (cin >> A >> B) {
	A += 11; A %= 13;
	B += 11; B %= 13;
	if (A < B) puts("Bob");
	else if (A > B) puts("Alice");
	else puts("Draw");
  }
}
																				   

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

#define REP(i, n) for(int i = 0;i < (int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

int main() {
  int N, K, S = 0;
  cin >> N >> K;
  vector<int> v(N);
  REP(i, N) {
    cin >> v[i];
  }
  sort(ALL(v));
  REP(i, K) {
    S += v[i];
  }
  cout << S << endl;
}

Measured memory_bytes: 3628
def main():

    from bisect import bisect_left as bl, bisect_right as br, insort
    import sys,heapq,math
    from collections import defaultdict as dd, deque
    def data(): return sys.stdin.readline().strip()
    def mdata(): return list(map(int, data().split()))
    out = sys.stdout.write
    # sys.setrecursionlimit(100000)
    INF = int(1e9)
    mod = int(1e9)+7

    n,m=mdata()
    H=mdata()
    l=[1]*n
    for i in range(m):
        a,b=mdata()
        if H[a-1]<H[b-1]:
            l[a-1]=0
        elif H[a-1]>H[b-1]:
            l[b-1]=0
        else:
            l[a-1]=0
            l[b-1]=0
    cnt=0
    for i in l:
         if i==1:
             cnt+=1
    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 81904
#include <bits/stdc++.h>
#define lint long long
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
using namespace std;

int main(){
  cout << fixed << setprecision(12);
  int A,B,H,M;
  cin >> A >> B >> H >> M;
  
  int mindeg = M * 6;
  double hourdeg = H * 30 + M / 2.0;
  double deg = max(hourdeg - mindeg, mindeg - hourdeg);
  deg = min(deg, 360-deg);
  double theta = deg * 3.14159265358979 / 180.0;
  
  // cout << deg << endl;
  
  double xx = A*A + B*B - 2*A*B*cos(theta);
  

  cout << sqrt(xx) << endl;
}
  
  
  


Measured memory_bytes: 4056
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;



signed main() {
	int n; cin >> n;
	int k = n / 15;
	int ans = n * 800 - k * 200;
	cout << ans << endl;
}

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

int main(void){
    int n, k, d[10];
    cin >> n >> k;
    for (int i = 0; i < k; i++) cin >> d[i];
    
    for (int i = n; i <= 200000; i++) {
        int i_c = i, l[5], lcnt = 0;
        while (i_c != 0) {
            l[lcnt] = i_c % 10;
            i_c /= 10;
            lcnt++;
        }
        
        bool ans = true;
        for (int j = 0; j < lcnt; j++) {
            for (int m = 0; m < k; m++) {
                if (l[j] == d[m]) ans = false;
            }
        }
        
        if (ans) {
            cout << i << endl;
            return 0;
        }
        
    }
    
}


Measured memory_bytes: 256
K = input()
N = len(K)
D = int(input())
mod = 10**9+7

dp = [[[0]*D for _ in range(2)] for _ in range(N+1)]
dp[0][0][0] = 1

for i in range(N):
    a = ord(K[i])-48
    for j in range(D):
        for k in range(10):
            b = (j+k)%D
            dp[i+1][1][b] += dp[i][1][j]
            dp[i+1][1][b] %= mod

            if k<a:
                dp[i+1][1][b] += dp[i][0][j]
                dp[i+1][1][b] %= mod
    
    for j in range(D):
        b = (j+a)%D
        dp[i+1][0][b] += dp[i][0][j]
        dp[i+1][0][b] %= mod

print((dp[N][1][0]+dp[N][0][0]-1)%mod)

Measured memory_bytes: 61788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		//入力表示

		double a = sc.nextInt();
		double b = sc.nextInt();
		double h = sc.nextInt();
		double m = sc.nextInt();

		double rad = Math.PI * 2 * (h / 12.0 + (m / 60.0) / 12.0 - m / 60.0);

		double rsq = Math.sqrt((a * a + b * b) - (2 * a *
				b) * Math.cos(rad));

		System.out.printf("%.20f", rsq);

	}
}

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

#define rep(i, x, y) for (int i = (x), _ = (y); i <= _; ++i)
#define down(i, x, y) for (int i = (x), _ = (y); i >= _; --i)
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define bin(x) (1 << (x))
//#define LX_JUDGE

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

template<typename T> inline void upmax(T &x, T y) { x < y ? x = y : 0; }
template<typename T> inline void upmin(T &x, T y) { x > y ? x = y : 0; }

const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;

inline ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }

int main() {
#ifdef LX_JUDGE
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	ll n, x;
	cin >> n >> x;
	cout << (n - gcd(n, x)) * 3 << endl;
	return 0;
}


Measured memory_bytes: 256
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         fozubaoyou    pass System Test!
*/
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define pb push_back
using ll = long long;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

bool Stripper(int _N){
  int temp1 = _N;
  int res;
  if(_N <= 10){
    return true;
  }else{
    while(temp1){
      int dig = temp1 % 10;
      res = res + dig;
      temp1 = temp1 / 10;
    }
  }

  if(_N % res == 0){
    return true;
  }else{
    return false;
  }

}

signed main(){
  int N;
  cin >> N;
  
  if(Stripper(N)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;

  }

}


Measured memory_bytes: 256
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

using namespace std;

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

typedef long long ll;

int n,k;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	cin>>n>>k;
	cout<<((((n+1)/2)>=k) ? "YES" : "NO");
	
	//printf("Time used = %.4f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int t=i,d=0;
		while(t!=0)
		{
			d++;
			t/=10;
		}
		if(d%2!=0) ans++;
	}
	cout<<ans;
	return 0;
}

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

int main(){
	const string t("Hoshino"), t2("Hoshina");
	int n;
	cin >> n;
	string s;
	getline(cin, s);
	for(int i = 0; i < n; i++){
		getline(cin, s);
		string::iterator iter = search(s.begin(), s.end(), t.begin(), t.end());
		for(string::iterator it = s.begin(); it != iter; it++) cout << *it;
		while(iter != s.end()){
			cout << t2;
			iter += t2.size();
			string::iterator it = iter;
			iter = search(iter, s.end(), t.begin(), t.end());
			for(;it != iter; it++) cout << *it;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)
const ll mod = 1e9+7;


int main(){
  int a,b;
  cin >> a >> b;
  int now = 1;
  int ans = 0;
  while(now < b){
    now += a - 1;
    ans++;
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 3640
#define _CRT_SECURE_NO_WARNINGS
#include <array>
#include <cstdio>

using namespace std;

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int main()
{
    const char *YES = "YES";
    const char *NO = "NO";

    int N, M;

    gc(N);
    gc(M);

    array<int, 100000> ab;
    ab.fill(0);

    for (int i = 0; i < M; i++)
    {
        int a, b;
        gc(a);
        gc(b);
        ab[a]++;
        ab[b]++;
    }

    for (int i = 0; i < N; i++)
    {
        if (ab[i] % 2 == 1)
        {
            printf("%s\n", NO);
            return 0;
        }
    }

    printf("%s\n", YES);
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int i=0; i<n; i++)
#define FOR1(i, n) for(int i=1; i<=n; i++)
#define FORI(i, n) for(int i=n-1; i>=0; i--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int T = 1;
//    cin >> T;
    FOR1(tt, T){
        int n;
        cin >> n;
        vector<int> L(n);
        FOR(i, n) cin >> L[i];
        sort(L.begin(), L.end());

        int sol = 0;
        FOR(i, n){
            for(int j=i+1; j<n; j++) if (L[i] != L[j]){
                    for(int k=j+1; k<n; k++) if (L[k] != L[j] && L[i]+L[j] > L[k])
                            sol++;
                }
        }
        cout << sol << endl;
    }

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define print(n) cout << n << endl
#define in(v) int v; cin >> v
#define vint vector<int>
#define pb push_back
typedef long long int ll;

int main(){
  int n,m;cin>>n>>m;int h[n+1][2];int a[m],b[m];
  int cnt=0;
  rep(i,n){
    cin>>h[i][0];
    h[i][1]=1;
  }
  rep(i,m){
    cin>>a[i]>>b[i];
    if(h[a[i]-1][0]<h[b[i]-1][0]){
      h[a[i]-1][1]=0;
    }else if(h[a[i]-1][0]>h[b[i]-1][0]){
      h[b[i]-1][1]=0;
    }else{
      h[a[i]-1][1]=0;
      h[b[i]-1][1]=0;
    }
  }
  rep(i,n){
    if(h[i][1]==1)cnt++;
  }
  print(cnt);
  return 0;
}

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

int main(void)
{
	long long N;
	long long d[101] = {};

	long long ln;

	cin >> N;
	N--;

	for(int i = 0; i < N; i++)
		cin >> d[i];
	cin >> ln;



	long long dp[2][21] = {{},{}};
	long long *acc = dp[0], *next_acc = dp[1];

	acc[d[0]] = 1ll;
	
	for(int i = 1; i < N; i++){
		for(int j = 0; j <= 20; j++){
			long long add = j + d[i];
			long long minu= j - d[i];
			
			if(add <= 20){
				next_acc[add] += acc[j];

			}
			if(minu >= 0){
				next_acc[minu]+= acc[j];

			}
			acc[j] = 0;	

		}
 
		swap(acc, next_acc);

	}

//	cout << endl << endl;
//	for(int i = 1; i <= 20; i++)
//		cout << i << ':' << acc[i] << endl;
cout << acc[ln] << endl;

		
	return 0;
}

Measured memory_bytes: 1156
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 205
#define MAXR 1005
#define MAXM 10005
int N,M,R;
int S[MAXN][MAXN],L[MAXN][MAXN];
int task[MAXR];
int dp[MAXR][MAXN];
int main()
{
	while(1)
	{
		scanf("%d%d",&N,&M);
		if(!N&&!M)break;
		for(int i=1;i<=N;i++)
			for(int j=1;j<=N;j++)
				S[i][j]=L[i][j]=1000000;
		for(int i=1;i<=N;i++)
			S[i][i]=L[i][i]=0;
		for(int i=1;i<=M;i++)
		{
			int a,b,t;char s[3];
			scanf("%d%d%d%s",&a,&b,&t,s);
			if(s[0]=='S')
			{
				S[a][b]=min(S[a][b],t);
				S[b][a]=min(S[b][a],t);
			}
			else
			{
				L[a][b]=min(L[a][b],t);
				L[b][a]=min(L[b][a],t);
			}
		}
		for(int k=1;k<=N;k++)
			for(int i=1;i<=N;i++)
				for(int j=1;j<=N;j++)
				{
					S[i][j]=min(S[i][j],S[i][k]+S[k][j]);
					L[i][j]=min(L[i][j],L[i][k]+L[k][j]);
				}
		scanf("%d",&R);
		for(int i=1;i<=R;i++)
			scanf("%d",task+i);
		for(int i=1;i<=R;i++)
			for(int j=1;j<=N;j++)
				dp[i][j]=1000000;
		dp[1][task[1]]=0;
		for(int i=2;i<=R;i++)//the Captain position
			for(int j=1;j<=N;j++)//the Ship position
			{
				dp[i][j]=min(dp[i][j],dp[i-1][j]+L[task[i-1]][task[i]]);
				for(int k=1;k<=N;k++)
					dp[i][k]=min(dp[i][k],dp[i-1][j]+L[task[i-1]][j]+S[j][k]+L[k][task[i]]);
			}
		int ans=0x7FFFFFFF;
		for(int i=1;i<=N;i++)
			ans=min(ans,dp[R][i]);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3716
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe
import qualified Data.Vector           as BV

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  n <- getInt
  tss <- BV.replicateM n $ do
    m <- getInt
    replicateM m $ do
      [x, y] <- getIntList
      return (x-1, y)

  let
    solve :: Int -> Int -> Int
    solve x y | x == 0    = y
              | otherwise = solve (x - 1) (max (solve' n x 0) y)
    solve' i x m | i == -1 = m
                 | otherwise =
                   let
                     c = check i x
                   in
                     if c >= 0 then solve' (i-1) x (m+c) else -1
    check i x = if testBit x i
      then if and $ map (\(a, b) -> testBit x a == (b == 1)) (tss BV.! i)
           then 1
           else -1
      else 0

  print $ solve ((1 `shift` n) - 1) 0

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    string S;
    cin>>S;
    cout<<((S[2]==S[3] && S[4]==S[5]) ? "Yes" : "No")<<endl;
    return 0;
}


Measured memory_bytes: 256
s = gets.chomp
q = gets.to_i
queries = q.times.map{ gets.split(" ") }

reversed = false
head = ""
tail = ""
queries.each do |query|
  if query[0] == "1"
    reversed = !reversed
  elsif query[1] == "1"
    (reversed ? tail : head) << query[2]
  else
    (reversed ? head : tail) << query[2]
  end
end

if reversed
  puts tail.reverse + s.reverse + head
else
  puts head.reverse + s + tail
end


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

int main(){
  int N;
  cin >> N;
  vector<int> A;
  for(int i=0; i<N; i++){
    int a; cin >> a;
    A.push_back(a);
  }
  int count=0;
  for(int i=0; i<N; i++){
    if(i+1==A[A[i]-1]) count++;
  }
  cout << count/2 << endl;
  return 0;
}


Measured memory_bytes: 892
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a=0;
    a=a+sc.nextInt();
    a=a+sc.nextInt();
    a=a+sc.nextInt();
    if(a>21){
      System.out.println("bust");
    }else{
      System.out.println("win");
    }
  }
  

  
}

Measured memory_bytes: 23764
/*
A3114:Min Element
 */
#include <stdio.h>

 
int main()
{
  int i,v,minv,ret,n;

  scanf("%d",&n);
  scanf("%d",&minv);

  for(i=1,ret=0;i<n;i++)
    {
      scanf("%d",&v);
   
      if(v<minv)
	{ ret=i;
	  minv=v;
	}
  }
  printf("%d\n",ret+1);
  return(0);
}



Measured memory_bytes: 2116
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
using namespace std;

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


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

int main() {
	int n, t;
	cin >> n >> t;
	vector<pair<int, int>> pairs;

	for (int i = 0; i < n; ++i) {
		int c, t;
		cin >> c >> t;
		pairs.push_back(make_pair(c, t));
	}
	
	int min_cost = 1001;
	bool isFound = false;
	
	auto itr = pairs.begin();
	for (itr; itr != pairs.end(); ++itr) {
		if (itr->second <= t) {
			if(itr->first < min_cost) {
				isFound = true;
				min_cost = itr->first;
			}
		}
	}
	if (isFound) {
		cout << min_cost << endl;
	} else {
		cout << "TLE" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
    
    double x1,y1,x2,y2,d,d1,d2;
    
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    
    d1=pow(x2-x1,2);
    d2=pow(y2-y1,2);
    d=sqrt(d1+d2);
    printf("%.8f\n",d);
    
    return 0;
    
}



Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;

int main(){
	int n;
	
	while(cin>>n,n){
		string str="";
		string bef="",aft="";
		for(int i=0;i<n;i++){
			char b,a;
			cin>>b>>a;
			bef+=b;
			aft+=a;
		}
		int n2;
		cin>>n2;
		for(int i=0;i<n2;i++){
			char a;
			cin>>a;
			for(int j=0;j<n;j++){
				if(a==bef[j]){
					a=aft[j];
					break;
				}
			}
			str+=a;
		}
		cout<<str<<endl;
	}
	return 0;
}

Measured memory_bytes: 1344
#include<iostream>
using namespace std;
 
int main(){
    int n,i,j,k;
    cin>>n;
    long long A,B,C=0;
    cin>>A>>B;
    for(i=3;i<=n;i++){
        long long t;
        cin>>t;
        C^=t;
    }
    long long D=A+B-C>>1;
    if(A+B-C & 1 || D<0 || D>A || D&C){
        cout<<"-1\n";
        return 0;
    }
    long long a=D;
    for(i=60;i>=0;i--){
        if(C>>i & 1 && D>>i&1^1&&(a|1ll<<i)<=A){
            a|=1ll<<i;
        }
    }
    if(a==0){
        cout<<"-1\n";
        return 0;
    }
    cout<<A-a<<endl;
 
    return 0;
}

Measured memory_bytes: 3644
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main (String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		int a[], b[];
		boolean flag;
		int count;

		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			a = new int[n];
			b = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
			}
			flag = true;
			count = 0;

			while (flag) {
				flag = false;
				HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
				for (int i = 0; i < n; i++) {
					if (map.get(a[i]) == null) {
						map.put(a[i], 1);
					} else {
						map.put(a[i], map.get(a[i]) + 1);
					}
				}
				for (int i = 0; i < n; i++) {
					b[i] = map.get(a[i]);
					if (a[i] != b[i]) {
						flag = true;
					}
					a[i] = b[i];
				}
				count++;
			}
			System.out.println(count - 1);
			String s = "";
			for (int i = 0; i < n; i++) {
				System.out.print(s + b[i]);
				s = " ";
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=2e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const double PI = acos(-1);
ll n,w;
vii v;
ll dp[110][110][500];
ll go(int idx,int cnt,int sum){
    if(cnt*v[0].f+sum>w)
        return -1e18;
    if(idx==n)
        return 0;
    ll &ret=dp[idx][cnt][sum];
    if(~ret)
        return ret;
    return ret=max(go(idx+1,cnt+1,sum+v[idx].f-v[0].f)+v[idx].s,go(idx+1,cnt,sum));
}
void solve(){
    cin>>n>>w;
    v.resize(n);
    for(auto &i:v)
        cin>>i.f>>i.s;
    mem(dp,-1);
    cout<<go(0,0,0)<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();
}


Measured memory_bytes: 50892
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  string a,b,c;cin>>a>>b>>c;
  int i=0;
  int j=0;
  int k=0;
  char next=a[i];
  i++;
  string ans;
  while(true){
    if(next=='a'){
      if(a.size()==i){
        ans="A";
        break;
      }
      next=a[i];
      i++;
    }
    if(next=='b'){
      if(b.size()==j){
        ans="B";
        break;
      }
      next=b[j];
      j++;
    }
    if(next=='c'){
      if(c.size()==k){
        ans="C";
        break;
      }
      next=c[k];
      k++;
    }
  }
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int K = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        System.out.println(solve(K, A, B) ? "OK" : "NG" );
    }

    private static boolean solve(int K, int A, int B) {
        for (int k=A; k<=B; k++) {
            if (k%K == 0) return true;
        }

        return false;
    }
}

Measured memory_bytes: 35724
#include<bits/stdc++.h>
#define rgt register
#define int long long
#define rint rgt int
#define LL long long
#define rll rgt LL
#define inf 0x7f7f7f7f
#define N 200007
using namespace std;
template<class K>inline bool cmax(K&a,const K&b){return(a<b)?a=b,1:0;}
template<class K>inline bool cmin(K&a,const K&b){return(a>b)?a=b,1:0;}
inline int read() {
	rint s=0;
	rgt char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) s=(s<<1)+(s<<3)+c-'0',c=getchar();
	return s;
}
struct node{
	int p,h;
}b[N];
int n,pos,p[N],w,v,res,D;
LL ans,s[N];
inline bool cmp(rgt node a,rgt node b) {
	return a.p<b.p;
}
signed main() {
	rint i,c;
	n=read(),D=read()<<1,v=read();
	for(i=1;i<=n;i++) b[i].p=read(),b[i].h=read();
	sort(b+1,b+n+1,cmp),p[n+1]=inf;
	for(i=1;i<=n;i++) p[i]=b[i].p;
	for(i=1;i<=n;i++) {
		s[i]+=s[i-1],res=b[i].h-s[i];
		if(res<=0) continue;
		c=res/v+((res%v)?1:0);
		pos=lower_bound(p+1,p+n+1,p[i]+D)-p;
		if(p[pos]==p[i]+D) ++pos;
		ans+=c,w=c*v,s[i]+=w,s[pos]-=w;
	}printf("%lld",ans);
	return 0;
}

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

int main(){
  int x;
  for (int i=0; i<10000; ++i) {
    cin >> x;
    if ( x != 0 )
      cout << "Case " << i+1 << ": " << x << endl;
    else
      break;
  }
  
  return 0;
}



Measured memory_bytes: 2992
n, t = map(int, input().split())
a = list(map(int, input().split()))

vm = a[n - 1]#数列を右から見た時の最大値
dfm = 0
cnt = 0
for i in range(n - 2, -1, -1):
    if a[i] > vm:
        vm = a[i]
    else:
        df = vm - a[i]
        if dfm < df:
            dfm = df
            cnt = 1
        elif dfm == df:
            cnt += 1

print(cnt)

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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nab = Console.ReadLine().Split(' ').Select(num => long.Parse(num)).ToArray();
            var n = nab[0];
            var a = nab[1];
            var b = nab[2];

            if (a == 0)
            {
                Console.WriteLine(0);
                return;
            }
            if (b == 0)
            {
                Console.WriteLine(n);
                return;
            }
            var result = a * (n / (a + b));
            var amari = n % (a + b);
            result += amari <= a ? amari : a;
            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define int long long
int ans;
// shouldn't there be mod???
int32_t main()
{
	vector <int> v;
	int n; cin >> n;
	for (int i = 0; i < n; ++i)
	{
		ans += i;
	}
	cout << ans;
	return 0;
	/*
	for (int i = 1; i <= n; ++i) 
	{
		v.push_back(i);
	}
	do
	{
		int tmp = 0;
		for (int i = 1; i <= n; ++i)
		{
			 tmp += v[i-1] % i;
		}
		if (tmp > ans)
		{
			av.clear();
			for (auto it : v) av.push_back(it);
			ans = tmp;
		}
	} while(next_permutation(v.begin(), v.end()));
	cout << ans << '\n';
	for (auto it : av) cout << it << ' ';
	*/
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		int k = sc.nextInt();
		int a = sc.nextInt();
      	int b = sc.nextInt();
		int i = 0;
        boolean iketaka = false;
      	for(i = a ; i <= b ; i++){
        	if(i%k == 0){
            	System.out.println("OK");
              	iketaka = true;
              	break;
            }
        	i += 1;
        }
		if(!iketaka){
          System.out.println("NG");
        }
		
	}
}

Measured memory_bytes: 35960
a, b, c, x, y = map(int,input().split())
if x >= y:
  ans = min(a*x + b*y, a*(x-y) + 2*c*y, 2*c*x)
else:
  ans = min(a*x + b*y, b*(y-x) + 2*c*x, 2*c*y)
print(ans)

Measured memory_bytes: 9092
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<set>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,fa[100005],num[100005],x,y,ans;
set<int> s[100005];
int fnd(int x)
{
	if (fa[x]==x) return x;
	return fa[x]=fnd(fa[x]);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++) scanf("%d",num+i);
	for (i=1;i<=n;i++) fa[i]=i;
	for (i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		if (fnd(x)!=fnd(y)) fa[fnd(x)]=fnd(y);
	}
	for (i=1;i<=n;i++) s[fnd(i)].insert(num[i]); 
	for (i=1;i<=n;i++) if (s[fnd(i)].count(i)) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10368
#include <iostream>
using namespace std;
int main(){
  int n,k;cin>>n>>k;
  string s;cin>>s;
  int chan = 0;
  for(int i = 1; s.size() > i; i++){
    if(s[i-1]!=s[i])chan++;
  }
  cout << min(n-chan+2*k,n)-1 << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>

using namespace std;

int main(void){
	char first;
	char second;
	scanf("%c %c",&first,&second);
	
	if(first == 'H' && second == 'H'){
		printf("H\n");
	}else if(first == 'H' && second == 'D'){
		printf("D\n");
	}else if(first == 'D' && second == 'H'){
		printf("D\n");
	}else{
		printf("H\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e9 + 7;
int si[8] = {-1,0,1,-1,1,-1,0,1};
int sj[8] = {-1,-1,-1,0,0,1,1,1};

int main() {
  int n;
  cin >> n;
  int f[n][10];
  rep(i,n) rep(j,10) cin >> f[i][j];

  vector<vector<ll>> p(n, vector<ll>(10));
  rep(i,n) rep(j,11) cin >> p[i][j];

  ll ans = -1 * M;
  rep(b, (1 << 10) - 1){
    ll x = 0;
    rep(i, n) {
      int c = 0;
      rep(k, 10) if (((b+1) >> k) & 1 && f[i][k]) c++;
      x += p[i][c];
    }
    ans = max(ans,x);
  }

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


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

int main()
{
  int a, b;
  cin >> a >> b;
  
  for (int i = 1; i <= 1000; ++i)
  {
    if (floor(i * 0.08) == a and floor(i * 0.1) == b)
    {
      cout << i << endl;
      return 0;
    }
  }
  
  cout << -1 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}
 
#define maxn 200005
int sub[maxn] = {0}, n;

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

    for (int i = 1; i < n; i++){
        int a;
        cin>>a;
        sub[a]++;
    }
    for (int i = 1; i <= n; i++){
        cout<<sub[i]<<"\n";
    }

    return 0;
}
 

Measured memory_bytes: 3932