akhauriyash/Code-Regression huggingface dataset:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output


def chkprint(*args):
    names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))

# Binary converter


def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]

# --------------------------------------------


dp = None


def main():
    A, B, X = li_input()

    if A <= X <= A + B:
        print("YES")
    else:
        print("NO")


main()


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

using namespace std;

int main() {
  int N;
  cin >> N;
  priority_queue<double> q;
  for (int i = 0; i < N; i++) {
    double A;
    cin >> A;
    q.push(-A);
  }

  while (q.size() > 1) {
    double a = -q.top();
    q.pop();
    double b = -q.top();
    q.pop();
    q.push(-(a + b) / 2.0);
  }

  printf("%.9lf\n", -q.top());
  return 0;
}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}

ll ngcd(vector<ll> a)
{
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size() && res != 1; i++)
  {
    res = gcd(a[i], res);
  }
  return res;
}

//実行部
void Main()
{
  ll n; cin >> n;
  ll sumuke, arai = 0; 
  vll a(n); rep(i, n) { cin >> a[i]; arai += a[i]; }
  sumuke = a[0], arai -= a[0];
  ll ans = abs(sumuke - arai);
  for(ll i = 1;i < n - 1;i++)
  {
    sumuke += a[i];
    arai -= a[i];
    ans = min(ans, abs(sumuke - arai));
  }
  fin(ans);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


Measured memory_bytes: 1792
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m, k;
    cin >> m >> k;
    int mm = 1 << m;
    printde(m, k, mm);
    if(k == 0){
        for(int i = 0; i < mm; i++){
            cout << i << ' ' << i << ' ';
        }
        return 0;
    }
    if(k >= mm || (m == 1 && k == 1)){
        cout << -1 << '\n';
        return 0;
    }
    cout << k << ' ';
    for(int i = 0; i < mm; i++){
        if(i == k){ continue; }
        cout << i << ' ';
    }
    cout << k << ' ';
    for(int i = mm - 1; i >= 0; i--){
        if(i == k){ continue; }
        cout << i << ' ';
        // cout << i << " \n"[i == 0];
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;


int main(){
    ll N;
    cin >> N;
    vll A(N+1);
    for(int i=2; i<N+1; i++){
        cin >> A[i];
    }
    vll ans(N+1, 0);
    for(int i=2; i<N+1; i++){
        ans[A[i]]++;
    }
    for(int i=1; i<N+1; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 6424
#include<iostream>
#include<string>
#include<algorithm>

typedef long long ll;
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXX 1e18

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll X,K,D; cin>>X>>K>>D;
    if(X > 0)
    {
        ll req = X/D;
        req = min(req,K);
        
        ll diff = K - req;
        
        if(diff%2)
            X = X - (req + 1)*D;
        else
            X = X - req*D;
        
        X = abs(X);
    }
    else
    {
        ll req = (ll)abs(X)/D;
        req = min(req,K);
        ll diff = K - req;
        if(diff%2)
            X = X + (req + 1)*D;
        else
            X = X + req*D;
        
        X = abs(X);
    }
    
    cout<<X<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  set<ll> b;
  int maxi = 0;
  int count = 0;
  vector<ll> temp(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int rec = b.size();
    b.insert(a[i]);
    int rec2 = b.size();
    if (rec == rec2) {
      temp[count] = a[i];
      count++;
      b.erase(a[i]);
    }
  }
  sort(temp.rbegin(), temp.rend());
  cout << temp[0] * temp[1] << endl;
}


Measured memory_bytes: 6528
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B = MAP()

if N % (A + B) <= A:
    print(int(N / (A + B)) * A + N % (A + B))
else:
    print(int(N / (A + B)) * A + A)


Measured memory_bytes: 5836
process.stdin.resume();
process.stdin.setEncoding('utf8'); 
var lines = [];
var reader = require('readline').createInterface({
	input: process.stdin,
	output: process.stdout
});
 
reader.on('line', (line) => {
	lines.push(line);
});

reader.on('close', () => {
	"use strict"
	const N = +lines[0].split(" ")[0];
	const M = +lines[0].split(" ")[1];
	const L = Array.from(Array(M), (e,i) => 
		+lines[i+1].split(" ")[0]);
	const R = Array.from(Array(M), (e,i) => 
		+lines[i+1].split(" ")[1]);
	
	const max_L = L.reduce((a,b) => Math.max(a,b), 1);
	const min_R = R.reduce((a,b) => Math.min(a,b), N);
	
	if(max_L>min_R){console.log(0)}
	else{console.log(min_R-max_L+1)}
});

Measured memory_bytes: 50164
#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 x;
  cin>>x;
  long long int a[100][100];
  for(int i=1;i<33;i++){
    for(int j=2;j<11;j++){
      if(pow(i,j)>x) break;
      a[i][j]=pow(i,j);
    }
  }
  int min=1000000;
 for(int i=1;i<33;i++){
    for(int j=2;j<11;j++){
      if(min>=x-a[i][j]){
        min=x-a[i][j];
      }
    }
  }
  cout<<x-min<<endl;
}

      

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int t;
long long a ,b , c, d;
long long l , r;
bool check(long long l,long long r,long long d)
{
    if(l % d == 0 || r % d == 0) return 1;
    return (l / d != r / d);
}
bool chk(long long a)
{
    if(l <= r){
        if(check(l , r , a)) return 0;
        else return 1;
    }
    else{
        if(check(0 , l , a) || check(r , d - 1 , a)) return 0;
        else return 1;
    }
}
long long gcd(long long x,long long y)
{
    return (x % y == 0) ? y : gcd(y , x % y);
}
int main()
{
    scanf("%d",&t);
    while(t--){
        scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
        if(d < b){
            puts("No");continue;
        }
        if(a < b){
            puts("No");continue;
        }
        if(c + 1 > b - 1){
            puts("Yes");continue;
        }
        long long k = (a - c) / b;a -= k * b;
        if(a > c) a -= b;
        if(a < 0){
            puts("No");continue;
        }
        d %= b;
        if(d == 0){
            puts("Yes");continue;
        }
        if(d < b - c){
            puts("No");continue;
        }
        l = (c + 1) % d , r = (b - 1) % d;
        l = (l - a + d) % d;r = (r - a + d) % d;
        //printf("%lld %lld %lld\n",l,r,a);
        //a = gcd(a , d);
        //printf("%lld %lld %lld\n",l,r,a);
        if(chk(gcd(b , d))) puts("Yes");
        else puts("No");
    }
    return 0;
}


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

#define F(i, a, n) for(int i=a;i<n;i++)
#define REP(i, n) F(i, 0, n)
#define REP1(i, n) for(int i=1;i<=n;i++)
#define MOD 1000000007

typedef long long ll;

const int MAX = 2e6 + 5;

int a,b,c;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>a>>b>>c;
	if(c >= a && c <= b)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
/*

????????°n
u k v1 v2 ...
u = ????????????
k = u???????¬???°
vi = ??£??\??????????????????

4		
1 2 2 4
2 1 4
3 0
4 1 3
*/

import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n, u, k, v;
		
		n = in.nextInt();
		int[][] ary = new int[n][n];
		
		//??£??\?????????????????£??\??????
		for(int i=0; i<n; i++){
			u = in.nextInt();
			k = in.nextInt();
			for(int j=0; j<k; j++){
				v = in.nextInt();
				ary[u-1][v-1] = 1;
			}
		}
		
		//??£??\???????????¨???
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				System.out.print(ary[i][j]);
				if(j != n-1) System.out.print(" ");
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 25868
#include<bits/stdc++.h>
using namespace std;
int cmp(int a,int b)
{
	return a>b;
}
long long a[4];
int main()
{
	for(int i=1;i<=3;i++)
	cin>>a[i];
	sort(a+1,a+4,cmp);
	if(a[2]-a[1]==a[3]-a[2])
	cout<<"YES";
	else 
	cout<<"NO";
	cout<<endl;
	return 0;
}

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

int main(void) {
  string S;
  map<char, int> ma;
  cin >> S;
  for (int i = 0; i < (int)S.length(); i++) {
    ma[S[i]]++;
  }

  for (auto m : ma) {
    if (m.second != 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 764
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((a<c&&c<b)||(a>c&&c>b))System.out.println("Yes");
        else System.out.println("No");
        
    }
    
 
}class Po{
    int a,b;
    public Po(int a,int b){
        this.a=a;
        this.b=b;
    }
    public String toString(){
        return a+" "+b;
    }
}


Measured memory_bytes: 21588
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<stack>
#include<queue>
#include<list>

using namespace std;

char s;
int main()
{
	cin >> s;
	if(s >= 'a' && s <= 'z')
	{
		printf("a\n");
	}
	else
	{
		printf("A\n");
	}
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
int A, B;
  cin >> A >> B;//入力完了
  int plug = 1;
  int counter = 0;
  for(int i = 0; i < 21; i++){
    if (plug + (A - 1) * i >= B)
    break;
    counter++;
  }
    cout << counter << endl;
}

Measured memory_bytes: 256
#include <climits>    
#include <iostream>
    #include <string>
    #include <cmath>
    
     
    using namespace std;
     
    string s;
    const int n = 753;
     
    int main() {
    	cin >> s;
    	int res = 1000;
    	for (int i = 0; i < (int)s.length() - 2; ++i) {
    		int num = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
    		if (abs(num - n) < res) {
    			res = abs(num - n);
    		}
    	}
        
        cout << res << endl;
    }

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def init_prime(n_max :int):
    """ https://qiita.com/fantm21/items/5e270dce9f4f1d963c1e
    # returns prime list [2..n_max]
    """
    if n_max <= 1: return []
    if n_max == 2: return [2,]
    prime = [2,]
    _app_p = prime.append
    limit = int(n_max**0.5)
    data = [i for i in range(3, n_max+1, 2)]
    while data:
        p = data[0]
        if p > limit:
            return prime + data
        _app_p(p)
        data = [e for e in data if e%p]

def main():
    N = 10**5
    vP = init_prime(N)
    sP = set(vP)

    vA = [0,]
    appA = vA.append
    cnt = 0
    for i in range(1, N+1):
        if i in sP and (i+1)//2 in sP:
            cnt += 1
        appA(cnt)

    #print(vA[:2018])###

    Q = int(input())
    vRes = []
    appRes = vRes.append
    for _ in range(Q):
        L, R = map(int, input().split())
        appRes(vA[R] - vA[L-1])
    print(*vRes, sep="\n")

if __name__ == "__main__":
    main()


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

using namespace std;

typedef long long ll;

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
//#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795


ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll N=2e5+1;

ll solve(ll t,vector<ll>& a,ll n)
{
  ll ans=0;
  for(int i=1;i<=n;i++)
    ans+=(a[i]-t)*(a[i]-t);

  return ans;

}


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

ll n,k;cin>>n>>k;

ll cnt=0;
while(n)
{
  n/=k;
  cnt++;
}

cout<<cnt<<"\n";

}

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

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

signed main(){
    llin(n);
    llin(k);
    stin(s);
    ll p=0;
    FOR(i,1,n-1){
        if(s[i-1]!=s[i]){
            p++;
        }
    }
    sal(min(n-1,(n-1-p+(p/2<=k?(p/2)*2+k-p/2:k*2))))
}


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

int main() {
    string X;
    string Y;
    cin >> X >> Y;
    if(X[0] == Y[2] && X[2] == Y[0]){
      if(X[1] == Y[1]){
        cout << "YES" << endl;
      }
      else {
        cout <<"NO"<<endl;
      }
    }
    else {
      cout << "NO" << endl;
    }
}



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

using namespace std; 

int h[100005], dp[100005]; 

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

	for(int i = 0; i < n; i++){
		cin >> h[i]; 
	}

	dp[0] = 0; 
	dp[1] = abs(h[1] - h[0]); 

	for(int i = 2; i < n; i++){
		dp[i] = abs(h[i] - h[i - 1]) + dp[i - 1];
		for(int j = 2; i - j >= 0 && j <= k; j++ )
			dp[i] = min(abs(h[i] - h[i - j]) + dp[i - j], dp[i]); 

		//cout <<dp[i] << " "; 
	}

	cout << dp[n - 1] << endl; 
}

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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    rep(i, N) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
local S = io.read()
local m = -1
local a = {}
a[#S+1] = 0
local t = {}
for i=#S,1,-1 do
  local c = S:sub(i,i)
  if c == '>' then
    a[i] = a[i+1] + 1
    m = math.max(m, a[i+1])
  else
    a[i] = 0
  end
end
for i=1,#S do
  local c = S:sub(i,i)
  if c == '<' and a[i+1] <= a[i] then
    a[i+1] = a[i] + 1
  end
end
local s = 0
for i=1,#a do
  --print(a[i])
  s = s + a[i]
end
print(s)


Measured memory_bytes: 17304
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;

int n,a,b;

int main() {
	scanf("%d %d %d",&n,&a,&b);
	if(a+b-1<=n && n<=(LL)a*b) {
		int p=0,res=n;
		for(int i=1;i<=a;i++) {
			int c=min(res-(a-i),b);
			for(int j=p+c;j>p;j--) {
				printf("%d ",j);
			}
			res-=c;
			p+=c;
		}
		printf("\n");
	}
	else {
		printf("-1\n");
	}
}

Measured memory_bytes: 2176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[] seqS = new int[n];
      String line = br.readLine();
      StrSplitToInt stoi = new StrSplitToInt(line, " ");
      for (int i=0; i<n; i++)
        seqS[i] = stoi.nextInt();

      int q = Integer.parseInt(br.readLine());
      String[] lines = br.readLine().split(" ");
      
      int cnt=0;
      for (String ref : lines) {
        if( isExistSeachByBinary(seqS, Integer.parseInt(ref)) )
          cnt++;
      }

      System.out.println(cnt);
    }
  }

  static boolean isExistSeachByBinary(int[] tar, int ref) {
    int left = 0;
    int right= tar.length;
    int mid;
    while( left < right ) {
      mid  = (left + right) / 2;
      if( tar[mid] > ref ) right = mid;
      else if(tar[mid] < ref ) left = mid + 1;
      else return true;
    }

    return false;
  }
}

class StrSplitToInt {
  final String s;
  final String split;
  final int endPos;
  final int splitLen;
  int currentPos;
  int nextPos;

  public StrSplitToInt(String s,String split) {
    this.s = s;
    this.split = split;
    currentPos = 0;
    nextPos = s.indexOf(split, currentPos);
    endPos = s.length();
    splitLen = split.length();
  }

  public int nextInt() {
    if( currentPos < endPos ) {
      int ret = Integer.parseInt( s.substring(currentPos, nextPos) );
      currentPos = nextPos + splitLen;
      nextPos = s.indexOf(split, currentPos);
      if(nextPos == -1) nextPos = endPos;

      return ret;
    }
    else
      return -1;
  }
}


Measured memory_bytes: 50208
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
 
#define rep(i,n) for(int i = 0; i < n; i++)
 
typedef long long ll;
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;
 
int main(){
  int n;
  cin >> n;
  vector<tuple<string,int,int> > vt;
  rep(i,n){
    string a;
    int b;    
    cin >> a >> b;
    vt.emplace_back(a,-b,i+1);
  }
  sort(vt.begin(), vt.end());
  rep(i,n) cout << get<2>(vt[i]) << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long llong;

int N, A;
int X[52];

llong DP[52][50*50+4];

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(NULL);

   cin >> N >> A;
   for (int i = 0; i < N; ++i)
      cin >> X[i];

   DP[0][0] = 1;
   for (int i = 0; i < N; ++i) {
      for (int k = i; k >= 0; --k) {
         for (int sum = 2500 - X[i]; sum >= 0; --sum) {
            if (DP[k][sum] == 0) continue;
            DP[k+1][sum+X[i]] += DP[k][sum];
         }
      }
   }

   llong ways = 0;
   for (int k = 1; k <= N; ++k) {
      int sum = k * A;
      ways += DP[k][sum];
   //   cerr << k << ' ' << sum << ' ' << DP[k][sum] << endl;
   }

   cout << ways << endl;

   return 0;
}


Measured memory_bytes: 640
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*
import kotlin.comparisons.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val (a, b) = readListOfInt()

    var total = 1
    var count = 0
    while(total < b) {
        total = (total - 1) + a
        count++
    }
    println(count)
    

    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }


// Extensions
fun<T> List<T>.toBuckets(bucketKeys: List<T>): Map<T, Int> {
    val buckets = bucketKeys.associate { t -> Pair(t, 0) }.toMutableMap()
    this.forEach { t ->
        buckets[t] = buckets[t]!! + 1
    }
    return buckets
}

fun <K, V> Map<K, V>.toMutableMap(): MutableMap<K, V> = HashMap(this)

// Util Functions
fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun Double.isDecimal(): Boolean = ((this - Math.floor(this)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 37756
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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



struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};




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

  if(k == 1 || n % k == 0){
    print(0);
    return 0;
  }
  ll ans = abs((n % k) - k);
  n > ans ? print(ans) : print(n);
  return 0;
}

Measured memory_bytes: 256
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end
x,y = gi
puts (x-y).abs <= 1 ? 'Brown' : 'Alice'


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

int main()
{
  int A,B;
  scanf("%d %d",&A,&B);

  if (A>B)
    printf("%d",A+(A-1));
  else if (A<B)
    printf("%d",B+(B-1));
 else if (A==B)
    printf("%d",A+B);

 return 0;
}


Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repr(i, a, b) for (int i = a; i <= b; ++i)
#define dep(i, a, b) for (int i = a; i > b; --i)
#define depr(i, a, b) for (int i = a; i >= b; --i)
#define getnum(n) scanf("%d", &n)
#define LL long long
#define INF 0x7f7f7f7f
#define PI acos(-1.0)
using namespace std;

const int MAXN = 1e5 + 5;
int f[MAXN], mark[MAXN], n, q, x, qt[MAXN], qv[MAXN], cnt, t;
LL ans;

inline int Find(int x) {
	return mark[x] < t ? x : f[x] = Find(f[x]);
}

inline void Init() {
	mark[1] = cnt = ans = 0;
	f[1] = 1;
	repr(i, 2, n) {
		getnum(f[i]);
		mark[i] = INF;
	}
}

inline void Solve() {
	char op[2];
	repr(i, 1, q) {
		scanf("%s%d", op, &x);
		if (op[0] == 'Q') {
			qt[cnt] = i;
			qv[cnt++] = x;
		}
		else mark[x] = min(mark[x], i);
	}
	while (cnt) {
		t = qt[--cnt];
		ans += Find(qv[cnt]);
	}
	
	printf("%lld\n", ans);
}

int main()
{
	while (~scanf("%d%d", &n, &q) && (n || q)) {
		Init();
		Solve();
	}
	return 0;
}

Measured memory_bytes: 4380
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val set = mutableSetOf<Int>()
    
    for (i in 1..N) {
        set.add(readInputLine().toInt())
    }
    
    println(set.size)
}

fun readInputLine(): String {
    return readLine()!!
}


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

int gcd[201][201];

int findGcd(int a,int b){
	if(gcd[a][b] != -1 || gcd[b][a] != -1)
		return gcd[a][b] = gcd[b][a];
		
	int x=max(a,b);
	int y=min(a,b);
	
	while(x % y != 0){
		int old_y = y;
		y=x % y;
		x=old_y;
	}
	return gcd[a][b] = gcd[b][a] = y;
}

int main(){
	int n;
	cin>>n;
	int g;
	int sum=0;
//	memset(gcd, -1, sizeof(gcd));
	
	for(int i = 0; i <= 200;i++)
		for(int j = 0; j <= 200; j++)
			gcd[i][j] = -1;
	
	for(int i = 1; i <= 200; i++) {
		for(int j = 1; j <= 200; j++) {
			gcd[i][j] = gcd[j][i] = findGcd(i, j);
		}
	}
	
	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= n ; j++){
			for(int k = 1 ; k <= n ; k++){
				g = gcd[i][j];
				
//				gcd=findGcd(i,j);
				sum += gcd[g][k];
			}
		}
	}
	cout<<sum<<endl;
	
}

Measured memory_bytes: 3796
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    int N;
    cin >> N;
    vector<int> b(N),ans;
    for(int i = 0; i < N;i++){
        cin >> b[i];
    }
    bool didItDelete;
    for(int j = 0; j < N ;j++){
        didItDelete = false;
        for(int i = b.size()-1; i >= 0;i--){
            if(b[i] == i+1){
                didItDelete = true;
                ans.push_back(b[i]);
                b.erase(b.begin()+i);
                break;
            }
        }
        if(!didItDelete){
            cout << -1 << endl;
            return 0;
        }
    }

    reverse(ALL(ans));
    for(int i = 0; i < N;i++)cout << ans[i] << endl;
    return 0;
}

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

constexpr int INF = 1e9;

using graph = std::vector<std::vector<int>>;

bool dfs(graph const& g, int v, std::vector<int>& match, std::vector<bool>& used) {
    used[v] = true;
    for(auto u : g[v]) {
        int w = match[u];
        if(w < 0 || !used[w] && dfs(g, w, match, used)) {
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching(graph const& g) {
    const int V = g.size();
    std::vector<int> match(V, -1);
    std::vector<bool> used(V);
    int res = 0;
    for(int v=0; v<V; ++v) {
        if(match[v] < 0) {
            std::fill(used.begin(), used.end(), false);
            if(dfs(g, v, match, used)) {
                ++res;
            }
        }
    }
    return res;
}

int main() {
    int N, M, L;
    while(cin >> N >> M >> L, N) {
        vector<vector<int>> d(N, vector<int>(N, INF));
        for(int i=0; i<N; ++i) {
            d[i][i] = 0;
        }
        for(int i=0; i<M; ++i) {
            int u, v, dd;
            cin >> u >> v >> dd;
            d[u][v] = d[v][u] = dd;
        }
        for(int k=0; k<N; ++k) {
            for(int i=0; i<N; ++i) {
                for(int j=0; j<N; ++j) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        vector<int> p(L), t(L);
        for(int i=0; i<L; ++i) {
            cin >> p[i] >> t[i];
        }
        graph g(L*2);
        for(int i=0; i<L; ++i) {
            for(int j=0; j<L; ++j) {
                if(i == j) {
                    continue;
                }
                if(d[p[i]][p[j]] <= t[j] - t[i]) {
                    g[i].push_back(L+j);
                }
            }
        }
        cout << L - bipartite_matching(g) << endl;
    }
}


Measured memory_bytes: 5428
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		sc.close();
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			char a = A.charAt(i);
			char b = B.charAt(i);
			char c = C.charAt(i);
			if(a == b && b == c) continue;
			if((a == b && a != c) || (a == c && a != b) || (b == c && a != b)) {
				cnt ++;
			}else {
				cnt += 2;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 22732
import java.util.Scanner;

class Solver {
    void solve(Scanner sc) {
        String s = sc.next();
        System.out.println(s.matches("[RUD](([LUD][RUD])+)?[LUD]?") ? "Yes" : "No");
    }
}

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

        new Solver().solve(in);

        in.close();
    }
}

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

int main(){
    int x,y;
    cin>>x>>y;
    if(x<y){
        for(int i=0;i<y;i++){
            cout<<x;
        }
        cout<<endl;
    }
    else{
        for(int i=0;i<x;i++){
            cout<<y;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
from bisect import insort

t = int(input())
buf = []
for _ in range(t):
    n = int(input())
    aaa = list(map(int, input().split()))
    s = input()

    is_ok = 0

    can = []
    for i in range(n - 1, -1, -1):
        a = aaa[i]
        if s[i] == '0':
            for (b, c) in can[::-1]:
                if a & b:
                    a ^= c
            if a:
                b = 1 << (a.bit_length() - 1)
                insort(can, (b, a))
        else:
            for (b, c) in can[::-1]:
                if a & b:
                    a ^= c
            if a:
                is_ok = 1
                break

    buf.append(is_ok)

print('\n'.join(map(str, buf)))


Measured memory_bytes: 9180
#include<stdio.h>
#include<string.h>
int N,M,Q,i,j,k;
char S[1000],B[1005],*s="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",res[1005];
int flg[1005][37],f,f2;

int main()
{
	for(;scanf("%d%d%d\n",&N,&M,&Q),N;)
	{
		int swt[37]={0};
		memset(res,0,sizeof(res));
		for(i=0;i<M;i++)for(j=0;j<N;j++)flg[i][j]=1;
		for(i=0;i<Q;i++)
		{
			scanf("%s %s\n",S,B);
			for(j=0;j<N;j++)
			{
				swt[j]^=(S[j]=='1'?1:0);
				for(k=0;k<M;k++)
				{
					if(flg[k][j]!=0&&swt[j]&&B[k]=='1')flg[k][j]=1;
					else if(flg[k][j]!=0&&swt[j]&&B[k]=='0')flg[k][j]=0;
					else if(flg[k][j]!=0&&(!swt[j])&&B[k]=='1')flg[k][j]=0;
				}
			}
		}
		f2=0;
		for(i=0;i<M;i++)
		{
			f=-1;
			for(j=0;j<N;j++)
			{
				if(f!=-2&&flg[i][j]==1)
				{
					if(f!=-1)f=-2;
					else f=j;
				}
			}
			res[i]=(f==-2?'?':s[f]);
		}
		//for(i=0;i<M;i++)
		puts(res);
	}
	return 0;
}

Measured memory_bytes: 744
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int dist[2002][2];

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

  string A,B;
  cin>>A;
  cin>>B;

  int N=A.size();
  bool allz=true;
  rep(i,N) if(B[i]=='1') allz=false;
  if(allz){
    if(A==B) cout<<0<<endl;
    else cout<<-1<<endl;
    return 0;
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<2;j++){
      int d=1;
      if(j==1) d=-1;
      for(int k=0;k<N;k++){
        int x=(i+k*d+N)%N;
        if(B[x]=='1'){
          dist[i][j]=k;
          break;
        }
      }
    }
  }

  auto go=[&](int a,int d){
    return (a+d+N)%N;
  };

  int ans=N*N;
  for(int k=0;k<2;k++){
    for(int i=0;i<N;i++){
      int w=-i;
      if(k) w=N-i;
      int diff=0;
      set<pair<int,int>> se;
      set<pair<int,int>> rest;
      for(int j=0;j<N;j++){
        int nex=go(j,w);
        if(A[j]!=B[nex]){
          diff++;
          if(dist[j][1-k]<=abs(w)) continue;
          se.insert(mkp(dist[j][k],j));
          rest.insert(mkp(dist[nex][1-k],nex));
        }
      }
      if(se.size()==0){
        chmin(ans,abs(w)+diff);
        continue;
      }

      auto it=se.end();
      it--;
      chmin(ans,abs(w)+diff+(*it).first*2);

      while(se.size()){
        auto f=se.begin();
        int now=(*f).second;
        int cost=(*f).first;
        rest.erase(mkp(dist[go(now,w)][1-k],go(now,w)));
        se.erase(f);

        int res=cost*2;
        if(rest.size()){
          auto itr=rest.end();
          itr--;
          res+=(*itr).first*2;
        }
        chmin(ans,abs(w)+res+diff);
      }
    }
  }

  cout<<ans<<endl;

  return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a % 2 == 0 || b % 2 == 0) {
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
import itertools

n = int(input())
l = list(map(int, input().split()))

x = 0
for ls in itertools.combinations(l, 3):
    if len(set(ls)) != 3:
        continue
    if ls[0] + ls[1] > ls[2] and ls[1] + ls[2] > ls[0] and ls[0] + ls[2] > ls[1]:
        x += 1
print(x)

Measured memory_bytes: 9176
# ABC 107: B – Grid Compression
h, w = [int(s) for s in input().split()]
a = [input() for _ in range(h)]

rows = []
columns = []

for i in range(w):
    for j in range(h):
        if a[j][i] != '.':
            break
    else:
        columns.append(i)

for i in range(h):
    if a[i].count('#') == 0:
        rows.append(i)

for i in range(h):
    tmp = ''
    if i not in rows:
        for j in range(w):
            if j not in columns:
                tmp += a[i][j]
        print(tmp)

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

int main() {
  int n, p;
  string s;
  cin >> s;
  n=(int)(s.length());
  p=2019;

  vector<int> d(n+1);
  int ten = 1;
  for (int i = n-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
  }
  vector<int> cnt(p);
  ll ans = 0;
  for (int i = n; i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4388
n = int(input())

def dfs(s):
    if int(s) > n:
        return 0
    if all(s.count(c) > 0 for c in "753"):
        ret = 1
    else:
        ret = 0
    for c in "753":
        ret += dfs(s + c)
    return ret

print(dfs("0"))

Measured memory_bytes: 2940
#include <ctype.h>
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

//char rbuf[]; int rbufl;
//#define getchar() rbuf[rbufl++]
#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void printint(int32_t x){ if(x<0){x=-x; putchar('-');}else if(x==0){putchar('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar(s[i]); putchar('\n'); }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

int p[5000];
int c[5000];
int main(void){
	int n=nextint();
	int k=nextint();
	for(int i=0; i<n; i++) p[i]=nextint()-1;
	for(int i=0; i<n; i++) c[i]=nextint();
	long ans=LONG_MIN;
	for(int i=0; i<n; i++){
		long r=c[i];
		int s=1;
		for(int j=p[i]; j!=i; j=p[j]){
			r+=c[j];
			s++;
		}
		if(r>0){
			int K=k<s?0:(k/s-1)*s;
			long C=K/s*r;
			if(K>0&&C>ans) ans=C;
			int j=i;
			for(K++; K<=k; K++){
				C+=c[j];
				if(C>ans) ans=C;
				j=p[j];
			}
		}else{
			int t=s>k?k:s;
			int K=0;
			long C=K/s*r;
			//if(K>0&&C>ans) ans=C;
			int j=i;
			for(K++; K<=t; K++){
				C+=c[j];
				if(C>ans) ans=C;
				j=p[j];
			}
		}
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 1644
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int X, A;
    cin >> X >> A;
    if (X < A) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}

Measured memory_bytes: 764
n,a,b = map(int,input().split())
s = list(input())
A = 0 #国内の合格者
B = 0 #海外の合格者

for i in range(n):
    if s[i] == "c":
        print("No")
    elif s[i] == "a" and (A + B) < a + b:
        print("Yes")
        A += 1
    elif s[i] == "b" and (A + B) < a + b and B < b:
        print("Yes")
        B += 1
    else:
        print("No")


Measured memory_bytes: 4708
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <time.h>

using namespace std;
typedef long long int ll;

int main()
{
	int n;
	scanf("%d", &n);
	if(n>=1000){
		printf("ABD\n");
	}else{
		printf("ABC\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  int n=s.size();
  bool p=true;
  rep(i,0,n){
    if(s[i]!=s[n-1-i]){
      p=false;
    }
  }
  rep(i,0,(n-1)/2){
    if(s[i]!=s[(n-1)/2-1-i]){
      p=false;
    }
  }
  rep(i,0,(n-1)/2){
    if(s[(n+1)/2+i]!=s[n-1-i]){
      p=false;
    }
  }
  if(p) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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


int main(){
    string s;
    cin >> s;
    string rs = s;
    reverse(rs.begin(), rs.end());
    bool flag = true;
    if(s != rs) flag = false;
    int a = (s.size()-1)/2;
    if(s.substr(0,a) != rs.substr(a+1)) flag=false;
    if(s.substr(a+1) != rs.substr(0,a)) flag=false;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

void Main() {
  int a, b;
  cin >> a >> b;
  cout << max(max(a + b, a - b), a * b) << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
import std.stdio,std.conv,std.algorithm,std.array;

int[] 		raia(){ return readln().split().map!(to!int).array; }	//read as int[]
string[]	rasa(){ return readln().split(); }			//read as string[]
void main()
{
	auto it = raia();
	it.sort();
	writeln( it[0]," ",it[1]," ",it[2]);
}

Measured memory_bytes: 1060
module M = Map.Make (struct type t = int let compare = compare end) ;;

Scanf.scanf "%d %d %d" (fun n d a ->
    let xh = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x h -> x, h)) in
    Array.sort compare xh;
    let add key v map = M.add key (v + try M.find key map with _ -> 0) map in
    let rec loop i event level bomb =
        if i = n then Printf.printf "%d\n" bomb else 
            let (x, h) = xh.(i) in
            if M.is_empty event then (
                let count = (h + a - 1) / a in
                let event = add (x + 2 * d) (-count * a) event in
                loop (i + 1) event (level + count * a) (bomb + count)
            ) else (
                let (next_x, decl) = M.min_binding event in
                if next_x < x then (
                    let event = M.remove next_x event in
                    loop i event (level + decl) bomb
                ) else (
                    if h <= level then (
                        loop (i + 1) event level bomb
                    ) else (
                        let count = (h - level + a - 1) / a in
                        let event = add (x + 2 * d) (-count * a) event in
                        loop (i + 1) event (level + count * a) (bomb + count)
                    )
                )
            )
    in
    loop 0 M.empty 0 0
)

Measured memory_bytes: 14720