akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;

int main() {
  int n, k;
  cin >> n >> k;
  int sum = 1;
  for (int i = 0; i < n; i++) {
    sum = sum <= k ? 2 * sum : sum + k;
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
import math
k = int(input())
a = 0
b = 0
c = 0

for i in range(1, k+1):
    for j in range(1, k+1):
        a = math.gcd(i,j)
        for k in range(1, k+1):
            b = math.gcd(a, k)
            c = c + b

print(c)


Measured memory_bytes: 9120
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long n = sc.nextLong();
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) != '1') {
				if(n < i+1) {
					System.out.println(1);
				} else {
					System.out.println(s.charAt(i));
				}
				return;
			}
		}
		System.out.println(1);
	}
}


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

/*昨日はStarry Sky Treeと同じ*/
/*Range Add Min(Max) Query*/
/*区間加算、区間Min,区間Max*/

class RSUQ{
public: 
  typedef long long ll;

  //マージ可能な主データ型
  struct D{
    ll value;
    D():value(0){} /*適切な値にする!!!!!!*/
    D(ll value):value(value){}
    bool operator < (D a)const {return value < a.value;}
  };

  //遅延用の型  
  struct T{
    int type; //0 - empty   , 1 - update
    ll value;
    T():type(0),value(0){}
    T(int type,ll value):type(type),value(value){}
  };

  
  int n, n_;
  vector<D> dat;
  vector<T> td;
  D returnD = D(0); // 範囲外の時に返す値。
  
  RSUQ(){n=-1;}
  RSUQ(int n_):n_(n_){
    n=1;
    while(n < n_) n *= 2;
    td.resize(2*n-1,T());
    dat.resize(2*n-1,D());
  }
  
  inline D merge(D a,D b){return a.value + b.value;}
  
  void delay(int k,int len){
    if(td[k].type==0) return;
    ll v = td[k].value;
    td[k].type = 0;
    td[k].value = 0;
    
    len /= 2;
    {
      int l = k*2+1;
      dat[l].value = v * len; td[l].type = 1; td[l].value = v;
    }
    {
      int r = k*2+2;
      dat[r].value = v * len; td[r].type = 1; td[r].value = v;
    }
  }

  D write(int k, D x, int len){
    dat[k].value = x.value * len;
    td[k].type = 1;
    td[k].value = x.value;
    return dat[k];
  }
  
  D dfs(int a, int b, D x, bool flag, int k, int l, int r){
    if(r <= a||b <= l) return flag? dat[k]:returnD;
    if(a <= l && r <= b) return flag? write(k, x, r - l):dat[k];
    delay(k, r - l);
    D vl = dfs(a, b, x, flag, k*2+1, l, (l+r)/2);
    D vr = dfs(a, b, x, flag, k*2+2, (l+r)/2, r);
    return flag? (dat[k] = merge(vl, vr)):merge(vl, vr);
  }

  //[l,r)の値をx変更　query(l,r,x)
  void update(int l,int r,ll x){
    assert(l <= r);
    assert(0 <= l && l <= n);
    assert(0 <= r && r <= n);
    dfs(l, r, D(x), true, 0, 0, n);
  }
  
  //[l,r)の合計値を得る　find(a,b);
  ll find(int l,int r){
    assert(l <= r);
    assert(0 <= l && l <= n);
    assert(0 <= r && r <= n);
    D res = dfs(l, r, D(), false, 0, 0, n);
    return res.value;
  }
};


signed main(){
  int n,q;
  cin>>n>>q;
  
  RSUQ rsuq(n);

  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd == 0){
      int s,t,x;
      cin>>s>>t>>x;
      rsuq.update(s,t+1,x);
    }
    
    if(cmd == 1){
      int s,t;
      cin>>s>>t;
      cout<<rsuq.find(s,t+1)<<endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 8892
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


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


    int n;
    cin >> n;
    int a[n + 2], b[n + 1];
    for (int i = 1; i <= n + 1; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    b[0] = 0;

    ll ans = 0;

    for (int i = 1; i <= n; i++) {
        ll taken = min(b[i], a[i]);
        b[i] -= taken;
        a[i] -= taken;
        ans += taken;

        if (i + 1 <= n + 1) {
            ans += min(a[i + 1], b[i]);
            a[i + 1] -= min(a[i + 1], b[i]);
        }
    }


    cout << ans;



}

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

public class Main{
  public static void main(String[] args) {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))){
      int n = Integer.parseInt(in.readLine());
      int max = -1;
      int min = 1001;
      for(String s: in.readLine().split(" ")){
        int a = Integer.parseInt(s);
        if(a>max){
          max=a;
        }
        if(a<min){
          min=a;
        }
      }
      System.out.println(max-min);
    }catch(IOException e){
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 21076
#include<iostream>

using namespace std;

int main(){
    string c;
    cin >> c;
    if (c=="a"){
    cout<<"vowel"<<endl;
    }
    else if(c=="e"){
    cout<<"vowel"<<endl;
    }
    else if(c=="i"){
    cout<<"vowel"<<endl;
    }
    else if(c=="o"){
        cout<<"vowel"<<endl;
    }
    else if(c=="u"){
        cout<<"vowel"<<endl;
    }
    else{
     cout<<"consonant"<<endl;
    }
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pci pair<char,int>
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a)*((b)/gcd(a,b))
#define popcount(x) __builtin_popcount(x)

const ll mod = 1e9+7;


// Call by reference is used in x
template<typename T, typename U>
static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}

// call by reference is used in x
template<typename T, typename U>
static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}


template<typename T> void scan(T &x)
{
    x = 0;
    bool neg = 0;
    register T c = getchar();

    if (c == '-')
        neg = 1, c = getchar();

    while ((c < 48) || (c > 57))
        c = getchar();

    for ( ; c < 48||c > 57 ; c = getchar());

    for ( ; c > 47 && c < 58; c = getchar() )
        x= (x << 3) + ( x << 1 ) + ( c & 15 );

    if (neg) x *= -1;
}

template<typename T> void print(T n)
{
    bool neg = 0;

    if (n < 0)
        n *= -1, neg = 1;

    char snum[65];
    int i = 0;
    do
    {
        snum[i++] = n % 10 + '0';
        n /= 10;
    }

    while (n);
    --i;

    if (neg)
        putchar('-');

    while (i >= 0)
        putchar(snum[i--]);

    putchar('\n');
}

using namespace std;

void dfs(int v)
{

}
void build(int ind,int low,int high)  // Build Segment Tree
{

}
int query(int ind,int low,int high,int l,int r)  //Query for Segment Tree
{

}
int main()
{
 	int n,x,t;cin>>n>>x>>t;
 	int d=n/x;
 	int r=n%x;
 	if(r==0) cout<<d*t;
 	else cout<<(d+1)*t;
 	
 	


return 0;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a / gcd(a, b) * b; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

int get_count(vector<int> arr,int n){
    int ret = 0;
    rep(i,arr.size()){
        if(arr[i] <= n)continue;
        ret += ((arr[i] + (n - 1)) / n) - 1;
    }
    return ret;
}
int bin_search(vector<int> arr,int k){
    int l = 0,r = maxArr(arr);

    while(abs(l - r) > 1){
        int mid = (l + r) / 2;
        if(get_count(arr,mid) <= k){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    return r;
}

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

    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    rep(i,n)cin>>a[i];

    cout<<bin_search(a,k)<<endl;

}


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

using namespace std;

int main(){
  vector<int> h,w;
  int _h,_w;
  while(1){
    cin >> _h >> _w;
    if(_h == 0 && _w == 0){
      break;
    }
    h.push_back(_h);
    w.push_back(_w);
  }
  for(int i=0;i<h.size();i++){
    for(int h_i=0;h_i<h[i];h_i++){
      for(int w_i=0;w_i<w[i];w_i++){
        if((h_i + w_i) % 2 == 0){
          cout << "#";
        }else{
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3132
#include<iostream>

using namespace std;

int main(void) {

	int n = 0, a = 0, n1, n2;

	cin >> n >> a;

	n1 = n / 500;

	n2 = n - (500 * n1);

	if (n2 <= a) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

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

const int B = 1e9+7;

inline ll calc(ll n) { return n*(n+1)/2; }

int main() {
	ll n, k; scanf("%lld%lld", &n, &k);
	ll sum = 0;
	REP(i,k,n+2){
		sum = (sum + calc(n)-calc(n-i)-calc(i-1)+1) % B;
	}

	printf("%lld\n", sum);
}

Measured memory_bytes: 3828
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

     String n = sc.next();
     char c ;
     String s;
     int data = 0;
     for (int i = 0;i<n.length() ;i++ ) {
       c = n.charAt(i);
       s = String.valueOf(c);
       int a =  Integer.parseInt(s);
       data  +=a;
     }

     if(Integer.parseInt(n)%data==0){
       System.out.println("Yes");
     }else{
       System.out.println("No");
     }




      }
    }


Measured memory_bytes: 23124
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>

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)
using ll = long long;
#define EPS 1e-9
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int MINF = -1e9;


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {
	
	int n;
	cin >> n;
	vector<int> h;
	rep(i, n) {
		int x;
		cin >> x;
		h.push_back(x);
	}
	ll dp[100050];
	rep(i, 100050) dp[i] = INF;

	dp[0] = 0;
	for(int i = 1; i < n; ++i) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1528
ai,ao,at,aj,al,aS,az=map(int,input().split())
ans = ao
if aj > 0 and al > 0 and ai > 0:
    print(ao + max(2 * (ai // 2 + al // 2 + aj // 2), 3 + 2 * ((ai - 1) // 2 + (al - 1) // 2 + (aj - 1) // 2)))
else:
    print(ao + 2 * (ai // 2 + al // 2 + aj // 2))


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

int main(){
	long long n,m;
	cin>>n>>m;
	if(abs(n-m)>1){
		cout<<0<<endl;
		return 0;
	}
	long long ans=1;
	for(int i=1;i<=n;i++){
		ans*=i;
		ans%=1000000007;
	}
	for(int i=1;i<=m;i++){
		ans*=i;
		ans%=1000000007;
	}
	if(n==m) ans*=2;
	ans%=1000000007;
	cout<<ans<<endl;
}

Measured memory_bytes: 3604
//2018.09.18 UC WA, RE

#include <iostream>
using namespace std;

int main() {

    int n,y;
    cin >> n >> y;

    int ten,five,one;
    int ten_max;

    ten_max = y/10000;
    bool ans=false;

    int i,j,k;
    bool calc = true;
    for(i=0;i<=ten_max;i++){
        for(j=0;j<=(n-i);j++){
            k=n-i-j;
            if(k>=0 && 10000*i+5000*j+1000*k==y) {
                ten=i;five=j;one=k;
                calc = false;
                break;
            }
        }
        if(calc==false) break;
    }


    if(calc==false) cout << ten << ' ' << five << ' ' << one << endl;
    else cout << "-1 -1 -1" << endl;

    return 0;
}

Measured memory_bytes: 256
s = str(input())
p = str(input())
if p[0] not in s:
	print("No")
elif p in s:
	print("Yes")
else:
	for i in range(len(s)):
		s = s[1:] + s[:1]
		if p in s:
			print("Yes")
			break
	else:
		print("No")


Measured memory_bytes: 5560
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int K, X;
    cin >> K >> X;
    FOR(i, X - K + 1, X + K) cout << i << " "; cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
const int maxn = 100;

int a[maxn];

int main() {
  static int n, ans;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      ans += a[i] * a[j];
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define x real()
#define y imag()
typedef complex<int> P;

void shift(P b, vector<P> &xy){
  REP(i, xy.size()) xy[i] += b;
}

bool check(vector<P> &nxy, vector<P> &mxy, int N, int M){
  REP(i, N){
    bool f = false;
    REP(j, M) if(nxy[i] == mxy[j]) f = true;
    if(!f) return false;
  }
  return true;
}

int main() {
  int N;
  while(cin >>N && N){
    vector<P> nxy(N), _nxy;
    REP(i, N){ int a, b; cin >>a >>b; nxy[i] = P(a, b); }
    int M; cin >>M;
    vector<P> mxy(M);
    REP(i, M){ int a, b; cin >>a >>b; mxy[i] = P(a, b); }
    REP(i, M){
      _nxy = nxy;
      P s = mxy[i] - _nxy[0];
      shift(s, _nxy);
      if(check(_nxy, mxy, N, M)){
        cout <<s.x <<" " <<s.y <<endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}

signed main()
{
   int N, Z, W; cin >> N >> Z >> W;
   V<int> a(N); REP(i, N) cin >> a[i];

   int ans;
   if (N == 1) {
      ans = abs(a[N-1] - W);
   } else {
      ans = max(abs(a[N-1] - W), abs(a[N-1] - a[N-2]));
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
s = input()

num = len(s)

while len(s)>=5:
    if s[-5:] == "dream" or s[-5:] == "erase":
        s = s[:-5]
    elif s[-7:] == "dreamer":
        s = s[:-7]
    elif s[-6:] == "eraser":
        s = s[:-6]
    else:
        break

if len(s) == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

const int N = 1e5+5;
vii g[N];
bool visited[N];
int dist[N];

int bfs(int src) {
	deque<int> dq;
	memset(visited, false, sizeof(visited));
	dist[src]=0;
	dq.push_back(src);
	while(!dq.empty()) {
		int curr = dq.front(); dq.pop_front();
		visited[curr]=true; // important to do it here not inside the for loop.

		for(ii nxt : g[curr]) {
			if(!visited[nxt.ff]) {
				dist[nxt.ff] = dist[curr] + nxt.ss;
				if(nxt.ss) {
					dq.push_back(nxt.ff);
				} else {
					dq.push_front(nxt.ff);
				}
			}
		}
	}

	return dist[0] + 1;
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int k;
    cin>>k;
    FOR(i, 0, k) {
    	g[i].push_back({(i+1)%k, 1});
    	g[i].push_back({(i*10)%k, 0});
	}
	cout<<bfs(1);

    return 0;
}

Measured memory_bytes: 6528
#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()
{
    int h, w;
    while (1)
    {
        cin >> h >> w;
        if (h == 0 && w == 0)
            break;
        rep(i, h)
        {
            rep(j, w) cout << "#";
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        boolean ans = Math.max(a, b) <= 8;
        System.out.println(ans ? "Yay!" : ":(");
        inp.close();
    }
}


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

using namespace std;

const int N = 110;

int vec[N];

int main() {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; ++i) {
		scanf("%d", &vec[i]);
	}
	long long ans = 0x3f3f3f3f;
	for (int i = -100; i <= 100; ++i) {
		long long at = 0;
		for (int j = 0; j < n; ++j) {
			at += (i-vec[j]) * 1ll * (i-vec[j]);
		}
		ans = min(ans, at);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<iterator>
#include<iomanip>
#include<cmath>
#include<map>
#include<string.h>
#include<algorithm>

using namespace std;
void ll(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main() {

	ll();
	
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++)
	{
		if (i==5||i==13)
		{
			cout << " ";
			continue;
			
		}
		
		cout << s[i];
	}
	cout << endl;

}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

const ll mod = 1000000007;

int main(void)
{
	ll h,w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		cout << 1 << endl;
		return 0;
	}
	ll s = (h * w + 1) / 2;
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif
#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;
const int MOD=1e9+7;
const int INF=1<<29;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
map<char,int> m;
void solve(){  
   int x,y,z;
   cin>>x>>y>>z;
   int res=(x-z)/(y+z);
   cout<<res<<endl;
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
    IOS;
    solve();
    #ifdef LOCAL_DEFINE
    cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
    #endif
}


Measured memory_bytes: 256
import sys
from functools import lru_cache
t=int(input())
def solve(n,A,B,C,D):
	@lru_cache(None)#メモ化再帰
	def f(x):
		if x<=1:
			return D*x
		ret=D*x

		if x%2==0:
			ret=min(ret,f(x//2)+A)
		else:
			ret=min(ret,f(x//2)+A+D,f(x//2+1)+A+D)
		
		if x%3==0:
			ret=min(ret,f(x//3)+B)
		elif x%3==1:
			ret=min(ret,f(x//3)+B+D)
		else:
			ret=min(ret,f(x//3+1)+B+D)

		if x%5<=2:
			ret=min(ret,f(x//5)+C+D*(x%5))
		else:
			ret=min(ret,f(x//5+1)+C+D*(5-x%5))
		return ret
	return f(n)
for _ in range(t):
	n,A,B,C,D=map(int,input().split())
	print(solve(n,A,B,C,D))

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

typedef long long ll;
const ll mod=1e9+7;
const int N=200000;

void Run()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int a[N],b[N];
list<char>v;
map<char,int>mp;
int main()
{
   Run();
    ll A,B,C,K;
  cin>>A>>B>>C>>K;
  if(K<=A) {
cout<<K<<endl;
    return 0;
  }
  else if(K>A+B) {
cout<<2*A+B-K<<endl;
  }
  else {
cout<<A<<endl;
  }
}



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back

int main() {
    ll a , b , c , d ;
    cin >> a>> b >> c >> d ;
    ll x = (c*d) / __gcd(c,d) ;

    ll r , l , m ,n ;
     r = b/c - (a-1)/c ;
     l = b/d - (a-1)/d ;
     m = b/x - (a-1)/x ;

     cout << (b-a+1) - ( r+l-m )<< endl  ;


}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS

readString = map BS.unpack . BS.words

getString = readString <$> BS.getLine

simulate :: String -> String -> String -> Char -> String
simulate [] _ _ 'a' = "A"
simulate _ [] _ 'b' = "B"
simulate _ _ [] 'c' = "C"
simulate as bs cs x
  | x == 'a' = simulate (tail as) bs cs (head as)
  | x == 'b' = simulate as (tail bs) cs (head bs)
  | x == 'c' = simulate as bs (tail cs) (head cs)

main = do
  [as] <- getString
  [bs] <- getString
  [cs] <- getString
  putStrLn $ simulate as bs cs 'a'


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

typedef long long ll;

int n,d,a,sz;
ll data[800005];
ll lazy[800005];
pair<int,int> mon[200005];

void build(int bk,int l,int r){
    if(l==r){
        if(l<=n){
            data[bk]=mon[l].second;
        }
        return;
    }
    build(bk<<1,l,(l+r)>>1);
    build(bk<<1|1,((l+r)>>1)+1,r);
    data[bk]=data[bk<<1]+data[bk<<1|1];
}

void upd(int bk,int l,int r,int ql,int qr,ll val){
    if(qr<l||r<ql)return;
    if(ql<=l&&r<=qr){
        lazy[bk]+=val;
        data[bk]+=val*(r-l+1);
        return;
    }
    lazy[bk<<1]+=lazy[bk];
    data[bk<<1]+=lazy[bk]*((r-l+1)>>1);
    lazy[bk<<1|1]+=lazy[bk];
    data[bk<<1|1]+=lazy[bk]*((r-l+1)>>1);
    lazy[bk]=0;
    upd(bk<<1,l,(l+r)>>1,ql,qr,val);
    upd(bk<<1|1,((l+r)>>1)+1,r,ql,qr,val);
    data[bk]=data[bk<<1]+data[bk<<1|1];
}

ll qry(int bk,int l,int r,int ql,int qr){
    if(qr<l||r<ql)return 0;
    if(ql<=l&&r<=qr){
        return data[bk];
    }
    lazy[bk<<1]+=lazy[bk];
    data[bk<<1]+=lazy[bk]*((r-l+1)>>1);
    lazy[bk<<1|1]+=lazy[bk];
    data[bk<<1|1]+=lazy[bk]*((r-l+1)>>1);
    lazy[bk]=0;
    return qry(bk<<1,l,(l+r)>>1,ql,qr)+qry(bk<<1|1,((l+r)>>1)+1,r,ql,qr);
}

ll ans;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>d>>a;
    sz=1;while(sz<n)sz<<=1;
    for(int i=1;i<=n;i++){
        cin>>mon[i].first>>mon[i].second;
    }
    sort(mon+1,mon+1+n);//读入，对怪物排序
    build(1,1,sz);//建立线段树
    int l=1,r=1;
    while(l<=n){
        while(mon[r+1].first-mon[l].first<=d+d&&r<n){
            r++;
        }//尺取法
        ll lft=qry(1,1,sz,l,l);//cerr<<lft<<endl;
        if(lft<=0){//如果怪物死了就不计算了，我还因为这个wa了一次qaq
            l++;
            continue;
        }
        ll tms=(lft+a-1)/a;//杀掉这个怪物需要多少炸弹
        ans+=tms;
        upd(1,1,sz,l,r,(-tms)*a);//我也不知道为什么要加上括号qaq
        l++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 12544
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
char s[N];
int fa[N],v[N],c[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline int find(int x) {return fa[x]==x?x:fa[x]=find(fa[x]);}
int main() {
    int n,m,p;
    scanf("%s%d",s+1,&m);
    n=strlen(s+1),p=n/2+1;
    for(int i=1;i<p;i++) fa[i]=i,s[i]-=s[n-i+1],c[i]=s[i]-s[i-1];
    fa[p]=p,c[p]=-s[p-1];
    while(m--) {
	int l=gi(),r=gi(),t=1;
	if(n&1) {
	    if(l==p&&r==p) continue;
	    if(l==p) ++l;
	    if(r==p) --r;
	}
	if(l<p&&r>=p) r=n-r+1,t=0;
	else if(l>=p) l=n-l+1,r=n-r+1;
	if(l>r) swap(l,r);
	fa[find(l)]=find(r+t);
    }
    for(int i=1;i<=p;i++) v[find(i)]+=c[i];
    for(int i=1;i<=p;i++)
	if(i==find(i)&&v[i]%26) return puts("NO"),0;
    puts("YES");
    return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

int main() {
    int N,M;
    cin >> N >> M;
    vector<pair<int,int>>v(M); // first = b, second = a

    rep(i,M){
        cin >> v[i].second >> v[i].first;
    }
    int distruct=0;
    int ans=0;
    sort(v.begin(), v.end());
    rep(i,M){
        if( !(v[i].second<=distruct && distruct<v[i].first) ){
            ans++;
            distruct=v[i].first-1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(input())
left = [[0 for i in range(W)] for j in range(H)]
right = [[0 for i in range(W)] for j in range(H)]
down = [[0 for i in range(W)] for j in range(H)]
up = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    cnt = 0
    for j in range(W):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
        left[i][j] = cnt

for i in range(H):
    cnt = 0
    for j in range(W)[::-1]:
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
        right[i][j] = cnt

for j in range(W):
    cnt = 0
    for i in range(H):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
        down[i][j] = cnt
    
for j in range(W):
    cnt = 0
    for i in range(H)[::-1]:
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
        up[i][j] = cnt

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        ans = max(ans, left[i][j] + right[i][j] + down[i][j] + up[i][j] -3)

print(ans)

Measured memory_bytes: 184324
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main() {
    ll n;cin>>n;
    vector<ll> v;
    ll cnt = 1;
    while(n > 0){
        v.push_back(cnt);
        n-=cnt;
        cnt++;
    }
    rep(i,v.size()){
        if(v[i]==abs(n))continue;
        cout << v[i] << endl;
    }
}



Measured memory_bytes: 384
#include <stdio.h>

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

Measured memory_bytes: 128
(N, M, C) = tuple(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
  A = list(map(int, input().split()))
  sum = 0
  for j in range(M):
    sum += B[j] * A[j]
  sum += C
  if sum > 0:
    ans += 1
print(ans)

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

int main () {
  int N;
  cin >> N;

  if (N >= 30) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

char arr[1005][1005];
int dis[1005][1005];

bool legal(int x, int y){
    if(x < 1 || y < 1 || arr[x][y] == '#') return 0;
    return 1;
}

int main()
{
    int i = 0, j = 0, cs = 0, in;
    int h, w; cin>>h>>w;
    int sy, sx; cin>>sy>>sx;
    int ey, ex; cin>>ey>>ex;
    for(i = 1; i <= h; i++){
        getchar();
        for(j = 1; j <= w; j++) cin>>arr[i][j];
    }
    int inf = (1<<28);
    for(i = 1; i <= h; i++)
        for(j = 1; j <= w; j++)
            dis[i][j] = inf;
    dis[sy][sx] = 0;
    deque<ii> q; q.pb({sy,sx});
    int dx[] = {-1,1,0,0};
    int dy[] = {0,0,-1,1};
    while(!q.empty()){
        int cury = q.front().ff, curx = q.front().ss;
        q.pop_front();
        for(i = 0; i < 4; i++){
            int ny = cury + dy[i], nx = curx + dx[i];
            if(!legal(ny,nx)) continue;
            if(dis[ny][nx] > dis[cury][curx]){
                dis[ny][nx] = dis[cury][curx];
                q.push_front({ny,nx});
            }
        }
        for(i = -2; i <= 2; i++){
            for(j = -2; j <= 2; j++){
                int ny = cury + i, nx = curx + j;
                if(!legal(ny,nx)) continue;
                if(dis[ny][nx] > dis[cury][curx]+1){
                    dis[ny][nx] = dis[cury][curx]+1;
                    q.push_back({ny,nx});
                }
            }
        }
    }
    if(dis[ey][ex] == inf) cout << -1 << endl;
    else cout << dis[ey][ex] << endl;
    return 0;
}


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

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

int main() {
    int n;
    int a[101000];
    int ans;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    for (int i = 0; i < n; i++) {
        ans = ((i == 0) ? a[i] : gcd(ans, a[i]));
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    }
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}

int main(){
    int Q;
    cin >> Q;
    sieve(100005);
    int l[Q], r[Q];
    int ans[100005];
    ans[0] = 0; ans[1] = 0; ans[2] = 0; ans[3] = 1;
    REP(i,4, 100005){
        ans[i] = ans[i-1];
        if (i >= 3 && IsPrime[i] && IsPrime[(i+1)/2]) {
            ans[i]++;
        }
  
    }
    rep(i, Q){
        cin >> l[i] >> r[i];

        cout << ans[r[i]] - ans[l[i]-1] << endl;

    }


}

Measured memory_bytes: 1792
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#define rep(i,n) for(int i = 0;i<(int)(n);i++);
using namespace std;
using ll = long long;
const ll INF = 100100100100100;

int main() {
	ll N, K;
	cin >> N >> K;//左から k個
	ll AMAX = 100001;
	vector<ll> cnt(AMAX);
	ll a = 0, b = 0;
	for (int i = 0; i < N; i++) {
		cin >> a >> b;
		cnt[a] += b;
	}
	for (int i = 1; i <= AMAX; i++) {
		if (K <= cnt[i]) {
			cout << i << endl;
			break;
		}
		K -= cnt[i];
	}
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Pair[] score = new Pair[n];
        for(int i=0;i<n;i++){
            score[i] = new Pair(sc.next(),Integer.parseInt(sc.next()),i+1);
        }

        Arrays.sort(score,new Comparator<Pair>() {

            @Override
            public int compare(Pair o1, Pair o2) {
                if(o1.key.compareTo(o2.key)==0){
                    return o2.val-o1.val;
                }else{
                    return o1.key.compareTo(o2.key);
                }
            }
        });
        for(int i=0;i<n;i++){
            System.out.println(score[i].num);
        }
    }
}
class Pair{
    String key;
    int val;
    int num;
    Pair(String key,int val,int num){
        this.key = key;
        this.val = val;
        this.num = num;
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,Q;
    cin>>N>>Q;
    dsu d(N);
    rep(i,Q){
        int t,u,v;
        cin>>t>>u>>v;
        if(t==0){
            d.merge(u,v);
        }else{
            cout<<d.same(u,v)<<endl;
        }

    }
    return 0;
}


Measured memory_bytes: 3912
using System;

namespace A___Beginner
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var n = int.Parse (input[0]);
            var r = int.Parse (input[1]);
            if (n >= 10)
                Console.WriteLine (r);

            else
                Console.WriteLine (r + 100 * (10 - n));
        }
    }
}

Measured memory_bytes: 13140
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
N = str(N)

if N[-1] in ['2', '4', '5', '7', '9']:
    print('hon')
elif N[-1] in ['0', '1', '6', '8']:
    print('pon')
else:
    print('bon')

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

int main(){
    int N,max=0;
    long long sum=0;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A.at(i);
        if(A.at(i)>max){
            max=A.at(i);
        }
        if(A.at(i)<max){
            sum+=(max-A.at(i));
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 4000
ABC = list(map(int, input().split()))

ABC.sort()

count = ABC[2] - ABC[1]

ABC[0] += count
ABC[1] += count

#ここまでで a, C, cとなっているはず

if (ABC[2] - ABC[0]) % 2 == 0:
    count += (ABC[2] - ABC[0]) // 2
else:
    count += ((ABC[2] - ABC[0]) + 1) // 2 + 1

print (count)

Measured memory_bytes: 3064
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
  int n,x;
  std::cin >> n >> x;
  int count = 0;
  int current = 0;
  rep(i,n) {
    int l;
    std::cin >> l;
    if(current<=x) count++;
    current+=l;
  }
  if(current<=x) count++;

  print(count);
  return 0;
}

Measured memory_bytes: 256
#ABC178b
a, b, c, d = map(int, input().split())

ans = 0

if a>=0:
    if d>=0:
        ans = b*d
    else:
        ans = a*d

elif a<=0 and b>=0:
    if c>=0:
        ans = b*d
    elif c<=0 and d>=0:
        if (c*a)>=(d*b):
            ans = c*a
        else:
            ans = d*b
    else:
        ans = a*c

else:
    if c>=0:
        ans = b*c
    else:
        ans = a*c

print(ans)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll v[500][50],v2[500][50];
char s[100][8];
int main()
{
    ll n,m,k,i,j,l,ans=0,K,x=1,y=1,r,d;
    scanf("%lld %lld %lld",&l,&r,&d);
   for(i=d;i<=r;i+=d)
   {
       if(i>=l&&i<=r)
       {
           ans++;
       }
   }
   printf("%lld\n",ans);



    return 0;

}


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

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

    if(n % 2 == 0){
        cout << 0.50000 << endl;
    } else if (n == 1) {
        cout << 1.00000 << endl;
    } else {
        double a = (n - 1)/2;
        double b = n - a;
        cout << b / n << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] h = new int[n];
        boolean[] bool = new boolean[n];
        for (int i=0;i<n;i++){
            h[i]=sc.nextInt();
            bool[i]=true;
        }
        for (int i=0;i<m;i++){
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            if (h[a]>h[b]){
                bool[b]=false;
            }else if (h[a]<h[b]){
                bool[a]=false;
            }else {
                bool[a]=false;
                bool[b]=false;
            }
        }
        int ans=0;
        for (int i=0;i<n;i++)if (bool[i])ans++;
        System.out.println(ans);
    }
}


Measured memory_bytes: 59672
S = list(input())
n = len(S)
c = 0
if n%2 ==1:
    print("No")
else:
    for i in range(n-1):
        if S[i] == "h" and S[i+1] == "i":
            c = c+1
    if c == int(n/2):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
N = int(input())
p = [None] * N

for i in range(N):
    x, y = map(int, input().split())
    p[i] = (x, y)

ans = 0
for i in range(N):
    for j in range(N):
        d = pow((p[i][0] - p[j][0])**2 + (p[i][1] - p[j][1])**2, 1/2)
        ans += d / N

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
 
long long pow_ll(long long a, int n)  {
  long long p = 1;
  for(int i=0; i<n; i++) {
    p *= a;
  }
  return p;
}
 
long long ord2(long long num) {
  long long ord = 0;
  while(num != 0) {
    num /=  2;
    ord++;
  }
  return ord;
}
 
int main() {
  long long N, K;
  cin >> N >> K;
 
  vector<long long> A(N,0);
  vector<long long> V(40,0);
 
  for(int n=0; n<N; n++) {
    cin >> A[n];
    for(long long i=0; i<40; i++) {
      if (A[n] & ((long long)1<<i)) {
        V[i]++;
      }
    }
  }
  
  /* 最適なXを発見 */
  int i = 0;
  long long X = 0;
  for(int i=39; i>=0; i--) {
    if(V[i]>=N-V[i]) {
       continue;
    }
    
    long long X_tmp = X | ((long long)1<<i);
    
    if(X_tmp<=K) {
      X = X_tmp;
    }
    
  }
  
  
  long long sum = 0;
  for(auto a:A) {
    sum += a ^ X;
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

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

using namespace std;

int main() {
    string s; cin >> s;
    int len = s.length();

    int ans0 = 0;
    int ans1 = 0;

    // ans0
    for (int i = 0; i < len; i=i+2)
    {
        if (s.at(i) != '0')
        {
            ans0++;
        }
        
    }
    if (len > 1)
    {
        for (int i = 1; i < len; i=i+2)
        {
            if (s.at(i) != '1')
            {
                ans0++;
            }
            
        }
    }

    // ans1
    for (int i = 0; i < len; i=i+2)
    {
        if (s.at(i) != '1')
        {
            ans1++;
        }
        
    }
    if (len > 1)
    {
        for (int i = 1; i < len; i=i+2)
        {
            if (s.at(i) != '0')
            {
                ans1++;
            }
            
        }
    }
    
    //cout << ans0 << endl;
    //cout << ans1 << endl;
    cout << min(ans0, ans1) << endl;



}


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

int main() {
   int N;
   cin >> N;
   vector<int> A(N);
   vector<vector<int>> X(N);
   vector<vector<int>> Y(N);
   for (int i=0; i<N; i++) {
       cin >> A.at(i);
       for (int j=0; j<A.at(i); j++) {
           int x,y;
           cin >> x >> y;
           X.at(i).push_back(x);
           Y.at(i).push_back(y);
       }
   }
   int total=0;
   for (int tmp=0; tmp<(1<<15); tmp++) {
       bitset<15> s(tmp);
       bool finished=false;
       for (int i=0; i<N; i++) {
           if (s.test(i)) {
               for (int j=0; j<A.at(i); j++) {
                   if (s.test(X.at(i).at(j)-1)!=Y.at(i).at(j)) {
                       finished=true;break;
                   }
               }
           }
           if (finished) break;
           if (i==N-1) {
               int count=0;
               for (int j=0; j<N; j++) {
                   if (s.test(j)) count++;
               }
               if (total<count) total=count;
           }
       }
   }
   cout << total << endl;
}

Measured memory_bytes: 256
s = gets.chomp.split("").map(&:to_s)
n = s.length
a = s[0..((n - 1) / 2 - 1)]
b = s[((n + 3) / 2 - 1)..(n - 1)]

def same(x)
  x == x.reverse
end

puts same(s) && same(a) && same(b) ? "Yes" : "No"

Measured memory_bytes: 3836