akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int abs(int n) {
    if( n >= 0)
        return n;
    return -n;
}

long long abssum(int n, long long b) {
    long long sum = 0;
    for (int i = 1; i <= n; i++)
        sum = sum + abs(a[i] - b);
    return sum;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] =  a[i] - i;
    }
    std::sort(a + 1, a + n + 1);
    long long b;
    if (n % 2 != 0)
        b = a[n/2 + 1];
    else {
        b = (a[n/2] + a[n/2 + 1])/ 2;
    }

    cout << abssum(n, b);
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long 
#define dd cout<<endl
const int mod=1e9+7;
const int nf=1e9+7;

//const int maxn=



int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	ll int n;
	
	while(cin>>n)
	{
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			if(to_string(i).size()&1)
				ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    for(int i = 0; i < M; ++i){
        cin >> X[i];
    }

    sort(X.begin(), X.end());
    
    vector<int> diffs;
    for(int i = 1; i < X.size(); i++){
        diffs.push_back(X[i] - X[i-1]);
    }
    sort(diffs.begin(), diffs.end(), greater<int>());
        
    int ans = X.back() - X[0];
    for(int i = 0; i < min((int)diffs.size(), N-1); i++){
        ans -= diffs[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1276
MODE = "stdio"
require 'matrix'
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = "\
  This is a pen.
  This is a pen.
  ".split("\n")
  tmp.each{|s|
    line << s.strip
  }
end

s = ""

n=0
while true 
  break if line[n] == nil
  s += line[n].downcase
  n += 1
end

[*'a'..'z'].each do |a|
    puts "#{a} : #{s.count(a)}"
  end

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

int main() {
  int n;
  cin>>n;
  vector<pair<int,int>>a(n);
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    a.at(i)=make_pair(l,i);
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
    if(i==a.at(n-1).second){
      cout<<a.at(n-2).first<<endl;
    }
    else cout<<a.at(n-1).first<<endl;
  }
}


Measured memory_bytes: 3200
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		System.out.println("ABC"+n);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


Measured memory_bytes: 21844
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i=0; i<N; i++) {
    cin >> L[i];
  }
  int 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++) {
        bool notEqual_ij = L[i] != L[j];
        bool notEqual_jk = L[j] != L[k];
        bool notEqual_ki = L[k] != L[i];
        bool notEqual = notEqual_ij && notEqual_jk && notEqual_ki;
        bool cos_i = L[i] < L[j] + L[k];
        bool cos_j = L[j] < L[i] + L[k];
        bool cos_k = L[k] < L[i] + L[j];
        bool cos = cos_i && cos_j && cos_k;
        if (notEqual && cos) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3608
// C - Sum of product of pairs
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int MOD = (1e9) + 7;
	int64_t ans = 0, b = 0;
	for(int i=0; i<N; ++i){
		int a; cin>>a;
		ans += a * b % MOD;
		b += a;
		b %= MOD;
	}
	cout<< (ans + MOD) % MOD <<endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;

int f(string const& s){
    int p=0;
    int res = 0;
    while(p<(int)s.size()){
        int n=0;
        while(isdigit(s[p])){
            n*=10;
            n+=s[p]-'0';
            p++;
        }
        if(n==0)n=1;
        char c = s[p];
        p++;
        if(c=='m')res+=1000*n;
        if(c=='c')res+=100*n;
        if(c=='x')res+=10*n;
        if(c=='i')res+=1*n;
    }
    return res;
}

string g(int n){
    string res;
    char c[]="ixcm";
    for(int i=0;i<4;i++){
        int k=n%10;
        n/=10;
        if(k==0) continue;
        res.push_back(c[i]);
        if(k!=1) res.push_back(k+'0');
    }
    reverse(res.begin(),res.end());
    return res;
}

int main(){
    int n;
    cin>>n;
    while(n--){
        string s,t;
        cin >> s >> t;
        cout << g(f(s)+f(t)) << endl;
        //cout << f(s) << " " << f(t) << endl;
    }
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n=3;
    string s;
    vector<int> A(4);
    vector<char> B(n);
    cin >> s;
    for(int i=0;i<4;i++){
        A.at(i) = s.at(i) - '0';
    }  

    for (int bit = 0; bit < (1<<n); ++bit) {
        int sum=A.at(0);
        for (int i = 0; i < 3; ++i) {
            if (bit & (1<<i)) {
                sum+=A.at(i+1);
                B.at(i)='+';
            }else{
                sum-=A.at(i+1);
                B.at(i)='-';
            }    
        }
        if(sum==7){
            break;
        }
    }
    for(int i=0;i<3;i++){
        cout << A.at(i) << B.at(i);
    }
    cout << A.at(3) << "=7" << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int inf=1e9;
int n,sl,fh,ans,col[210],dis[210][210];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
void dfs(int u,int c)
{
	col[u]=c;
	for(int i=1;i<=n;++i)
		if(dis[u][i]<inf)
		{
			if(!~col[i]) dfs(i,c^1);
			else if(col[i]==col[u]) {puts("-1"); exit(0);}
		}
}
int main()
{
	n=rd();
	for(int i=1;i<=n;++i) col[i]=-1;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
		{
			scanf("%1d",&dis[i][j]);
			if(!dis[i][j]) dis[i][j]=inf;
		}
	dfs(1,0);
	for(int k=1;k<=n;++k) 
		for(int i=1;i<=n;++i)
			if(i!=k)
				for(int j=1;j<=n;++j)
					if(i!=j&&j!=k)
						dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(dis[i][j]<inf)
				ans=max(ans,dis[i][j]);
	printf("%d\n",ans+1);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N;
    cin>>N;
    string str,cstr;
    cin >> str;
    cstr=str;
    for(int i=0;str.length()!=0;){
        if(str[i]=='('&&str[i+1]==')'){
            str.erase(str.begin()+i,str.begin()+i+2);
            i=0;
        }else if(str[i]==')'){
            str.erase(str.begin()+i,str.begin()+i+1);
            cstr="("+cstr;
            i=0;
        }else if(str[i]=='('&&i==str.length()-1){
            str.erase(str.begin()+i,str.begin()+i+1);
            cstr=cstr+")";
            i=0;
        }else{i++;}
    }
    cout << cstr <<"\n";
    return 0;
}

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

int main() {
  bool table[2000] = {false};
  vector<int> suf;
  int N, ndata, size = 0;
  cin >> ndata;

  int data;
  for(int i = 0; i < ndata; i++) {
    cin >> data;
    int count = 0;
    for(int j = 0; j < size; j++) {
      if(!table[suf[j]+data]) {
	table[suf[j]+data] = true;
	suf.push_back(suf[j]+data);
	count++;
      }
    }
    size += count;
    table[data] = true;
    suf.push_back(data);
    size++;
  }

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> data;
    if(table[data])
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }

  return 0;
}

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



int main() {
    int n;
    cin >> n;
    
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    
    int cnt = 0;
    rep(i,n-2) {
        if((p[i] <= p[i+1] && p[i+1] <= p[i+2]) ||
           (p[i] >= p[i+1] && p[i+1] >= p[i+2]))
            cnt++;
    }
    
    cout << cnt << endl;
    
    
    return 0;
}




Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int X, Y, Z;
    cin >> X >> Y >> Z;

    cout << Z << " " << X << " " << Y << endl;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc161/abc161_a && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc161/abc161_a && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc161/abc161_a && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //a
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; n - i > i; i++) {
    ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Long = long long;
int main() {
    Long n,a,b;
    cin >> n >> a >> b;
    vector<Long> v(n);
    for(auto &t : v) cin >> t;
    Long ans = 0;
    for(int i = 1; i < n; i++) {
        ans += min(b,(v[i]-v[i - 1]) * a);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
#define ll long long 
#define ull unsigned ll
#define db double
#define pii pair<int, int>
#define vi vector<int>
#define INF 1e9+7

int main() {
	int N;
	cin >> N;
	int ans = 0;
	int t = N;
	while (t) {
		ans += t % 10;
		t /= 10;
	}
	if (N % 10 == 0 && ans == 1) {
		cout << 10 << endl;
	} else {
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  println(" " + (1 to n).filter(i => isMultipleOf3(i) || hasNumberOf3(i)).mkString(" "))

  def isMultipleOf3(i: Int): Boolean = i % 3 == 0

  def hasNumberOf3(i: Int): Boolean = {
    def loop(i: Int): Boolean = i match {
      case _ if i % 10 == 3 => true
      case _ if i / 10 == 0 => false
      case _ => loop(i / 10)
    }
    loop(i)
  }
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

#define MAXN 200005

const int INF = 1e9;

int st[4*MAXN], lazy[4*MAXN];

void push(int p, int l, int r) {
    if (lazy[p]) {
        st[p] = lazy[p];
        if (l != r) {
            int m = (l + r) / 2;
            lazy[2*p] = lazy[p];
            lazy[2*p+1] = lazy[p] + m - l + 1;
        }
        lazy[p] = 0;
    }
}

void update(int p, int l, int r, int i, int j, int val) {
    push(p, l, r);
    if (i > r || j < l)
        return;
    if (i <= l && r <= j) {
        st[p] = val;
        if (l != r) {
            int m = (l + r) / 2;
            lazy[2*p] = val;
            lazy[2*p+1] = val + m - l + 1;
        }
        return;
    }
    int m = (l + r) / 2;
    update(2*p, l, m, i, j, val);
    update(2*p+1, m+1, r, i, j, val + max(m - max(i, l) + 1, 0));
    st[p] = min(st[2*p], st[2*p+1]);
}

int query(int p, int l, int r, int idx) {
    push(p, l, r);
    if (l == r)
        return st[p];
    int m = (l + r) / 2;
    if (idx <= m)
        return query(2*p, l, m, idx);
    return query(2*p+1, m+1, r, idx);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int h, w;
    cin >> h >> w;
    update(1, 0, w, 0, 0, INF);
    for (int i=1; i<=h; i++) {
        int a, b;
        cin >> a >> b;
        update(1, 0, w, a, b, query(1, 0, w, a-1) + 1);
        cout << (st[1] + i >= INF ? -1 : st[1] + i) << "\n";
    }

    return 0;
}


Measured memory_bytes: 7668
import sys
sys.setrecursionlimit(1<<30)
def dfs(x, dis):
    for y in Tree[x]:
        if parent[y] != x:
            parent[x] = y
            dis[y] = dis[x] + 1
            dfs(y, dis)
N, u, v = map(int,input().split())
Tree = [[] for _ in range(N+1)]
for i in range(N-1):
    A, B = map(int,input().split())
    Tree[A].append(B)
    Tree[B].append(A)
disT = [-1]*(N+1)
disA= [-1]*(N+1)
disT[u] = 0
disA[v] = 0
parent = [-1]*(N+1)
dfs(u, disT)
parent = [-1]*(N+1)
dfs(v, disA)
Ans = 0
for i in range(len(disA)):
    if disA[i] >= disT[i]:
        Ans = max(Ans, disA[i]-1)
print(Ans)

Measured memory_bytes: 102684
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  int dp[n+1]={};

  for(int i=0;i<n;i++){
    dp[i+1]=max(dp[i],dp[i+1]);
    if(str[i]=='1') continue;
    int s=i,t=i;
    while(s-1>=0&&str[s-1]=='1') s--;
    while(t+1<n&&str[t+1]=='1') t++;
    if(s==i||t==i) continue;

    for(int j=i-1;j>=s;j--){
      dp[i+2]=max(dp[i+2],dp[j]+i-j);
    }
    for(int j=i+1;j<=t;j++){
      dp[j+1]=max(dp[j+1],dp[i-1]+j-i);
    }
  }

  cout<<dp[n]<<endl;

  return 0;
}


Measured memory_bytes: 2820
#include <cstdio>
#include <cstdlib>
#include <vector>

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  std::vector<int> a(N), b(N);
  for (size_t i = 0; i < N; ++i) 
    scanf("%d %d", &a[i], &b[i]);

  std::vector<int> c(M), d(M);
  for (size_t j = 0; j < M; ++j)
    scanf("%d %d", &c[j], &d[j]);

  for (size_t i = 0; i < N; ++i) {
    size_t res = -1;
    int min = 1e9;
    for (size_t j = 0; j < M; ++j) {
      int cur = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if (min > cur) {
        min = cur;
        res = j+1;
      }
    }
    printf("%zu\n", res);
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <string>
#include <iostream>

using namespace std;
const int INF = 0x3f3f3f3f;

const int dir[4] = {-1, 1, -4, 4};

unordered_map<string, int> um;
string s;

void bfs() {
    queue<string> que;
    const string ans = "01234567";
    um[ans] = 0; que.push(ans);
    while(!que.empty()) {
        string now = que.front(); que.pop();
        if(now == s) return;
        int pos = 0;
        for(int i = 1; i < 8; ++i) {
            if(now[i] == '0') {
                pos = i; break;
            }
        }
        for(int i = 0; i < 4; ++i) {
            int tpos = pos + dir[i];
            if(pos == 4 && i == 0) continue;
            if(pos == 3 && i == 1) continue;
            if(tpos < 0 || tpos > 7) continue;
            string temp = now;
            swap(temp[pos], temp[tpos]);
            if(um.find(temp) == um.end()) {
                um[temp] = um[now] + 1;
                que.push(temp);
            }
        }
    }
}

int main() {
    bfs();
    while(getline(cin, s)) {
        s.erase(remove(s.begin(), s.end(), ' '), s.end());
        printf("%d\n", um[s]);
    }
    return 0;
}



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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;
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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= 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
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s; cin >> s;
  int n = s.size();
  stack<char> st;
  for(auto c : s) {
    if(c == 'S') st.push(c);
    else {
      if(!st.empty() && st.top() == 'S') st.pop();
      else st.push(c);
    }
  }
  cout << st.size() << endl;
}


Measured memory_bytes: 3772
import numpy as np

ND=np.array(input().split(),dtype=np.int64)
XY=[]
for i in range(ND[0]):
    XY.append(np.array(input().split(),dtype=np.int64))

D=ND[1]

cnt=0
for xy in XY:
    x=xy[0]
    y=xy[1]
    if(np.sqrt(pow(x,2)+pow(y,2))<=D):
        cnt+=1

print(cnt)

Measured memory_bytes: 56844
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main(int argc, char* argv[])
{
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0;
  ll ret = 0;
  for (int i = 40; i >= 0; i--) {
    ll mask = 1LL << i;
    ll cnt = 0;
    rep(j, n) {
      if (a[j] & mask) ++cnt;  // i 桁目でビットが立っているものを数える
    }
    if (cnt >= n - cnt) {   // ビットを立てない方がお得
      ans += mask * cnt;
    } else {                // ビットを立てた方がお得
      if (mask + ret <= k) {  // ビットを立てても K 以内に収まる
        ans += (n - cnt) * mask;
        ret += mask;
      } else {               // ビットを立てると K を超えるなら立てない
        ans += mask * cnt;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;




int main(int argc, const char * argv[]) {
#ifdef __APPLE__
    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
    //freopen("/Users/danya.smelskiy/Documents/Danya/Danya/output.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int x, y, z;
    cin >> x >> y >> z;
    int k;
    cin >> k;
    if (x > y) swap(x, y);
    if (y > z) swap(y, z);
    if (x > y) swap(x, y);
    for (int i = 1; i <= k; ++i)
        z *= 2;
    cout << x + y + z << '\n';
    return 0;
}



Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b=LI()

  if a%2!=b%2:
    return 'IMPOSSIBLE'
  return (a+b)//2

# main()
print(main())


Measured memory_bytes: 6480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mp make_pair
const int maxn = 3000+5;
const int MOD = 1e9+7;
#define mod(x) x % MOD
#define INF 0x3f3f3f3f

double dp[maxn][maxn];
double a[maxn];

int main(){
    int n = 0;
    while(~scanf("%d", &n)){
        for(int i = 1;i <= n;i++){
            scanf("%lf",a + i);
        }
        dp[0][0] = 1;
        for(int i = 1;i<=n;i++){
            dp[i][0] = (1.0 - a[i]) * dp[i-1][0];
        }
        for(int i = 1;i <= n;i++){
            for(int j = 1;j <= i;j++){
                dp[i][j] = (1.0 - a[i]) * dp[i-1][j] + a[i] * dp[i-1][j-1];
            }
        }
        double sum = 0;
        int start = n / 2 + 1;
        for(int i = start;i <= n;i++){
            sum += dp[n][i];
        }
        
        /*for(int i = 1;i <= n;i++){
            for(int j = 1;j <= i;j++){
                cout<<dp[i][j]<<endl;
                if(j >= (i) / 2 + 1){
                    sum += dp[i][j];
                }
            }
        }*/
        printf("%.10lf\n",sum);
        //cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 68992
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    a, b, c, d = MI()

    l = a + b
    r = c + d
    if l > r:
        print("Left")
    elif l < r:
        print("Right")
    else:
        print("Balanced")
    pass


if __name__ == "__main__":
    main()


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

int main() {
	int a,b;cin >>a>>b;
	int xb = 10*b;
	int out =-1;
	for(int i = xb;i<xb+10;++i){
		int tmp = i*8/100;
		if(tmp==a){
			out = i;
			break;
		}
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
*a,=map(int,input().split())

aa=sorted([a[i]-i-1 for i in range(n)])

if n%2==0:
    b=(aa[n//2]+aa[n//2-1])//2
else:
    b=aa[(n-1)//2]

ans=0
for x in aa:
    ans+=abs(x-b)

print(ans)

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

typedef long long ll;

int main(void)
{
    //freopen("input.txt", "r", stdin);
    int n, i, ac = 0, wa = 0, tle = 0, re = 0;
    cin >> n;
    string s;
    for(i = 0; i < n; i++)
    {
        cin >> s;
        if(s == "AC")
            ac++;
        else if(s == "WA")
            wa++;
        else if(s == "TLE")
            tle++;
        else if(s == "RE")
            re++;
    }
    cout << "AC x " << ac << "\n" << "WA x " << wa << "\n";
    cout << "TLE x " << tle << "\n" << "RE x " << re << "\n";

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n, m;
    cin >> n >> m;
    if (n == m)
    {
        Yes(1);
    }
    else
    {
        Yes(0);
    }
}

Measured memory_bytes: 256
r, c = (int(i) for i in input().split())
data = [[0 for j in range(c)] for i in range(r)]

sumr = [0 for i in range(r)]
sumc = [0 for j in range(c)]

for i in range(r):
    j = -1
    for strval in input().split():
        j += 1
        val = int(strval)
        data[i][j] = val
        sumr[i] += val
        sumc[j] += val

for i in range(r):
    for j in range(c):
        print(str(data[i][j]) + " ", end="")
    print(str(sumr[i]))

sumtotal = 0

for i in range(c):
    print(str(sumc[i]) + " ", end="")
    sumtotal += sumc[i]

print(sumtotal)


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

int main() {
  int N;
  cin >> N;
  
  string s;
  map<string, int> mp;
  for (int i = 0; i < N; i++) {
    cin >> s;
    sort(s.begin(), s.end());
    if( mp.count(s) ) {
        mp[s]++;
    } else {
        mp[s] = 1;
    }
  }
  
  int64_t num_a=0;
  int64_t n;
  for(auto p : mp) {
    n = p.second-1;
    num_a += ((1ll+n)*n)/2ll;
  }
  
  cout << num_a << endl;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }



template<typename T>
struct BIT {
    vector<T> array;
    const int n;
public:
    BIT(int _n) : array(_n + 1, 0), n(_n) {}
    
    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += array[i];
            i -= i & -i;
        }
        return s;
    }
    T sum(int i, int j) {
        T ret_i = sum(i - 1);
        T ret_j = sum(j);
        return ret_j - ret_i;
    }
    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i;
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, q;
    cin >> n >> q;
    BIT<int> bit(n);
    
    rep(i, q) {
        int com, x, y;
        cin >> com >> x >> y;
        
        if (com == 0) {
            bit.add(x, y);
        } else {
            cout << bit.sum(x, y) << endl;
        }
    }
    
}



Measured memory_bytes: 3244
n = int(input())
li1 = 1
li2 = 2
luca = 0
if n == 1:
    print(li1)
    quit()
for i in range(n-1):
    luca = li1 + li2
    li2 = li1
    li1 = luca
print(luca)
    
    


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m;cin>>n>>m;
    priority_queue<long long> q;
    for(int i=0;i<n;i++){
        long long x;cin>>x;
        q.push(x);
    }
    for(int i=0;i<m;i++){
        long long x=q.top();
        q.pop();
        q.push(x/2);
    }
    long long ans=0;
    while(q.size()>0){
        ans+=q.top();
        q.pop();
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1400
S = input()
if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)

Measured memory_bytes: 8900
from itertools import product

N = int(input())
for h, n in product(range(1, 3501), repeat=2):
    if 4 / N > 1 / h + 1 / n:
        numer = N * h * n
        denom = 4 * h* n - N * (n + h)
        if denom <= 0:
            continue
        w, r = divmod(numer, denom)
        if r == 0:
            print(h, n, w)
            break

Measured memory_bytes: 3188
a,b,c,d=map(int,input().split())
now=0
while True:
    if a<=0 or c<=0:
        break
    else:
        if now%2==0:
            c-=b
            now+=1
        else:
            a-=d
            now+=1
print('Yes' if a>0 else 'No')

Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n)  for(int i=0;i<(n);++i)
#define ALL(x) (x).begin(),(x).end()
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N), y(M);
  REP(i, N) {
    cin >> x.at(i);
  }
  REP(i, M) {
    cin >> y.at(i);
  }
  sort(ALL(x));
  reverse(ALL(x));
  sort(ALL(y));
  
  if (x.at(0) < y.at(0) && x.at(0) > X && y.at(0) < Y) {
    cout << "No War";
  }
  else {
    cout << "War";
  }
  cout << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

def even_count(array,num):
    count = 0
    for i in range(num):
        if array[i]%2 == 0:
            count += 1
    return(count)

num = int(input())
a = [int(i) for i in input().split()]
count = 0
even = 0
while True:
    even = even_count(a,num)
    if even != num:
        break
    else:
        a = list(map(lambda x:x/2, a))
        count += 1
    even = 0

print(count)
  

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  ll A,B;
  cin>>A>>B;
  cout<<(B-1+A-2)/(A-1)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef unsigned long long ull;

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

    int N;
    cin >> N;
    ull T, A;
    ull v1 = 1, v2 = 1;
    for(int i=0; i<N; i++){
        cin >> T >> A;
        ull u1 = v1 / T;
        ull u2 = v2 / A;
        if(v1 % T) u1++;
        if(v2 % A) u2++;
        ull m = max(u1, u2);
        v1 = m * T;
        v2 = m * A;
    }
    cout << v1 + v2 << endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;
int a[100006];
int l[100006], r[100006];
int rwa[300006];
signed main() {
	int n, q; cin >> n >> q;
	map<int, int>M, M1;
	rep(i, n) {
		cin >> a[i];
		M[a[i]]++;
	}
	rep(i, q) {
		cin >> l[i] >> r[i];
		M[l[i]]++;
		M[r[i]]++;
	}
	int cnt = 0;
	for (auto itr = M.begin(); itr != M.end(); itr++) {
		M1[itr->first] = cnt; cnt++;
	}
	rep(i, n) {
		a[i] = M1[a[i]];
		rwa[a[i] + 1]++;
	}
	rep(i, 300000)rwa[i + 1] += rwa[i];
	rep(i, q) {
		l[i] = M1[l[i]];
		r[i] = M1[r[i]];
		cout << rwa[r[i] + 1] - rwa[l[i]] << endl;
	}
}


Measured memory_bytes: 45268
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h, w = LI()
ch, cw = LI()
dh, dw = LI()
s = [input() for _ in range(h)]

dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]
que = deque([(cw-1, ch-1)])
d = [[10**10] * w for _ in range(h)]
d[ch-1][cw-1] = 0
while que:
    x, y = que.popleft()
    for i in range(4):
        nx, ny = x + dx[i], y + dy[i]
        if 0 <= nx < w and 0 <= ny < h:
            if s[ny][nx] == '.' and d[ny][nx] > d[y][x]:
                d[ny][nx] = d[y][x]
                que.appendleft((nx, ny))
    for i in range(-2, 3):
        for j in range(-2, 3):
            nx, ny = x + i, y + j
            if 0 <= nx < w and 0 <= ny < h:
                if s[ny][nx] == '.' and d[ny][nx] > d[y][x] + 1:
                    d[ny][nx] = d[y][x] + 1
                    que.append((nx, ny))
if d[dh-1][dw-1] == 10**10:
    print(-1)
else:
    print(d[dh-1][dw-1])


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

int K;

// メモ化再帰により一つ下の桁から上の桁へ遷移していくdp
ll solve(string &s, int k = 0, bool status = 1, int c = 0) {
    // dp[k][status] := 上(k+1)桁が定まっていてその時点でstatus(:=
    // 上限値と一致するかの真偽値)のときの場合の数
    static ll dp[100001][2][4];
    static bool visited[1000001][2][4] = {};
    static int max_num = 9;

    if (k == s.size()) {
        return (c == K);
    }

    ll &res = dp[k][status][c];
    if (visited[k][status][c])
        return res;
    else
        res = 0;

    visited[k][status][c] = true;
    int r = (status ? s[k] - '0' : max_num);

    for (int i = 0; i <= r; i++) {
        if (c == K && i) break;
        ll cnt = solve(s, k + 1, status && i == r, c + (i > 0));
        res += cnt;
    }
    return res;
}

int main() {
    string N;
    cin >> N >> K;
    cout << solve(N) << endl;
    return 0;
}

Measured memory_bytes: 2304
/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*                                                                                 *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                 *
\*********************************************************************************/

//Now Write to Code ___________________________


#include <bits/stdc++.h>
using namespace std ;
 
 
typedef long long                ll;
typedef long double              ld;
typedef unsigned long long       ull;
typedef pair <int,int>           pii;
typedef pair <ll,ll>             pll;
typedef vector <int>             vi;
typedef vector <ll>              vll;
typedef vector <vector <int> >   vvi;
 
inline int    Int(){int x; cin >> x; return x;}
inline ll     Long(){ll x; cin >> x; return x;}
inline float  Float(){float x; cin >> x; return x;}
inline double Double(){double x; cin >> x; return x;}
inline void   Yes(){cout << "Yes" << endl;}
inline void   No(){cout << "No" << endl;}
inline void   YES(){cout << "YES" << endl;}
inline void   NO(){cout << "NO" << endl;}
 
const int N             =(int)2e5 + 5;
const int maxN          =(int)1e6 + 6;
const ll  Mod           =(ll)1e9 + 7;
const int inf           =(int)2e9;
const ll  Inf           =(ll)1e18;
 
#define     T           int t,q; cin >> t; for(q=1;q<=t;q++)
#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i=(b); i!=(e+1)-2*(b > e); i =i+1-2*(b > e))
#define     Int         Int()
#define     Long        Long()
#define     Float       Float()
#define     Double      Double()
#define     all(x)      x.begin() , x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
#define     biday       return 0 
 
 
int main()
{
	int A,B;
	cin >> A >> B;

	if(A>B)cout << "safe" << endl;
	else cout << "unsafe" << endl;    


    biday;
}
 
//...............BYE BYE................

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

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

    int x, y;

    int ans[n+5];

    for (int i=0 ; i<n+5 ; i++) {
        ans[i] = 0;
    }

    for (int i=0 ; i<m ; i++) {
        cin >> x >> y;

        ans[x]++;
        ans[y+1]--;
    }

    int temp=0;

    for (int i=0 ; i<n+5 ; i++) {
        temp += ans[i];
        ans[i] = temp;
    }

    int total = 0;

    for (int i=0 ; i<n+5 ; i++) {
        if (ans[i]==m) {
            // cout << "i is " << i << endl;
            total++;
        }
    }

    cout << total << endl;
}


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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int n;
vector<pair<string, pair<int, int>>> v;

int main()
{
	IOS;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		string s; int x;
		cin >> s >> x;
		v.push_back({s, {-x, i}});
	}
	sort(v.begin(), v.end());
	for (auto i : v) {
		cout << i.second.second << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;


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

	if (test.size() <= n) {
		cout << test;
	} else {
		for (int i = 0; i < n; i++) {
			printf("%c", test[i]);
		}
		printf("...");
	}

}



Measured memory_bytes: 3720
import java.util.Scanner;

public class Main 
{
    public static void main(String [] args)
    {
    Scanner scanner = new Scanner(System.in);
    int x = scanner.nextInt();
    
    if(x == 0)
    {
        System.out.println(1);
    }
    else
    {
            System.out.println(0);
    }
    
}
}

Measured memory_bytes: 35796
n = int(input())
c = []
for i in range(n):
  t,a = map(int,input().split())
  c.append((t,a))
  
al = c[0][0]
ar = c[0][1]
for i in range(n):
  if i == 0:
    continue
  b = max((al-1)//c[i][0]+1,(ar-1)//c[i][1]+1)
  al = c[i][0]*b
  ar = c[i][1]*b
  
print(al+ar)

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		string card,add;
		int m,h;
		cin >> card;
		if (card == "-") break;
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> h;
			add = card.substr(0,h);
			card += add;
			card.erase(0, h);
		}
		cout << card << "\n";
	}
	return 0;
}



Measured memory_bytes: 3208
using System;
using System.Collections.Generic;

public class CSharp{
    public static void Main(){
        Kyopuro chokudai = new Kyopuro();
	    chokudai.AtCoder();
	}
}

public class Kyopuro{
    
    const int p = 1000000007;
    int n, m;
    int[] s, t;
    long[][] dp;
    
    public void AtCoder(){
        
        string[] input = Console.ReadLine().Split(' ');
        n = int.Parse(input[0]);
        m = int.Parse(input[1]);
        s = new int[n+1];
        t = new int[m+1];
        input = Console.ReadLine().Split(' ');
        for(int i=1; i<=n; i++) s[i] = int.Parse(input[i-1]);
        input = Console.ReadLine().Split(' ');
        for(int i=1; i<=m; i++) t[i] = int.Parse(input[i-1]);
        
        dp = new long[n+1][];
        for(int i=0; i<=n; i++){
            dp[i] = new long[m+1];
        }
        for(int i=0; i<=m; i++) dp[0][i] = 1;
        for(int i=1; i<=n; i++){
            dp[i][0] = 1;
            for(int j=1; j<=m; j++){
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + p;
                dp[i][j] %= p;
                if(s[i] == t[j]){
                    dp[i][j] += dp[i-1][j-1];
                    dp[i][j] %= p;
                }
            }
        }
        Console.WriteLine(dp[n][m]);
    }
    
    public static void DebugWL(object x){ System.Diagnostics.Debug.WriteLine(x); }
}


Measured memory_bytes: 44120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n, w;
  while (cin >> n >> w, n || w)
  {
    int mp[101] = {};
    int num = 0;
    for (int i = 0; i < n; ++i)
    {
      int v;
      cin >> v;
      mp[v / w]++;
      num = max(num, v / w);
    }

    int nmax = 0;
    double sum = 0.01;
    for (int i = 0; i <= num; ++i)
    {
      nmax = max(nmax, mp[i]);
    }

    for (int i = 0; i <= num; ++i)
    {
      sum += (double)((1.0 * (num - i) / num) * (1.0 * mp[i] / nmax));
    }
    cout << setprecision(10) << sum << endl;
  }

  return 0;
}



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

int main()
{
    int a, b;
    while(cin >> a >> b)
    {
        if(a >= 10) cout << -1 << endl;
        else if(b >= 10) cout << -1 << endl;
        else cout << a*b << endl;
    }
    return 0;
}


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

using namespace std;

typedef unsigned long long ull;

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

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<int> v(m);
        int mb = 0;
        rep(i, m){ cin >> v[i]; mb = max(mb, v[i]);}
        int lb = -1, ub = 1500010;
        while(ub-lb > 1){
            int mid = (ub+lb)/2;
            int count = 1, width = 0;
            rep(i, m){
                width += v[i];
                if(mid < width){width = v[i]; count++;}
            }
            if(count <= n && mb <= mid){
                ub = mid;
            } else {
                lb = mid;
            }
        }
        cout << ub << endl;
    }
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
#define ll long long
#define mod 1000000007
long long exp(long long taban, long long us) {
    long long carpan = taban;
    long long temp = us;
    long long res = 1;
    for(int i = 0;;i++){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
        if(temp == 0) break;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (((a*b)%mod)*(exp(ebob(a,b), (ll)mod-2))) % mod;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string k; ll d; cin>>k>>d;
	ll dp[k.size()][d][2] = {};
	ll sum = 0;
	ll tmp1[10] = {};
	for(int j = 0; j < 10; j++){
		tmp1[j%d]++;
	}
	for(int i = 0; i < k.size(); i++){
		sum += k[i] - '0';
		if(i == 0){
			for(int j = 0; j < k[i] - '0'; j++){
				dp[i][j%d][0]++;
			}
			dp[i][sum % d][1]++;
			continue;
		}
		dp[i][sum%d][1]++;
		ll tmp2[k[i] - '0'] = {};
		for(int j = 0; j < k[i] - '0'; j++){
			tmp2[j%d]++;
		}
		
		for(int j = 0; j < d; j++){
			for(int m = 0; m < 10; m++){
				dp[i][(j+m)%d][0] = (dp[i][(j+m)%d][0] + dp[i-1][j][0] * tmp1[m] + mod) % mod;
			}
			for(int m = 0; m < k[i] - '0'; m++){
				dp[i][(j+m)%d][0] = (dp[i][(j+m)%d][0] + dp[i-1][j][1] * tmp2[m] + mod) % mod;
			}
		}
	}
	//-1 is for 00000...0
	cout<<(dp[k.size()-1][0][0] + dp[k.size()-1][0][1] - 1 + mod) % mod;
	return 0;
}


Measured memory_bytes: 15872
import java.util.*;

class Main {

    static void solve (int n) {
        int weight = 2;
        boolean first = true;

        while (n != 0) {
            if (n % weight != 0) {
                if (!first) System.out.printf(" %d", weight / 2);
                else {
                    System.out.print(weight / 2);
                    first = false;
                }
                    
                n -= weight / 2;
            }
            weight *= 2;
        }
        
        System.out.println("");

    }

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        while(sc.hasNext()) {
            int n = sc.nextInt();
            solve(n);
        }

    }
}

Measured memory_bytes: 12000