akhauriyash/Code-Regression huggingface dataset:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // int(gcd(a, b))

import functools

def solve():
    n = input()
    nums = map(int, input().split())
    print(functools.reduce(lcm, nums))

solve()

Measured memory_bytes: 8352
N,K = map(int, input().split())
if N % K == 0:
    print(0)
elif N > K:
    hako1 = N%K
    hako2 = abs(hako1-K)
    if hako1 > hako2:
      print(hako2)
    else:
      print(hako1)
else:
    if N >= abs(N-K):
        print(abs(N-K))
    else:
        print(N)

Measured memory_bytes: 9120
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ff first
#define ss second
#define eb emplace_back
#define MP make_pair
#define pb push_back
#define pf push_front
#define ins insert
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define tr(c,it) for(auto it=c.begin();it!=c.end();it++)
#define fr(i,n) for(lli i=0;i<(n);i++)
#define inc(i,a,b) for(lli i=a;i<=b;i++)
#define dec(i,a,b) for(lli i=a;i>=b;i--)
#define fr2(i,n) for(int i=0;i<(n);i++)
#define inc2(i,a,b) for(int i=a;i<=b;i++)
#define dec2(i,a,b) for(int i=a;i>=b;i--)
#define ymin(a,b)  (a=min((a),(b)))
#define ymax(a,b)  (a=max((a),(b)))
#define sz(x) (lli)(x).size()
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr<< *it << " = " << a << endl;
	err(++it, args...);
}

typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<lli,lli> plli;
typedef vector<lli> vlli;
typedef vector<int> vi;
//typedef  vector<vector<lli> >ncr(1001,vector<lli>(1001,0))
typedef vector<plli> vplli;
long long MOD=1000000009;
#define addm(x,y) (x+y>=MOD? (x+y-MOD):(x+y))
lli n,m;
vector<vector<lli>>adj;
vector<lli>vis;
vector<lli>dp;
void dfs(int v)
{
	vis[v]=1;
	for(auto i:adj[v])
	{
		if(!vis[i])
			dfs(i);
		dp[v]=max(dp[v],dp[i]+1);
	}
}
void solve()
{
	cin>>n>>m;
//	lev.resize(n+1);
	adj.resize(n+1);
	vis.assign(n+1,0);
	dp.assign(n+1,0);
	//vector<lli>dis(n+1,0);


	for(int i=0;i<m;i++)
	{
		lli x,y;
		cin>>x>>y;
		adj[x].eb(y);
		//adj[y].eb(x);
	}
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
			dfs(i);
	}
	cout<<*max_element(all(dp))<<endl;

}
int main()
{
	// 	#ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS
	// clock_t start,end;
	// start=clock();
	// int t;
	// cin>>t;
	// for(int i=1;i<=t;i++)
	// {
	// 	cout<<"Case #"<<i<<": ";
	// 	solve();

	// }
	
	
	// end=clock();
	
	// double time_taken=double(end-start)/double(CLOCKS_PER_SEC);
	// cout<<fixed<<setprecision(10)<<time_taken<<" sec"<<endl;
	solve();
}


Measured memory_bytes: 9984
// Problem : A - Pay to Win
// Contest : AtCoder - AtCoder Grand Contest 044
// URL : https://atcoder.jp/contests/agc044/tasks/agc044_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 8e18
#define PI acos(-1.0)
#define int long long

int t;
int n,a,b,c,d;

unordered_map<int,int> dp;

int f(int x){
    if(x <= 0) return 0;
    if(x == 1) return d;
    if(dp.find(x) != dp.end()) return dp[x];
    int ret = inf;
    for(int i=x-1;i<=x+1;i++){
        if(i%2 == 0) ret = min(ret, f(i/2) + d*abs(i-x) + (d>inf/(i-i/2) || (i-i/2)*d > a ? a : (i-i/2)*d));
    }
    for(int i=x-2;i<=x+2;i++){
        if(i%3 == 0) ret = min(ret, f(i/3) + d*abs(i-x) + (d>inf/(i-i/3) || (i-i/3)*d > b ? b : (i-i/3)*d));
    }
    for(int i=x-4;i<=x+4;i++){
        if(i%5 == 0) ret = min(ret, f(i/5) + d*abs(i-x) + (d>inf/(i-i/5) || (i-i/5)*d > c ? c : (i-i/5)*d));
    }
    dp[x] = ret;
    return ret;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>t;
    while(t--){
		cin>>n>>a>>b>>c>>d;
		dp.clear();
		//for(int i=1;i<=11;i++) cout<<f(i)<<" ";
		cout<<f(n)<<endl;
    }
    return 0;
}


Measured memory_bytes: 4124
import numpy as np
n,m,c=map(int,input().split())
b_np = np.array(list(map(int,input().split())))
ans=0
for i in range(n):
	a_np = np.array(list(map(int,input().split())))
	if sum(b_np * a_np)+c >0:
		ans +=1
print(ans) 


Measured memory_bytes: 12744
import bisect
from operator import itemgetter
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()

LR = [IL() for i in range(M)]

l = 0
r = MAX_INT
for L,R in LR:
    if l < L:
        l = L
    if r > R:
        r = R
print(max(0,r-l+1))

Measured memory_bytes: 36372
N,K,Q = map(int,input().split())
A = [0]*Q
for i in range(Q): A[i]=int(input())-1
P = [K-Q]*N
for i in range(Q): P[A[i]]+=1
for i in range(N):
  if(P[i]>0): print("Yes")
  else: print("No")
  

Measured memory_bytes: 10412
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<string.h>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 1000000001
#define EPS 1.0e-6
#define MAX_V 300

using namespace std;

typedef long long ll;


int n;

int akax[150];
int akay[150];
int aox[150];
int aoy[150];

//グラフをつくる
/*loop
s-t pathをさがす　なければ終了
あったらそれに沿って流す
グラフを更新
*/

struct edge {
	int to, cap, rev;
};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap)
{
	G[from].push_back(edge{ to,cap,(int)G[to].size() });
	G[to].push_back(edge{ from, 0, (int)G[from].size() - 1 });
}

int dfs(int v, int t, int f)
{
	if (v == t)return f;
	used[v] = true;
	for (int i = 0; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t)
{
	int flow = 0;
	for (;;) {
		for (int i = 0; i < MAX_V; i++) {
			used[i] = 0;
		}
		//memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0)return flow;
		flow += f;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> akax[i] >> akay[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> aox[i] >> aoy[i];
	}
	
	for (int i = 0; i < n; i++) {
		add_edge(2 * n, i, 1);
	}

	for (int i = 0; i < n; i++) {
		add_edge(n + i, 2 * n + 1, 1);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (akax[i] < aox[j] && akay[i] < aoy[j]) {
				add_edge(i, n + j, 1);
			}
		}
	}

	cout << max_flow(2 * n, 2 * n + 1) << endl;



	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    ll MOD = 998244353;
    int N;
    cin >> N;
    vector<ll> D(N);
    map<ll, ll> ma;
    rep(i, N) {
        cin >> D[i];
        ma[D[i]]++;
    }

    if (D[0] != 0) {
        cout << 0 << endl;
        return 0;
    }
    if (ma[0] > 1){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    for (auto m : ma) {
        if (m.first == 0)
            continue;
        else {
            ans *= modpow(ma[m.first - 1], m.second, MOD);
            ans %= MOD;
        }
    }

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

Measured memory_bytes: 10260
n,m=map(int,input().split())
inf=10**12

ab=[]
cs=[]
for i in range(m):
    a,b=map(int,input().split())
    c=tuple(map(int,input().split()))
    ab.append((a,b))
    cs.append(c)
dp=[inf]*(2**n)
dp[0]=0
for i in range(m):
    x=0
    for h in cs[i]:
        x+=2**(h-1)
    for j in range(2**n):
        dp[j|x]=min(dp[j|x],dp[j]+ab[i][0])
print(dp[-1] if dp[-1]!=inf else -1)

Measured memory_bytes: 44904
while 1:
	n,m=map(int,input().split())
	if n==n==0: break
	li=[]
	for i in range(n):
		li.append(int(input()))
	s_li=[li[0]]
	for i in range(1,n):
		s_li.append(s_li[-1]+li[i])
	c_li=[s_li[m-1]]
	for i in range(n-m):
		c_li.append(s_li[i+m]-s_li[i])
	print(max(c_li))


Measured memory_bytes: 15532
n = int(input())
for i in range(n):
    numlst = list(input())
    numlst.sort(reverse= True)
    maxnum = [i for i in numlst]
    numlst.sort()
    minnum = [i for i in numlst]

    maxnum = int(''.join(maxnum))
    minnum = int(''.join(minnum))
    print(maxnum - minnum)


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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





int main()
{
//    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("input.txt","w",stdout);

    int i,n;
    cin >> n;
    int a[n+3];
    cin >> a[1];
    int lcm=a[1];
    for(i=2; i<=n; i++)
    {
        cin >> a[i];
        lcm=(lcm*a[i])/__gcd(lcm,a[i]);
    }
    double sum=0;
    for(i=1; i<=n; i++)
    {
        sum+=(lcm/a[i]);
    }
    cout << lcm/sum;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int W,H,x,y;
  cin >>W>>H>>x>>y;
  double menseki=(double)W*(double)H*0.5;
  if(2*x==W&&2*y==H){
    cout<<fixed<<setprecision(10)<<menseki<<" "<<1<<endl;
  }else{
    cout<<fixed<<setprecision(10)<<menseki<<" "<<0<<endl;
  }
  return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    string s;
    cin >> s;
    if(s=="ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  
  long long ans=1;
  long long  K=(pow(10,9)+7);
 
  for(int i=1;i<=N;i++){
    ans=ans*i;
   
      ans=ans%K;
    
  }
  cout<<ans<<endl;
}


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

using namespace std;

int main()
{
  int n;
  cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  while(n--)
  {
    string s;
    cin >> s;
    if(s == "AC")
      ac++;
    else if(s == "WA")
      wa++;
    else if(s == "TLE")
      tle++;
    else
      re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

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

void Main() {
    u32 N, K;
    cin >> N >> K;
    Vec<u64> H(N);
    for (u32 i = 0; i < N; i++) cin >> H[i];
    sort(ALL(H));
    if (N <= K) {
        cout << 0 << endl;
        return;
    }
    u64 c = N - K;
    u64 sum = 0;
    for (u32 i = 0; i < c; i++) {
        sum += H[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <functional>
#include <map>
#include <math.h>
#include <list>

using namespace std;

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

	int count[200005] = {};
	int n; cin >> n;
	int m;
	for (int i = 1; i < n; i++) {
		cin >> m;
		count[m]++;

	}

	for (int i = 1; i <= n; i++) {
		cout << count[i] << endl;

	}





	return 0;
}


Measured memory_bytes: 4388
fun main(args: Array<String>) {
    val n = readLine()!!.toCharArray()
    when ((n.last() - '0').toInt()) {
        2, 4, 5, 7, 9 -> println("hon")
        0, 1, 6, 8 -> println("pon")
        3 -> println("bon")
    }
}

Measured memory_bytes: 38344
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
	string s; cin>>s;
	if(s=="ABC") cout<<"ARC";
	else cout<<"ABC";
}


Measured memory_bytes: 3524
S = input()
b = list(S)
a = b[0::2]
c = b[1::2]
d = len(a)
e = len(c)
cnt = 0
f = a.count('R')
g = a.count('U')
h = a.count('D')
i = f + g + h



j = c.count('L')
k = c.count('U')
l = c.count('D')
m = j + k + l



if i == d and m == e:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if true
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
$ss = inputs[0][0]
if $debugFlag
  p $ss
end

ones = 0
$ss.length.times do |i|
  ones += 1 if $ss[i..i] == "1"
end

puts 2*[ones, $ss.length - ones].min


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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> x(n), y(n), a(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> a[i];
  }

  int s[110][110] = {0};

  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      for (int j = 0; j <= x[i]; j++) {
        for (int k = 0; k <= h; k++) {
          s[j][k] = 1;
        }
      }
    }
    else if (a[i] == 2) {
      for (int j = x[i] + 1; j <= w; j++) {
        for (int k = 0; k <= h; k++) {
          s[j][k] = 1;
        }
      }
    }
    else if (a[i] == 3) {
      for (int j = 0; j <= w; j++) {
        for (int k = 0; k <= y[i]; k++) {
          s[j][k] = 1;
        }
      }
    }
    else if (a[i] == 4) {
      for (int j = 0; j <= w; j++) {
        for (int k = y[i] + 1; k <= h; k++) {
          s[j][k] = 1;
        }
      }
    }
  }

  int ans = 0;
  for (int i = 1; i <= w; i++) {
    for (int j = 1; j <= h; j++) {
      if (s[i][j] == 0) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;
using Graph = vector<vector<int>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

vector<bool> seen;

void dfs(const Graph& G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int abs_B(long long num, long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

bool permutation(vector<int>& vec, vector<int>& P) {
    bool ok = true;
    for (int i = 0; i < vec.size(); i++) {
        if (vec.at(i) != P.at(i)) {
            ok = false;
        }
    }
    return ok;
}

const long long MOD = 1000000007;
const int INF = 1001001001;

int main() {
    int X;
    cin >> X;
    int count = 0;
    int ans = 1;
    for (int i = 1; i < X; i++) {
        for (int j = 2; j < X; j++) {
            int zyou = pow(i, j);
            if (zyou <= X) {
                count = zyou;
            }
            else {
                break;
            }
            ans = max(ans, count);
            count = 0;
        }
    }

    cout << ans << endl;
        
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve2(int n) {
        int ret = 0;
        int l = 1, r = 1;
        // [l,r)

        int val = 0;
        while (l <= 1000) {
            if (l == r) {
                val += r++;
                continue;
            }
            if (val < n) {
                val += r++;
                continue;
            }
            if (val == n) {
                if (r - l > 1)ret++;
                val -= l++;
                continue;
            }
            if (val > n) {
                val -= l++;
                continue;
            }
        }

        cout << ret << endl;

    }

    void solve() {
        input();
        while (true) {
            int n;
            cin >> n;
            if (n != 0) solve2(n);
            else break;
        }


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}



Measured memory_bytes: 3080
x, y, a, b, c = map(int, input().split())
p_list = sorted(list(map(int, input().split())), reverse=True)
q_list = sorted(list(map(int, input().split())), reverse=True)
r_list = sorted(list(map(int, input().split())), reverse=True)

p_count = 0
q_count = 0
r_count = 0
total = 0
for i in range(0, x + y):
  score_max = 0
  flag = 0
  if p_count < x:
    score = p_list[p_count]
    if score_max < score:
      score_max = score
      flag = 1
  if q_count < y:
    score = q_list[q_count]
    if score_max < score:
      score_max = score
      flag = 2
  if r_count < c:
    score = r_list[r_count]
    if score_max < score:
      score_max = score
      flag = 3
  if flag == 1:
    p_count += 1
  elif flag == 2:
    q_count += 1
  else:
    r_count += 1
  total += score_max
  
print(total)

    

Measured memory_bytes: 22720
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>

long long f(long long n, int k)
{
	if (k == 1)
		return n;
	long long temp = f(n, k / 2);
	temp = temp * temp % 1000000007;
	if(k % 2)
		temp = temp * n % 1000000007;
	return temp;
}

int main(void)
{
	int n;
	long long temp;
	scanf("%d", &n);
	temp = f(10, n);
	temp -= f(9, n) * 2;
	temp += f(8, n);
	temp = (temp % 1000000007 + 1000000007) % 1000000007;
	printf("%lld\n", temp);
	return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
ll A[100100];
ll f(ll l,ll x){
	return ((l-1ll)/x+1ll)*x;
}
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%lld",&A[i]);
	}
	ll l = 2, r = 2;
	for(int i=N-1;i>=0;i--){
		l = f(l,A[i]);
		if(l>r){
			cout << -1 << endl;
			return 0;
		}
		r = f(r+1ll,A[i])-1ll;
	}
	cout << l << ' ' << r << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

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

const int INF = 1001001001;
const double EPS = 1e-10;

struct Edge {
	int dst, cost;
	Edge(int d, int c) : dst(d), cost(c) {}
};

struct Data {
	int pos, stat, cost;
	Data(int p, int s, int c) : pos(p), stat(s), cost(c) {}
	bool operator< (const Data& d)const {
		return cost > d.cost;
	}
};

int main()
{
	int n, m;
	while(scanf("%d%d", &n, &m), n){
		vector<Edge> G[100];
		rep(i, m){
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			--a;
			--b;
			G[a].push_back(Edge(b, c));
			G[b].push_back(Edge(a, c));
		}
		
		priority_queue<Data> Q;
		Q.push(Data(0, 0, 0));
		bool visited[100][3] = {{false}};
		int ans;
		
		while(!Q.empty()){
			Data d = Q.top();
			Q.pop();
			if(visited[d.pos][d.stat])
				continue;
			visited[d.pos][d.stat] = true;
			if(d.pos == n-1 && d.stat != 1){
				ans = d.cost;
				break;
			}
			
			rep(i, G[d.pos].size()){
				Edge e = G[d.pos][i];
				if(d.stat != 1)
					Q.push(Data(e.dst, d.stat, d.cost+e.cost));
				if(d.stat < 2)
					Q.push(Data(e.dst, d.stat+1, d.cost));
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1052
# ABC093C - Same Integers
a, b, c = sorted(list(map(int, input().rstrip().split())), reverse=True)
cnt = 0
while (a + b + c + cnt * 2) % 3 != 0 or (b + c + cnt * 2) / 2 < a:
    cnt += 1
print(cnt)

Measured memory_bytes: 2940
#include <stdio.h>
     
int main(){
int N,K,i;
int A[100001];
int ans = 0;
scanf("%d %d",&N,&K);
for(i=0;i<N;i++){
    scanf("%d",&A[i]);
}
ans++;
N = N-K;
if(N > 0) ans += N / (K-1);
if(N % (K-1) != 0) ans++;
printf("%d\n",ans);
}

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

double dp[601], dp2[601];

int main() {
  int N, M;
  cin >> N >> M;
  vector< vector<int> > to(N), ot(N);	// 接続先、接続元
  vector< int > o(N,0);	// 出自数
  vector< double > p(N,0);	// 到着確率

  REP(i,M) {
    int src, dst;
    cin >> src >> dst;
    src--; dst--;
    to[src].push_back(dst);
    ot[dst].push_back(src);
    o[src]++;
  }

  // 初期状態での期待値生成
  for (int i=N-2; i>=0; --i ) {
    for ( auto r: to[i] ) {
      dp[i] += dp[r];
    }
    dp[i] /= o[i];
    dp[i] += 1;
  }

  // 初期状態での到着確率生成
  p[0] = 1;
  for( int i=0; i<N; i++ ) {
    for ( auto r: to[i] ) {
      p[r] += p[i] / o[i];
    }
  }

//  REP(i,N)
//    cout << i << " : " << p[i] << " " << dp[i] << endl;

  double E = dp[0];
  REP(i,N) dp2[i] = dp[i];

  // 前から順に一番期待値に影響が大きい辺を削除して期待値再計算する
  for (int i=0; i<N-1; ++i ) {
    if (o[i] == 1) continue;	// 出自数が1なら削除できない
    vector< double > v;
    for ( auto r: to[i] ) v.push_back(dp[r]);
    sort(v.begin(), v.end());
    v.pop_back();		// 一番大きい期待値を除外
    // 消した辺の始点の期待値再計算
    dp2[i] = 0;
    for( auto x: v ) dp2[i] += x;
    dp2[i] /= (o[i]-1);
    dp2[i] += 1;
    // 現在位置より手前の期待値再計算
    for (int j=i-1; j>=0; --j) {
      dp2[j] = 0;
      for ( auto r: to[j] ) {
        dp2[j] += dp2[r];
      }
      dp2[j] /= o[j];
      dp2[j] += 1;
    }
    E = min( E, dp2[0] );
    
    REP(k,N) dp2[k] = dp[k];
  }
  cout << fixed << setprecision(10) << E << endl;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
int main(){
 vector<int>N(3);
 for(int i=0;i<3;i++){
 cin>>N.at(i);
 }
  sort(N.begin(),N.end());
  if( (N.at(0)== N.at(1) )){
  	if(N.at(2)==7){
    cout<<"YES";
    }
  }
  else{
  cout<<"NO";
  }
}

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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

template <typename T> struct Segtree {
    Segtree(int n):base(1){
        while (base < n) base *= 2;
        nodes.resize(base*2, T::empty());
    }
    void setLeaf(int i, T x) {
        nodes[base+i] = x;
        for (auto v=(base+i)/2; v>0; v/=2)
            nodes[v] = T::merge(nodes[v*2], nodes[v*2+1]);
    }
    void applyLeaf(int i, const T& x) {
        setLeaf(i, T::merge(nodes[base+i], x));
    }
    T readRange(int left, int right) const { return implRR(left, right, 0, base, 1); }
    T implRR(int left, int right, int i, int e, int v) const {
        if (left >= e or right <= i) return T::empty();
        if (left <= i and right >= e) return nodes[v];
        return T::merge(implRR(left, right, i, (i+e)/2, v*2), implRR(left, right, (i+e)/2, e, v*2+1));
    }
    int base;
    vector<T> nodes;
};

template <typename T> struct Max {
    Max(T x):x(x){}
    operator const T&() const { return x; }
    T x;
    static Max merge(const Max& a, const Max& b) { return max<T>(a, b); }
    static Max empty() { return 0; } 
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    auto n = load<int>();
    auto height = loadMany<int>(n);
    auto beauty = loadMany<int>(n);
    auto segtree = Segtree<Max<long long>>(n+1);
    for (auto i=0; i<n; ++i) {
        auto prefBeauty = segtree.readRange(0, height[i]);
        auto curr = prefBeauty + beauty[i];
        segtree.applyLeaf(height[i], curr);
    }
    cout << segtree.readRange(0, n+1).x << '\n';
}


Measured memory_bytes: 5888
n = gets.chomp.to_i
p_ = gets.chomp.split(" ").map(&:to_i)
a_ = (1..n).map{|x| x * n}
b_ = a_.reverse
d = 1
p_.each do |i|
  a_[i-1] += d
  d += 1
end
puts a_.join(" ")
puts b_.join(" ")


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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int N = 8;
int n;
int r[N], c[N], rdd[N*2-1], ldd[N*2-1];
int z[N][N];

void print_board() {
  int i, j;
  for (i=0; i<N; i++)
    for (j=0; j<N; j++) {
      if (z[i][j] && r[i]!=j) return; 
    }

  for (i=0; i<N; i++) {
    for (j=0; j<N; j++)
      printf("%c", (r[i]==j) ? 'Q' : '.');
    printf("\n");
  }
}

void rec(int i) {
  int j;
  if (i==N) {
    print_board();
    return;
  }

  for (j=0; j<N; j++) {
    if (c[j] || rdd[N-1+i-j] || ldd[i+j]) continue;
    r[i] = j;
    c[j] = rdd[N-1+i-j] = ldd[i+j] = 1;
    rec(i+1);
    r[i] = -1;
    c[j] = rdd[N-1+i-j] = ldd[i+j] = 0;
  }
}

int main() {
  int i, j;
  memset(r, 0xff, sizeof(r));
  memset(c, 0, sizeof(c));
  memset(rdd, 0, sizeof(rdd));
  memset(ldd, 0, sizeof(ldd));
  memset(z, 0, sizeof(z));
  scanf("%d ", &n);
  for (i=0; i<n; i++)
    for (j=0; j<n; j++) {
      int x, y;
      scanf("%d%d ", &y, &x);
      z[y][x] = 1; 
    }
  
  rec(0); 

	return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

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

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    int N, M;
    cin >> N >> M;
    PRINT(N * (N - 1) / 2 + (M * (M - 1) / 2));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int a,b,c;



int main(){
    cin >> a>>b>>c;
    int round = a+b;
    int cnt=0;
    while(1){
        if((60*cnt+60)%(a+b)==0){
            if(c%(a+b)<=a)break;
            cnt = -1;
            break;   
        }
        if(c%(a+b)<=a)break;
        c+=60;
        cnt++;
    }
    if(cnt==-1){
        cout << cnt << endl;
    }else{
        cout << c << endl;
    }


}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define INF (ll)(1e18)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
#define mp make_pair
//manip
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl
#define ina(a, n) rep(i, n) cin >> a[i];
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always

int main() {
    int n, a, b; cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main(int argc, char **argv)
{
    int K;
    std::string S;
    std::cin >> K >> S;
    if(S.size() <= K){
        std::cout << S << std::endl;
    }else{
        std::string s;
        s = S.substr(0, K);
        std::cout << s << "..." << std::endl;
    }
}


Measured memory_bytes: 3628
#include<iostream>

using namespace std;

static const int MAX = 105;
int N;
int A[MAX];

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

	int a, minsum = 1 << 29,sum = 0;
	for(int i = -100; i <= 100; i++){
		for(int j = 0; j < N; j++){
			sum += (i - A[j]) * (i - A[j]);
		}
		if(sum < minsum) minsum = sum;
		sum = 0;
	}
	cout << minsum << endl;

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

char grid[16][64];
bool used[16][64][4][16][64][4];
vector<string> output{
    "He can accomplish his mission.",
    "He cannot return to the kitchen.",
    "He cannot bring tea to his master.",
};

void dfs(int fy, int fx, int fd, int ry, int rx, int rd){
    if(used[fy][fx][fd][ry][rx][rd]) return;
    used[fy][fx][fd][ry][rx][rd] = true;
    for(int diff=1; diff<=3; diff+=2){
        int nfy = fy;
        int nfx = fx;
        int nfd = (fd +diff) %4;
        while(grid[nfy+dy[nfd]][nfx+dx[nfd]] != '#'){
            nfy += dy[nfd];
            nfx += dx[nfd];
        }
        if(ry == 0){
            dfs(nfy, nfx, nfd, 0, 0, 0);
            continue;
        }
        int nry = ry;
        int nrx = rx;
        int nrd = (rd +diff) %4;
        while(grid[nry][nrx] != '#'){
            if(grid[nry+dy[nrd]][nrx+dx[nrd]] == '#'){
                dfs(nfy, nfx, nfd, nry, nrx, nrd);
            }
            nry -= dy[rd];
            nrx -= dx[rd];
        }
    }
}

int main(){
    while(1){
        int w,h;
        cin >> w >> h;
        if(w == 0) break;

        memset(used, 0, sizeof(used));
        int sy,sx,gy,gx;
        sy = sx = gy = gx = -1;
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                cin >> grid[i][j];
                if(grid[i][j] == 'K'){
                    sy = i;
                    sx = j;
                }
                if(grid[i][j] == 'M'){
                    gy = i;
                    gx = j;
                }
            }
        }

        int dir_go=-1, dir_ret=-1;
        for(int d=0; d<4; d++){
            if(grid[sy+dy[d]][sx+dx[d]] != '#'){
                dir_go = d;
            }
            if(grid[gy+dy[d]][gx+dx[d]] != '#'){
                dir_ret = d;
            }
        }
        int fsy = sy;
        int fsx = sx;
        while(grid[fsy+dy[dir_go]][fsx+dx[dir_go]] != '#'){
            fsy += dy[dir_go];
            fsx += dx[dir_go];
        }
        int fgy = gy;
        int fgx = gx;
        while(grid[fgy+dy[dir_ret]][fgx+dx[dir_ret]] != '#'){
            fgy += dy[dir_ret];
            fgx += dx[dir_ret];
        }
        
        dfs(fsy, fsx, dir_go, sy, sx, (dir_go+1)%4);
        dfs(fsy, fsx, dir_go, sy, sx, (dir_go+2)%4);
        dfs(fsy, fsx, dir_go, sy, sx, (dir_go+3)%4);
        dfs(fsy, fsx, dir_go, 0, 0, 0);
        bool ok = false;
        for(int i=0; i<4; i++){
            if(used[gy][gx][i][fgy][fgx][dir_ret]){
                ok = true;
            }
        }
        if(ok){
            cout << output[0] << endl;
            continue;
        }
        if(used[gy][gx][(dir_ret+2)%4][0][0][0]){
            cout << output[1] << endl;
        }else{
            cout << output[2] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 20092
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef pair<int, int> pi;
typedef vector<pair<int,int> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N],ARR[N]  ;
bool visited[N]={};
int cnt[N]={};
bool f;
int main()
{

   ll n,count(0),ans(0);
   cin>>n;
   rep(i,n&&cin>>arr[i]);
   for(ll i=1;i<n;i++)
    {
        count++;
       if(arr[i-1]<arr[i])
       {
           count=0;
       }
       ans=max(ans,count);
   }
cout<<ans;
go;
}


Measured memory_bytes: 1024
N = int(input())
S = input()
St = []
for i in range(N):
  St += [ord(S[i])-97]
  
St.reverse()
ans = 0
#初期化
dp=[[0 for i in range(N+1)] for j in range(N+1)]

#DP:dp[i][j] Sのi文字目以降とj文字目以降の最大マッチング
for i in range(N):
  for j in range(i):
    if (St[i] == St[j]): 
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
      ans = max(ans, min(dp[i+1][j+1], i-j))
    if i-j <= dp[i+1][j+1]:
      break
      
print(ans)

Measured memory_bytes: 247944
K = int(input())

def calc_next(ar):
  res = []
  for val in ar:
    for j in range(-1, 2):
      add = (val % 10) + j
      if add >= 0 and add <= 9:
        res.append(val*10+add)
  return res

cur = []
all_ = []
# 1桁の場合
for v in range(1, 10):
  cur.append(v)
  all_.append(v)
  
# 10桁まで
for d in range(1, 10):
  # 次の桁を列挙
  cur = calc_next(cur)
  
  # allに格納
  for val in cur:
    all_.append(val)

#K番目
print(all_[K-1])

Measured memory_bytes: 13048
d=int(input())
c=list(map(int,input().split()))
c_days=[0]*26
for i in range(d):
    s=list(map(int,input().split()))
    #最大満足度を選択
    c_low=[c[x]*(i+1-c_days[x]) for x in range(26)]
    c_max=[s[x]-c_low[x] for x in range(26)]
    n=c_max.index(max(c_max))
    c_days[n]=i+1
    print(n+1)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };
int N;
vv<bool> emp;
vv<int> dist;
deque<pair<int, int>> dq;

void bfs() {
    while (!dq.empty()) {
        auto v = dq.front();
        dq.pop_front();
        for (int d = 0; d < 4; ++d) {
            int nx = v.first + dx[d], ny = v.second + dy[d];
            if (nx < 0 || nx >= N + 2 || ny < 0 || ny >= N + 2) continue;
            if (emp[nx][ny] && dist[v.first][v.second] < dist[nx][ny]) {
                dist[nx][ny] = dist[v.first][v.second];
                dq.emplace_front(nx, ny);
            }
            else if (!emp[nx][ny] && dist[v.first][v.second] + 1 < dist[nx][ny]) {
                dist[nx][ny] = dist[v.first][v.second] + 1;
                dq.emplace_back(nx, ny);
            }
        }
    }
}

int main() {
    cin >> N;
    vector<int> P(N * N);
    rep(i, N * N) cin >> P[i], P[i]--;

    emp = vvec(N + 2, N + 2, false);
    dist = vvec(N + 2, N + 2, INF);
    rep(x, N + 2) rep(y, N + 2) {
        if (x != 0 && x != N + 1 && y != 0 && y != N + 1) continue;
        emp[x][y] = true;
        dist[x][y] = 0;
        dq.emplace_back(x, y);
    }
    bfs();

    ll ans = 0;
    rep(i, N * N) {
        int x = P[i] / N + 1, y = P[i] % N + 1;
        ans += dist[x][y] - 1;
        emp[x][y] = true;
        rep(d, 4) dist[x][y] = min(dist[x][y], dist[x + dx[d]][y + dy[d]]);
        dq.emplace_back(x, y);
        bfs();
    }

    write(ans);
}


Measured memory_bytes: 6248
import java.io.*;
import java.util.*;

public class Main {

    static int mod = (int) (1e9 + 7);

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int m = in.nextInt();
        char[][] c = new char[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.next();
            for (int j = 0; j < m; j++) {
                c[i][j] = s.charAt(j);
            }
        }

        long dp[][] = new long[n][m];
        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                long x = ((i - 1) >= 0 && c[i - 1][j] == '.') ? dp[i - 1][j] : 0;
                long y = ((j - 1) >= 0 && c[i][j - 1] == '.') ? dp[i][j - 1] : 0;
                dp[i][j] = (x + y + dp[i][j]) % mod;
            }
        }
        out.println(dp[n - 1][m - 1]);
        out.close();
    }

    private static void dfs(Vertex v, Set<Vertex> visited, Stack<Vertex> st) {
        visited.add(v);
        for (Vertex n : v.adj) {
            if (!visited.contains(n))
                dfs(n, visited, st);
        }
        st.add(v);
    }

    static class Vertex {
        int i;

        public Vertex(int i) {
            this.i = i;
        }

        List<Vertex> adj = new ArrayList<>();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


Measured memory_bytes: 37484
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

    if (s[0] == 'R') {
        if (s[1] == 'R') {
            if (s[2] == 'R') {
                cout << 3 << endl;
                return 0;
            } else {
                cout << 2 << endl;
                return 0;
            }
        } else {
            cout << 1 << endl;
            return 0;
        }
    }

    if (s[1] == 'R') {
        if (s[2] == 'R') {
            cout << 2 << endl;
            return 0;
        } else {
            cout << 1 << endl;
            return 0;
        }
    }

    if (s[2] == 'R') {
        cout << 1 << endl;
        return 0;
    }

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

Measured memory_bytes: 3164
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD=10**9+7

N,M=rl()
L=[0]*M
R=[0]*M
for i in range(M):
    L[i],R[i] = rl()

gate = [0]*(N+2)
for l,r in zip(L,R):
    gate[l] += 1
    gate[r+1] -= 1
for i in range(1,N+1):
    gate[i] += gate[i-1]

print(gate.count(M))

Measured memory_bytes: 14964