akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef pair<ll, ll> P;
typedef pair<int, int> i_i;
ll INF = 1e12+10;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
vector<pair<ll, ll> > pairs;
#define print1(x) cerr << "x = " << x << endl;
#define print2(x, y) cerr<< "x,y = "  << x << "," << y << endl;
#define print3(x, y, z) cerr << "x,y,z = " << x << "," << y << "," << z << endl;
#define print4(x, y, z, w) cerr << "x,y,z,w = " << x << "," << y << "," << z << "," << w << endl;
const ll MAX = ll(1e10) * 300 + 10;
vector<pair<ll, ll> > P;

ll N, M;
ll mod = 1000000007;
int main()
{
    ll T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    
    if (T1 * A1 + T2 *A2 == T1 * B1 + T2 *B2){
        cout << "infinity";
        return 0;
    }
    if (T1 * A1 + T2 *A2 < T1 * B1 + T2 *B2){
        ll tmp = A1;
        A1 = B1;
        B1 = tmp;
        tmp = A2;
        A2 = B2;
        B2 = tmp;
    }
    if (T1 *A1 > T1 * B1){
        cout << 0;
        return 0;
    }
    ll diff_t2 = T1 * A1 + T2 *A2 - T1 * B1 - T2 * B2;
    ll diff_t1 = T1 * B1 - T1 * A1;
    //cout << diff_t2/1000000000 << " " << diff_t1/1000000000  << endl;
    ll ans = 1LL + (diff_t1/diff_t2) * 2LL;
    if (diff_t1%diff_t2 == 0)ans--;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
n = input()
output1 = [0,0,0]

for x in range (3):

    output1[x]=n[x]
    
    if n[x]=='1':
        output1[x]=9
    if n[x]=='9':
        output1[x]=1
str1 = ''.join(str(e) for e in output1)

print (str1)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#define N  3
#define N2 9
using namespace std;
struct Puzzle{
	int f[N2];
	int space;
	string path;
	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;
	}
};

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

bool isTarget(Puzzle p)
{
	for (int i = 0; i < N2; ++i)
	{
		if (p.f[i] != (i+1)) return false;
	}
	return true;
}

string bfs(Puzzle s)
{
	queue<Puzzle> Q;
	map<Puzzle, bool> V;
	Puzzle u,v;
	s.path = "";
	Q.push(s);
	V[s] = true;
	while(!Q.empty())
	{
		u = Q.front(); Q.pop();
		if (isTarget(u)) return u.path;
		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;
			swap(v.f[u.space], v.f[tx * N + ty]);
			v.space = tx * N + ty;
			if (!V[v])
			{

				V[v] = true;
				v.path += dir[r];
				Q.push(v);
			}
		}
	}
	return "unsolvable";
}

int main()
{
	Puzzle in;
	for (int i = 0; i < N2; ++i)
	{
		cin>>in.f[i];
		if (in.f[i]==0) {
			in.space = i;
			in.f[i] = N2;
		}
	}
	string ans = bfs(in);
	cout<<ans.size()<<endl;
	return 0;
}

Measured memory_bytes: 30456
#include <stdio.h>
 
int main() {
  int A, B, pos = 0;
  char S[20];
  scanf("%d %d %s", &A, &B, S);
  for (int i = 0; S[i] != '\0'; i++) {
    (S[i] == '-') ? pos += i + 1 : pos += 0;
  }
  pos == A + 1 ? puts("Yes") : puts("No");
  return 0;
}


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

int main()
{
	int m, n;

	cin >> m >> n;

	while (m != 0 || n != 0) {
		queue<int> a;

		for (int i = 0; i < m; i++)
			a.push(i + 1);

		for (int i = 0; i < n; i++) {
			string s;
			bool f = 0;

			cin >> s;

			if ((i + 1) % 15 == 0) {
				if (s != "FizzBuzz")
					f = 1;
			}
			else if ((i + 1) % 3 == 0) {
				if (s != "Fizz")
					f = 1;
			}
			else if ((i + 1) % 5 == 0) {
				if (s != "Buzz")
					f = 1;
			}
			else if (stoi(s) != i + 1)
				f = 1;

			if (f && a.size() > 1)
				a.pop();
			else {
				int b = a.front();
				a.pop();
				a.push(b);
			}
		}

		vector<int> c;

		while (!a.empty()) {
			c.push_back(a.front());
			a.pop();
		}

		sort(c.begin(), c.end());

		for (int i = 0; i < c.size() - 1; i++)
			cout << c[i] << " ";

		cout << c.back() << endl;

		cin >> m >> n;
	}

	return 0;
}



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

int main(){
    int N,A,B,C,D;
    cin >> N;
    A = N/1000;
    B = (N%1000)/100;
    C = (N%100)/10;
    D = N%10;
    if((A+B+C+D)==7){
        cout << A << "+" << B << "+" << C << "+" << D << "=" << 7 << endl;
    }
    else if((A+B+C-D)==7){
        cout << A << "+" << B << "+" << C << "-" << D << "=" << 7 << endl;
    }
    else if((A+B-C+D)==7){
        cout << A << "+" << B << "-" << C << "+" << D << "=" << 7 << endl;
    }
    else if((A+B-C-D)==7){
        cout << A << "+" << B << "-" << C << "-" << D << "=" << 7 << endl;
    }
    else if((A-B+C+D)==7){
        cout << A << "-" << B << "+" << C << "+" << D << "=" << 7 << endl;
    }
    else if((A-B+C-D)==7){
        cout << A << "-" << B << "+" << C << "-" << D << "=" << 7 << endl;
    }
    else if((A-B-C+D)==7){
        cout << A << "-" << B << "-" << C << "+" << D << "=" << 7 << endl;
    }
    else if((A-B-C-D)==7){
        cout << A << "-" << B << "-" << C << "-" << D << "=" << 7 << endl;
    }
}

Measured memory_bytes: 256
# -*-coding:utf-8

#import fileinput
import math

def main():
    while True:
        a, b = map(int, input().split())

        if (a == 0 and b == 0):
            break
        else:
            for i in range(a):
                for j in range(b):
                    if(((i+1)+(j+1)) % 2 == 0):
                        print('#', end='')
                    else:
                        print('.', end='')

                print('')
        print('')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9100
h, w = map(int, input().split())
a = []
for _ in range(h):
  t = list(input())
  if t.count('.') != w:
    a.append(t)
i = 0
while True:
  if i >= len(a[0]):break
  for t in a:
    if t[i] != '.':
      i += 1
      break
  else:
    for j in range(len(a)):
      del a[j][i]
for t in a:
  print(''.join(t))

Measured memory_bytes: 3064
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    C = [input() for _ in range(2)]

    ok = True
    for i in range(3):
        if C[0][i] != C[1][2-i]:
            ok = False
    if ok:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    resolve()

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

const int MOD = 1e9 + 7;
int n;


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);    
     
    cin >> n;
    int ans = 1ll;
    for (int i = 1; i <= n; i++){
      ans *= i;
      ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
leftSum = 0
rightSum = 0
for i in range(M):
    if(A[i] < X):
        leftSum += 1
    elif(A[i] > X):
        rightSum += 1
print(min(leftSum, rightSum))

Measured memory_bytes: 3060
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = list(map(int, list(input()[:-1].decode())))
    N = len(n)
    k = int(input())

    dp = [[[0] * (k + 1) for _ in range(2)] for _ in range(N + 1)]
    dp[0][0][0] = 1
    for i in range(1, N + 1):
        num = n[i - 1]
        for j in range(k + 1):
            dp[i][1][j] += dp[i - 1][1][j]
            if num != 0:
                dp[i][1][j] += dp[i - 1][0][j]
            else:
                dp[i][0][j] += dp[i - 1][0][j]
            if j >= 1:
                dp[i][1][j] += 9 * dp[i - 1][1][j - 1]
                if num != 0:
                    dp[i][0][j] += dp[i - 1][0][j - 1]
                    dp[i][1][j] += (num - 1) * dp[i - 1][0][j - 1]

    print(dp[N][0][k] + dp[N][1][k])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 62468
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    R, G, B, N = LI()

    ans = 0
    for r in range(N // R + 1):
        for g in range((N - R * r) // G + 1):
            b_ball = (N - r * R - g * G)
            b = b_ball // B
            if 0 <= b and b_ball % B == 0:
                ans += 1

    print(ans)

if __name__ == '__main__':
    resolve()


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

int main() {
  int x,y;cin>>x>>y;
  int a[] = {1, 3, 5, 7, 8, 10, 12};
  int b[] = {4, 6, 9, 11};
  
  if (x == y) {
    cout << "Yes" << endl;
    return 0;
  }
  
  int x_ = 0;
  int y_ = 0;
  for (int i=0; i<7;i++){
    if (a[i] == x) x_ = 1;
    if (a[i] == y) y_ = 1;
  }
  for (int i=0; i<4;i++){
    if (b[i] == x) x_ = 2;
    if (b[i] == y) y_ = 2;
  }

  if (x_ == y_) {
    cout << "Yes" << endl;
    return 0;
  }
  
  cout << "No" << endl;

}

Measured memory_bytes: 3600
n = int(input())
s = input()
if (n%2 == 1):
  print("No")
else:
  c = 0
  for i in range(int(n/2)):
    if (s[i] != s[i + int(n/2)]):
      c = 1
  if (c == 0):
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long t1, t2, a1, a2, b1, b2, s1, s2, ans, v1, v2, a, b, v, w;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	t1 *= 60; t2 *= 60;

	a = (a1 - b1) * t1;
	b = (a2 - b2) * t2; 

	if ((a > 0) && (b > 0)) ans = 0;
	else if ((a < 0) && (b < 0)) ans = 0;
	else if (a == -b) ans = -1;
	else {
		if (a < 0) {
			a = -a; b = -b;
		}

		v = (a + b);
		if (v > 0) ans = 0;
		else {
			v = -v;

			w = a / v;
			ans = w * 2;
			if (a % v > 0) ans++;

			s1 = 0;
		}
	}


	if (ans == -1) cout << "infinity\n";
	else cout << ans << "\n";
		
	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, i;
    cin >> n;
    vector<pair<int, int> > p(n);
    for(i=0;i<n;i++){
        int a;
        cin >> a;
        p[i]=make_pair(a, i+1);
    }
    sort(p.begin(), p.end());
    for(i=0;i<n;i++){
        cout << p[i].second << " ";
    }
    cout <<endl;
    return 0;
}

Measured memory_bytes: 1536
let rec tabulate n f = 
  let rec loop acc m =
    if m < n then loop (f m :: acc) (m + 1)
    else List.rev acc in
  loop [] 0

let () =
  let n, x = Scanf.scanf "%d %d\n" (fun n x -> n, x) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  tabulate n (fun magics -> magics)
  |> List.fold_left (fun (acc, times) magics ->
      (List.fold_left ( + ) (x * magics) times :: acc,
       let magics = magics + 1 in
       List.mapi (fun i time -> min time as_.((n + i - magics) mod n)) times))
      ([], tabulate n (fun i -> as_.(i)))
  |> fst
  |> List.fold_left min max_int
  |> Printf.printf "%d\n"


Measured memory_bytes: 3840
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ***************************CODE**********************//


int H,W;
char s[51][51];
int table[51][51];
int black = 0;

int main(){
        cin >> H >> W;
        for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                        cin >> s[i][j];
                        if(s[i][j] == '#') black++;
                        table[i][j] = 1e9;
                }
        }
        //場所が悪かったみたい。
        int gx = H-1, gy = W-1;

        queue<P> q;
        q.push(make_pair(0,0));
        table[0][0] = 0;

        while(!q.empty()){
                P p = q.front();
                q.pop();

                if(p.first == gx && p.second == gy) break;

                for(int i = 0; i < 4; i++){
                        int nx = p.first + dx[i];
                        int ny = p.second + dy[i];

                        if(nx >= 0 && nx < H && ny >= 0 && ny < W && s[nx][ny] != '#' && table[nx][ny] == 1e9){
                                table[nx][ny] = table[p.first][p.second] + 1;
                                q.push(make_pair(nx,ny));
                        }
                }
        }




        if(table[H-1][W-1] == 1e9) cout << -1 << endl;
        else{
                cout << H*W - (table[gx][gy]+1) - black << endl;
        }

        return 0;


}


Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
        int N, A;
        cin >> N >> A;

        if ((N % 500) <= A)
                cout << "Yes" << endl;
        else
                cout << "No" << endl;

        return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };



void solve() {
    ll a, b, c, d, e , m, n, k, x, y, l,r,t;
    string s;
    ll ans = 0;
    double dans = 0;
    string sans = "Yes";
    vector<ll> ar;
    vector<string> sr;

    cin >> n;
    sans = "Yes";
    
    rep(i,n){
        string s;
        cin >> s;

        auto it  = find(all(sr),s);
        if(it != sr.end()){
            sans = "No";
            break;
        }
        if(i!=0){
            auto tail = *sr.rbegin();
            if(s[0] != *tail.rbegin()){
                sans =  "No";
                break;
            }
        }

        sr.push_back(s);
    }


    // std::cout << ans << endl; 

    std::cout << sans << endl; 
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long int a[n][3];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		cin>>a[i][j];
	}
	for(int i=0;i<n-1;i++)
	{
		for(int j=0;j<3;j++)
		{
			long long int ans=0;
			for(int k=0;k<3;k++)
			{
				if(k!=j)
				ans=max(ans,a[i][k]);
			}
			a[i+1][j]+=ans;
		}
	}
	long long int ans=0;
	for(int i=0;i<3;i++)
	ans=max(ans,a[n-1][i]);
	cout<<ans;
	
}

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

main()
{
    int k,n; cin>>n>>k;
    vector<int> acc(n+1);
    int ans{};
    for(int i=1; i<=n; ++i)
    {
        int p; cin>>p;
        acc[i]=acc[i-1]+p;
        if(i<k) continue;
        int tmp=acc[i]-acc[i-k];
        if(tmp>ans) ans=tmp;
    }
    cout << fixed << setprecision(10);
    cout << (long double)(ans+k)/2 << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <stack>
#include <cstdlib>
#include <cstdio>
using namespace std;
stack <int> st;
int solve(string str){
    int b = st.top(); st.pop();
    int a = st.top(); st.pop();
    if(str=="+") return a+b;
    else if(str=="-")return a-b;
    else if(str=="*")return a*b;
    else if(str=="/")return a/b;
}
int main(){
    string str;
    while(cin>>str){
        if(str=="+"||str=="-"||str=="*"||str=="/") st.push(solve(str));
        else st.push(atoi(str.c_str()));
        if(getchar()=='\n'){
            cout << st.top() << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3152
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

string makestring(char c, int num);

int main() {

	int sx, sy, tx, ty;

	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);

	string ans = "";

	ans += makestring('R', tx - sx);
	ans += makestring('U', ty - sy);
	ans += makestring('R', 1);
	ans += makestring('D', ty - sy + 1);
	ans += makestring('L', tx - sx + 1);
	ans += makestring('U', 1);
	ans += makestring('U', ty - sy);
	ans += makestring('R', tx - sx);
	ans += makestring('U', 1);
	ans += makestring('L', tx - sx + 1);
	ans += makestring('D', ty - sy + 1);
	ans += makestring('R', 1);

	cout << ans << endl;

	return 0;
}
string makestring(char c, int num) {

	string ret = "";

	int i;

	for (i = 0; i < num; i++) {
		ret += c;
	}
	return ret;
}

Measured memory_bytes: 256
from fractions import*
a,b,c,d=map(int,input().split())
x=b-(b//c+b//d-b//(c*d//gcd(c,d)))
y=a-1-((a-1)//c+(a-1)//d-(a-1)//(c*d//gcd(c,d)))
print(x-y)

Measured memory_bytes: 5048
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, K, a, c=0;
  std::cin >> N >> K;
  for(int i=0;i<N;i++) {
    std::cin >> a;
    if(a>=K) c++;
  }
  std::cout << c << '\n';
  return 0;
}


Measured memory_bytes: 888
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i64,
        k: i64,
    }
    let nn = n as f64;
    let kk = k as f64;
    let ans = nn.log(kk) as usize;
    println!("{}", ans + 1);
}

Measured memory_bytes: 4352
#include <vector>
#include <queue>
#include <stdio.h>
#include <iostream>
#include <limits>

using namespace std;

const int MAXN = 10000;
const int INF = numeric_limits<int>::max();

vector< pair<int, int> > G[MAXN];
int dist[MAXN];
int n;

void dijkstra(int start) {
  for (int i = 0; i < n; ++i) dist[i] = INF;

  priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > q;
  q.emplace(0, start);
  dist[start] = 0;
  while (!q.empty()) {
    pair<int, int> cur = q.top(); q.pop();
    int v = cur.second;
    int cost = cur.first;
    if (dist[v] < cost) continue;

    for (size_t i = 0; i < G[v].size(); ++i) {
      int u = G[v][i].first;
      int new_cost = G[v][i].second + cost;
      if (dist[u] > new_cost) {
	q.emplace(new_cost, u);
	dist[u] = new_cost;
      }
    }
  }
}
int main () {
  cin >> n;

  for (int i = 0; i < n; ++i) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; ++j) {
      int v, c;
      cin >> v >> c;
      G[u].emplace_back(v, c);
    }
  }
  dijkstra(0);
  for (int i = 0; i < n; ++i) {
    cout << i << " " << dist[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 7972
#!/usr/bin/env python3
import sys


def solve(S: int):
    s = set()
    s.add(S)
    c = 2
    while True:
        if S % 2 == 1:
            S = 3 * S + 1
        else:
            S /=  2
        if S in s:
            print(c)
            break
        s.add(S)
        c += 1

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = int(next(tokens))  # type: int
    solve(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61832
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions
fn dfs(visited:&mut Vec<bool>, E:&Vec<Vec<usize>>, N:usize, v:usize) -> usize {
    let mut all_visited = true;
    for i in 0..N{
        if !visited[i] {
            all_visited = false;
        }
    }
    if all_visited {
        return 1;
    }
    let mut res = 0;
    for e in &E[v]{
        if ! visited[*e] {
            visited[*e] = true;
            res += dfs(visited,E,N,*e);
            visited[*e] = false;
        }
    }
    return res;
}

// Main
fn main(){
    input!{
        N: usize,
        M: usize,
        AB: [(usize,usize); M],
    }
    let mut E = vec![vec![0; 0]; N];
    for ab in AB{
        let (a,b) = ab;
        E[a-1].push(b-1);
        E[b-1].push(a-1);
    }
//    for e in E{
//        println!("{:?}",e);
//    }
    let mut visited = vec![false; N];
    visited[0] = true;
    println!("{}", dfs(&mut visited, &E, N, 0));
}

Measured memory_bytes: 4352
// i_am_arin

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<string> vs;


#define f(i, a, n) for(ll i=a; i<(ll)n; i++)
#define f2(i, a, b) for(ll i=a; i<=(ll)b; i++)
#define PB push_back
#define FF first
#define SS second
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;


ll a[100005];
ll n,k;

void solve(){
cin>>n>>k;
f(i,1,n+1) cin>>a[i];
ll dp[n+1];
f(i,1,n+1) dp[i]=INF;
dp[1]=0;
f(i,2,n+1){
	f(j,1,k+1){
		if(i<=j) continue;
		//if(dp[i]==0) dp[i]=abs(dp[i]-dp[i-j]);
		dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
	}

}

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var p = new long[N + 1];
            var gr = Sarray();
            p[0] = gr[0];
            p[1] = gr[1];
            for (var i = 2; i <= N; ++i)
            { p[i] = Sarray()[1]; }
            
            var dp = new long[N + 1, N + 1];
            for (var i = 1; i < N; ++i)
            {
                for (var j = 0; j < N - i; ++j)
                {
                    var cst = long.MaxValue;
                    for (var k = j; k < j + i; ++k)//計算
                    { cst = Math.Min(cst, dp[j, k] + dp[k + 1, j + i] + p[j] * p[k + 1] * p[j + i + 1]); }
                    dp[j, j + i] = cst;
                }
            }
            WriteLine(dp[0, N - 1]);
        }
    }
}


Measured memory_bytes: 20468
#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for (int i=(a); i<=(b); ++i)
char s[7][4]={"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
char c[4];
int main(void)
{
	scanf("%s",c);
	For(i,0,6)
	{
		if (!strcmp(s[i],c))
		{
			cout<<7-i;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
////=====BIsmillahir Rahmanir Rahim =====////

/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
         Comilla University

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define fi 2*acos(0.0)
#define ee 2.71828
#define ll  long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define edl printf("\n")
#define infinity 1e16
#define mod 1000000007
#define cn continue
#define csprint1 printf("Case %lld: ", cs++)
#define csprint2 printf("Case %lld:\n", cs++)
#define sf(a) scanf("%lld", &a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define all(v) v.begin(),v.end()
#define pfn(a) printf("%lld\n",a)
#define pfs(a) printf("%lld ",a)

using namespace __gnu_pbds;
using namespace std;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<pl> vpi;
typedef vector<pl> vpl;
typedef tree<pair<ll, int> , null_type, less<pair<ll, int> >, rb_tree_tag, tree_order_statistics_node_update> ost;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a <<","<< spc;
    err(++it, args...);
    cout<<edl;
}
///Bit manipulation

bool checkbit(int mask,int bit){return mask & (1<<bit);}
int setbit(int mask,int bit){ return mask | (1<<bit) ; }
int clearbit(int mask,int bit){return mask & ~(1<<bit);}
int togglebit(int mask,int bit){return mask ^ (1<<bit);}
int bitno(int mask) {return (int)__builtin_popcount(mask);}

/*----------------------Graph Moves----------------*/
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

///=====================================///

const int  maX=1e5+10;
ll M = 10000007;
int main() {
    ll n;sf(n);
    ll ara[n];
    for(ll i=0;i<n;i++)sf(ara[i]);
    ll sum=0;
    ll dp[maX];
    dp[n-1]=0;
    for(ll i=n-2;i>=0;i--){
        ll x,y;
        x=dp[i+1]+abs(ara[i]-ara[i+1]);
        y=infinity;
        if(i+2<n){
            y=dp[i+2]+abs(ara[i]-ara[i+2]);
        }
        //cout<<x<<spc<<y<<endl;
        dp[i]=min(x,y);
    }
    pfn(dp[0]);
return 0;
}


Measured memory_bytes: 5284
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

int min(int a,int b) {
	if(a>b) return b;
	else return a;
}


//main関数
int main() {
	int N;
	scanf("%d",&N);
	if( N%1000 == 0){
		printf("0");
	}
	else {
		printf("%d",1000-(N%1000));
	}
}


Measured memory_bytes: 1732
#入力(これは一つにまとめられる) #lst = [i for i in input()]
s = input()
lst = [i for i in s]
ans = []
#ATGCのいずれかの文字だったらカウントを１増やす
cnt = 0
"""
まえから順にATGCのいずれかであるかを判定する
カウントは毎回ansに追加していくので、lstの要素分だけ追加される
同じ値が続けばカウントは1増えて配列ansにつかされる
最終出力は配列の中の最大値を出力する。
"""
for i in range(len(lst)):
    if s[i] == "A" or s[i] == "T" or s[i] == "G" or s[i] == "C":
        cnt += 1
    else:
        cnt = 0
    ans.append(cnt)

print(max(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;
int D[50];

bool check(int m) {
  vector<int> v;
  for (int i = 0; i < N; i++) {
    v.emplace_back(D[i]);
  }
  int p = 0;
  while (p+1 < v.size()) {
    if (v[p+1]-v[p] < m) {
      if (v[p+1] >= 12) return false;
      v.insert(lower_bound(v.begin(), v.end(), 24-v[p+1]), 24-v[p+1]);
      v.erase(v.begin() + (p+1));
    } else {
      p++;
    }
  }
  return true;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> D[i];
  }
  sort(D, D+N);
  int ans = 0;
  for (int i = 0; i <= D[0]; i++) {
    if (check(i)) ans = max(ans, i);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#define INFLL        1e18
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
using ull=unsigned long long;
template<typename T>using pqg=priority_queue<T,vector<T>,greater<T>>;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

int main()
{
    string s;cin>>s;
    vector<ll>near_l(s.length()),near_r(s.length());
    REP(i,s.length()){
        if(s[i]=='R'){
            auto pos=find(s.begin()+i+1,s.end(),'L')-s.begin();
            for(ll j=i;j<pos;++j)near_l[j]=pos;
            i=pos;
        }
    }
    reverse(ALL(s));
    REP(i,s.length()){
        if(s[i]=='L'){
            auto pos=find(s.begin()+i+1,s.end(),'R')-s.begin();
            for(ll j=i;j<pos;++j)near_r[s.length()-1-j]=s.length()-1-pos;
            i=pos;
        }
    }
    reverse(ALL(s));
    vector<ll>res(s.length(),1);
    REP(i,s.length()){
        ll dest;
        if(s[i]=='R')dest=(near_l[i]-i)%2?near_l[i]-1:near_l[i];
        else         dest=(i-near_r[i])%2?near_r[i]+1:near_r[i];
        ++res[dest];
        --res[i];
    }
    REP(i,res.size()){
        if(i!=0)cout<<' ';
        cout<<res[i];
    }
    cout<<endl;
}

Measured memory_bytes: 3072
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
	ll N;
	cin >> N;
	rep(i,0,N) {
		ll A, B;
		cin >> A >> B;
		ll good = 1;
		ll bad = max(A, B)+1;
		while (bad - good >= 2) {
			ll mid = (bad + good) / 2;
			if (mid * mid <= A*B-1) {
				good = mid;
			} else {
				bad = mid;
			}
		}
		ll ans = 2 * good;
		if ((A*B-1)/good == good) {
			ans--;
		}
		if (A <= good) {
			ans--;
		}
		if (B <= good) {
			ans--;
		}
		cout << ans << endl;
	}
}

/*
1
8 9
*/


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

using namespace std;
int main()
{
    int i,j,l,arr[11];
    char ch[100];

    cin>>ch;

    l=strlen(ch);
    j=0;
    memset(arr,0,sizeof(arr));

    for(i=0; i<l; i++){
        if(ch[i]=='A' || ch[i]=='C' || ch[i]=='G' || ch[i]=='T'){
            arr[j]++;
        }
        else{
            j++;
        }
    }
    int m=0;

    for(i=0; i<11; i++){
        if(m<arr[i]){
            m=arr[i];
        }
    }
    cout<<m<<endl;

    return 0;
}


Measured memory_bytes: 256
//
// FileName : AT2020.cpp
// Creator  : GGG1235
// Date     : 2019/11/26
// Comment  :
//

#include <bits/stdc++.h>

#pragma GCC optimize(3)

using namespace std;

typedef long long LL;

int main(int argc,const char **argv,const char **envp) 
{
    ios::sync_with_stdio(false);
    cin.tie();
    
    string szInput;
    cin >> szInput;
    for (int i = 1; i < static_cast<int>(szInput.size()); i++) 
    {
        if (szInput[i] == szInput[i - 1]) 
        {
            cout << i << " " << i + 1 << endl;
            return 0;
        }
    }
    for (int i = 2; i < static_cast<int>(szInput.size()); i++) 
    {
        if (szInput[i] == szInput[i - 2]) 
        {
            cout << i - 1 << " " << i + 1 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int n;
char s[20]={"a"};
void f(int a,int m){
  int i;
  if(a==n){
    s[a]=0;
    printf("%s\n",s);
    return;
  }
  for(i=0;i<m;i++){
    s[a]='a'+i;
    f(a+1,m);
    s[a]=0;
  }
  s[a]='a'+m;
  f(a+1,m+1);
  s[a]=0;
  return;
}
int main(){
  scanf("%d",&n);
  f(1,1);
  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  int a[n];
  int b[3];
  int s;
  int ans = 0;
  rep(i, n) cin >> a[i];
  rep(i, n - 2) {
    b[0] = a[i];
    b[1] = a[i + 1];
    b[2] = a[i + 2];
    s = b[1];
    sort(b, b + 3);
    if (s == b[1]) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	while (true) {
		int a, b;
		cin >> a >> b;
		if (a == 0 && b == 0) {
			break;
		}
		int count100 = 0, count500 = 0, count1000 = 0;
		int rest = b - a;
		while(rest >= 1000) {
			count1000++;
			rest -= 1000;
		}
		while(rest >= 500) {
			count500++;
			rest -= 500;
		}
		while(rest >= 100) {
			count100++;
			rest -= 100;
		}
		cout << count100;
		cout << " " << count500;
		cout << " " << count1000 << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1073741824
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
int main()
{
   
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  	int n,k;
  	cin >> n >> k;
  	double ans = 0.0 ,m = -1.0;
  	vector <int>v(n);
  	for (int i = 0; i < n; ++i)
  	{
  		cin >> v[i];
  	}
  	for (int i = 0; i < k; ++i)
  	{
  		ans += (v[i]*(v[i]+1)/2.0)*(1.0/v[i]);
  	}
  	m = max(m,ans);
  	for (int i = k; i < n; ++i)
  	{
  		ans -=(v[i-k]*(v[i-k]+1)/2.0)*(1.0/v[i-k]);
  		ans += (v[i]*(v[i]+1)/2.0)*(1.0/v[i]);
  		m = max(m,ans);
  	}
  	std::cout << fixed;
  	cout <<std::setprecision(6) << m << endl;
  	return 0;
}	

Measured memory_bytes: 1024
#!/usr/bin/env python3
#ABC128 B

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

n = I()
lst = []
for i in range(n):
    s,p = input().split()
    lst.append((s,int(p),i+1))
lst.sort(key = lambda x:(x[0],-x[1]))
for i,j,k in lst:
    print(k)

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
unsigned int gcd(unsigned int a, unsigned int b) {
	if(a == 0) return b;
	if(b == 0) return a;
	if(a > b) swap(a, b);
	int r = b % a;
	return gcd(r, a);
}

int main() {
	int N, X;
	cin >> N >> X;
	unsigned int res = 0;
	for(int i = 0; i < N; i++) {
		int x;
		cin >> x;
		res = gcd(res, abs(X - x));
	}

	cout << res << endl;
}


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

#define int long long
#define ll long long
const int mod = 1e+9+7;
ll qpow(ll p,ll q) {
    ll r = 1;
    for(; q; p*=p, p%=mod, q>>=1) if(q&1) r*=p, r%=mod;
    return r;
}
int inv(int p) {
    return qpow(p,mod-2);
}

const int N = 1e+6+5;
int f[N],g[N];

int solve(int i,int m) {
    memset(f,0,sizeof f);
    memset(g,0,sizeof g);
    g[0]=i+1; f[1]=i+1;
    for(int k=2;k<=m+1;k++) f[k]=f[k-1]*(i+k)%mod*inv(k)%mod;
    /*cout<<endl;
    for(int k=1;k<=m;k++) cout<<f[k]<<" ";
    cout<<endl;*/
    for(int j=1;j<=m;j++) g[j]=(g[j-1]+f[j+1])%mod;
    return g[m];
}

signed main() {
    int r1,c1,r2,c2;
    cin>>r1>>c1>>r2>>c2;
    --r1; --c1;
    cout<<((solve(r2,c2)-solve(r1,c2)-solve(r2,c1)+solve(r1,c1)%mod+mod)%mod)<<endl;
}


Measured memory_bytes: 15872
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val h = sc.nextInt()
    val w = sc.nextInt()
    val grid = Array(h) { Array(w) { '.' } }
    val isWall = Array(h) { BitSet(w) }
    for (i in 0 until h) {
        val s = sc.nextLine()
        for (j in 0 until w) {
            grid[i][j] = s[j]
            isWall[i][j] = grid[i][j] == '#'
        }
    }
    val left = Array(h) { Array(w) { 0 } }
    val right = Array(h) { Array(w) { 0 } }
    val up = Array(h) { Array(w) { 0 } }
    val down = Array(h) { Array(w) { 0 } }
    for (i in 0 until h) {
        var count = 0
        for (j in 0 until w) {
            left[i][j] = count
            if (!isWall[i][j]) {
                count++
            } else {
                count = 0
            }
        }
    }
    for (i in 0 until h) {
        var count = 0
        for (j in w - 1 downTo 0) {
            right[i][j] = count
            if (!isWall[i][j]) {
                count++
            } else {
                count = 0
            }
        }
    }
    for (j in 0 until w) {
        var count = 0
        for (i in 0 until h) {
            up[i][j] = count
            if (!isWall[i][j]) {
                count++
            } else {
                count = 0
            }
        }
    }
    for (j in 0 until w) {
        var count = 0
        for (i in h - 1 downTo 0) {
            down[i][j] = count
            if (!isWall[i][j]) {
                count++
            } else {
                count = 0
            }
        }
    }
    var ans = 0
    for (i in 0 until h) {
        for (j in 0 until w) {
            if (isWall[i][j]) continue
            val num = left[i][j] + right[i][j] + up[i][j] + down[i][j] + 1
            ans = Math.max(ans, num)
        }
    }
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 341100
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
typedef pair<int,int> P;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
	int n;
	cin>>n;
	map<int,int> a;
	vector<int> a2(n);
	rep(i,n){
		int in;
		cin>>in;
		a[in-i]++;
		a2[i]=in+i;
	}
	int ans=0;
	rep(i,n)ans+=a[-a2[i]];
	cout<<ans<<endl;
}


Measured memory_bytes: 27312
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        long n = scn.nextLong();
        String s = "abcdefghijklmnopqrstuvwxyz";
        String ans = "";
        n = n - 1;
        int a;
        char c;


        while (n / 26!=0) {
            long num = n % 26;
            a = (int) num;
            c = s.charAt(a);
            ans = String.valueOf(c) + ans;

            n = (n / 26)-1;

        }
        long num = n % 26;
        a = (int) num;
        c = s.charAt(a);
        ans = String.valueOf(c) + ans;



        System.out.println(ans);

        scn.close();

    }


}


Measured memory_bytes: 27080
#!/usr/bin/env python3
import sys

def min(val: int, new: int):
    if new < val:
        return new
    else:
        return val

def solve(N: int, K: int, h: "List[int]"):
    dp = [sys.maxsize] * N
    dp[0] = 0

    for i in range(1,N):
        for j in range(1,K+1):
            if i-j >= 0:
                dp[i] = min(dp[i],dp[i-j] + abs(h[i]-h[i-j]))

    print(dp[N-1])

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(N, -1));
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        for(int j=0; j<a; j++){
            int x,y;
            cin >> x >> y;
            A.at(i).at(x-1) = y;
        }
    }
    int ans=0;

    for(int bit=0; bit<(1<<N); bit++){
        vector<int> P(N, 0);
        for(int i=0; i<N; i++){
            if(bit & (1<<i)){
                P.at(i) = 1;
            }
        }
        bool ok=true;
        for(int i=0; i<N; i++){
            for(int j=0; j<N; j++){
                if(P.at(i) == 1){
                    if(A.at(i).at(j)==0 && P.at(j)==1){
                        ok = false;
                    }
                    if(A.at(i).at(j)==1 && P.at(j)==0){
                        ok = false;
                    }

                }
            }
        }
        if(ok){
            int n=0;
            for(int i=0; i<N; i++){
                n += P.at(i);
            }
            ans = max(n, ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
M, D = map(int, input().split())


def isSEKIDay(m, d):
    ds = str(d).zfill(2)
    d1 = int(ds[1])
    d10 = int(ds[0])
    return (d1 >= 2) and (d10 >= 2) and (d1 * d10 == m)


cnt = 0
for i in range(M):
    for j in range(D):
        if isSEKIDay(i + 1, j + 1):
            cnt += 1

print(cnt)


Measured memory_bytes: 3060