akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var s = ReadLine();
            var K = Sarray()[0];
            var strings = new List<string>();
            var N = s.Length;
            var pos = Enumerable.Repeat(0, 26).Select(_ => new List<int>()).ToArray();
            for (var i = 0; i < N; ++i)
                pos[s[i] - 'a'].Add(i);
            for (var i = 0; i < 26; ++i)
            {
                foreach (var p in pos[i])
                {
                    for (var j = 0; j < Min(N - p, K); ++j)
                        strings.Add(new string(s.Skip(p).Take(j + 1).ToArray()));
                }
            }
            var cdt = strings.Distinct().OrderBy(ss => ss, StringComparer.OrdinalIgnoreCase).ToArray();
            WriteLine(cdt[K - 1]);
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 35360
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
int M = 0;
int P = 0;

signed main(){
    cin >> N;
    rep(i, N){
        int A, B;
        cin >> A >> B;
        if(A > M){
            M = A;
            P = B;
        }
    }
    cout << M+P << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
using namespace std;
string s;
string t="+-*";
int p[3];
int id;
long f(int i)
{
	long now;
	if(i==3)
	{
		if(s[id]=='(')
		{
			id++;
			now=f(0);
			id++;
		}
		else
		{
			now=0;
			while(s[id]>='0')
			{
				now=now*10+s[id]-'0';
				id++;
			}
		}
		return now;
	}
	now=f(i+1);
	while((p[0]==i&&s[id]==t[0])||(p[1]==i&&s[id]==t[1])||(p[2]==i&&s[id]==t[2]))
	{
		char op=s[id];
		id++;
		long next=f(i+1);
		if(op=='+')now+=next;
		else if(op=='-')now-=next;
		else now*=next;
	}
	return now;
}
main()
{
	cin>>s;
	sort(t.begin(),t.end());
	long ans=f(0);
	for(p[0]=0;p[0]<3;p[0]++)
	{
		for(p[1]=0;p[1]<3;p[1]++)
		{
			for(p[2]=0;p[2]<3;p[2]++)
			{
				id=0;
				ans=max(ans,f(0));
			}
		}
	}
	cout<<ans<<endl;
}


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

using namespace std;
int a[3];
int sum=0;

int main()
{
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    while(a[2]-a[1]>=2)
    {
        a[1]+=2;
        sum++;
    }
    while(a[1]-a[0]>=2)
    {
        a[0]+=2;
        sum++;
    }
    while(a[2]-a[0]>=2)
    {
        a[0]+=2;
        sum++;
    }
    sort(a,a+3);
    if(a[1]-a[0]==1) sum+=2;
    if(a[1]==a[0]&&a[2]==a[1]+1) sum+=1;
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.BitSet;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static long[] fal_rnd(int size){
		AtomicInteger l=new AtomicInteger(-1),r=new AtomicInteger(size);
		long[] res=new long[size];
		INS(size).unordered().parallel().mapToLong(Long::parseLong).forEach(v->res[ThreadLocalRandom.current().nextBoolean()?l.incrementAndGet():r.decrementAndGet()]=v);
		return res;
	}
	static IntStream REPS(int v){
		return IntStream.range(0,v);
	}
	static Stream<String> INS(long size){
		return StreamSupport.stream(Spliterators.spliterator(s,size,Spliterator.NONNULL&Spliterator.IMMUTABLE),false).limit(size);
	}
	
	public static void main(String[] __){
		int[] p=new int[114514*3];
		PrimeIterator pi=new PrimeIterator(114514*3);
		for(int i:pi)
			p[i]++;
		Arrays.parallelPrefix(p,Integer::sum);
		int v;
		while((v=s.nextInt())!=0){
			System.out.println(p[v*2]-p[v]);
		}
	}
	static class PrimeIterator implements Iterable<Integer>,PrimitiveIterator.OfInt{
		private BitSet	bitSet;
		private int		nextV;
		private int		limit;
		public PrimeIterator(int limit){
			this.limit=limit;
			bitSet=new BitSet(limit+1);
			nextV=limit<2?-1:2;
		}
		@Override
		public boolean hasNext(){
			return nextV>=0;
		}
		@Override
		public int nextInt(){
			if(!hasNext())
				throw new NoSuchElementException();
			int r=nextV;
			final long buf=nextV;
			if(buf*buf<=limit)
				for(int i=nextV*nextV;i<=limit;i+=nextV)
				bitSet.set(i);
			nextV=bitSet.nextClearBit(nextV+1);
			if(nextV>limit) nextV=-1;
			return r;
		}
		@Override
		public Iterator<Integer> iterator(){
			return this;
		}
	}
}

Measured memory_bytes: 35128
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;


const int mod = 1e9 + 7;
vector<int> g[100003];
bool u[100003] = { false };


P solve(int p) {
    int i;
    ll res0, res1;
    P k;
    res0 = res1 = 1;
    u[p] = true;
    for (i = 0; i < g[p].size(); i++) {
        if (!u[g[p][i]]) {
            k = solve(g[p][i]);
            res0 = res0 * (k.first + k.second) % mod;
            res1 = res1 * k.first % mod;
        }
    }
    return P(res0, res1);
}


int main(void) {
    int n, i, x, y;
    P ans;

    cin >> n;
    for (i = 0; i < n - 1; i++) {
        cin >> x >> y;
        g[x - 1].push_back(y - 1);
        g[y - 1].push_back(x - 1);
    }

    ans = solve(0);

    cout << (ans.first + ans.second) % mod << endl;

    return 0;
}

Measured memory_bytes: 11392
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	queue<int> que[3];
	char S[3][101];
	for(int i=0;i<3;i++){
		cin>>S[i];
		for(int j=0;j<strlen(S[i]);j++){
			que[i].push(S[i][j]-'a');
		}
	}
	int last=0;
	while(1){
		//cout<<last<<endl;
		if(!que[last].size()){
			cout<<(char)(last+'A')<<endl;
			return 0;
		}
		int temp=last;
		last=que[temp].front();
		que[temp].pop();
	}
	return 0;
}

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


int main() {
	string o, e;
	cin >> o >> e;
	reverse(o.begin(), o.end());
	reverse(e.begin(), e.end());
	while (o.size() || e.size()) {
		if (o.size()) {
			cout << o[o.size()-1];
			o.pop_back();
		}
		if (e.size()) {
			cout << e[e.size()-1];
			e.pop_back();
		}
	}
	return 0;
}


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

int main() {
int n,t;
cin >> n >>t;
vector<int>a(n);
for(int i=0;i<n;i++){
    cin >> a.at(i);
}
int ans =t;
for(int i=1;i<n;i++){
    if(t+a.at(i-1)>a.at(i)){
        ans+=a.at(i)-a.at(i-1);
    }
    else{
        ans+=t;
    }
}
cout << ans <<endl;
}




Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int tmp, cnt = 0;
ll a,b,c,d,n,m;
string s;
ull L[87]={};

int main()
{
    L[0] = 2; L[1] = 1;
    cin >> n;

    for(int i=2; i<=n; i++){
        L[i] = L[i-1] + L[i-2];
    }
    
    cout<<L[n]<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
	int x,a,b;
	cin>>x>>a>>b;
	x-=a;
	for(int i=0;;i++)
	{
		x-=b;
		if(!x)
		{
			cout<<0;
			return 0;
		}
		if(x<0)
		{
			cout<<x+b;
			return 0;
		}
	}
    return 0;
}


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

using namespace std;

#define lint long long
#define P pair<int, int>

struct edge {
    int from, to; lint cost; //頂点の番号はint, 辺の重みはlint
};

const int V_MAX = 100000;

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


//edgeの情報をstructで保持しておくグラフ

class Graph{
public:
    vector<vector<edge>> es;
    int E; //edgeの数
    int V; //頂点の数
    const lint INF = 1E18;
    lint d[V_MAX]; //ある頂点からの最短距離の配列
    
    
public:
    Graph(int v); //Vを決定、esをV_MAXでresize、dをINFで埋めて初期化
    void add(int from, int to, lint cost); //edgeをグラフに追加する
    bool BellmanFord(int s); //頂点sから各頂点への最小距離を求める O(EV)
    
};

Graph::Graph(int v){
    V = v;
    for(int i = 0; i < V_MAX; ++i){
        d[i] = INF;
    }
    es.resize(V_MAX);
}

void Graph::add(int from, int to, lint cost){
    edge e = {from, to, cost};
    es[from].push_back(e);
}

bool Graph::BellmanFord(int s){
    bool flag = false;
    d[s] = 0;
    

    lint tmp;
    
    for(int i = 0; i <= 2 * V; ++i){
        if(i == V){
            tmp = d[V - 1];
        }
        if(i == 2 * V){
            if(tmp == d[V - 1]){
                return true;
            }
        }

        bool update = false;
        for(auto e : es){
            for(auto f : e){
                if(d[f.from] != INF && d[f.to] > d[f.from] + f.cost){
                d[f.to] = d[f.from] + f.cost;
                update = true;
                }
            }
        }
        if(!update){
            flag = true;
            break;
        }

        
    }

    return flag;
}

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

    Graph G(N + 1);


    for(int i = 0; i < M; ++i){
        int u, v, w;
        cin >> u >> v >> w;

        G.add(u, v, -w);
    }

    if(G.BellmanFord(1)){
        cout << -G.d[N] << endl;
    } else {
        cout << "inf" << endl;
    }

    
}

Measured memory_bytes: 3456
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
ll N, M, P;
ll dist[3000];
vector<vector<ll>>Eli;
vector<ll>E[3000];
int vis[3000];
void dfs(int now){
	fore(x, E[now]) {
		if (vis[x])continue;
		vis[x] = 1;
		dfs(x);
	}
}
 
ll Bellman_Ford(){
	//init
	for (int i = 0; i < N; i++)dist[i] = inf;
	dist[0] = 0;
	for (int i = 0; i < N - 1; i++) {
		for (int j = 0; j < M; j++) {
			ll u = Eli[j][0];
			ll v = Eli[j][1];
			ll c = Eli[j][2];
			if (!vis[v])continue;
			if (dist[u] == inf)continue;
			if (dist[v] > dist[u] + c)dist[v] = dist[u] + c;
		}
	}
 
	
	//check
	for (int j = 0; j < M; j++) {
		ll u = Eli[j][0];
		ll v = Eli[j][1];
		ll c = Eli[j][2];
		if (!vis[v])continue;
		if (dist[u] == inf)continue;
		if (dist[v] > dist[u] + c)return inf;
	}
	return max(0LL,-dist[N - 1]);
}
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	cin >> N >> M >> P;
	for (int i = 0; i < M; i++) {
		ll A, B, C;
		cin >> A >> B >> C;
		A--, B--;
		Eli.pb({A,B,-(C-P)});
		E[B].pb(A);
	}
	vis[N - 1] = 1;
	dfs(N - 1);
 
 
	ll ans = Bellman_Ford();
	if (ans == inf)puts(-1);
	else puts(ans);
 
	return 0;
}

Measured memory_bytes: 3636
h, w, a, b = map(int, input().split())

ans = []

for i in range(b):
    line = [1]*a + [0] * (w-a)
    ans.append(line)

for j in range(h-b):
    line = [0] * a + [1] * (w-a)
    ans.append(line)

for i in range(h):
    line = ''.join(map(str, ans[i]))
    print(line)




Measured memory_bytes: 11892
#include <iostream>

int main(void) {
	int h, w;
	for (;;) {
		std::cin >> h >> w;
		if (h == 0 && w == 0) { break; }
		for (int y = 0; y < h; ++y) {
			for (int x = 0; x < w; ++x) {
				std::cout << ((x + y) % 2 == 0
					? "#"
					: ".");
			}
			std::cout << "\n";
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int main() {
  long long int x,y;
  long long int z = 0;
  cin >> x >> y;
  if (x <= y) {
    cout << 0;
    exit(0);
  }
  vector<int> vec(x);
  for (int i = 0;i < x; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0;i < y; i++) {
  vec.at(x - 1 - i) = 0;
  }
  for (int i = 0;i < x; i++) {
    z += vec.at(i);
  }
  cout << z;
}

Measured memory_bytes: 1024
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

p_order = sorted(list(itertools.permutations(p)))
q_order = sorted(list(itertools.permutations(q)))

p_point = p_order.index(p)
q_point = q_order.index(q)

print(abs(p_point-q_point))

Measured memory_bytes: 13112
#include<bits/stdc++.h>
using namespace std;
bool f[100001];
int c[100002],N,L,R,i,j;
int main(){
  fill(f,f+100001,true);
  for(i=2;i<=100000;i++)if(f[i])for(j=i+i;j<=100000;j+=i)f[j]=false;
  for(i=3;i<=100000;i+=2)if(f[i]&&f[(i+1)/2])c[i]++;
  for(i=3;i<=100000;i++)c[i]+=c[i-1];
  scanf("%d",&N);
  while(N--){
    scanf("%d%d",&L,&R);
    printf("%d\n",c[R]-c[L-1]);
  }
}


Measured memory_bytes: 1152
#include<cstdio>
const long long p=1000000007;
int factorize(int n, int l[], int e[]){
    int k=n,i=0;
    if(k%2==0){
        int e2=0;
        while(k%2==0){
            e2++;
            k/=2;
        }
        l[i]=2;
        e[i]=e2;
        i++;
    }
    for(int q=3;q*q<=n;q+=2){
        if(k%q==0){
            int ei=0;
            while(k%q==0){
                ei++;
                k/=q;
            }
            l[i]=q;
            e[i]=ei;
            i++;
            if(k==1)break;
        }
    }
    if(k>1){
        l[i]=k;
        e[i]=1;
        i++;
    }
    return i;
}
int esum[1000]={};
int main(){
    int n,l[20],e[20];
    long long ans=1;
    scanf("%d",&n);
    for(int i=2;i<=n;i++){
        int m=factorize(i,l,e);
        for(int j=0;j<m;j++){
            esum[l[j]]+=e[j];
        }
    }
    for(int i=0;i<1000;i++){
        ans=(ans*((long long)esum[i]+1))%p;
    }
    printf("%lld",ans);
    return 0;
}

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

#define ll long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()

struct cake {
    ll x;
    ll y;
    ll z;
};

ll sum(vector<cake> cs, ll m) {
    ll sx = 0;
    ll sy = 0;
    ll sz = 0;
    REP(i, m) {
        sx += cs[i].x;
        sy += cs[i].y;
        sz += cs[i].z;
    }
    return abs(sx) + abs(sy) + abs(sz);
}

int main() {
    ll N, M;
    cin >> N >> M;
    vector<cake> cakes;
    cakes.resize(N);
    REP(i, N) {
        cin >> cakes[i].x >> cakes[i].y >> cakes[i].z;
    }
    auto cmp1 = [](cake a, cake b) {return (a.x + a.y + a.z) < (b.x + b.y + b.z);};
    auto cmp2 = [](cake a, cake b) {return (a.x + a.y - a.z) < (b.x + b.y - b.z);};
    auto cmp3 = [](cake a, cake b) {return (a.x - a.y + a.z) < (b.x - b.y + b.z);};
    auto cmp4 = [](cake a, cake b) {return (a.x - a.y - a.z) < (b.x - b.y - b.z);};
    auto cmp5 = [](cake a, cake b) {return (-a.x + a.y + a.z) < (-b.x + b.y + b.z);};
    auto cmp6 = [](cake a, cake b) {return (-a.x + a.y - a.z) < (-b.x + b.y - b.z);};
    auto cmp7 = [](cake a, cake b) {return (-a.x - a.y + a.z) < (-b.x - b.y + b.z);};
    auto cmp8 = [](cake a, cake b) {return (-a.x - a.y - a.z) < (-b.x - b.y - b.z);};

    ll mx = -1;
    sort(ALL(cakes), cmp1);
    mx = max(sum(cakes, M), mx);
    sort(ALL(cakes), cmp2);
    mx = max(sum(cakes, M), mx);
    sort(ALL(cakes), cmp3);
    mx = max(sum(cakes, M), mx);
    sort(ALL(cakes), cmp4);
    mx = max(sum(cakes, M), mx);
    sort(ALL(cakes), cmp5);
    mx = max(sum(cakes, M), mx);
    sort(ALL(cakes), cmp6);
    mx = max(sum(cakes, M), mx);
    sort(ALL(cakes), cmp7);
    mx = max(sum(cakes, M), mx);
    sort(ALL(cakes), cmp8);
    mx = max(sum(cakes, M), mx);
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long inf = 1ll<<61;
const double eps = 0.000000000001;
typedef pair<int, int> P;
typedef pair<P,int> PP;
struct edge { int to; int to2; int cost; };


signed main() {
	int l, r; cin >> l >> r;
	int ans = inf;
	for (int i = l; i < min(r, 2019 + l); i++) {
		for (int j = i + 1; j <= min(r, 2019 + l); j++) {
			ans = min(ans, i*j % 2019);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    map<int,int> mp;
    for(int i = 0;i < N;i++){
        int a;
        cin >> a;
        mp[a] ++;
    }
    int sum = 0;
    for(auto p:mp){
        int key = p.first, num = p.second;
        if(key <= num)sum += num - key;
        else sum += num;
    }
    cout << sum << endl;
}

Measured memory_bytes: 4736
n = int(input())
L = list(map(int, input().split()))

for i in range(1, n):
    print(' '.join(str(x) for x in L))
    v = L[i]
    j = i - 1
    while j >= 0 and L[j] > v:
        L[j+1] = L[j]
        j -= 1
    L[j+1] = v

print(' '.join(str(x) for x in L))


Measured memory_bytes: 5604
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		String[] str = Integer.toString(n).split("");
		int num = 0;
		for(int i = 0;i < str.length;i++){
			num += Integer.parseInt(str[i]);
		}
		if(n%num == 0){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 22996
S = list(map(int,input().split()))
sx = S[0]
sy = S[1]
tx = S[2]
ty = S[3]

dx = tx - sx
dy = ty - sy
path = ''
path += 'L' + 'U'*(dy+1) + 'R'*(dx+1) + 'D'
path += 'R' + 'D'*(dy+1) + 'L'*(dx+1) + 'U'
path += 'U'*dy + 'R'*dx
path += 'D'*dy + 'L'*dx

print(path)

Measured memory_bytes: 3064
#include <stdio.h>
#define N 100


int main(){

    int i,j,n,a[N],b,min,count=0,flag=0;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }

    for(i=0;i<n;i++){
        min = i;
        for(j=i;j<n;j++){
            if(a[min]>a[j]){
                min = j;
                flag=1;
            }
        }
        if(flag==1){
            count++;
            flag=0;
        }
        b = a[i];
        a[i] = a[min];
        a[min] = b;
    }
    for(i=0;i<n-1;i++){
        printf("%d ",a[i]);
    }
      printf("%d\n%d",a[n-1],count);
      printf("\n");
    
      return 0;
}

Measured memory_bytes: 2728
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int main() {
	string s;
	cin >> s;
	string stack;
	rep(i, s.size()) {
		if (s.at(i) == '0') {
			stack.push_back('0');
		}
		else if (s.at(i) == '1') {
			stack.push_back('1');
		}
		else if(s.at(i)=='B'&&stack.size()>0){
			stack.pop_back( );
		}
	}
cout << stack << endl;
}

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

int main(){
    string s;
    cin >> s;
    char before = 'i';
    if(s.size() == 1){
        cout << "No" << endl;
        return 0;
    }
    rep(i,s.size()){
        if(before == 'i' && s.at(i)== 'h')before = 'h';
        else if(before == 'h' && s.at(i) == 'i')before = 'i';
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    if(before == 'i')cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N;
   int T,A;
   cin >> N >> T>> A;
   int H[N];
   for(int i = 0; i < N; i++){
      cin >> H[i];
   }
   double diff = DBL_MAX;
   int ind = -1;
   for(int i = 0 ; i < N; i++){
      double curDiff=abs(A-T+H[i]*0.006);
      if(curDiff<diff){
         diff = curDiff;
         ind = i;
      }
   }
   cout << ind+1<<endl;
   return 0;
}


Measured memory_bytes: 256
fn read_str() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).expect("Fail to read input.");
    s
}

fn read_num() -> i32 {
    read_str().trim().parse().expect("Could not parse.")
}

fn read_nums() -> Vec<i32> {
    let s = read_str();
    let a: Vec<&str> = s.split(' ').collect();
    let mut v: Vec<i32> = Vec::new();
    for x in a {
        v.push(x.trim().parse().expect("Could not parse."));
    }
    v
}

fn print_vec<T: std::fmt::Display>(v: Vec<T>) {
    let n = v.len();
    if n > 0 {
        print!("{}", v[0]);
        for i in 1..n {
            print!(" {}", v[i]);
        }
    }
    println!("");
}

fn main() {
    let mut v = read_nums();
    v.sort();
    print_vec(v);
}



Measured memory_bytes: 5040
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define bgn begin()
#define sz size()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second


signed main(){
  int n,m;
  cin >> n >> m;
  V<V<int>> G(n);
  fo(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  V<int> ans(n+5, -1);
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int v = q.front();
    q.pop();
    for(auto nv : G[v]){
      if(ans[nv] != -1)
        continue;
      ans[nv] = v;
      q.push(nv);
    }
 }
 for(int i = 1; i < n; i++){
  if(ans[i] == -1){
    cout << "No" << endl;
    return 0;
  }
 }
 cout << "Yes" << endl;
 for(int i = 1; i< n; i++){
  cout << ans[i]+1 << endl;
 }
}



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

typedef struct ninomae {
    ll pre, suf, sum, ind;
} inanis;

int main() {
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, 0, n) cin >> s[i];
    vector<inanis> p(n);
    rep(i, 0, n) {
        ll mx = -1e18;
        ll cur = 0;
        rep(j, 0, s[i].size()) {
            cur += (s[i][j] == ')' ? 1 : -1);
            mx = max(cur, mx);
        }
        p[i].pre = mx; p[i].sum = cur;
        mx = -1e18; cur = 0;
        for(ll j = s[i].size()-1; j >= 0; j--) {
            cur += (s[i][j] == '(' ? 1 : -1);
            mx = max(cur, mx);
        }
        p[i].suf = mx; p[i].ind = i;
    }
    sort(p.begin(), p.end(), [](auto l, auto r){
        ll ld = l.suf - l.pre;
        ll rd = r.suf - r.pre;
        if(ld >= 0 && rd < 0) return true;
        else if(ld < 0 && rd >= 0) return false;
        else if(ld >= 0 && rd >= 0) return (l.pre < r.pre);
        else return (l.suf > r.suf); 
    });
    ll cur = 0;
    rep(i, 0, n) {
        ll id = p[i].ind;
        rep(j, 0, s[id].size()) {
            cur += (s[id][j] == '(' ? 1 : -1);
            if(cur < 0) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cerr << "final judgement" << endl;
    if(cur == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 65636
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define MAX_N 1001

struct S {
    int y, x;
    S(int y, int x) : y(y), x(x) {}
};

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

int W, H, N;
int X1[MAX_N], Y1[MAX_N], X2[MAX_N], Y2[MAX_N];

int compress(int *x1, int *x2, int w) {
    vector<int> xs;
    xs.push_back(0);
    for (int i = 0; i < N; i++) {
        if (x1[i] - 1 >= 0) xs.push_back(x1[i] - 1);
        xs.push_back(x1[i]);
        xs.push_back(x2[i] - 1);
        if (x2[i] < w) xs.push_back(x2[i]);
    }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    for (int i = 0; i < N; i++) {
        x1[i] = lower_bound(xs.begin(), xs.end(), x1[i]) - xs.begin();
        x2[i] = lower_bound(xs.begin(), xs.end(), x2[i]) - xs.begin();
    }
    return xs.size();
}

int main() {
    while (scanf("%d %d", &W, &H), W || H) {
        scanf("%d", &N);
        for (int i = 0; i < N; i++) {
            scanf("%d %d %d %d", &X1[i], &Y1[i], &X2[i], &Y2[i]);
        }
        int w = compress(X1, X2, W);
        int h = compress(Y1, Y2, H);

        bool F[h][w]; memset(F, 0, sizeof(F));
        for (int n = 0; n < N; n++) {
            for (int i = Y1[n]; i < Y2[n]; i++) {
                for (int j = X1[n]; j < X2[n]; j++) {
                    F[i][j] = true;
                }
            }
        }

        bool used[h][w]; memset(used, 0, sizeof(used));
        int cnt = 0;
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                if (!used[y][x] && !F[y][x]) {
                    cnt++;
                    used[y][x] = true;
                    queue<S> q; q.push(S(y, x));
                    while (!q.empty()) {
                        S s = q.front(); q.pop();
                        for (int i = 0; i < 4; i++) {
                            int ny = s.y + dy[i], nx = s.x + dx[i];
                            if (!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
                            if (!used[ny][nx] && !F[ny][nx]) {
                                used[ny][nx] = true;
                                q.push(S(ny, nx));
                            }
                        }
                    }
                }
            }
        }

        printf("%d\n", cnt);

        //for (int i = 0; i < h; i++) {
        //    for (int j = 0; j < w; j++) {
        //        printf("%d", F[i][j]);
        //    }
        //    puts("");
        //}
        //printf("w: %d, h: %d\n", w, h);
        //for (int i = 0; i < N; i++) {
        //    printf("%d %d %d %d\n", X1[i], Y1[i], X2[i], Y2[i]);
        //}
    }
    return 0;
}

Measured memory_bytes: 3004
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();

    set<char> x(s.begin(), s.end());
    bool ans = false;
    if(x.size() == 2){
        if(x == set<char>{'N', 'S'} || x == set<char>{'W', 'E'})
            ans = true;
    }
    else if(x.size() == 4){
        ans = true;
    }

    if(ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

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

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

    int N, M;
    cin >> N >> M;
    vector<int> imosu(100010);
    int L, R;
    for (int i = 0; i < M; i++) {
        cin >> L >> R;
        imosu[L] += 1;
        imosu[R + 1] -= 1;
    }
    for (int i = 1; i < imosu.size(); i++) {
        imosu[i] = imosu[i - 1] + imosu[i];
    }
    int ans = 0;
    for (auto i : imosu) {
        if (i == M) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 200100
#define INF 100000000
using namespace std;
int main()
{
	int last=0,Max=0,move=0,N;
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		int k;
		scanf("%d",&k);
		if(last>=k)
			move++;
		else
		{
			Max=max(Max,move);
			move=0;
		}
		last=k;
	}
	Max=max(Max,move);
	printf("%d\n",Max);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N, T, c, t, ans=0, i;
  scanf("%d %d", &N, &T);
  for(i=0;i<N;i++){
    scanf("%d %d", &c, &t);
    if(t<=T && ans==0) ans = c;
    if(t<=T && c<ans) ans = c;
  }
  if(ans>0) printf("%d\n", ans);
  else puts("TLE");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	ll n,ans=0;

	cin >> n;
	
	vecll d(n);
	
	forll(i, 0, n)
		cin >> d[i];

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

	ans = max(d[n / 2] - d[n / 2 - 1],(ll)0);

	cout << ans;

}


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

const int maxn=1e5+100;

int dp[maxn],n;
vector <int> v;

int main(){
	scanf("%d",&n);
	int u=1;
	while(u*6<=n){
		u*=6;
		v.push_back(u);
	}
	u=1;
	while(u*9<=n){
		u*=9;
		v.push_back(u);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	v.push_back(1);
	for(int i=0;i<maxn;i++) dp[i]=1e9+10;
	dp[n]=0;
	for(int i=0;i<v.size();i++){
		for(int j=n;j>=0;j--){
			if(v[i]<=j){
				dp[j-v[i]]=min(dp[j-v[i]],dp[j]+1);
			}
		}
	}
	printf("%d",dp[0]);
	return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = [int(i) for i in input()][::-1]

    s = c = 0

    for i in range(len(n)):
        d = n[i] + c
        c = 0

        if (d > 5) or (d == 5 and i + 1 < len(n) and n[i + 1] + 1 > 5):
            s += 10 - d
            c = 1
        else:
            s += d

    print(s + c)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


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

int main(){
  vector<int> abc(3);
  int k,ans;
  cin >> abc[0] >> abc[1] >> abc[2] >> k;
  sort(abc.begin(),abc.end());
  for(int i = 0;i < k;i++){
    abc[2] = abc[2] * 2;
  }
  ans = abc[0] + abc[1] + abc[2];

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = s; i < (int)(n); i++)
#define print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 

int main() {
    int a, b;
    cin >> a >> b;
    int ret = (b-1)/(a-1);
    if ((b-1)%(a-1)) ret++;
    cout << ret << endl; 
    return 0;
}

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

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N;
	static long[][] W;

	public static void main(String[] args) {
		long INF = 1L << 50;
		N = sc.nextInt();
		int S = sc.nextInt() - 1;
		Star[] stars = new Star[N + 1];
		for (int i = 0; i < N; ++i) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			stars[i] = new Star(l, r, i);
		}
		stars[N] = new Star(0, 0, N);
		W = new long[N + 1][N + 1];
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				W[i][j] = Integer.parseInt(sc.next());
			}
		}
		for (int i = 0; i < N; ++i) {
			W[N][i] = W[S][i];
			W[i][N] = INF;
		}
		long[][] dist = new long[N + 1][N + 1];
		for (long[] a : dist) {
			Arrays.fill(a, INF);
		}
		for (int i = 0; i <= N; ++i) {
			for (int j = 0; j <= N; ++j) {
				dist[i][j] = W[i][j];
			}
		}
		for (int i = 0; i <= N; ++i) {
			for (int j = 0; j <= N; ++j) {
				for (int k = 0; k <= N; ++k) {
					if (dist[j][k] > dist[j][i] + dist[i][k]) dist[j][k] = dist[j][i] + dist[i][k];
				}
			}
		}
		Arrays.sort(stars);
		long[] dp = new long[N + 1];
		Arrays.fill(dp, -1);
		dp[0] = 0;
		long ans = 0;
		for (int i = 1; i <= N; ++i) {
			for (int j = 0; j < i; ++j) {
				if (dp[j] == -1) continue;
				long arrival = stars[j].r + dist[stars[j].idx][stars[i].idx];
				if (arrival > stars[i].r) continue;
				long add = stars[i].r - Math.max(stars[i].l, arrival);
				dp[i] = Math.max(dp[i], dp[j] + add);
			}
			ans = Math.max(ans, dp[i]);
		}
		System.out.println(ans);
	}

	static class Star implements Comparable<Star> {
		int l, r, idx;

		public Star(int l, int r, int idx) {
			this.l = l;
			this.r = r;
			this.idx = idx;
		}

		public int compareTo(Star o) {
			return this.r - o.r;
		}
	}
}

Measured memory_bytes: 68116
n, y = map(int, input().split())

flag = False
for i in range(n + 1):
    for j in range(n - i + 1):
            if 10000*i + 5000*j + 1000*(n - i - j) == y:
                print(str(i) + ' ' + str(j) + ' ' + str(n - i - j))
                flag = True
                break
    if flag:
        break
if flag == False:
    print('-1 -1 -1')


Measured memory_bytes: 3060
n, x = gets.split.map(&:to_i)

def pn(n)
	(2**(n+1))-1
end

def loopn(n,x)
	return x == 1 ? 1 : 0 if n == 0
	s = pn(n)
	case x
		when 0..1        then return 0
		when 2...s-1     then return loopn(n-1,x-1)
		when s-1         then return pn(n-1)
		when s           then return pn(n-1)+1
		when s+1...s*2-1 then return pn(n-1)+loopn(n-1,x-s)+1
		else                  return s
	end
end

p loopn(n,x)

Measured memory_bytes: 1788
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])
ans = 0
for h in range(H):
    for w in range(W):
        if A[h][w] != -1:
            ans += c[A[h][w]][1]
print(ans)

Measured memory_bytes: 3316
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

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

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


struct STree {
  const static int maxn = (1 << 13);
  long long a[2 * maxn][2];
  int n;

  void build(int n_) {
    for (n = 1; n < n_; n <<= 1) ;
    assert(n <= maxn);
    for (int i = 1; i < 2 * n; ++i) {
      a[i][0] = a[i][1] = 0;
    }
  }

  long long get() const {
    return a[1][0];
  }

  void add(int v, int l, int r, int l0, int r0, long long toadd) {
    if (l0 >= r || l >= r0) {
      return;
    }

    if (l0 <= l && r <= r0) {
      a[v][0] += toadd;
      a[v][1] += toadd;
      return;
    }

    int m = (l + r) / 2;
    add(2 * v, l, m, l0, r0, toadd);
    add(2 * v + 1, m, r, l0, r0, toadd);

    a[v][0] = max(a[2 * v][0], a[2 * v + 1][0]) + a[v][1];
  }

  void add(int v, long long toadd) {
    //eprintf("add [%d..inf)  %lld\n", v, toadd);
    add(1, 0, n, v, n, toadd);
  }
} tree;

const int maxn = (int) 5e3 + 10, maxm = 210;
int n, m;
int a[maxn];

int b[maxm][maxn];

int read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return 0;
  }
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", b[j] + i);
    }
  }
  return 1;
}

vector<int> st[maxm];
int left[maxm];

void solve() {
  for (int i = 0; i < m; ++i) {
    st[i].clear();
  }
  tree.build(n);

  long long res = 0;
  for (int i = n - 1; i >= 0; --i) {
    for (int j = 0; j < m; ++j) {
      int last = 0;
      while (sz(st[j]) && b[j][st[j].back()] <= b[j][i]) {
        tree.add(st[j].back(), last - b[j][st[j].back()]);
        last = b[j][st[j].back()];
        st[j].pop_back();
      }
      if (sz(st[j])) {
        tree.add(st[j].back(), last - b[j][i]);
      }
      st[j].pb(i);
      tree.add(i, b[j][i]);
    }

    res = max(res, tree.get());
    if (i) {
      tree.add(i, -a[i - 1]);
    }
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 4480
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;

int main(){
    int N,result;
    cin >>N;
    int A[N];
    for (int i = 0;i<N;i++){
        cin >> A[i];
    }
    for (int i = 0;i<N;i++){
        while (A[i]%2 == 0){
            A[i] = A[i] / 2;
            result++;
        }
    }
    cout << result <<endl;
}


Measured memory_bytes: 256
import sys

s = raw_input()
ps = len(s) / 2
gs = len(s) - ps
at = list('g'*gs + 'p'*ps)
top = list(s)
#print 'at : ' + at
w, l = 0, 0
for x in range(len(top)):
	if (at[x] == 'p' and top[x] == 'g'):
		w += 1
	elif (at[x] == 'g' and top[x] == 'p'):
		l += 1
	else:
		pass

print str(w-l)


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n, h;
  cin >> n >> h;

  vll a(n), b(n);
  REP(i, n)
    cin >> a[i] >> b[i];

  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());

  ll ans = 0;
  REP(i, n){
    if(h <= 0 || b[i] <= a[0])
      break;

    h -= b[i];
    ans++;
  }


  if(h > 0){
    ans += h/a[0];
    if(h % a[0] != 0)
      ans += 1;
  }

  cout << ans << endl;


}


Measured memory_bytes: 1792
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

const = 10 ** 9 + 7
MAX = 10 ** 5 + 50

#エラトステネス
L = [1 for i in range(100001)]
L[0] = 0
L[1] = 0
plist = []
for i in range(100001):
	if L[i] == 1:
		plist.append(i)
		c = 2
		while True:
			if i * c <= 100000:
				L[i * c] = 0
				c += 1
			else:
				break

#組み合わせ、逆元前計算
fac = [0] * (MAX)
inv = [0] * (MAX)
finv = [0] * (MAX)
fac[0], fac[1] = 1, 1
inv[1] = 1
finv[0], finv[1] = 1, 1

for i in range(2, MAX):
	fac[i] = fac[i - 1] * i % const
	inv[i] = inv[const % i] * (const - (const // i)) % const
	finv[i] = finv[i - 1] * inv[i] % const

#受け取り、処理
N, M = getlist()
if M == 1:
	print(1)
else:
	D = defaultdict(int)
	while M != 1:
		judge = "No"
		for i in plist:
			if M % i == 0:
				D[i] += 1
				M = M // i
				judge = "Yes"
				break
		if judge == "No":
			D[M] += 1
			break

	data = []
	for i in D:
		data.append(D[i])

	#計算
	ans = 1
	for i in data:
		ans *= fac[i + N - 1] * finv[i] * finv[N - 1]
		ans %= const
	print(ans)

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

int main(){
    while(1){
        int N,M;
        cin>>N>>M;
        if(N==0 && M == 0)  break;
        vector<pair<int,int> > data(N);
        
        for(int i=0; i<N; i++){
            cin>>data[i].second>>data[i].first;
        }

        sort(data.begin(),data.end(),greater<pair<int,int> >());

        int ans = 0;

        for(int i=0; i<N; i++){
            while(1){
                if(M == 0 || data[i].second == 0) break;
                data[i].second--;
                M--;
            }
        }

        for(int i=0; i<N; i++){
            ans += data[i].first*data[i].second;
        }

        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 3104