akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    map<ll int,ll int> m;
    map<ll int,ll int>::iterator itr;
    ll int i,n,a,c=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a;
        m[a]++;
    }
    for(itr=m.begin();itr!=m.end();itr++)
    {
        if(itr->second<itr->first)
            c+=itr->second;
        else
            c+=min(itr->second,itr->second-itr->first);
    }
    cout<<c;
}


Measured memory_bytes: 9532
# -*- coding: utf-8 -*-
"""
Dynamic Arrays and List - Deque
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_1_B&lang=jp

"""
from collections import deque

dq = deque()
for _ in range(int(input())):
    op, m, n = (input() + ' 1 1').split()[:3]
    if op == '0':
        if m == '0':
            dq.appendleft(n)
        else:
            dq.append(n)
    elif op == '1':
        print(dq[int(m)])
    else:
        if m == '0':
            dq.popleft()
        else:
            dq.pop()




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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int n,K; cin >> n >> K;
    vector<lint> p(n), c(n);
    rep(i,n){
        cin >> p[i]; p[i]--;
    }
    rep(i,n) cin >> c[i];

    vector<bool> seen(n, false);
    lint res = -INF;

    rep(i,n){
        if(seen[i]) continue;

        vector<lint> vec; vec.push_back(c[i]);
        int j = i;
        while(1){
            j = p[j];
            seen[j] = true;
            if(i == j) break;
            vec.push_back(c[j]);
        }

        int l = vec.size();
        rep(k, l-1) vec[k+1] += vec[k];
        lint cycle = vec[l-1];

        vector<lint> maxseg(l+1, -INF);
        for(int s = -1; s < l-1; s++) for(int t = s+1; t < l; t++){
            int len = t-s;
            if(s == -1){
                maxseg[len] = max(maxseg[len], vec[t]);
                maxseg[l-len] = max(maxseg[l-len], cycle-vec[t]);
            }
            else{
                maxseg[len] = max(maxseg[len], vec[t]-vec[s]);
                maxseg[l-len] = max(maxseg[l-len], cycle-(vec[t]-vec[s]));
            }
        }

        lint ans = -INF;
        if(cycle <= 0 || K <= l){
            int bnd = min(K, l);
            repn(k, bnd){
                ans = max(ans, maxseg[k]);
            }
            res = max(res, ans);
        }
        else{
            int y = K / l;
            repn(k, l){
                if(k <= K%l) ans = max(ans, maxseg[k]+y*cycle);
                else ans = max(ans, maxseg[k]+(y-1)*cycle);
            }
            res = max(res, ans);
        }
    }

    out(res);
}

Measured memory_bytes: 3784
def main():
    a, b, c = list(map(int, input().split()))
    k = int(input())
    # if b == 1 or c == 1:
    #     print('No')
    #     return
    # count = 0
    # while count < k:
    #     if b <= a:
    #         b *= 2
    #         count += 1
    #         continue
    #     elif c <= b:
    #         c *= 2
    #         count += 1
    #         continue
    #     else:
    #         break
    for i in range(k):
        if b <= a:
            b *= 2
            continue
        elif b > a and c <= b:
            c *= 2
            continue
        elif b > a and c > b:
            break
    if a < b and b < c:
        print('Yes')
    else:
        print('No')

main()

Measured memory_bytes: 9176
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;



int isPointInsidePolygon(vector<pair<double,double>> angle,pair<double,double> point){    //点が多角形の内側にあるかどうかを求める
    long angleSum=angle.size();
    int count=0;
    
    for(int i=0;i<angleSum;i++){
        double x1=angle[i].first;
        double y1=angle[i].second;
        double x2=angle[(i+1)%angleSum].first;
        double y2=angle[(i+1)%angleSum].second;
        double xp=point.first;
        double yp=point.second;
        
        double result=(x2-x1)*(yp-y1) - (xp-x1)*(y2-y1);
        
        if(result>0)count++;
        
    }
    if(count%angleSum==0)return 1;    //点は内側にある
    else return 0;
    
}



int main(){
    double a,b,c,d,e,f,g,h;
    while(cin>>a>>b>>c>>d>>e>>f>>g>>h){
        vector<pair<double,double>> angle;
        angle.pb(pair<double,double>(a,b));
        angle.pb(pair<double,double>(c,d));
        angle.pb(pair<double,double>(e,f));

        if(isPointInsidePolygon(angle,pair<double,double>(g,h))){
            cout<<"YES"<<endl;
        }
        else cout<<"NO"<<endl;
    }


    return 0;
}

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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

int solve(int N, int K, string& s)
{
    int ans = 0, L = 0;
    vector<int> hs;

    hs.push_back(0);

    // Separa em segmentos de pessoas olhando na mesma direção
    while (L < N)
    {
        auto R = L + 1;

        while (R < N and s[R] == s[L])
            ++R;

        hs.push_back(R - L);
        L = R;
    }

    // A operação ótima troca dos elementos cercados de mesmo tipo pelo outro, aumentando
    // happy em duas unidades
    while (K-- and hs.size() > 2)
    {
        auto a = hs.back(); hs.pop_back();
        auto b = hs.back(); hs.pop_back();
        auto c = hs.back(); hs.pop_back();

        hs.push_back(a + b + c);
    }

    // Cada grupo de N aumenta happy em N - 1
    for (auto x : hs)
        ans += (x ? (x - 1) : 0);

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;

    string s;
    cin >> s;

    auto ans = solve(N, K, s);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 972
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 1000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e6+10;
const double eps=1e-6;

int n,m,k;

int main(){
    #ifdef ONLINE_JUDGE
    #else
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    #endif

    cin>>n>>m>>k;
    int temp;
    int juge=0;
    if(k==0)
        juge=1;
    if(k%n==0)
        juge=1;
    if(k%m==0)
        juge=1;
    for(int i=1;i<=m;i++){
        temp=n*i+m-2*i;
        if(temp==k)
            juge=1;
    }
    for(int i=1;i<=n;i++){
        temp=m*i+n-2*i;
        if(temp==k)
            juge=1;
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            int temp=i*m+j*n-2*i*j;
            if(temp==k){
                juge=1;
                break;
            }
        }
    }        
    if(juge)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;   
}

Measured memory_bytes: 256
N, X, Y = map(int, input().split())
X = X-1
Y = Y-1

cnt = [0]*N
for i in range(N):
    for j in range(i+1, N):
        dist = min(abs(i-j),
                   abs(X-i) + abs(Y-j) + 1,
                   abs(X-j) + abs(Y-i) + 1)
        cnt[dist] += 1

print(*cnt[1:], sep='\n')


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


int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) {
    cin >> a[i];
  }

  int num=a[0],count=0;
  while(count<=n) {
    count++;
    if(num==2) {
      break;
    }
    num=a[num-1];
  }
  if(count==n+1) count=-1;
  cout << count << endl;
}

Measured memory_bytes: 640
solve :: Int -> Int -> Int -> String
solve a b c
  | cond = "YES"
  | otherwise = "NO"
    where
      cond = any (==c) $ map f [1..100]
      f i = i * a `mod` b

main = do
  [a,b,c] <- map read . words <$> getLine :: IO [Int]
  putStrLn $ solve a b c


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    int num = 1;
    rep(i, n) {
        num = a[num - 1];
        ans++;
        if(num == 2) {
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 640
def main():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    import collections
    a = collections.Counter(a).most_common()
    a = sorted(a, key=lambda x: x[0], reverse=True)
    t = -1
    for k, v in a:
        if v >= 4:
            if t != -1:
                print(t * k)
                exit()
            else:
                print(k ** 2)
                exit()
        elif v >= 2:
            if t != -1:
                print(t * k)
                exit()
            else:
                t = k
    print(0)

if __name__ == '__main__':
    main()


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

int main() {
    int n; cin >> n;
    string s; cin >> s;

    int ans = 0;
    for (int i = 1; i < n; i++) {
        int cnt = 0;
        for (int j = 0; j < 26; j++) {
            vector<bool> b(26);
            for (int k = 0; k < n; k++) {
                if (k < i) {
                    if (s.at(k) == (char)('a'+(char)j))
                        b.at(j) = true;
                }
                else {
                    if (s.at(k) == (char)('a'+(char)j) && b.at(j) == true) {
                        cnt++;
                        break;
                    }
                }
            }
        }
        ans = max(ans, cnt);
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int a,b,w;
	cin>>w>>a>>b;
	if(b>a && b>(a+w)){
	  	cout<<abs(b-(a+w));
	  }
	  else
	  if(a>b)
	  {
	  	cout<<abs(a-(b+w));
	  }
	  else
	  if(a<=b<=(a+w))
	  {
	  	cout<<"0";
	  }
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e7 + 5;


int invmod(int a, int m) { 
    int m0 = m; 
    int y = 0, x = 1; 
    if(m == 1) return 0; 
    while (a > 1){ 
        int q = a / m; 
        int t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if(x < 0){
       x += m0; 
    }
    return x; 
} 
  
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x, y;
    cin>>x>>y;
    vector<int> fact(MAXN);
    fact[0] = 1;
    for(int i= 1;i<MAXN;i++){
    	fact[i] = ((fact[i-1] % MOD) * (i % MOD)) % MOD;
    }
    int ans = 0;
    for(int i= 0;i*2<=x;i++){
    	int sum = i*2;
    	int j = x-sum;
    	if(y == (i + j + j)){
    		int den = (fact[i]*fact[j])% MOD;
    		ans += (fact[i+j]*(invmod(den, MOD) % MOD)) % MOD;
    		ans %= MOD;
    	}
    }
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 78464
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; i<n; i++)
#define REP2(i, a, b) for(int i=a; i<b; i++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

class Comb{
    // テーブルを作るのに O(NlogN)
    // 計算は O(1)
    int N;
    vector<long long> fact_num, fact_den;
    long long bipow(long long n, long long m) {
        if (m == 0) return 1;
        if (m % 2 == 0) {
            n = (n * n) % MOD;
            return bipow(n, m / 2) % MOD;
        } else
            return (n * bipow(n, m - 1)) % MOD;
    }
    void set_table(){
        fact_num.resize(N+1, 0);
        fact_den.resize(N+1, 0);
        vector<long long> fact_denpow(N+1, 0);

        fact_num[0] = 1;
        for(int i=1; i<=N; i++) fact_num[i] = (fact_num[i-1] * i) % MOD;
        for(int i=0; i<=N; i++) fact_denpow[i] = bipow(i, MOD-2);
        fact_den[0] = 1;
        for(int i=1; i<=N; i++) fact_den[i] = (fact_den[i-1] * fact_denpow[i]) % MOD;
    }
public:
    Comb(int N): N(N) { set_table(); }
    // nCk
    long long calc(long long n, long long k){
        if(k > n) return 0;
        return ((fact_num[n] * fact_den[k]) % MOD * fact_den[n-k]) % MOD;
    }
};

int main(){
    long long X, Y;
    cin >> X >> Y;
    Comb comb(X+Y+10);

    long long ans = 0;
    for(int i=0; i<=X; i++){
        long long j = (X-i)/2;
        if(i+2*j!=X || 2*i+j!=Y) continue;
        cerr << i << " " << j << endl;
        ans += comb.calc(i+j, i);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 47104
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(){
	
	int syako[10],number,i;
	for(i=0;i<=9;i++){
		syako[i]=0;
	}
	i=0;
	while(0<=scanf("%d",&number)){
		if(number>0){
			syako[i]=number;
			i++;
		}else{
			i--;
			printf("%d\n",syako[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t X;
    std::cin >> X;
    std::string ans = X >= 30 ? "Yes" : "No";
    std::cout << ans << std::endl;
}

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


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
#define NIL -1

//左子右兄弟表現の実装
struct Node { int parent, left, right; };
struct Node T[100001];

int D[100001];

//深さを求める
void Depth( int u, int p ) {
  D[u] = p;
  if ( T[u].right != NIL ) {
    Depth( T[u].right, p );
  }
  if ( T[u].left != NIL ) {
    Depth( T[u].left, p + 1 );
  }
}

//出力
void print ( int u ) {
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].parent << ", ";
  cout << "depth = " << D[u] << ", ";

  //根、内部節点、葉を判定し出力する
  if ( T[u].parent == NIL ) cout << "root, ";
  else if ( T[u].left == NIL ) cout << "leaf, ";
  else cout << "internal node, ";
  
  cout << "[";
  
  //子のリストを出力する
  for ( int i = 0, c = T[u].left; c != NIL; i++, c = T[c].right ) {
    if ( i > 0 ) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

int main() {
  int n, k, id, c, l, r;
  cin >> n;
  for ( int i = 0; i < n; i++ ) T[i].parent = T[i].left = T[i].right = NIL; //初期化
  
  //入力
  for ( int i = 0; i < n; i++ ) {
    cin >> id >> k;
    for ( int j = 0; j < k; j++ ) {
      cin >> c;
      if ( j == 0 ) T[id].left = c;
      else T[l].right = c;
      l = c;
      T[c].parent = id;
    }
  }
  
  for ( int i = 0; i < n; i++ ) {
    if ( T[i].parent == NIL ) r = i; 
  }

  Depth(r,0);

  for ( int i = 0; i < n; i++ ) print(i);
  return 0;
}

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

#ifdef LOCAL
#include "bib/debug.h"
#else
#define debug
#define cerr if (false) cerr 
#endif

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  long long ans = min(n, n % k);
  ans = min(ans, k - ans);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
import fractions
A, B, C, D = map(int, input().split())
n = B-A+1
c1 = n//C
d1 = n//D
cd = C*D//fractions.gcd(C, D)
cd1 = n//(cd)
if ((A+c1*C-1)%C + (B-(A+c1*C-1))) // C == 1:
    c1 += 1
if ((A+d1*D-1)%D + (B-(A+d1*D-1))) // D == 1:
    d1 += 1
if ((A+cd1*cd-1)%(cd) + (B-(A+cd1*cd-1))) // cd == 1:
    cd1 += 1
print(n-(c1+d1-cd1))

Measured memory_bytes: 5472
#include <cstdio>
#define maxn 1005
using namespace std;

char s[1005], t[1005];

int main(int argc, char** argv)
{
	scanf("%s%s", s, t);
	int tlen = 0, ans = maxn;
	for(; t[tlen]; tlen++);
	if(s[tlen] == '\0')
	{
		ans = 0;
		for(int i=0; i<tlen; i++)
			if(s[i] != t[i])
				ans ++;
		printf("%d\n", ans);
		return 0;
	}
	for(int i=0; s[i+tlen]; i++)
	{
		int cnt = 0;
		for(int j=0; j<tlen; j++)
			if(s[i + j] != t[j])
				cnt ++;
		if(cnt < ans) ans = cnt;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1724
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int p[n];
    for (int i=0; i<n; i++) {
        cin >> p[i];
    }
    int cnt = 0;
    for (int i=1; i<n-1; i++) {
        if ((p[i]-p[i-1])*(p[i]-p[i+1]) < 0) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,p[1000];
/*long long solve(vector<long long>E){
    long long cnt=0;
    while(true){
        sort(E.begin(),E.end());
        if(E[E.size()-1]<(long long)E.size())break;
        E[E.size()-1]-=E.size();
        for(int i=0;i<E.size()-1;i++)E[i]++;
        cnt++;
    }
    return cnt;
}*/
int main(){
    cin>>n;
    long long B=n/50;
    for(long long i=0;i<50;i++)p[i]=49+B;
    for(long long i=0;i<(n%50);i++){
        p[i]+=50;
        for(long long j=0;j<50;j++){if(i!=j)p[j]--;}
    }
    /*vector<long long>T;
    for(int i=0;i<50;i++)T.push_back(p[i]);
    long long Y=solve(T);if(Y!=n)cout<<"WA"<<endl; cout<<Y<<endl;*/
    cout<<50<<endl;
    for(long long i=0;i<50;i++){if(i)cout<<' ';cout<<p[i];}
    cout<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.10lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[6] = {-1,-1,0,0,1,1};
int dy[6] = {-1,0,-1,1,0,1};

const int N = 5e2+5;

void solve(){
    int x,y;
    cin>>x>>y;
    string s;
    cin>>s;
    int ans=x,curr=y;
    for(int i=0;i<x;++i){
        if(s[i]=='N'){
            curr+=1;
        }
        if(s[i]=='S'){
            curr-=1;
        }
    }
    int me=0;
    for(int i=x;i<sz(s);++i){
        if(me==abs(curr)){
            cout<<ans<<endl;
            return;  
        }
        if(s[i]=='E' or s[i]=='W'){
            ans+=1;
            continue;
        }
        if(s[i]=='N'){
            curr+=1;
        }
        if(s[i]=='S'){
            curr-=1;
        }
        ans+=1;
        if(me==abs(curr)){
            cout<<ans<<endl;
            return;  
        }
        me+=1;
    }
    if(me==abs(curr)){
        cout<<ans<<endl;
        return;
    }
    cout<<"IMPOSSIBLE"<<endl;
}

int main(){
    int n;
    cin>>n;
    int l,r;
    cin>>l>>r;
    for(int i=l;i<=r;++i){
        if(i%n==0){
            return cout<<"OK"<<endl,0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define PR pair
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define REP(i, x, y)   for(int i = (int)(x); i <= (int)(y); i++)
#define FOR(i, x, y)   for(int i = (int)(x); i <  (int)(y); i++)
#define PER(i ,x, y)  for(int i = (int)(x); i >= (int)(y); i--)
#define CH	         ch = getchar()
#define Exit(...)    printf(__VA_ARGS__), exit(0)
#define dln()        fprintf(stderr,"\n")
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef double	  db;
typedef long long LL;
typedef vector<int> VI;
typedef vector<VI > VII;
typedef PR<int,int> PII;
typedef vector<PII> VPI;
const	int inf=2e9;
const	LL Inf=1e10;
const	int P=1e9+7;
const	int N=100005;

inline LL IN(){
	LL x = 0;
	int ch = 0, f = 0;
	for (CH; ch != -1 && (ch < 48 || ch > 57); CH) f = (ch == '-');
	for (; ch >= 48 && ch <= 57; CH) x = (x << 1) + (x << 3) + ch - '0';
	return f ? (-x) : x;
}
template<typename T> inline int chkmin(T &a, const T &b){if(b < a) return a = b, 1; return 0;}
template<typename T> inline int chkmax(T &a, const T &b){if(b > a) return a = b, 1; return 0;}

void renew(int &x, const int &y){
	x += y;
	if(x >= P) x -= P;
	if(x <  0) x += P;
}

int Pow(int x, int y, int p){
	int a = 1;
	for (; y; y >>= 1, x = (LL)x * x %p) if(y & 1) a=(LL)a * x%p;
	return a;
}

int n, Q;
LL q[N], cf[N], ans[N], mn[N << 2];

#define ls ((x) << 1)
#define rs ((ls) | 1)
#define md ((L + R) >> 1)

void B(int x, int L, int R){
	if(L == R){
		mn[x] = q[L];
		return;
	}
	B(ls, L, md);
	B(rs, md + 1, R);
	mn[x] = min(mn[ls], mn[rs]);
}

int qx, qans; LL qv;
void work(int x, int L, int R){
	if(mn[x] > qv) return;
	if(qans) return;
	if(L == R){qans = L; return;}
	if(qx > md) work(rs, md + 1, R);
	work(ls, L, md);
}

int findpre(int r, LL w){
//	for(int x = r; x >= 1; x --) if(q[x] <= w) return x;
//	return 1;

	qx = r; qv = w; qans = 0;
	work(1, 1, Q);
	if(!qans) qans = 1;
	return qans;

}

int main(){
	scanf("%d%d", &n, &Q);
	if(!Q){
		REP(i, 1, n) puts("1");
		return 0;
	}
	Q ++; q[1] = n;
	REP(i, 2, Q) scanf("%lld", q + i);
	B(1, 1, Q);
	cf[Q] = 1;
	PER(i, Q, 2){
		int u = i;
		LL v = q[i];
		LL c = cf[i];
		while(1){
			int x = findpre(u - 1, v);
			if(x == 1){
				cf[1] += c * (v / q[x]);
				v %= q[x];
				ans[1] += c;
				ans[1 + v] -= c;
				break;
			}
			cf[x] += c * (v / q[x]);
			u = x;
			v %= q[x];
		}
	}
	ans[0] = cf[1];
	REP(i, 1, n) ans[i] += ans[i - 1];
	REP(i, 1, n) printf("%lld\n", ans[i]);
	return 0;
}

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

#define fi first
#define se second

typedef pair<int, int> pii;

const int MAXN = 85, MAXM = 1e5 + 5;

int main() {
	int n; cin >> n;
	long long sum = 0;

	for (int i = 1; i <= n; i++) {
		sum += (i%3 == 0 or i%5 == 0) ? 0 : i; 
	}
	cout << sum << endl;

}

Measured memory_bytes: 3608
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		try {
			System.setIn(new FileInputStream("src/aoj0024/input.txt"));
			System.setOut(new PrintStream(new FileOutputStream("src/xxxyyyy/result.txt")));
		} catch (FileNotFoundException e) {
		}
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextDouble()) {
			System.out.println(solve(sc.nextDouble()));
		}
	}
	
	int solve(double d) {
		int hi = 987654321;
		int lo = 0;
		while( hi - lo > 1 ) {
			int mid = (hi + lo) >> 1;
			double height = 5.0 * mid - 5.0; 
			double t = sqrt(height / 4.9);
			double v = 9.8 * t;
			if( v >= d ) hi = mid;
			else lo = mid;
		}
		return hi;
	}
	
	void debug(Object... os) {
		System.err.println(deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
const ll MOD=1e9+7;
ll dp[2001][2001]{};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin>>N>>M;
    vector<ll>S(N);
    vector<ll>T(M);
    for(ll i=0;i<N;i++){
        cin>>S[i];
    }
    for(ll i=0;i<M;i++){
        cin>>T[i];
    }
    for(ll i=1;i<=N;i++){
        for(ll j=1;j<=M;j++){
            if(S[i-1]==T[j-1]){dp[i][j]+=dp[i-1][j-1]+1;dp[i][j]%=MOD;}
            dp[i][j]+=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1];
            if(dp[i][j]<0){dp[i][j]+=MOD;}
            dp[i][j]%=MOD;
        }
    }
    cout<<dp[N][M]+1<<endl;
}

Measured memory_bytes: 31616
import java.util.*

fun main(args: Array<String>) = abc161d()

fun abc161d() {
    val k = readLine()!!.toInt()

    val queue = ArrayDeque((1..9L).toList())
    var i = 1

    while (true) {
        val curr = queue.poll()
        if (i++ == k) return println(curr)
        val max = Math.min(curr % 10 + 1, 9)
        val min = Math.max(curr % 10 - 1, 0)
        queue.addAll((min..max).map { curr * 10 + it })
    }
}


Measured memory_bytes: 46160
import sys
 
size = int(input())
a = list(map(int, input().split()))
cnt = 0
 
while True:
  for i in range(size):
    if(a[i]%2 == 1):
      print(cnt)
      sys.exit()
    
  a = list(map(lambda x:x/2, a))
  cnt+=1

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

#define MOD 1000000007

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<long long> s(N+1, -1);

    for (int i=0; i<M; i++) {
        int a;
        cin >> a;
        s[a] = 0;
    }

    s[0] = 1;
    for (int i=1; i<=N; i++) {
        if (s[i] == 0) {
            ;
        } else {
            if (i==1) {
                s[i] = s[i-1];
            } else {
                s[i] = s[i-1] + s[i-2];
            }
        }
        s[i] %= MOD;

    }

    cout << s[N] << endl;

    return 0;
}

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

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	string s;
	int a[26] = {};
	
	cin>>s;
	
	for(int i = 0; i < s.size(); i++){
		a[s[i] - 'a']++;
	}
	
	for(int i = 0; i < 26; i++){
		if(a[i] == 0){
			cout<<(char)('a' + i)<<endl;
			return 0;
		}
	}
	cout<<"None"<<endl;
	
	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<algorithm>
#define RI register int
#define CI const int&
using namespace std;
const int N=100005;
int n,m,a[N<<1],pos,ans;
inline bool check(CI x)
{
	for (RI i=(x<<1)+1,j=(n<<1);i<=j;++i,--j) if (a[i]+a[j]<m) return 0; return 1;
}
int main()
{
	RI i,j; for (scanf("%d%d",&n,&m),i=1;i<=(n<<1);++i)
	scanf("%d",&a[i]); sort(a+1,a+(n<<1)+1);
	int l=0,r=n,mid; while (l<=r)
	if (check(mid=l+r>>1)) pos=mid,r=mid-1; else l=mid+1;
	for (i=1,j=(pos<<1);i<=j;++i,--j) ans=max(ans,a[i]+a[j]);
	for (i=(pos<<1)+1,j=(n<<1);i<=j;++i,--j) ans=max(ans,a[i]+a[j]-m);
	return printf("%d",ans),0;
}

Measured memory_bytes: 4440
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while ( true ) {
			double x = sc.nextDouble();
			double h = sc.nextDouble();
			if ( x == 0 && h == 0 ) break;
			double te = x*x;
			double h2 = Math.sqrt( ( (x/2) * (x/2) ) + (h*h));
			double tan = x * h2 / 2.0;
			System.out.printf("%.6f%n",te+tan*4);
		}
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
int main()
{
        int kane,otu,mai=0;
        int i,j,k;
        while(1){
        scanf("%d",&kane);
        otu=1000-kane;
        if(otu==1000)break;
        for(i=0;i<100;i++){
                if(otu-500>=0)
                {
                        otu-=500;
                        mai++;
                }
        }
        for(i=0;i<100;i++){
                if(otu-100>=0)
                {
                        otu-=100;
                        mai++;
                }
        }
        for(i=0;i<100;i++){
                if(otu-50>=0)
                {
                        otu-=50;
                        mai++;
                }
        }
        for(i=0;i<100;i++){
                if(otu-10>=0)
                {
                        otu-=10;
                        mai++;
                }
        }
        for(i=0;i<100;i++){
                if(otu-5>=0)
                {
                        otu-=5;
                        mai++;
                }
        }
        for(i=0;i<100;i++){
                if(otu-1>=0)
                {
                        otu-=1;
                        mai++;
                }
        }
        printf("%d\n",mai);
        mai=0;
        }
        return 0;
}

Measured memory_bytes: 600
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF            1e9
#define INFLL          1e18
#define EPS            1e-9
#define REP(i,n)       for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)      for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)      for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)     for(ll i=(n);i>0;--i)
#define REPC(i,obj)    for(auto i:obj)
#define ALL(obj)       (obj).begin(),(obj).end()
#define SETP(n)        cout<<fixed<<setprecision(n)
#define VV(T,h,w)      move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i)   move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T, ll h, ll w>using vec2 = vector<vector<T>>;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

bool leap(ll y)
{
	return y % 400 == 0 || y % 100 != 0 && y % 4 == 0;
}
struct date {
	ll y, m, d;
	date operator++(int)
	{
		auto cpy = *this;
		switch (m) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			d = d == 31 ? 1 : d + 1;
			if (d == 1)m = m == 12 ? 1 : m + 1;
			if (d == 1 && m == 1)++y;
			break;
		case 2:
			if (leap(y))d = d == 29 ? 1 : d + 1;
			else d = d == 28 ? 1 : d + 1;
			if (d == 1)m = 3;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			d = d == 30 ? 1 : d + 1;
			if (d == 1)++m;
			break;
		}
		return cpy;
	}
	bool operator==(const date&dt)
	{
		return y == dt.y && m == dt.m && d == dt.d;
	}
	bool operator!=(const date&dt)
	{
		return !(*this == dt);
	}
};
signed main()
{
	date d1, d2;
	while (cin >> d1.y >> d1.m >> d1.d >> d2.y >> d2.m >> d2.d, d1.y != -1) {
		ll ans = 0;
		while (d1++ != d2)++ans;
		cout << ans << endl;
	}
}


Measured memory_bytes: 2992
#include <iostream>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int d[N],count = 0;
  for(int i = 0;i < N;i++)cin >> d[i];
  for(int i = 0;i < N;i++){
    if(d[i]){
      for(int j = i + 1;j < N;j++){
        if(d[i] == d[j])d[j] = 0;
      }
      d[i] = 0;
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n, k;
    cin >> n >> k;
    vi h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    vl dp(n);
    for (int i = 1; i < n; ++i) {
        dp[i] = INF;
        for (int j = i - 1; j >= max(0, i - k); --j) {
            chmin(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    cout << dp[n - 1] << "\n";
    return 0;
}

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

int main(){
    long long int price =100;
    long long int k;
    cin >>k;
    int ans=0;
    while(price<k){
        price +=price/100;
        ans ++;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3160
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A = list(map(int, readline().split()))
    
    if sum(A) >= 22:
        print('bust')
    else:
        print('win')
    
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9108
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <functional>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
using namespace std;
template <typename T, typename X> auto vectors(T a, X x) { return vector<T>(x, a); }
template <typename T, typename X, typename Y, typename... Zs> auto vectors(T a, X x, Y y, Zs... zs) { auto cont = vectors(a, y, zs...); return vector<decltype(cont)>(x, cont); }
 
const int dy[] = { -1, 1, 0, 0, -1, 1, -1, 1 };
const int dx[] = { 0, 0, 1, -1, -1, 1, 1, -1 };
 
vector<vector<bool> > load_image() {
    int h, w; cin >> h >> w;
    if (h == 0 and w == 0) return vector<vector<bool> >();
    vector<vector<bool> > f = vectors(false, h+2, w+2);
    repeat (y,h) repeat (x,w) {
        char c; cin >> c;
        f[y+1][x+1] = c == '#';
    }
    return f;
}
 
vector<set<int> > make_tree(vector<vector<bool> > const & f) {
    int h = f.size();
    int w = f.front().size();
    vector<vector<int> > k = vectors(-1, h, w);
    vector<set<int> > g;
    function<void (int, int, int)> dfs = [&](int y, int x, int cur_k) {
        k[y][x] = cur_k;
        repeat (i, f[y][x] ? 8 : 4) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (ny < 0 or h <= ny or nx < 0 or w <= nx) continue;
            if (f[ny][nx] == f[y][x]) {
                if (k[ny][nx] == -1) {
                    dfs(ny, nx, cur_k);
                }
            } else {
                if (k[ny][nx] != -1) {
                    g[k[ny][nx]].insert(k[y][x]);
                }
            }
        }
    };
    repeat (y,h) repeat (x,w) if (k[y][x] == -1) {
        g.emplace_back();
        dfs(y, x, g.size() - 1);
    }
    return g;
}
 
string format_tree(int i, int p, vector<set<int> > const & g) {
    vector<string> ts;
    for (int j : g[i]) if (j != p) {
        ts.push_back(format_tree(j, i, g));
    }
    whole(sort, ts);
    string s;
    s += '(';
    for (string t : ts) s += t;
    s += ')';
    return s;
}
 
bool is_isomorphic(vector<set<int> > const & t1, vector<set<int> > const & t2) {
    return format_tree(0, -1, t1) == format_tree(0, -1, t2);
}
 
int main() {
    while (true) {
        auto g1 = load_image(); if (g1.empty()) break;
        auto g2 = load_image();
        auto t1 = make_tree(g1);
        auto t2 = make_tree(g2);
        cout << (is_isomorphic(t1, t2) ? "yes" : "no") << endl;
    }
    return 0;
}



Measured memory_bytes: 3364
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std;

typedef long long ll;
typedef short int sh;

const int inf=0x3f3f3f3f;
const int MAX=1e5+10;
const int mod=1e9+7;

int position[26][MAX],Size[26];
char str[MAX];

void Get_Pos()
{
    memset(Size,0,sizeof(Size));
    for(int i=0;str[i];i++)
    {
        int k=str[i]-'a';
        position[k][Size[k]++]=i;
    }
}

void Solve()
{
    for(int i=0;i<26;i++)
    {
        for(int j=0;j<Size[i]-1;j++)
        {
            for(int k=j+1;k<Size[i];k++)
            {
                if(((k-j+1)<<1)>position[i][k]-position[i][j]+1)
                {
                    printf("%d %d\n",position[i][j]+1,position[i][k]+1);
                    return;
                }
            }
        }
    }
    printf("-1 -1\n");
}

int main()
{
    int n;
    while(scanf("%s",str)!=EOF)
    {
        Get_Pos();
        Solve();
    }
    return 0;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
const int N = 1005;

int n, m, x, y, fx, fy, f[N][N];
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
char a[N][N];
struct node {
	int x, y;
};
deque <node> q;

int main() {
	cin>>n>>m>>x>>y>>fx>>fy;
	memset(f, -1, sizeof(f));
	rep(i, 1, n)
	    rep(j, 1, m) 
	    	cin>>a[i][j];
	if(a[x][y] == '#' || a[fx][fy] == '#') {
		cout<<-1<<endl;
		return 0;
	}
	q.push_front((node) {x, y});
	f[x][y] = 0;
	while(!q.empty()) {
		node cur = q.front();
		q.pop_front();
		int cx = cur.x, cy = cur.y;
		if(cx == fx && cy == fy) break;
		rep(i, 0, 3) {
			int nx = cx + dx[i], ny = cy + dy[i];
			if(nx > n || nx < 1 || ny < 1 || ny > m || a[nx][ny] == '#') continue;
			if(f[nx][ny] != -1 && f[nx][ny] <= f[cx][cy]) continue;
			f[nx][ny] = f[cx][cy];
			q.push_front((node) {nx, ny});
		}
		rep(i, -2, 2)
		    rep(j, -2, 2) {
		    	int nx = cx + i, ny = cy + j;
				if(nx > n || nx < 1 || ny < 1 || ny > m || a[nx][ny] == '#') continue;
				if(f[nx][ny] != -1) continue;
				f[nx][ny] = f[cx][cy] + 1;
				q.push_back((node) {nx, ny});
		    }
	}
	cout<<f[fx][fy]<<endl;
}

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

using namespace std;

const long long inf = 1000000000000000000;

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

	auto id = [&] (int i, int j) {
		return i * 2501 + j;
	};

	vector<vector<pair<int, int> > > G;
	G.resize(id(n, 0));

	for(int i = 0; i < m; ++i) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		
		--u;
		--v;

		for(int j = 2500; j >= a; --j) {
			G[id(u, j)].emplace_back(id(v, j - a), b);
			G[id(v, j)].emplace_back(id(u, j - a), b);
		}
	}

	for(int i = 0; i < n; ++i) {
		int c, d;
		cin >> c >> d;

		c = min(c, 2500);

		for(int j = 0; j < 2500; ++j) {
			G[id(i, j)].emplace_back(id(i, min(j + c, 2500)), d);
		}
	}

	priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > q;
	
	q.emplace(0, id(0, min(2500, s)));

	vector<long long> d;
	d.assign(id(n, 0), inf);

	d[id(0, min(2500, s))] = 0;

	while(!q.empty()) {
		auto o = q.top();
		q.pop();

		int u = o.second;

		if(d[u] < o.first) {
			continue;
		}

		for(auto t : G[u]) {
			int v = t.first;
			int w = t.second;

			if(d[u] + w < d[v]) {
				d[v] = d[u] + w;
				q.emplace(d[v], v);
			}
		}
	}

	for(int i = 1; i < n; ++i) {
		long long ans = inf;

		for(int j = 0; j <= 2500; ++j) {
			ans = min(ans, d[id(i, j)]);
		}

		cout << ans << '\n';
	}

	return 0;
}


Measured memory_bytes: 17500
import heapq

N,M = map(int,input().split())
value = list(map(int,input().split()))
value = list(map(lambda x: x*(-1), value))
heapq.heapify(value)

for i in range(M):
  num = (heapq.heappop(value)*(-1)//2)*(-1)
  heapq.heappush(value,num)

print(sum(list(map(lambda x: x*(-1), value))))


Measured memory_bytes: 14180
k = gets.to_i

puts [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][k - 1]


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

int main() {
  int N;
  cin>>N;
  
  vector<int> Lseat(1100);
  vector<int> Rseat(1100);
  
  for(int i=0;i<N;i++){
    cin>>Lseat[i];
    cin>>Rseat[i];
    cout<<endl;
  }
  
  int x=0;
  for(int i=0;i<N;i++){
    x+=Rseat[i]-Lseat[i]+1;
  }
  
  cout<<x<<endl;
}


Measured memory_bytes: 256
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

// 20:49

enum{N=100023};

ll a[N];

int main(){
	ll n=ci();
	ll sum=0;
	rep(i,1,n) sum+= a[i]=ci();
	ll t=sum/(n*(n+1)/2);
	if( sum!=t*n*(n+1)/2 ){ puts("NO"); return 0; }
	ll tmp= a[n];
	rev_rep(i,n,2) a[i]=a[i-1]-a[i]+t;
	a[1]= tmp-a[1]+t;
	rep(i,1,n) if( a[i]<0 || a[i]%n!=0 ){ puts("NO"); return 0; }
	puts("YES");
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}
 
int main() { 
    long double a, b, h, m;
    cin >> a >> b >> h >> m;
    // int kod = min(abs(30 * h - 6 * m), abs(360 - 30 * h - 6 * m));
    long double hm = 60 * h + m;
    long double kod = /*min(*/max(hm * 0.5, m * 6) - min(hm * 0.5, m * 6)/*, 360 - (max(hm * 0.5, m * 6) - min(hm * 0.5, m * 6)))*/;
    // cout << kod << endl;
    long double pi = 3.14159265358979;
    long double rad = pi * kod / 180;
    long double ans = sqrt(a * a + b * b - 2 * a * b * cos(rad));
    // cout << kod << endl;
    // cout << rad << endl;
    // cout << cos(1.57) << endl;
    cout << fixed << setprecision(10) << ans << endl;
}

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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << endl;
#define endl "\n"
#define MOD (int) 1e9+7
#define inf (int) (1e18)

void solve(){
    ll n,d;
    cin>>n>>d;
    ll ans=0;
    for(long int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        ll tp=a*a+b*b;
        if(tp<=d*d){
            ans++;
        }
    }
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin >> t;
    for(long int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>

int main() {
  std::string x;
  
  std::cin >> x;
  
  if (x[1] == x[2] && (x[0] == x[1] || x[2] == x[3])) {
    std::cout << "Yes\n";
  } else {
    std::cout << "No\n";
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#include <algorithm>

using namespace std;

int cmp_count = 0;


void merge(int A[],int left,int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int L[n1+1],R[n2+1];
	for(int i = 0; i < n1; i++) L[i] = A[left + i];
	for(int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] =  INT_MAX;

	int i = 0, j = 0;
	for(int k = left;k < right; k++){
		if(L[i] <= R[j]){
			A[k] = L[i++];
			cmp_count++;
		}else{
			A[k] = R[j++];
			cmp_count++;
		}
	}
}

void mergeSort(int A[],int left,int right){
	if(left+1 < right){
		int mid = (left+right)/2;
		mergeSort(A,left,mid);
		mergeSort(A,mid,right);
		merge(A,left,mid,right);
	}
}

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

	mergeSort(S,0,n);

	for(int i = 0; i < n-1; i++) printf("%d ",S[i]);
	printf("%d\n",S[n-1]);
	printf("%d\n",cmp_count);

}

Measured memory_bytes: 4932
#include <stdio.h>
#include <math.h>
#include <vector>
 
using namespace std;
 
int main(){
 
    int n,tmp,sum=0,tmp_min;
    scanf("%d",&n);
    int table[n][n],check[n],num_of_group=0,parent,child;
    vector<int> Group;
 
    for(int i=0;i<n;i++){
        for(int k=0;k<n;k++){
            scanf("%d",&tmp);
            table[i][k]=tmp;
        }
        check[i]=0;
    }
 
    Group.push_back(0);
    check[0]=1;
    num_of_group = 1;
    while(num_of_group<n){
        tmp_min=2001;
 
        for(int i=0;i<num_of_group;i++){
            for(int k=0;k<n;k++){
                if(table[Group[i]][k]!=-1&&check[k]==0&&table[Group[i]][k]<tmp_min){
                    tmp_min = table[Group[i]][k];
                    parent=Group[i];
                    child = k;
                }
            }
        }
        Group.push_back(child);
        sum+=table[parent][child];
        check[child]=1;
        num_of_group++;
    }
 
    printf("%d\n",sum);
 
    return 0;
}


Measured memory_bytes: 2676
#include <stdio.h>
int main(void)

{   int a,b,i;
    char op;
    for(i=1;i>0;i++){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+')
        {printf("%d\n",a+b);
        }
        else if(op=='-')
        {printf("%d\n",a-b);
        }
        else if(op=='*')
        {printf("%d\n",a*b);
        }
        else if(op=='/'){
            printf("%d\n",a/b);
        }else if(op=='?') {
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
#pragma GCC optimize("O999")
//示例：#define ll long long
//unsigned long long ;
const int INF=0x3f3f3f3f;
const int maxn=50000005;
using namespace std;

int main(){
	//freopen(".in", "r",stdin );
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	long long n, k, minv=n;
	cin >> n >> k;
	cout << min(n%k,k-(n%k)) << endl;
	return 0;
}

Measured memory_bytes: 256
s=input()
n=len(s)
m=n//2
def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True
if is_kaibun(s[:m]) and is_kaibun(s[m+1:]) and s[:m]==s[m+1:]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
cnt = [0 for _ in range(N)]
for i in range(N):
    cnt[A[i]-1] += 1
S = 0
for i in range(N):
    S += cnt[i]*(cnt[i]-1)/2
for i in range(N):
    if cnt[A[i]-1] == 1:
        print(int(S))
    else:
        print(int(S+(3-2*cnt[A[i]-1])/2))


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

using namespace std;


int main() {
    int n;
    cin>>n;
    int a,b,c,d;
    a=n/1000;
    b=n/100%10;
    c=n/10%10;
    d=n%10;
    if(a+b+c+d==7)printf("%d+%d+%d+%d=7",a,b,c,d);
    else if(a+b+c-d==7)printf("%d+%d+%d-%d=7",a,b,c,d);
    else if(a+b-c+d==7)printf("%d+%d-%d+%d=7",a,b,c,d);
    else if(a-b+c+d==7)printf("%d-%d+%d+%d=7",a,b,c,d);
    else if(a+b-c-d==7)printf("%d+%d-%d-%d=7",a,b,c,d);
    else if(a-b+c-d==7)printf("%d-%d+%d-%d=7",a,b,c,d);
    else if(a-b-c+d==7)printf("%d-%d-%d+%d=7",a,b,c,d);
    else if(a-b-c-d==7)printf("%d-%d-%d-%d=7",a,b,c,d);

    return 0;
}

Measured memory_bytes: 256