akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
#define PI acos(-1.0)
#define EPS 1e-10
const ll INT = 1e16;
const ll MOD = 1e9 + 7;
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define rep(i,N) FOR(i, 0, N)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).reeal(), (b).real) && EQ((a).imag(), (b).imag()))
#define NIL -1

ll h,w;
ll a,b,c,d;
string s;
vector<string> vs;
bool field[10][10];

vector<string> split(string str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep)) {
        v.push_back(buffer);
    }
    return v;
}

ll fill(){
    ll width = 0;
    rep(i,h){
        int now = 0;
        rep(j,vs[i].size()){
            if(vs[i][j] == 'b'){
                field[i][now] = 1;
                now++;
            }
            else now += (vs[i][j] - '0');
        }
        width = now;
    }
    return width;
}

vector<string> solve(){
    vector<string> res;
    rep(i,h){
        string s = "";
        int cnt = 0;
        rep(j,w){
            if(field[i][j] == 0)cnt++;
            else{
                if(cnt != 0)s += (char)('0' + cnt);
                s += "b";
                cnt = 0;
            }
        }
        if(cnt != 0)s += (char)('0' + cnt);
        res.push_back(s);
    }
    return res;
}

int main(){
    while(cin >> s && s != "#"){
        rep(i,10)rep(j,10)field[i][j] = 0;
        vs.clear();
        vs = split(s,'/');
        h = vs.size();
        w = fill();
        cin >> a >> b >> c >> d;
        a--; b--;
        c--; d--;
        field[a][b] = 0;
        field[c][d] = 1;
        vector<string> ans = solve();
        rep(i,h){
            if(i != 0)cout << "/";
            cout << ans[i];
        }
        cout << endl;
    }
    
}


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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
//const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;
#define ret() return 0;

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

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

    ll s1 = s + 1;
    if (s == 1000000000ll) {
        s1 = s - 1;
    }

    if (k == 0) {
        vector<ll> ans(n, s1);
        for (ll a : ans) cout << a << ' ';
        ret();
    }

    vector<ll> ans(n, s1);
    for (int i = 0; i < k; i++) {
        ans[i] = s;
    }
    for (ll a : ans) cout << a << ' ';
}




Measured memory_bytes: 2048
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a:usize,
        b:usize
    }
    println!("{}", (a+b)%24);
}


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

int main() {
  int N;
  cin >>N;
  vector<string> s(N);
  for (int i=0;i<N;i++) cin>>s[i];
  for (int i=0;i<N;i++) sort(s[i].begin(),s[i].end());
  //cout <<s[0]<<endl;
  map<string, long> card;  // 名前→成績
  for(int i=0;i<N;i++){
    if(card.count(s[i])){
      card[s[i]] ++;
    }
    else{
      card[s[i]] =1;
    }
  }
  long c=0;

  for(auto p: card){
    auto v = p.second;
    c+= v*(v-1)/2;
  }

cout<<c<<endl;
}


Measured memory_bytes: 18176
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

A = list(range(1, N + 1))
for i, x in enumerate(itertools.permutations(A)):
    if list(x) == P:
        pn = i
    if list(x) == Q:
        qn = i
print(abs(pn - qn))


Measured memory_bytes: 41456
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

temp = input_numbers()

n = temp[0]
y = temp[1]

flag = 0

for i in range(0, n + 1):
    for j in range(0, n - i + 1):
        k = n - i - j
        if(i * 10000 + j * 5000 + k * 1000 == y):
            if(flag == 0):
                output = str(i) + ' ' + str(j) + ' ' + str(k)
                print(output)
                flag = 1

if(flag == 0):
    print('-1 -1 -1')

Measured memory_bytes: 12500
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;

int main() {
    ll N, M;
    cin >> N >> M; //頂点数と辺数の入力
    const ll NMAX = 1000;
    const ll MMAX = 2000;
    ll a[MMAX], b[MMAX];
    ll c[MMAX];
    for (int i = 0; i < M; ++i) {
        cin >> a[i] >> b[i] >> c[i]; //辺およびその重みの入力
        c[i] = -c[i];
    }
    ll dist[NMAX];
    for (int i = 0; i < N; ++i) {
        dist[i] = INF;
    }
    dist[0] = 0;
    for (int loop = 0; loop < N - 1; ++ loop) {
        for (int i = 0; i < M; ++i) {
            if (dist[a[i] - 1] == INF) continue;
            if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
                dist[b[i] - 1] = dist[a[i] - 1] + c[i];
            }
        }
    }
    ll ans = dist[N - 1];
    bool negative[NMAX];
    for (int i = 0; i < N; ++i) {
        negative[i] = false;
    }
    for (int loop = 0; loop < N ; ++ loop) {
        for (int i = 0; i < M; ++i) {
            if (dist[a[i] - 1] == INF) continue;
            if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
                dist[b[i] - 1] = dist[a[i] - 1] + c[i];
                negative[b[i] - 1] = true;
            }
            if (negative[a[i] - 1] == true) {
                negative[b[i] - 1] = true;
            }
        }
    }
    if (negative[N - 1]) cout << "inf" << endl;
    else cout << -ans << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

const int MAX = 2e5+10;
const int INF = 1e9+10;

int N;
vii U, D, R, L;

vii holRev(vii v) {
    vii ret;
    FORE (xy, v) {
        int x, y; tie(x, y) = xy;
        ret.push_back(ii(MAX-x, y));
    }
    return ret;
}

vii verRev(vii v) {
    vii ret;
    FORE (xy, v) {
        int x, y; tie(x, y) = xy;
        ret.push_back(ii(x, MAX-y));
    }
    return ret;
}

int sub1(vii r, vii l, bool hol) {
    int ret = INF;
    vector<set<int>> u(MAX);
    FORE (xy, l) {
        int x, y; tie(x, y) = xy; if (!hol) swap(x, y);
        u[y].insert(x);
    }
    FORE (xy, r) {
        int x, y; tie(x, y) = xy; if (!hol) swap(x, y);
        auto it = u[y].upper_bound(x);
        if (it != u[y].end()) {
            CHMIN(ret, (*it - x) * 5);
        }
    }

    return ret;
}

int sub2(vii uu, vii r) {
    int ret = INF;
    vector<set<int>> u(2*MAX+10);
    FORE (xy, uu) {
        int x, y; tie(x, y) = xy;
        u[x+y].insert(x);
    }
    FORE (xy, r) {
        int x, y; tie(x, y) = xy;
        auto it = u[x+y].upper_bound(x);
        if (it != u[x+y].end()) {
            CHMIN(ret, (*it - x) * 10);
        }
    }

    return ret;
}

int solve() {
    int ret = INF;

    // 正面衝突
    CHMIN(ret, sub1(R, L, true));
    CHMIN(ret, sub1(U, D, false));

    // 直行衝突
    CHMIN(ret, sub2(U, R));
    CHMIN(ret, sub2(holRev(U), holRev(L)));
    CHMIN(ret, sub2(verRev(D), verRev(R)));
    CHMIN(ret, sub2(holRev(verRev(D)), holRev(verRev(L))));

    return ret;
}

int main() {
    cout << fixed << setprecision(15);
    cin >> N;
    REP (i, N) {
        int x, y, c; char u; cin >> x >> y >> u;
        if (u == 'U') U.push_back(ii(x, y));
        else if (u == 'R') R.push_back(ii(x, y));
        else if (u == 'D') D.push_back(ii(x, y));
        else L.push_back(ii(x, y));

    }
    int ans = solve();
    if (ans == INF) cout << "SAFE" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 51152
from heapq import heappush,heappop
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  heappush(b,(a[i],i+1))
a=[]
for i in range(n):
  c,d=heappop(b)
  a.append(d)
print(*a)

Measured memory_bytes: 23512
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

    LL n, l;
    cin >> n >> l;
    LL a[n];
    for( int i = 0; i < n; ++i ) cin >> a[i];

    int pos = -1;
    for( int i = 0; i < n - 1; ++i ) {
        if( a[i] + a[i + 1] >= l ) {
            pos = i;
            break;

        }
    }

    if( pos == -1 ) {
        cout << "Impossible" << endl;
        return 0;

    }

    cout << "Possible" << endl;
    for( int i = 1; i <= pos; ++i ) {
        cout << i << endl;

    }
    for( int j = n - 1; j > pos; --j ) {
        cout << j << endl;

    }

    return 0;
}



Measured memory_bytes: 1664
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 a[6];
  for (i32 i = 0; i < 6; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  puts(a[4] - a[0] <= a[5] ? "Yay!" : ":(");
}

int main (void) {
  run ();
  return 0;
}


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

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

  if (N / 10 % 111 == 0 ||
   N % 1000 % 111 == 0 ){ 
  cout << "Yes" << endl; 
  }
  
  else 
  {
  cout << "No" << endl; 
  }
}

Measured memory_bytes: 256
n = gets.to_i
p = gets.split(' ').map(&:to_i)

count = 0
(n-2).times do |i|
    if (p[i] < p[i+1] && p[i+1] < p[i+2]) || (p[i] > p[i+1] && p[i+1] > p[i+2]) then
        count += 1
    end
end

print count

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

const int MAXN = 3.1e5;
const int MAXM = 1.1e5;
const int S = 1 << 17;

int seg[2*S];
void update(int i) {
  for (int a = S+i; a; a /= 2) {
    seg[a] ++;
  }
}
int query(int l, int r) {
  int ans = 0;
  for (int a = S+l, b = S+r; a < b; a /= 2, b /= 2) {
    if (a & 1) ans += seg[a++];
    if (b & 1) ans += seg[--b];
  }
  return ans;
}

int N, M;
vector<int> facs[MAXM];
vector<int> rights[MAXM];
long long ans[MAXM];

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int l, r; cin >> l >> r;
    rights[l].push_back(r);
  }
  for (int d = 1; d <= M; d++) {
    for (int v = d; v <= M; v += d) facs[v].push_back(d);
  }
  for (int v = 1; v <= M; v++) {
    for (int r : rights[v]) update(r);
    for (int d : facs[v]) ans[d] += query(v, min(S, v+d));
  }
  for (int d = 1; d <= M; d++) cout << ans[d] << '\n';
}

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

int main() {
    int N;
    cin >> N;
    int a[N];
    int max_leg = 0;
    int sum = 0;
    for (int i = 0; i < N; i++){
        int b = 0;
        cin >> b;
        sum += b;
        max_leg = max(max_leg, b);
    }
    if (sum - max_leg* 2 > 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#define llint long long
#define inf 1e18

using namespace std;

llint N, M;
llint x[1005], y[1005], z[1005];
llint a[] = {1, 1, 1, 1, -1, -1, -1, -1};
llint b[] = {1, 1, -1, -1, 1, 1, -1, -1};
llint c[] = {1, -1, 1, -1, 1, -1, 1, -1};

llint dp[1005][1005];

llint calc(int p)
{
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= M; j++){
			dp[i][j] = -inf;
		}
	}
	dp[0][0] = 0;
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= M; j++){
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if(j < M) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + (a[p]*x[i+1] + b[p]*y[i+1] + c[p]*z[i+1]));
		}
	}
	return dp[N][M];
}

int main(void)
{
	cin >> N >> M;
	for(int i = 1; i <= N; i++) cin >> x[i] >> y[i] >> z[i];
	
	llint ans = 0;
	for(int i = 0; i < 8; i++){
		ans = max(ans, calc(i));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdint>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))
#define MOD 1000000007;

typedef long long ll;



template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<1000000007>;

int main() {
    int r1,r2,c1,c2; cin >> r1 >> c1 >> r2 >> c2;
    vector<mint> fact(2000005);
    fact[0] = 1;
    for (int i = 1; i < fact.size(); ++i) {
        fact[i] = fact[i - 1] * i;
    }
    const auto comb = [&fact](int n, int r) {
        return fact[n] / fact[r] / fact[n - r];
    };
    mint ans=0, aa=0,bb=0,cc=0,dd=0;
    int c = c2, r = r2;
    for(int i=0;i<=c;i++){
        aa += mint(r+1) * comb(i+r+1,r+1) / mint(i+1);   
    }
    c = c1-1, r = r2;
    for(int i=0;i<=c;i++){
        bb += mint(r+1) * comb(i+r+1,r+1) / mint(i+1);   
    }
    c = c2, r = r1-1;
    for(int i=0;i<=c;i++){
        cc += mint(r+1) * comb(i+r+1,r+1) / mint(i+1);
    }
    c = c1-1, r = r1-1;
    for(int i=0;i<=c;i++){
        dd += mint(r+1) * comb(i+r+1,r+1) / mint(i+1);   
    }
    
    cout << (aa-bb-cc+dd).a << endl;
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


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

ll hpow(ll x,ll y){
    ll ans=1;
    ll i=x;
    if(y==0)return 1;
    while(y>0){
        if(y%2==1){
            ans=(ans*i)%a7;
        }
        i=(i*i)%a7;
        y=y/2;
        
    }
    return ans;
}

ll memop[2000000];
ll mkai(ll i){
    if(i==0){
        return 1;
    }
    if(memop[i]!=0){
        return memop[i];
    }else{
        ll ans=(mkai(i-1)*hpow(i,a7-2))%a7;
        memop[i]=ans;
        return ans;
    }
}

ll memok[2000000];
ll kai(ll i){
    if(i==0){
        return 1;
    }
    if(memok[i]!=0){
        return memok[i];
    }else{
        ll ans=(kai(i-1)*i)%a7;
        memok[i]=ans;
        return ans;
    }
}

ll comb(ll n,ll k){
    if(k<0 || n<k){
        return 0;
    }
    ll ans=(kai(n)*mkai(k))%a7;
    ans=(ans*mkai(n-k))%a7;
    return ans;
}

int main(){
    ll n,k;cin>>n>>k;
    ll ans[k+1];
    ll a,b;
    rep(i,1,k){
        ans[i]=0;
        a=comb(k-1,i-1);
        b=comb(n-k+1,i);
        ans[i]=(a*b)%a7;
        //cout<<a<<' '<<b<<endl;
    }
    rep(i,1,k){
        cout<<ans[i]%a7<<endl;
    }
    
    return 0;
}




Measured memory_bytes: 2304
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int ans = 0;
            for (int i = n; i <= m; i++) {
                String str = String.valueOf(i);
                String reverseStr = new StringBuffer(str).reverse().toString();
                if (str.equals(reverseStr)) {
                    ans++;
                }
            }
            out.print(ans);

        }

    }
}



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

using namespace std;
int a[100005],dp[100003];
int n;
int mincost(int x)
{
	if(dp[x]!=-1)
		return dp[x];
	if(x==n)
	{
		dp[x]=0;
		return dp[x];
	}
	if(x==n-1)
	{
		if(dp[x]==-1)
			dp[x]= abs(a[n]-a[n-1]);
		return dp[x];
	}
	dp[x]=min(mincost(x+1)+abs(a[x+1]-a[x]),mincost(x+2)+abs(a[x+2]-a[x]));
	return dp[x];
}
int main()
{
	cin>>n;
	for (int i = 1; i <=n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 0; i < 100002; ++i)
	{
		dp[i]=-1;
	}
	
	cout<<mincost(1)<<'\n';
	// for (int i = 1; i <= n; ++i)
	// {
	// 	cout<<dp[i]<<' ';
	// }
	// cout<<'\n';

}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    long long ans = 0;
    if (a + b <= c * 2) {
        ans = a * x + b * y;
    } else {
        if (x > y) {
            ans = min(y * c * 2 + (x - y) * a, x * c * 2);
        } else {
            ans = min(x * c * 2 + (y - x) * b, y * c * 2);
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    b = [a[0]]
    for i in a:
        if b[-1] == i:
            continue
        b.append(i)
    res = 1
    if len(b) <= 2:
        print(res)
    else:
        i = 1
        while i <= len(b)-2:
            if b[i] == max(b[i-1], b[i], b[i+1]) or b[i] == min(b[i-1], b[i], b[i+1]):
                res += 1
                i += 1
            i += 1
        print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14636
n = int(input())
A = list(map(int,input().split()))
B = A[:]
cntp = 0
totp = 0
for i in range(n):
    if i%2==0:
        if B[i]>=1-totp:
            totp += B[i]
        else:
            cntp += 1-totp-B[i]
            totp = 1
    else:
        if B[i]<=-1-totp:
            totp += B[i]
        else:
            cntp += B[i]+1+totp
            totp = -1
cntm = 0
totm = 0
for i in range(n):
    if i%2==0:
        if B[i]<=-1-totm:
            totm += B[i]
        else:
            cntm += B[i]+1+totm
            totm = -1
    else:
        if B[i]>=1-totm:
            totm += B[i]
        else:
            cntm += 1-totm-B[i]
            totm = 1
print(min(cntp,cntm))

Measured memory_bytes: 85580
N = int(input())
num_list = list(map(int, input().split()))

ans = 1

if 0 in num_list:
    print(0)
else:
    for i in num_list:
        ans *= i
        if ans > 10**18:
            print('-1')
            break

    if ans<= 10**18:
        print(ans)

Measured memory_bytes: 21652
#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main(void){
	while(1){
		string str;
		getline(cin, str);
		if(str == ".") break;

		stack<char> st;
		bool flag = true;
		for(int i=0; i<str.length(); i++){
			if(!flag) break;
			if(str[i] == '(' || str[i] == '['){
				st.push(str[i]);
			} else if(str[i] == ')'){
				if(st.empty() || st.top() == '['){
					flag = false;
					break;
				}
				st.pop();
			} else if(str[i] == ']'){
				if(st.empty() || st.top() == '('){
					flag = false;
					break;
				}
				st.pop();
			}
		}
		if(flag && st.empty()) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}


Measured memory_bytes: 3144
def main():

    n, a, b = [int(i) for i in input().split()]
    
    result = n // (a + b) * a

    if n % (a + b) > 0:
        if n % (a + b) >= a:
            result += a
        else:
            result += n % (a + b)
    print(result)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <set>

int main(int argc, char *argv[]) {
  int a, b, k;
  std::cin >> a >> b >> k;
  std::set<int> ans;

  for (int i = a; i <= b && i < a + k; ++i) {
    ans.insert(i);
  }
  for (int i = b; i >= a && i > b - k; --i) {
    ans.insert(i);
  }

  for (auto &v : ans)
    std::cout << v << std::endl;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  string s;
  cin >> s;
  bool ans=true;
  for(int i=0;i<s.size();i++){
    if((s.at(i)=='-'&&i!=a)||(s.at(i)!='-'&&i==a))
      ans=false;
  }
  cout << (ans?"Yes":"No");
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,ans=0;
	scanf("%d%d",&a,&b);
	if (a>b) swap(a,b);
	for(int i=a;i<=b;i++)
	  if (i/10000==i%10&&i/1000%10==i/10%10)
	    ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import qualified Data.Map as Map
import qualified Data.IntMap as IMap

solve :: [Int] -> Int
solve = f5 . f4 . f3 . f2

f5 :: [Int] -> Int
f5 = sum . map comb
    where comb n = div (n*(n-1)) 2

f4 :: IMap.IntMap Int -> [Int]
f4 = map snd . IMap.toList

f3 :: [Int] -> IMap.IntMap Int
f3 [] = IMap.empty
f3 (x:xs) = append x rest
    where append v mp | IMap.member v rest = IMap.update (\x->Just (x+1)) v rest
                      | otherwise = IMap.insert v 1 rest
          rest = f3 xs

f2 :: [Int] -> [Int]
f2 = foldl f1 [0]

f1 :: [Int] -> Int -> [Int]
f1 [] a = [a]
f1 all@(x:xs) a = (a+x):all

main = do
    getLine
    list <- map read . words <$> getLine :: IO [Int]
    print $ solve list

Measured memory_bytes: 161148
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main
int main() {
    string s;
    cin >> s;
    if (s.back() == 's') cout << s << "es\n";
    else cout << s << "s\n";
    
}


Measured memory_bytes: 3656
#include <iostream>
#include<iomanip>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
using namespace std;

const int NN=1;

int main()
{
    double ans;
    double a,b;
    scanf("%lf%lf",&a,&b);
    ans=ceil(a/(2.0*b+1.0));
    printf("%.0f\n",ans);
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private long MOD = (long) (1e9 + 7);

    private void solve() throws IOException {

        int n = nextInt();
        int m = nextInt();
        long[][] d = new long[2][n];
        long[][] dd = new long[2][n];
        Arrays.fill(d[0], 1);
        d[0][0] = 0;
        d[1][0] = 1;
        for (int i = 0; i < m - 1; i++) {
            Arrays.fill(dd[0], 0);
            Arrays.fill(dd[1], 0);

            for (int j = 0; j < n; j++) {
                for (int k = 0; k < 2; k++) {
                    dd[k][j] += 2 * d[k][j];
                    if (j > 0) {
                        dd[j - 1 == 0 ? 1 : k][j - 1] += d[k][j];
                    }
                    if (j < n - 1) {
                        dd[k][j + 1] += d[k][j];
                    }
                }
            }

            for (int j = 0; j < n; j++) {
                dd[0][j] %= MOD;
                dd[1][j] %= MOD;
            }

            long[][] t = d; d = dd; dd = t;
        }
        long res = 0;
        for (int i = 0; i < n; i++) {
            res += d[1][i];
            res %= MOD;
        }
        res *= 4;
        res %= MOD;
        out.println(res);
    }

    // ------------------

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


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

int main() {
    int n;
    cin>>n;
    vector<ll> a(n);
    map<ll,ll> m;
    for(int i = 0;i < n;++i) {
        cin>>a[i];
        ++m[a[i]];
    }
    map<ll,ll> b;
    ll sum=0;
    for(auto i:m) {
        ll t=i.second;
        b[i.first]=t*(t-1)/2;
        sum+=b[i.first];
    }
    //cerr<<"s:"<<sum<<endl;
    for(int i = 0;i < n;++i) {
        ll t=m[a[i]]-1;
        ll ans=sum-b[a[i]];
        cout<<ans+t*(t-1)/2<<endl;
    }
    return 0;
}


Measured memory_bytes: 20224
#include <iostream>
using namespace std;
int main(){

  int n,a[100],result=0,i,j;

  cin>>n;
  for(i=0;i<n;i++) cin>>a[i];

  for(i=0;i<n-1;i++){
    int now,minnum=101;
    for(j=i;j<n;j++) if(minnum>a[j]){
        now=j;
        minnum=a[j];
      }
    if(i!=now){
      swap(a[i],a[now]);
      result++;
    }
  }
  for(i=0;i<n-1;i++) cout<<a[i]<<" ";
  cout<<a[n-1]<<endl;

  cout<<result<<endl;
  return 0;
}

Measured memory_bytes: 3112
using System;

namespace TestSpace
{
    class Test
    {
        static void Main(string[] args)
        {
            string[] arrRead;
            arrRead = Console.ReadLine().Split(' ');
            int a, b;
            a = int.Parse(arrRead[0]);
            b = int.Parse(arrRead[1]);

            if (a < b)
            {
                Console.WriteLine("{0}", "a < b");
            }
            else if (a > b)
            {

                Console.WriteLine("{0}", "a > b");
            }
            else
            {
                Console.WriteLine("{0}", "a == b");
            }
        }
    }
}



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


int main(){
int a,b,c,d,ans;
ans=0;
scanf("%d %d %d %d",&a,&b,&c,&d);
if(a>b){
ans=ans+b;
}else{
ans=ans+a;
}
if(c>d){
ans=ans+d;
}else{
ans=ans+c;
}
printf("%d\n",ans);
}

Measured memory_bytes: 128
/*input
10 10
1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1
*/

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> s, t;
    rep(i, n) {
        cin >> a[i];
        if (a[i] < 0) t.push_back(a[i]);
        else s.push_back(a[i]);
    }

    int S = s.size();
    int T = t.size();
    bool ok = false;
    if (S > 0) {
        if (n == k) ok = (T%2 == 0);
        else ok = true;
    }
    else {
        ok = (k%2 == 0);
    }

    mint ans = 1;
    if (!ok) {
        sort(a.begin(), a.end(), [](int x, int y){
            return abs(x) < abs(y);
        });
        rep(i, k) ans *= a[i];
    }
    else {
        sort(s.begin(), s.end());
        sort(t.rbegin(), t.rend());
        if (k%2 == 1) {
            ans *= s.back();
            s.pop_back();
        }
        vector<ll> p;
        while (s.size() >= 2) {
            ll x = s.back(); s.pop_back();
            x *= s.back(); s.pop_back();
            p.push_back(x);
        }
        while (t.size() >= 2) {
            ll x = t.back(); t.pop_back();
            x *= t.back(); t.pop_back();
            p.push_back(x);
        }
        sort(p.rbegin(), p.rend());
        rep(i, k/2) ans *= p[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 6328
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()
    pre = ['x'] * n

    ans = 0
    for i, j in enumerate(t):
        if i < k or j != pre[i-k]:
            pre[i] = j
            if j == 'r':
                ans += p
            elif j == 's':
                ans += r
            else:
                ans += s
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4084
import java.util.Scanner;

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

        int testNum = scanner.nextInt();
        String[] scoreName = new String[]{"AC", "WA", "TLE", "RE"};
        int[] score = new int[4];

        for (int i = 0; i < testNum+1; i++) {
            String temp = scanner.nextLine();
            switch (temp) {
                case "AC" :
                    score[0]++;
                    break;
                case "WA" :
                    score[1]++;
                    break;
                case "TLE" :
                    score[2]++;
                    break;
                case "RE" :
                    score[3]++;
            }
        }
        for(int i = 0; i<4; i++) {
            System.out.println(scoreName[i]+" x "+score[i]);
        }
    }
}
  

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

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}

int main(void){
	int n=in(),m=in(),a,b,c[51]={},i;
	for(i=0;i<m;i++){
		a=in();
		b=in();
		c[a]++;
		c[b]++;
	}
	for(i=0;i<n;i++){
		print(c[i+1]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

bool isEachDifferent(ll a,ll b,ll c){
	if( a == b || b == c || a == c) return false;
	return true;
}

int main(){
	int n;
	cin>>n;
	vector<ll> L(n);
	for(int i = 0; i < n; i++){
		cin>>L[i];
	}
	ll ans = 0;
	for(int i = 0; i < n -2; i++){
		for(int j = i + 1; j < n-1; j++){
			for(int k = j + 1; k < n; k++){
				ll a = L[i];
				ll b = L[j];
				ll c = L[k];
				if( a + b > c && b + c > a && c + a > b && isEachDifferent(a,b,c) == true) ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3196
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

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

struct node {
    vector<int> link;
    int no;
};

vector<node> nod;

void f(int ind) {
    for (int i : nod[ind].link) {
        if (nod[i].no != -1)continue;
        nod[i].no = nod[ind].no;
        f(i);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    nod.resize(n);
    rep(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        nod[x].link.push_back(y);
        nod[y].link.push_back(x);
    }
    rep(i, n)nod[i].no = -1;
    int c = -1;
    rep(i, n) {
        if (nod[i].no != -1) continue;
        c++;
        nod[i].no = c;
        f(i);
    }
    cout << c + 1 << endl;
    return 0;
}



Measured memory_bytes: 9600
import java.util.*;

class Main {
	Scanner sc;
	int[][] A;
	int N;
	
	private void calc() {
		sc = new Scanner(System.in);
		A = new int[3][3];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		N = sc.nextInt();
		for (int i = 0; i < N; i++) {
			int b = sc.nextInt();
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					if (A[j][k] == b) A[j][k] = -1;
				}
			}
		}
		// 判定
		// 横
		for (int i = 0; i < 3; i++) {
			int j = 0;
			for (; j < 3; j++) {
				if (A[i][j] != -1) break;
			}
			if (j == 3) {
				System.out.println("Yes");
				return;
			}
		}
		// 縦
		for (int i = 0; i < 3; i++) {
			int j = 0;
			for (; j < 3; j++) {
				if (A[j][i] != -1) break;
			}
			if (j == 3) {
				System.out.println("Yes");
				return;
			}
		}
		// 左上から右下
		int i = 0;
		for (; i < 3; i++) {
			if (A[i][i] != -1) break;
		}
		if (i == 3) {
			System.out.println("Yes");
			return;
		}
		
		// 左上から右下
		i = 0;
		for (; i < 3; i++) {
			if (A[i][2-i] != -1) break;
		}
		if (i == 3) {
			System.out.println("Yes");
			return;
		}
		System.out.println("No");
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}


Measured memory_bytes: 35696
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;

int s[10234];

int main(){
	int n, q;
	
	cin >> n >> q;
	
	REP(i,n){
		s[i] = i;
	}
	
	REP(i,q){
		int com, x, y;
		
		cin >> com >> x >> y;
		
		if (com == 0){
			int tmp1, tmp2;
			
			if (x < y){
				tmp1 = s[y];
				tmp2 = s[x];
			}
			else if (y < x) {
				tmp1 = s[x];
				tmp2 = s[y];
			}
			
			REP(i,n){
				if (s[i] == tmp1){
					s[i] = tmp2;
				}
			}
		}
		else {
			if (s[x] == s[y]) cout << 1 << endl;
			else cout << 0 << endl;
		}
	}
	
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define itn int
typedef long long ll;
typedef pair<int,int> p;


int main()
{
  int n;
  cin >> n;
  if(n % 10 == 0) cout << 10 << endl;
  else{
    int tmp = log10(n);
    int res = 0;
    for (int i = tmp; i > 0; i--)
    {
      res += n / (pow(10, i));
      n -= ((n / int((pow(10, i)))) * pow(10, i));
    }
    res += n;
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
kind={}
N.times do|i|
  s,p=get
  p=p.to_i
  kind[s]=[] if kind[s].nil?
  kind[s].push([p,i+1])
end
#p kind
kind=kind.sort{|x,y| x[0]<=>y[0]}
kind.each do|k,arr|
    arr.sort!{|x,y| y[0]<=>x[0]}
    arr.each do|x|
        puts x[1]
    end
end

Measured memory_bytes: 14184
#include<stdio.h>
#include<string.h>

int n, q,s[100000], t,  c=0;

int serch(int a[], int n, int t){
    int l=0, r=n, mid;
    while(l < r){
        mid = (l + r) / 2;
        if(a[mid] == t) return 1;
        else if(t < a[mid]) r = mid;
        else l = mid + 1;
    }
    return 0;
}


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

    scanf("%d",&q);
    for(int i=0 ; i<q ; i++){
        scanf("%d",&t);
        c += serch(s, n, t);
    }

    printf("%d\n", c);

    return 0;
}


Measured memory_bytes: 2068
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

ll BASE_NUM = 1000000007;
int main()
{
  // 整数の入力
  ll A,B,N;
  cin >> A >> B >> N;
  ll x = min(B-1,N);
  cout << A* x/B - A *( x/ B) << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
 
#define ll long long

int main() {
  	ll A, B, N;
  	cin >> A; 
  	cin >> B;
  	cin >> N;
  	
  	ll max=0;
  	if(B>N){
    	max=(A*N/B)/1-A*((N/B)/1);
    }
  	else{
      	max=(A*(B-1)/B)/1-A*(((B-1)/B)/1);
    }
	cout << max << endl;
}

Measured memory_bytes: 3596
#include<iostream>

int main() {
	char s[11];
	std::cin >> s;

	int n = 0;
	for (int i = 0; i < 10; i++) {
		if ('1' <= s[i] && s[i] <= '9') n++;
		else break;
	}

	long long int temp, sum, ans = 0;
	for (int i = 0; i < (1 << (n - 1)); i++) {
		temp = s[0] - '0';
		sum = 0;
		for (int j = 0; j < n - 1; j++) {
			if ((i&(1 << j)) != 0) {
				sum += temp;
				temp = 0;
			}
			temp = temp * 10 + s[j + 1] - '0';
		}
		sum += temp;
		ans += sum;
	}


	printf("%lld", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ash[101][100001];
ll maxpro(ll weight[],ll value[],ll w,ll n)
{
  if(w==0||n==0)
    return 0;
  if(ash[n][w]!=-1)
    return ash[n][w];
  if(weight[n-1]<=w)
    return ash[n][w]=max(value[n-1]+maxpro(weight,value,w-weight[n-1],n-1),maxpro(weight,value,w,n-1));
else
  return ash[n][w]=maxpro(weight,value,w,n-1);
}
int main()
{
  for(int i=0;i<101;i++)
    for(int j=0;j<100001;j++)
      ash[i][j]=-1;
  ll n,w;
  cin>>n>>w;
  ll weight[n],value[n];
  for(int i=0;i<n;i++)
    cin>>weight[i]>>value[i];
  cout<<maxpro(weight,value,w,n);
 return 0; 
}

Measured memory_bytes: 82540
#include <iostream>
#include <math.h>
using namespace std;
int main(){
  int N,A,B,C,D;
  cin >> N >> A >> B >> C >> D;
  int X = (N % A != 0 ? N / A + 1 : N/A) * B;
  int Y = (N % C != 0 ? N / C + 1 : N/C) * D;
  cout << min(X,Y) << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int N;
    cin >> N;
    cout << N*(N-1)/2-N/2 << endl;
    for(int i=1;i<N;i++){
        for(int j=i+1;j<N+1;j++){
            if(i+j!=N+1-N%2)cout << i << ' ' << j << endl;
        }
    }


}

/*



 */



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int n,m,flag=1;
int main()
{
	int a[105];
	int i,j,k,n,m,x,y,l,sum,ans=0;
	multiset<int> b;
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]>0)
		flag=0;
	}
	if(flag)
	{
		cout<<"0\n";
		return 0;
	}
	int left=min(n,k);
	for(i=0;i<=left;i++)
	{
		for(j=0;j<=left-i;j++)
		{
			sum=0;
			b.clear();
            for(l=0; l<i; l++)
            {
                b.insert(a[l]);
                sum+=a[l];
            }
            for(l=0; l<j; l++)
            {
                b.insert(a[n-1-l]);
                sum+=a[n-1-l];
            }
            //for(l=0; l<i+j; l++)
            //{
            //    sum+=b[l];
            //}
            ans=max(ans,sum);
            x=k-i-j;
            int qwe=*b.begin();
            while(x>0&&b.size()>0 && qwe<0)
            {
                sum-=*b.begin();
                x--;
                b.erase(b.begin());
                if(b.size())
                qwe=*b.begin();
            }
            ans=max(ans,sum);
		}
	} 
	cout<<ans<<"\n";
	return 0;
	
}

Measured memory_bytes: 256