akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;

int main() {
	int n,count=0,max=0,maxnum,ii;
	cin >> n;
	for (int i = 0; i < n+1; i++) {
		ii = i;
		if (ii % 2==0&& ii!=0) {
			for (;;) {
				if (ii % 2 == 0) {
					count++;
					ii /= 2;
				}
				else break;
			}
		}
		if (count >= max) {
			max = count;
			maxnum = i;
		}
		count = 0;
	}

	cout << maxnum << endl;
	return 0;
}

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

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

	long long x; cin >> x;
	for (long long a = -2000; a <= 2000; a++) {
		for (long long b = -2000; b <= 2000; b++) {
			long long f1 = a*a*a*a*a;
			long long f2 = b*b*b*b*b;

			if ((f1 - f2) == x) {
				cout << a << ' ' << b; exit(0);
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3652
func main(input1: String = readLine()!, input2: String = readLine()!) {
    let stones = Array(input2)
    let numberOfR = stones.filter { $0 == "R" }.count
    if numberOfR == 0 {
        return print(0)
    }
    let numberOfMovingW = stones[..<numberOfR].filter { $0 == "W" }.count
    print(numberOfMovingW)
}

main()

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

queue<int> q,tmp;
int N,M;
const int maxn = 1000+2;
bool mp[maxn][maxn];
#define fre(i,a,b)  for(int (i)=(a);(i)<=(b);(i)++)
int dx[]{0,0,-1,1};
int dy[]{-1,1,0,0};
int main()
{
    ios::sync_with_stdio(false);
    cin>>N>>M;
    string str;
    for(int i=0;i<N;++i)
    {
        cin>>str;
        for(int j=0;j<M;++j)
            if(str[j]=='#')
                mp[i][j]=1;
    }
    fre(i,0,N-1)
        fre(j,0,M-1)
            if(mp[i][j])
                q.push(i*M+j);
    int ans=-1;
    while(!q.empty())
    {
        ans++;
        while(!tmp.empty()) tmp.pop();
        while(!q.empty())
        {
            int d=q.front();
            q.pop();
            int x=d/M,y=d%M;
            fre(i,0,3)
            {
                int xx=x+dx[i],yy=y+dy[i];
                if(xx<0||yy<0||xx>=N||yy>=M)    continue;
                if(!mp[xx][yy])
                {
                    tmp.push(xx*M+yy);
                    mp[xx][yy]=1;
                }
            }
        }
        swap(tmp,q);
    }
    cout<<ans<<endl;
    return 0;
}

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

int T[17][17];
bool Vert[17][17];
bool Horiz[17][17];

void initialize(void);

void input_matatabi(void);

void calc_t(void);

int main(){
	int n, gx, gy, num_matatabi;
	cin >> n;
	for (int i = 0; i < n; i++) {
		initialize();
		cin >> gx >> gy;
		cin >> num_matatabi;
		for (int i = 0; i < num_matatabi; i++)
			input_matatabi();
		calc_t();
		if (T[gx + 1][gy + 1] == 0)
			cout << "Miserable Hokusai!" << endl;
		else 
			cout << T[gx + 1][gy + 1] << endl;
	}
}

void initialize(void) {
	for (int i = 0; i < 17; i++)
		for (int j = 0; j < 17; j++) {
			T[i][j] = 0;
			Vert[i][j] = true;
			Horiz[i][j] = true;
		}
	T[1][1] = 1;
}

void input_matatabi(void) {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	if (x1 == x2)
		Vert[x1 + 1][min(y1, y2) + 1] = false;
	else
		Horiz[min(x1, x2) + 1][y1 + 1] = false;
}

void calc_t(void) {
	for (int i = 1; i < 17; i++)
		for (int j = 1; j < 17; j++) {
			if (Vert[i][j - 1])
				T[i][j] += T[i][j - 1];
			if (Horiz[i - 1][j])
				T[i][j] += T[i - 1][j];
		}
}

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

int main() {
  string S,T,U;
  int A,B;
  cin >>S>>T>>A>>B>>U;

  if (U == S) {
    cout << A-1<<" "<<B << endl;
  }
  else if(U == T){
  cout << A<<" "<<B-1 << endl;
  }
}

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m, c; cin >> n >> m >> c;

  int b[m]; rep(i, m) cin >> b[i];

  int ans = 0;
  rep(i, n) {
    int sum = 0;
    rep(j, m) {
      int x; cin >> x;
      sum += b[j] * x;
    }
    if(sum > -c) ++ans;
  } cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define int long long
#define endl "\n"
using namespace std;
const int N = 2e5 + 10, inf = 1e18 + 10, mod = 1e9 + 7;
int t[4 * N], c[4 * N], x[N], d[N], L[N], R[N], ans;
vector <int> a[N];
void push(int v, int tl, int tr)
{
    if(c[v])
    {
        t[v] += c[v];
        if (tl != tr){
            c[v + v] += c[v];
            c[v + v + 1] += c[v];
        }
        c[v] = 0;
    }
}
ll ma(int v, int tl, int tr, int l, int r)
{
    push(v, tl, tr);
    if(l <= tl && tr <= r)return t[v];
    else if(tr < l || r < tl)return -inf;
    else
    {
        int mid = (tl + tr) / 2;
        return max(ma(v + v, tl, mid, l, r), ma(v + v + 1, mid + 1, tr, l, r));
    }
}
void up(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if(l <= tl && tr <= r)
    {
        c[v] += val;
        push(v, tl, tr);
    }
    else if(tr < l || r < tl) return;
    else
    {
        int mid = (tl + tr) / 2;
        up(v + v, tl, mid, l, r, val);
        up(v + v + 1, mid + 1, tr, l, r, val);
        t[v] = max(t[v + v], t[v + v + 1]);
    }
}
main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("prices.in", "r", stdin);
    //freopen("prices.out", "w", stdout);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        cin >> L[i] >> R[i] >> x[i];
        a[L[i]].pb(i);
        a[R[i]].pb(-i);
    }
    for(int i = 1; i <= n; i++)
    {
        for(auto j : a[i])
        {
            if(j > 0)up(1, 0, n, 0, i - 1, x[j]);
        }
        d[i] = ma(1, 0, n, 0, i - 1);
        up(1, 0, n, i, i, d[i]);
        for(auto j : a[i])
        {
            if(j < 0)
            {
                up(1, 0, n, 0, L[-j] - 1, -x[-j]);
            }
        }
        ans = max(ans, d[i]);
    }
    cout << ans;
}


Measured memory_bytes: 29824
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(a,n) rep(i,0,n){ cout<<(i ? " ":"")<<a[i]; }cout<<endl;
const long mod=1e9+7;
int main(){
	long H,W,N;cin>>H>>W>>N;
	int a,b,c,d;long count[10]={};
	map<int,map<int,int>> backet;
	rep(i,0,N){
		cin>>a>>b;a--;b--;
		rep(j,a-1,a+2)rep(k,b-1,b+2){
			if(j<1||j>H-2||k<1||k>W-2) continue;
			backet[j][k]++;
			count[backet[j][k]]++;
		}
	}
	count[0]=(H-2)*(W-2)-count[1];
	rep(i,1,9) count[i]-=count[i+1];
	rep(i,0,10) cout<<count[i]<<endl;
}

Measured memory_bytes: 70528
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<string.h>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<assert.h>
using namespace std;
typedef long long ll;

const int max_n = 1e5 + 1;
const int INF = 2*1e9;
int N;
int h[max_n];
int d[max_n];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> h[i];

	for (int i = 1; i < N; i++)
	{
		d[i] = d[i - 1] + abs(h[i] - h[i - 1]);
		if (i - 2 >= 0)
			d[i] = min(d[i], d[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << d[N - 1];
}	

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int cnt[100010];

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n){
    cin >> a[i];
    cnt[a[i]]++;
  }
  bool ok=true;
  if(cnt[0]>=2)ok=false;
  rep(i,n){
    if((n-a[i])%2==0)ok=false;
    if(cnt[a[i]]>=3)ok=false;
    if(!ok)break;
  }
  if(!ok){
    cout << 0 << endl;
    return 0;
  }
  ll ans=1;
  rep(i,n/2){
    ans*=2;
    ans%=mod;
  }
  cout << ans << endl;
return 0;}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll A[303][303];

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

    ll H, W, D;
    cin >> H >> W >> D;

    map<ll, pll> mp; 

    REP(i, H){
    	REP(j, W){
    		ll tmp;
    		cin >> tmp;
    		tmp--;
    		mp[tmp] = {i, j};
    	}
    }

    vector<ll> z = {0ll};
    vector<vector<ll>> cum(D, z);
    REP(i, H*W){
    	if(i+D<H*W){
    		ll m = i%D;
    		cum[m].push_back(abs(mp[i+D].first - mp[i].first) + abs(mp[i+D].second - mp[i].second) + cum[m].back());
    	}
    }

    /*
    cout << endl;
    REP(i, D){
    	REP(j, cum[i].size()){
    		cout << cum[i][j] << " "; 
    	}
    	cout << endl;
    }
    */

    ll Q;
    cin >> Q;
    while(Q--){
    	ll L, R;
    	cin >> L >> R;
    	L--, R--;
    	ll m = L%D;
    	//dump(m)
    	//dump(R/D)
    	//dump(L/D)
    	cout << cum[m][R/D] - cum[m][L/D] << endl;
    }
    return 0;
}

Measured memory_bytes: 11008
import sys
input = sys.stdin.readline
from collections import defaultdict, deque

(n, m), g = map(int, input().split()), defaultdict(list)
for i in range(m): a, b = map(int, input().split()); g[a].append(b); g[b].append(a)
s, q = [0, 0] + [-1 for i in range(1, n)], deque([1])
for i in range(2, n + 1):
    x = q.popleft()
    for a in g[x]:
        if s[a] == -1: q.append(a); s[a] = x
if not all([a != -1 for a in s]): print('No')
else:
    print('Yes')
    for i in s[2:]: print(i)

Measured memory_bytes: 107896
#include <stdio.h>

int main(void)
{
	int a,b,c,d=0,i;
	scanf("%d %d",&a,&b);
	c=b-a;
	for(i=0;i<10000;i++){
		d=d+i;
		if(i==c){
			printf("%d",d-b);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

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

		LinkedList<String> list = new LinkedList<String>();

		while (sc.hasNext()) {
			list.add(sc.next());
		}

		sc.close();

		int ans = 0;

		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).equals("0")) {
				ans = i + 1;
			}
		}

		System.out.println(ans);

	}

}

Measured memory_bytes: 26972
#include <iostream>
#include <string>
int main(int argc, char *argv[])
{
  std::string s, t;
  std::cin >> s >> t;
  int c = 0;
  for (int i = 0; i < 3; i++)
  {
    if (s[i] == t[i])
    {
      c++;
    }
  }

  std::cout
      << c << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

/* 基本要素 */
typedef complex<double> Point;
typedef pair<Point, Point> Line;
typedef vector<Point> VP;
const double PI = acos(-1);
const double EPS = 1e-9; // 許容誤差^2
#define X real()
#define Y imag()
#define LE(n,m) ((n) - (m) < EPS)
#define GE(n,m) (EPS > (m) - (n))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// 点集合を含む最小の円の中心
Point minEnclosingCircle(const VP& ps) {
  Point c;
  double move = 0.5;
  rep(i,30) {  // 2^(-39-1) \approx 0.9e-12
    rep(t,30) {
      double max = 0;
      int k = 0;
      rep (j, ps.size()) if (max < norm(ps[j]-c)) {
        max = norm(ps[j]-c);
        k = j;
      }
      c += (ps[k]-c) * move;
    }
    move /= 2;
  }
  return c;
}

Point READ(){
    int x,y;
    cin >>x >>y;
    return Point(x,y);
}

const int N = 14;
const int INF = 19191919;
int dp[1<<N];

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

    VP p(n);
    rep(i,n) p[i] = READ();

    vector<double> r(1<<n);
    for(int mask=1; mask<(1<<n); ++mask){
        VP pts;
        rep(i,n)if(mask>>i&1) pts.pb(p[i]);

        Point c = minEnclosingCircle(pts);
        for(Point pp:pts) r[mask] = max(r[mask], abs(pp-c));
    }

    auto check = [&](double lim){
        rep(i,1<<n) dp[i] = INF;
        dp[(1<<n)-1] = 0;

        for(int mask = (1<<n)-1; mask>0; --mask){
            int sub = mask;
            do{
                sub = sub-1;
                sub &= mask;
                int tgt = mask^sub;
                if(r[tgt] <= lim) dp[sub] = min(dp[sub], dp[mask]+1);
            }while(sub>0);
        }

        return dp[0]<=m;
    };

    double ng=0, ok = 500000;
    rep(loop,100){
        double mid = (ng+ok)/2;
        if(check(mid)) ok = mid;
        else ng = mid;
    }
    printf("%.10f\n", ok);
    return 0;
}



Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> l(m),r(m);
  int lm=1,rm=n;
  for(int i=0;i<m;i++){
    cin >> l[i] >> r[i];
    lm=max(lm,l[i]);
    rm=min(rm,r[i]);
  }
  cout << max(rm-lm+1,0) << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define fail {puts("No");return 0;}
using namespace std;
typedef long long ll;
int n,p[300005],tree[300005];
vector<int>v[3];
void add(int x){for(int i=x;i;i-=(i&(-i)))tree[i]++;}
int ask(int x){int res=0;for(int i=x;i<=n;i+=(i&(-i)))res+=tree[i];return res;}
ll get(vector<int>c)
{
    memset(tree,0,sizeof(tree));
    ll res=0;
    for(int i=0;i<c.size();i++)res+=ask(c[i]),add(c[i]);
    return res;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&p[i]);
        if((i&1)!=(p[i]&1))fail
        v[i&1].pb(p[i]);
        v[2].pb(p[i]);
    }
    if((get(v[0])+get(v[1]))*3==get(v[2]))puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 10720
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;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 FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int n;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
ll Max(ll a, ll b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

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

int main() {
	ll a[3000];
	scanf("%d", &n);
	REP(i, n) {
		scanf("%lld", &a[i]);
	}
	/*
	ll hcm=a[0];
	REPS(i, n - 2) {
		PRINTL(hcm);
		hcm = hcm / gcd(hcm, a[i])*a[i];
	}
	ll mod = hcm - 1;
	ll ans = 0;
	REP(i, n) {
		ans += mod%a[i];
	}
	*/
	ll ans = 0;
	REP(i, n) {
		ans += a[i] - 1;
	}
	PRINTL(ans);
}

Measured memory_bytes: 128
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var aa = ToIntArray(input.ReadLine(), n);

        var c = 0;
        var num = 1;

        for(int i=0; i<n; i++) {
            var a = aa[i];
            if(a == num) {
                num++;
            } else {
                c++;
            }
        }
        if (c >= n) return -1;
        return c;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 29532
N, W = map(int, input().split())
goods = []
for i in range(N):
    goods.append(list(map(int, input().split())))
from collections import defaultdict
dp = defaultdict(lambda: defaultdict(int))
for i, g in enumerate(goods):
    for w in range(1, W+1):
        if w>=g[1]:
            dp[(i+1)%2][w]=max(dp[i%2][w-g[1]]+g[0],dp[i%2][w])
        else:
            dp[(i+1)%2][w]=dp[i%2][w]
print(dp[(len(goods))%2][W])


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int c[16], x[20010], dp[20010][300];
signed main(void)
{
  while(true) {
    int n, m;
    cin >> n >> m;
    if(!n && !m) break;
    REP(i, m) cin >> c[i];
    REP(i, n) cin >> x[i];

    REP(i, n+1) REP(j, 256) dp[i][j] = INF;
    dp[0][128] = 0;
    REP(i, n) REP(j, 256) {
      if(dp[i][j] != INF) {
        REP(k, m) {
          int tmp = j+c[k];
          tmp = max(tmp, (ll)0);
          tmp = min(tmp, (ll)255);
          dp[i+1][tmp] = min(dp[i+1][tmp], dp[i][j] + (x[i]-tmp)*(x[i]-tmp));
        }
      }
    }
    /*
    REP(j, n+1) {
      FOR(i, 125, 140) {
        if(dp[j][i] == INF) cout << -1 << " ";
        else cout << dp[j][i] << " ";
      }
      cout << endl;
    }*/

    int ret = INF;
    REP(i, 256) ret = min(ret, dp[n][i]);
    cout << ret << endl;
  }

  return 0;
}

Measured memory_bytes: 50124
n = gets.chomp.to_i

arr= []
n.times do |i|
  s, p = gets.chomp.split(' ')
  p = p.to_i
  arr << [i+1, s, p]
end

arr.map

arr.sort!{|x, y| y[2] <=> x[2]}
arr.sort!{|x, y| x[1] <=> y[1]}

arr.each do |elm|
  puts elm[0]
end

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


public class Main {
    public static void main(String[] args) {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        try {
            String string = in.readLine();
            int amount = 0;
            for (int i = 0; i < string.length(); i++) {
                if (string.charAt(i) == '2') {
                    amount++;
                }
            }
            System.out.println(amount);
        } catch (IOException ex) {

        }
    }
}

Measured memory_bytes: 21972
import static java.lang.System.*;
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int x = sc.nextInt();
		TreeSet<Integer> set = new TreeSet<>();
		set.add(1);
		for (int i=2; i<=33; i++) {
			for (int j=2; j<=100; j++) {
				if (Math.pow(i,j) > x) break;
				set.add((int)Math.pow(i,j));
			}
		}
		
		int ans = 1;
		for (Integer n: set) {
			if (n > x) break;
			ans = n;
		}
		out.println(ans);
	}
}

Measured memory_bytes: 23764
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
#define watch(x) cout << (#x)<<" = "<<x<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
int mod = 1e9 + 7;
ll fpow(ll x, ll p) {
	if (!p)
		return 1;
	ll sq = fpow(x, p / 2);
	sq *= sq;
	sq %= mod;
	if (p & 1)
		sq *= x;
	return sq % mod;
}
const int N = 5e5 + 9;
ll fact[N];
void preProc() {
	fact[0] = fact[1] = 1;
	for (int i = 2; i < N; i++)
		fact[i] = (fact[i - 1] * i) % mod;
}
ll nCrMod(ll n, ll r) {
	if (!fact[0]) preProc();
	// you must call preProc before using nCr
	// you must modify mod first
	// you must modify N
	if (n < r) return 0;
	return (fact[n] * fpow((fact[n - r] * fact[r]) % mod, mod - 2LL)) % mod;
}
ll nPrMod(ll n, ll r) {
	if (!fact[0]) preProc();
	if (n < r) return 0;
	return (fact[n] * fpow(fact[n - r], mod - 2LL)) % mod;
}
ll n, m;
ll gt(ll x) {
	ll ret = nCrMod(n, x)  * nPrMod(m - x, n - x);
	return ret % mod;
}
int main() {
	file();
	fast();
	cin >> n >> m;
	ll add = 0;
	for (int i = 1; i <= n; i++) {
		if (i% 2 == 0) add -= gt(i);
		else add += gt(i);
		add += mod;
		add %= mod;
	}
	ll ans = nPrMod(m, n) * nPrMod(m, n);
	ans %= mod;
	ans = (ans - (add * nPrMod(m, n)) % mod + mod) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7560
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      (int)1e9+7
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;

int main(){
	int n;
	cin>>n;
	
	vi cnt(3,0);
	REP(i,n){
		int a;
		cin>>a;
		if(a%4==0) cnt[2]++;
		else if(a%2==0) cnt[1]++;
		else cnt[0]++;
	}
	
	bool jud=false;
	if(cnt[1]){
		if(cnt[2]>=cnt[0]) jud=true;
	}else{
		if(cnt[2]>=cnt[0]-1) jud=true;
	}
	
	cout<<(jud?"Yes":"No")<<endl;
	return 0;
}//解説参考.

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

int main() {
	// your code goes here
	long long int a,b,c,i,j,s=0;
	cin >> a;
	cin >> b >> c;
	for(i=b;i<=c;i++)
	{
		if(i%a==0)
		{
			s=1;
			break;
		}
	}
	if(s==1)
	{
		cout << "OK" << endl;
	}
	else{
		cout << "NG" << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////




int main() {

	ll A, B, Q;
	cin >> A >> B >> Q;
	
	
	vector<ll> s;
	s.push_back(-INF);
	repn(i, A) {
		ll S;
		cin >> S;
		s.push_back(S);
	}
	s.push_back(INF);
	
	vector<ll> t;
	t.push_back(-INF);
	repn(i, B) {
		ll T;
		cin >> T;
		t.push_back(T);
	}
	t.push_back(INF);

	repn(i, Q) {
		ll x;
		cin >> x;

		auto a=lower_bound(s.begin(),s.end(),x);

		ll rs = *a - x;
		ll ls = x-*(--a);
		

		
		auto b = lower_bound(t.begin(), t.end(), x);

		ll rt = *b - x;
		ll lt = x-*(--b);
		
		ll ans = max(ls, lt);
		ans = min(ans, max(rs, rt));
		ans = min(ans, rs * 2 + lt);
		ans = min(ans, ls * 2 + rt);
		ans = min(ans, rt * 2 + ls);
		ans = min(ans, lt * 2 + rs);

		cout << ans << endl;
	}


	system("PAUSE");
}

Measured memory_bytes: 3188
#include <stdio.h>

int N, A[112345];
long long int res, ans;

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

	for (int i = 0; i <= N; ++i)
	{
		if (A[i] == 0 || i == N)
		{
			ans += res / 2;
			res = 0;
		}
		else
		{
			res += A[i];
		}
	}

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define allof(a) (a).begin(),(a).end()

typedef vector<int> vi;

int main()
{
	for(int a,b,c;cin>>a>>b>>c;){
		vi cards;
		repi(i,1,10+1)
			if(i!=a && i!=b && i!=c)
				cards.push_back(i);
		int i=distance(cards.begin(),upper_bound(allof(cards),20-a-b));
		if(i>=4)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	char a,b;
	cin>>a>>b;
	if(a>b)cout<<">"<<endl;
	else if(a<b)cout<<"<"<<endl;
	else cout<<"="<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a1,a2,b1,b2;
	cin>>a1>>a2>>b1>>b2;
	do{
	   b1=b1-a2;
	   if(b1<=0){
	      cout<<"Yes"<<endl;
	      return 0;
	   }
	   a1=a1-b2;
	   if(a1<=0){
	   	  cout<<"No"<<endl;
	   	  return 0;
	   }
	}while(1==1);
	return 0;
}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {
        int X = int.Parse(Console.ReadLine());
        int A = int.Parse(Console.ReadLine());
        int B = int.Parse(Console.ReadLine());
        X -= A;
        while (X >= B)
        {
            X -= B;
        }
        Console.WriteLine(X);
    }
}

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

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

    int H, W;
    string s = "";
    while(1){
        cin >> H >> W;
        if(H == 0 and W == 0) break;
        else{
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    if(i == 0 or i == H - 1){
                        s += "#";
                    }else{
                        if(j == 0 or j == W - 1){
                            s += "#";
                        }else{
                            s += ".";
                        }
                    }
                }
                cout << s << endl;
                s = "";
            }
            cout << endl;
        }
    }
    return 0;
}

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

int main() {
  
  string C, D;
  
  cin >> C;
  cin >> D;
  
  if(C.at(0)==D.at(2) && C.at(1)==D.at(1) && C.at(2)==D.at(0)) {
    
    cout << "YES" << endl;
    
  } else {
    
    cout << "NO" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int N, K; cin >> N >> K;
    int cnt = 0;
    rep(i, 0, N){
        int h; cin >> h;
        if(h >= K) cnt++;
    }
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	int n; scanf("%d", &n);
	
	std::vector<int> dp(100, 1 << 30); dp[0] = 0;
	for(int v = 1; v < 6; v++) {
		for(int i = 0; i < 100; i++) {
			int to = i + v;
			if(to >= 100) continue;

			dp[to] = std::min(dp[to], dp[i] + 1);
		}
	}
	
	int r = n % 100, d = n / 100;
	printf("%d\n", (d - dp[r] >= 0));
	return 0;
}


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

namespace ConsoleApplication44
{
    class Program
    {
        static void Main()
        {
            while (true)
            {
                string t = Console.ReadLine();
                if (t == null) break;
                int[] a = t.Split(',').Select(int.Parse).ToArray();
                Array.Sort(a);
                if (a[0] == a[3] || a[1] == a[4]) { Console.WriteLine("four card"); goto s; }
                if (a[0] == a[2] && a[3] == a[4]) { Console.WriteLine("full house"); goto s; }
                if (a[0] == a[1] && a[2] == a[4]) { Console.WriteLine("full house"); goto s; }
                if (a[0] + 1 == a[1] && a[1] + 1 == a[2] && a[2] + 1 == a[3]&&a[3]+1==a[4])
                {
                     Console.WriteLine("straight"); goto s; 
                }
                if (a[0] == 1 && a[1] == 10 && a[2] == 11 && a[3] == 12 && a[4] == 13)
                {
                    Console.WriteLine("straight"); goto s;
                }
                if (a[0] == a[2] || a[1] == a[3] || a[2] == a[4]) { Console.WriteLine("three card"); goto s; }
                if (a[0] == a[1] && a[2] == a[3]) { Console.WriteLine("two pair"); goto s; }
                if (a[0] == a[1] && a[3] == a[4]) { Console.WriteLine("two pair"); goto s; }
                if (a[1] == a[2] && a[3] == a[4]) { Console.WriteLine("two pair"); goto s; }
                if (a[0] == a[1] || a[1] == a[2] || a[2] == a[3] || a[3] == a[4]) { Console.WriteLine("one pair"); goto s; }
                Console.WriteLine("null");
            s:;
            }
        }
    }
}

Measured memory_bytes: 9432
import itertools
import math
l = [int(input()) for i in range(5)]

ans = []

for p in itertools.permutations(l):
  t = p[0]
  for i in range(1, 5):
    t = math.ceil(t/10)*10
    t += p[i]
  ans.append(t)
print(int(min(ans)))

Measured memory_bytes: 3188
#!/usr/bin/python

# AtCoder Beginner Contest 075
# C - Bridge

from sys import stdin

def nReachable(node, edges):
  visited = []
  gray    = [node]
  while len(gray) > 0:
    n    = gray[0]
    gray = gray[1:]
    if n not in visited:
      visited.append(n)
      gray.extend([e[1] for e in edges if e[0] == n])
      gray.extend([e[0] for e in edges if e[1] == n])
  return len(visited)

def solve(N, E):
  cnt = 0
  for i in range(len(E)):
    EE = E[:i] + E[i + 1:]  # drop E[i]
    if nReachable(1, EE) < N:
      cnt += 1
  return cnt

def splitIntoInt(line):
  words = line.strip().split()
  return [int(w) for w in words]

N, M = splitIntoInt(stdin.readline())
E = []
for i in range(M):
  a, b = splitIntoInt(stdin.readline())
  E.append((a, b))
print(solve(N, E))

Measured memory_bytes: 2696
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	int N, L;
	cin >> N >> L;
	string s[100];
	for (int i = 0;i < N;++i) {
		cin >> s[i];
	}
	sort(s,s+N);
	string ans;
	int i;
	for (i = 0;i < N;++i)ans+=s[i];
	cout << ans << endl;
	return 0;
}


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

int main(){
    vector<int> A(3);
    cin >> A[0] >> A[1] >> A[2];
    sort(A.begin(), A.end());
    cout << A[0] << ' ' << A[1] << ' ' << A[2] << endl;
    return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
int table[41][401][401];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int ans = 4001;
    int n,ma,mb;
    cin >> n >> ma >> mb;
    vector<int> a(n+1);
    vector<int> b(n+1);
    vector<int> c(n+1);
    int am[n+1];
    int bm[n+1];
    am[0]=0;
    bm[0]=0;
    for(int i=1;i<=n;i++){
        cin >> a[i] >> b[i] >> c[i];
        am[i]=am[i-1]+a[i]; 
        bm[i]=bm[i-1]+b[i];
    } 
      
    for(int i = 0;i<=n;i++){
        for(int j=0;j<=400;j++){
            for(int k=0;k<=400;k++){
                table[i][j][k]=4001;
            }
        }
    }
    table[0][0][0] = 0;
    
    for(int i=1;i<=n;i++){
        for(int j=0;j<=am[i-1];j++){
            for(int k=0;k<=bm[i-1];k++){
                if(table[i-1][j][k]==4001) continue;
                table[i][j][k] = min(table[i-1][j][k],table[i][j][k]);
                table[i][j+a[i]][k+b[i]] = min(table[i][j+a[i]][k+b[i]], table[i-1][j][k]+c[i]);
            }
        }
    }
    
    for(int i = 1;i<=am[n];i++){
        for(int j=1;j<=bm[n];j++){
            if(i*mb==j*ma) ans = min(ans,table[n][i][j]);
        }
    }
    
    if(ans==4001) ans = -1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 25984
#include <algorithm>
#include <bits/stdc++.h>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define PB push_back
#define MP make_pair
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
using ll = long long;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


void Main() {
  int N;
  IN(N);
  int mx=0;
  int sum=0;
  vector<int> X(N);
  REP(i,N){
    IN(X[i]);
    if(X[i] > mx) mx=X[i];
    sum += X[i];
  }
  if(sum-mx > mx) OUT("Yes");
  else OUT("No");
}

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

  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		List<Integer> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {

			int a = sc.nextInt();

			list.add(a);

		}

		double ave = list.stream().mapToDouble(Double::valueOf).average().getAsDouble();

		List<Double> ans = new ArrayList<>();
		for (int num : list) {

			ans.add(Math.abs(ave - num));
		}

		double min = ans.stream().mapToDouble(Double::valueOf).min().getAsDouble();


		int place = ans.indexOf(min);
		// System.out.println(ave);
		System.out.println(place);


		sc.close();

	}
}

Measured memory_bytes: 29012
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int H,N,max1=0,max2=0;
	cin >> H >> N;
	// vector<int> a(N);
	// for (int i = 0; i < N; ++i) {
	// 	cin >> a.at(i);
	// }
	// sort(a.begin(), a.end());
	// if(a.at(N-1)+a.at(N-2)>=H){
	// 	cout << "Yes" << endl;
	// }else{
	// 	cout << "No" << endl;
	// }
	if(H%N!=0){
		cout << H/N+1 << endl;
	}else{
		cout << H/N << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.lang.*;
import java.util.*;

public class Main
{
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] prices = new int[n];
        for (int i = 0; i < n; i++) {
            prices[i] = sc.nextInt();
        }
        Arrays.sort(prices);
        int total = 0;
        for (int i = 0; i < k; i++) {
            total += prices[i];
        }
        System.out.println(total);
    }
}


Measured memory_bytes: 38800
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, M;
  cin >> N >> M;

  vector<pll> X(M);
  vl A(N, 1);
  vector<bool> B(N, false);
  B[0] = true;

  REP(i, M) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    X[i] = make_pair(a, b);
  }

  REP(i, M) {
    A[X[i].first]--;
    if (B[X[i].first]) {
      B[X[i].second] = true;
    }
    A[X[i].second]++;
    if (A[X[i].first] == 0) {
      B[X[i].first] = false;
    }
  }
  ll ans = 0;
  REP(i, N) {
    if (B[i])
      ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2688
from heapq import heappop, heappush

def dijkstra(s):
    used = [1] * n
    dp = [INF] * n
    dp[s] = 0
    hq = []
    used[s] = 0
    for i in cost[s]:
        heappush(hq, i)

    while hq:
        minv = heappop(hq)
        if used[minv[1]] == 0:
            continue
        v = minv[1]
        dp[v] = minv[0]
        used[v] = 0
        for i in cost[v]:
            if used[i[1]]:
                heappush(hq, [i[0] + dp[v], i[1]])
    return dp

INF = 10 ** 18
n, x, y = map(int, input().split())
cost = [[] for _ in range(n)]

for i in range(n - 1):
    a = i
    b = i + 1
    cost[a].append([1, b])
    cost[b].append([1, a])
cost[x - 1].append([1, y - 1])
cost[y - 1].append([1, x - 1])
ans = [0] * n
for i in range(n - 1):
    dp1 = dijkstra(i)
    for j in dp1[i:]:
        ans[j] += 1

for i in ans[1:]:
    print(i)


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

int main(){
	int x, a, b;
	cin >> x >> a >> b;
	if(abs(x - a) > abs(x - b)) cout << "B" << endl;
	else cout << "A" << endl;
	return 0;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

#define WA printf("WA\n");
int main()
{
    ll count = 0;
    ss s;
    cin >> s;
    rep(i,SIZE(s)){
        if(i==0){
            if(s[i] != 'A'){
                //cout << 1 << endl;
                WA;
                return 0;
            }
        }
        else if(i >= 2 && i <= SIZE(s)-2){
            if(s[i] == 'C'){
                count++;
                //cout << "count" << endl;
            }
            if(count>1){
                //cout << 2 << endl;
                WA;
                return 0;
            }
        }
        else {
            if((int)s[i] < 97){
                //cout << 3 << endl;
                WA;
                return 0;
            }
        }
    }
    if(count == 0){
        //cout << 4 << endl;
        WA;
        return 0;
    }
    cout << "AC" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007
 

int main() {
	string s, t;
	cin >> s;
	if (s.length() == 2)print(s);
	else {
		t += s[2]; t += s[1]; t += s[0];
		print(t);
	}


	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//最大公約数
long long gcd(long long a, long long b) {
	if (a < b) std::swap(a, b);
	long long r = a % b;
	while (r) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

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

	ll n, m;
	cin >> n >> m;
	vll a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		a[i] /= 2;
	}

	ll lcm = 1;
	for (ll i = 0; i < n; i++) lcm *= a[i] / gcd(lcm, a[i]);
	for (ll i = 0; i < n; i++) {
		if (lcm / a[i] % 2 == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	ll ans = 0;
	if (lcm <= m) {
		ans++;
		m -= lcm;
		ans += m / (2 * lcm);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
using namespace std;
 
int main() {
  int N, K, R, S, P;
  long int score = 0;
  
  cin >> N>> K;
  cin>>R>>S>>P;
  vector<char> hand(N);
  string T;
  cin>>T;
  
  rep(i, N){
  	if(T[i] == 'r'){
      //勝てないとき
      if(i>=K && hand[i-K] == 'p'){
        if(T[i+K] == 's'){
        	hand[i] = 's';
        }
        else{
          hand[i] = 'r';
        }
      }
      else{
        hand[i] =  'p';
        score += P;
      }
    }
      
    else if(T[i] == 's'){
      if(i>=K && hand[i-K] == 'r'){
      	if(T[i+K] == 'p'){
        	hand[i] = 'p';
        }
        else{
        	hand[i] = 's';
        }
      }
      else{
        hand[i] =  'r';
        score+= R;
      }
    }
      
    else{
      if(i>=K && hand[i-K] == 's'){
      	if(T[i+K] == 'r'){
        	hand[i] = 'r';
        }
        else{
        	hand[i] = 'p';
        }
      }
      else{
        hand[i] =  's';
        score+= S;
      }
    }
    
  }
  cout<<score<<endl;
  
}

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

typedef long long LL;

const int N=200000;

char s[N+9];
int n;

int main(){
  scanf("%s",s+1);
  n=strlen(s+1);
  for (int i=1;i<=n;++i)
	putchar(s[i]=='?'?'D':s[i]);
  return 0;
}

Measured memory_bytes: 3832
import javax.sound.midi.Soundbank;
import java.util.*;
import java.lang.*;

public class Main
{
    public static void main (String[] args)
    {
        // your code goes here
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int d = s.nextInt();
        int c = 0;
        for(int i=0; i<n; i++)
        {
            int x = s.nextInt();
            int y = s.nextInt();
            double distsq = Math.pow(x,2)+Math.pow(y,2);
            if(distsq<=Math.pow(d,2))
                c++;
        }
        System.out.println(c);

    }
}


Measured memory_bytes: 60616
#include <cstdio>
#define INF 1e9
#define eps 1e-6
typedef long long ll;

int n;
char s[5010];
ll ans, sa, sb, sc;

int main(){

	scanf("%d %s", &n, s + 1);
	for(int i = 1; i <= n; i++){
		if(s[i] == 'R') sa++;
		if(s[i] == 'G') sb++;
		if(s[i] == 'B') sc++;
	}
	ans = sa * sb * sc;
	for(int i = 1; i <= n; i++)
		for(int j = 1; i - j >= 1 && i + j <= n; j++)
			if(s[i] != s[i - j] && s[i] != s[i + j] && s[i - j] != s[i + j])
				ans--;
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 1736