akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int H, W, K, ans;
char c[6][6];

int solve(int t1, int t2) {
	int ret = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if ((t1 / (1 << i)) % 2 == 1 && (t2 / (1 << j)) % 2 == 1) {
				if (c[i][j] == '#') ret++;
			}
		}
	}
	return ret;
}

int main() {
	cin >> H >> W >> K;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) cin >> c[i][j];
	}
	for (int i = 0; i < (1 << H); i++) {
		for (int j = 0; j < (1 << W); j++) {
			if (solve(i, j) == K) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define FAST_IO   ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Relocate freopen("./in.txt","r",stdin);freopen("./out.txt","w",stdout)
#define up(mi,a,b) for(mi=a;mi<=b;++mi)
#define down(mi,b,a) for(mi=b;mi>=a;--mi)
#define mfill(a,v) memset(a,v,sizeof(a))
#define INF 0x3f3f3f3f
#define MAX 5000005
#define v_n 5005
#define LL long long
#define e_n 5000005
#define MOD 1000000007
#define eps 0.000000001
#define Blen 32
using namespace std;
int N;
struct p {
	int par, sz;
};
p ufs[MAX];
vector<int> g[MAX];
int col[MAX];
void Init()
{
	for (int i = 1; i <= N; i++)
	{
		ufs[i].par = i;
		ufs[i].sz = 1;
	}
}
int Find(int i)
{
	if (ufs[i].par == i)
		return i;
	return ufs[i].par = Find(ufs[i].par);
}
bool Union(int i, int j)
{
	int si = Find(i), sj = Find(j);
	if (si == sj)
	{
		return 0;
	}
	else if (ufs[si].sz < ufs[sj].sz)
	{
		ufs[si].par = sj;
		ufs[sj].sz += ufs[si].sz;
	}
	else
	{
		ufs[sj].par = si;
		ufs[si].sz += ufs[sj].sz;
	}
	return 1;
}
struct e {
	int s, t;
	LL w;
};
vector<e> hh;
void dfs(int r)
{
	for (auto one : g[r])
	{
		if (col[one] == 0)
		{
			col[one] = 3 - col[r];
			dfs(one);
		}
	}
}
int main(void)
{
	int i, j, k;
	FAST_IO;
	//Relocate;
	LL w;
	cin >> N;
	Init();
	up(i, 2, N)
	{
		cin >> j >> k >> w;
		if (!(w & 1))
		{
			Union(j, k);
		}
		else
		{
			hh.push_back(e{ j,k,w });
		}
	}
	if (hh.empty())
	{
		up(i, 1, N)
		{
			cout << 0 << endl;
		}
		return 0;

	}
	int r;
	for (auto one : hh)
	{
		int rs = Find(one.s);
		int rt = Find(one.t);
		r = rs;
		g[rs].push_back(rt);
		g[rt].push_back(rs);
	}
	col[r] = 1;
	dfs(r);
	up(i, 1, N)
	{
		cout << col[Find(i)] - 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 126192
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stdio.h>
#include<cmath>
#include<string.h>

using namespace std;

int main(void)
{
	int n,ans=0;
	cin >> n;
	vector<int > a(n);
	int i;
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (i = 0; i < n - 1; i++)
	{
		if (a[i] == a[i + 1])
		{
			a[i + 1] = 100000;
			ans++;
		}
	}
	cout << ans << endl;

		return 0;
}

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

using namespace std;

int m(int a, int b, int n) {

	int c;

	c = min(abs(1 - a), min(abs(n - a), min(abs(1 - b), abs(n - b))));
	return c % 3;
}


int main() {

	int n, k;
	pair<int, int> h[1000];

	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		cin >> h[i].first >> h[i].second;
		cout << m(h[i].first, h[i].second, n) + 1 << endl;
	}

	return 0;
}





Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 1LL << 20;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    ll X;
    cin >> X;

    ll v = 100;
    int y = 0;
    while(v < X){
        v += v / 100;
        y++;
    }

    cout << y << endl; 
}


Measured memory_bytes: 3652
<>;@D=(1)x2e6;$s=.5;*y=-($%^=$_),$%?$P[$%]+=($D[$%]+=$P[$%]*(-$y+($y=$0)))%=$=:($0++,$s*=2)%=$==1e9+7for split$",<>;$s+=$_ for@P;print$%?$D[$%]:$s%$=

Measured memory_bytes: 270208
import java.util.Arrays;
import java.util.Scanner;
public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        int n = nextInt();
        int n1,n2,n3;
        n1 = n%10;
        n2 = n%100-n1;
        n3 = n%1000-n2-n1;
        yesNo(n1==7||n2==70||n3==700);
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}

Measured memory_bytes: 35684
from itertools import permutations

n = int(input())
li = []
for i in range(n):
  x, y = map(int,input().split())
  li.append((x, y))

p_li = list(permutations(li))

dist = 0

for p in p_li:
  for j in range(n-1):
    dist += ((p[j][0] - p[j+1][0]) ** 2 + (p[j][1] - p[j+1][1]) ** 2) ** 0.5
  
result = dist/(len(p_li))
print(result)

Measured memory_bytes: 8052
using System;
using System.Collections.Generic;
using System.Linq;

namespace AizuOnline_DataStructure
{
    public class Node
    {
        public int id;
        public bool isPassed = false;
        public int groupId;
        public int cost = int.MaxValue;
    }

    internal class Program
    {
        private static void Main(string[] args)
        {
            var nodes = new List<Node>();
            var n = Convert.ToInt32(Console.ReadLine());
            var p = Console.ReadLine().Split(' ');

            for (int i = 0; i < n; i++)
            {
                var node = new Node()
                {
                    id = i + 1,
                    cost = Convert.ToInt32(p[i])
                };
                nodes.Add(node);
            }

            foreach (var node in nodes)
            {
                Console.Write("node " + node.id + ": key = " + node.cost + ", ");
                var maxIndex = nodes.Count();

                if (node.id != 1)
                {
                    Console.Write("parent key = " + p[node.id / 2 - 1] + ", ");
                }

                if (node.id * 2 - 1 < maxIndex)
                {
                    Console.Write("left key = " + p[node.id * 2 - 1] + ", ");
                }

                if (node.id * 2 < maxIndex)
                {
                    Console.Write("right key = " + p[node.id * 2] + ", ");
                }

                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }
}

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

int main(){
    int N, M, X;
    cin >> N >> M >> X;

    vector<int> C(N);
    vector< vector<int> > A(N, vector<int>(M));
    int i,j;

    for( i = 0; i < N; i++ ){
        cin >> C[i];
        for( j = 0; j < M; j++ ){
            cin >> A[i][j];
        }
    }

    int ibit;
    vector<int>  skill(M);
    int cost;
    int flag;
    int ans = -1;
    for( ibit = 0; ibit < (1<<N); ibit++ ){
        // initialize
        cost = 0;
        flag = 0;
        for( j = 0; j < M; j++ ) skill[j] = 0;

        for( i = 0; i < N; i++ ){
            if( ibit & 1<<i ){
                cost += C[i];
                for( j = 0; j < M; j++ ) skill[j] += A[i][j];
            }
        }
        // check
        for( j = 0; j < M; j++ ){
            if( skill[j] < X ) flag = 1;
        }
        if( flag != 1 ){
            if( ans == -1 || ans > cost ) ans = cost;
        }
    }

    cout << ans << endl;


}


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

using namespace std;
#define IOS cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;

#define pb push_back
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

const int mod = 1e9+7;

ll pwr(ll a, ll b){
    a %= mod;
    ll ans = 1;
        while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    
    return ans;
}

const int nax = 1e5 + 10;
ll factorial[nax];

void f1(){
    factorial[0] = 1;
    for(int i = 1; i <= nax; i++){
        factorial[i] = factorial[i-1] * i % mod;
    }
}


ll inverse(ll a){
    ll g = __gcd(a, (ll)mod);
    if(g == 1){
        return pwr(a, (ll)mod-2ll);
    }

}


ll binom(int n, int k){
    return factorial[n] * inverse(factorial[k]) % mod * inverse(factorial[n-k]) % mod;
}


int main(){
    IOS

    f1();

    int  n, k; cin>>n>>k;

    vector<ll> a(n);
    for(ll & x : a)cin>>x;

    vector<ll> mx(n,0), mn(n,0);
    sort(all(a));

    for(int i = 0; i < n; i++){
        if(n-1-i >= k-1)
            mn[i] = binom(n-1-i,k-1);
    }
    for(int i = n-1; i >= 0; --i){
        if(i >= k-1)
            mx[i] = binom(i,k-1);
    }

    ll ans = 0;

    for(int i = 0; i < n; i++){
        ans += ((mx[i] - mn[i])*a[i] % mod), ans %= mod;
    }

    cout<<ans<<"\n";    
}


Measured memory_bytes: 3456
nd = input().split()
N = int(nd[0])
D = int(nd[1])
D = D**2

ans = 0

for i in range(N):
    ls = input().split()
    x = int(ls[0])
    y = int(ls[1])
    d = x**2 + y**2
    if d <= D :
        ans += 1

print(ans)


Measured memory_bytes: 9152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    set<string>s;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string o;
        cin>>o;
        s.insert(o);
    }
    cout<<s.size()<<endl;
}


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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<int> a(n); rep(i, n) cin >> a[i];
	set<int> st; rep(i, n) st.insert(a[i]);
	cout << ((int)st.size() == n ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <vector>

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

using namespace std;

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

	int d[25] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9};

	rep(i,n)
	{
		int a,b;
		cin >> a >> b;

		vector<int> v,v2;
		
		bool flag = false;
		for(int j=0;j<26;j++)
		{
			if(d[j] == a && !flag)
			{
				flag = true;
			}
			else if(d[j] == a && flag)
			{
				v.clear();
			}

			if(flag) v.push_back(d[j]);
			
			if(flag && d[j] == b)
			{
				flag = false;
				break;
			}
		}

		bool first = true;
		rep(j,v.size())
		{
			if(first)
			{
				first = false;
			}
			else cout << " ";
			cout << v[j];
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
        int h, w, d;
        scanf("%d%d%d", &h, &w, &d);
        for (int i = 0; i < h; i ++) {
                for (int j = 0; j < w; j ++) {
                        int x = (i + j) / d % 2;
                        int y = (h - 1 - (i - j)) / d % 2;
                        printf("%c", "RYGB"[x * 2 + y]);
                }
                puts("");
        }
        return 0;
}



Measured memory_bytes: 512
h = {48:"light fly", 51:"fly", 54:"bantam", 57:"feather", 60:"light" , 64:"light welter", 69:"welter", 75:"light middle", 81:"middle", 91:"light heavy"}
while 1:
	try: w = float(input())
	except: break
	for i, x in sorted(h.items()):
		if w <= i: 
			print(h[i])
			break
	else: print("heavy")



Measured memory_bytes: 5580
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		var p = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		int counter = 0;
		
		for(int i=0;i!=n;i++){
			if(p[i]!=i+1){
				counter++;
			}
		}
		
		if(counter<=2){
			Console.WriteLine("YES");
		}else{
			Console.WriteLine("NO");
		}
		
	}
}

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

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int a[m],b[m];
	for (int i = 0; i < m; ++i)
	{
		cin>>a[i]>>b[i];
		--a[i];--b[i];
	}
	vector<int> ans;
	int mi=1000000;
	for (int i = 0; i < m; ++i)
	{
		set<int>edge[n];
		for (int j = 0; j < m; ++j)
		{
			if (i!=j)
			{
				edge[a[j]].insert(b[j]);
			}
		}
		int memo[n]={},back[n],dist[n];
		for (int j = 0; j < n; ++j)
		{
			back[j]=-1;
			dist[j]=-1;
		}
		memo[b[i]]=1;
		dist[b[i]]=1;
		queue<int> que;
		que.push(b[i]);
		while(que.size()>0)
		{
			int now=que.front();
			que.pop();
			for (auto v:edge[now])
			{
				if (memo[v]==0)
				{
					memo[v]=1;
					back[v]=now;
					dist[v]=dist[now]+1;
					que.push(v);
				}
			}
		}
		if (memo[a[i]]==1)
		{
			if (mi>dist[a[i]])
			{
				mi=dist[a[i]];
				ans={};
				int now=a[i];
				while (now!=b[i])
				{
					ans.push_back(now);
					now=back[now];
				}
				ans.push_back(b[i]);
			}
		}
	}
	if (mi==1000000)
	{
		cout<<"-1\n";
	}
	else
	{
		reverse(ans.begin(), ans.end());
		cout<<mi<<endl;
		for (auto v:ans)
		{
			cout<<v+1<<endl;
		}
	}
	return 0;
}

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

int main(){
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  int sumA=0;
  int sumB=0;
  if(A+B<=C*2){
    sumA=A*X+B*Y;
    sumB=A*X+B*Y;
  }else{
    if(X>Y){
      sumA=C*X*2;
      sumB=C*Y*2+A*(X-Y);
    }else{
      sumA=C*Y*2;
      sumB=C*X*2+B*(Y-X);
    }
  }
  cout << min(sumA,sumB) << endl;
  return 0;
}


Measured memory_bytes: 256
# C
l,r = map(int, input().split())
mod = 2019
if r-l >= mod:
    print(0)
else:
    minnum = 2019
    for i in range(l,r):
        for j in range(i+1,r+1):
            tmp = ((i%mod)*(j%mod))%mod
            if tmp < minnum:
                minnum = tmp
    print(minnum)

Measured memory_bytes: 41452
from sys import stdin
def main():
    n = int(stdin.readline())
    a = map(int, stdin.readline().split())
    L = range(n + 2)
    R = range(n + 2)
    b = [0] * (n + 2)
    L[n+1] = R[n+1] = n
    L[0] = R[0] = 1
    for i, x in enumerate(a, 1):
        b[x] = i
    s = 0
    for i in xrange(n, 0, -1):
        j = b[i]
        s += i * (R[j] - j + 1) * (j - L[j] + 1)
        R[L[j]-1] = R[j]
        L[R[j]+1] = L[j]
    print s
main()


Measured memory_bytes: 28028
N = int(input())
S = input()

targets = tuple("{:0>3}".format(i) for i in range(1000))
ans = []
for target in targets:
    a, b, c = target
    a_index = S.find(a)
    b_index = S.find(b, a_index + 1)
    c_index = S.find(c, b_index + 1)
    ret = (a_index, b_index, c_index)
    if -1 not in ret:
        # print(target, ret)
        ans.append(ret)
print(len(ans))

Measured memory_bytes: 3316
M=10^9+7
A=(x->parse(Int,x)).(split(readlines()[2]))
i=s=r=big"0"
f=1
for a=A
	s+=invmod(i+=1,M)
	r+=a*(s-1)+A[end+1-i]*s
	f=f*i%M
end
print(r*f%M)

Measured memory_bytes: 167696
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long pow_mod(long long n,long long k,long long m){
    if (k == 0){
        return 1;
    } else if (k % 2 == 1){
        return pow_mod(n,k-1,m)*n % m;
    } else {
        long long t = pow_mod(n,k/2,m);
        return t*t % m;
    }
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int par[100010],dep[100010];
void init(int N){
    for(int i = 0; i < N; i++){
        par[i] = i;
        dep[i] = 0;
    }
}

int find(int x){
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
}

void merge(int a,int b){
    a = find(a);
    b = find(b);
    if (dep[a] > dep[b]){
        par[b] = a;
        dep[a] += b;
    } else {
        par[a] = b;
        dep[b] += a;
    }
}

int main(){
    int n; cin >> n;
    int a[n];
    cin >> a[0];
    int mx = a[0],se_mx = 0;
    for(int i = 1;i < n; i++){
        cin >> a[i];
        if (a[i] > mx){
            se_mx = mx;
            mx = a[i]; 
        } else if (se_mx < a[i]){
            se_mx = a[i];
        }
    }
    for(int i = 0; i < n; i++){
        if (a[i] == mx){
            cout << se_mx << endl;
        } else {
            cout << mx << endl;
        }
    }
}


Measured memory_bytes: 2432
#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()
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int a[n],b[n],amax=-1;
  rep(i,n){
    cin >> a[i];
    b[i]=a[i];
    amax=max(a[i],amax);
  }
  
  sort(b,b+n,greater<int>());
  rep(i,n){
    if(a[i]==amax)
    cout << b[1] << endl;
    else 
    cout << b[0] << endl;
  }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define INF 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

const int PLUS=-1;
const int MUL=-2;

class expr{
public:
	bool f=true;
	ll l=0,m=0,r=0;
	expr(){}
	expr(bool ff,ll lv,ll mv,ll rv){
		f=ff;
		l=lv;
		m=mv;
		r=rv;
	}
};

expr merge(expr el,expr er,int op){
	expr res;
	if(op==PLUS){
		res.f=false;
		if(el.f && er.f){
			res.l=el.m;
			res.r=er.m;
			res.m=0;
		}else if(el.f){
			res.l=el.m;
			res.m=min(INF,er.l+er.m);
			res.r=er.r;
		}else if(er.f){
			res.l=el.l;
			res.m=min(INF,el.m+el.r);
			res.r=er.m;
		}else{
			res.l=el.l;
			// maybe overflow a+b+c+d
			res.m=min(INF,el.m+el.r+er.l+er.m);
			res.r=er.r;
		}
	}else if(op==MUL){
		res.f=el.f&&er.f;
		if(el.f && er.f){
			res.l=0;
			res.m=min(INF,el.m*er.m);
			res.r=0;
		}else if(el.f){
			res.l=min(INF,el.m*er.l);
			res.m=er.m;
			res.r=er.r;
		}else if(er.f){
			res.l=el.l;
			res.m=el.m;
			res.r=min(INF,el.r*er.m);
		}else{
			res.l=el.l;
			//maybe overflow a+b*c+d
			res.m=min(INF,el.m+el.r*er.l+er.m);
			res.r=er.r;
		}
	}else{
		res=el;
	}
	return res;
}

struct segtree{
	int N;
	expr ex[1<<21];
	int op[1<<21];
	segtree(){}
	void memsetN(int n){
		N=1;
		while(N<n){
			N*=2;
		}
		
		for(int i=0;i<N*2;i++){
			ex[i]=expr(true,0,1,0);
			op[i]=MUL;
		}
	}
	void init(vector<ll> &v,int k,int l,int r){
		if((r-l)==1){
			if(l*2<v.size())ex[k]=expr(true,0,v[l*2],0);
			return;
		}
		int mid=(l+r)/2;
		init(v,k*2+1,l,mid);
		init(v,k*2+2,mid,r);
		if(2*mid-1<v.size())op[k]=v[2*mid-1];
		ex[k]=merge(ex[k*2+1],ex[k*2+2],op[k]);
	}
	expr query(int a,int b,int k,int l,int r){
		if(b<=l || r<=a)return expr(true,0,1,0);
		if(a<=l && r<=b)return ex[k];
		int mid=(l+r)/2;
		expr el=query(a,b,k*2+1,l,mid);
		expr er=query(a,b,k*2+2,mid,r);
		if(mid<=a)return er;
		if(b<=mid)return el;
		//printf("%d %d %d %d %d %d (%lld,%lld,%lld),%d (%lld,%lld,%lld),%d\n",a,b,k,l,r,op[k],el.l,el.m,el.r,el.f?1:0,er.l,er.m,er.r,er.f?1:0);
		return merge(el,er,op[k]);
	}
	ll getval(int l,int r){
		expr res=query(l,r,0,0,N);
		return min(INF,res.l+res.m+res.r);
	}
};

segtree seg;

ll n;
string str;
int pos=0;
ll ans=0;

// v {num, op, num, op, ...}
ll solve2(vector<ll> v){
	int m=v.size()/2+1;
	seg.memsetN(m);
	seg.init(v,0,0,seg.N);
	int r=0;
	int r2=0;
	for(int i=0;i<m;i++){
		ll tmp=0;
		r=max(i,r);
		r2=max(i,r2);
		while(r<m && (tmp=seg.getval(i,r+1))<=n){
			r++;
		}
		while(r2<m && (tmp=seg.getval(i,r2+1))<n){
			r2++;
		}
		ans+=(r-r2);
	}
	return seg.getval(0,m);
}

ll solve(){
	vector<ll> v;
	while(pos!=(int)str.size()){
		char c=str[pos];
		if(c=='('){
			pos++;
			v.push_back(solve());
		}
		if(c==')'){
			pos++;
			break;
		}
		if(isdigit(c)){
			pos++;
			v.push_back(c-'0');
		}
		if(c=='*'){
			pos++;
			v.push_back(MUL);
		}
		if(c=='+'){
			pos++;
			v.push_back(PLUS);
		}
	}
	return solve2(v);
}

int main(void){
	while(1){
		scanf("%lld",&n);
		if(n==0LL)break;
		cin >> str;
		//printf("%d\n",(int)str.size());
		ans=0;
		pos=0;
		solve();
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 110992
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

d = 0
for i in range(n):
    if i > 0 and a[i] == a[i-1]+1:
        d += b[a[i]-1]+c[a[i]-2]
    else:
        d += b[a[i]-1]

print(d)

Measured memory_bytes: 3064
'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''
'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''
'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''
'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''
'''
.append(要素)
.extend(要素)
.insert(場所,要素)
del 配列名[場所]
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)
'''
'''
sort()
sorted(reverse=true)
'''
'''
2分探索
bisect.bisect_left(リスト, 要素)
'''
'''
リスト同士の演算
list(map(lambda x, y: x+y, el2, el3))
'''
'''
配列の初期化
配列名=[a]*n+[b]*m
'''
'''
重複
list(set())
２次元配列
list(map(list, set(map(tuple, addition))))
'''
'''
順列
for el in itertools.permutations(配列のパターン):
'''
'''
Decimal()
'''
# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()




from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
import itertools
from functools import reduce
from operator import mul
def gcd(*numbers):
    return reduce(math.gcd, numbers)


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


N = int(stdin.readline().rstrip())
P = [int(s) for s in stdin.readline().rstrip().split()]
count = 1
min = P[0]
for k in range(len(P)):
    if k == 0:
        continue
    if min > P[k]:
        count += 1
        min = P[k]
print(count)


Measured memory_bytes: 73024
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define SIZE 100000
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	int ren[SIZE];
	void init()
	{
		for (int i = 0; i<SIZE; i++)
		{
			par[i] = i;
			ran[i] = 0;
			ren[i] = 1;
		}
	}
	int find(int a)
	{
		if (a == par[a])return a;
		else return par[a] = find(par[a]);
	}
	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (ran[a]>ran[b])
		{
			par[b] = a;
			ren[a] += ren[b];
		}
		else
		{
			par[a] = b;
			ren[b] += ren[a];
		}
		if (ran[a] == ran[b])ran[b]++;
	}
};
unionfind uf;
typedef pair<int, int>pii;
typedef pair<int, pii>pi3;
typedef long long ll;
int main()
{
	int num;
	scanf("%d", &num);
	uf.init();
	vector<pii>va, vb;
	for (int i = 0; i < num; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		va.push_back(make_pair(za, i));
		vb.push_back(make_pair(zb, i));
	}
	sort(va.begin(), va.end());
	sort(vb.begin(), vb.end());
	vector<pi3>v;
	for (int i = 0; i < num - 1; i++)v.push_back(make_pair(va[i + 1].first - va[i].first, make_pair(va[i].second, va[i + 1].second)));
	for (int i = 0; i < num - 1; i++)v.push_back(make_pair(vb[i + 1].first - vb[i].first, make_pair(vb[i].second, vb[i + 1].second)));
	sort(v.begin(), v.end());
	ll ans = 0;
	for (int i = 0; i < v.size(); i++)
	{
		if (uf.find(v[i].second.first) != uf.find(v[i].second.second))
		{
			uf.unite(v[i].second.first, v[i].second.second);
			ans += v[i].first;
		}
	}
	printf("%lld\n", ans);
}

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<int>> l(n+1,vector<int>(10,0)), r(n+1,vector<int>(10,0));
  rep(i,n) {
    int d = s[i] - '0';
    l[i][d] = 1;
    if (i != 0) for (int j = 0; j < 10; j++) l[i][j] |= l[i-1][j];
  }
  for (int i = n-1; i >= 0; i--) {
    int d = s[i] - '0';
    r[i][d] = 1;
    if (i != n-1) for (int j = 0; j < 10; j++) r[i][j] |= r[i+1][j];
  }
  set<int> se;
  for (int i = 1; i < n-1; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        if (l[i-1][j] && r[i+1][k]) se.insert(100*j + 10*(s[i]-'0')+k);
      }
    }
  }
  cout << sz(se) << endl;
  return 0;
} 

Measured memory_bytes: 4480
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

#define INF 2e9

#define REP(i,n) for(int i = 0; i < n;++i)
#define REPA(i,a,n) for(int i = a; i < n; ++i)
#define ALL(a) a.begin(), a.end()

using namespace std;

int main(void) {

	int N;
	long long int sum = 0;

	cin >> N;

	vector<int> d(N);

	REP(i, N) cin >> d[i];

	REP(i, N){
		REPA(j, i + 1, N){
			sum += d[i] * d[j];
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())

x = 0
z = 0
y = N
flg = False

while y >= 0:

    total = x * 1000 + y * 5000 + z *10000

    if total == Y:
        flg = True
        break

    elif total > Y:
        x += 1
        y -= 1

    else:
        z += 1
        y -= 1

if flg == False:
    x = -1
    y = -1
    z = -1

print("{} {} {}".format(z, y, x))

Measured memory_bytes: 3064
from collections import deque
h , w = map(int,input().split())
ma = [["#" for i in range(w+2)]]
for i in range(h):
    kar = ["#"]
    kar.extend(list(input()))
    kar.append("#")
    ma.append(kar)
ma.append(["#" for i in range(w+2)])
ans = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        if ma[i][j] == "#":
            continue
        elif ma[i][j] ==".":
            p = [[-1 for g in range(w+2)] for f in range(h+2)]
            p[i][j] = 0
            q = deque()
            q.append([i,j])
            while q:
                y,x = q.popleft()
                if ma[y+1][x] == "." and p[y+1][x] == -1:
                    p[y+1][x] = p[y][x] + 1
                    q.append([y+1,x])
                if ma[y-1][x] == "." and p[y-1][x] == -1:
                    p[y-1][x] = p[y][x] + 1
                    q.append([y-1,x])
                if ma[y][x+1] == "." and p[y][x+1] == -1:
                    p[y][x+1] = p[y][x] + 1
                    q.append([y,x+1])
                if ma[y][x-1] == "." and p[y][x-1] == -1:
                    p[y][x-1] = p[y][x] + 1
                    q.append([y,x-1])
            for l in range(1,h+1):
                ans = max(ans,max(p[l]))
print(ans)

Measured memory_bytes: 9508
#include<cstdio>
using namespace std;
int a[200005];
long long sum[200005];
int main(){
	int n,i;
	long long ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum[i]=sum[i-1]+a[i];
		sum[i]%=1000000007;
	}
	for(i=n;i;i--){
		ans+=sum[i-1]*a[i]%1000000007;
		ans%=1000000007;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4072
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define pb push_back
int main()
{
    ll n,r,c,d;
    cin>>n;
    c=(n/500)*1000;
    r=(n%500)/5;
    r=r*5;
    c=c+r;
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a_l = list(map(int, input().split()))

# 0 ~ 10**6に入力値の個数を入れる
# (count()で数えると、o(n**2)になるため)
val_list = [0 for i in range(10**6+1)]
for i in a_l:
	val_list[i] += 1

# 重複削除
a_l = list(set(a_l))

# 0 ~ 10**6のリスト
A_list = [True for i in range(10**6+1)]
# 倍数のところにFalseを入れる
for i in a_l:
	for j in range(i*2, 10**6+1, i):
		A_list[j] = False

# Trueと一致するa_lの個数を数える
cnt = 0
for i in a_l:
	if(val_list[i] != 1):
		continue
	if(A_list[i]):
		cnt += 1

print(cnt)

Measured memory_bytes: 41040
def solve(A, i, m, n):
    """Return if it is possible to make value m with some elements in A.

    n is length of A.
    i is index.
    R is the record of answer i, m.
    Using Divide-and-Conquer method.
    """

    if R[i][m] != None:
        return R[i][m]
    if m == 0:
        R[i][m] = True
        return True
    elif i >= n:
        R[i][m] = False
        return False
    else:
        ans = solve(A, i + 1, m, n) or solve(A, i + 1, m - A[i], n)
        R[i][m] = ans
        return ans


import sys

n = int(sys.stdin.readline())
A = tuple(map(int, sys.stdin.readline().split()))
q = int(sys.stdin.readline())
M = tuple(map(int, sys.stdin.readline().split()))

s_A = sum(A)
R = [[None] * 2000 for i in range(n + 1)]

ans = ''

for m in M:
    if s_A < m:
        ans += 'no\n'
    elif solve(A, 0, m, n):
        ans += 'yes\n'
    else:
        ans += 'no\n'

print(ans, end = '')

Measured memory_bytes: 8076
import itertools
n, m, q = map(int, input().split())

q_list = []
for _ in range(q):
    q_list.append(list(map(int, input().split())))

a_p = [i for i in range(1, m + 1)]
a_list = list(itertools.combinations_with_replacement(a_p, n))

a_max = 0
for a in a_list:
    d_cnt = 0
    for q_v in q_list:
        if q_v[1] > len(a):
            continue
        if a[q_v[1] - 1] - a[q_v[0] - 1] == q_v[2]:
            d_cnt += q_v[3]

    if a_max < d_cnt:
        a_max = d_cnt

print(a_max)


Measured memory_bytes: 84512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    ll n,k;
    cin >> n >> k;
    ll a[n];
    for(ll i = 0; i < n; i++){
        cin >> a[i];
    }
    ll cnt1 = 0,cnt2 =0;
    for(ll i = 0; i < n; i++){
        for(ll j = i+1; j < n; j++){
            if(a[i] > a[j])cnt1++;
        }
    }
    sort(a,a+n);
    reverse(a,a+n);
    for(ll i = 0; i < n; i++){
        for(ll j = i+1; j < n; j++){
            if(a[i] > a[j])cnt2++;
        }
    }
    ll x = (k % mod) * ((k-1) % mod) / 2;
    x %= mod;
    ll ans = (cnt1 * k) + (cnt2 * x);
    ans %= mod;
    cout << ans << endl;  
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(size_t i = (j); i < (n); ++i)
#define rrep(i, j, n) for(size_t i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

int n, a, b, c;
vector<int> l;
int ans = 1 << 30;


void dfs(int i, int cost, int alen, int blen, int clen) {
	if (i == n) {
		if (alen == 0 || blen == 0 || clen == 0) return;
		ans = min(ans, cost + abs(a - alen) + abs(b - blen) + abs(c - clen));
		return;
	}

	if (alen > 0) dfs(i + 1, cost + 10, alen + l[i], blen, clen);
	else dfs(i + 1, cost, alen + l[i], blen, clen);

	if (blen > 0) dfs(i + 1, cost + 10, alen, blen + l[i], clen);
	else dfs(i + 1, cost, alen, blen + l[i], clen);

	if (clen > 0) dfs(i + 1, cost + 10, alen, blen, clen + l[i]);
	else dfs(i + 1, cost, alen, blen, clen + l[i]);

	dfs(i + 1, cost, alen, blen, clen);
	return;
}

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

	cin >> n >> a >> b >> c;
	l.resize(n);
	rep(i, 0, n) cin >> l[i];

	dfs(0, 0, 0, 0, 0);
	cout << ans << endl;

	return 0;

}


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

int main(void){
	int N;
	cin>>N;
	vector<pair<int,int>> pairs;
	vector<int> numbers;

	for(int i=0;i<N;i++){
		int X;
		cin>>X;
		pair<int,int> temp = make_pair(i,X);
		pairs.push_back(temp);
		numbers.push_back(X);
	}
	
	sort(numbers.begin(),numbers.end());

	int candidate = numbers.at(N/2);
	int candidate_minus= numbers.at((N/2) -1);

	for(int i=0;i<N;i++){
		pair<int,int> temp = pairs.at(i);
		if(temp.second >= candidate){
			cout<<candidate_minus<<endl;
		}else{
			cout<<candidate<<endl;
		}
	}

	return 0;
}


Measured memory_bytes: 5616
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// 4-direction
int dy4[] = {0,  1, -1,  0};
int dx4[] = {1,  0,  0, -1};

// 8-direction
int dy8[] = {0,  1,  1,  1,  0, -1, -1, -1};
int dx8[] = {1,  1,  0, -1, -1, -1,  0,  1};

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

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

  int a, z;

  for(int i=0; i<s.length(); i++) {
    if(s[i]=='A') {
      a = i;
      break;
    }
  }

  for(int i=s.length()-1; i>=0; i--) {
    if(s[i]=='Z') {
      z = i;
      break;
    }
  }

  cout << z - a + 1 << endl;

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    ll N, K;
    cin >> N >> K;
    cout << min(N%K,K-N%K) << endl;
}

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

using namespace std;
typedef long long ll;

int N;
int arr[110];

int main()
{
    ios_base::sync_with_stdio(0);

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

    int ans = 1e9;
    for (int x = 1; x <= 100; x++)
    {
        int cv = 0;
        for (int i = 0; i < N; i++)
            cv += (x - arr[i]) * (x - arr[i]);
        ans = min (ans, cv);
    }
    cout << ans << "\n";
}

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

using namespace std;

int main()
{
    int n;
    vector<int> a;

    cin >> n;

    for (int i = 0; i < n; i++) {
        int num;
        cin >> num;
        a.push_back(num);
    }
    vector<int> b(a);

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

    int cnt = 0;

    for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) {
            cnt++;
        }
        if (cnt > 2) {
            cout << "NO" << endl;
            return (0);
        }
    }

    cout << "YES" << endl;

}


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

using namespace std;

int main(){

    string S;
    cin >> S;

    int count = 0;
    for (int i = 0; i < S.length(); i++){
        if (S[i] == 'x'){
            count ++;
        }
    }

    if (count <= 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
ints = [int(x) for x in input().split()]

ans = 0
r = 0
s = 0
xs = 0
for l in range(N):
    while r < N and s + ints[r] == xs ^ ints[r]:
        s += ints[r]
        xs ^= ints[r]
        r += 1
    ans += (r - l)
    s -= ints[l]
    xs ^= ints[l]

print(ans)


Measured memory_bytes: 23560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    long long N,A,B;cin >> N >> A >> B;if(A > B) swap(A,B);
    if((A%2) != (B%2)){
        long long ans = 0;
        if(abs(1-max(A,B)) < abs(N-min(A,B)) ){
            ans += abs(1 - min(A,B));
            if(ans == 0){ans++;B--;}
            B -= abs(1 - min(A,B));A -= abs(1 - A);
            if(B <= 1){
                cout << ans << endl;
                return 0;
            }
            else{
                cout << (abs(A - B)+1)/2 + ans << endl;
            }
        }
        else{
            ans += abs(N-max(A,B));
            if(ans == 0){ans++;A++;}
            A += abs(N-max(A,B));B += abs(N-B);
            if(A >= N){
                cout << ans << endl;
                return 0;
            }
            else{//cout << ans << ' ' << A << ' ' << B << endl;
                cout << (abs(A - B)+1)/2 + ans << endl;
            }
        }
    }
    else{
        cout << abs(A-B)/2 << endl;
    }
}

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

#define ris   return *this
#define tmplt template<class T
#define dbgo  debug& operator<<
tmplt > struct rge { T b, e; };
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
~debug(){cerr<<endl;}
tmplt > dbgo(T x){cerr<<boolalpha<<x;ris;}
tmplt, class C > dbgo(pair<T, C> x){ris<<"("<<x.first<<", "<<x.second<<")";}
tmplt > dbgo(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}ris<<"]";}
tmplt > dbgo(vector<T> x){ris<<range(x.begin(),x.end());}
#else
tmplt > dbgo(const T&){ris;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}

double f(ll n) {
    double ans = n;
    int sum = 0;
    while(n) {
        sum += n % 10;
        n /= 10;
    }
    return ans / sum;
}

ll next(ll n) {
    ll ans = n;
    double score = f(n);
    for(ll p = 10; p <= n; p *= 10) {
        ll rem = n % p;
        n -= rem;
        n += p - 1;
        if(f(n) < score) {
            ans = n;
            score = f(n);
        }
        n -= p - 1;
        n += rem;
    }
    
    return ans;
}

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

    int k;
    cin >> k;
    vector<ll> snuke;
    ll n = 1;
    while((int) snuke.size() < k) {
        n = next(n);
        snuke.push_back(n);
        n++;
    }
    for(ll x : snuke) {
        cout << x << '\n';
    }
}













// Don't worry, you're getting better

// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)

// Author: blondie


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

using namespace std;

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

const int N = 200010;

ll n , m;

int main(){
    //freopen("input.txt", "r", stdin);
	cin >> n >> m;
	ll res = min(n,m/2);
	m -= res * 2;
	res += m/4;
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int ans1=0;
    int ans2=0;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int num;
        cin>>num;
        if(num%2)
        {
            ans1++;
        }
        else
        {
            ans2++;
        }
    }
    if(ans1%2)
    {
        cout<<"NO";
    }
    else
    {
        cout<<"YES";
    }
    return 0;
}


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

int main() {
    int a, b, c, d, e;
    int k;

    cin >> a >> b >> c >> d >> e >> k;

    if (b - a <= k && c - a <= k && d - a <= k && e - a <= k) {
      cout << "Yay!" << endl;
    } else {
      cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
#define ll long long
#define lint long long
static const int INF = 1 << 22;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
/*******source code below********/
int main(void) {

	ll N, K; cin >> N >> K;
	string T; cin >> T;
	vector<lint> S; S.push_back(0);
	for (ll i = 1; i < N ; i++)
	{
		if (T[i] != T[i - 1]) S.push_back(i);
	}
	S.push_back(N);
	vector<ll> X(S.size());
	
	for (ll i = 0; i < S.size(); i++)
	{
		if (T[S[i]] == '0') {
			X[i] = S[min((long long)(S.size() - 1), i + 2 * K)] - S[i];
		}
		else {
			X[i] = S[min((long long)(S.size() - 1), i + 2 * K + 1)] - S[i];
		}
	}
	sort(X.begin(), X.end());
	reverse(X.begin(), X.end());

	cout << X[0] << endl;
	return 0;
}

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

public class Main {
	
	public  void solve() throws IOException{
		int n;
		while( (n = nextInt()) != 0 ){
			int[] ans = new int[n/2+1];
			Set<Integer> set = new HashSet<Integer>();
			for(int i = 1; i < n; i++){
				int x = i*i%n;
				set.add(x);
			}
			List<Integer> list = new ArrayList<Integer>(set);
			Collections.sort(list);
			for(int i = 0; i < list.size(); i++){
				for(int j = i+1; j < list.size(); j++){
					int key = ((list.get(i)-list.get(j))+n)%n;
					key = Math.min(n-key, key);
					ans[key] += 2;
				}
			}
			for(int i = 1; i < ans.length; i++){
				writer.println(ans[i]);
			}
		}
		writer.flush();
	}
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}		
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

Measured memory_bytes: 10000
// This file is a "Hello, world!" in D language by DMD for wandbox.
import std.stdio;
import std.string;
import std.range;
import std.algorithm;
import std.conv;
void main()
{
    readln;
    size_t aa = 0;
    auto k = readln.strip.split(' ').map!(to!int).array;
    for (ptrdiff_t i = 0; i < k.length; i++)
    {
        bool f = false;
        for (ptrdiff_t j = k.length - 1; j >= i + 1; j--)
        {
            if (k[j] < k[j - 1])
            {
                f = true;aa++;
                swap(k[j], k[j - 1]);
            }
        }
        if (!f)break;
    }
    writeln(k.map!(to!string).join(" "));
    writeln(aa);
}


Measured memory_bytes: 2460
#include<iostream>
#define n 8
using namespace std;
int row[n],col[n],dpos[2*n-1],dneg[2*n-1],X[n][n];
void print()
{
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        if(X[i][j]&&row[i]!=j) return ; //这一段留着还是必要的，因为每到8 会输出，不判断就很难受
    for(int i=0;i<n;cout<<endl,i++)
        for(int j=0;j<n;j++)
        cout<<((row[i]==j)?"Q":".");
}
void recursive(int i)
{
    if(i==n)
    {
        print();
        return ;
    }
    for(int j=0;j<n;j++)
    {
        if(col[j]==1||dpos[i+j]==1||dneg[i-j+n-1]==1)continue;
        row[i]=j; col[j]=dpos[i+j]=dneg[i-j+n-1]=1;
        recursive(i+1);
        row[i]=col[j]=dpos[i+j]=dneg[i-j+n-1]=-1;
    }
}
int main()
{
    for(int i=0;i<n;i++)row[i]=col[i]=-1;
    for(int i=0;i<2*n-1;i++)dpos[i]=dneg[i]=-1;
    int k,x,y;
    cin>>k;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)X[i][j]=0;
    for(int i=0;i<k;i++)cin>>x>>y,X[x][y]=1;
    recursive(0);
    return 0;
}



Measured memory_bytes: 3120
#include<stdio.h>
int main(void){
	int i,j;
	int t0=100000,t1=0;
	char S[1001],T[1001];
	scanf("%s",&S);
	scanf("%s",&T);
	
	for(i=0;i< (strlen(S)-strlen(T)+1);i++){
		for(j=0;j<strlen(T);j++){
			if(S[i+j] != T[j])
				t1+=1;
		}
		if(t0 > t1)
			t0 =t1;
		t1=0;
	}
	printf("%d",t0);
	
	return 0;
}

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

int main(int argc, const char * argv[]) {



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

    /////////////////////
    // Write code below /
    /////////////////////
    
    string S;

    cin>>S;

    if(S == "AAA" || S== "BBB")
        cout<<"No"<<endl;
    else
    {
        cout<<"Yes"<<endl;
    }
    


    

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int P = Integer.parseInt(scanner.next());
        int Q = Integer.parseInt(scanner.next());
        int R = Integer.parseInt(scanner.next());
        scanner.close();

        int[] arr = {P, Q, R};
        Arrays.sort(arr);

        System.out.println(arr[0] + arr[1]);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int main()
{
	int n;
	string s;
	cin>>n>>s;
	s=s+s;
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			a[0]=i;
			a[1]=j;
			for(int i=2;i<=n+1;i++)
			{
				if(s[i-1]=='o'&&a[i-1]==0)
					a[i]=1-a[i-2];
				if(s[i-1]=='o'&&a[i-1]==1)
					a[i]=a[i-2];
				if(s[i-1]=='x'&&a[i-1]==0)
					a[i]=a[i-2];
				if(s[i-1]=='x'&&a[i-1]==1)
					a[i]=1-a[i-2];
			}
			if(a[n]==a[0]&&a[n+1]==a[1])
			{
				for(int i=0;i<n;i++)
				{
					if(a[i])
						cout<<'S';
					else
						cout<<'W';
				}
				return 0;
			}
		}
	}
	cout<<"-1";

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    int a, b; cin >> a >> b;
    if ( (a + b )% 2 == 0) {
        cout << (a + b) / 2 << "\n";
    } else {
        cout << "IMPOSSIBLE"
             << "\n";
    }
    return 0;
}


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

int main() {
	int n;
	std::vector<int> d;

	std::cin >> n;

	int tmp;
	for(int i=0;i<n;i++){
		std::cin >> tmp;
		d.push_back(tmp);
	}

	int max_dif = *(d.begin()+1) - *d.begin();
	auto max_idx = d.begin();
	for(auto it=d.begin()+1;it!=d.end();++it){
		if(*it - *max_idx >= max_dif){
			max_dif = *it - *max_idx;
		}
		if(*it - *(it-1) >= max_dif){
			max_dif = *it - *(it-1);
		}
		if(*max_idx > *(it-1)){
			*max_idx = *(it-1);
		}
	}

	std::cout << max_dif << std::endl;

	return 0;
}



Measured memory_bytes: 3896
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
const int mx = 1e6;
int divv[mx + 5];
int main() {
	for (int i = 1; i <= mx; ++i)
		for (int j = i; j <= mx; j += i)
			++divv[j];

	int n;
	int ans = 0;
	cin >> n;
	for (int i = 1; i < n; ++i){
        ans += divv[n - i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 7540