akhauriyash/Code-Regression huggingface dataset:
h,w = map(int,input().split())
array = [[0]*w for i in range(h)]

for i in range(h):
  s = input()
  for j in range(w):
    if s[j] == "#":
      if i-1>=0 and j-1>=0:
        array[i-1][j-1] += 1
        
      if i-1>=0:
        array[i-1][j] += 1
        
      if i-1>=0 and j+1 <= w-1:
        array[i-1][j+1] += 1
        
      if j-1>=0:
        array[i][j-1] += 1
        
      array[i][j] = 9
      
      if j+1 <= w-1:
        array[i][j+1] += 1
        
      if i+1 <= h-1 and j-1>=0:
        array[i+1][j-1] += 1
        
      if i+1 <= h-1:
        array[i+1][j] += 1
      if i+1 <= h-1 and j+1 <=w-1:
        array[i+1][j+1] += 1

for i in range(h):
  for j in range(w):
    if array[i][j] >= 9:
      array[i][j] = "#"
    else:
      array[i][j] = str(array[i][j])
for i in range(h):
  print("".join(array[i]))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
//		int t = sc.nextInt();
//		StringBuilder ans = new StringBuilder();
//		while (--t >= 0) {
		int n = sc.nextInt();
		int numOfNotes = n / 1000;
		if (n % 1000 != 0)
			numOfNotes++;
		System.out.println(1000 * numOfNotes - n);
	}
}
//}


Measured memory_bytes: 35872
N,M = readline.chomp.split.map(&:to_i)
as = []
N.times do |i|
  a = readline.chomp.split.map(&:to_i)[1..-1]
  as << a
end

intersection = as[0]
(1..(N-1)).each do |i|
  intersection &= as[i]
end
puts intersection.size


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;


int main(){
    ll N, M; cin >> N >> M;
    vector<ll> A(N); for(int i = 0; i < N; i++) cin >> A[i];
    ll SUM = 0; for(int i = 0; i < N; i++) SUM += A[i];
    priority_queue<ll> Q;
    for(int i = 0; i < N; i++){
        ll X = A[i];
        while(X > 0){
            ll temp = X / 2;
            Q.push(X - temp);
            X = temp;
        }
    }
    for(int i = 0; i < M; i++) {
        ll x = Q.top(); Q.pop();
        SUM -= x;
    }
    cout << max((ll)0, SUM) << endl;

}


Measured memory_bytes: 35812
#include<iostream>
#include<algorithm>
#include<tuple>

using namespace std;

using Point = pair<int, int>;

Point rps[200];
Point bps[200];
bool usedRps[200];

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

	for (int i = 0; i < N; i++)
	{
		cin >> rps[i].first >> rps[i].second;
	}
	for (int i = 0; i < N; i++)
	{
		cin >> bps[i].first >> bps[i].second;
	}

	sort(begin(rps), begin(rps) + N, [](Point p1, Point p2) { return p2.second < p1.second; });
	sort(begin(bps), begin(bps) + N, [](Point p1, Point p2) { return p1.first < p2.first; });

	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (usedRps[j])
				continue;

			if (rps[j].first < bps[i].first && rps[j].second < bps[i].second)
			{
				ans++;
				usedRps[j] = true;
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t;cin>>t;while(t--)
#define X first
#define Y second
#define pb push_back
#define all(s) s.begin(),s.end()

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

const int MOD = 1e9+7;

void solve(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    ll ans =0;
    if(k){
        ans += min(a,k);
        k -= min(a,k);
    }
    if(k){
        k -= min(b,k);
    }
    if(k){
        ans -= min(c,k);
        k -= min(c,k);
    }
    cout << ans;
}

int main(){
    FIN;   
    // test
    solve();
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rrep(i,n) for (int i = 1; i <= (n); i++)
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

int main() {
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  ll total = 0.0;
  ll ans = 1e18;
  rep(i,100001) {
    total = (ll)2 * c * i + max(x-i,0) * a + max(y-i,0) * b;
    if (total < ans) ans = total;
  }
  cout << ans << endl;
}


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

using namespace std;

const int MAXN = 1e5 + 5;
typedef long long ll;
int n,wmax;
ll mem[104][MAXN];
int we[MAXN],val[MAXN];
ll solve(int i,int w)
{
if(w > wmax) return -1e9;
if(i == n || w == wmax) return 0;

ll &ret = mem[i][w];

if(ret != -1) return ret;

ret = max(solve(i + 1 , w) , solve(i + 1 , w + we[i]) + val[i]);

return ret;



}

int main()
{
  cin >> n >> wmax;
  for(int i = 0 ; i < n ; i++) cin >> we[i] >> val[i];
  memset(mem,-1,sizeof(mem));
  cout << solve(0,0) ;

}

Measured memory_bytes: 81536
def insertion_sort(array, n):
    for i in range(1, n):
        v = array[i]
        j = i - 1
        while j >= 0 and v < array[j]:
            array[j + 1] = array[j]
            j -= 1
        array[j + 1] = v
        print(*array)


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    print(*a)
    insertion_sort(a, n)


if __name__ == '__main__':
    main()




Measured memory_bytes: 5976
X = int(input())

if 400 <= X and X < 600:
    print("8")
elif 600 <= X and X < 800:
    print("7")
elif 800 <= X and X < 1000:
    print("6")
elif 1000 <= X and X < 1200:
    print("5")
elif 1200 <= X and X < 1400:
    print("4")
elif 1400 <= X and X < 1600:
    print("3")
elif 1600 <= X and X < 1800:
    print("2")
elif 1800 <= X and X < 2000:
    print("1")

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100010
#define INF 1e9
int n;
int h[MAXN], dp[MAXN];
class fastio {
public:
    fastio() {
        ios_base::sync_with_stdio(false);
        cout.tie(nullptr);
        cin.tie(nullptr);
    }
} __fastio;
void solve() {
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> h[i];
  }
  for(int i=1; i<n; i++) {
      if(h[i] <= h[i-1]) {
          dp[i] = 1 + dp[i-1];
      }
  }
  int maxi = -INF;
  for(int i=0; i<n; i++) {
      maxi = max(maxi, dp[i]);
  }
  cout << maxi << endl;
}
int main() {
  __fastio;
  solve();
  return 0;
}


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

    int n,x,y;
    cin >> n;
    stack<int>st;
    while(true){

         x = n%(-2);
         n = n/(-2);

        if(x<0)
            x = x+2, n++ ;
        //cout << x << " " << y << endl;
        st.push(x);
        if(n==0)
            break;


    }
    while(!st.empty())
        cout << st.top(),st.pop();

    cout << endl;



return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int p, q, r, a;
  cin >> p >> q >> r;
  a = p + q;
  if (a > (q + r)) {
    a = (q + r);
  }
  if (a > (r + p)) {
    a = (r + p);
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
def myAnswer(N:int,K:int,H:list) -> int:
   H.sort()
   ans = 10**9
   i = 0
   for j in range(K-1,len(H)):
      ans = min(ans,H[j] - H[i])
      i +=1
   return ans


def modelAnswer():
   tmp=1
def main():
   N, K = map(int,input().split())
   H = []
   for _ in range(N):
      H.append(int(input()))
   print(myAnswer(N,K,H[:]))

if __name__ == '__main__':
   main()

Measured memory_bytes: 8280
#include <iostream>
using namespace std;
int gcd(int a,int b){
	return (b==0 ? a : gcd(b,a%b));
}
int main(void){
    int x,y;
    cin>>x>>y;
    int g=gcd(x,y);
    cout<<x+y-g+1<<endl;
}



Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(){
  char s[4];cin>>s;
  int cnt=0;
  string res="Yes";
  for(int i=0;i<4;i++){
    cnt=0;
    for(int j=0;j<4;j++){
      if(s[i]==s[j])cnt++;
    }
    if(cnt!=2){
      res = "No";
      break;
    }
  }
  cout<<res<<endl;
}

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    // 入力
    int n, m;
    cin >> n >> m;
    int a[n];  //学生
    int b[n];
    int c[m];  //チェックポイント
    int d[m];
    rep(i, n) { cin >> a[i] >> b[i]; }
    rep(i, m) { cin >> c[i] >> d[i]; }

    // 処理
    int num = 0;
    rep(i, n) {
        int minV = INF;
        int k;
        rep(j, m) {
            num = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (minV > num) {
                minV = num;
                k    = j;
            }
        }
        cout << k + 1 << endl;
    }
    // 出力

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int,Int>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

Int LCM(Int a, Int b){
    return a*b/GCD(a,b);
}


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

    bool bad = false;
    rep(i,S.size()-1){
        if(S[i]==S[i+1]){
            bad = true;
        }
    }

    if(bad == true){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<string,int> m;
int main(){
    int N;
    string s;
    (cin>>N).get();
    m["AC"]=0;
    m["WA"]=0;
    m["TLE"]=0;
    m["RE"]=0;
    while(N--){
        getline(cin,s);
        m[s]++;
    }
    cout<<"AC x "<<m["AC"]<<endl;
    cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<endl;
    cout<<"RE x "<<m["RE"]<<endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
      	String k = sc.next();
		String hat[] = k.split("");
        int i;
        int ans = 0;
        for(i = 0;i < n;i++){
          if(hat[i].equals("R")){
            ans++;
          }else{
            ans--;
          }
        }
      if(ans > 0){
            System.out.println("Yes");   
      }else{
        	System.out.println("No"); 
      }
 
 
    }
}

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

int main(int argc, char const* argv[])
{
    std::string in_str;
    std::cin >> in_str;

    auto len = in_str.length();
    uint64_t result = 0;
    for(uint64_t bit = 0; bit < (1 << len); ++bit)
    {
        uint64_t sum = 0;
        uint64_t tmp1 = 0;
        for(uint64_t i=0; i < len; ++i)
        {
            if(bit & (1 << i))
            {
                tmp1 = tmp1 * 10 + in_str[i] - '0';
            }
            else {
                sum += tmp1;
                tmp1 = 0;
            }
        }
        sum += tmp1;
        result += sum;
    }
    std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n, sum;
	char num[100];
	int i;
	
	while (scanf("%s", num) != EOF){
		sum = 0;
		for (i = strlen(num); 0 <= i; i--){
			if (num[i - 1] == 'C' && num[i] == 'M'){
				sum += 800;
			}
			else if(num[i - 1] == 'C' && num[i] == 'D'){
				sum += 300;
			}
			else if(num[i - 1] == 'X' && num[i] == 'C'){
				sum += 80;
			}
			else if(num[i - 1] == 'X' && num[i] == 'L'){
				sum += 30;
			}
			else if(num[i - 1] == 'I' && num[i] == 'X'){
				sum += 8;
			}
			else if(num[i - 1] == 'I' && num[i] == 'V'){
				sum += 3;
			}
			else if(num[i] == 'M'){
				sum += 1000;
			}
			else if(num[i] == 'D'){
				sum += 500;
			}
			else if(num[i] == 'C'){
				sum += 100;
			}
			else if(num[i] == 'L'){
				sum += 50;
			}
			else if(num[i] == 'X'){
				sum += 10;
			}
			else if(num[i] == 'V'){
				sum += 5;
			}
			else if(num[i] == 'I'){
				sum += 1;
			}
		}
		printf("%d\n", sum);
	}
	
	return (0);
}

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

int main()
{
    long long t, a, k;
    cin >> t >> a >> k;
    long long t_rem, a_rem;

    t_rem = (k < t) ? t - k : 0;
    a_rem = (t_rem) ? a : (a - k + t < 0) ? 0 : a - k + t;

    cout << t_rem << " " << a_rem << "\n";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
int A, B, C, X;
cin >> A >> B >> C >> X;
int cnt = 0;
for (int a = 0; a < A + 1; ++a) { 
        for (int b = 0; b < B + 1; ++b) { 
                for (int c = 0; c < C + 1; ++c) { 
                        if (500 * a + 100 * b + 50 * c == X) {
                                cnt++;
                        }   
                }   
        }   
}
cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n;
    long long a, b = 1;
    cin >> n;
    for(int i = 0; i < n; i++) {
        scanf("%lld", &a);
        if (a == 0) {
            b = 0;
        } else if(b == -1 || b > (long long)1e18 / a){
            b = -1;
        } else {
            b *= a;
        }
    }
    cout << b << endl;
    return 0;
}

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

int main(){
	int n,r;
	while(cin >> n >> r, n, r){
		int data[50], tmp[50];
		for(int i=0; i<n; i++){
			data[i]	= n-i;
			tmp[i] = n-i;
		}
		for(int i=0; i<r; i++){
			int p,c;
			cin >> p >> c;
			for(int j=0; j < p+c-1; j++){
				if(j<p-1){
					tmp[j+c] = data[j];
				}else{
					tmp[j-p+1] = data[j];
				}
			}
			for(int j=0; j<n; j++){
				data[j] = tmp[j];	
			}
		}
		cout << data[0] << endl;
	}
}

Measured memory_bytes: 3084
#include<stdio.h>
int main()
{
	int n,a=0,b;
	char N[200000+1];
	scanf("%s",N);
	while(N[a]!='\0'){
		n=N[a]-'0';
		b=b+n;
		a++;
	}
	if(b%9==0){
		printf("Yes");
	}
	else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1880
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,M,i,j;cin>>N>>M;
  vector<vector<P>>X(N,vector<P>());
  vector<P>ans(M);
  REP(i,M){
    cin>>ans.at(i).F>>j;X.at(ans.at(i).F-1).push_back(P(j,i));
  }
  REP(i,N){
    sort(ALL(X.at(i)));
    REP(j,X.at(i).size())ans.at(X.at(i).at(j).S).S=j+1;
  }
  REP(i,M)printf("%06ld%06ld\n",ans.at(i).F,ans.at(i).S);
  return 0;
}

Measured memory_bytes: 8576
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

#define int LL

const int MAX_V = 101010;

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

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

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

void bfs(int s) {
	REP(i, MAX_V)level[i] = -1;
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		REP(i, G[v].size()) {
			edge &e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

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

int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		bfs(s);
		if (level[t] < 0)return flow;
		REP(i, MAX_V)iter[i] = 0;
		int f;
		while ((f = dfs(s, t, INF)) > 0) {
			flow += f;
		}
	}
}


int n;
int a[101010];
LL sum;

signed main() {
	cin >> n;
	REP(i, n) {
		cin >> a[i];
		if (a[i] > 0)sum += a[i];
	}
		int s = 1234, t = 1235;
	REP(i, n) {
		if (a[i] <= 0) {
			add_edge(s, i + 1, -a[i]);
		}
		else {
			add_edge(i + 1, t, a[i]);
		}
	}
	for (int i = 1; i <= n; i++) {
		int num = 2;
		while (i*num <= n) {
			add_edge(i, i*num,10e9+123);
			num++;
		}
	}
	cout << sum - max_flow(s, t) << endl;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;


int main(){
  int N;
  LLI K;
  while(cin >> N >> K){
    vector<int> A(N), F(N); cin >> A >> F;

    sort(ALL(A));
    sort(ALL(F));

    dump(A, F);


    auto check =
      [&](LLI X){
        LLI t = K;
        vector<LLI> b(N);
        REP(i,N){
          b[i] = X / F[i];
        }
        sort(ALL(b));

        REP(i,N){
          if(b[i] < A[i]){
            t -= A[i]-b[i];
          }
        }

        return t >= 0;
      };


    

    LLI lb = -1, ub = 1LL<<60;
    while(abs(lb-ub) > 1){
      LLI mid = (lb+ub) / 2;

      if(check(mid)){
        ub = mid;
      }else{
        lb = mid;
      }
    }
    

    LLI ans = ub;

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3456
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;


//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

int main() {
	int X;cin >> X;
	if(X>=30) cout << "Yes" << endl;
	else cout << "No" << endl;
}	

Measured memory_bytes: 11020
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

int N, W;
VI v(101), w(101);
VVI dp(101, VI(10001, -1));
int64_t val(const int i, const int u){
    if (dp[i][u] != -1) return dp[i][u];
    if (i == N) return 0;
    else if (u < w[i]) return dp[i][u] = val(i+1, u);
    else return dp[i][u] = max(val(i+1, u), val(i+1, u - w[i]) + v[i]);
}

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

cin >> N >> W;
rep(i, 0, N) cin >> v[i] >> w[i];

cout << val(0, W) << endl;

}

// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり




Measured memory_bytes: 11172
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace EXAWIZARDS2019C
{
    public partial class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var Q = ss.Next(int.Parse);
            var S = "0" + ss.Next() + "0";
            var TD = ss.Next(2, Q);

            var left = 1;
            var right = N + 1;

            foreach (var td in TD.Reverse())
            {
                if (td[1][0] == 'L')
                {
                    if (td[0][0] == S[left]) left++;
                    if (td[0][0] == S[right]) right++;
                }
                if (td[1][0] == 'R')
                {
                    if (td[0][0] == S[left - 1]) left--;
                    if (td[0][0] == S[right - 1]) right--;
                }
            }

            sw.WriteLine(right - left);
            //---------------------------------
        }
    }

    public class StreamScanner
    {
        static readonly char[] Separator = {' '};
        readonly StreamReader streamReader;

        string[] line = new string[0];
        int index = 0;

        public StreamScanner(Stream stream)
        {
            this.streamReader = new StreamReader(stream);
        }

        public string Next()
        {
            return Next(s => s);
        }

        public string[] Next(int x)
        {
            return Next(s => s, x);
        }

        public string[][] Next(int x, int y)
        {
            return Next(s => s, x, y);
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (index < line.Length) return parser(line[index++]);
            index = 0;
            line = streamReader.ReadLine()?.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }

    public partial class Program
    {
        static void Main()
        {
            Excute(Console.OpenStandardInput(), Console.OpenStandardOutput());
        }

        public static void Excute(Stream input, Stream output)
        {
            var ss = new StreamScanner(input);
            var sw = new StreamWriter(output);
            new Program().Solve(ss, sw);
            sw.Flush();
        }
    }
}

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

using namespace std;

#define ll long long 
#define Fastest ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

int main()
{
	Fastest
	
	vector<pair<int,int>>v;
	
	int n, m, a , b;
	
	cin >> n >> m;
	
	for(int i = 0; i < n; i++) 
	{
	    cin >> a >> b;
	    
	    v.push_back(make_pair(a,b));
	}
	
	sort(v.begin(), v.end());
	
	ll sum = 0;
	
	for(int i = 0; i < n; i++)
	{
		if(v[i].second <= m)
		{
			sum += v[i].first*1LL*v[i].second;
			m-=v[i].second;
		}
		else
		{
			sum += v[i].first*1LL*m;
			break;
		}
	}
	
	
	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


signed main(){
	int A, B;
	cin >> A >> B;

	if(B%A==0) cout << A+B << endl;
	else cout << B-A << endl;

	return 0;
}

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

east = S.count("E")
west = 0

ans = 10 ** 18
for s in S:
    if s == "W":
        ans = min(ans, east + west)
        west += 1
    else:
        east -= 1
        ans = min(ans, east + west)
print(ans)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}
ll cnt(ll x){
    ll res = 0;
    while(x%2==0){
        x/=2;
        res++;
    }
    return res;

}

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

    ll n;
    cin>>n;
    Vec a(n);
    rep(i,n)cin>>a[i];
    ll ans=0;

    rep(i,n){
        ans += cnt(a[i]);
    }

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    ll A[X], B[Y], C[Z];
    rep(i, X) scanf("%lld", A+i);
    rep(i, Y) scanf("%lld", B+i);
    rep(i, Z) scanf("%lld", C+i);
    vector<ll> AB;
    rep(i, X)rep(j, Y) AB.push_back(A[i]+B[j]);
    sort(AB.begin(),AB.end(),greater<ll>());
    vector<ll> ABC;
    rep(i, min(X*Y, K))rep(j, Z) ABC.push_back(AB[i]+C[j]);
    sort(ABC.begin(),ABC.end(),greater<ll>());
    rep(i, K) printf("%lld\n", ABC[i]);
    return 0;
}

Measured memory_bytes: 43108
#include<cstdio>
struct with {
	int x, y, cost;
} ar[66];
int L;
bool binary[30];
int n,m,base;
int ex[30];
void ar_push(int x, int y, int cost) {
	ar[++m].x = x; ar[m].y = y; ar[m].cost = cost;
}
int main() {
	scanf("%d", &L);
	base=1;
	while (L > 0) {
		ex[n] = base;
		binary[n++] = L % 2;
		L /= 2; base *= 2;
	}
	int i;
	base /= 2;
	int exx = base;
	for (i = 1; i < n; i++) {
		exx /= 2;
		ar_push(i, i + 1, 0);
		ar_push(i, i + 1, exx);
	}
	for (i = n - 2; i >= 0; i--) {
		if (binary[i]) {
			ar_push(1, n - i, base);
			base += ex[i];
		}
	}
	printf("%d %d\n", n, m);
	for (i = 1; i <= m; i++) {
		printf("%d %d %d\n", ar[i].x, ar[i].y, ar[i].cost);
	}
	return 0;
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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



int main(void) {
	
	while (1) {
		long long int n, m;
		long long int dp[11] = {};
		long long int d, p;
		long long int total = 0;

		cin >> n >> m;
		if (n == 0) {
			break;
		}
		FOR(i, 0, n-1) {
			cin >> d >> p;
			dp[p] += d;
		}
		RFOR(i, 10, 0) {
			if (m >= dp[i]) {
				m -= dp[i];
				dp[i] = 0;
			}
			else {
				dp[i] -= m;
				m = 0;
				break;
			}
		}
		FOR(i, 0, 10) {
			total += dp[i] * i;
		}
		cout << total << endl;
	}
	
}


Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int ans = 0;

void search(string s,int n,int a,int b, int c){
  if(s.size() != 0 && a > 0 && b > 0 && c > 0){
    int comp = atoi(s.c_str());
    if(comp <= n) ans++;
  }
  
  if(s.size() == 9) return;
  
  s.push_back('3');
  search(s,n,a+1,b,c);
  s.pop_back();
  
  s.push_back('5');
  search(s,n,a,b+1,c);
  s.pop_back();
  
  s.push_back('7');
  search(s,n,a,b,c+1);
  s.pop_back();
}

int main(){
  int n;
  cin >> n;
  string s;
  search(s,n,0,0,0);
  
  cout << ans << endl;
}


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

void doReplace(int a, int b, string &p, string &str) {
    str.replace(a, b - a + 1, p);
}

void doReverse(int a, int b, string &str) {
    string tmp = str.substr(a, b - a + 1);
    int n = tmp.size();
    for (int i = 0; i < n; i++) {
        str[i + a] = tmp[n - i - 1];
    }
}

void doPrint(int a, int b, string str) {
    cout << str.substr(a, b - a + 1) << endl;
}

int main(int argc, char const *argv[]) {
    string str;
    cin >> str;

    int q;
    cin >> q;

    string imperativeWord;
    int a, b;
    string p;

    for (int i = 0; i < q; i++) {
        cin >> imperativeWord;
        if (imperativeWord == "replace") {
            cin >> a >> b >> p;
            doReplace(a, b, p, str);
        } else if (imperativeWord == "reverse") {
            cin >> a >> b;
            doReverse(a, b, str);
        } else {
            // print
            cin >> a >> b;
            doPrint(a, b, str);
        }
    }
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define pp 1000000007
#define pb push_back
									//nestedcode
ll dp[100005];

 int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0); cout.tie(0);
  	ll n,w,ww,v,i,j,ans=0;
    cin>>n>>w;
    
    for(i=1;i<100005;i++){
        dp[i] = LLONG_MAX -w*n - 5;
      
    }
    dp[0] = 0;
    for(i=0;i<n;i++){
    	cin>>ww>>v;
    	for(j=100005-v;j>=0;j--){
    	  
    		dp[j+v] = min(dp[j+v],dp[j]+ww);
    	//	cout<<j<<" "<<dp[j]<<endl;
		}
	}
	
	for(i=0;i<100005;i++){
	   // cout<<dp[i]<<" ";
		if(dp[i]<=w){
			ans = i;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include <stdlib.h>

int main(void)
{
	int s_length,left=0,mid,i,j, q_length,C = 0;
	scanf("%d", &s_length);
	int right=s_length;
	int *s, *q;
	s = (int *)malloc(sizeof(int) * s_length);
	for(i = 0;i < s_length;i++){
		scanf("%d", &s[i]);
	}
	
	scanf("%d", &q_length);
	
	q = (int *)malloc(sizeof(int) * q_length);
	for(i = 0;i < q_length;i++){
		scanf("%d", &q[i]);
	}
	
	
	for(i=0;i<q_length;i++){
		while(left<right){
			mid=(left+right)/2;
			if(s[mid]==q[i]){
				C++;
				break;
			}
			else if(s[mid]>q[i]){
				right=mid;
			}
			else{
				left=mid+1;
			}
		}
		right = s_length;
				left = 0;
	}
	printf("%d\n",C);
	return(0);
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll dp[100005][3];
ll max(ll x, ll y)
{
    if(x>y)
        return x;
    else
        return y;
}
ll max3(ll x, ll y, ll z)
{
    if(x>=y && x>=z)
        return x;
    else if(y>x && y>z)
        return y;
    else
        return z;
}
ll f(ll a[],ll b[],ll c[],ll n,ll i)
{
    if(n<0)
        return 0;
    if(dp[n][i]!=-1)
            return dp[n][i];
    if(i==1)
    {
        dp[n][i]=0;
        dp[n][i]+=max(b[n]+f(a,b,c,n-1,2),c[n]+f(a,b,c,n-1,3));
    }
    if(i==2)
    {
        dp[n][i]=0;
        dp[n][i]+=max(a[n]+f(a,b,c,n-1,1),c[n]+f(a,b,c,n-1,3));
    }
    if(i==3)
    {
        dp[n][i]=0;
        dp[n][i]+=max(a[n]+f(a,b,c,n-1,1),b[n]+f(a,b,c,n-1,2));
    }
    return dp[n][i];
}
int main()
{
    ll n,i,j;
    cin>>n;
    ll a[n],b[n],c[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    //a=1,b=2,c=3
    for(i=0;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
            dp[i][j]=-1;
        }
    }
    ll x=max3(a[n-1]+f(a,b,c,n-2,1),b[n-1]+f(a,b,c,n-2,2),c[n-1]+f(a,b,c,n-2,3));
    cout<<x;
   return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int d;
vector<int> c(26);
vector<vector<int>> s(400, vector<int>(26));

int get_score(vector<int> t){
    int ans = 0;
    vector<int> last(26, 0);
    rep(i, d){
        ans += s[i][t[i]];
        rep(j, 26){
            if(t[i] == j)last[j] = i+1;
            ans -= c[j] * ((i+1)-last[j]);
        }
    }
    return ans;
}

int main() {
    cin >> d;
    rep(i, 26)cin >> c[i];
    rep(i, d)rep(j, 26)cin >> s[i][j];
    //-----code------// 
    vector<P> a;
    rep(i, 26){
        int now = 0;
        rep(j, d)now += s[j][i];
        a.push_back({now, i+1});
    }
    sort(rall(a));
    vector<int> t(d, a[0].second);
    while(clock() < 1950000){
        int D = rand() % d, q = rand() % 26;
        int old = t[D], olds = get_score(t);
        t[D] = q;
        if(get_score(t) < olds)t[D] = old;
    }
    rep(i, d)cout << t[i]+1 << endl;
}


Measured memory_bytes: 3708
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#ifdef RUBICK
#include "dbg.h"
#else
#define dbg(exp) /* nop; */
#endif

using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;

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

    auto pos = s.find(t);
    if (pos != string::npos) {
        for (auto c : s) {
            if (c == '?')
                cout << 'a';
            else
                cout << c;
        }
        cout << '\n';
        return 0;
    }

    reverse(begin(t), end(t));

    int n = s.size();

    for (int b = n-1; b >= 0; b--) {
        string ans = s;
        bool ok = true;
        for (int i = 0; i < int(t.size()); i ++) {
            if (ans[b-i] == '?' || ans[b-i] == t[i])
                ans[b-i] = t[i];
            else
                ok = false;
        }

        if (!ok)
            continue;

        for (auto c : ans) {
            if (c == '?')
                cout << 'a';
            else
                cout << c;
        }
        cout << '\n';
        return 0;
    }

    puts("UNRESTORABLE");

    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
void inline swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void inline swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

int n, k, q;
const int MAX = 100001;
int score[MAX];


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

	REP1C(i, n)
		score[i] = -q + k ;

	REP(i, q)
	{
		int a;
		cin >> a;
		++score[a];
	}

	REP1C(i, n)
	{
		if (score[i] > 0)
			cout << "Yes";
		else
			cout << "No";
		cout << endl;
	}

}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void) {
	int t[100] = {};
	int r,c,i,j,k;
	scanf("%d %d\n",&r,&c);
	for(;r;r--){
		for(i=0,k=0;i<c;i++){
			scanf("%d",&j);
			t[i]+=j;
			k+=j;
			printf("%d ",j);
		}
		printf("%d\n",k);
	}
	for(i=0,k=0;i<c;i++){
		k+=t[i];
		printf("%d ",t[i]);
	}
	printf("%d\n",k);
	return 0;
}

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

using namespace std;

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

int main() {
  int n;
  while (cin >> n, n) {
    int a[n + 1][4], p[n], t[n], res = 1e9;
    a[0][0] = 0;
    a[0][1] = -1;
    a[0][2] = -1;
    a[0][3] = -1;
    rep (i, n) cin >> p[i] >> t[i];
    rep (i, n) {
      a[i + 1][0] = -1;
      if (a[i][0] != -1) {
	if (p[i] <= t[i]) {
	  a[i + 1][1] = p[i];
	} else {
	  a[i + 1][1] = -1;
	}
      } else {
	bool f = false;
	a[i + 1][1] = 1e9;
	if (a[i][1] != -1 && 2 * p[i - 1] + p[i] <= t[i] - t[i - 1]) {
	  a[i + 1][1] = min(a[i + 1][1], p[i - 1] + p[i] + a[i][1]);
	  f = true;
	}
	if (a[i][2] != -1 && 3 * p[i - 1] + p[i] <= t[i] - t[i - 1]) {
	  a[i + 1][1] = min(a[i + 1][1], p[i - 1] + p[i] + a[i][2]);
	  f = true;
	}
	if (a[i][3] != -1 && 4 * p[i - 1] + p[i] <= t[i] - t[i - 1]) {
	  a[i + 1][1] = min(a[i + 1][1], p[i - 1] + p[i] + a[i][3]);
	  f = true;
	}
	if (!f) a[i + 1][1] = -1;
      }
      if (a[i][1] != -1 && 2 * abs(p[i - 1] - p[i]) <= t[i] - t[i - 1]) {
	a[i + 1][2] = abs(p[i - 1] - p[i]) + a[i][1];
      } else {
	a[i + 1][2] = -1;
      }
      if (a[i][2] != -1 && 3 * abs(p[i - 1] - p[i]) <= t[i] - t[i - 1]) {
	a[i + 1][3] = abs(p[i - 1] - p[i]) + a[i][2];
      } else {
	a[i + 1][3] = -1;
      }
      if (a[i + 1][1] == -1 && a[i + 1][2] == -1 && a[i + 1][3] == -1) {
	cout << "NG " << i + 1 << endl;
	goto next;
      }
    }
    if (a[n][1] != -1) res = min(res, a[n][1] + p[n - 1]);
    if (a[n][2] != -1) res = min(res, a[n][2] + p[n - 1]);
    if (a[n][3] != -1) res = min(res, a[n][3] + p[n - 1]);
    cout << "OK " << res << endl;
  next:;
  }
  return 0;
}

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

constexpr int MAX_N = (1<<20);
constexpr int MOD = 1e9+7;
ll n,k;

ll f[MAX_N], invf[MAX_N];

ll modpow(ll x, ll y)
{
	ll res = 1;
	while(y > 0){
		if(y&1) res = (res * x)%MOD;
		x = x*x%MOD;
		y>>=1;
	}
	return res;
}

void init()
{
	f[0]=1;
	for(int i=1;i<=n;++i) f[i]=f[i-1]*i%MOD;
	invf[n]=modpow(f[n],MOD-2);
	for(int i=n-1;i>=0;--i) invf[i]=invf[i+1]*(i+1)%MOD;
}

ll nCk(int N, int K)
{
	return (f[N]*invf[N-K])%MOD*invf[K]%MOD;
}

void solve()
{
	init();
	ll res = 0;
	const int L = min(n-1, k);
	for(int i=0;i<=L;++i){
		// distributing i into N-i rooms
		res = (res + nCk(n,i)*nCk(n-i+i-1,i)) % MOD; 
	}
	cout << res;
}

int main()
{
	cin >> n >> k;
	solve();
	return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long

string a, b;
int32_t main() {
	int ans = 0;
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> a >> b;
	for(int i = 0; i < 3; ++i) {
		if (a[i] == b[i]) ++ans;
	}
	cout << ans;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  queue<pair<int, int>> que;
  vector<vector<int>> count(H, vector<int>(W, -1));
  
  vector<vector<char>> maze(H, vector<char>(W, ' '));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> maze.at(i).at(j);
      if (maze.at(i).at(j) == '#') {
        que.push(pair<int, int>(i, j));
        count.at(i).at(j) = 0;
      }
    }
  }
  
  int dx[] = {1, -1, 0, 0};
  int dy[] = {0, 0, 1, -1};
  int result = 0;
  
  while (!que.empty()) {
    pair<int, int> pos = que.front();
    que.pop();
    
    for (int i = 0; i < 4; i++) {
      int nx = pos.first + dx[i];
      int ny = pos.second + dy[i];
      
      if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if (maze.at(nx).at(ny) == '#') continue;
      if (count.at(nx).at(ny) != -1) continue;
      
      count.at(nx).at(ny) = count.at(pos.first).at(pos.second) + 1;
      result = max(result, count.at(nx).at(ny));
      que.push(pair<int, int>(nx, ny));
    }
  }
  
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 13328
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> m(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> m[i];
    sum += m[i];
  }
  int mini = *min_element(all(m));
  cout << n + (x - sum) / mini << endl;
  return 0;
}

Measured memory_bytes: 256