akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;

string fillZero(string s, int zeros, int direction = 0) { //0のとき右にくっつける 1で左につける 
	if (direction == 1) {
		string z;
		for (int i = 0; i < zeros; i++) {
			z += "0";
		}
		return s + z;
	}
	else if (direction == 0) {
		string z;
		for (int i = 0; i < zeros; i++) {
			z += "0";
		}
		return z + s;
	}
}

string set_with_zero(string s, int length) {// lengh桁になるまでゼロを左につける
	int a = s.size();
	return fillZero(s, length - a, 0);
}

int main() {
	int N, M; cin >> N >> M;
	vector<vector<pii>> pref(N);
	for (int i = 0; i < M; i++) {
		int p, y; cin >> p >> y;
		--p;
		pair<int, int> pa; // year , id
		pa = { y,i };
		pref[p].push_back(pa);
	}
	vvi ans(M, vi(2)); // {pref,order}
	for (int i = 0; i < N; i++) {
		sort(ALL(pref[i]));
		for (int j = 0; j < pref[i].size(); j++) {
			int id = pref[i][j].second;
			ans[id] = { i + 1,j + 1 };
		}
	}

	for (int i = 0; i < M; i++) {
		string s1 = set_with_zero(to_string(ans[i][0]),6);
		string s2 = set_with_zero(to_string(ans[i][1]),6);

		cout << s1 + s2 << endl;
	}
}

Measured memory_bytes: 13844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		long N = Long.parseLong(st.nextToken());
		long M = Long.parseLong(st.nextToken());
		if (N % M == 0) {
			System.out.println("0");
			return;
		}
		if (N > M) {
			N %= M;
		}
		System.out.println(Math.min(N, M - N));
	}
}

Measured memory_bytes: 21972
import java.io.*;

class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        String[] strarr = str.split(" ");
        
        int num1 = Integer.parseInt(strarr[0]);
        int num2 = Integer.parseInt(strarr[1]);
        int num3 = Integer.parseInt(strarr[2]);
        
        int n;
        if(num1 > num2) {
            n = num2;
            num2 = num1;
            num1 = n;
        }
        
        if(num2 > num3) {
            n = num3;
            num3 = num2;
            num2 = n;
        }
        
        if(num1 > num2) {
            n = num2;
            num2 = num1;
            num1 = n;
        }
        
        System.out.println(num1 + " " + num2 + " " + num3);
    }
    
}


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

using namespace std;

int n;
string s, t;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s >> t;
    n = s.size();
    bool flag = true;
    for (int i = 0; i < n; i++)
    {
        if (s[i] != t[i])
        {
            flag = false;
            break;
        }
    }
    cout << (flag ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3612
'use strict'

function Main(input) {
    const lines = input.trim().split("\n");
    const N = parseInt(lines[0]);
    const ST = lines[1].split(" ");
    const S = ST[0]
    const T = ST[1]

    let answer = "";
    for (var i = 0; i < N; i++) {
        answer += S[i] + T[i]
    }
    console.log(answer)
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

  int64_t n;
  cin>>n;

  vector<int64_t> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }

  //値段が上がる前に勝って上がったら売るを繰り返す。
  
  int64_t money=1000;
  int64_t stock=0;
  for(int i=0;i<n;i++){
    if(i<n-1){
    if(a.at(i+1)>a.at(i)){
      int64_t buy = money/a.at(i);
      stock+=buy;
      money-=buy*a.at(i);
//      cout<<"buy="<<a.at(i)<<endl;
    }else if(a.at(i+1)<a.at(i)){
      money+=a.at(i)*stock;
      stock=0;
//      cout<<"sell="<<a.at(i)<<endl;
    }
    }
    else{
      if(stock!=0){
          money+=a.at(i)*stock;
          stock=0;
      }
    }
  }

  cout<<money<<endl;

	return 0;
}

Measured memory_bytes: 3624
s = list(str(input()))
ans = 0
x = ""
for i in range(len(s)):
    if i % 2 == 0:
        x = x + "0"
    else:
        x = x + "1"
xx = ""
for i in range(len(s)):
    if i % 2 == 0:
        xx = xx + "1"
    else:
        xx = xx + "0"
ans1 = 0
for i in range(len(s)):
    if s[i] != x[i]:
        ans1 += 1
ans2 = 0
for i in range(len(s)):
    if s[i] != xx[i]:
        ans2 += 1
if ans1 > ans2:
    print(ans2)
else:
    print(ans1)


Measured memory_bytes: 4012
object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val pw = new java.io.PrintWriter(System.out)
	
	val s, _ = sc.next
	val a, b = sc.nextInt
	val ua = if (sc.next == s) 1 else 0
	val ub = if (ua == 1) 0 else 1
	
	pw.println(s"${a - ua} ${b - ub}")
	pw.flush()
}

Measured memory_bytes: 25556
#include<iostream>
using namespace std;
static const int  MAX = 200000; 

int main()
{
	int R[MAX], n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> R[i];

	int maxv = -10000000000;
	int minv = R[0];

	for(int i = 1; i < n; i++)
	{
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	cout << maxv << endl;

	return 0;
}


Measured memory_bytes: 3888
#include<iostream>
#include<cstring>
#define mod 1000000007
using namespace std;
char arr[1001][1001];
int dp[1001][1001];
int solve(int n,int m)
{
    for(int i=0;i<n;i++)
    {
        if(arr[i][0]!='#')
        {
            dp[i][0]=1;
        }
        else
        {
            break;
        }
        
    }
    for(int i=0;i<m;i++)
    {
        if(arr[0][i]!='#')
        {
            dp[0][i]=1;
        }
        else
        {
            break;
        }
        
    }
    dp[0][0]=1;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<m;j++)
        {
            if(arr[i][j-1]!='#')
            {
                dp[i][j]=dp[i][j-1];
            }
            if(arr[i-1][j]!='#')
            {
                dp[i][j]+=dp[i-1][j];
            }
            dp[i][j]%=mod;
        }
    }
    return dp[n-1][m-1]%mod;
}
int main()
{
    int n,m;
    cin>>n>>m;
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>arr[i][j];
        }
    }
    cout<<solve(n,m);
    // for(int i=0;i<5;i++)
    // {
    //     for(int j=0;j<5;j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<'\n';
    // }
    return 0;
}

Measured memory_bytes: 8472
program main
   implicit none
   integer n,i
   integer ,ALLOCATABLE :: a(:), ans(:)
   read(*,*) n
   allocate (a(n),ans(n))
   read(*,*)a(2:n)
   ans=0
   do i=1,n
      ans(a(i))=ans(a(i))+1
   enddo
   do i=1,n
      write(*,*) ans(i)
   enddo
end program main

Measured memory_bytes: 5784
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
int x[51][10];
int y[51][10];
int l[51][9];
int M[51];
string turns[51];

int main(){
  while(true){
    int N;
    cin >> N;
    if(N == 0){
      break;
    }
    for(int i = 0; i < N + 1; i++){
      cin >> M[i];
      for(int j = 0; j < M[i]; j++){
        cin >> x[i][j] >> y[i][j];
      }
    }

    for(int i = 0; i < N + 1; i++){
      turns[i] = "";
      for(int j = 0; j < M[i] - 1; j++){
        if(j > 0){
          int prev_vec_x = x[i][j] - x[i][j - 1];
          int prev_vec_y = y[i][j] - y[i][j - 1];
          int cur_vec_x = x[i][j + 1] - x[i][j];
          int cur_vec_y = y[i][j + 1] - y[i][j];

          if(prev_vec_x * cur_vec_y - prev_vec_y * cur_vec_x < 0){
            turns[i].push_back('R');
          } else {
            turns[i].push_back('L');
          }

        }
        if(x[i][j] == x[i][j + 1]){
          l[i][j] = abs(y[i][j + 1] - y[i][j]);
        } else {
          l[i][j] = abs(x[i][j + 1] - x[i][j]);
        }
      }
    }

    vector <int> ans;
    for(int i = 1; i < N + 1; i++){
      bool is_same = true;
      if(M[0] == M[i]){
        for(int j = 0; j < M[i] - 1; j++){
          if(l[0][j] != l[i][j]){
            is_same = false;
            break;
          }
        }
        for(int j = 0; j < M[i] - 2; j++){
          if(turns[0][j] != turns[i][j]){
            is_same = false;
            break;
          }
        }

        if(is_same){
          ans.push_back(i);
          continue;
        }

        is_same = true;
        for(int j = 0; j < M[i] - 1; j++){
          if(l[0][j] != l[i][M[i] - j - 2]){
            is_same = false;
            break;
          }
        }
        for(int j = 0; j < M[i] - 2; j++){
          if(turns[0][j] == turns[i][M[i] - j - 3]){
            is_same = false;
            break;
          }
        }

        if(is_same){
          ans.push_back(i);
        }
      }
    }

    /*
    for(int i = 0; i < N + 1; i++){
      cout << turns[i] << endl;
      for(int j = 0; j < M[i] - 1; j++){
        cout << l[i][j] << " ";
      }
      cout << endl;
    }
    */

    for(int i = 0; i < ans.size(); i++){
      cout << ans[i] << endl;
    }
    cout << "+++++" << endl;
  }

  return 0;
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll 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)
#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;

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
    ll n, p, ans = 1;
    cin >> n >> p;
    for(auto a : prime_factor(p)){
        if(a.second >= n){
            ans *= pow(a.first, a.second/n);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
N, M = map(int, input().split())
favorite = []
output = 0

for i in range(N):
    favorite.append(list(map(int, input().split())))

test = {favorite[0][i]:0 for i in range(1, favorite[0][0] + 1)}

for k in favorite:
    for l in test.keys():
        if l in k[1::]:
            test[l] += 1

        if test[l] == N:
            output += 1

print(output)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

ll dp[1001][1001][2] = {};

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<ll>> xyz(N, vector<ll>(3));
    vector<vector<ll>> X(8, vector<ll>(N));
    for (int i = 0; i < N; ++i)
    {
        cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];
    }

    for (int i = 0; i < 8; ++i)
    {
        for (int k = 0; k < N; ++k)
        {
            for (int j = 0; j < 3; ++j)
            {
                if ((i >> j) & 1)
                {
                    X[i][k] += xyz[k][j];
                }
                else
                {
                    X[i][k] -= xyz[k][j];
                }
            }
        }
    }

    for(int i=0;i<8;i++){
        sort(X[i].begin(), X[i].end(), greater<ll>());
    }

    ll ans = 0, v;
    for(int i=0;i<8;i++){
        v = 0;
        for(int j=0;j<M;++j){
            v += X[i][j];
        }
        ans = max(ans, v);
    }

    cout << ans << endl;
}


Measured memory_bytes: 384
import sys

input = sys.stdin.readline
n = int(input())
n_div_list = []
for i in range(1, int(n**0.5)+1):
    if n%i == 0:
        if int(n/i) == i:
            n_div_list.append(i)
        else:
            n_div_list.append(i)
            n_div_list.append(int(n/i))
check = 0
cnt = 0
for n_div in n_div_list:
    if n_div - 1 > check:
        cnt += n_div - 1
    check = n_div
print(cnt)


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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint comb(int n, int m) {
    return perm(n) / (perm(n - m) * perm(m));
}

// End of Template //



int main() {

    int N , M;
    cin >> N >> M;

    cou((N < 10 && M < 10 ? N * M : -1));
}

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

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h) cin >> s[i];

    int ans = 0;
    for(int S = 0; S < (1 << h); S++)
    {
        for(int T = 0; T < (1 << w); T++)
        {
            int cnt = 0;
            rep(i,h) rep(j,w)
            {
                if((1 & (S >> i) || (1 & (T >> j)))) continue;
                if(s[i][j] == '#') cnt++;
            }
            if(cnt == k) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
 
using namespace std;
 
int read()
{
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)) { if(c == '-') f = 0; c = getchar(); }
	while(isdigit(c)) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); }
	return f ? x : -x;
}
 
typedef long long LL;
#define int long long
const int maxn = 1e5 + 10, maxm = maxn << 1;
int mod, to[maxm], nxt[maxm], head[maxn], e, f[maxn], g[maxn], ans[maxn], p[maxn];
vector<int> vec[maxn];
 
void add(int x, int y) 
{
	to[++e] = y; nxt[e] = head[x]; head[x] = e;
	to[++e] = x; nxt[e] = head[y]; head[y] = e;
}
 
void dfs(int u, int fa)
{
	f[u] = 1;
	int tot = 0;
	for(int i = head[u]; i; i = nxt[i])
	{
		int v = to[i];
		if(v == fa) continue;
		dfs(v, u);
		f[u] = (LL)f[u] * (f[v] + 1) % mod;
		p[v] = tot++; vec[u].push_back(f[v]);
	}
}
 
void dp(int u, int fa)
{
	vec[u].push_back(g[u] + 1);
	for(int i = (int)vec[u].size() - 2; i >= 0; --i)
		vec[u][i] = (LL)(vec[u][i] + 1) * vec[u][i + 1] % mod;
	int now = 1; ans[u] = (LL)(g[u] + 1) * f[u] % mod;
	for(int i = head[u]; i; i = nxt[i])
	{
		int v = to[i];
		if(v == fa) continue;
		g[v] = (LL)now * vec[u][p[v] + 1] % mod;
		dp(v, u);
		now = (LL)now * (f[v] + 1) % mod;
	}
}
 
main()
{
 
	int n = read(); mod = read();
	for(int i = 2; i <= n; ++i) add(read(), read());
	dfs(1, 0);
	dp(1, 0);
	for(int i = 1; i <= n; ++i) printf("%lld\n", ans[i]);
 
	return 0;
}

Measured memory_bytes: 19456
A,B,C,X,Y = map(int,input().split(" "))
Z = max(X,Y)
o = Z * 2 * C
for z in range(Z+1):
    x = max(X-z,0)
    y = max(Y-z,0)
    o = min(x*A+y*B+z*2*C,o)

print(o)


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

int main(){
    string S;
    cin >> S;
    for(int i = 0; i < 3; i++){
        if(S.at(i) == S.at(i + 1)){
            cout << "Bad" << endl;
            break;
        }

        else {
            if (i == S.size() - 2){
                cout << "Good" << endl;
            }
            continue;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,a,b;cin>>n>>a>>b;
    vector<vector<ll> >pas(52,vector<ll>(52));
    pas[0][0]=1;
    rep(i,51){
        rep(j,51){
            if(i+j>50)continue;
            pas[i+1][j]+=pas[i][j];
            pas[i][j+1]+=pas[i][j];
        }
    }
    vector<ll>v(n);
    rep(i,n){
        cin>>v[i];
    }
    sort(all(v));
    reverse(all(v));
    vector<ll>rui(n+1);
    ll ma=rui[a];
    ll idx=a;
    rep(i,n){
        rui[i+1]=v[i]+rui[i];
        if(i+1>=a&&i+1<=b){
            if(ma*(i+1)<idx*rui[i+1]){
                ma=rui[i+1];
                idx=i+1;
            }
        }
    }
    ll ans=0;
    REP(i,a,b+1){
        if(ma*i==idx*rui[i]){
            ll k=i;
            ll cnt1=0,cnt2=0;
            rep(j,n){
                if(v[k-1]<v[j])cnt1++;
                if(v[j]==v[k-1])cnt2++;
            }
            ans+=pas[cnt2-(k-cnt1)][k-cnt1];
        }
    }
    cout<<fixed<<setprecision(6)<<(double)ma/(double)idx<<endl;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.*;


public class Main {
    public static void main(String[] args) throws IOException {
        Reader reader=new Reader();
        PrintWriter pw=new PrintWriter(System.out);
        long t=reader.nextLong();
        long count=0;
        for (long i = 100; i <t ; ) {
            i+=i*.01;
            count++;
        }
        System.out.println(count);

        pw.close();
    }
}

 class Reader {
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader() {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException {
        byte[] buf = new byte[64];
        int cnt = 0, c;
        while ((c = read()) != -1) {
            if (c == '\n') break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException {
        int ret = 0;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (neg) return -ret;
        return ret;
    }

    public long nextLong() throws IOException {
        long ret = 0;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (neg) return -ret;
        return ret;
    }

    public double nextDouble() throws IOException {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
        if (neg) return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) buffer[0] = -1;
    }

    private byte read() throws IOException {
        if (bufferPointer == bytesRead) fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException {
        if (din == null) return;
        din.close();
    }
}



Measured memory_bytes: 32560
class BinaryIndexedTree():  #1-indexed
    def __init__(self, n):
        self.n = n
        self.tree = [0 for _ in range(n + 1)]

    def sum(self, idx):
        res = 0
        while idx:
            res += self.tree[idx]
            idx -= idx & -idx
        return res

    def add(self, idx, x):
        while idx <= self.n:
            self.tree[idx] += x
            idx += idx & -idx

    def bisect_left(self, x):
        if x <= 0: return 0
        res, tmp = 0, 2**((self.n).bit_length() - 1)
        while tmp:
            if res + tmp <= self.n and self.tree[res + tmp] < x:
                x -= self.tree[res + tmp]
                res += tmp
            tmp >>= 1
        return res + 1

class RAQandRSQ():
    def __init__(self, n):
        self.bit1 = BinaryIndexedTree(n)
        self.bit2 = BinaryIndexedTree(n)

    def add(self, lt, rt, x):
        self.bit1.add(lt, -x * (lt - 1))
        self.bit1.add(rt, x * (rt - 1))
        self.bit2.add(lt, x)
        self.bit2.add(rt, -x)

    def sum(self, lt, rt):
        rsum = self.bit2.sum(rt - 1) * (rt - 1) + self.bit1.sum(rt - 1)
        lsum = self.bit2.sum(lt - 1) * (lt - 1) + self.bit1.sum(lt - 1)
        return rsum - lsum

import sys
input = sys.stdin.readline

N, Q = map(int, input().split())

R = RAQandRSQ(N)

res = []

for _ in range(Q):
    q, *p = map(int, input().split())
    if q == 0:
        s, t, x = p
        R.add(s, t + 1, x)
    else:
        s, t = p
        res.append(R.sum(s, t + 1))

print('\n'.join(map(str, res)))


Measured memory_bytes: 19392
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const int MAX = 5100000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    COMinit();

    ll X, Y;
    cin >> X >> Y;

    ll ans;

    ll x = 2*X - Y,  y = -X + 2*Y;
    if (x < 0 || y < 0 || x % 3 != 0 || y % 3 != 0) {
        ans = 0;
    } else {
        x /= 3;
        y /= 3;
        ans = COM(x+y, y);
    }

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

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

int main(){
    int x,y;
    cin>>x>>y;
    vector<int> G={0,1,3,1,2,1,2,1,1,2,1,2,1};
    if(G.at(x)==G.at(y)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
-- 最小公倍数を取って割って和の余り

solve :: [Integer] -> Integer
solve numbers =
  let
    numbersLcm = foldr1 lcm numbers
  in
    (sum $ map (\a -> numbersLcm `div` a) numbers) `mod` 1000000007

main = do
  count <- getLine
  numbers <- (map read . words) <$> getLine
  putStrLn $ show $ solve numbers


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

int main() {
  int64_t ans = 4, n, m;
  cin >> n;
  for (int i = 0; i < 5; i++) {
    int64_t a;
    cin >> a;
    if (i == 0) {
      m = a;
    }
    else {
      m = min(m, a);
    }
  }
  if (n%m != 0) {
    ans++;
  }
  ans += n/m;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
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;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    string N;int K;cin>>N>>K;
    int dpk[N.size()+1][5];
    int dpm[N.size()+1][5];
    //dp[決めた桁数][0でない数字の個数](ただしdpkはN以下確定、dpmはN以下未確定)
    REP(i,N.size()+1)REP(j,5)dpk[i][j]=dpm[i][j]=0;
    REPS(i,N.size()){
        int d=N[i-1]-'0';
        if(i==1){
            if(d>=1){
                dpk[1][1]=d-1;
                dpk[1][0]=1;
                dpm[1][1]=1;
            }
            if(d==0){
                dpm[1][0]=1;
            }
        }
        else{
            if(d>=1){
                REP(k,4){
                    dpk[i][k+1]+=dpk[i-1][k]*9+dpm[i-1][k]*(d-1);
                    dpk[i][k]+=dpk[i-1][k]+dpm[i-1][k];
                    dpm[i][k]+=dpm[i-1][k-1];
                }
            }
            if(d==0){
                REP(k,4){
                    dpk[i][k+1]+=dpk[i-1][k]*9;
                  	dpk[i][k]+=dpk[i-1][k];
                    dpm[i][k]+=dpm[i-1][k];
                }
            }
        }
    }
    cout<<dpk[N.size()][K]+dpm[N.size()][K]<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.Comparator;
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        int N = sc.nextInt();
        String[] S = new String[N];
        for(int i = 0; i < N; i++){
            S[i] = sc.next();
        }
        HashMap<String, Integer> mp = new HashMap<>();
        for(int i = 0; i < N; i++){
            mp.put(S[i], mp.getOrDefault(S[i], 0) + 1);
        }
        List<String> res = new ArrayList<>();
        int max_val = 0;
        for(Entry<String, Integer> e: mp.entrySet()){
            max_val = Math.max(max_val, e.getValue());
        }

        for(Entry<String, Integer> e: mp.entrySet()){
            if(max_val == e.getValue()){
                res.add(e.getKey());
            }
        }
        res.sort(Comparator.naturalOrder());
        for(String s: res){
            System.out.println(s);
        }




    }

    private static class FastScanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
				if (ptr < buflen) {
						return true;
				}else{
						ptr = 0;
						try {
								buflen = in.read(buffer);
						} catch (IOException e) {
								e.printStackTrace();
						}
						if (buflen <= 0) {
								return false;
						}
				}
				return true;
		}
		private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
		private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
		public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
		public String next() {
				if (!hasNext()) throw new NoSuchElementException();
				StringBuilder sb = new StringBuilder();
				int b = readByte();
				while(isPrintableChar(b)) {
						sb.appendCodePoint(b);
						b = readByte();
				}
				return sb.toString();
		}
		public long nextLong() {
				if (!hasNext()) throw new NoSuchElementException();
				long n = 0;
				boolean minus = false;
				int b = readByte();
				if (b == '-') {
						minus = true;
						b = readByte();
				}
				if (b < '0' || '9' < b) {
						throw new NumberFormatException();
				}
				while(true){
						if ('0' <= b && b <= '9') {
								n *= 10;
								n += b - '0';
						}else if(b == -1 || !isPrintableChar(b)){
								return minus ? -n : n;
						}else{
								throw new NumberFormatException();
						}
						b = readByte();
				}
		}
		public int nextInt() {
				long nl = nextLong();
				if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
				return (int) nl;
		}
		public double nextDouble() { return Double.parseDouble(next());}
	}
 
}

Measured memory_bytes: 73868
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  bool ans=0;
  string s;
  char t1,t2;
  int a1=0,a2=0;
  cin >> s;

  sort(all(s));
  if(s[0]== s[1] && s[2] == s[3]){
    ans=1;
  }
  if(s[1] == s[2]){
    ans=0;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int A,B; cin >> A >> B;
    if (A+B>=10) cout << "error" << endl;
    else cout << A+B << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * Created by enpingkuang on 2020/9/11 11:30 下午
 */
public class Main {

    static class Node{
        int i;
        int j;
        int value;

        Node(int i,int j,int value){
            this.i = i;
            this.j =j;
            this.value =value;
        }
    }

    private static int[][] dir = {{-1,0},{1,0},{0,-1},{0,1}};

    private static int vis[][] = new int[1003][1003];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int h = scanner.nextInt();
        int w = scanner.nextInt();
        int s = scanner.nextInt();
        int e= scanner.nextInt();
        int ts = scanner.nextInt();
        int te = scanner.nextInt();
        String[] map = new String[h+1];
        for(int i=1;i<=h;i++){
            map[i] =scanner.next();
        }
        for(int i = 1;i<=h;i++){
            for(int j = 1;j<=w;j++){
                vis[i][j] = 100000000;
            }
        }
        Deque<Node> deque = new LinkedList<>();
        deque.add(new Node(s,e,0));
        vis[s][e] = 0;
        while(!deque.isEmpty()){
            Node node = deque.pollFirst();
            int now_i = node.i;
            int now_j = node.j;
            int now_value = node.value;
            for(int i = 0;i<4;i++){
                int tmp_i = dir[i][0] + now_i;
                int tmp_j = dir[i][1] + now_j;
                if(tmp_i <=0 || tmp_i > h || tmp_j <=0 || tmp_j > w)continue;
                if(vis[tmp_i][tmp_j] > now_value  && map[tmp_i].charAt(tmp_j-1) != '#') {
                    deque.addFirst(new Node(tmp_i, tmp_j, now_value));
                    vis[tmp_i][tmp_j] = now_value;
                }
            }
            for(int i = now_i-2;i<=now_i+2;i++){
                if(i <=0 || i > h)continue;
                for(int j = now_j-2;j<=now_j+2;j++){
                    if(j <=0 || j > w)continue;
                    if(vis[i][j] > now_value+1 && map[i].charAt(j-1) != '#') {
                        deque.addLast(new Node(i, j, now_value+1));
                        vis[i][j] = now_value+1;
                    }
                }
            }
        }
        System.out.println(vis[ts][te] == 100000000?-1:vis[ts][te]);
    }
}


Measured memory_bytes: 63480
#include <stdio.h>

int main() {
	int l;
	int N;
	scanf("%d", &N);
	if (N % 2 == 0) {
		printf("%d", N);
	}
	else if (N % 2 == 1) {
		l = N * 2;
		printf("%d", l);
	}
	return 0;
}

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

int main() {

  int N; cin >> N; // 社員数：2≤N≤2×10^5
  map<int,int> M;   // 上司別部下数

  int wk_N;
  rep(i,N-1){
    cin >> wk_N;  // 直属の上司
    M[wk_N]++;
  }

  // 出力
  rep(i,N){
    cout << M[i+1] << endl;
  }

}


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

int main(){
    int a, b, c, d; cin >> a >> b >> c >> d;
    int l = a + b;
    int r = c + d;

    if (l > r) {
        cout << "Left" << endl;
    } else if (l==r){
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e3 + 10;
const int maxm = 2e3 + 10;
const int inf = 1e9 + 9;
const int mod = 998244353;

ll dp[maxn][maxn];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); //C++关同步
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for(int i = 1; i <= c; ++i){
        for(int j = 1; j <= d; ++j){
            if((i > a && j >= b) || (i >= a && j > b)){
                dp[i][j] = (i * dp[i][j - 1] + j * dp[i - 1][j] - dp[i - 1][j - 1] * (i - 1) % mod * (j - 1) % mod + mod) % mod;
            }
        }
    }
    cout << dp[c][d] << '\n';
    return 0;
}


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

void dfs (vector<vector<int>> &vec, vector<vector<int>> &shd, int h, int w) {
  if (h < 0 || h >= vec.size() || w < 0 || w >= vec[0].size()) return;
  else if (!vec[h][w]) return;
  else if (shd[h][w]) return;
  else shd[h][w] = 1;

  dfs(vec, shd, h + 1, w);
  dfs(vec, shd, h , w + 1);
  dfs(vec, shd, h - 1, w);
  dfs(vec, shd, h, w - 1);
  dfs(vec, shd, h + 1, w + 1);
  dfs(vec, shd, h + 1, w - 1);
  dfs(vec, shd, h - 1, w + 1);
  dfs(vec, shd, h - 1, w - 1);

  return;
}
     
int main() {
  int w, h, cou=0;
  vector<int> vec_ans(1000,2147483647);

  cin >> w >> h;

  do {
    int ans=0;
    vector<vector<int>> vec(h, vector<int>(w, 0));
    vector<vector<int>> shd(h, vector<int>(w, 0));
    rep(i, h) rep(j, w) cin >> vec[i][j];

    rep(i, h) rep(j, w) {
      if (!shd[i][j] && vec[i][j]) {
        ++ans;
        dfs(vec, shd, i, j);
      }
    }

    vec_ans[cou] = ans;
    ++cou;
    cin >> w >> h;
  } while (w || h);

  for (int i=0; vec_ans[i] != 2147483647; ++i) {
    cout << vec_ans[i] << endl;
  }
}


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

typedef long long LL;

#define __m int mid=(l+r)>>1;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

#define rep(i,a,b) for(int i = (a); i< (b); i++)
#define pb push_back

#ifdef LOCAL
    #define bug(x) cout<<#x<<" : "<<x<<endl;
#else
    #define bug(x) 
#endif

template<class T>
inline bool read(T &num)  
{
       char in;bool IsN=false;
       while(in=getchar(),in!='-'&&(in<'0'||in>'9'))if(in==EOF)return false;
       in=='-'?(IsN=true,num=0):num=in-'0';
       while(in=getchar(),in>='0'&&in<='9')num=num*10+in-'0';
       return IsN?num=-num:num,true;
}

const int maxn = 2e3+7;
const int inf = 2e9+7;
const int mod = 1e9+7;

int main(){
#ifdef LOCAL
    //freopen("sample.in","r",stdin);
#endif
    ios::sync_with_stdio(false);
    int a,b,c,x,y;
    int ans=inf;
    cin>>a>>b>>c>>x>>y;
    c*=2;
    ans=max(x,y)*c;
    if(x>y)
        ans=min(ans,y*c+(x-y)*a);
    else
        ans=min(ans,x*c+(y-x)*b);
    ans=min(ans,a*x+b*y);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N, K;
  cin >> N >> K;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  ll ret = 0;
  ll left = 0, middle = 0, right = 0;
  rep(i,K){
    middle += v[i];
  }
  REP(i,K,N){
    right += max(v[i],0);
  }

  rep(i,N-K+1){
    ret = max(ret, left + middle + right);
    ret = max(ret, left + 0 + right);

    left += max(v[i],0);
    middle -= v[i];
    if(i+K<N){
      middle += v[i+K];
      right -= max(v[i+K], 0);
    }
  }

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



Measured memory_bytes: 892
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int n;
cin>>n;
vector<ll> a(n);
for(int i=0;i<n;i++)cin>>a[i];
vector<vector<ll>> one(60,vector<ll>(n,0)),zero(60,vector<ll>(n,0));
for(int i=0;i<60;i++){
  for(int j=0;j<n-1;j++){
           if(a[j]&(1ll<<i)){
             one[i][j+1]+=one[i][j]+1;
             zero[i][j+1]+=zero[i][j];
           }
           else {
             one[i][j+1]+=one[i][j];
             zero[i][j+1]+=zero[i][j]+1;
           }
  }
}
ll ans=0;
for(int i=0;i<60;i++){
  ll now=(1LL<<i);
  now%=mod;
  for(int j=1;j<n;j++){
           if(a[j]&(1ll<<i))(ans+=now*zero[i][j]%mod)%=mod;
           else (ans+= now*one[i][j]%mod)%=mod;
  }
}
cout<<ans<<endl;
}



Measured memory_bytes: 286296
S = gets.chomp
T = gets.chomp
ans = nil
(S.length - T.length + 1).times do |i|
    success = true
    ss = S.dup
    T.length.times do |j|
        if S[i+j] == '?' || S[i+j] == T[j]
            ss[i+j] = T[j]
        else
            success = false
            break
        end
    end
    if success
        ss.gsub!('?', 'a')
        ans = ss if !ans || ans > ss
    end
end

puts ans || 'UNRESTORABLE'

Measured memory_bytes: 1788
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

int n, m;
// i本のマッチで作ることができる最大桁数
int dp[10010], a[10];
const int INF = 1e8;
int matti[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

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

  cin >> n >> m;
  REP(i, m) cin >> a[i];
  sort(a, a+m);
  reverse(a, a+m);
  fill(dp, dp+10010,-INF);  
  dp[0] = 0;
  
  REP(i, n){
    if(dp[i] == -INF) continue;
    REP(j, m){      
      dp[i+matti[a[j]]] = max(dp[i]+1, dp[i+matti[a[j]]]);
    }
  }
  cerr << dp[n] << endl;

  int used[10];
  fill(used, used+10, 0);
  int index = n;
  while(index!=0){
    REP(i, m){
      //dp[n - matti[a[i]]] == dp[n]-1 -> そのときのa[i]の文字によって文字列長が増えた
      if(index - matti[a[i]] >= 0 && dp[index - matti[a[i]]] == dp[index]-1){
	index -= matti[a[i]];
	//文字の使った回数
	used[a[i]]++;
	break;
      }
    }
  }
  //あとで上の桁から大きい順に出力
  ROF(i, 9, 0){
    REP(j, used[i]){
      cout << i;
    }
  }

  cout << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
struct edge{
	int to,nxt;
}e[2*maxn];
int fir[maxn],sg[maxn];
int n,tot;
inline void add_edge(int x,int y){e[tot].to=y; e[tot].nxt=fir[x]; fir[x]=tot++;}
void dfs(int now,int fa)
{
	sg[now]=0;
	for(int i=fir[now];~i;i=e[i].nxt)
		if(e[i].to!=fa){
			dfs(e[i].to,now);
			sg[now]^=(sg[e[i].to]+1);
		}
}
int main()
{
	n=read();
	memset(fir,255,sizeof(fir)); tot=0;
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		add_edge(x,y); add_edge(y,x);
	}
	dfs(1,-1);
	if(sg[1])puts("Alice");
	else puts("Bob");
	return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
    int to;
    ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    ll a, b, x;
    cin >> a >> b >> x;
    if (a % x != 0) {
        a = (a / x + 1) * x;
    }
    b = (b / x) * x;
    cout << max(0LL, (b - a) / x + 1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pair;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP_SIZE 51
#define GRAPH 50
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int n,m;
int a[GRAPH], b[GRAPH];

bool graph[GRAPH][GRAPH];
bool visited[GRAPH];

void dfs(int v){
    visited[v] = true;
    for(int v2 = 0; v2 < n; v2++){
        if(graph[v][v2] == false) continue;
        if(visited[v2] == true) continue;
        dfs(v2);
    }
}
int main(){
    scanf("%d %d", &n, &m);

    for(int i = 0; i < m; i++){
        scanf("%d %d", &a[i], &b[i]);
        a[i]--; b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    int ans = 0;

    for(int i = 0; i < m; i++){
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
        for(int j = 0; j < n; j++) visited[j] = false;
        dfs(0);

        bool brigde = false;
        for(int j = 0; j < n; j++) if(visited[j] == false) brigde = true;
        if(brigde) ans++;

        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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


def solve():
    n, m, k = rl()
    A = rl()
    B = rl()
    Ap = [0]
    for a in A:
        nxt = Ap[-1] + a
        if nxt > k:
            break
        Ap.append(nxt)

    best = bisect.bisect_right(Ap, k) - 1
    # print (best)
    bs = 0
    bcount = 0
    for b in B:
        bs += b
        bcount += 1
        if bs > k:
            break
        diff = k - bs
        acount = bisect.bisect_right(Ap, diff) - 1
        best = max(best, acount + bcount)
    print (best)




mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 121484
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12



int main(void)
{
	//変数の宣言
	int a,b,c;
	
	//よく使う変数
	int i, j, k, l;
	int flag = 0;
	int ans = 0;
	int count = 0;
	int temp, temp1, temp2;
	int max, min;
	int len;
	int sum = 0;
	int under, upper, middle;
	int dummy;

	//データの読み込み
	scanf("%d %d %d", &a,&b,&c);
	//scanf_s("%lld", &n);
	
	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理
	
	ans=b+min(a+b+1,c);
	
	//	printf("計算部分終了\n");
	//出力
	
	printf("%d", ans);
	

	//	printf("結果の出力終了\n");
	
	return 0;
	
}



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

int main() {

  int N;
  cin >> N;

  vector<vector<pair<int,int>>> xy(N+1,vector<pair<int,int>>(0));
  for(int i = 0;i < N;i++) {
    int a;
    cin >> a;
    for(int j = 0;j < a;j++) {
      int x,y;
      cin >> x >> y;
      xy.at(i+1).push_back(make_pair(x,y));
    }
  }

  int maxi = 0;
  for(long long bit = 0;bit < (1<<N);bit++) {
    vector<int> c(N+1,0);
    int sum = 0;
    for(int j = 0;j < N;j++) {
      if(1&(bit>>j)) {
        c.at(j+1) = 1;
        sum++;
      }
    }

    bool can = true;
    for(int j = 1;j <= N;j++) {
      for(int k = 0;k < xy.at(j).size();k++) {
        int d = xy.at(j).at(k).first;
        if(c.at(j)) {
          if(c.at(d) != xy.at(j).at(k).second) can = false;
        }
        //else {
        //   if(c.at(d) == xy.at(j).at(k).second) can = false;
        // }
      }
    }

    if(can) maxi = max(maxi,sum);
  }

  cout << maxi << endl;
}




Measured memory_bytes: 256
'''input
1
2
4
8
9
15
'''

a=[]
for i in range(5):
	a.append(int(input()))
k=int(input())
# print(a)

for i in range(5):
	for j in range(5-i):
		if abs(a[i+j]-a[i])>k:
			print(':(')
			exit()
print('Yay!')



Measured memory_bytes: 3064
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())


def solve(T1, T2, A1, A2, B1, B2):
    if (Da := T1 * A1 + T2 * A2) == (Db := T1 * B1 + T2 * B2) or A1 == B1:
        return 'infinity'

    # Aの方が速くなるようそろえる
    if Da < Db:
        A1, A2, Da, B1, B2, Db = B1, B2, Db, A1, A2, Da

    if A1 > B1:
        return 0
    else:
        D1 = (B1 - A1) * T1
        if D1 % (Da - Db):
            return D1 // (Da - Db) * 2 + 1
        else:
            return D1 // (Da - Db) * 2


print(solve(T1, T2, A1, A2, B1, B2))


Measured memory_bytes: 9212