akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main() {
    char s[101], p[101];
    int i, j, k;
    scanf("%s", &s);
    scanf("%s", &p);
    for (i = 0; s[i]; i++) {
        if (s[i] == p[0]) {
            for (j = i, k = 0; p[k]; k++) {
                if (s[j] != p[k]) {
                    break;
                }
                if (!s[++j]) {
                    j = 0;
                }
            }
            if (!p[k]) {
                printf("Yes\n");
                break;
            }
        }
    }
    if (!s[i]) {
        printf("No\n");
    }
    return 0;
}

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

int main() {
  int A, B;
  std::cin >> A >> B;

  int ans = 0;
  ans = std::max(ans, A + A - 1);
  ans = std::max(ans, A + B);
  ans = std::max(ans, B + B - 1);

  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <=0){
                return false;
            }
        }
        return true;
    }

    private int readByte(){
        if(hasNextByte())return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c){
        return 33<=c && c<=126;
    }
    public boolean hasNext(){
        while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
        return hasNextByte();
    }

    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b<='9'){
                n*=10;
                n+=b-'0';
            }else if(b==-1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDoutble(){return Double.parseDouble(next());}
}

class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int k = fs.nextInt();
        int[] h = new int[n];
        for(int i=0;i<n;i++)h[i] = fs.nextInt();
        int[] dp = new int[n];
        dp[0] = 0;
        for(int i=1;i<n;i++){
            dp[i] = dp[i-1] + Math.abs(h[i]-h[i-1]);
            for(int j=2;j<=k;j++){
                if(i-j>=0){
                    dp[i] = Math.min(dp[i],dp[i-j] + Math.abs(h[i]-h[i-j]));
                }
            }
        }
        System.out.println(dp[n-1]);
        System.out.flush();
    }
}

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

int main(){
  int n;
  string s;
  vector<char> vs, ans;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> s;
    if(i == 0){
      for(int j = 0; j < s.size(); j++){
        vs.push_back(s[j]);
        ans.push_back(s[j]);
      }
    }
    else{
      ans.clear();
      for(int j = 0; j < s.size(); j++){
        for(int k = 0; k < vs.size(); k++){
          if(s[j] == vs[k]){
            // cout << "find " << s[j] << endl;
            ans.push_back(s[j]);
            vs.erase(vs.begin() + k);
            break;
          }
        }
      }
      vs.clear();
      vs.resize(ans.size());  //忘れないこと
      copy(ans.begin(), ans.end(), vs.begin());
    }
  }
  sort(ans.begin(), ans.end());
  for(int i = 0; i < ans.size(); i++){
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define deb 0

int mark[100001], A[100001];

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

	int n, i, j, k, x, y, z, c = 0;
	cin >> n;
	for (i = 1; i <= n; ++i) cin >> A[i];
	x = 1;
	c = 0;
	mark[1] = 1;
	while (x != 2) {
		c++;
		x = A[x];
		if (mark[x]) break;
		mark[x] = 1;
	}
	if (x == 2) cout << c << endl;
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;
    while(left < right){
        mid = (left + right) / 2;
        if(key == A[mid])return 1;
        if(key >A[mid])left = mid +1;
        else if(key < A[mid])right = mid;
    }
    return 0;
}
 
int main(void){
    int i, q, k,sum = 0;
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&k);
        if(binarySearch(k)) sum++;
    } 
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 2140
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
/*lli gcd(lli a, lli b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}*/
int main(void)
{
    lli N;
    cin >> N;
    lli ans = 11;
    for (lli i = 1; i <= (lli)sqrt(N) + 1; i++)
    {
        lli j = (lli)(N / i);
        if (i * j == N)
        {
            ans = min(ans, (lli)(log10(j) + 1));
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int a[111][111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	rep(i,n)rep(j,n)cin>>a[i][j];
	ll res=0;
	rep(i,n)rep(j,i){
		res+=min(a[i][j],a[j][i]);
	}
	cout<<res<<endl;
	return 0;
}

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

using namespace std;


#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define mp make_pair
#define pb push_back
#define eps 1e-9
#define PI acos(-1.0)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<int, pii> iii;
typedef vector<pii> vii;
typedef long double ld;
const int INF = 1e9 + 5;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

bool prime(ll x)
{
    if(x == 2)
        return true;
    for(int i = 2 ; i * i <= x ; i++)
        if(x % i == 0)
            return false;
    return true;
}
void self_max(ll &a, ll b)
{
    a = max(a, b);
}
bool cmp(int a, int b)
{
    return a > b;
}
int a[int(1e5 + 5)];
int main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio (0);
    cin.tie(0);

    int n, w;
    cin >> n >> w;
    std::vector<ll> dp(w + 5);
    for (int item = 0; item < n; ++item)
    {
        int wt, val;
        cin >> wt >> val;
        for (int wt_alrdy = w - wt; wt_alrdy >= 0; --wt_alrdy)
        {
            self_max(dp[wt_alrdy + wt], dp[wt_alrdy] + val);
        }

    }
    ll ans = 0;
    for (int i = 0; i <= w; ++i)
    {
        self_max(ans, dp[i]);
    }
    cerr << dp.size();
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
from collections import Counter

S = input()
mods = [0]
num, ten = 0, 1
for n in S[::-1]:
    num += int(n) * ten
    num %= 2019
    mods.append(num)
    ten *= 10
    ten %= 2019

c = Counter(mods)
ans = 0
for v in c.values():
    ans += v * (v - 1) // 2
print(ans)


Measured memory_bytes: 16860
#include <stdio.h>

int main(void) {
  long a, b, sum = 0, i;

  scanf("%ld %ld", &a, &b);

  for (i = 1; i <= b-a; i++) {
    sum += i;
  }

  printf("%ld\n", sum - b);

  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String... args){
        Scanner scan = new Scanner(System.in);
        int list[] = new int[3];
        list[0] = scan.nextInt();
        list[1] = scan.nextInt();
        list[2] = scan.nextInt();
        
        int n = 0;
        for(int i = 1;i < 3;i++){
           if(list[n] > list[i])n = i;

        }
        System.out.print(list[n]+" ");

        int a = 0,b = 0;
        switch(n){
            case 0:
                a = list[1];
                b = list[2];
                break;
            case 1:
                a = list[0];
                b = list[2];
                break;
            case 2:
                a = list[0];
                b = list[1];
                break;

        }

        if(a < b)System.out.println(a + " " + b);
        else System.out.println(b + " " + a);

        scan.close();
    }
}


Measured memory_bytes: 26268
c=input()

alphabet=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

for i in range(len(alphabet)):
  if c==alphabet[i]:
    answer=alphabet[i+1]

print(answer)

Measured memory_bytes: 3060
package main

import (
        "fmt"
        "os"
)

func main() {
        var n int
        fmt.Scanf("%d", &n)
        var s string
        fmt.Scanf("%s", &s)

        if n%2 == 1 {
                fmt.Println("No")
                os.Exit(0)
        }

        before := s[:n/2]
        after := s[n/2:]

        for i := 0; i < n/2; i++ {
                if before[i] != after[i] {
                        fmt.Println("No")
                        os.Exit(0)
                }
        }
        fmt.Println("Yes")
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	string s; cin>>s;
	sort(s.begin(),s.end());
	cout<<(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]?"Yes":"No")<<endl;

	return 0;
}


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

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)

const int mxN = 2e5+5;
const int lgN = 19;
int N, V, X[mxN];
vector<int> S;
int M, dpL[(1<<lgN)], dpR[(1<<lgN)], r[lgN][mxN], l[lgN][mxN];
int bestR[mxN], bestL[mxN];

struct SparseTable {
    int *V, A[mxN][lgN];
    void init(int* _V) {
        V = _V;
        FOR(i,0,N) A[i][0] = i;
        FOR(k,1,lgN-1){
            FOR(i,0,N-(1<<k)+1){
                int x = A[i][k-1], y = A[i+(1<<(k-1))][k-1];
                A[i][k] = (V[x] < V[y] ? x : y);
            }
        }
    }
    int qval(int l, int r) {
        int k = floor(log2(r-l+1));
        int i = A[l][k], j = A[r-(1<<k)+1][k];
        return min(V[i],V[j]);
    }
} st;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> V;
    FOR(i,1,N){
        cin >> X[i];
    }
    for (int x = V; x; x >>= 1) S.push_back(x);
    S.push_back(0);
    reverse(ALL(S));
    M = SZ(S);
    FOR(i,0,M-1){
        r[i][N] = N;
        RFOR(j,N-1,1){
            r[i][j] = j;
            if (X[j+1]-X[j] <= S[i]) r[i][j] = max(r[i][j],r[i][j+1]);
        }
        l[i][1] = 1;
        FOR(j,2,N){
            l[i][j] = j;
            if (X[j]-X[j-1] <= S[i]) l[i][j] = min(l[i][j],l[i][j-1]);
        }
    }
    dpL[0] = 0;
    FOR(x,1,(1<<(M-1))-1){
        dpL[x] = 1;
        int y = x;
        while (y) {
            int b = y&-y, c = __builtin_ctz(b);
            y ^= b;
            dpL[x] = (dpL[x^b] == N ? N : max(dpL[x],r[c][dpL[x^b]+1]));
        }
    }
    dpR[0] = N+1;
    FOR(x,1,(1<<(M-1))-1){
        dpR[x] = N;
        int y = x;
        while (y) {
            int b = y&-y, c = __builtin_ctz(b);
            y ^= b;
            dpR[x] = (dpR[x^b] == 1 ? 1 : min(dpR[x],l[c][dpR[x^b]-1]));
        }
    }
    fill(bestR,bestR+1+N,N+2);
    FOR(x,0,(1<<(M-1))-1){
        int y = ((1<<(M-1))-1) ^ x;
        bestR[dpL[x]] = min(bestR[dpL[x]],dpR[y]);
    }
    st.init(bestR);
    //FOR(i,0,N){ cout << bestR[i] << ' '; } cout << endl;

    FOR(i,1,N){
        int rcov = st.qval(l[M-1][i]-1,r[M-1][i]);
        cout << (r[M-1][i]+1 >= rcov ? "Possible" : "Impossible") << '\n';
    }
}



Measured memory_bytes: 52352
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int n;
  cin>>n;
  string s[n];
  rep(i,n){
    cin>>s[i];
  }
  int ab=0,enda=0,startb=0,both=0;
  rep(i,n){
    rep(j,s[i].length()-1){
      if(s[i].substr(j,2)=="AB"){
        ab++;
      }
    }
    if(s[i][0]=='B'){
      startb++;
    }
    if(s[i][s[i].length()-1]=='A'){
      enda++;
    }
    if(s[i][0]=='B' && s[i][s[i].length()-1]=='A'){
      startb--; enda--; both++;
    }
  }
  if(startb==0 && enda==0 && both!=0){
    cout<<ab+both-1;
  }else{
    cout<<ab+min(enda,startb)+both;
  }
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll h,w;
cin>>h>>w;
ll ans;
if(w==1 || h==1){
    ans=1;
}
else{
    if(w%2!=0){
            ans=((w/2)+1)*h-(h/2);
    }
    else{
            ans=(w/2)*h;
    }
}
cout<<ans<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
<?php

while (true) {
    list($H, $W) = array_map("intval", explode(' ', trim(fgets(STDIN))));

    if ($H == 0 && $W == 0) break;

    $line1 = str_repeat('#.', (int)floor($W / 2)) . str_repeat('#', $W % 2) . "\n";

    $line2 = str_repeat('.#', (int)floor($W / 2)) . str_repeat('.', $W % 2) . "\n";

    $lines = $line1 . $line2;

    $board = str_repeat($lines, (int)floor($H / 2)) . str_repeat($line1, $H % 2);

    echo $board . "\n";
}

?>


Measured memory_bytes: 9380
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,i;
    cin>>N;
    double A[N];
    for(i=1;i<=N;i++)
    {
    	cin>>A[i];
    }
    sort(A+1,A+N+1);
double c=A[1];
    for(i=1;i<=N;i++)
{
    	c+=A[i];
        c=c/2;
    }
    cout<<fixed<<setprecision(6);
    cout<<c;

    


}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
int main() {
    int a, b; cin >> a >> b;
    cout << a / b << " " << a % b << " ";
    double s, t; s = a; t = b;
    double q = s / t;
    cout << fixed << setprecision(10)  << q << endl;
}


Measured memory_bytes: 3280
// A - Zero-Sum Ranges O(NlogN)
/*
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
using ll=long long;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin>>N;
  ll A[N+1];
  memset(A,0,sizeof(A));
  for (int i=1; i<=N; i++) {
    cin>>A[i];
    A[i]+=A[i-1];
  }
  sort(A,A+N+1);
  ll ans=0;
  for (int i=0; i<=N; i++) {
    ll cnt=0;
    int I=i;
    for (int j=I; j<=N&&A[I]==A[j]; j++) {
      cnt++;
      i=j;
    }
    ans+=cnt*(cnt-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}
*/
// B - Find Symmetries O(N^3)
#include <iostream>
using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin>>N;
  char S1[N][N];
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      cin>>S1[i][j];
    }
  }
  char S2[N][N];
  int ans=0;
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      for (int k=0; k<N; k++) {
        S2[j][k]=S1[(i+j)%N][k];
      }
    }
    bool ok=true;
    for (int j=0; j<N; j++) {
      for (int k=0; k<N; k++) {
        if (S2[j][k]!=S2[k][j]) {
          ok=false;
        }
      }
    }
    if (ok) {
      ans+=N;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    ll n; cin >> n;

    ll ans = 0;
    map<ll,ll> mp;
    for(ll i = 2; i<= sqrt(n)+1; i++){

        if(n % i == 0){
            while(n % i == 0){
                mp[i]++;
                n /= i;
            }
        }

    }
    mp[n]++;
    mp[1]--;

    for(auto e: mp){
        ll tmp = 1;

        while(e.second >= tmp){
            e.second -= tmp;
            tmp++;
            ans++;
        }

    }

    cout << ans << endl;
}

Measured memory_bytes: 3756
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();         
        int b = sc.nextInt();
		int c = sc.nextInt(); 
        if((10*b+c)%4==0){System.out.println("YES");}
		else{System.out.println("NO");}
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> v(n), c(n);
    for(int i = 0; i < n; i++) std::cin >> v[i];
    for(int i = 0; i < n; i++) std::cin >> c[i];
    
    int sum = 0; // select nothing
    for(int i = 0; i < n; i++){
        if(v[i] - c[i] > 0) sum += v[i] - c[i];
    }

    std::cout << sum << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

#define max 51

using namespace std;

int min(int a,int b){
	return a < b ? a : b;
}

int main(void){
	int n;
	cin >> n;
	int res[26],box[26];
	for(int i=0;i<26;i++)res[i] = max;
	for(int i=0;i<n;i++){
		int box[26] = {0};
		string s;
		cin >> s;
		for(int i=0;i<s.length();i++){
			box[s[i]-'a']++;
		}
		for(int i=0;i<26;i++){
			res[i] = min(res[i],box[i]);
		}
	}
	for(int i=0;i<26;i++){
		for(int j=0;j<res[i];j++){
			cout << char('a'+i);
		}
	}
	cout << endl;
}

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

V.sort(reverse=True)

AVERAGE=V[:A]

print(sum(AVERAGE)/A)

MIN=AVERAGE[-1]

MINUSE=0
for a in AVERAGE:
    if a==MIN:
        MINUSE+=1

MAXUSE=0
for a in V[:B]:
    if a==MIN:
        MAXUSE+=1

ALLUSE=0
for a in V:
    if a==MIN:
        ALLUSE+=1

import math

if V[0]!=MIN:
    print(math.factorial(ALLUSE)//math.factorial(MINUSE)//math.factorial(ALLUSE-MINUSE))

else: 
    ANS=0
    for use in range(MINUSE,MAXUSE+1):
            ANS+=math.factorial(ALLUSE)//math.factorial(use)//math.factorial(ALLUSE-use)

    print(ANS)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define int long long

#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define U 1000000007
#define N 100005
#define ins insert
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n+1],b[n+1],c[n+1],dp[n+1][3];
  rep(i,1,n+1) cin>>a[i]>>b[i]>>c[i];

  dp[0][0]=0;
  dp[0][1]=0;
  dp[0][2]=0;
  rep(i,1,n+1)
  {
    dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
    dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
    dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
    //cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
  }
  cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
 



}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
#include <cmath>
using namespace std;
 
int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    
    char c[h][w];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            char tmp;
            cin >> tmp;
            c[i][j] = tmp;
        }
    }
    
    int cnt = 0;
    vector<std::bitset<6>> v1;
    vector<std::bitset<6>> v2;
    for(int i1=0; i1<64; i1++)
    {
        std::bitset<6> t(i1);
        //cout << t << endl;
        v1.push_back(t);
        v2.push_back(t);
    }
    
    int ans = 0;
    for(int i=0; i<pow(2.0, h); i++){
        std::bitset<6> b1 = v1[i];
        for(int j=0; j<pow(2.0, w); j++){
            std::bitset<6> b2 = v2[j];
            
            //cout << "---" << endl;
            //cout << b1 << ":" << b2 << endl;

            
            char tmp[h][w];
            for(int ih=0; ih<h; ih++){
                for(int iw=0; iw<w; iw++){
                    if(b1[ih] == 0 && b2[iw] == 0){
                        tmp[ih][iw] = c[ih][iw];
                    }
                    else{
                        tmp[ih][iw] = '-';
                    }
                    //cout <<  tmp[ih][iw] << ",";
                }
            }
            //cout << endl;
            
            int sum = 0;
            for(int ih=0; ih<h; ih++){
                for(int iw=0; iw<w; iw++){
                    if(tmp[ih][iw] == '#') sum++;
                }
            }
            //cout << "SUM:" << sum << endl;
            if(sum == k) ans++;
        }
    }
    cout << ans << endl;
        
    return 0;
}

Measured memory_bytes: 4072
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> line(n);
  int ans = 0;
  for(int i = 0; i < n; ++i) cin >> line[i];
  sort(line.begin(), line.end());
  for(int i = 0; i < n - 1; ++i){
    for(int j = i + 1; j < n; ++j){
      int max_index = lower_bound(line.begin(), line.end(), line[i] + line[j]) - line.begin();
      ans += max(0, max_index - (j + 1));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}

struct UnionFind {
    vector<int> parent;
    UnionFind(int n=0): parent(n, -1) {}
    int root(int x) {
        if (parent[x] < 0) return x;
        return parent[x] = root(parent[x]);
    }
    bool connect(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        parent[x] += parent[y];
        parent[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -parent[root(x)]; }
};


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

    vector<P> e;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        e.emplace_back(a, b);
    }

    int ans = 0;
    rep(i, m) {
        UnionFind tree(n);
        rep(j, m) if (i != j) tree.connect(e[j].first, e[j].second);
        int group = 0;
        rep(j, n) if (tree.root(j) == j) group++;
        if (group > 1) ans++;
    }
    cout << ans << endl;
}


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

int main() {
	int a, b, c[4] = {0, 0, 0, 0};
	for (int i = 0;i < 3;++ i) {
		cin >> a >> b;
		++ c[a - 1];
		++ c[b - 1];
	}
	for (int i = 0;i < 4;++ i) {
		if (c[i] >= 3) {
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

同値条件: 3個以上出現する数字が存在しない
全ての数字は１個ずつ出現するので、1-2-2-1ならok
1-3-1-1ならダメ
*/

Measured memory_bytes: 256
#include<stdio.h>

#define MAXW 10050
#define MAXN 105 
int dp[MAXN][MAXW];
int max(int a, int b){return a>b?a:b;}

int main(){
	//i means:the first ith ele and j means: the capacity
	int N = 0,W=0;
	scanf("%d %d",&N,&W);
	
	int ele[N+1][2];
	for(int i = 1; i<=N;i++){
		scanf("%d %d",&ele[i][0],&ele[i][1]);//v,w	
	}
	//boundary case for dp
	for(int i = 0; i<=N; i++){
		for(int j = 0; j<=W; j++){
		dp[i][j] = 0;
		}
	}
	
	for(int i = 1; i<=N; i++){
		for(int j = 1; j<=W; j++){
			dp[i][j] = dp[i-1][j];
			if(j-ele[i][1]>=0){
				dp[i][j] = max(dp[i-1][j],dp[i-1][j-ele[i][1]]+ele[i][0]);
			}
				
		}
	}
	/*for(int i = 0; i<=N; i++){
		for(int j = 0; j<=W; j++){
			printf("%d ",dp[i][j]);
		}
		printf("\n");
	}*/
	printf("%d\n",dp[N][W]);
	return 0;
}

Measured memory_bytes: 6692
#include <bits/stdc++.h>
using namespace std;
    int main(){
      int N;cin>>N;
      bool ok=true;
      int a[N];
      for(int i=0;i<N;i++)cin>>a[i];
      for(int i=0;i<N;i++){
          
          if(a[i]%2==0){
              ok=false;
              if(a[i]%3==0)ok=true;
              if(a[i]%5==0)ok=true;

          }
          if(ok==false)break;

      }
      if(ok)cout<<"APPROVED"<<endl;
      else cout<<"DENIED"<<endl;
    }






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

int main(){
    int n;
    cin >> n;
    int a[n], x;
    for(int i = 0; i < n; i ++){
        cin >> x;
        a[i] = x;
    }
    cout << a[n - 1];
    for(int i = 1; i < n; i ++){
        cout << " " << a[n - i - 1];
    }
    cout << endl;
    return 0;
}


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

string S;
int ans,now;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<char> left={'q','w','e','r','t'
                        ,'a','s','d','f','g'
                        ,'z','x','c','v','b'};
    while(cin >> S,S!="#"){
        ans=0;
        for (int i=0;i<S.size();++i){
            int L=count(left.begin(),left.end(),S[i]);
            if (i&&now!=L) ++ans;
            now=L;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3156
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int h, w;
	char *u, *v;
	scanf("%d %d", &h, &w);
	u = malloc(sizeof(char) * h);
	v = malloc(sizeof(char) * w);
	for(int i = 0; i < h; i++)u[i] = 0;
	for(int i = 0; i < w; i++)v[i] = 0;
	char **block = malloc(sizeof(char *) * h);
	for(int i = 0; i < h; i++){
		block[i] = malloc(sizeof(char) * (w + 1));
		scanf("%s", block[i]);
		for(int j = 0; j < w; j++){
			if(block[i][j] == '#'){
				u[i]++;
				v[j]++;
			}
		}
	}
	for(int i = 0; i < h; i++){
		if(u[i] == 0)continue;
		for(int j = 0; j < w; j++){
			if(v[j] > 0)printf("%c", block[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>

#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using namespace std;

int main() {
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N);
    vector<long long> seen(N, -1);
    rep(i, N) {
        cin >> A[i];
    }
    rep(i, N) {
        A[i]--;
    }

    long long ret = 0;
    long long md = 0;
    rep(i, K) {
        if (seen[ret] == -1) {
            seen[ret] = i;
            ret = A[ret];
            continue;
        }
        md = (K-i) % (i - seen[ret]);
        break;
    }

    rep(i, md) {
            ret = A[ret];
    }

    cout << ret + 1 << endl;


    return 0;
}


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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;


void solve(int testCase){

    ll A , B , N;
    scanf("%lld %lld %lld" , &A , &B , &N);

    if(N < B) {
            printf("%lld\n" , A*N / B);
    }
    else {
            N = B - 1;

            printf("%lld\n" , A*N / B);
    }

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,k;
vvi a;

int main(){
	cin>>k;
	n=(k+3)/4*2;
	a=vvi(n,vi(n));
	int t=(k+3)/4*4;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) a[i][j]=(i*n+(i+j)%(t/2))%t;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(k<=a[i][j]) a[i][j]-=t/2;
	if(k==1){
		n=1;
		a=vvi(n,vi(n));
		a[0][0]=0;
	}
	cout<<n<<endl;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) cout<<a[i][j]+1<<" \n"[j==n-1];
}

Measured memory_bytes: 2176
inputline = input().split()
a = int(inputline[0])
b = int(inputline[1])

def menseki(a,b):
    c = a*b
    return c
def syuu(a,b):
    d = a*2 + b * 2
    return d
print(str(menseki(a,b))+" "+str(syuu(a,b)))


Measured memory_bytes: 5596
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

// ll me(ll x,ll n)
// {
//   ll res=1;

//   while(n)
//   {
//     if(n&1)
//       res=(res*x)%mod;

//       x=(x*x)%mod;

//       n/=2;
//   }

//   return res;
// }



int main() 
{ 
    int n;
    scf(n); 
    
    vector<int>v;
    vector<int>w;
    

    rep(i,0,n)
    {
        int x,y;
        scf(x),scf(y);
        
        v.pb(x+y);
        w.pb(x-y);

    }
    
   sort(all(v));
    sort(all(w));

    int a=v[n-1]-v[0],b=w[n-1]-w[0];
    
    
    prin(max(a,b));

        //printf("\n");    
      
  
}   

Measured memory_bytes: 5100
n=[int(input()) for i in range(5)]
s=[0,0,0,0,0]
for i in range(5):
    if n[i]%10==0:
        s[i]=0
    else:
        s[i]=10-n[i]%10
#print(s)
a=s.index(max(s))
#print(a)
b=0
for i in range(5):
    if i!=a:
        b+=n[i]+s[i]
    else:
        b+=n[i]
print(b)

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

string lcs(string x,string y)
{
    int m = x.size(),n = y.size();
    int dp[m+1][n+1];
    for(int i = 0; i <= m; i++)
        dp[i][0] = 0;
    for(int j = 0; j <= n; j++)
        dp[0][j] = 0;

    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(x[i-1] == y[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
        }
    }
    ll index = dp[m][n];        // Length of LCS
	//cout << index << " " << m << " " << n << " " << dp[m][n] << "\n";
    string lcs = "";
    for(int i = 0; i < index; i++)
        lcs += "0";
    int i = m, j = n;

    while (i > 0 && j > 0)
    {
        if (x[i-1] == y[j-1])
        {
            lcs[index-1] = x[i-1];
            i--; j--; index--;
        }
        else if (dp[i-1][j] > dp[i][j-1])
            i--;
        else
            j--;
    }
    return lcs;
}

int main()
{
  string x,y;
  cin >> x >> y;
  
  cout << lcs(x, y) << "\n";
  return 0;
}

Measured memory_bytes: 35456
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>

using namespace std;

#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle {
  int f[N2];
  int space;
  int MD;
  int cost;

  bool operator < (const Puzzle& p) const {
    for (int i = 0; i < N2; i++) {
      if (f[i] == p.f[i]) {
        continue;
      }
      return f[i] < p.f[i];
    }
    return false;
  }
};

struct State {
  Puzzle puzzle;
  int estimated;
  bool operator < (const State& s) const {
    return estimated > s.estimated;
  }
};

int getAllMD(Puzzle pz) {
  int sum = 0;
  for (int i = 0; i < N2; i++) {
    if (pz.f[i] == N2) {
      continue;
    }
    sum += MDT[i][pz.f[i] - 1];
  }
  return sum;
}

int astar(Puzzle s) {
  priority_queue<State> PQ;
  s.MD = getAllMD(s);
  s.cost = 0;
  map<Puzzle, bool> V;
  Puzzle u, v;
  State initial;
  initial.puzzle = s;
  initial.estimated = getAllMD(s);
  PQ.push(initial);

  while (!PQ.empty()) {
    State st = PQ.top(); PQ.pop();
    u = st.puzzle;

    if (u.MD == 0) {
      return u.cost;
    }
    V[u] = true;

    int sx = u.space / N;
    int sy = u.space % N;

    for (int r = 0; r < 4; r++) {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if (tx < 0 || ty < 0 || tx >= N || ty >= N) {
        continue;
      }
      v = u;

      v.MD -= MDT[tx * N + ty][v.f[tx * N + ty] - 1];
      v.MD += MDT[sx * N + sy][v.f[tx * N + ty] - 1];
      swap(v.f[sx * N + sy], v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if (!V[v]) {
        v.cost++;
        State news;
        news.puzzle = v;
        news.estimated = v.cost + v.MD;
        PQ.push(news);
      }
    }
  }
  return -1;
}

int main(){
  for (int i = 0; i < N2; i++) {
    for (int j = 0; j < N2; j++) {
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
    }
  }

  Puzzle in;

  for (int i = 0; i < N2; i++) {
    cin >> in.f[i];
    if (in.f[i] == 0) {
      in.f[i] = N2;
      in.space = i;
    }
  }

  cout << astar(in) << endl;

  return 0;
}




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

using namespace std;

struct Edge {
	int src, dst;
	Edge(int f, int t) {
		src = f;
		dst = t;
	}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

vector<int> tarjan(const Graph& g) {
	int n = g.size(), idx = 0, k = 0, s = 0;
	vector<int>ord(n, -1), low(n), onS(n), cmp(n), stk(n);
	function<void(int)>dfs;
	dfs = [&](int v) {
		ord[v] = low[v] = idx++;
		stk[s++] = v;
		onS[v] = true;
		for (auto &e : g[v]) {
			int w = e.dst;
			if (ord[w] == -1) {
				dfs(w);
				low[v] = min(low[v], low[w]);
			}
			else if (onS[w]) {
				low[v] = min(low[v], ord[w]);
			}
		}
		if (low[v] == ord[v]) {
			while (1) {
				int w = stk[--s];
				onS[w] = false;
				cmp[w] = k;
				if (w == v)break;
			}
			++k;
		}
	};
	for (int v = 0; v<n; ++v)
		if (ord[v] == -1)dfs(v);
	return cmp;
}

int main() {
    int V, E;
    cin >> V >> E;
    Graph g(V);
    for (int i = 0; i<E; ++i) {
        int s, t; cin >> s >> t;
        g[s].emplace_back(s, t);
    }
    int Q; cin >> Q;
    vector<int>SCC = tarjan(g);
    for (int i = 0; i<Q; ++i) {
        int u, v; cin >> u >> v;
        cout << (SCC[u] == SCC[v]) << endl;
    }
}

Measured memory_bytes: 4360
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
ll find(ll x, ll y)
{ll res = 1;
while (y > 0)
{if(y & 1) res = (res*x) ;
y = y>>1;x = (x*x) ;
}return res;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int x;
cin>>x;
for(int i=-1000;i<1000;i++)
{
    for(int j=-1000;j<1000;j++)
    {
        int val=find(i,5);
        int r=find(j,5);
        if(val-r==x)
        {
            cout<<i<<" "<<j<<endl;
            return 0;
        }
    }
}
    return 0;
}


Measured memory_bytes: 3640
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

string s[110];
int p[110];

map<string, vector<P>> mp; 

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

  int n;
  cin >> n;

  REP(i, n){
    cin >> s[i] >> p[i];
    mp[s[i]].push_back({p[i], i+1});
  }
  
  for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
    sort(itr->second.begin(), itr->second.end());
    reverse(itr->second.begin(), itr->second.end());
    REP(i, itr->second.size()){
      cout << itr->second[i].second << endl;
    }
    //cerr << itr->second[itr->second.size()-1].second << endl;
  }

  
  
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;
int count_bit(int bit);

int main(){
    int N;
    scanf("%d",&N);
    int A[N];
    vector<vector<int>> x(N);
    vector<vector<int>> y(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
        for(int j=0;j<A[i];j++){
            int a,b;
            scanf("%d %d",&a,&b);
            x[i].push_back(a);
            y[i].push_back(b);
        }
    }
    int max_count=0;
    for(long bit=0;bit<(1<<N);bit++){
        bool ok=true;
        for(int i=0;i<N;i++){
            if((bit&(1<<i))>0){
                for(int j=0;j<A[i];j++){
                    if(y[i][j]==0){
                        if((bit&(1<<(x[i][j]-1)))>0)ok=false;
                    }
                    if(y[i][j]==1){
                        if((bit&(1<<(x[i][j]-1)))==0)ok=false;
                    }
                }
            }
        }
        if(ok){
            max_count = max(max_count,count_bit(bit));
        }
    }
    cout<<max_count<<"\n";
}

int count_bit(int bit){
    int a=0;
    while(bit!=0){
        if(bit%2==1)a++;
        bit = bit/2;
    }
    return a;
}






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

int main() {
  int h,w;
  cin >> h >> w;
  vector<string>data(h);
  vector<int>left(h);
  vector<int>right(h);
  for(int i = 0;i < h;i++) cin >> data[i];
  for(int i = 0;i < h;i++){
    bool flag = true;
    for(int j = 0;j < w;j++){
      if(data[i][j] == '#'){
        if(flag){
          left[i] = j;
          flag = false;
        }
        right[i] = j;
      }
    }
  }
  for(int i = 0;i < h-1;i++){
    if(right[i] != left[i+1]){
      cout << "Impossible" << endl;
      return 0;
    }
  }
  cout << "Possible" << endl;
  return 0;
}


Measured memory_bytes: 256
import array

N = int(input())
A = array.array('L', list(map(int, input().split())))
MAX = 10**5+1
X = array.array('L', [0]) * MAX
Y = array.array('L', range(MAX))

for i in range(len(A)): X[A[i]] += 1
    
Q = int(input())
cur = sum(array.array('L', (X[i]*Y[i] for i in range(len(X)))))

for i in range(Q):
    [b, c] = list(map(int, input().split()))
    cur = cur - X[b]*b + X[b]*c
    print(cur)
    X[c] += X[b]
    X[b] = 0



Measured memory_bytes: 21004
const config = {
    input: '/dev/stdin',
    newline: '\n'
};

const line = require('fs').readFileSync(config.input, 'utf-8').split(config.newline);

const solve = arr => {
    const helper = (xs, stack) => {
        if (xs.length === 0) return stack[0];
        const hd = xs[0];
        const tl = xs.slice(1);
        if (hd === '+') {
            const snd = stack.pop();
            const fst = stack.pop();
            stack.push(fst + snd);
        } else if (hd === '-') {
            const snd = stack.pop();
            const fst = stack.pop();
            stack.push(fst - snd);
        } else if (hd === '*') {
            const snd = stack.pop();
            const fst = stack.pop();
            stack.push(fst * snd);
        } else {
            stack.push(parseFloat(hd));
        }
        return helper(tl, stack); 
    };

    return helper(arr, []);
};

console.log(solve(line[0].split(' ')));



Measured memory_bytes: 16028
S=input()
S1=int(S[0]+S[1])
S2=int(S[2]+S[3])

if 1<=S1<=12 and 1<=S2<=12:
    print('AMBIGUOUS')

elif 1<=S1<=12 :
    print('MMYY')

elif 1<=S2<=12:
    print('YYMM')

else:
    print('NA')

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

struct UnionFind
{
	vector<int> r;						//represents parent/size*(-1) at child/root

	UnionFind(int n)
	{
		r = vector<int>(n, -1);
	}

	int root(int n)
	{
		if(r[n] < 0)	return n;
		else	return r[n] = root(r[n]);
	}

	void unite(int n, int m)
	{
		n = root(n), m = root(m);
		if(n != m)
		{
			if(r[m] < r[n])	swap(m, n);	//represent larger by n
			r[n] += r[m];
			r[m] = n;
		}
	}

	int size(int n)
	{
		return -r[root(n)];
	}
};

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

	UnionFind UF(n);
	int a, b;
	for(int i = 0; i < m; i++)
	{
		cin >> a >> b;
		a--, b--;
		UF.unite(a, b);
	}

	int ans = 0;
	for(int i = 0; i < n; i++)		//Max size set
	{
		ans = max(ans, UF.size(i));
	}

	cout << ans << endl;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))



void solve(){
    map<ll,ll> m;
    ll n,temp;cin>>n;
    rep(i,0,n){
        cin>>temp;
        m[temp]++;
    }
    ll ans=0;
    for(auto u:m){
        if(u.y%2!=0){
            ans++;
        }
    }
    cout<<ans;



}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;

    while(t--){
        solve();
    }
    return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

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

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

  a--;
  int lcm = c/gcd(c, d)*d;

  int ta1 = a / c;
  int ta2 = a / d;
  int ta3 = a / lcm;

  int tb1 = b / c;
  int tb2 = b / d;
  int tb3 = b / lcm;

  int t1 = tb1 - ta1;
  int t2 = tb2 - ta2;
  int t3 = tb3 - ta3;

  int ans = (b-a) - (t1+t2-t3);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		sc.close();

		char s[] = new char[S.length()];

		for (int i = 0; i < S.length(); i++) {
			s[i] = S.charAt(i);

			if (i == 0) {
				if (s[i] != 'A') {
					System.out.print("WA");
					return;
				}
			}

			if (i == S.length() - 1) {
				if (s[i] == 'C') {
					System.out.print("WA");
					return;
				}
			}
		}

		int countC = 0;
		int indexC = 0;

		for (int i = 2; i < S.length() - 1; i++) {
			if (s[i] == 'C') {
				countC++;
				indexC = i;
			}
		}

		if (countC != 1) {
			System.out.print("WA");
			return;
		}

		for (int i = 1; i < S.length(); i++) {
			if (i == 0) {
				continue;
			}
			if (i == indexC) {
				continue;
			}

			if (Character.isUpperCase(s[i])) {
				System.out.print("WA");
				return;
			}
		}
		System.out.print("AC");
	}
}

Measured memory_bytes: 23124
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto ap = readNums!int;

  writeln((ap[0]*3+ap[1])/2);
}


Measured memory_bytes: 256
n=int(input())
d={}
ans=0
for i in range(n):
    s=sorted(list(input()))
    e=""
    for v in range(10):
        e+=s[v]
    if e in d:
        d[e]+=1
    else:
        d[e]=1
for _ in d:
    if d[_]==1:
        pass
    else:
        ans+=d[_]*(d[_]-1)//2
print(ans)

Measured memory_bytes: 17808