akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

// dijkstra(O((E+V)log(v)))
template<class T>
struct dijkstra {
    struct edge{int to, cost;};
    vector<T> d;
    vector<vector<edge>> G;
    T init_v;

    dijkstra(int n, T init_v): init_v(init_v) {init(n);} 

    void init(int n) {
        G.resize(n);
        d.resize(n);
        rep(i,n) d[i] = init_v;
    }

    void add_edge(int s, int t, int cost) {
        edge e;
        e.to = t; e.cost = cost;
        G[s].push_back(e);
    }

    void run(int s) {
        priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q;
        d[s] = 0;
        q.push(pair<T,int>(0,s));
        while (!q.empty()) {
            pair<T,int> e = q.top(); q.pop();
            int v = e.second;
            if (d[v] < e.first) continue;
            for (auto e: G[v]) {
                if (chmin(d[e.to],d[v]+e.cost)) {
                    q.push(pair<T,int>(d[e.to],e.to));
                }
            }
        }
    }
};

int main() {
    int n, m; cin >> n >> m;
    int s, t; cin >> s >> t;
    s--; t--;
    dijkstra<ll> dj_s(n,inf_l), dj_t(n,inf_l);
    rep(i,m) {
        int u, v, a, b; 
        cin >> u >> v >> a >> b;
        u--; v--;
        dj_s.add_edge(u,v,a);
        dj_s.add_edge(v,u,a);
        dj_t.add_edge(u,v,b);
        dj_t.add_edge(v,u,b);
    }
    dj_s.run(s); dj_t.run(t);
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> cost;
    rep(i,n) cost.push(make_pair(dj_s.d[i]+dj_t.d[i],i+1));
    ll init_v = 1e15;
    rep(i,n) {
        auto p = cost.top();
        if (i < p.second) cout << init_v - p.first << endl;
        else {
            while (i >= p.second) {
                cost.pop();
                p = cost.top();
            }
            cout << init_v - p.first << endl;
        }
    }
}

Measured memory_bytes: 19844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ll n, k;    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n)   cin >> a[i];
    vector<ll> dp(n, LINF);
    dp[0] = 0;
    REP(i, n){
        FOR(j, 1, k+1){
            if(i+j<n)
                dp[j+i] = min(dp[i]+abs(a[i]-a[i+j]), dp[j+i]);
        }

    }
    cout << dp.back() << endl;
    
}


Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast


        
    int a,b,c;
    cin>>a>>b>>c;


    int gcd = __gcd(a,b);

    vi v;

    int i = 1;
    for(; i*i < gcd; i++)
    {
        if(gcd%i == 0)
        {
            v.pb(i);
            v.pb(gcd/i);
        }
    }

    if(i*i == gcd) v.pb(i);

    sort(all(v));


    cout<<v[v.sze-c];




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#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++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;
  cin>>a>>b;
  a--;
  int res=1;
  while(b>res)res+=a;
  cout<<(res-1)/(a)<<endl;
  return 0;

}


Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

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


int main(){
  ll n; cin >> n; vector<string> gacha(n);
  
  rep(i,n) cin >> gacha[i];
  
  sort(all(gacha));
  
  ll cnt = 1;
  
  for(ll i=0; i < n-1; i++){
    if(gacha[i] != gacha[i+1]) cnt++;
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 9648
//Author: Rahul Purohit

#include<bits/stdc++.h>
#define vi vector<int>
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define ll  long long int
#define pi pair<ll,ll>
#define f first
#define mp make_pair
#define mod 1000000007
#define s second
#define pb push_back
#define mp make_pair
#define N 100001
using namespace std;
int gcd(int a, int b)
{
	if(b==0)
		return a;
	else
		return (b,a%b);
}
/*ll isp[N]={1};
void sieve(int n)
{
	isp[0]=isp[1]=0;
	for(int i=2;i<=n;i++)
	{
		if(isp[i]==1)
		{
			for(int j=i*i;j<=n;j+=i)
			{
				isp[j]==0;
			}
		}
	}
}*/
ll pow(int x,int  y,int m)
{
	ll ans=1;
	while(y!=0)
	{
		if(y%2==1)
		{
			ans=(ans*x)%m;
		}
		x=(x*x)%m;
		y/=2;
	}
	return ans;
}
template <class x>
void swap(x &a,x &b)
{
	x tp;
	tp=a;
	a=b;
	b=tp;
}
template <class x>
void max(x &a,x &b)
{
	return (a>=b?a:b);
}
template <class x>
void min(x &a,x &b)
{
	return (a>=b?b:a);
}
int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll n;
	cin>>n;
	double a,res=0;
	string b;
	rep(i,0,n)
	{
		cin>>a>>b;
		if(b=="BTC")
		{
			res+=(a*380000.0);
		}
		else
		{
			res+=a;
		}
	}
	cout<<fixed<<res<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  

  int n, a, b;
  cin>>n>>a>>b;
  int rem  = ((a % 2) != (b % 2));
  if (rem % 2 == 1) {
    cout<<"Borys\n";
  } else {
    cout<<"Alice\n";
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


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

int main() {
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;

  if (((b-a)<=k)&&((c-a)<=k)&&((d-a)<=k)&&((e-a)<=k)&&((c-b)<=k)&&((d-b)<=k)&&((e-b)<=k)&&((d-c)<=k)&&((e-c)<=k)&&((e-d)<=k))
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
}


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

vector<string> ans;

void solve(int N,string S,char mx){
	if(N==0)ans.push_back(S);
	else {
		for(char c='a';c<=mx;c++){
			if(c!=mx)solve(N-1,S+c,mx);
			else solve(N-1,S+c,mx+1);
		}
	}
}


signed main(){
	int N; cin>>N;
	solve(N,"",'a');
	sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 7796
#include<stdio.h>

int main(){
  int n;
  char p, dummy;
  int input;
  int arr[4][13];
  int i, j;

  // array initialization
  for(i = 0; i < 4; i++){
    for(j = 0; j < 13; j++){
      arr[i][j] = 0;
    }
  }

  // array input
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%c", &dummy);
    scanf("%c %d", &p, &input);
    switch(p){
      case 'S':
	arr[0][input - 1] = 1;
	break;
      case 'H':
	arr[1][input - 1] = 1;
	break;
      case 'C':
	arr[2][input - 1] = 1;
	break;
      case 'D':
	arr[3][input - 1] = 1;
	break;
    }
  }

  // output
  for(i = 0; i < 4; i++){
    for(j = 0; j < 13; j++){
      if(arr[i][j] == 0){
        switch(i){
          case 0:
            printf("S %d\n", j + 1);
            break;
          case 1:
            printf("H %d\n", j + 1);
            break;
          case 2:
            printf("C %d\n", j + 1);
            break;
          case 3:
            printf("D %d\n", j + 1);
            break;
        }
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 2088
#include"bits/stdc++.h"
using namespace std;

int main(){
  int n, i, s, ans, max=0, second;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);

  for(i=0; i<n; i++){
    cin >> a[i];
    if(max<a[i]) max=a[i];
    b[i]=a[i];
  }

  sort(b.begin(), b.end());
  second = b[n-2];

  if(max==second){
    for(i=0; i<n; i++) cout << max << endl;
  }else{
    for(i=0; i<n; i++){
      if(a[i]==max) ans=second;
      else ans=max;
      cout << ans << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3200
s = str(input())
n = int(input())
for i in range(n):
    cmd = list(map(str, input().split()))
    a = int(cmd[1])
    b = int(cmd[2])
    if cmd[0] == "print":
        print(s[a:b+1])
    elif cmd[0] == "reverse":
        tmp = s[a:b+1]
        s = s[:a] + tmp[::-1] + s[b+1:]
    elif cmd[0] == "replace":
        s = s[:a] + cmd[3] + s[b+1:]




Measured memory_bytes: 5608
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

short dp[2][1 << 20];
template<int SZ> int solve(int n, int m){
	if(SZ / 2 >= m) return solve<SZ / 2>(n, m);
	
	int ans = 0;
	vector<bitset<SZ>> b(n);
	
	rep(i, n){
		string s; cin >> s;
		rep(j, m) if(s[j] == '1') b[i][j] = 1;
	}
	rep(mask, 1 << n){
		bitset<SZ> sum;
		rep(i, n) if(mask & 1 << i) sum ^= b[i];
		if(sum.none()) ans = max(ans, __builtin_popcount(mask));
	}
	return ans;
};
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, m;
	while(cin >> n >> m, n){
		if(m > 20){
			cout << solve<512>(n, m) << endl;
		}
		else{
			memset(dp, -1, sizeof(dp));
			vi b(n);
			rep(i, n){
				string s; cin >> s;
				rep(j, m) if(s[j] == '1') b[i] |= 1 << j;
			}
			
			dp[0][0] = 0;
			int cur = 0, next = 1;
			rep(i, n){
				memcpy(dp[next], dp[cur], sizeof(dp[cur]));
				rep(j, 1 << m) if(dp[cur][j] >= 0){
					dp[next][j ^ b[i]] = max(dp[next][j ^ b[i]], (short)(dp[cur][j] + 1));
					//dp[next][j] = max(dp[next][j], dp[cur][j]);
				}
				swap(cur, next);
			}
			cout << dp[cur][0] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 7208
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

std::vector<int> primes;
bool isPrime[1000000 + 1];

void initPrimes(){
    std::fill(isPrime, isPrime+1000000+1, true);

    isPrime[0] = false;
    isPrime[1] = false;
    for(int i=4;i<=1000000;i+=2){isPrime[i] = false;}
    
    primes.push_back(2);

    for(int i=3;i<=1000000;i+=2){
        if(isPrime[i]){
            primes.push_back(i);
            for(int j=2*i;j<=1000000;j+=i){
                isPrime[j] = false;
            }
        }
    }
}

int main(){
    initPrimes();

    int N;
    while(std::cin >> N, N){
        int res = 0;
        REP(i, N){
            int P, M;
            std::cin >> P >> M;
            res += std::upper_bound(primes.begin(), primes.end(), P+M)
                - std::lower_bound(primes.begin(), primes.end(), P-M) - 1;
        }

        std::cout << res << std::endl;
    }
}

Measured memory_bytes: 2568
#include <iostream>
#include <vector>
#include <map>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  vector<int> p(n), q(n);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];
  vector<int> a(n);
  rep(i,n) a[i] = i+1;

  map<vector<int>, int> mp;
  do {
    mp[a] = mp.size();
  }while(next_permutation(a.begin(), a.end()));
  cout << abs(mp[p] - mp[q]) << endl;
  return 0;
}


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

int main()
{
    string s,t;
    cin >> s >> t;

    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());

    int flag = 0,cnt = 0;
    int sl = s.length(),tl = t.length();
    for(int i = 0; i < min(sl,tl); i++){
        if(s[i] < t[i]) flag = 1;
        if(s[i] == t[i]) cnt++;
    }
    if(cnt == min(sl,tl) && sl < tl)flag = 1;
    
    cout << (flag == 1 ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
s = input()
a, b = '', ''
for i in range(len(s)):
    if s[i] != 'x':
        a += s[i]
        b = s[i] + b
if a != b:
    print(-1)
    sys.exit()
ans = 0
while len(s) != 0:
    if s[0] == s[-1]:
        s = s[1:-1]
    elif s[0] == 'x' and s[-1] == 'x':
        if len(s) == 1:
            s = ''
        else:
            s = s[1:-1]
    elif s[0] == 'x':
        s = s[1:]
        ans += 1
    elif s[-1] == 'x':
        s = s[:-1]
        ans += 1
print(ans)

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

int main() {
	int N;
	cin>>N;
	vector<tuple<string,int,int>> vec(N);
	
	for(int i=0; i<N; i++){
		string a;
		int b;
		cin>>a;
		cin>>b;
		vec.at(i)=make_tuple(a,-b,i+1);
	}
	sort(vec.begin(), vec.end());

	
	for(auto x:vec){
		cout << get<2>(x) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll                 long long
#define ull                unsigned long long
#define ld                 long double
#define fastio             ios_base::sync_with_stdio(false);cin.tie(NULL);
#define NO                 cout << "NO" << endl
#define YES                cout << "YES" << endl
#define vec                vector<ll>
#define pi                 pair<ll, ll>
#define intarr(arr, n)     ll arr[n]; for (ll i = 0; i < n; i++) cin >> arr[i]
#define intvec(v, n)       for (ll i = 0; i < n; i++) { ll x;cin >> x; v.pb(x);}
#define loop(i, a, b, c)   for (ll i = a; i < b; i += c)
#define pb                 push_back
#define mkp                make_pair
#define printarr(a, n, m)  for (ll i = n; i < m; i++) {  cout << a[i] << " "; }  cout << endl
#define printvec(a, n, m)  for (ll i = n; i < m; i++) {   cout << a[i] << " ";   } cout << endl
#define endl               "\n"
#define mod2               998244353
#define mod                1000000007
#define mem(dp, a)         memset(dp, a, sizeof(dp));
#define all(v)             v.begin(), v.end()
#define ump                unordered_map<ll, ll>
#define pair               pair<ll, ll>
#define F                  first
#define S                  second
#define PI                 3.14159265358979323846
#define minh               priority_queue<ll>
#define maxh               priority_queue<ll,vector<ll>,greater<ll>>
#define flush              cout<<flush


ll Ceil(ll a, ll b)
{
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}

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

ll inv(ll a)
{
  ll p = mod;
  ll b = p - 2, ans = 1;
  for (; b > 0; a = a * a % p, b >>= 1)
    if (b & 1)
      ans = ans * a % p;
  return ans;
}

ll ncrmod(ll n, ll m)
{
  ll p = mod;
  if (m > n)
    return 0;
  ll up = 1, down = 1;
  for (ll i = n - m + 1; i < n + 1; i++)
    up *= i, up %= p;
  for (ll i = 1; i < m + 1; i++)
    down *= i, down %= p;
  return up * inv(down) % p;
}

ll powmod(ll a, ll n)
{
  if (!n)
    return 1;
  ll pt = powmod(a, n / 2);
  pt *= pt, pt %= mod;
  if (n & 1)
    pt *= a, pt %= mod;
  return pt;
}

bool SieveOfEratosthenes(ll n)
{
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));

  for (ll p = 2; p * p <= n; p++)
  {
    if (prime[p] == true)
    {
      for (ll i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }
  return prime[n];
  // for (int p=2; p<=n; p++)
  //    if (prime[p])
  //       cout << p << " ";
}

void solve()
{
   ll k;
   cin>>k;
   string s;
   cin>>s;
   string s2="";
   if(s.length()<=k) cout<<s;
   else{
    s2+=s.substr(0,k);
    s2+="...";
    cout<<s2;
   }
}


int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  fastio;
  ll t;
  t = 1;
  //cin >> t;
  while (t--)
  {
    solve();
  }

  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

  return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; string S; cin >> N >> S;
    vector<vector<int>> dp(N + 1, vector<int>(N + 1, 0));

    int ans = 0;
    // for (int i = N - 1; i >= 0; i--) {
    //     for (int j = N - 1; j > i; j--) {
    //         if (S[i] == S[j]) {
    //             dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1);
    //             ans = max(ans, min(dp[i][j], j - i));
    //         }
    //     }
    // }
    REP(i, 0, N) {
        REP(j, i + 1, N) {
            if (S[i] == S[j]) {
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
                ans = max(ans, min(dp[i + 1][j + 1], j - i));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  int N;
  cin>>N;
  vector<int> A(N+1);
  for(int i=1; i<=N; i++)
    cin>>A[i];

  int count = 0;
  int b = 1;
  while(1){
    if(b==2){
      cout<<count<<endl;
      return 0;
    }
    b = A[b];
    count++;
    if(count >= N+1)  break;
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		for(int i  = 1; i < 1000; i++) {
			for(int j = -1000; j < 1000; j++) {
				long a = (long) Math.pow(i, 5);
				long b = (long) Math.pow(j, 5);
				if(a-b == x) {
					System.out.println(i+" "+j);
					return;
				}
			}
		}
	}
}

Measured memory_bytes: 38784
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] nums = new int[N];
		for(int a = 0 ; a < N ; a++){
			nums[a] = sc.nextInt();
		}
		sc.close();
		int ans = 0;
		Arrays.sort(nums);
		ans = Math.abs(nums[nums.length-1])-Math.abs(nums[0]);
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

int main()
{
    long long n, k, q, d;
    long long ans;
    ans = 0;
    cin >> n >> k;
    if(k == 0){
        ans = n * n;
    }
    else {
        for (int i=k+1; i<=n; ++i){
            q = n / i;
            d = n % i;
            ans += q * (i - k) + (d >= k ? d - k + 1 : 0);
            //cout << i << " @ " << q << " : " << ans << endl;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	int i;
	int s = 0;
	for (i = 1; ; i++)
	{
		s += (a + (i % 7 ? 0 : b));
		if (s >= c)
		{
			break;
		}
	}

	cout << i << endl;
}


Measured memory_bytes: 3100
def f(s)
    return s == 'ABC' if s.size <= 3
    x = s.gsub('ABC', 'X')
    return false if x !~ /X/
    a = %w(A B C)
    a.delete(?A) if x =~ /A/
    a.delete(?B) if x =~ /B/
    a.delete(?C) if x =~ /C/
    return a.any? {|c| f(x.gsub(?X, c))}
end

s = gets.chomp
puts f(s) ? 'Yes' : 'No'



Measured memory_bytes: 27480
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1L<<32;
ll fac[MAX], finv[MAX], inv[MAX];
//ワーシャルフロイド法、o(v^3)
int main(){
  ll v,e;cin>>v>>e;
  vvll g(v,vll(v,MOD));
  rep(i,0,e){
    ll s,t,d;cin>>s>>t>>d;
    g[s][t]=d;
  }
  rep(i,0,v){g[i][i]=0;}
  bool ok=true;
  rep(k,0,v){
    rep(i,0,v){
      if(g[i][k]==MOD)continue;
      rep(j,0,v){
        if(g[k][j]==MOD)continue;
        g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
      }
      if(g[i][i]<0)ok=false;//負の閉回路の検出
    }
  }
  if(!ok){
    out("NEGATIVE CYCLE");
  }
  else{
      rep(i,0,v){
    rep(j,0,v){
    
      if(g[i][j]!=MOD){cout<<g[i][j];}
      else{cout<<"INF";}
      if(j!=v-1){cout<<" ";}
    }
    cout<<endl;
  }
  }
  
  
}





Measured memory_bytes: 3224
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

ll n;

inline bool ok(ll x)
{
	ll tmp=n;
	while(tmp && tmp%x==0) tmp/=x;
	return tmp%x==1;
}

int main(void)
{
	scanf("%lld",&n);
	
	ll ans=0;
	for(int i=1; (ll)i*i<=n; ++i)
		if(n%i==0)
		{
			if(i>1) ans += ok(i);
			if((ll)i*i!=n) ans += ok(n/i);
		}
	
	--n;
	for(int i=1; (ll)i*i<=n; ++i)
		if(n%i==0)
		{
			if(i>1) ++ans;
			if((ll)i*i!=n) ++ans;
		}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
// constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    int minv = a[0];
    LL sum = 0;
    REP(i,1,n) {
        if (minv <= a[i]) {
            minv = a[i];
            continue;
        }
        sum += minv - a[i];
        // dump(sum);
    }
    cout << sum << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 4844
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 22:30:26 2020

@author: shinba
"""

from operator import itemgetter

N = int(input())

data = {}

for i in range(N):
    string = input()
    if string in data:
        data[string] += 1
    else:
        data[string] = 1

s = sorted(data.items(),key=itemgetter(1),reverse = True)

M = s[0][1]

ans = [s[0][0]]
for i in range(1,len(s)):
    if s[i][1] == M:
        ans.append(s[i][0])
    else:
        break

ans.sort()

for i in ans:
    print(i)
        

Measured memory_bytes: 45788
#include "bits/stdc++.h"

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define en '\n'
#define pb push_back
#define P pair<int, int>

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;

struct aaa {
	aaa() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
}aaaaa;

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

	s[k - 1] = tolower(s[k - 1]);

	cout << s << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,r[1000000];
  int i,max,min;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&r[i]);

  max=r[1]-r[0];
  min=r[0];

  for(i=1;i<n;i++){
    if(max<r[i]-min)max=r[i]-min;
    if(min>r[i])min=r[i];
  }

  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 2644
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;


int main(int argc, const char * argv[]) {


    int n, ans;
    string s;
    
    cin >> n >> s;
    
    ans = n;
    
    for(int i=0; i<n-1; i++)
    {
        if (s[i] == s[i+1]) ans--;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 512
n,r = map(int,input().split())

while n!=0 and r!=0:
	card = list(range(1,n+1))[::-1]
	for _ in range(r):
		p,c = map(int,input().split())
		pcard = card[0:p-1]
		ccard = card[p-1:p-1+c]
		tmp = card[p-1+c:]
		nxt = []
		nxt.extend(ccard)
		nxt.extend(pcard)
		nxt.extend(tmp)
		card = nxt
	print(card[0])
	n,r = map(int,input().split())

Measured memory_bytes: 7676
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int P[200000];
ll G[200000];

int main()
{
	int N, ans = 0, minP;

	cin >> N;
	rep(i, N) cin >> P[i];

	rep(i, N) {
		if (i == 0) {
			minP = P[i];
			ans++;
		}
		else {
			if (minP >= P[i]) ans++;
			minP = min(minP, P[i]);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int q;
    cin >> q;

    bool prime[100100];
    rep(i, 100100) prime[i] = true;
    prime[0] = false;
    prime[1] = false;
    for(int i = 2; i <= 100010; i++){
        if(prime[i]){
            for(int j = 2; i * j <= 100010; j++){
                prime[i * j] = false;
            }
        }
    }

    vector<ll> sum(100010, 0);
    for(int i = 1; i <= 100000; i++){
        if(prime[i] && prime[(i + 1) / 2]){
            sum[i] = sum[i - 1] + 1;
        } else {
            sum[i] = sum[i - 1];
        }
    }

    rep(i, q){
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l - 1] << endl;
    }
} 

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--)
using namespace std;
int dp[10001][101][2],d;
string str;
int rec(int i,int s,int e){
	if(s < 0)
		return 0;
	if(i == str.size()){
		if(s==0)
		return 1;
		return 0;
	}
	if(dp[i][s][e]!=-1)
		return dp[i][s][e];
	int ways = 0;
	if(e){
		for(int j=0;j<=str[i]-'0';j++){
			if(j != str[i]-'0'){
				ways += rec(i+1,(s+j)%d,0);
			}
			else
				ways += rec(i+1,(s+j)%d,1);
			ways %= MOD;
		}
	}
	else{
		for(int j=0;j<=9;j++){
			ways += rec(i+1,(s+j)%d,0);
		}
		ways %= MOD;
	}
	dp[i][s][e] = ways;
	return ways;
}
int32_t main(){

	
	FASTIO;
	mem(dp,-1);
	//string str;
	cin >> str >> d;
	cout << (rec(0,0,1)-1+MOD)%MOD << endl;
    return 0;

}

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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	
	int a, b, c;
	cin >> a >> b >> c;

	if (c >= a && c <= b)
		cout << "Yes\n";
	else
		cout << "No\n";
    return 0;
}


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

using ll = long long;
using pii = pair<int, int>;

#define     endl               "\n"
#define     fast_io            ios::sync_with_stdio(false); cin.tie(0);
#define     all(x)             begin(x), end(x)
#define     debug(x)           cerr <<"Line "<< __LINE__ <<" : "<< #x " = "<< x <<endl;
 
template<typename T, typename TT>
ostream& operator<<(ostream &os, const pair<T, TT> &t) { return os<<"("<<t.first<<", "<<t.second<<")"; }
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &t) { for(auto& i: t) os<<i<<" "; return os; }
 
 
 
 


int main(int argc, char** argv) {
    fast_io
   
    int n;
    cin >> n;
    
    bool flag = true;
    for(int i = 0, a ; i < n; ++i) {
	cin >> a;
	if(!(a&1) && (a%3 && a%5)) flag = false;
    }
    
    cout << (flag ? "APPROVED\n" : "DENIED");
    

    return 0;
}






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

using namespace std;

int main() {
	int N;
	cin >> N ;
	
	vector<int> H(N,0);
	vector<int> max(N,0);
	int ans = 0;
	
	for (int i = 0; i < N; i++) {
		cin >> H.at(i);
		if (i > 0){
			if (H.at(i) > max.at(i-1)) {
	//			cout << "dbg koushin" << endl;
				max.at(i) = H.at(i);
			} else {
				max.at(i) = max.at(i - 1);
	//			cout << "dbg low" << endl;
			}
			
		} else {
			max.at(i) = H.at(i);
		}
		if(max.at(i) == H.at(i)) {
			ans++;
	//		cout << "dbg " << i << ", " << H.at(i) << endl;
		}
		
	//	cout << "dbg2 " << H.at(i) << ", " << max.at(i) << endl;
		
	}
	
	cout << ans << endl;
	
	



	return 0;
}


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

using namespace std;

pair <int,int> p[1003];
int main()
{
  int n;
  cin >> n;
  for(int i=0 ; i<n ; i++)
    scanf("%d%d" , &p[i].first , &p[i].second);
  sort(p , p+n);
  int res = p[0].second - p[0].first + 1;
  for(int i=1 ; i<n ; i++)
  {
    if(p[i].first <= p[i-1].second && p[i].second <= p[i-1].second)
    {
      p[i].second = p[i-1].second;
      continue;
    }
    if(p[i].first <= p[i-1].second)
      res += p[i].second - p[i-1].second + 1;
    else
      res += p[i].second - p[i].first + 1;
  }
  printf("%d" , res);
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        while (true){
            String line = br.readLine();
            String[] ln = line.split(" ");
            int H = Integer.parseInt(ln[0]);
            int W = Integer.parseInt(ln[1]);
            if (H==0 && W==0) break;
            for (int j=0; j<H; j++){
                if (j==0|j==H-1){
                    for (int i=0; i<W; i++){
                        sb.append("#");
                    }
                }else{
                    for (int i=0; i<W; i++){
                        if (i==0|i==W-1){
                            sb.append("#");
                        }else{
                            sb.append(".");
                        }
                    }
                }
                sb.append("\n");
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }
}

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

int N;
double p[3000],dp[3000][3000],ans;
int main()
{
    scanf("%d",&N);
    for(int i=1; i<=N; i++)
        scanf("%lf",&p[i]);
    dp[0][0]=1.0;
    for(int i=1; i<=N; i++)
    {
        dp[i][0]=dp[i-1][0]*(1-p[i]);
        for(int j=1; j<=i; j++)
            dp[i][j]=p[i]*dp[i-1][j-1]+(1-p[i])*dp[i-1][j];
    }
    for(int i=N; i>N/2; i--)
        ans+=dp[N][i];
    printf("%.9f\n",ans);
}


Measured memory_bytes: 68864
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)
    sum_A = 0
    for i in range(A):
        sum_A += sort_v[i]
    max_ave_v = sum_A / A

    print(max_ave_v)

    num = sort_v.count(sort_v[0])
    num2 = sort_v.count(sort_v[A-1])
    if sort_v[0] == sort_v[A-1]:
        ans = 0
        for i in range(A,B+1):
            if num >= i:
                ans += cmb(num,i)
    else:
        cnt = 0
        for i in range(A):
            if sort_v[i] == v[A-1]:
                cnt += 1
        ans = cmb(num2, cnt)

    print(ans)
        


main()

Measured memory_bytes: 38640
n, m = map(int, input().split())
ac = [0]*n
wa = [0]*n
a = 0
w = 0
for i in range(m):
  p, s = input().split()
  p = int(p)-1
  if ac[p] == 0 and s == "AC":
    ac[p] += 1
    a += 1
    w += wa[p] 
  elif ac[p] == 0 and s == "WA":
    wa[p] += 1
print(a,w)

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

int main(){
  int k, x;
  cin >> k >> x;
  rep(i,min(x+k,1000001),max(x-k+1,-1000000)) cout << i << " ";
  cout << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

const (
	BUFSIZE   = 10000000
	MOD       = 1000000007
	INF_INT   = math.MaxInt32
	INF_INT64 = math.MaxInt64
)

var rdr *bufio.Reader

func main() {
	rdr = bufio.NewReaderSize(os.Stdin, BUFSIZE)
	solve()
}

var prime []int

func solve() {
	N := readint()
	ans := 0
	for i := 1; i <= N; i++ {
		y := int(N / i)
		ans += (y + 1) * y / 2 * i
	}
	fmt.Println(ans)
}

func primes(n int) int {
	ans := 1
	for _, index := range prime {
		if n == 1 {
			break
		}
		count := 0
		for n%index == 0 {
			n /= index
			count += 1
		}
		ans *= (count + 1)
	}
	return ans
}
func readline() string {
	buf := make([]byte, 0, BUFSIZE)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			fmt.Println(e.Error())
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readIntSlice(size int) []int {
	slice := make([]int, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i(v)
	}
	return slice
}

func readInt64Slice(size int) []int64 {
	slice := make([]int64, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i64(v)
	}
	return slice
}

func readint() int {
	return s2i(readline())
}

func readint64() int64 {
	return s2i64(readline())
}

// For int64
func b2i64(b bool) int64 {
	if b {
		return 1
	}
	return 0
}

func abs64(v int64) int64 {
	if v < 0 {
		return -v
	}
	return v
}

func min64(values ...int64) int64 {
	ret := int64(INF_INT64)
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max64(values ...int64) int64 {
	ret := -int64(INF_INT64)
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i64(s string) int64 {
	v, ok := strconv.ParseInt(s, 10, 64)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int64")
	}
	return v
}

// For int
func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

func abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func min(values ...int) int {
	ret := INF_INT
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max(values ...int) int {
	ret := -INF_INT
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i(s string) int {
	v, ok := strconv.Atoi(s)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int")
	}
	return v
}

func lcm(v1, v2 int) int {
	if v1 > v2 {
		v1, v2 = v2, v1
	}
	for v1 != 0 {
		v1, v2 = v2%v1, v1
	}
	return v2
}

func gcd(v1, v2 int) int {
	return v1 * v2 / lcm(v1, v2)
}

/* ------------------------------------------------ */
/* Data stracture                                   */
/* ------------------------------------------------ */
type IntHeap []int

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }


Measured memory_bytes: 2484
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int MAX_N = 2e5 + 5;
const int INF = 0x7fffffff;
int dp[MAX_N], nxt[MAX_N][26];
char s[MAX_N];

int main()
{
#ifdef ANONYM
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    clock_t rtime = clock();
#endif

    scanf("%s", s);
    int len = strlen(s);
    dp[len] = 1; dp[len+1] = 0;
    REP(i, 0, 26) {
        nxt[len][i] = len;
    }
    for(int i=len-1; i>=0; --i) {
        REP(j, 0, 26) {
            nxt[i][j] = nxt[i+1][j];
        }
        nxt[i][s[i] - 'a'] = i;
        dp[i] = INF;
        REP(j, 0, 26) {
            dp[i] = min(dp[i], dp[nxt[i][j] + 1] + 1);
        }
    }
    int now = 0;
    while(now != len+1) {
        int j = 0;
        while(dp[nxt[now][j] + 1] + 1 != dp[now]) {
            j++;
        }
        putchar('a' + j);
        now = nxt[now][j] + 1;
    }
    puts("");
    int a = 1;

#ifdef ANONYM
    debug("time: %d\n", (int)(clock() - rtime));
#endif
    return 0;
}


Measured memory_bytes: 21504