akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;
#define inf 1e9

int main() {
    int n, maxi=0,index;
    cin>>n;
    vector<int> a(n),b(n);
    vector<int> c(n+1,0),d(n+1,0);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n) c[i+1]=c[i]+a[i];
    rep(i,n) d[i+1]=d[i]+b[i];
    int ans=-inf;
    for (int i=1; i<n+1; i++) {
        int res=0;
        res+=c[i];
        res+=d[n]-d[i-1];
        ans=max(ans,res);
    }
    cout<<ans<<endl;
} 


Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <iostream>
using namespace std;

int main() {
	int n;
	long double v,y;
	while (cin >> v) {
		y = v * v / 9.8 / 2;
		n = y/5;
		if (n*5 < y)
			n++;
		cout << n + 1 << endl;
	}
	return 0;
}




Measured memory_bytes: 3176
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    S = input().strip()
    T = input().strip()

    res = len(T)
    for i in range(len(S) - len(T) + 1):
        res = min(res, sum(1 if s != t else 0 for s, t in zip(S[i:], T)))

    print(res)

if __name__ == "__main__":
    main()



Measured memory_bytes: 68588
#include<iostream>
#include<cstdio>
#include<set>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<string>
#include<vector>
#include<queue>
#define mp make_pair
#define pb push_back
#define INF 100000005
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
typedef long long int ll;

int main(){
    double x[105][2];
    int N;
    double ans1=0.0,ans2=0.0;
    scanf("%d",&N);
    vector<double> xs;
    rep(i,N){
        cin>>x[i][0]>>x[i][1];
        xs.pb(x[i][0]);
    }
    x[N][0]=x[0][0];
    x[N][1]=x[0][1];
    sort(xs.begin(),xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());
    vector<double> yl,yr;
    rep(i,xs.size()-1){
        yl.clear();
        yr.clear();
        double wid=xs[i+1]-xs[i];
        rep(j,N){
            if(x[j][0]!=x[j+1][0]){
                if((x[j][0]<=xs[i]&&xs[i+1]<=x[j+1][0])||(x[j+1][0]<=xs[i]&&xs[i+1]<=x[j][0])){
                    yl.pb((x[j][1]*(x[j+1][0]-xs[i])+x[j+1][1]*(xs[i]-x[j][0]))/(x[j+1][0]-x[j][0]));
                    yr.pb((x[j][1]*(x[j+1][0]-xs[i+1])+x[j+1][1]*(xs[i+1]-x[j][0]))/(x[j+1][0]-x[j][0]));
                }
            }
        }
        sort(yl.begin(),yl.end());
        sort(yr.begin(),yr.end());
//        rep(j,yl.size()){
//            cout<<xs[i]<<": l "<<yl[j]<<endl;
//        }
//        rep(j,yr.size()){
//            cout<<xs[i]<<": r "<<yr[j]<<endl;
//        }
        assert(yl.size()%2==0);
        assert(yr.size()%2==0);
        rep(j,yl.size()/2){
            double len = yl[j*2+1]-yl[j*2];
            ans1+=len*(wid/4.0+1.0/8.0);
            ans2+=len*(wid/4.0-1.0/8.0);
        }
        rep(j,yr.size()/2){
            double len = yr[j*2+1]-yr[j*2];
            ans1+=len*(wid/4.0-1.0/8.0);
            ans2+=len*(wid/4.0+1.0/8.0);
        }
    }
    printf("%.6f\n",max(ans1,ans2));
}

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

using namespace std;
typedef pair<int, int> P;
const int MAXC = 40;
const int MAXN = 510;
const int INF = 1e9 + 7;

int n, c;
int d[MAXC][MAXC], grid[MAXN][MAXN];
int cnt[3][MAXC];

void solve() {
  for (int i=0;i<n;i++) {
    for (int j=0;j<n;j++) {
      cnt[(i + j + 2) % 3][grid[j][i]-1]++;
    }
  }
  vector<P> minCost[3];
  for (int i=0;i<3;i++) {
    for (int j=0;j<c;j++) {
      int tmp = 0;
      for (int k=0;k<c;k++) {
        tmp += cnt[i][k] * d[j][k];
      }
      minCost[i].push_back(P(tmp, j));
    }
    sort(minCost[i].begin(), minCost[i].end());
  }
  int cost = INF;
  for (int i=0;i<3;i++) {
    for (int j=0;j<3;j++) {
      for (int k=0;k<3;k++) {
        if (minCost[0][i].second != minCost[1][j].second &&
            minCost[1][j].second != minCost[2][k].second &&
            minCost[2][k].second != minCost[0][i].second) {
          cost = min(cost, minCost[0][i].first + minCost[1][j].first + minCost[2][k].first);
        }
      }
    }
  }
  cout << cost << endl;
}

int main() {
  cin >> n >> c;
  for (int i=0;i<c;i++) {
    for (int j=0;j<c;j++) {
      cin >> d[j][i];
    }
  }
  for (int i=0;i<n;i++) {
    for (int j=0;j<n;j++) {
      cin >> grid[j][i];
    }
  }
  solve();
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
const int MN = 100;
const int MW = 10000;

int dp[MN+1][MW+1];
vector<int> v,w;

int main(){
    int N,W;

    cin >> N >> W;

    for(int i=0; i<N; i++){
        int s,t;
        cin >> s >> t;
        v.push_back(s);
        w.push_back(t);
    }

    for(int i=0; i<N; i++){
        for(int j=0; j<=W; j++){
            if(j < w[i]){
                dp[i+1][j] = dp[i][j];
            }else{
                dp[i+1][j] = max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
            }
        }
    }

    cout << dp[N][W] << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> q(n);
    for (int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        q[p - 1] = i;
    }

    string ans;
    stack<int> st;
    int count_closing_parenthesis = 0;
    for (int i = 0; i < n; ++i) {
        ans += "(";
        st.push(q[i]);

        while (st.size() && count_closing_parenthesis == st.top()) {
            ans += ")";
            st.pop();
            count_closing_parenthesis++;
        }
    }
    if (!st.empty()) {
        cout << ":(" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits.h>
#include <queue>
#include <map>
#include <ctime>
#include <set>
 
#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) a.begin(),a.end()
 
using namespace std;
 
int main(){
	int n;
	cin >> n;
	vector<int> dp(n+1);
	rip(i,n,0){
		dp[i+1]=dp[i]+1;
		int co=6;
		while(co<=i+1){
			dp[i+1]=min(dp[i+1],dp[i+1-co]+1);
			co*=6;
		}
		co=9;
		while(co<=i+1){
			dp[i+1]=min(dp[i+1],dp[i+1-co]+1);
			co*=9;
		}
	}
	cout << dp[n] << endl;
}

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

int main() {
	ll n,k;
	cin >> n >> k;
	ll ans = 0;
	ll kbai = n / k;
	ans += kbai*kbai*kbai;
	if (k%2==0) {
		ll lbai = (n-k/2) / k + 1;
		if (2*n<k) lbai = 0;
		ans += lbai*lbai*lbai;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int main(){
    int x,y;
    scanf("%d %d",&x,&y);
    if(2*x<=y && y<=4*x && y%2==0){
        printf("Yes");
        return 0;
    }
    printf("No");
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    
    int ans = -1;
    for(int i = 1; i < s.size(); i++) {
        string ss = s.substr(0, s.size() - i);
        int n1 = ss.size()/2;
        int n2 = ss.size() - n1;
        string s1 = ss.substr(0, n1);
        string s2 = ss.substr(n1, n2);
        if(s1 == s2) ans = max(ans, (int)ss.size());
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
	int d, n;
	cin >> d >> n;
	
	if( d == 0 ) {
		if( n == 100 ) {
			cout << 101 << endl;
		} else {
			cout << n << endl;
		}
	}
	else if( d == 1 ) {
		if( n == 100 ) {
			cout << 100*101 << endl;
		} else {
		 	cout << n*100 << endl;
		}
	}
	else {
		if( n == 100 ) {
			cout << 10000*101 << endl;
		} else {
			cout << n*10000 << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
ll const mod = 1e9 + 7;
int c[2001] {0};
 
void bfs(vector<int> graph[], int src, int V)
{
    queue<int> q;
    q.push(src);
    
    bool visited[V] {false};
    int dist[V] {0};
    
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        visited[u]=true;
        
        for(int i=0;i<graph[u].size();i++)
        {
            if(!visited[graph[u][i]])
            {
                visited[graph[u][i]]=true;
                dist[graph[u][i]]=1+dist[u];
                q.push(graph[u][i]);
            }
        }
    }
    for(int i=0;i<V;i++)
        c[dist[i]]++;
}
 
int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, x, y;
    cin>>n>>x>>y;
    x--;y--;
    vector<int> a[n];
    for(int i=0;i<n-1;i++)
    {
        a[i].push_back(i+1);
        a[i+1].push_back(i);
    }
    a[x].push_back(y);
    a[y].push_back(x);
    
    
    for(int i=0;i<n;i++)
    bfs(a, i,  n);
    
    for(int i=1;i<n;i++)
    cout<<c[i]/2<<'\n';
    
	// your code goes here
	return 0;
}

Measured memory_bytes: 384
#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 yes cout << "Yes" << endl
#define no cout << "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 = INF;
    
    int N, K;
    cin >> N;
    vector<int> h(N);
    cin >> K;
    REP (i, N) {
        cin >> h[i];
    }
    SORT(h);
    REP(i,N-K+1) ans = min(ans, h[i+K-1]-h[i]);
    cout << ans << endl;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc115/abc115_c && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc115/abc115_c && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc115/abc115_c && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3964
import sys
sys.setrecursionlimit(10**7)
N=int(input())
table=[[] for i in range(N)]
for i in range(N-1):
    w,v=map(int,input().split())
    table[w-1].append(v-1)
    table[v-1].append(w-1)
mod=10**9+7
f=[-1]*N
g=[-1]*N
def ser(par,son):
    if f[son]!=-1 and g[son]!=-1:
        return f[son],g[son]
    s=1
    t=1
    for grason in table[son]:
        if grason==par:
            continue
        x,y=ser(son,grason)
        s*=x
        s%=mod
        t*=(x+y)
        t%=mod
    f[son],g[son]=t,s
    return t,s
z=1
w=1
for i in table[0]:
    ser(0,i)
    z*=f[i]
    z%=mod
    w*=(f[i]+g[i])
    w%=mod
print((z+w)%mod)

Measured memory_bytes: 218572
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
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(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
        int n, m, p;
        while(scanf("%d%d%d", &n, &m, &p) && n){
                --m;
                int x[n], sum=0;
                rep(i, n){
                        scanf("%d", &x[i]);
                        sum+=x[i];
                }
                if(x[m]==0){
                        printf("%d\n", 0);
                        continue;
                }
                printf("%d\n", sum*(100-p)/x[m]);
        }
}


Measured memory_bytes: 3236
n,a,b = map(int,input().split())

mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def com(n,k,mod=10**9+7):
    u = 1
    s = 1
    for i in range(n,n-k,-1):
        u = u*i % mod
    for i in range(k,0,-1):
        s = s*i % mod
    return u * modinv(s)

c = pow(2,n,mod)
c -= 1
c -= com(n,a)
c -= com(n,b)
print(c%mod)

Measured memory_bytes: 38848
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 110


int main(){
  int h,w;
  char chair[SIZE][SIZE];
  
  scanf("%d%d",&h,&w);

  for(int i=0;i<h;i++) scanf("%s",chair[i]);

  int ans = 0;
  
  for(int i=1;i<h;i++){
    for(int j=0;j<w;j++){
      bool flag = chair[i][j]=='-';
      
      if(j > 0 && chair[i][j-1]!='-') flag = false;
      if(j < w-1 && chair[i][j+1]!='-') flag = false;

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

      for(int k=0;k<8;k++){
        if(0<=i+dy[k] && i+dy[k]<h && 0<=j+dx[k] && j+dx[k]<w)
          flag &= chair[i+dy[k]][j+dx[k]]!='x';
      }

      ans += flag;
    }
  }

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

Measured memory_bytes: 3228
n = gets.to_i
s = n.times.map { gets.chomp }

h = Hash.new(0)
s.each do |word|
  h[word] += 1
end

maxi = h.values.max

ans = []
h.each_pair do |k,v|
  if v == maxi
    ans << k
  end
end

ans.sort.each do |word|
  puts word
end


Measured memory_bytes: 41444
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int64_t K;
int32_t to[33][5000];
int64_t score[33][5000];

int main()
{
    using std::endl;
    in.sync_with_stdio(false);
    out.sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);

    in >> N >> K;

    for (int32_t i = 0; i < N; i++)
    {
        in >> to[0][i]; --to[0][i];
    }
    for (int32_t i = 0; i < N; i++)
    {
        in >> score[0][i];
    }

    for (int32_t d = 1; d < 33; d++)
    {
        for (int32_t i = 0; i < N; i++)
        {
            to[d][i] = to[d - 1][to[d - 1][i]];
            score[d][i] = score[d - 1][i] + score[d - 1][to[d - 1][i]];
        }
    }

    int64_t res = -11000000000;
    for (int32_t i = 0; i < N; i++)
    {
        int64_t pos = i;
        int64_t nscore = 0;
        for (int32_t c = 0; c < std::min<int64_t>(K, N+100); c++)
        {
            nscore += score[0][pos];
            pos = to[0][pos];
            res = std::max(res, nscore);
        }

        for (int64_t k = std::max<int64_t>(1, K - N - 1); k <= K; k++)
        {
            pos = i;
            nscore = 0;
            int32_t count = 32;
            int64_t mask = ((int64_t)(1)) << count;
            while (mask > 0) {
                if (k & mask) {
                    nscore += score[count][pos];
                    pos = to[count][pos];
                }
                --count;
                mask >>= 1;
            }
            res = std::max(res, nscore);
        }
    }

    out << res << endl;
    return 0;
}
#endif


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

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n)cin >> v[i];
	sort(v.begin(),v.end());
	cout << v[n/2] - v[n/2-1] << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("%s = %d\n", #x, x)
#define debug2(x, y) printf("%s = %d, %s = %d\n", #x, x, #y, y)
#define debug3(x, y, z) printf("%s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z)
#define debug4(x, y, z, t) printf("%s = %d, %s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z, #t, t)
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

ll a, b, g, divisors;
set<ll> choices;

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

ll prime_divisors(ll n) {
    ll res = 0;

    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res++;

            while (n % i == 0) {
                n = n / i;
            }
        }
    }

    if (n > 1) {
        res++;
    }

    return res;
}

int main() {
    scanf("%lld%lld", &a, &b);
    g = gcd(a, b);

    divisors = prime_divisors(g);

    printf("%lld\n", divisors + 1);

    return 0;
}

Measured memory_bytes: 256
import math
from collections import Counter

N, A, B = map(int, input().split())
v = list(map(int, input().split()))

v.sort(reverse = True)
cnt_v = Counter(v)
ave = []

for i in range(A, B+1):
    ave.append(sum(v[0:i]) / i)

max_ave = max(ave)
ans = 0

for j in range(B-A+1):
    temp = 1
    if ave[j] == max_ave:
        l = v[:A+j]
        cnt_l = Counter(l)
        for key, values in cnt_l.items():
            temp *= (math.factorial(cnt_v[key]) // math.factorial(values) // math.factorial(cnt_v[key] - values))
        ans += temp

print(max_ave)
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
main()
{
  int N, l;
  cin >> N >> l;
  string a[110];
  for (int i = 0; i < N; i++)
  {
    cin >> a[i]; 
   } 
 sort(a, a + N);
  for (int i = 0; i < N; i++)
  {
    cout << a[i];
  }
  cout << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N,M;
vector<int> L,R,X;
vector<int> ri[303];

i64 dp[303][303][303];
i64 MOD = 1e9 + 7;
int main(){
  cin >> N >> M;
  L.resize(M);
  R.resize(M);
  X.resize(M);
  rep(i,0,M - 1) cin >> L[i] >> R[i] >> X[i];
  rep(i,0,M - 1) ri[R[i]].push_back(i);
  dp[0][0][0] = 1;

  rep(r,0,N - 1){
    rep(g,0,N - 1){
      rep(b,0,N - 1){
        int next = max({r,g,b}) + 1;
        //red
        {
          bool ok = true;
          int MIN = min({g,b});
          int MAX = max({g,b});
          for(auto idx : ri[next]){
            int cnt = 1;
            if(MAX >= L[idx]) cnt++;
            if(MIN >= L[idx]) cnt++;
            ok = ok && cnt == X[idx];
          }
          if(ok){
            dp[next][g][b] += dp[r][g][b];
            dp[next][g][b] %= MOD;
          }
        }
        {
          bool ok = true;
          int MIN = min({r,b});
          int MAX = max({r,b});
          for(auto idx : ri[next]){
            int cnt = 1;
            if(MAX >= L[idx]) cnt++;
            if(MIN >= L[idx]) cnt++;
            ok = ok && cnt == X[idx];
          }
          if(ok){
            dp[r][next][b] += dp[r][g][b];
            dp[r][next][b] %= MOD;
          }
        }
        {
          bool ok = true;
          int MIN = min({g,r});
          int MAX = max({g,r});
          for(auto idx : ri[next]){
            int cnt = 1;
            if(MAX >= L[idx]) cnt++;
            if(MIN >= L[idx]) cnt++;
            ok = ok && cnt == X[idx];
          }
          if(ok){
            dp[r][g][next] += dp[r][g][b];
            dp[r][g][next] %= MOD;
          }
        }
      }
    }
  }

  i64 ans = 0;
  rep(i,0,N - 1){
    rep(j,0,N - 1){
      ans = (dp[N][i][j] + ans) % MOD;
      ans = (dp[i][N][j] + ans) % MOD;
      ans = (dp[i][j][N] + ans) % MOD;
    }
  }

  cout << ans << endl;
}

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

long long int L[3003][3003][4];

int G[3003][3003];
int H,W,K;

signed main(){
	cin>>H>>W>>K;
	int h,w,v;
	for(int i=1;i<=K;i++){
		cin>>h>>w>>v;
		G[h][w]=v;
	}
	for(int h=1;h<H+1;h++){
		for(int w=1;w<W+1;w++){
			long long int X=0;
			for(int k=0;k<4;k++){
				X=max(X,L[h-1][w][k]);
			}
			for(int k=1;k<4;k++){
				L[h][w][k]=max(max(L[h][w-1][k],L[h][w-1][k-1]+G[h][w]),X+G[h][w]);	
			}
		}
	}
	
	long long int ans=0;
	for(int i=0;i<=3;i++){
		ans=max(ans,L[H][W][i]);
	}  
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 320160
#include <cstdio>

int N, P; char S[200200]; long long cnt[10010];

int inv(int x)
{
	if (x <= 1) return x;
	return (P - P / x) * inv(P % x) % P;
}

int main()
{
	scanf ("%d %d", &N, &P);
	scanf ("%s", S);

	long long ans = 0;
	if (P == 2 || P == 5){
		for (int i = 0; S[i]; i++){
			if ((S[i] - '0') % P == 0) ans += i + 1;
		}
	}
	else{
		cnt[0]++;
		long long s = 0, it = inv(10 % P), g = 1;
		for (int i = 0; S[i]; i++){
			g = g * it % P;
			s = s + (S[i] - '0') * g;
			s %= P;
			ans += cnt[s]++;
		}
	}

	printf ("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 384
import collections

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
counter = collections.Counter(A)
Asum = sum(A)
ans = list()
for i in range(Q):
    B,C = map(int,input().split())
    if B in counter:
        num = counter.pop(B)
        Asum = Asum + (C-B)*num
        counter[C] = counter[C]+num
    ans.append(Asum)
for a in ans:
    print(a)
    	


Measured memory_bytes: 21732
$<.map{|i|b=(a=i.split(?,).map(&:to_i).sort).map{|j|a.count(j)}.max;s=a.uniq.size;puts b>3?"four card":b>2?s>2?"three card":"full house":b>1?s>3?"one pair":"two pair":a[4]-a[0]<5||a[1]>9?:straight: :null}

Measured memory_bytes: 8668
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	e := make(map[int]int)
	o := make(map[int]int)
	var v int
	for i := 0; i < n; i++ {
		fmt.Scan(&v)
		if i%2 == 0 {
			e[v]++
		} else {
			o[v]++
		}
	}

	k1, v1 := maxVal(e)
	k2, v2 := maxVal(o)

	if k1 != k2 {
		fmt.Println(n - v1 - v2)
	} else {
		e[k1] = 0
		o[k2] = 0
		_, v3 := maxVal(e)
		_, v4 := maxVal(o)

		a := n - v1 - v4
		b := n - v2 - v3
		if b < a {
			a = b
		}
		fmt.Println(a)
	}
}

func maxVal(m map[int]int) (int, int) {
	val := 0
	key := 0
	for k, v := range m {
		if val < v {
			val = v
			key = k
		}
	}
	return key, val
}


Measured memory_bytes: 7808
N = int(input())
data = [[] for _ in range(N)]
for _ in range(N-1):
    p, q, w = map(int, input().split())
    p -= 1
    q -= 1
    data[p].append((q,w))
    data[q].append((p,w))

colors = [0]*N
visited = [0]*N
start = 0
next_set = [start]
while next_set:
    p = next_set.pop()
    visited[p] = 1
    color = colors[p]
    for q, w in data[p]:
        if visited[q]:
            continue
        colors[q] = (color + w%2)%2
        next_set.append(q)
print(*colors, sep="\n")


Measured memory_bytes: 96344
n = int(input())
A = list(map(int,input().split(' ')))
rate = [0]*9
for a in A:
    c = min(a//400, 8)
    rate[c] += 1
count = 0
i = 0
while i < 8:
    if rate[i] != 0:
        count += 1
    i += 1
cmax = count+rate[8]
cmin = max(1, count)

print(str(cmin)+' '+str(cmax))

Measured memory_bytes: 3064
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		StringTokenizer tokenizer;
		String s;
		while((s=reader.readLine())!=null){
			Path2D.Double sank = new Path2D.Double();
			tokenizer = new StringTokenizer(s);
			double[] z = new double[8];
			for(int i=0;i<8;i++){
				z[i] = Double.parseDouble(tokenizer.nextToken());
			}
			sank.moveTo(z[0], z[1]);
			sank.lineTo(z[2], z[3]);
			sank.lineTo(z[4], z[5]);
			
			Point2D.Double pt = new Point2D.Double(z[6], z[7]);
			System.out.println(sank.contains(pt)?"YES":"NO");
		}
	}

}

Measured memory_bytes: 16972
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main() {
  //H*W行列,N色の色を使う
  //各iの色はaiマス塗る
  //色iのマスは互いに連結
  //塗り方を一求める
  //aiが大きい色から順に、一番上の行から、左→右、右→左の順に塗っていく
  //(ai,i)のペア配列を作る
  //C[0][0]から順に、C[ai-1][0]までiを塗っていき,途中で塗れなくなったら、下に行く,下に行くとそれまでと反対側に塗っていく
  //下に行った時、それまでi++ならi--に、i--ならi++にしたい
  //C[0][0]から順に、右隣か左隣で塗っていないマスが在ればiで塗り、右端か左端に達すれば下の行に行く
  int H,W,N;
  cin >> H >> W >> N;
    vector<P> p(N);
  for(int i = 0;i<N;i++){
      cin >> p[i].first;
      p[i].second = i+1;
  }
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  
   vector<vector<int>> C(H, vector<int>(W));

  vector<int> y = {1,-1};

  
int k = 0;
int i = 0;
int j  =0;
int c = 0;//塗った回数をカウント
  C[0][0] = p[0].second;
  p[0].first--;
  if(p[k].first == 0){
     k++;
    }
  c++;
  
  bool flag = false;
  
  while(true){
   if(c == H*W) break;
   
   for(int l = 0;l<2;l++){
     int ny = j + y[l];//[i][j]から左か右に移動した時の位置
     
       if(0<= ny && ny < W && C[i][ny] == 0){//右か左に移動可能かつまだ塗られていないなら塗る
          C[i][ny] = p[k].second;
          c++;
         if(c == H*W){
           flag = true;
           break;//全てのマスを塗り終えたら終了
         }
           p[k].first--;
           j = ny;//塗った位置に移動
         //ある色の塗る回数が終われば次の色にする
          if(p[k].first == 0){
            k++;
           }
         }
 
          //塗った位置が右端か左端であれば下の行に移動し、塗る
         if(j == 0 || j == W-1 && i< H-1){
            i++;
           C[i][j] = p[k].second;
           c++;
           if(c == H*W){
             flag = true;
             break;//全てのマスを塗り終えたら終了
           }
           p[k].first--;
            //ある色の塗る回数が終われば次の色にする
            if(p[k].first == 0){
               k++;
              }
            }
      } 
       if(flag) break;
   } 

 
  for(int i = 0;i<H;i++){
      for(int j = 0;j<W;j++){
          cout << C[i][j] << " ";
          if(j == W-1) cout << endl;
      }
  }


}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int , int> pii;
#define MAX 510

vector<int> v[MAX];
int n, m, q;

int main() {
    cin.tie(0), cout.sync_with_stdio(false);
    cin >> n >> m >> q;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
    }
    for (int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());

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

        int ans = 0;
        for (int j = x; j <= y; j++) {
            ans += (int) (lower_bound(v[j].begin(), v[j].end(), y + 1) - v[j].begin());
        } 
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 2176
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
long long f(long long i){
    i = i + i/100;
    return i;
}
int main(){
    long long n = 100,x,c = 0;
    cin >> x;
    while(n < x){
        n = f(n);
        //cout << n << endl;
        c++;
    }
  cout << c << endl;
}

Measured memory_bytes: 3608
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Score = Tuple!(long, "p", long, "c");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long d, g;
    scan(d, g);
    auto scores = new Score[](d);
    foreach (ref e; scores)
    {
        long r, c;
        scan(r, c);
        e = Score(r, c);
    }
    auto m = INF;
    foreach (i; iota(1 << d))
    {
        long p, plus, moves;
        auto b = i.bitary(d);
        foreach (j; iota(b.length))
        {
            if (b[j])
            {
                p += scores[j].p * 100 * (j + 1);
                p += scores[j].c;
                moves += scores[j].p;
            }
            else
                plus = j;
        }
        long n = scores[plus].p;
        while (n > 1 && p < g)
        {
            p += 100 * (plus + 1);
            moves++, n--;
        }
        // moves.writeln();
        if (p >= g)
            m = min(moves, m);
    }
    m.writeln();
}

auto bitary(long n, long m)
{
    auto b = new long[](m);
    long i;
    while (n > 0)
    {
        b[i++] = n % 2;
        n = n >> 1;
    }
    b.reverse();
    return b;
}


Measured memory_bytes: 380
n,m = map(int, input().split())
a = [input() for  _ in range(n)]
b = [input() for  _ in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        # print(i,j)
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    break
            else:
                continue
            break
        else:
            print('Yes')
            # print(i,j)
            exit()

print('No')

Measured memory_bytes: 38256
from bisect import bisect
from collections import defaultdict


class Bit:
    def __init__(self, n, MOD):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()
        self.mod = MOD

    def sum(self, i):
        s = 0
        while i > 0:
            s = (s + self.tree[i]) % self.mod
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = (self.tree[i] + x) % self.mod
            i += i & -i

    def debug_print(self):
        for i in range(1, self.size + 1):
            j = (i & -i).bit_length()
            print('  ' * j, self.tree[i])

    def lower_bound(self, x):
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_


n, m = map(int, input().split())
xxx = list(map(int, input().split()))
yyy = list(map(int, input().split()))
ab = defaultdict(set)
coordinates = set()

for x in xxx:
    if x < yyy[0] or yyy[-1] < x:
        continue
    i = bisect(yyy, x)
    a = x - yyy[i - 1]
    b = yyy[i] - x
    ab[a].add(b)
    coordinates.add(b)

# Bitのindexは1から始まるように作っているが、"0"を取れるようにするため、全体を1ずらす
cor_dict = {b: i for i, b in enumerate(sorted(coordinates), start=2)}
cdg = cor_dict.get
MOD = 10 ** 9 + 7
bit = Bit(len(coordinates) + 1, MOD)
bit.add(1, 1)

for a in sorted(ab):
    bbb = sorted(map(cdg, ab[a]), reverse=True)
    for b in bbb:
        bit.add(b, bit.sum(b - 1))

print(bit.sum(bit.size))


Measured memory_bytes: 61768
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int paper[15][15] = {{0}};
    int x,y,size;
    while( scanf ("%d,%d,%d",&x ,&y ,&size ) != EOF)
    {
        x+=2;
        y+=2;
        if(size==1)
        {
            paper[x][y]+=1;paper[x+1][y]+=1;paper[x-1][y]+=1;paper[x][y-1]+=1;paper[x][y+1]+=1;
        }
        if(size==2)
        {
            paper[x][y]+=1;paper[x-1][y+1]+=1;paper[x-1][y]+=1;paper[x-1][y-1]+=1;paper[x][y+1]+=1;paper[x][y-1]+=1;paper[x+1][y-1]+=1;paper[x+1][y]+=1;paper[x+1][y+1]+=1;
        }
        if(size==3)
        {
            paper[x][y]+=1;paper[x-1][y+1]+=1;paper[x-1][y]+=1;paper[x-1][y-1]+=1;paper[x][y+1]+=1;paper[x][y-1]+=1;paper[x+1][y-1]+=1;paper[x+1][y]+=1;paper[x+1][y+1]+=1;paper[x+2][y]+=1;paper[x-2][y]+=1;paper[x][y+2]+=1;paper[x][y-2]+=1;
        }
    }
    int max=0,voi=0;
    for(int i=2;i<=11;i++)
    {
        for(int j=2;j<=11;j++)
        {
            if(paper[i][j]>max)max=paper[i][j];
            if(paper[i][j]==0)voi++;
        }
    }
    cout<<voi<<endl<<max<<endl;
    return 0;
}

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

const int MaxN = 100000 + 5;

int N;
int A[MaxN];
int dp[MaxN];

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
}

inline int myAbs(int x) {
  if (x < 0) return -x;
  else return x;
}

void solve() {
  dp[1] = 0; dp[2] = myAbs(A[1] - A[2]);
  for (int i = 3; i <= N; ++i)
    dp[i] = min(dp[i - 2] + myAbs(A[i] - A[i - 2]), dp[i - 1] + myAbs(A[i] - A[i - 1]));
  cout << dp[N] << endl;
}

int main() {
  init();
  solve();
  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  string s,t;
  cin>>s>>t;
  vector<vector<int>>dp(s.size()+1,vector<int>(t.size()+1,0));
  vector<vector<pii>>pre(s.size()+1,vector<pii>(t.size()+1,{0,0}));
  for(int i=1;i<=s.size();i++){
    for(int j=1;j<=t.size();j++){
      if(s[i-1]==t[j-1]){
        dp[i][j]=dp[i-1][j-1]+1;
        pre[i][j]={i-1,j-1};
      }
      else if(dp[i-1][j]>dp[i][j-1]){
        dp[i][j]=dp[i-1][j];
        pre[i][j]={i-1,j};
      }
      else{
        dp[i][j]=dp[i][j-1];
        pre[i][j]={i,j-1};
      }
    }
  }
  pii a={s.size(),t.size()};
  vector<pii>ans;
  while(a!=pii({0,0})){
    ans.push_back(a);
    a=pre[a.first][a.second];
  }
  string res="";
  for(int i=0;i<ans.size();i++){
    if(s[ans[i].first-1]==t[ans[i].second-1])res=s[ans[i].first-1]+res;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 106112
<?php
$n    = trim(fgets(STDIN));
$data = explode(' ', trim(fgets(STDIN)));

$count = 0;
while (true) {
    foreach ($data as $value) {
        if ($value % 2 === 1) {
            break 2;
        }
    }
    $data = array_map(function ($value) {
        return $value / 2;
    }, $data);
    $count++;
}

print $count;

Measured memory_bytes: 4604
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define int long long int

using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, int> PPI;
typedef pair<int, PII> PIP;
typedef pair<PII, PII> PPP;
typedef vector<PII> VP;
typedef VP::iterator VPI;
typedef vector<int> VI;
const int INF = 3e18;
const double PI = acos(-1);
const int MOD = 1e9 + 7;

int a, b, c;
signed main()
{
  cin >> a >> b >> c;
  cout << min(a * b * (c % 2), min(a * c * (b % 2), b * c * (a % 2))) << endl;
  return 0;
}


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

typedef pair<int, int> P;
const int INF = 100100100;

int H,W;
char m[60][60];
int d[60][60];

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

int bfs(){
  queue<P> q;
  q.push(P(0,0));
  d[0][0]=0;

  while(!q.empty()){
    P p = q.front(); q.pop();
    if(p.first==W-1 && p.second==H-1) return d[p.first][p.second];
    rep(i,4){
      int nx = p.first + dx[i], ny=p.second + dy[i];
      if(nx>=0 && nx < W && ny >= 0 && ny < H
         && m[nx][ny]!='#' && d[nx][ny] == INF){
        q.push(P(nx, ny));
        d[nx][ny]=d[p.first][p.second]+1;
      }
    }
  }
  return d[W-1][H-1];
}

int main()
{

  cin >> H >> W;
  rep(i,H){
    char buf[60];
    cin >> buf;
    rep(j,W) m[j][i] = buf[j];
  }

  // Initialize
  rep(i,H){
    rep(j,W){
      d[j][i] = INF;
    }
  }

  int res=H*W;
  rep(i,H){
    rep(j,W){
      if(m[j][i]=='#') res--;
    }
  }
  res -= bfs();
  res--; // for start point
  
  // rep(i,H){
  //   rep(j,W){
  //     if(d[j][i]==INF) printf(" X ");
  //     else printf("%2d ", d[j][i]);
  //   }
  //   printf("\n");
  // }

  if(res<0) res = -1;

  cout << res << endl;
}


Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあって そんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/pavan/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;


int main(){
	FIO
	
	map<string, int> m;
	int n;cin >> n;
	forn(i, n){
		string s;cin >> s;
		m[s]++;
	}
	priority_queue<pair<int,string>> pq;
	for(auto i:m){
		pq.push({i.second, i.first});
	}
	
	auto x = pq.top().first;
	set<string> s;
	while(!pq.empty()){
		if(pq.top().first == x)s.insert(pq.top().second);
		else break;
		pq.pop();
	}
	for(auto i:s)cout << i << "\n";
	return 0;
}


Measured memory_bytes: 37228
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

int main(void){
	int n;
	vector<pair<string, int>> v;
	string s;
	int p;
	cin>>n;
	rep(i,n){
		cin>>s>>p;
		v.push_back(pair<string,int>{s,-1000*p + -1*(i+1)});
	}
	sort(all(v));
	rep(i,n){
		cout<<(v[i].second*(-1))%1000<<endl;
	}
	
	return 0;
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N;
    string A,B,C;
    cin >> N >> A >> B >> C;
    
    i64 ans=0;
    rep(i,0,N){
        vector<i64> cnt(26);
        ++cnt[A[i]-'a'];
        ++cnt[B[i]-'a'];
        ++cnt[C[i]-'a'];
        ans+=3-*max_element(begin(cnt),end(cnt));
    }
    
    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

int main(){
    int N; long long ans = 1;
    cin >> N;
    for(int i = 1; i <= N; i++){
        ans *= i;
        if(ans > 1000000007)ans = ans % 1000000007;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int64_t x;
    cin >> x;

    int a = -1000000,b = -1000000;
    for (int64_t i = -1000; i < 1000; i++){
        for (int64_t j = -1000; j < 1000; j++){
            if (i * i * i * i * i - j * j * j * j * j == x){
                a = i;
                b = j;
                break;
            }
        }

    if (a != -1000000 && b != -1000000){
        break;
    }
    }

    cout << a << " " << b << endl;

    return 0;
}


Measured memory_bytes: 3580
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
#include<time.h>
#include<map>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;

bool cmp(const P &a, const P &b) {
	if (a.first == b.first) {
		return a.second < b.second;
	}
	else  return a.first < b.first;
}

int main(void) {
	ll n, a, b;
	cin >> n;
	vector<P>p(n);
	map<pair<ll, ll>, ll>m;
	for (ll i = 0;i < n;i++) {
		cin >> a >> b;
		p[i] = make_pair(a, b);
	}
	ll num = 0;
	for (ll i = 0;i < n ;i++) {
		for (ll j = 0;j < n;j++) {
			if (i == j)continue;
			m[{p[j].first - p[i].first, p[j].second - p[i].second}]++;
		}
	}
	ll ans = 0;
	for (auto itr = m.begin();itr != m.end();++itr) {
		ans = max(ans, itr->second);
	}
	cout << n - ans << endl;
	return 0;
}

Measured memory_bytes: 384
N,K = map(int,input().split())



#数字が1刻みなので最大値と最小値の間の数字は全部求める事が可能である
#ただし足す項の数で結果が異なるので注意する。

N = N+1

#選ぶ項の数がKの時の組み合わせの数を確認する
def minmax(N,K):
    #最大値-最小値={N+(n-1)+   }-{k+(k-1)+(k-2)+   }
    #=(N-k)*k
    return (N-K)*K+1


Ans = 0
for i in range(K,N+1):
    Ans = Ans + minmax(N,i)


mod = 1000000007
Ans = Ans % mod

print(Ans)












Measured memory_bytes: 9136
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i16 = read(&mut stdin_lock, &mut buf, b'\n');
    let ans = n / 3;
    println!("{}", ans);
}


Measured memory_bytes: 4352
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
temp = [False for _ in range(N)]

a = {}
a["r"] = P
a["s"] = R
a["p"] = S

ans = 0
for i in range(N):
    ans += a[T[i]]

for i in range(N):
    if 0 <= (i - K):
        if T[i] == T[i - K]:
            if not temp[i-K]:
                ans -= a[T[i]]
                temp[i] = True

print(ans)

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

class UnionFind {
public:
  vector<int> parent;
  UnionFind(int n) { parent = vector<int>(n, -1); }
  int root(int a) {
    if(parent[a] < 0)
      return a;
    return parent[a] = root(parent[a]);
  }
  int size(int a) { return -parent[root(a)]; }
  bool connect(int a, int b) {
    a = root(a);
    b = root(b);
    if(a == b)
      return false;
    if(size(a) < size(b))
      swap(a, b);
    parent[a] += parent[b];
    parent[b] = a;
    return true;
  }
  void reset() { fill(parent.begin(), parent.end(), -1); }
};

int main() {
  int n, m, o = 0;
  cin >> n >> m;
  vector<pair<int, int>> ab(m);
  UnionFind uni(n);
  for(int i = 0; i < m; i++) {
    cin >> ab.at(i).first >> ab.at(i).second;
    ab.at(i).first--;
    ab.at(i).second--;
  }
  for(int i = 0; i < m; i++) {
    for(int j = 0; j < m; j++)
      if(i != j)
        uni.connect(ab.at(j).first, ab.at(j).second);
    if(uni.connect(ab.at(i).first, ab.at(i).second))
      o++;
    uni.reset();
  }
  cout << o << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
dp=[-1 for i in range(N+1)]
dp[0]=1
dp[1]=1
for i in range(M):
    a=int(input())
    dp[a]=0

for i in range(2,N+1):
    if dp[i]==0:
        pass
    else:
        dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
print(dp[N])


Measured memory_bytes: 7064