akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)

#define N 1300000
bool prime[N];

int solve(int n){
    if(prime[n]) return 0;
    int l=n,r=n;
    while(!prime[l])l--;
    while(!prime[r])r++;
    return r-l;
}

int main(void){
    rep(i,N) prime[i] = true;
    prime[0] = prime[1] = false;
    for(int i=2; i<=sqrt(N); i++){
        if(!prime[i]) continue;
        for(int j=i*i; j<N; j+=i){
            prime[j] = false;
        }
    }

    int n;
    while(cin>>n,n){
        cout<<solve(n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 4284
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    static final int M = (int) 1E9 + 7;
    static long[][] com;
    
    public static void main(String[] args) {
        com = calcCom(2000);
        
        int N = nint();
        int K = nint();
        int s = N-K+1;
        
        for (int i = 1; i <= K; i++) {
            long a = com[s][i];
            long b = com[K-1][i-1];
            so.println(((a%M) * (b%M)) % M);
        }
    }
    
    public static long[][] calcCom(int size) {
        long[][] com = new long[size+1][size+1];
        com[0][0] = 1;
        for (int i = 1; i <= size; i++) {
            com[i][0] = 1;
            for (int j = 1; j <= size; j++) {
                com[i][j] = (com[i-1][j-1] + com[i-1][j]) % M;
            }
        }
        return com;
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static String[] nstrs(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = nstr();
        return a;
    }

    private static char[][] nsToChars2D(int h, int w) {
        return nsToChars2D(h, w, 0);
    }

    private static char[][] nsToChars2D(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nsToChars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


Measured memory_bytes: 81232
n, k = map(int, input().split())
g = [1] * k
mod = 10 ** 9 + 7

for i in range(k, 0, -1):
    x = k // i
    m = n
    while m > 0:
        if m & 1:
            g[i-1] = g[i-1] * x % mod
        x = x * x % mod
        m >>= 1

    y = 2
    while i * y <= k:
        g[i-1] -= g[i*y-1]
        y += 1

ans = 0
for i in range(k):
    ans = (ans + g[i] * (i + 1)) % mod

print(ans)


Measured memory_bytes: 11044
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <climits>
using namespace std;
typedef long long int ll;

int const INF=INT_MAX;

struct SegmentTree{
private:
    int n;
    vector<int> node;
public:
    SegmentTree(vector<int> v){
        int sz=v.size();
        n=1;
        while(n<sz)n*=2;
        node.resize(2*n-1,INF); // INF
        // 最下段に値を入れた後に、下の段から順番に値を入れる
        for(int i=0;i<sz;i++){
            node[i+n-1]=v[i];
        }
        for(int i=n-2;i>=0;i--){
            node[i]=min(node[2*i+1],node[2*i+2]);
        }
    }
    void update(int x,int val){
        //最下段のノードにアクセスする
        x+=(n-1);
        node[x]=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=min(node[2*x+1],node[2*x+2]);
        }
    }
    int getmin(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(r<=a||b<=l)return INF;
        if(a<=l&&r<=b) return node[k];
        int vl=getmin(a,b,2*k+1,l,(l+r)/2);
        int vr=getmin(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
};

int main(){
    int n,q; cin >> n >> q;
    SegmentTree seg(vector<int> (n,INF));
    for(int i=0;i<q;i++){
        int c,x,y; cin >> c >> x >> y;
        if(c==0){
            seg.update(x,y);
        }
        else{
            cout << seg.getmin(x,y+1) << endl;
        }
    }
}


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

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> L(m), R(m);
    rep(i, m) {
        cin >> L[i] >> R[i];
    }
    vector<int> P(q), Q(q);
    rep(i, q) {
        cin >> P[i] >> Q[i];
    }

    const int N_MAX = 505;
    vector<vector<int>> M(N_MAX, vector<int>(N_MAX));
    rep(i, m) {
        M[L[i]][R[i]]++;
    }

    // 2次元累積和
    for (int i = 1; i < N_MAX; i++) {
        for (int j = 1; j < N_MAX; j++) {
            M[i][j] += M[i - 1][j];
            M[i][j] += M[i][j - 1];
            M[i][j] -= M[i - 1][j - 1];
        }
    }

    rep(i, q) {
        int x = P[i]; int y = Q[i];
        cout << M[y][y] - M[x - 1][y] - M[y][x - 1] + M[x - 1][x - 1] << endl;
    }
}

Measured memory_bytes: 6692
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

bool check(const vector<int>& v, const vector<int>& w){
  rep(i,v.size()){
    if(v[i] != w[i]) return false;
  }
  return true;
}

int main(){
  int N;
  cin >> N;
  vector<int> P, Q;
  rep(i,N){
    int a;
    cin >> a;
    P.push_back(a);
  }
  rep(i,N){
    int a;
    cin >> a;
    Q.push_back(a);
  }

  vector<int> v;
  rep(i,N) v.push_back(i+1);

  int cnt = 0;
  int X, Y;
  do{
    if(check(v, P)) X = cnt;
    if(check(v, Q)) Y = cnt;
    cnt++;
  }while(next_permutation(ALLOF(v)));

  cout << abs(X-Y) << endl;
  
  return 0;
}



Measured memory_bytes: 3632
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>

using namespace std;


int main(){

    string s;
    int n,k;
    cin>>n>>k>>s;

    if(s[k-1]=='A'){
        s[k-1]='a';
    }else if(s[k-1]=='B'){
        s[k-1]='b';
    }else if(s[k-1]=='C'){
        s[k-1]='c';
    }

    cout<<s<<endl;

        return 0;
}

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

int main() {
  int n;

  cin >> n;

  int ans = n - 1;

  int tmp = 2;
  for (int i = n / 2; i > 0; i--) {
    for (int j = tmp; j <= n; j++) {
      if (i * j >= n) {
        ans += j - 2;
        tmp--;
        break;
      }
      tmp++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define vi vector<int>
#define fi first
#define se second 
#define mp make_pair
#define show(x) cout<<#x<<" = "<<x<<endl;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define LL long long 
#define pi acos(-1)
#define fin freopen("in","r",stdin);
const int inf=0x3f3f3f3f;
const double eps=1e-8;
#define zero(x) (((x)>0?(x):-(x))<eps)
#define _sign(x) ((x)>eps?1:((x)<-eps?2:0))
typedef long long ll;
const int maxn = 1000005, mod = 1e9+7;
#define fin freopen("in","r",stdin);
char b[maxn];
int n,a[maxn];
int main(){
	cin>>b;
	n=strlen(b);
	for(int i=0;i<n;i++) a[i]=b[i]-48;
	int a1=0;
	for(int i=0;i<n;i++){
		if((i%2)^a[i]) a1++;
	}
	int a2=0;
	for(int i=0;i<n;i++){
		if(((i+1)%2)^a[i]) a2++;
	}
	cout<<min(a1,a2)<<endl;
	return 0;
}

Measured memory_bytes: 2688
using System;

class Program {
  static void Main() {
    var s = Console.ReadLine();
    int[] a = new int[10];
    int p = 0;
    foreach (var c in s) {
      if (c == '0') p++;
      else if (c == '1') a[p++] = 1;
      else {
        if (p > 0) a[--p] = 0;
      }
    }
    for (int i = 0; i < p; i++) {
      Console.Write(a[i]);
    }
    Console.WriteLine();
  }
}

Measured memory_bytes: 11092
#include <iostream>

using namespace std;

const int N = 1e6;
int p[N] = { 0 };

int main(){
    int n, c = 0;
    cin >> n;
    for(int i = 0;i < n;++i){
        cin >> p[i];
        --p[i];
    }
    for(int i = 0;i < n;++i){
        if(i < p[i] && i == p[p[i]]) ++c;
    }
    cout << c << endl;
    return 0;
}

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

int main(void)
{
	int count = 0;
	int N, M, C; cin >> N >> M >> C;
	vector<int> B(M);
	int A;
	for (int i = 0; i < M; i++)cin >> B[i];
	for (int i = 0; i < N; i++) {
		int tmp = 0;
		for (int j = 0; j < M; j++) {
			cin >> A;
			tmp += A * B[j];
		}
		if (tmp + C > 0)count++;
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,t[1000],p[1000],x[1000],ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t[i];
    ans+=t[i];
  }
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>p[i]>>x[i];
    cout<<ans-t[p[i]-1]+x[i]<<endl;;
  }
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define turbo cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define inf 99999999

using namespace std;

const int P = 3000;

double tab[3005];
double dp[3005][6005];
int bul[3005][6005];

double licz(int n, int k){
  //cout << "JESTEM W " << n << " " << k << "\n";
  if(n == 0){
    if(k == 0){
      dp[n][k+P] = 1;
      bul[n][k+P] = 1;
    }
    return dp[n][k+P];
  }
  if(abs(k)>n)
    return 0;
  k += P;
  if(bul[n][k] == 1)
    return dp[n][k];
  k -= P;
  licz(n-1,k+1);
  licz(n-1,k-1);
  k += P;
  dp[n][k] = double(dp[n-1][k+1] *  (1-tab[n])) + double(dp[n-1][k-1] * tab[n]);
  bul[n][k] = 1;
  k -= P;
  return dp[n][k+P];
}

int main(){
    turbo
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
      cin >> tab[i];
    }
    double w = 0;
    for(int i=1;i<=n;i++){
      w += licz(n,i);
    }
    printf("%.10lf\n",w);

    return 0;
}


Measured memory_bytes: 209920
import math;

input_line = input().rstrip().split(' ')
a = int(input_line[0])
b = int(input_line[1])
x = int(input_line[2])

if a * a * b > 2 * x:
  y = 2 * x / (a * b)  
  answer = math.degrees(math.atan(b / y))  
  
else:
  y = -2 * (x / (a * a) - b)
  answer = math.degrees(math.atan(y / a))
  
print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
  	int A , B , C ;
  	scanf("%d%d%d", &A, &B, &C);
    int poor = 0;
  	if(A == B && B != C) poor = 1;
  	if(B == C && C != A) poor = 1;
  	if(C == A && A != B) poor = 1;
  	
  	if(poor == 0){
      	puts("No");
    }else{
      	puts("Yes");
    }
return 0;
}

Measured memory_bytes: 256
n = int(input())
s = {}
for i in range(n):
    tmp = input()
    if not tmp in s.keys():
        s[tmp] = 1
    else:
        s[tmp] += 1
m = 0
l = []
for i in sorted(s.items(), key=lambda x:x[1], reverse=True):
    if m <= i[1]:
        m = i[1]
        l.append(i[0])
    else:
        break
 
for i in sorted(l):
    print(i)

Measured memory_bytes: 43228
MOD = int(1e9+7)

def main():
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]
    broken = [False] * (N+1)
    for a in A:
        broken[a] = True
    dp = [0] * (N+1)
    dp[0] = 1
    if not broken[1]:
        dp[1] = 1
    for i in range(2, N+1):
        if not broken[i]:
            dp[i] = (dp[i-2] + dp[i-1]) % MOD
    print(dp[N])

if __name__ == "__main__":
    main()


Measured memory_bytes: 50776
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<stack>
using namespace std;
void solve(int n,list<int>a) {
	if (n == 0) {
		list<int>::iterator it = a.begin();
		while (it != a.end()) {
			if (it == a.begin()) cout << (*it);
			else cout << " " << (*it);
			it++;
		}
		cout << endl;
		return;
	}
	if (!a.empty()) {
		list<int>::iterator it = a.end();
		it--;
		for (int j = n; j >= 1; j--) {
			if ((*it) >= j) {
				a.push_back(j);
				solve(n - j, a);
				a.pop_back();
			}
		}
	}
	else {
		for (int j = n; j >= 1; j--) {
			a.push_back(j);
			solve(n - j, a);
			a.pop_back();
		}
	}
}
int main() {
	int n;
	while (cin >> n&&n != 0) {
		list<int>a;
		solve( n,a);
	}
}

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

int main() {
  int nx[4] = {1,0,-1,0};
  int ny[4] = {0,1,0,-1};
  int h,w,bc = 0;
  cin >> h >> w;
  vector<vector<bool>>data(h,vector<bool>(w,false));
  vector<vector<int>>dist(h,vector<int>(w,-1));
  dist[0][0] = 0;
  for(int i = 0;i < h;i++) for(int j = 0;j < w;j++){
    char a;
    cin >> a;
    if(a == '#'){
      data[i][j] = true;
      bc++;
    }
  }
  queue<pair<int,int>>que;
  que.push(pair<int,int>(0,0));
  //bfs
  while(!que.empty()){
    int vx,vy;
    vx = que.front().first;
    vy = que.front().second;
    que.pop();
    for(int i = 0;i < 4;i++){
      if(vx == 0 && i == 2) continue;
      if(vx == h-1 && i == 0) continue;
      if(vy == 0 && i == 3) continue;
      if(vy == w-1 && i == 1) continue;
      if(dist[vx+nx[i]][vy+ny[i]] != -1 || data[vx+nx[i]][vy+ny[i]]) continue;
      que.push(pair<int,int>(vx+nx[i],vy+ny[i]));
      dist[vx+nx[i]][vy+ny[i]] = dist[vx][vy]+1;
    }
  }
  if(dist[h-1][w-1] == -1) cout << -1 << endl;
  else cout << h*w-bc-dist[h-1][w-1]-1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  string s;
  cin >> n >> s;

  rep(i, s.size()) {
    s[i] = (char)(((int)s[i]-'A')+n)%26+'A';
  }
  cout << s << endl;
}


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

int main() {
  int N, A;
  cin >> N >> A;
  
 int B;
  B = N %= 500;
  
  if(B < A + 1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,k,s;vector<int> ans;
signed main(){
  cin>>n>>k>>s;int x = 1000000000;
  if(s != x){
    rep(i,k)ans.push_back(s);
    rep(i,n-k)ans.push_back(x);
  }else{
    rep(i,k)ans.push_back(x);
    rep(i,n-k)ans.push_back(1);
  }
  rep(i,n)cout << ans[i] << (i == n-1 ? "\n" : " ");
}



Measured memory_bytes: 2164
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#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(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	while (a >= b && k > 0){
		k--;
		b *= 2;
	}
	while (b >= c && k > 0){
		k--;
		c *= 2;
	}
	if(a < b && b < c){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	// cout << a << b << c << endl;

	return 0;
}

Measured memory_bytes: 3636
n = int(input())
hs = list(map(int, input().split()))
min_cost = [float('inf')] * n
min_cost[0] = 0
for i in range(n):
    if i+1 < n:
        min_cost[i+1] = min(min_cost[i+1], min_cost[i] + abs(hs[i] - hs[i+1]))
    else:
        continue
    if i+2 < n:
        min_cost[i+2] = min(min_cost[i+2], min_cost[i] + abs(hs[i] - hs[i+2]))
    else:
        continue
print(min_cost[n-1])


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

string str, s;
int pos;

void a() {
  for(int i = 0; i < str.length(); ++i) {
    if(str[i] != '-') continue;
    int j;
    for(j = i+1; j < str.length() && str[j] == '-'; ++j);
    if(j == i+1) continue;
    if((j-i) % 2 == 0)
      str = str.substr(0, i) + str.substr(j);
    else
      str = str.substr(0, i+1) + str.substr(j);
  }
}

int exp();

int factor2() {
  int x;
  if(s[pos] == '(') {
    ++pos;
    x = exp();
    ++pos;
  } else {
    x = s[pos++] - '0';
  }
  return x;
}

int factor() {
  int x;
  if(s[pos] == '-') {
    ++pos;
    x = 2-factor();
  } else {
    x = factor2();
  }
  return x;
}

int term() {
  int x = factor();
  while(s[pos] == '*') {
    ++pos;
    x = min(x, factor());
  }
  return x;
}

int exp() {
  int x = term();
  while(s[pos] == '+') {
    ++pos;
    x = max(x, term());
  }
  return x;
}

int solve() {
  int ans = 0;
  //a();
  for(char p = '0'; p <= '2'; ++p) {
    for(char q = '0'; q <= '2'; ++q) {
      for(char r = '0'; r <= '2'; ++r) {
	s = str;
	for(int i = 0; i < s.length(); ++i) {
	  if(s[i] == 'P') s[i] = p;
	  if(s[i] == 'Q') s[i] = q;
	  if(s[i] == 'R') s[i] = r;
	}
	pos = 0;
	if(exp() == 2) ++ans;
      }
    }
  }
  return ans;
}

main() {
  while((cin >> str) && str != ".") {
    cout << solve() << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
    double pi=3.14159265358979323;
    double a,b,h,m; cin >> a >> b >> h >> m;
    double th1=(h*60.0+m)/720.0*2*pi;
    double th2=fmod(m,60.0)/60.0*2*pi;
    double th=min({abs(th1-th2),abs(th2+2*pi-th1),abs(th1+2*pi-th2)});
    //cout << th << endl;
    cout << std::fixed << std::setprecision(15) ;
    cout << sqrt(a*a+b*b-2*a*b*cos(th)) << endl;

}

Measured memory_bytes: 4224
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <numeric>

using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;

typedef pair<long long, string> pls;


#define ll long long




/*
class UnionFind {
public:
	vector <ll> par; 
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i; 
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, k, a, b, c, d, e,H, W;
long long A[200]= {};
long long B[200005] = {};
long long C[20][200] = {};
bool f;
bool ff;
string S[200];
set <long long>sll;
pl buf;
pls bufls;
vector <long long>vl;
vector <pl>vpl;
vector <pls>vpls;
vector <string> vs;

struct ST
{
	long long group;
	long long rank;
	long long tugi=-1;
	int siro;
};



vector <ST> vst;
double fl, fll;




int main() {

	cin >>N;

	for (int i = 0; i < N; i++) {
		cin >> S[i]>>A[i];
		bufls.first = A[i];
		bufls.second = S[i];
		vpls.push_back(bufls);
		vs.push_back(S[i]);
	}

	sort(vpls.begin(), vpls.end());
	reverse(vpls.begin(), vpls.end());

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

	for (int i = 0; i < vs.size(); i++) {
		if (i > 0) {
			if (vs[i] == vs[i - 1]) {
				continue;
			}
		}
		for (int j = 0; j < vpls.size(); j++) {
			if (vpls[j].second == vs[i]) {

				for (int jj = 0; jj < N; jj++) {
					if (vpls[j].first == A[jj] && vpls[j].second == S[jj]) {
						cout << jj + 1 << endl;
						break;
					}
				}

			}
		}
	}
	

	return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

// AtCode Express 2
int main() {
  uint32_t N, M, Q;
  cin >> N >> M >> Q;
  // Nが500以下なことを上手く利用してメモしていく．
  // memo[l][r]で，lはじまりr終わりの道路の数を表す．
  uint32_t memo[501][501] = {};
  for (int i = 0; i < M; i++) {
    uint32_t L, R;
    cin >> L >> R;
    memo[L][R]++;
  }
  // sum[l][r]で，lはじまりr以下終わりの道路の数を表す．
  uint32_t sum[501][501] = {};
  for (size_t i = 1; i <= N; i++) {
    for (size_t j = i; j <= N; j++) {
      sum[i][j] = sum[i][j - 1] + memo[i][j];
    }
  }
  for (int i = 0; i < Q; i++) {
    uint32_t p, q;
    cin >> p >> q;
    uint32_t ans = 0;
    for (auto s = p; s <= q; s++) {
      ans += sum[s][q];
    }
    cout << ans << endl;
  }
  return 0;
}


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

int main()
{
  int N,M;cin>>N>>M;
  pair<int,int> ab[N];pair<int,int> cd[M];
  int num[M];fill(num,num+M,0);
  for(int i=0;i<N;i++)cin>>ab[i].first>>ab[i].second;
  for(int i=0;i<M;i++)cin>>cd[i].first>>cd[i].second;
  for(int i=0;i<N;i++)
  {
    pair<int,int> p={1000000000,-1};
    for(int j=0;j<M;j++)
  	{
    	int dist=abs(ab[i].first-cd[j].first)+abs(ab[i].second-cd[j].second);
    	if(p.first>dist)p.first=dist,p.second=j;
  	}
    cout<<p.second+1<<endl;
  }
}

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

N, M, Q = (int(i) for i in input().split())
dp = [[0] *(N+1) for i in range(N+1)]
for i in range(M):
    L, R = (int(i) for i in input().split())
    dp[L-1][R-1] += 1

for j in range(N):
    for i in range(N-j):
        dp[i][i + j] = dp[i][i + j - 1]  + dp[i + 1][i + j] - dp[i + 1][i + j - 1] + dp[i][i + j]

for i in range(Q):
    L, R = (int(i) for i in input().split())
    print(dp[L-1][R-1])

Measured memory_bytes: 55516
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

typedef vector<int> Node;
typedef vector<Node> Graph;
int N, K;
Graph G;
map<int, int> value;
const int MAX_N = 100000;
int parent[MAX_N];
vector<int> child[MAX_N];
void dfs(int r, int p) {
    parent[r] = p;
    for(int c : G[r]) {
        if(c != p) {
            child[r].push_back(c);
            dfs(c, r);
        }
    }
}
void build_rooted_tree(int root) {
    REP(i, N) child[i].clear();
    dfs(root, -1);
}

int ub[MAX_N];
int lb[MAX_N];
void set_bound(int v) {
    for(int c : child[v]) {
        set_bound(c);
    }
    if(value.count(v)) {
        lb[v] = ub[v] = value[v];
    } else {
        for(int c : child[v]) {
            if(lb[c] > INT_MIN) {
                lb[v] = max(lb[v], lb[c]-1);
            }
            if(ub[c] < INT_MAX) {
                ub[v] = min(ub[v], ub[c]+1);
            }
        }
    }
}

int main(){
    iostream_init();

    while(cin >> N) {
        G.assign(N, Node());

        REP(i, N-1) {
            int a, b;
            cin >> a >> b;
            a--; b--;
            G[a].push_back(b);
            G[b].push_back(a);
        }

        value.clear();
        cin >> K;
        REP(i, K) {
            int v, p;
            cin >> v >> p;
            v--;
            value[v] = p;
        }

        const int root = value.begin()->first;
        build_rooted_tree(root);

        REP(i, N) ub[i] = INT_MAX;
        REP(i, N) lb[i] = INT_MIN;
        set_bound(root);

        bool valid = true;
        int answer[MAX_N] = {};
        answer[root] = value[root];
        queue<int> que;
        for(int c : child[root]) que.push(c);
        while(!que.empty()) {
            const int v = que.front(); que.pop();
            const int parent_val = answer[ parent[v] ];
            bool is_set = false;
            for(int d = -1; d <= 1; d += 2) {
                const int next_val = parent_val + d;
                if(lb[v] <= next_val && next_val <= ub[v]) {
                    answer[v] = next_val;
                    is_set = true;
                    for(int c : child[v]) que.push(c);
                    break;
                }
            }
            if(!is_set) {
                valid = false;
                break;
            }
        }
        if(valid) {
            cout << "Yes" << endl;
            REP(i, N) {
                cout << answer[i] << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 22144
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			Dice dice = new Dice(sc.nextLine().split(" "));
			char[] str = sc.next().toCharArray();
			
			for(char ch: str) {
				dice.rotate(ch);
			}
			System.out.println(dice.showTop());
		}
	}
	static class Dice{
		private int[] face;
		public Dice(int[] face) {
			this.face = face;
		}
		public Dice(String[] face) {
			this.face = new int[6];
			for(int i=0;i<this.face.length;i++) {
				this.face[i] = Integer.parseInt(face[i]);
			}
		}
		public void rotate(char to){
			int buf;
			switch(to) {
			case 'E':
				buf = this.face[0];
				this.face[0] = this.face[3];
				this.face[3] = this.face[5];
				this.face[5] = this.face[2];
				this.face[2] = buf;
				break;
			case 'W':
				buf = this.face[0];
				this.face[0] = this.face[2];
				this.face[2] = this.face[5];
				this.face[5] = this.face[3];
				this.face[3] = buf;
				break;
			case 'S':
				buf = this.face[0];
				this.face[0] = this.face[4];
				this.face[4] = this.face[5];
				this.face[5] = this.face[1];
				this.face[1] = buf;
				break;
			case 'N':
				buf = this.face[0];
				this.face[0] = this.face[1];
				this.face[1] = this.face[5];
				this.face[5] = this.face[4];
				this.face[4] = buf;
				break;
			}
		}
		public int showTop() {
			return this.face[0];
		}
	}
}


Measured memory_bytes: 26256
#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;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (1e+18) + 7;
typedef pair<int, int>P;
#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()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%mod;
		a = a * a%mod; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 500;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

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

void solve() {
	string s, t;
	int a, b;
	string u;
	cin >> s >> t >> a >> b >> u;
	if (s == u)a--;
	if (t == u)b--;
	cout << a << " " << b << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//init_f(); init();
	//int t; cin >> t; rep(i, t)solve();
	//while(cin>>n,n)solve();
	solve();
	stop
		return 0;
}

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

template<class T>
struct Edge{
	int from,to;
	T cost;
	Edge(int to,T cost) : to(to),cost(cost){}
	Edge(int from,int to,T cost) : from(from),to(to),cost(cost){}
	operator int() const noexcept { return to; }
};

template<class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using Graph = vector<vector<int>>;
template<class T>
using Matrix = vector<vector<T>>;

template<class T>
struct TwoEdgeConnectedComponents{
	T G;
	vector<int> cmp,depth,s;
	vector<vector<int>> tecc;
	stack<int> vs;
	using pii = pair<int,int>;
	vector<pii> bridge;

	TwoEdgeConnectedComponents(const T &G) : G(G),cmp(G.size()),depth(G.size(),-1),s(G.size()){}

	void dfs(int v,int par,int d){
		depth[v] = d;
		vs.push(v);
		for(const auto &e : G[v]){
			int to = (int)e;
			if(depth[to] == -1){
				dfs(to,v,d + 1);
				s[v] += s[to];
			}else if(to != par && depth[v] > depth[to]) s[to]--,s[v]++;
		}
		if(!s[v]){
			if(par != -1) bridge.push_back(minmax(v,par));
			tecc.emplace_back();
			while(1){
				int u = vs.top(); vs.pop();
				tecc.back().push_back(u);
				cmp[u] = tecc.size() - 1;
				if(u == v) break;
			}
		}
	}

	void build(){
		for(int i = 0;i < G.size();i++) if(depth[i] == -1) dfs(i,-1,0);
	}
};

signed main(){
	int n,m;
	cin >> n >> m;
	Graph G(n);
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	TwoEdgeConnectedComponents<Graph> tecc(G);
	tecc.build();
	sort(tecc.bridge.begin(),tecc.bridge.end());
	for(const auto &e : tecc.bridge) cout << e.first << " " << e.second << endl;
}



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

int w,h;

void init_map(int map[WMAX][HMAX]){
  rep(i,HMAX){
    rep(j,WMAX){
      map[j][i]=0;
    }
  }
}

int dd[5]={0,1,0,-1,0};

void dfs_aux(int sx, int sy, int map[WMAX][HMAX],int *min,int count){
  rep(r,4){
    int nx=sx,ny=sy;
    if(map[nx+dd[r]][ny+dd[r+1]]==1)
      continue;
    while(0<=nx+dd[r] && nx+dd[r]<w && 0<=ny+dd[r+1] && ny+dd[r+1]<h){
      nx+=dd[r];
      ny+=dd[r+1];
      if(map[nx][ny]==3)
	if(*min > count){
	  *min = count;
	  break;
	}
      if(map[nx][ny]==1){
	break;
      }
    }
    
    if(map[nx][ny]==1 && count <10){
      map[nx][ny]=0;
      nx-=dd[r];ny-=dd[r+1];
      dfs_aux(nx,ny,map,min,count+1);
      nx+=dd[r];ny+=dd[r+1];
      map[nx][ny]=1;
    }
  }
}  

int dfs(int sx, int sy, int map[WMAX][HMAX]){
  int min=11;
  dfs_aux(sx,sy,map,&min,1);
  if(min>10)
    return -1;
  return min;
}

int main(){
  for(;;){
    scanf("%d %d",&w,&h);
    if(!(w+h)) break;
    int map[WMAX][HMAX],sx,sy;
    init_map(map);
    rep(i,h){
      rep(j,w){
	scanf("%d",&map[j][i]);
	if(map[j][i]==2){
	  sx=j;
	  sy=i;
	}
      }
    }
    printf("%d\n",dfs(sx,sy,map));
  }
}

Measured memory_bytes: 1188
#include<iostream>
#include<fstream>
#include<iomanip>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, L, s[100000], t[100000], u[100000];

int main(){
	/*
	ifstream is("ans.txt");
	ifstream is2("so.txt");
	double a, b;
	while(is >> a){
		is2 >> b;
		cout << b << endl;
		if(abs(a - b) > EPS){
			cout << a << " " << b << endl;
			return 0;
		}
	}
	*/
	while(scanf("%d%d", &n, &L), n){
		rep(i, n) scanf("%d%d%d", s + i, t + i, u + i);
		double lo = 0, hi = INF, mid;
		rep(it, 100){
			long double l = L, x;
			bool ok = 1;
			mid = (lo + hi) / 2;
			rep(j, 2){
				rep(i, n){
					l = min(L * 1.0l, l + mid * (s[i] - (i ? t[i - 1] : 0)));
					l = min(L * 1.0l, l + (mid - u[i]) * (t[i] - s[i]));
					if(l <= 0){
						ok = 0;
						goto END;
					}
				}
				l = min(L * 1.0l, l + mid * (86400 - t[n - 1]));
				if(j == 0) x = l;
			}
			END:
			if(ok && l >= x) hi = mid;
			else lo = mid;
		}
		cout << fixed << setprecision(20) << hi << endl;
	}
	return 0;
}

Measured memory_bytes: 2292
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = (1 << 30) - 1;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

const int N = 300 + 10;
int g[N][N], h[N][N];

int main() {
  int n, m, L;
  scanf("%d%d%d", &n, &m, &L);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      g[i][j] = INF;
    }
    g[i][i] = 0;
  }
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    --x; --y;
    g[y][x] = g[x][y] = z;
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (g[i][k] + g[k][j] < g[i][j]) {
          g[i][j] = g[i][k] + g[k][j];
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      h[i][j] = g[i][j] <= L ? 1 : INF;
    }
    h[i][i] = 0;
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        h[i][j] = min(h[i][j], h[i][k] + h[k][j]);
      }
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    int ret = h[x][y];
    if (ret == INF) ret = 0;
    printf("%d\n", ret - 1);
  }

  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll x,k,d,n,m,ans;
    cin>>x>>k>>d;
    x=abs(x);
    n=(x/d);
    if(n>=k)
        cout<<x-k*d<<endl;
    else
    {
        m=k-n;
        if(m%2)
        {
            ans=(x%d);
            abs(ans-d)<=ans+d?ans=abs(ans-d):ans=ans+d;
            cout<<ans<<endl;
        }
        else
            cout<<x%d<<endl;
    }

}


Measured memory_bytes: 3628
#include <stdio.h>
long long p = 998244353;
char s[305];
long long a[305];
long long r[305];
long long da[305][305];
long long db[305][605];
long long ds[305][305];
long long kn, n, m, l, ans;
int main() {
	scanf(" %s", s);
	while (s[n] != NULL)n++;
	s[n] = '0';
	n++;
	s[n] = NULL;
	scanf("%lld", &kn);
	for (int i = 0; i < n; i++) {
		if (s[i] == '0') {
			r[m] = l;
			m++;
		}
		else l++;
	}
	a[0] = r[0];
	if (kn > r[m - 1])kn = r[m - 1];
	for (int i = 1; i < m; i++) {
		a[i] = r[i] - r[i - 1];
	}
	for (int i = 0; i < m; i++) {
		r[m - 1 - i] = a[i];
	}
	for (int i = 0; i < m; i++) {
		a[i] = r[i];
	}
	r[0] = a[0];
	for (int i = 1; i < m; i++) {
		r[i] = a[i] + r[i - 1];
	}
	for (int i = 0; i <= r[0]; i++) {
		ds[i][0] = 1;
	}
	for (int i = 1; i < m; i++) {
		for (int j = 0; j <= r[i]; j++) {
			for (int k = 0; k <= kn; k++) {
				da[j][k] = 0;
				db[j][k] = 0;
			}
		}
		for (int j = 0; j <= r[i - 1]; j++) {
			for (int k = 0; k <= kn; k++) {
				da[j][k] += ds[j][k];
				da[j][k] %= p;
				da[a[i] + j][k] -= (ds[j][k] - p);
				da[a[i] + j][k] %= p;
				db[a[i] + j][k] += ds[j][k];
				db[a[i] + j][k] %= p;
				db[r[i] + 1][r[i] - a[i] + 1 + k - j] -= (ds[j][k] - p);
				db[r[i] + 1][r[i] - a[i] + 1 + k - j] %= p;
			}
		}
		for (int k = 0; k <= kn; k++) {
			for (int j = 1; j <= r[i]; j++) {
				da[j][k] += da[j - 1][k];
				da[j][k] %= p;
			}
		}
		for (int j = 0; j <= r[i]; j++) {
			for (int k = 0; k <= kn; k++) {
				if (j && k) {
					db[j][k] += db[j - 1][k - 1];
					db[j][k] %= p;
				}
			}
		}
		for (int j = 0; j <= r[i]; j++) {
			for (int k = 0; k <= kn; k++) {
				ds[j][k] = da[j][k] + db[j][k];
				ds[j][k] %= p;
				//printf("%lld ", ds[j][k]);
			}
			//printf("\n");
		}
		//printf("\n");
	}
	for (int k = 0; k <= kn; k++) {
		ans += ds[r[m - 1]][k];
		ans %= p;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 4568
from numba import jit

@jit
def gcd(a,b):
    if b == 0: return a
    else: return gcd(b, a % b)

@jit
def main2(K):
    ans = 0
    for i in range(1,K+1):
        for j in range(1,K+1):
            tmp = gcd(i,j)
            for k in range(1,K+1):
                ans += gcd(tmp,k)
    return ans    


K = int(input())
print(main2(K))

Measured memory_bytes: 109764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int[][] dp = new int[201][201];
		long res = 0;
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				int gcd;
				if (dp[i][j] == 0) {
					gcd = gcd(i, j);
					dp[i][j] = gcd;
				} else {
					gcd = dp[i][j];
				}
				for (int k = 1; k <= K; k++) {
					int gcd3;
					if (dp[gcd][k] == 0) {
						gcd3 = gcd(gcd, k);
						dp[gcd][k] = gcd3;
					} else {
						gcd3 = dp[gcd][k];
					}
					res += gcd3;
				}
			}
		}
		System.out.println(res);
	}

	private static int gcd(int i, int j) {
		while (i != 0 && j != 0) {
			if (i < j) {
				j %= i;
			} else {
				i %= j;
			}
		}
		return Math.max(i, j);
	}
}

Measured memory_bytes: 36532
#include <stdio.h>
#include <algorithm>
#include <vector>

using namespace std;

#define ll long long
#define REP(i, n) for (int i = 0; i < n; ++i)

int main() {
    int N, K;
    scanf("%d %d", &N, &K);

    vector<int> x(N), y(N);
    vector<int> xary, yary;

    REP(i, N) {
        scanf("%d %d", &x[i], &y[i]);
        xary.push_back(x[i]);
        yary.push_back(y[i]);
    }

    sort(xary.begin(), xary.end());
    sort(yary.begin(), yary.end());

    ll ans = 1LL * (xary[N - 1] - xary[0]) * (yary[N - 1] - yary[0]);

    REP(xi, N) {
        for (int xj = xi + 1; xj < N; ++xj) {
            REP(yi, N) {
                for (int yj = yi + 1; yj < N; ++yj) {
                    ll lx = xary[xi], rx = xary[xj];
                    ll by = yary[yi], uy = yary[yj];

                    int num = 0;
                    REP(i, N) {
                        if ((lx <= x[i]) && (x[i] <= rx) && (by <= y[i]) && (y[i] <= uy)) {
                            num++;
                        }
                    }

                    if (num >= K) {
                        ans = min(ans, 1LL * (rx - lx) * (uy - by));
                    }
                }
            }
        }
    }

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

    return 0;
}


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

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			String[] se = s.split(" ");
			Double in1 = Double.valueOf(se[0]);
			doMain(++inCnt, in1);
		}
		System.exit(0);
	}

	private static void doMain(int inCnt, Double in1) {
		Double a = 2 * in1 * Math.PI;
		Double b = in1 * in1 * Math.PI;
		System.out.printf("%f %f\n", b, a);

	}
}

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

signed main(){
    //A
    /*
    int s,w;cin>>s>>w;
    if(s<=w) cout<<"unsafe"<<endl;
    else  cout<<"safe"<<endl;
    */
   //B
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   while(a!=0&&c!=0){
       c-=b;
       if(c<=0){
           cout<<"Yes"<<endl;
           return 0;
       }
       a-=d;
       if(a<=0){
           cout<<"No"<<endl;
           return 0;
       } 
   }
}

Measured memory_bytes: 3592
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; 
    int m;
    cin >> n >> m;

    vector<int> M(n, 0);
    for (int i = 0; i < m; ++i) {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int x;
            cin >> x;
            --x;
            M[x] |= 1 << i; 
        }
    }

    vector<int> P(m, 0);
    for (int i = 0; i < m; ++i) {
        cin >> P[i];
    }

    auto ok = [&](int N) {
        vector<int> S(m, 0);
        for (int i = 0; i < n; ++i) {
            if (N & (1 << i)) {
                for (int j = 0; j < m; ++j) {
                    if (M[i] & (1 << j)) {
                        S[j] ^= 1;
                    }
                }
            }
        }
        for (int i = 0; i < m; ++i) {
            if (S[i] != P[i]) {
                return false;
            }
        }
        return true;
    };

    int res = 0;
    for (int i = 0; i < (1 << n); ++i) {
        if (ok(i)) {
            ++res;
        }
    }

    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
/*Made by Shivam Solanki*/
#include<bits/stdc++.h> 
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
typedef queue<int> qii;
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define repllr(i,k,n) for (ll i = n; i >= k; --i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// const int INF = 1e9+5;
const int MOD = 1e9+7;


ll mul(ll a,ll b){
    return a*b%MOD;
}
 
ll mypow(ll a,ll b){
    ll r=1;
    while(b){
        if(b%2){
            r=mul(a,r);
        }
        a=mul(a,a);
        b/=2;
    }
    return r;
}
 
ll my_inv(ll a){
    return mypow(a,MOD-2);
}

ll nCr(ll n,ll k){  
    ll res = 1;  
    if(k>n-k)  
        k=n-k;  
  
    // Calculate value of  
    // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]  
    for(ll i = 0; i < k; ++i)  
    {  
        res=(res*(n-i))%MOD;  
        // res = res/(i + 1);
        res = mul(res,my_inv(i+1))%MOD;  
    }  
  
    return res;  
} 

ll binpow(ll a,ll b) {
    a %= MOD;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

void solve(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll total=binpow(2,n);
    total=(total-1)%MOD;
    // cout<<total<<'\n';
    ll x=nCr(n,a),y=nCr(n,b);
    ll ans=(total-x-y)%MOD;
    if(ans<0){
        ans+=MOD;
    }
    cout<<ans<<'\n';
} 
  
int main(){
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    // fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 384