akhauriyash/Code-Regression huggingface dataset:
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
int N, M;
int main() {
  fastio;
  cin >> N >> M;
  vector<pair<int,int>> sub(N+1, {0,0});
  int p; string s;
  int ans = 0, pen = 0;
  rep(i, M) {
    cin >> p >> s;
    if (sub[p].first == 1) continue;
    if (s == "AC") {
      ans++;
      pen += sub[p].second;
      sub[p].first = 1;
    } else {
      sub[p].second++;
    }
  }
  cout << ans << " " << pen << '\n';
  
  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int K, T, a[110];
	cin >> K >> T;
	int m = 0, ans = 0, sum = 0;
	for (int i = 0; i < T; i++) {
		cin >> a[i];
		if (a[i] > m) m = a[i];
		sum += a[i];
	}
	sum -= m;
	ans = max(m - sum - 1, 0);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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 EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
  cin>> A >> B;
  if(A==B) cout<<"Draw"<<endl;
  else if(A==1) cout<<"Alice"<<endl;
  else if(B!=1&&A>B) cout<<"Alice"<<endl;
  else cout<<"Bob"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k;
	string s;
	cin>>k>>s;
	if(s.size()<=k)
		cout<<s<<endl;
	else
	{
		for(int i=0;i<k;i++)
			cout<<s[i];
		cout<<"...";
	}
	return 0;
}

Measured memory_bytes: 3596
# -*- coding: utf-8 -*-
import collections
s = (input())

"""
n = len(s)
ans = 0
for i in range(n-4):
    for j in range(i+4,n+1):
        if int(s[i:j]) % 2019 == 0:
            ans += 1
print(ans)
"""

n = len(s)
ans = 0
l = 0
#r = l
num = int(s)

tmp = [0 for _ in range(n+1)]
#ten = [0 for _ in range(n)]
tmp1 = 0
#val = 1
for i in range(0,n):
    #ten[i] = val
    tmp1 += (int(s[n-i-1]) * pow(10, i, 2019))
    tmp[i+1] = tmp1 % 2019
    #val = (val * 10) % 2019
#print(tmp)

c = collections.Counter(tmp)
#print(c)
for i in range(0, 2020):
    a = c[i]
    if a > 0:
        ans += ((a * (a - 1)) // 2)
print(ans)


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

using namespace std;

long f(long x)
{
	long res = (x % 4 == 1 || x % 4 == 2);
	for (int i = 50; i >= 2; i--)
	{
		long a = 1UL << i;
		long b = 1UL << (i-1);
		long r = ((x % a) - b) + 1;
		if (r <= 0) continue;
		if (r & 1)  res += b;
	}
	return res;
}

void solve()
{
	long a, b;
	cin >> a >> b;
	if (a) a--;
	cout << (f(a) ^ f(b)) << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  ull N;
  cin >> N;

  ull digit_sum {};
  ull n = N;
  while (n>0) {
    digit_sum += (n%10);
    n /= 10;
  }
  if (N%digit_sum) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }

}


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

using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll A[300001];
int main()
{
    ll n,k;
    cin>>n>>k;

    for(int i=0; i<n; i++)
        cin>>A[i];
    sort(A,A+n);
    ll ans=1,sign=0;
    int l=0,r=n-1;
    if(k%2)
    {
        ans=A[r];
        r--;
        --k;
        if(ans<0)
            sign=1;
    }
    while(k)
    {
        ll x=A[l]*A[l+1],y=A[r]*A[r-1];
        if(sign)
        {
            if(x<y)
            {
                ans=x%mod*ans%mod;
                l+=2;
            }
            else
            {
                ans=y%mod*ans%mod;
                r-=2;
            }
        }
        else
        {
            if(x>y)
            {
                ans=x%mod*ans%mod;
                l+=2;
            }
            else
            {
                ans=y%mod*ans%mod;
                r-=2;
            }
        }
        k-=2;
    }
    cout<<(ans+mod)%mod<<endl;
    return 0;
}


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

int main() {

    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if (S == U) cout << A-1 << " " << B << endl;
    else cout << A << " " << B-1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
const int N=200001;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k,a[N],b,tn=0,ans=0;
	cin >> n >> k;
	CLR(a);
	for(int i=0;i<n;i++){
		cin >> b;
		if(a[b]==0)tn++;
		a[b]++;
	}
	sort(a,a+N);
	while(tn>k){
		for(int i=0;i<=N;i++){
			if(a[i]==0){

			}else{
				ans += a[i];
				tn--;
				if(tn<=k)break;
			}
		if(tn<=k)break;
		}
	}

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
string s;
map<string,int>f;
map<string,int>g;
int F(string s);
int G(string s){
    if(g.find(s)!=g.end())
    return g[s];
    if(s.size()==1)
    return g[s]=s[0]-'0'+1;
    for(int i=1;i<s.size();i++){
        if(s.size()%i==0){
            string t;
            for(int j=0;j<i;j++){
                int r=1;
                for(int k=0;k<s.size()/i;++k)
                if(s[i*k+j]=='0')
                r=0;
                t+=(char)(r+'0');
            }
            g[s]=(g[s]+F(t))%mod;
        }
    }
    return g[s];
}
int F(string s){
    if(f.find(s)!=f.end())
    return f[s];
    for(int i=1;i<=s.size();i++)
    f[s]=(f[s]+1ll*F(s.substr(0,s.size()-i))*G(s.substr(s.size()-i,i))%mod)%mod;
    return f[s];
}
int main(){
    cin>>s;
    f[""]=1;
    cout<<F(s)<<endl;
    return 0;
}

Measured memory_bytes: 12928
a=input()
n=len(a)
from collections import Counter
c=Counter()
dp=[0]*(n)
dp[0]=1
c[a[0]]=1
for i in range(1,n):
    dp[i]=dp[i-1]+i-c[a[i]]
    c[a[i]]+=1
print(dp[-1])

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

int main(){
  int A,B;
  cin >> A >> B;
  if(2 * A <= B && 4 * A >= B && B % 2 == 0){
    cout << "Yes" << endl;
  }
    else{
cout << "No" << endl;
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;

    rep(i, h){
        rep(j, w){
            cout << ((int)(i < b)^(int)(j < a));
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
const int INF=1000000000;
const int MAX_N=50;
const int MAX_M=50;
typedef pair<int,int> P;
char maze[MAX_N][MAX_N+1];
int N,M;
int sx,sy;
int gx,gy;
int d[MAX_N][MAX_N];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int bfs(){
  cin>>N>>M;
  int count =0;
  sx=0;
  sy=0;
  gx=N-1;
  gy=M-1;
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin>>maze[i][j];
      
      /*if(maze[i][j]=='S'){
        sx=i;
        sy=j;
      }else if(maze[i][j]=='G'){
        gx=i;
        gy=j;
      }*/
      if(maze[i][j]=='.')count++;
    }
  }
  if(maze[0][0]=='#'){
    return -1;
  }
  if(maze[N-1][M-1]=='#'){
    return -1;
  }
  queue<P>que;
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      d[i][j]=INF;
    }
  }
  que.push(P(sx,sy));
  d[sx][sy]=0;
  while(que.size()){
    P p=que.front();que.pop();
    if(p.first==gx&&p.second==gy)break;
    for(int i=0;i<4;i++){
      int nx=p.first+dx[i],ny=p.second+dy[i];
      if(0<=nx&&nx<N&&0<=ny&&ny<M&&maze[nx][ny]!='#'&&d[nx][ny]==INF){
        que.push(P(nx,ny));
        d[nx][ny]=d[p.first][p.second]+1;
      }
    }
  }
  return count-(d[gx][gy]+1);
}
int main(){
  int kotae=bfs();
  if(kotae<0){
    cout<<-1<<endl;
  }else{
    cout<<kotae<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
import math

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    md = 10 ** 9 + 7
    l, r = map(int, input().split())
    n = int(math.log2(r)) + 1
    # dp[i][t][f][g] i桁目まで見て最上位が決定済みか(t)、L<xが確定(f)、y<Rが確定
    dp = [[[[0] * 2 for _ in range(2)] for __ in range(2)] for ___ in range(n + 1)]
    dp[0][0][0][0] = 1
    ans = 0
    for i in range(n):
        lk = l >> (n - 1 - i) & 1
        rk = r >> (n - 1 - i) & 1
        for t in range(2):
            for f in range(2):
                for g in range(2):
                    pre = dp[i][t][f][g]
                    for x, y in [(0, 0), (0, 1), (1, 1)]:
                        nt, nf, ng = t, f, g
                        if t == 0 and (x, y) == (0, 1): continue
                        if f == 0 and lk > x: continue
                        if g == 0 and y > rk: continue
                        if (x, y) == (1, 1): nt = 1
                        if lk == 0 and x == 1: nf = 1
                        if y == 0 and rk == 1: ng = 1
                        if i == n - 1:
                            ans = (ans + pre) % md
                        else:
                            dp[i + 1][nt][nf][ng] = (dp[i + 1][nt][nf][ng] + pre) % md
    print(ans)

main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);	
	
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = min(k, a);
	ans -= max(0, k - a - b);
	cout << ans << endl;
}


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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,h[100000],dp[100000];

main() {
    cin >> n >> h[0] >> h[1];
    dp[1] = abs(h[0]-h[1]);
    repo(i,2,n) {
        cin >> h[i];
        dp[i] = min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1]);
    }
    ct(dp[n-1])
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
 
int main(){
  int n;
  cin>>n;
  
  ll V=0, E=0;
  rep(i,n) V+=1ll*(i+1)*(n-(i+1)+1);
  
  
  rep(i,n-1){
    int u, v;
    cin>>u>>v;
    if(u>v) swap(u,v);
    E+=1ll*u*(n-v+1);
  }
  
  ll ans;
  ans=V-E;
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
// D - Road to Millionaire
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int64_t yen = 1000, stock = 0;
	int nxt; cin>>nxt;
	while(--N){
		int now = nxt; cin>>nxt;
		if(now < nxt){
			stock += yen / now;
			yen -= yen / now * now;
		}
		else{
			yen += stock * now;
			stock = 0;
		}
	}
	cout<< yen + stock * nxt <<endl;
}


Measured memory_bytes: 3620
'''
N頂点M辺の有向グラフGの有向パスのうち最長のものを求めよ。
terms:
    2<=N<=10**5
    1<=M<=10**5
    (x_i,y_i)はすべて相異なる
    Gは有向閉路を含まない

input:
    4 5
    1 2
    1 3
    3 2
    2 4
    3 4
output:
    3
'''


from collections import defaultdict,deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))

n, m = inpl()
v = [[] for _ in range(n)]
for i in range(m):
    a, b = inpl()
    v[a - 1].append(b - 1)
'''
v[0]=[1,2]
v[1]=[3]
v[2]=[1,3]
'''

from functools import lru_cache
@lru_cache(maxsize=None)
def dp(x):
    r = 0
    for i in v[x]:
        r = max(r, dp(i) + 1)
    return r

res = max([dp(i) for i in range(n)])
print(res)

Measured memory_bytes: 144132
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scan = new Scanner(System.in);
        Integer N = scan.nextInt();
        Integer answer = 0;
        if(N / 100000 > 0) {
            answer = 90909;
        } else if(N / 10000 > 0) {
            answer = N - 10000 + 1 + 909;
        } else if(N / 1000 > 0) {
            answer = 909;
        } else if(N / 100 > 0) {
            answer = N - 100 + 1 + 9;
        } else if(N / 10 > 0) {
            answer = 9;
        } else if(N / 1 > 0) {
            answer = N;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 23124
h,w = map(int, input().split())
a = [list("*"*(w+2))]
for i in range(h):
  a.append(['*'] + list(input()) + ['*'])
a.append(list("*"*(w+2)))

b = [[0]*(w+2) for _ in range(h+2)]
direction = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans=0
for i in range(1,h+1):
  for j in range(1,w+1):
    if a[i][j]=='#' and b[i][j]==0:
      countw = countb = 0
      stackb = [(i, j)]
      stackw = []
      while stackb:
        xb, yb = stackb.pop(-1)
        if b[xb][yb] != 0: continue
        countb+=1
        b[xb][yb]=1
        for d in direction:
          p, q = xb + d[0], yb + d[1]
          if a[p][q]=='.' and b[p][q]==0:
            stackw.append((p, q))
        while stackw:
          xw, yw = stackw.pop(-1)
          if b[xw][yw] != 0: continue
          countw+=1
          b[xw][yw]=1
          for d in direction:
            p, q = xw + d[0], yw + d[1]
            if a[p][q]=='#' and b[p][q]==0:
              stackb.append((p, q))
      ans += countb*countw
print(ans)

Measured memory_bytes: 20704
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll N, M, C;
  cin >> N >> M >> C;

  vll B(M);
  rep(i, M) {
    cin >> B[i];
  }

  ll ans = 0;
  rep(i, N) {
    ll sum = C;
    rep(j, M) {
      ll a;
      cin >> a;
      sum += a * B[j];
    }
    if (sum > 0) {
      ans++;
    }
  }
  COUT(ans);
  return 0;
}

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

int N,C[200010];
int col_id[200010] = {};
int col_sum[200010] = {};
ll dp[200010] = {},inf = 1e9+7;
int main(){
    cin >> N;
    int c;
    for(int i=1;i<=N;i++){
        cin >> C[i];
    }
    dp[0] = 1;
    for(int i=1;i<=N;i++){
        (dp[i] += dp[i-1]+(C[i-1]!=C[i]? col_sum[C[i]]:0))%=inf;
        (col_sum[C[i]] = dp[i])%=inf;
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 3328
#include <iostream>

using namespace std;

long long int l[10];

int main(){
        int a,b,c,d,ans,i;
        char op1,op2,op3;
        cin >> ans;
        a = ans/1000;
        ans -= a*1000;
        b = ans/100;
        ans -= b*100;
        c = ans/10;
        d = ans%10;
        ans = a;
        for(i=0;i<8;i++){
                if(i<4)l[i]=ans+b;
                else l[i]=ans-b;
        }
        for(i=0;i<8;i+=2){
                l[i]+=c;
                l[i+1]-=c;
        }
        for(i=0;i<8;i++){
                if(i%4 == 0 || i%4== 1)l[i]+=d;
                else l[i]-=d;
        }
        for(i=0;i<8;i++){
                if(l[i]==7)break;
        }
        if(i<4)op1='+';
        else op1 = '-';
        if(i%2 == 0)op2 = '+';
        else op2 = '-';
        if(i%4 == 0 || i%4 == 1)op3 = '+';
        else op3 = '-';

        cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;

return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

class CombTools(object):
    def __init__(self, cap: int, mod: int):
        self.cap = cap
        self.mod = mod
        self.inv = self._calc_inv()
        self.fac = self._calc_fac()
        self.fac_inv = self._calc_fac_inv()

    def _calc_inv(self):
        inv = [0, 1]
        for i in range(2, self.cap+1):
            inv.append((self.mod - (self.mod // i) * inv[self.mod % i]) % self.mod)

        return inv

    def _calc_fac(self):
        fac = [1]
        for i in range(1, self.cap+1):
            fac.append((i * fac[-1]) % self.mod)

        return fac

    def _calc_fac_inv(self):
        fac_inv = [1]
        for i in range(1, self.cap+1):
            fac_inv.append((self.inv[i] * fac_inv[-1]) % self.mod)

        return fac_inv

    def nCr(self, n: int, r: int):
        # validation
        if r > n:
            raise ValueError("n must be larger than r (n={}, r={})".format(n, r))

        # calculation
        return self.fac[n] * self.fac_inv[n-r] * self.fac_inv[r] % self.mod

x, y = li()
MOD = 10**9 + 7

ct = CombTools(10**6, MOD)
n = (x+y) // 3

if (x+y)%3 != 0:
    print(0)
elif x < n or x > 2*n:
    print(0)
else:
    print(ct.nCr((x+y) // 3, x - (x+y) // 3))

Measured memory_bytes: 131888
#include<iostream> 
using namespace std; 
typedef long long ll; 
int main() 
{ 
		ios::sync_with_stdio(false); 
		cin.tie(NULL); 
		ll r;
		cin>>r; 
		float pi=3.1415; 
		float answer=2*r*pi;
		cout<<answer; 
		return 0; 
}


Measured memory_bytes: 3800
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> visit(m+1, false);
    vector<deque<int>> dq(n, deque<int>(m, 0));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m ;j++) {
            cin >> dq[i][j];
        }
    }
    int ans = n;
    for(int i = 0; i < m; i++) {
        unordered_map<int, int> cnt;
        int max_cnt = 0;
        int target = -1;
        for(int j = 0; j < n; j++) {
            if (++cnt[dq[j].front()] > max_cnt) {
                max_cnt = cnt[dq[j].front()];
                target = dq[j].front();
            }
        }
        ans = min(ans, max_cnt);
        visit[target] = true;
        for(int j = 0; j < n; j++) {
            while(!dq[j].empty() && visit[dq[j].front()] == true) {
                dq[j].pop_front();
            }
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 768
import java.util.*;
 
class Main {
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		int[][] a = new int[3][3];
		int[] b = new int[10];
		boolean[][] appear = new boolean[3][3];
		String ans = "No";
 
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				a[i][j] = sc.nextInt();
				appear[i][j] = false;
			}
		}
 
		int n = sc.nextInt();

		for(int i = 0; i < n; i++){
			b[i] = sc.nextInt();
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 3; k++){
					if(a[j][k] == b[i]){
						appear[j][k] = true;
					}
				}
			}
		}
 
		for(int i = 0; i < 3; i++){
			if(appear[i][0] && appear[i][1] && appear[i][2])
				ans = "Yes";
		}
		for(int i = 0; i < 3; i++){
			if(appear[0][i] && appear[1][i] && appear[2][i])
				ans = "Yes";
		}
		if(appear[0][0] && appear[1][1] && appear[2][2]){
			ans = "Yes";
		}
		if(appear[0][2] && appear[1][1] && appear[2][0]){
			ans = "Yes";
		}
		System.out.println(ans);
	}
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vll arr (N);
	F0R(i, N) {
		cin >> arr[i];
	}
	sort(arr.rbegin(), arr.rend());
	
	ll ans = 0;
	ans += arr[0];
	N -= 2;
	int i = 1;
	while (N >= 2) {
		ans += 2 * arr[i]; ++i; N -= 2;
	}
	if (N) ans += arr[i];
	print(ans);
}

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

#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0);
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(ll x=j;x<n;x++)
#define repr(x,j,n)for(ll x=j;x>n;x--)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
const int N=2e6+7;

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
    if(b&1)
    r=(r*a)%m;
    b=b/2;
    a=(a*a)%m;
    }
    return r%m;
}
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int t=0;
    while(a>0&&c>0)
    {
        if(t==0)c-=b;
        else a-=d;
        t=t+1;
        t%=2;
    }
    if(a<=0)cout<<"No";
    else cout<<"Yes";





















}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int b[100010];
int c[100010];
int d[100010];
int main()
{
    int n;
    long long sum=0,sum1=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)
        b[n-i+1]=a[i];
    int r=1;
    for(int i=1;i<=n/2;i++)
    {
        c[r++]=b[i];d[r-1]=a[i];
        c[r++]=a[i];d[r-1]=b[i];
    }
    if(n&1)
    {
        for(int i=2;i<r;i++)
            sum+=abs(c[i]-c[i-1]),sum1+=abs(d[i]-d[i-1]);

        sum+=max(abs(c[n-1]-a[n/2+1]),abs(c[1]-a[n/2+1]));
        sum1+=max(abs(d[n-1]-a[n/2+1]),abs(d[1]-a[n/2+1]));
        if(sum<sum1)
            sum=sum1;
        printf("%lld\n",sum);
    }
    else
    {
        for(int i=2;i<r-1;i++)
            sum+=abs(c[i]-c[i-1]);
        sum+=max(abs(c[n-1]-a[n/2]),abs(c[1]-a[n/2]));
        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 1792
/***********************************************
 *                   _ooOoo_                   *
 *                  o8888888o                  *
 *                  88" . "88                  *
 *                  (| -_- |)                  *
 *                  O\  =  /O                  *
 *               ____/`---'\____               *
 *             .'  \\|     |//  `.             *
 *            /  \\|||  :  |||//  \            *
 *           /  _||||| -:- |||||-  \           *
 *           |   | \\\  -   * |    |           *
 *           | \_|  ''\---/''  |   |           *
 *           \  .-\__  `-`  ___/-. /           *
 *         ___`. .'  /--.--\  `. . __          *
 *      ."" '<  `.___\_<|>_/___.'  >'"".       *
 *     | | :  `- \`.;`\ _ /`;.`/ - ` : | |     *
 *     \  \ `-.   \_ __\ /__ _/   .-` /  /     *
 *======`-.____`-.___\_____/___.-`____.-'======*
 *                   `=---='                   *
 *^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

             佛祖保佑       永无BUG

   本程序已经经过开光处理，绝无可能再产生bug
 **********************************************/
#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define ll long long
#define INF 0x3f3f3f3f
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
using namespace std;

int main(void)
{
    #ifdef test
    freopen("in.txt","r",stdin);
    //freopen("in.txt","w",stdout);
    clock_t start=clock();
    #endif //test

    int h,a;
    scanf("%d%d",&h,&a);
    if(h%a==0)printf("%d\n",h/a);
    else printf("%d\n",h/a+1);

    #ifdef test
    clockid_t end=clock();
    double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    printf("\n\n\n\n\n");
    cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位
    cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位
    #endif //test
    return 0;
}


// ━━━━━━神兽出没━━━━━━
//      ┏┓       ┏┓
//     ┏┛┻━━━━━━━┛┻┓
//     ┃           ┃
//     ┃     ━     ┃
//     ????━????   ┃
//     ┃           ┃
//     ┃    ┻      ┃
//     ┃           ┃
//     ┗━┓       ┏━┛
//       ┃       ┃
//       ┃       ┃
//       ┃       ┗━━━┓
//       ┃           ┣┓
//       ┃           ┏┛
//       ┗┓┓┏━━━━━┳┓┏┛
//        ┃┫┫     ┃┫┫
//        ┗┻┛     ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))

_sum=sum(A[1:])
mod=10**9+7
re=0
for i in range(0,N-1):
    re+=A[i]*_sum
    _sum-=A[i+1]
    re%=mod
    _sum%=mod
print(re%mod)


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

int main(){
    long N;
    cin >> N;
    vector<LL> a,b,c;
    long bm[N];
    fill(bm,bm+N,0);
    for(int i=0;i<N;i++){
        LL s;
        cin >> s;
        a.push_back(-s);
    }
    for(int i=0;i<N;i++){
        LL s;
        cin >> s;
        b.push_back(s);
    }
    for(int i=0;i<N;i++){
        LL s;
        cin >> s;
        c.push_back(s);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    LL count=0;
    for(int i=0;i<N;i++){
        auto aitr=upper_bound(a.begin(),a.end(),-b[i]);
        auto citr=upper_bound(c.begin(),c.end(),b[i]);
        count+=(a.end()-aitr)*(c.end()-citr);
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4720
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
int dp[101010];

int main(){
  int n,k;
  cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];
  dp[0]=2;
  for(int i=1;i<k+1;i++){
    rep(j,n){
      int x = a[j];
      if(i-x>=0&&dp[i-x]==2){
        dp[i]=1;
      }
    }
    if(dp[i]==0) dp[i]=2;
  }
  /*rep(i,n){
    cout << a[i] << " ";
  }
  cout << endl;*/
  /*rep(i,k+1){
    cout << dp[i] << " ";
  }
  cout << endl;*/
  if(dp[k]==2) cout << "Second";
  else cout << "First";
}

Measured memory_bytes: 640
import math
def prime_array(n=1000):
	List = [2]
	i = 3
	while i <= n:
		judge = True
		for k in List :
			if math.sqrt(i) < k :
				break
			if i%k == 0:
				judge = False
				break
		if judge :
			List.append(i)
		i += 2
	return List
def main():
	cnt=0
	prime_List=prime_array(10**4)
	n=input()
	for i in range(n):
		a=input()
		if a<=10**4:
			for j in prime_List:
				if a==j:
					cnt+=1
					break
		else:
			judge=True
			for j in prime_List:
				if a%j==0:
					judge=False
					break
			if judge:
				cnt+=1
	print('%d' % cnt)
if __name__=='__main__':
	main()

Measured memory_bytes: 6704
<?php
$person = nextInt();
for ($i = 0; $i < 5; $i++) {
  $canMove[] = nextInt();
}

$a = min($canMove);
echo (int)ceil($person / $a) + 4, PHP_EOL;

function nextInt()
{
  return (int) trim(fgets(STDIN));
}


Measured memory_bytes: 4604
import math
a,b,x=map(int,input().split())

if x>=a*a*b/2:
    ans=math.degrees(math.atan(2*(a*a*b-x)/(a*a*a)))
else:
    ans=math.degrees(math.pi/2-math.atan(2*x/(a*b*b)))

print(ans)

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, K;
std::vector<int> H, v;
ll dp[310][310][310];

inline ll f(int h1, int h2){
    if(h1 > h2){
        return h1 - h2;
    }

    return 0;
}

ll rec(int i, int h, int c){
    if(i == N){
        return v[h];
    }

    if(dp[i][h][c] != -1){
        return dp[i][h][c];
    }

    ll res = f(v[h], v[H[i]]) + rec(i + 1, H[i], c);

    if(c < K){
        res = std::min(res, rec(i + 1, h, c + 1));
        res = std::min(res, f(v[h], 0) + rec(i + 1, 0, c + 1));
    }

    return dp[i][h][c] = res;
}

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

  std::cin >> N >> K;

  H.resize(N);
  v.resize(N);

  for(int i=0;i<N;++i){
      std::cin >> H[i];
  }

  std::copy(H.begin(), H.end(), v.begin());
  v.emplace_back(0);
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
  
  for(int i=0;i<N;++i){
      H[i] = std::lower_bound(v.begin(), v.end(), H[i]) - v.begin();
  }

  memset(dp, -1, sizeof(dp));

  ll res = rec(1, H[0], 0);

  if(K >= 1){
      for(int i=0;i<v.size();++i){
          res = std::min(res, rec(1, i, 1));
      }
  }

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


Measured memory_bytes: 233088
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
def main():
    N = int(readline())
    tasks = np.array(read().split(), np.int64).reshape((-1, 2))
    tasks = tasks[np.argsort(tasks[..., 1]), ...]
    tasks[..., 0] = np.add.accumulate(tasks[..., 0], axis=0)
    tmp = tasks[..., 1]-tasks[..., 0]
    if np.all(tmp>=0):
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()


Measured memory_bytes: 36392
import sys
input = sys.stdin.readline
n,m = input().split()
n = int(n)
m = int(m)
x = input().split()
for i in range(m):
    x[i] = int(x[i])
x.sort()
l = [0 for i in range(m-1)]
for i in range(m-1):
    l[i] = x[i+1] - x[i]
l.sort()
sum = 0
if n >= m:
    print(0)
else:
    for i in range(n-1):
        sum += l[m-2-i]
    dist = x[m-1] - x[0]
    print(dist-sum)

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

int main() {
	int N;
	cin >> N;
	vector<int> P(N);
	for (int i = 0; i < N; i++) {
		cin >> P.at(i);
	}

	int min_P = P.at(0), ans = 0;
	for (int i = 0; i < N; i++) {
		if (min_P >= P.at(i)) {
			ans++;
		}
		if (min_P > P.at(i)) {
			min_P = P.at(i);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { parse(&get_word()) }

fn main() {
    let n = get();
    let a: Vec<i64> = (0 .. n).map(|_| get()).collect();
    let mut ans: Vec<i64> = vec![0; n];
    let mut delta: Vec<i64> = vec![0; n];
    {
        let mut cur = 0;
        for i in 0 .. n {
            if cur < a[i] {
                delta[i] = a[i] - cur;
                cur = a[i];
            }
        }
    }
    let mut srt = Vec::new();
    for i in 0 .. n {
        srt.push((a[i], i));
    }
    srt.push((0, 114514));
    srt.sort();
    srt.reverse();
    let mut mi = n;
    for i in 0 .. srt.len() - 1 {
        let diff = srt[i].0 - srt[i + 1].0;
        mi = min(mi, srt[i].1);
        ans[mi] += diff * (i + 1) as i64;
    }
    for i in 0 .. n {
        println!("{}", ans[i]);
    }
}


Measured memory_bytes: 11260
#include<iostream>
using namespace std;
int main()
{
    int N;
    while(cin>>N)
    {
        unsigned long long   sum=1;
        unsigned long long  M=1e9+7;
        int i;
        for(i=1;i<=N;i++)
        {
            sum*=i;
            sum%=M;
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	int n;
	int[] a;
	long[][] dp;

	long dp(int k, int sum) {
		if (sum < 0 || 20 < sum) {
			return 0;
		}
		if (k == 0) {
			if (a[k] == sum) return 1;
			return 0;
		}
		if (0 <= dp[k][sum]) {
			return dp[k][sum];
		}

		long res = 0;
		res += dp(k - 1, sum - a[k]);
		res += dp(k - 1, sum + a[k]);
		return dp[k][sum] = res;
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		dp = new long[n][10*n + 5];
		for (int i = 0; i < n; i++) {
			Arrays.fill(dp[i], -1);
		}
		System.out.println(dp(n - 2, a[n - 1]));
	}

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

Measured memory_bytes: 22296
N = int(input())

S = []
P = []

cities = {}

for i in range(N):
    line = input().split()
    try:
        cities[line[0]].append(i)
    except:
        cities[line[0]] = [i]
    S.append(line[0])
    P.append(int(line[1]))

for k, v in sorted(cities.items()):
    v = sorted(v, key=lambda x: -P[x])
    for vv in v:
        print(vv+1)


Measured memory_bytes: 3060
#include<stdio.h>

int main(void) {
	int n;
	int l[5001];
	scanf("%d", &n);
	int i, j, k;
	int count = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &l[i]);
	}
	for(i = 2; i < n; i++) {
		for (j = 1; j < i; j++) {
			for(k = 0; k < j; k++) {
				if (l[k] < l[j] + l[i]) {
					if (l[j] < l[k] + l[i]) {
						if (l[i] < l[k] + l[j]) {
							count++;

						}
					}

				}

			}
		}
	}
	printf("%d", count);

	return 0;
}



Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

const int N=1e5+1e3+7;

char s[N],last[N];

int vis[N];

int main()
{
	scanf("%s",s);
	int n=strlen(s);
	for(int i=0;i<n;i++)
		last[i]=s[i];
	if(n==26)
	{
		
		if(next_permutation(s,s+n))
		{
			for(int i=0;i<n;i++)
			{
				putchar(s[i]);
				if(s[i]!=last[i])
					break;
			}
		}
		else
			puts("-1");
		exit(0);
	}
	printf("%s",s);
	for(int i=0;i<n;i++)
		vis[s[i]-'a']=1;
	for(int i=0;i<26;i++)
		if(!vis[i])
		{
			putchar(i+'a');
			exit(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
def cal(x,y,z)
    return x**2+y**2+z**2+x*y+y*z+z*x
end
ans=array(N+1,0)
1.upto(100) do|x|
    1.upto(100) do|y|
        1.upto(100) do|z|
          next if cal(x,y,z)>N
          ans[cal(x,y,z)]+=1
        end
    end
end
1.upto(N) do|i|
    puts ans[i]
end

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

int main(){
    ll N, A, B; cin >> N >> A >> B;
    ll ans = 0;
    ll a = 0;
    ans = N / (A+B) * A;
    a = N % (A+B);
    if(a > A) ans += A;
    else ans += a;
    cout << ans << endl;
}

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

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

Measured memory_bytes: 256
n,x,y=map(int,input().split())
k=[0]
k*=(n-1)
z=x-y
for i in range(1,n+1):
    for j in range(i+1,n+1):
        ans1=j-i
        ans2=abs(x-i)+abs(y-j)+1
        ans3=abs(x-j)+abs(y-i)+1
        ans=min(ans1,ans2,ans3)
        k[ans-1]+=1
        
for i in range(n-1):
    print(k[i])

Measured memory_bytes: 9256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=998244353,MAX=200005,INF=1<<30;

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

ll dp[MAX][2];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,M;cin>>N>>M;
    map<pair<int,int>,int> MA;
    
    ll ok=true;
    ll free=max(0LL,(N-2)*(N-3)/2);
    for(int i=0;i<M;i++){
        int a,b,c;cin>>a>>b>>c;
        a--;b--;
        MA[{a,b}]=c;
        if(abs(a-b)>=3){
            if(MA.count({b,a})){
                if((MA[{a,b}]+MA[{b,a}])&1) ok=false;
            }else free--;
        }
    }
    
    if(!ok){
        cout<<0<<endl;
        return 0;
    }
    
    ll ans=rui(2,free);
    
    for(int bit=0;bit<(1<<4);bit++){
        if(__builtin_popcount(bit)&1) continue;
        bool can=true;
        for(int i=0;i<2;i++){
            for(int j=0;j<2;j++){
                if(MA.count({i,j})){
                    int a=bit&(1<<(i*2+j)),b=MA[{i,j}];
                    if(a&&!b) can=false;
                    if(!a&&b) can=false;
                }
            }
        }
        if(can) dp[1][(bit&(1<<3))==(1<<3)]++;
    }
    
    for(int i=1;i<N-1;i++){
        for(int j=0;j<2;j++){
            if(dp[i][j]==0) continue;
            
            for(int bit=0;bit<(1<<5);bit++){
                if(__builtin_popcount(bit)&1) continue;
                
                int z=0;
                if(bit&(1<<3)) z++;
                if(bit&(1<<1)) z++;
                if(bit&(1<<0)) z++;
                
                if((j+z)&1) continue;
                
                bool can=true;
                for(int x=0;x<3;x++){
                    for(int y=0;y<3;y++){
                        if(x<=1&&y<=1) continue;
                        if(MA.count({i-1+x,i-1+y})){
                            int a,b=MA[{i-1+x,i-1+y}];
                            if(x==0) a=bit&(1<<4);
                            else if(x==1) a=bit&(1<<3);
                            else if(y==0) a=bit&(1<<2);
                            else if(y==1) a=bit&(1<<1);
                            else a=bit&(1<<0);
                            
                            if(a&&!b) can=false;
                            if(!a&&b) can=false;
                        }
                    }
                }
                
                if(can){
                    dp[i+1][bit&1]+=dp[i][j];
                    dp[i+1][bit&1]%=mod;
                }
            }
        }
    }
    
    cout<<ans*((dp[N-1][0]+dp[N-1][1])%mod)%mod<<endl;
}



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

int main() {
    string S;
    cin >> S;
    int char_size = (S.size() + 1) / 2;
    char O[char_size];
    int j = 0;
    for (int i = 0; i < S.size(); i++) {
        if ((i + 1) % 2 != 0) {
            O[j] = S.at(i);
            j++;
        }
    }
    for (auto o : O) cout << o;
    cout << endl;
}


Measured memory_bytes: 512
n, l = gets.chomp.split(" ").map{|i| i.to_i}

s = Array.new(n)

for i in 0...n
  s[i] = gets.chomp
end


z = ""

for k in 0...n
  x = s[0]
  y = 0
  for i in 0...n-k
    if x > s[i]
      x = s[i]
      y = i
      # puts "x = #{x}"
    end
  end
  
  s.delete_at(y)
  z = z + x
  
  # p s
end

puts z




Measured memory_bytes: 2300
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
const int MO=998244353;
LL ans;
int sum,n,a[500010],b[500010],f[310][90010][2][2];
LL pw(LL x,LL y){
	LL t=1;
	for (;y;y>>=1){
		if (y&1) t=t*x%MO;
		x=x*x%MO;
	}
	return t;
}
int main(){
	cin>>n;
	FOR(i,1,n) getint(a[i]),sum+=a[i];
	f[0][0][0][0]=1;
	FOR(i,0,n-1)
		FOR(j,0,i*300)
			FOR(k,0,1)
				FOR(l,0,1)
					if (f[i][j][k][l]){
						int t=f[i][j][k][l];
						(f[i+1][j+a[i+1]][k][l]+=t)%=MO;
						(f[i+1][j][1][l]+=t)%=MO;
						(f[i+1][j][k][1]+=t)%=MO;
					}
	FOR(i,0,sum)
		if (sum-i<=i){
			(ans+=f[n][i][1][1]*3ll)%=MO;
		}
	ans=-ans;
	
	(ans+=pw(3,n))%=MO;
	(ans-=3*pw(2,n))%=MO;
	(ans+=3)%=MO;
	ans=(ans%MO+MO)%MO;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 424192
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int n;
int a[N], ans[N];

int32_t main()
{
	IOS;
	cin >> n;
	for(int i = 2; i <= n; i++)	
	{
		int par;
		cin >> par;
		ans[par]++;
	}
	for(int i = 1; i <= n; i++)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 5220