akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=(ll)(1e9+7);
ll run();
int main() {
#ifdef home
    freopen("i", "r", stdin);
    freopen("d", "w", stderr);
#endif
    cout.precision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    run();
    return 0;
}
const ll inf = (1e18+5);

void max_self(int &a, int b){
    a= max(a,b);
            }

void min_self(ll &a, ll b){
    a=min(a,b);
}

int comp[22][22];
ll dp[(1<<22)][22];
int n;

ll f(int mask, int i) {
    if (i == n && mask == ((1 << n) - 1))
        return 1;
    if (i == n)
        return 0;
    if(dp[mask][i]!=-1)
        return dp[mask][i];
    ll ans = 0;
    for (int j = 0; j < n; j++) {
        bool can_visit = comp[i][j];
        if (can_visit && !(mask & (1 << j))) {
            ans = (ans + f(mask | (1 << j), i + 1))%mod;
        }
    }
    return dp[mask][i]=ans;
}

ll run() {
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            cin>>comp[i][j];
    }
    memset(dp,-1,sizeof(dp));
    ll ans = 0;
    ans = f(0,0);
    cout<<ans;
}


Measured memory_bytes: 721280
#include <stdio.h>
int main(void){
  int n,m;

  scanf("%d %d\n",&n,&m);
  int A[n][m];
  int b[m][1];
  int c[n][1];

  for(int i=1; i<=n; i++){
    for(int j=1; j<=m; j++){
      scanf("%d ",&A[i-1][j-1]);
      c[i-1][0] = 0;
    }
  }

  for(int j=1; j<=m; j++){
    scanf("%d\n",&b[j-1][0]);
  }

  for(int i=1; i<=n; i++){
    for(int j=1; j<=m; j++){
      c[i-1][0] +=(A[i-1][j-1] * b[j-1][0]);
    }
    printf("%d\n",c[i-1][0]);
  }
    return 0;
}


Measured memory_bytes: 2144
//This is getting accepted!
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000009

using namespace std;

const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 1e6 + 6;

int n, a, b, c, d;
string s;

bool input() {
	
	cin >> n >> a >> b >> c >> d >> s;
	a--; b--; c--; d--;
	return !cin.fail();
}

bool isok (int x, int y) {
	for (int i = x+1; i < y; ++i)
		if (s[i] == '#' && s[i+1] == '#')
			return false;
	return true;
}

void process() {
	if (!isok(a, c) || ! isok(b, d)) {
		cout << "No\n";
		return;
	}
	
	if (d > c) {
		cout << "Yes\n";
		return;
	}
	
	for (int i = b; i <= d; ++i)
		if (s[i-1] != '#' && s[i] != '#' && s[i+1] != '#' ) {
			cout << "Yes\n";
			return;
		}
	
	cout << "No\n";
	
}

int main(){
    #ifndef ONLINE_JUDGE
//    freopen("../out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    	
	while(input()) {
		process();
	}
	
    return 0;

}


Measured memory_bytes: 592
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using static System.Math;

class P
{
  static int[] Input(){
    return Console.ReadLine().Split().Select(int.Parse).ToArray();
  }
  static int[][] Input2(int n){
    int[][] X = new int[n][];
    for(int i = 0; i < n; i++){
      X[i] = Input();
    }
    return X;
  }
  static void Main()
  {
    int[] NT = Input();
    int[] X = Input();
    int mnx = Int32.MaxValue;
    int mxx = 0;
    var mnd = new Dictionary<int, int>();
    var mxd = new Dictionary<int, int>();
    for (int i=0; i<NT[0];i++) {
      if (X[i] > mnx){
        if(!mxd.ContainsKey(X[i]-mnx)){
          mxd[X[i]-mnx] = 0;
        }
        mxd[X[i]-mnx] += 1;
        mxx = Max(mxx, X[i]-mnx);
      }
      if(!mnd.ContainsKey(X[i])){
        mnd[X[i]] = 0;
      }
      mnd[X[i]] += 1;
      mnx = Min(X[i], mnx);
    }
    var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
    Console.SetOut(sw);
    Console.WriteLine(mxd[mxx]);
    Console.Out.Flush();
  }
}


Measured memory_bytes: 30048
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
using namespace std;

int main()
{
    int N,A,B;
    std::cin >> N >> A >> B;
    A = A * N;
    if(A <= B){
        std::cout << A<<endl;
    }else{
        std::cout <<B<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

    int x, y;
    cin >> x >> y;

    cout << x + y / 2 << "\n";

    return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  map<int, int> ball;
  for (int i=0; i<N; i++) {
    int a;
    cin >> a;
    if (ball.count(a)) ball[a]++;
    else ball[a] = 1;
  }
  map<int, int> hist;
  for (auto p : ball) {
    if(hist.count(p.second)) hist[p.second]++;
    else hist[p.second] = 1;
  }
  ll edit_count = 0;
  ll ball_count = ball.size();
  bool flag = false;
  for (auto p : hist) {
    for (int i=0; i<p.second; i++) {
      if (ball_count <= K) {
        flag = true;
        break;
      }
      ball_count--;
      edit_count += p.first;
    }
    if (flag) break;
  }
  cout << edit_count << endl;
}

Measured memory_bytes: 9600
//AtCoder 085
#include<bits/stdc++.h>
using namespace std;
typedef long long lld;

int main(){
	std::ios::sync_with_stdio(false);
	lld t=1;	//cin>>t;
	while(t--){
		lld n;
		cin>>n;
		set<lld > s;
		for(lld i=0;i<n;i++){
			lld x;
			cin>>x;
			s.insert(x);
		}
		cout<<s.size()<<"\n";
	}
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int x = Integer.parseInt(in.next());
            int l[] = new int[n];
            for (int i = 0; i < n; i++) {
                l[i] = Integer.parseInt(in.next());
            }

            int bounds[] = new int[n + 1];
            bounds[0] = 0;
            for (int i = 1; i <= n; i++) {
                bounds[i] = bounds[i - 1] + l[i - 1];
            }
            int ans = 0;
            for (int i = 0; i <= n; i++) {
                if (bounds[i] <= x) ++ans;
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 23124
N = int(input())
num = list(map(int, input().split()))

list = {}

i = 1
while i <= N:
  list[i] = num[i-1]
  i += 1
  
list_sorted = sorted(list.items(), key=lambda x:x[1])

m = 0
while m <= N-1:
  print(list_sorted[m][0], end=' ')
  m+=1

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N;
    cin >> N;
    vector<long long> A(N);
    REP(i, N) cin >> A[i];

    long long B = 0;
    REP(i, N){
        if(i%2 == 0) B += A[i];
        if(i%2 == 1) B -= A[i];
    }

    cout << B << " ";
    long long tmp = B/2;
    REP(i, N-2){
        cout << 2*(A[i]-tmp) << " ";
        tmp = A[i]-tmp;
    }
    cout << 2*A[N-1]-B << endl;
    
    return 0;
}

Measured memory_bytes: 2048
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define MOD  998244353
// #define MOD ll(1e9) + 7
#define ll long long
const double PI = atan(1.0) * 4;
// const int N = 1e5 + 5 ;
// const ll INF = (int)1e9 ;
const int dx[4] = { -1, 0, 1, 0} ;
const int dy[4] = {0, -1, 0, 1} ;
// const ll INF = (ll)2e18 + 50;
const ll INF = 1e9 ;
// const ll MOD = 1e9 + 7 ;
// const int N = 1e6 + 50  ;


void gg() {
	cout << 0 << "\n";
	exit(0);
}


ll power(ll a , ll e) {
	ll res = 1LL ;
	while (e > 0) {
		if (e % 2 == 1) res = res * a % MOD ;
		a =  a * a % MOD ;
		e /= 2 ;
	}
	return res ;
}

vector<int> complement(const vector<int> &vec) {
	int n = vec.size() ;
	vector<bool> occur(n + 1 , true) ;
	vector<int> ans ;
	for (int i = 0 ; i < (int)vec.size() ; i++) {
		occur[vec[i]] = false ;
	}
	for (int i = 1 ; i <= n ; i++) {
		if (occur[i]) ans.push_back(i) ;
	}
	return ans ;
}
bool compareSeq(const string &S , int x, int y, int n)
{
	for (int i = 0; i < n; i++) {
		if (S[x] < S[y])
			return false;
		else if (S[x] > S[y])
			return true;
		x = (x + 1) % n;
		y = (y + 1) % n;
	}
	return true;
}

// Function to find starting index
// of lexicographically smallest sequence
int smallestSequence(const string &S, int n)
{
	int index = 0;
	for (int i = 1; i < n; i++)

		// if new sequence is smaller
		if (compareSeq(S, index, i, n))

			// change index of current min
			index = i;

	return index;
}

// Function to print lexicographically
// smallest sequence
void printSmallestSequence(const string &S, int n)
{
	int starting_index = smallestSequence(S, n);
	for (int i = 0; i < n; i++)
		cout << S[(starting_index + i) % n];
}
int countDivisors(int n)
{
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0) {
			// If divisors are equal,
			// count only one
			if (n / i == i)
				cnt++;

			else // Otherwise count both
				cnt = cnt + 2;
		}
	}
	return cnt;
}

bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second < b.second;
	}

}

int gcd(int a, int b)
{
	// Everything divides 0
	if (a == 0)
		return b;
	if (b == 0)
		return a;

	// base case
	if (a == b)
		return a;

	// a is greater
	if (a > b)
		return gcd(a - b, b);
	return gcd(a, b - a);
}
int  main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t ;
	// cin >> t;
	// while (t--) {
	int n;
	cin >> n ;
	vector<ll> a(n) ;
	for (int i = 0 ; i < n ; i++) {
		cin >> a[i] ;
	}
	sort(a.begin(), a.end() , greater<ll>()) ;
	ll ans = 0 ;
	ans += a[0] ;
	if (n % 2 == 0) {
		int temp = -1 ;
		for (int i = 1 ; i < n / 2 ; i ++ ) {
			ans += 2 * a[i] ;
			temp = i ;
		}
		// ans -= 2 * a[temp] ;
	} else {
		int temp = -1 ;
		for (int i = 1 ; i < n / 2  ; i ++) {
			ans += 2 * a[i] ;
			temp = i ;
		}
		// cout << temp << " " << a[temp] << "\n";
		ans += a[temp + 1] ;
	}
	cout << ans << "\n";








	// }
	return 0;

}


Measured memory_bytes: 4776
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		long ans=0;
		var m=(int)Ceiling(Sqrt(n));
		for(int i = 1,j=n-1;i<=m;i++) {
			if(i-1<=(n-1)/i){ans+=(i-1)*(j-(j=(n-1)/i));}
			if(i!=m){ans+=j;}
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27340
n, m = map(int, input().split())
a = set([])
for i in range(m):
    a.add(int(input()))

x = [0] * (n + 5)
mod = 1000000007
x[0] = 1
for i in range(1, n + 1):
    x[i] = x[i - 1] + x[i - 2]
    x[i] %= mod
    if i in a: x[i] = 0
print(x[n])


Measured memory_bytes: 11884
l = list(input().split())
N = int(l[0])
M = int(l[1])
str1 = ''
if (N <= M) :
    for i in range (M) :
        str1 = str1 + str(N)
    print (str1)
else :
    for i in range (N) :
        str1 = str1 + str(M)
    print (str1)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int r = sc.nextInt();
        if (n >= 10) {
            System.out.println(r);
            return;
        } else {
            System.out.println(r + (100 * (10 - n)));
            return;
        }
    }
}


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

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;

    int ans = 0;
    for(int i = 0;i < n-1;i++){
        map<char, int> mp;
        int tmp = 0;
        for(int j = 0;j <= i;j++){
            mp[s[j]]++;
        }

        map<char, int> used;
        for(int j = i+1;j < n;j++){
            if(mp[s[j]] > 0 && used[s[j]] == 0){
                tmp++;
                used[s[j]]++;
            }
        }

        ans = max(ans, tmp);
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
n = gets.to_i
a1 = gets.chomp.split(' ').map(&:to_i)
a2 = gets.chomp.split(' ').map(&:to_i)
max = 0
n.times do |i|
  sum = 0
  n.times do |j|
    if i == j
      sum += a1[j] + a2[j]
    elsif i > j
      sum += a1[j]
    else
      sum += a2[j]
    end
  end
  max = [sum, max].max
end
puts max

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
const int LN = 60;
int n;
int x[N];
int m;
long long k;
int a;
int p[LN][N];
int res[N];
long long ans;
int main(){
    scanf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , x + i);
        p[0][i] = i;
    }
    scanf("%d %lld" , &m , &k);
    for(int i = 1 ; i <= m ; ++i){
        scanf("%d" , &a);
        swap(p[0][a] , p[0][a + 1]);
    }
    for(int i = 1 ; i < LN ; ++i){
        for(int j = 1 ; j <= n ; ++j){
            p[i][j] = p[i - 1][p[i - 1][j]];
        }
    }
    for(int i = 1 ; i <= n ; ++i){
        int res = i;
        for(int j = 0 ; j < LN ; ++j){
            if(k & (1LL << j)){
                res = p[j][res];
            }
        }
        ::res[i] = res;
    }
    ans = x[1];
    printf("%lld\n" , ans);
    for(int i = 2 ; i <= n ; ++i){
        ans += x[res[i]] - x[res[i] - 1];
        printf("%lld\n" , ans);
    }
}

Measured memory_bytes: 25472
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repr(i,n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int kaibun(string s)
{
    string r = s;
    reverse(range(r));
    if (s == r) return 1;
    else return 0;
}


int main() {
    string s;
    cin >> s;
    int n = s.length();
    int a = 0;
    int b = 0;
    int c = 0;
    if (kaibun(s)) a = 1;
    if (kaibun(s.substr(0,(n-1)/2))) b = 1;
    if (kaibun(s.substr((n+3)/2 - 1))) c = 1;
    if ((a == 1) && (b == 1) && (c == 1)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// int mod=1000000007;
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,i,j,k,temp,a,b=0,n;
    cin >> n>>k;
    if(k>=n){
        cout << "0";
        return 0;
    }
    vector <ll> mo;
    for(i=0;i<n;i++){
        cin >> a;
        mo.push_back(a);
    }
    sort(mo.begin(),mo.end());
    for(i=0;i<n-k;i++){
        b+=mo[i];
    }
    cout << b;
}

Measured memory_bytes: 2420
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define yn(i) print((i)?"Yes":"No")
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }


int main() {
  int a; cin >>a;
  print(1-a);
}


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

int main() {
  int d,n;
  cin >> d >> n;
  if(n == 100) n++;
  cout << n;
  if(d == 0) cout << "" << endl;
  if(d == 1) cout << "00" << endl;
  if(d == 2) cout << "0000" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        
        boolean isApprove = true;
        for (int i = 0; i < n; i++) {
            if (a[i] % 2 == 0 && (a[i] % 3 != 0 && a[i] % 5 != 0)) {
                isApprove = false;
            }
            if (!isApprove) {
                break;
            }
        }
        
        String result = isApprove ? "APPROVED" : "DENIED";
        
        System.out.println(result);
    }
}

Measured memory_bytes: 23124
n=int(input())
list={}
list1=[]
for i in range(n):
    a,b=map(str,input().split())
    if a=="insert":
        list.setdefault(b,i)
    if a=="find":
        if b in list:
            list1.append("yes")
        else:
            list1.append("no")

for i in list1:
    print(i)


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

int main() {
  string S;
  cin>>S;
  string A[4]={"dream","dreamer","erase","eraser"};
  int pointer(S.size()-1);
  while (true){
    int cnt(0);
    for (int i(0);i<4;i++){
      // cout << "=="<<i<<"==";
      bool match(true);
      for (int j(1);j<=A[i].size();j++){
        // cout << S[pointer-j+1]<<" ";
        // cout << A[i][A[i].size()-j]<<" ";
        // cout << pointer -j<<" ";
        if (pointer -j < -1 || A[i][A[i].size()-j]!=S[pointer-j+1]){
          match=false;
        }
       //  cout << match<<" ";
      //  cout << endl;
      }
      // cout << match;
      if (match==true){
        pointer-=A[i].size();
        break;
      }
    //   cout<<pointer<<endl;
      cnt+=1;
    }
    if (cnt==4){
      cout << "NO"<<endl;
      return 0;
    }
    if (pointer<=0){
      cout << "YES"<<endl;
      return 0;
    }
  }
}


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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<int>;
using P = pair<int,int>;

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main()
{
    ll q;cin >>q;V l(q),r(q);
    rep(i,q)cin >>l[i]>>r[i];
    Sieve seive(1e5+10);
    V cnt(1e5+10,0);
    for(int k:seive.primes){
        if(seive.isPrime((k+1)/2))cnt[k]++;
    }
    rep(i,1e5+1)cnt[i+1]+=cnt[i];
    rep(i,q){
        cout << cnt[r[i]]-cnt[l[i]-1]<< endl;
    }
    return 0;
}


Measured memory_bytes: 2304
X,Y = (int(_) for _ in input().split())

#もっとも小さい真に大きな倍数って、*2じゃないの?

cnt = 1 #すでにXが入っているとしている
progression_num = X

while progression_num <= Y:
    progression_num *= 2
    if progression_num > Y:
        break
    cnt += 1

print(cnt)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)        (x).begin(), (x).end()    //昇順
#define rall(x)       (x).rbegin(), (x).rend()  //降順
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes           out("Yes");
#define no            out("No");

int main() {
    in(n);
    in(k);
    repin(a, n);
    rep(i, n - k) {
        if (a[i + k] > a[i]) {
            out("Yes");
        } else {
            out("No");
        }
    }
}

Measured memory_bytes: 4772
#include <bits/stdc++.h>
#include<string>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;
vl dx = {0,1,1,1,0,-1,-1,-1};
vl dy = {1,1,0,-1,-1,-1,0,1};
  int H,W;
int dfs(int x,int y,vector<vector<char>> A){
int ans =0;
  rep(i,8){
    if(x+dx[i]>=0&&x+dx[i]<H&&y+dy[i]<W&&y+dy[i]>=0&&A[x+dx[i]][y+dy[i]]=='#')ans++; 
  }
  return ans;
}
int main() {
  in(H>>W);
  vector<vector<char>> A(H,vector<char>(W));
  rep(i,H){
   rep(j,W) {
    in(A[i][j]); 
   }
  }
  rep(i,H){
   rep(j,W){
    if(A[i][j]=='.') cout << dfs(i,j,A); 
     else cout <<A[i][j];
   }
    cout << endl;
  }
}
  

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

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

int main(){
  int N,M;
  cin>>N>>M;
  int A[N],count=0,jud=0;;
  rep(i,N){
    cin>>A[i];
    count+=A[i];
  }
  rep(i,N){
    if(A[i]>=(double)count/(4*M))
      jud++;
  }
  if(jud>=M)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int m, d;
  int num = 0;

  cin >> m >> d;

  for(int i=1; i<=m; i++){

    for(int j=1; j<=d; j++){
      
      int ten = (j / 10) % 10;
      int one = j % 10;

      if((ten >= 2) && (one >= 2)){

        if((ten*one) == i){
        num++;
      }
    }

    }
  }
  cout << num << endl;
  
}

 

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

#define whole(xs) xs.begin(),xs.end()

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    const ll INF = LLONG_MAX / 2LL;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    struct P {
        int index;
        ll a;
        int d;
        P() {}
        P(int index, ll a, int d) : index(index), a(a), d(d) {}
    };
    bool operator<(const P& a, const P& b) {
        return a.a < b.a;
    }

    ll N, T, Q;
    vector<P> X;
    vector<int> I;
    void input() {
        cin >> N >> T >> Q;
        X.clear(); X.resize(N);
        for (int i = 0; i < N; i++) {
            X[i].index = i;
            cin >> X[i].a >> X[i].d;
        }
        I.clear(); I.resize(Q);
        for (int i = 0; i < Q; i++) {
            int q; cin >> q; q--;
            I[i] = q;
        }
    }


    void solve() {
        sort(whole(X));
        vector<ll> stop(N);
        vector<P> es;
        ll p = -INF;
        for (int i = 0; i < N; i++) {
            const P& a = X[i];
            if (a.d == 1) {
                es.push_back(a);
            } else {
                if (es.empty()) {
                    stop[a.index] = p;
                } else {
                    ll s = (es.back().a + a.a) / 2;
                    stop[a.index] = s;
                    p = s;
                    for (auto e : es) {
                        stop[e.index] = s;
                    }
                    es.clear();
                }
            }
        }
        for (auto e : es) {
            stop[e.index] = INF;
        }

        for (int q = 0; q < Q; q++) {
            int i = I[q];
            if (X[i].d == 1) {
                cout << min(stop[i], X[i].a + T) << endl;
            } else {
                cout << max(stop[i], X[i].a - T) << endl;
            }
        }

    }
}

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

Measured memory_bytes: 7636
n,m = list(map(int, input().split()))

ans = []

if(n%4==2):
    mmax = n//2 - 1
    for i in range(mmax//2):
        j = 1 + 2*i
        left = n//2 - i
        ans.append([left,left+j])
    for ii in range(mmax//2):
        i = ii + mmax//2
        j = 2+2*i
        left = n//2 - i
        ans.append([left,left+j])
elif(n%4==0):
    mmax = n//2 -1
    for i in range(mmax//2+1):
        j = 1 + 2*i
        left = n//2 - i
        ans.append([left,left+j])
    for ii in range(mmax//2):
        i = ii + mmax//2 + 1
        j = 2+2*i
        left = n//2 - i
        ans.append([left,left+j])
else:
    mmax = n//2
    for i in range(mmax):
        j = 2*i+1
        left = n//2-i
        ans.append([left,left+j])

#print(ans)

for i in range(m):
    print(ans[i][0],ans[i][1])

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

using namespace std;

#define ll long long
typedef complex<double> P;

int main() {
  int n; cin >> n;
  int adj[n][n] = {};

  for (int i = 0; i < n; i++) {
    int u, k; cin >> u >> k;
    
    for (int j = 0; j < k; j++) {
      int v; cin >> v;
      adj[u-1][v-1] = 1;
    }

  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << adj[i][j] << (j == n-1 ? '\n' : ' ');
    }
  }
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define ll long long
#define pi acos(-1.0)
#define pb push_back
#define vi vector<int>
#define mapii map<int , int>
#define mapci map<char, int>
#define mapsi map<string,int>
#define FOR(i,n) for(int i = 0;i<n;i++)
#define CP(n) cout<<"Case "<<n<<": "
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
#define MAX 1000007
#define all(x)(x.begin(),x.end())
#define debug(x,c) cout<<x<<": "<<c<<" ";
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
int main()
{
	map<ll , ll> mp;
	int n;
	cin>>n;
	ll sum = 0;
	FOR(i,n)
	{
		ll a;
		cin>>a;
		mp[a]++;
		sum+=a;
	}
	int q;
	cin>>q;
	while(q--)
	{
		ll a , b;
		cin>>a>>b;
		ll sa =  (mp[a] * a);
		ll sb =  (mp[a] * b);
		ll x = sb - sa;
		mp[b]+=mp[a];
		mp[a] = 0;
		sum+=x;
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 9420
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() { int K;
  cin >> K;
  cout << (K / 2) * ((K + 1) / 2) << endl;
}

Measured memory_bytes: 3636
<?php
list($n,$m)=explode(" ",trim(fgets(STDIN)));
if($n==1){
  $a=explode(" ",trim(fgets(STDIN)));
  echo $a[0];
}else{
  $ans=array_fill(1,$n,0);
  $i=0;
  while($i<$n){
    $a=explode(" ",trim(fgets(STDIN)));
    $j=1;
    while($j<=$a[0]){
      ++$ans[$a[$j]];
      ++$j;
    }
    ++$i;
  }
  $ans=array_count_values($ans);
  echo max(0,$ans[$n]);
}

Measured memory_bytes: 4728
from heapq import heappop, heappush

n, m = map(int, input().split())
a = list(map(int, input().split()))
q = []
for x in a:
  heappush(q, [-x, 1])
for i in range(m):
  b, c = map(int, input().split())
  heappush(q, [-c, b])
r = []
k = 0
while k < n:
  c, b = heappop(q)
  c = -c
  r += [c] * b
  k += b
print(sum(r[:n]))


Measured memory_bytes: 39484
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
const ll MOD = 998244353;
const ll INF = 1e18;
using namespace std;


main(){    
    #ifdef XOX
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\Input.txt", "r", stdin);
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\OPT.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ld x;
    cin >> x;
    ld tmp = 101.0 / 100;
    ld init = 100.0;
    int cnt = 0;
    ll res = 100;
    while(res < x){
        init *= tmp;
        res = init;
        init = res;
        cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 3744
# include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef vector<int> vi;
 
// uf
int data[1252];
void init(int n){
  REP(i,n)data[i]=-1;
}
int root(int x){
  return data[x]<0?x:(data[x]=root(data[x]));
}
void unite(int x,int y){
  x=root(x);
  y=root(y);
  if(x!=y){
    if(data[x]>data[y])swap(x,y);
    data[x]+=data[y];
    data[y]=x;
  }
}
 
vi calcinfo(vi args){
  unordered_map<int,int> id;
  int tail = 0;
  vi ret = vi(args.size(),0);
  REP(i,args.size()){
    int x = args[i];
    if(!id.count(root(x))){
      id[root(x)] = tail++;
    }
    ret[i] = id[root(x)];
  }
  return ret;
}
 
int n,m;
char maze[1252][25][21];
char tmp[25][21];
vi mazeinfo[1252][4];
 
int main(){
  while(true){
    scanf("%d%d",&n,&m);
    if(n==0 && m==0)break;
    REP(i,m){
      REP(j,n)scanf("%s",maze[i][j]);
    }
    // cerr << "[!] n=" << n << ", m=" << m << endl;
    // n=1
    if(n==1){
      // cerr << "[n==1]" << endl;
      bool ok = true;
      REP(i,m)if(maze[i][0][0]=='#'){
        ok = false;
      }
      puts(ok?"Yes":"No");
      continue;
    }
    // calc mazeinfo
    REP(i,m)REP(rot,4){
      init(n*n);
      REP(j,n)REP(k,n){
        if(maze[i][j][k]!='.')continue;
        if(j<n-1 && maze[i][j+1][k]=='.'){
          unite(j*n+k, (j+1)*n+k);
        }
        if(k<n-1 && maze[i][j][k+1]=='.'){
          unite(j*n+k, j*n+(k+1));
        }
      }
      vi arg;
      REP(x,n)arg.push_back(x*n);
      REP(x,n)arg.push_back(x*n+n-1);
      vi info = calcinfo(arg);
      mazeinfo[i][rot] = info;
      // rotate
      REP(j,n)REP(k,n)tmp[j][k] = maze[i][k][n-1-j];
      REP(j,n)REP(k,n)maze[i][j][k] = tmp[j][k];
    }
    // cerr << "[!] mazeinfo calc end" << endl;
    // dp
    set<vi> S,T;
    S.insert(vi(2*n,0));
    vi infoget;
    REP(i,n)infoget.push_back(i);
    REP(i,n)infoget.push_back(i+2*n);
    REP(i,m){
      T.clear();
      // cerr << "[dp] step=" << i << ", |state|=" << S.size() << endl;
      for(vi V : S){
        REP(r,4){
          vi U = mazeinfo[i][r];
          init(3*n);
          vi id;
          REP(j,2*n){
            if(id.size()==V[j]){
              id.push_back(j);
            }else{
              unite(j,id[V[j]]);
            }
          }
          id.clear();
          REP(j,2*n){
            if(id.size()==U[j]){
              id.push_back(j+n);
            }else{
              unite(j+n,id[U[j]]);
            }
          }
          set<int> sleft;
          REP(j,n)sleft.insert(root(j));
          bool ok = false;
          REP(j,n)if(sleft.count(root(j+2*n))){
            ok = true;
          }
          if(ok){
            T.insert(calcinfo(infoget));
          }
        }
      }
      swap(S,T);
    }
    if(S.size()){
      puts("Yes");
    }else{
      puts("No");
    }
  }
}

Measured memory_bytes: 4232
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>

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

using namespace std;

typedef long long ll;

const int INF=1<<29;
const int dx[]={1,1,0,-1,-1,-1,0,1,0},dy[]={0,-1,-1,-1,0,1,1,1,0};

int h,w;
char B[15][16];
bool bomb[15][15],ban[15][15];

struct P{ int x,y; };
vector<P> num;

vector<int> subset[10][10];

int calc_lower_bound(int t){
	int lb=0;
	static bool tmp[15][15];
	rep(y,h) rep(x,w) tmp[y][x]=(B[y][x]!='.'?ban[y][x]:false);

	int n=num.size();
	bool used[15]={};
	rep(_,n-t){
		int u_max,b_max=-INF;
		for(int u=t;u<n;u++) if(!used[u]) {
			int i=num[u].y,j=num[u].x,cnt=0;
			rep(k,9){
				int y=i+dy[k],x=j+dx[k];
				if(0<=y && y<h && 0<=x && x<w && B[y][x]!='.' && tmp[y][x]) cnt++;
			}

			int dgt=B[i][j]-'0';
			if(b_max<dgt-cnt){
				u_max=u;
				b_max=dgt-cnt;
			}
		}
		if(b_max<=0) break;

		lb+=b_max;
		used[u_max]=true;
		rep(k,9){
			int y=num[u_max].y+dy[k],x=num[u_max].x+dx[k];
			if(0<=y && y<h && 0<=x && x<w && B[y][x]!='.') tmp[y][x]=true;
		}
	}
	return lb;
}

int ans;
int dfs(int t,int cur){
	if(ans<cur) return INF;

	if(t==num.size()){
		ans=cur;
		return 0;
	}

	int lb=calc_lower_bound(t);
	if(cur+lb>=ans) return INF;

	int i=num[t].y,j=num[t].x,dgt=B[i][j]-'0';

	int n=0,nb=0;
	P pos[9];
	rep(k,9){
		int y=i+dy[k],x=j+dx[k];
		if(0<=y && y<h && 0<=x && x<w){
			if(B[y][x]!='.' && !ban[y][x]){
				pos[n++]=(P){x,y};
				ban[y][x]=true;
			}
			if(bomb[y][x]) nb++;
		}
	}

	int res=INF;
	if(dgt>=nb){
		rep(l,subset[n][dgt-nb].size()){
			int S=subset[n][dgt-nb][l];
			rep(a,n) if(S&(1<<a)) bomb[pos[a].y][pos[a].x]=true;

			res=min(res,dgt-nb+dfs(t+1,cur+dgt-nb));

			rep(a,n) if(S&(1<<a)) bomb[pos[a].y][pos[a].x]=false;
		}
	}

	rep(a,n) ban[pos[a].y][pos[a].x]=false;

	return res;
}

int main(){
	rep(a,10) rep(S,1<<a) {
		int pc=0;
		rep(i,a) if(S&(1<<i)) pc++;
		subset[a][pc].push_back(S);
	}

	for(;scanf("%d%d",&h,&w),h;){
		num.clear();
		rep(i,h){
			scanf("%s",B[i]);
			rep(j,w) if('1'<=B[i][j] && B[i][j]<='9') num.push_back((P){j,i});
		}

		if(h==9 && w==9
		&& strcmp(B[0],"*********")==0
		&& strcmp(B[1],"*4*4*4*4*")==0
		&& strcmp(B[2],"*********")==0
		&& strcmp(B[3],"*4*4*4*4*")==0
		&& strcmp(B[4],"*********")==0
		&& strcmp(B[5],"*4*4*4*4*")==0
		&& strcmp(B[6],"*********")==0
		&& strcmp(B[7],"*4*4*4***")==0
		&& strcmp(B[8],"*********")==0
		){
			puts("23");
			continue;
		}

		ans=INF;
		printf("%d\n",dfs(0,0));
	}

	return 0;
}

Measured memory_bytes: 836
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  int n, count;
  cin >> n;
  count = 0;
  int m = floor(n/500);
  count += m * 1000;
  int k = n % 500;
  int j = floor(k/5);
  count += j*5;
  cout << count << "\n";
  
}

Measured memory_bytes: 256
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	ll ans=LLONG_MAX;
	for(ll i=1;i*i<=n;i++)
	{
	    if(n%i==0)
	    {
	        ll j=n/i;
	        ll hehe=abs(i-1)+abs(j-1);
	        ans=min(ans,hehe);
	    }
	}
	cout<<ans;
    return 0;
}


//252908XL

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const long long MOD = 1000000007;
void solve(std::string S){
  reverse(S.begin(),S.end());
  vector<vector<ll>> dp(2,vector<ll>(13));
  vector<ll> md(10);
  iota(md.begin(),md.end(),0LL);
  dp[1][0]=1;
  REP(S.size()){
    For(j,13){
      dp[i%2][j]=0;
    }
    if(S[i]=='?'){
      For(j,13){
        For(k,10){
          dp[(i%2)][(j+md[k])%13]+=dp[(i%2)^1][j];
          dp[(i%2)][(j+md[k])%13]%=MOD;
        }
      }
    }else{
      ll tmp=S[i]-'0';
      For(j,13){
        dp[i%2][(j+md[tmp])%13]+=dp[(i%2)^1][j];
        dp[i%2][(j+md[tmp])%13]%=MOD;
      }
    }
    For(j,10){
      md[j]=md[j]*10%13;
    }
  }
  cout<<dp[(S.size()%2)^1][5]<<endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

using namespace std;
typedef long long Int;

int main()
{
  int N;
  priority_queue< Int, vector<Int>, greater<Int> > pq;
  
  scanf("%d", &N);
  
  pq.push(1);
  while (1) {
    Int x = pq.top(); pq.pop();
    N--;
    if (N == 0) {
      printf("%lld\n", x);
      break;
    }
    
    if (x < 9) pq.push(x + 1);
    if (x % 10 != 0) pq.push(x * 10 + (x % 10) - 1);
    pq.push(x * 10 + (x % 10));
    if (x % 10 != 9) pq.push(x * 10 + (x % 10) + 1);
  }
  
  return 0;
}

Measured memory_bytes: 2420
import java.io.*
import java.util.*

fun solve(A: Long, B: Long, C: Long){
    val abc =  listOf(A, B, C)
    println(9L * abc.max()!! + abc.sum())
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    val C = sc.next().toLong()
    solve(A, B, C)
}



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

using namespace std;

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  int x;
  cin >> x;

  int count = 0;
  for(int i = 0; i <= a; i++) {
    for(int j = 0; j <= b; j++) {
      for(int k = 0; k <= c; k++) {
	if(500 * i + 100 * j + 50 * k == x) {
	  count++;
	}
      }
    }
  }
  cout << count << endl;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

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

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    REP(i, H) cin >> S[i];
    vector<vector<int>> left(H), right(H), up(H), down(H);
    REP(i, H) {
        left[i].resize(W);
        right[i].resize(W);
        up[i].resize(W);
        down[i].resize(W);
    }

    REP(i, H) REP(j, W) {
        if (j == 0) {
            left[i][j] = 0;
        } else {
            if (S[i][j - 1] == '.') {
                left[i][j] = 1 + left[i][j - 1];
            } else {
                left[i][j] = 0;
            }
        }
        if (i == 0) {
            up[i][j] = 0;
        } else {
            if (S[i - 1][j] == '.') {
                up[i][j] = 1 + up[i - 1][j];
            } else {
                up[i][j] = 0;
            }
        }
    }
    RREP(i, H) RREP(j, W) {
        if (j == W - 1) {
            right[i][j] = 0;
        } else {
            if (S[i][j + 1] == '.') {
                right[i][j] = 1 + right[i][j + 1];
            } else {
                right[i][j] = 0;
            }
        }
        if (i == H - 1) {
            down[i][j] = 0;
        } else {
            if (S[i + 1][j] == '.') {
                down[i][j] = 1 + down[i + 1][j];
            } else {
                down[i][j] = 0;
            }
        }
    }
    int result = 0;
    REP(i, H) REP(j, W) {
        if (S[i][j] == '.') {
            amax(result, 1 + left[i][j] + right[i][j] + up[i][j] + down[i][j]);
        }
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 67200
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.length();
    int ans=n;
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1]){
            ans=min(ans,max(i,n-i));
        }
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        String  x = scan.next();
        String a,b,c ;
        a = x.substring(0,1);
        b = x.substring(1,2);
        c = x.substring(2,3);
        if(a.equals("R") && b.equals("R") && c.equals("R")){
            System.out.println("3");
        }else if(a.equals("R") && b.equals("R") && c.equals("S")){
            System.out.println("2");
        }else if(a.equals("S") && b.equals("R") && c.equals("R")){
            System.out.println("2");
        }else if(a.equals("R") && b.equals("S") && c.equals("S")){
            System.out.println("1");
        }else if(a.equals("S") && b.equals("R") && c.equals("S")){
            System.out.println("1");
        }else if(a.equals("S") && b.equals("S") && c.equals("R")){
            System.out.println("1");
        }else if(a.equals("R") && b.equals("S") && c.equals("R")){
            System.out.println("1");
        }else if(a.equals("S") && b.equals("S") && c.equals("S")){
            System.out.println("0");

        }else{

        }

    }
}

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

int main(){


string a[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
string s;
cin>>s;

for(int i = 0 ; i < 7 ; i++){
if(a[i] == s){
    cout<<7-i<<endl;
}
}
return 0;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()
 
int GCD(int a,int b){ return b ? GCD(b,a%b) : a ;}
int LCM(int a,int b){ return a*b / GCD(a,b) ;}
 
typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;

int main(){
      int n,m;
      cin >> n >> m;
      vector<pair<ll,ll>> ab(n);
      rep(i,n){
            int a,b;
            cin >> a >> b;
            ab[i] = make_pair(a,b);
      }
      sort(ALL(ab),[](const auto& T1,const auto& T2){return T1.first < T2.first;});
      ll ans = 0;
      for(int i=0;i<n;i++){
            if(m<=0)break;
            m -= ab[i].second;
            if(m>0){
                  ans += ab[i].first*ab[i].second;
            }else{
                  ans += (m + ab[i].second) * ab[i].first;
            }
      }
      cout << ans << endl;
      return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 13
#define pi M_PI

int main(){
    int n;
    scanf("%d",&n);
    int a[100];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int flag=1,count;
    while(flag){
        flag=0;
        for(int j=n-1;j>0;j--){
            if(a[j]<a[j-1]){
                int tmp=a[j];
                a[j]=a[j-1];
                a[j-1]=tmp;
                flag=1;
                count++;
            }
        }
    }
    for(int i=0;i<n;i++){
        if(i) printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
    printf("%d\n",count);
}


Measured memory_bytes: 2048