akhauriyash/Code-Regression huggingface dataset:
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var c = input[N].split(" ").map(i => parseInt(i));
  c.sort(function(a,b){return b-a});
  input.splice(N,input.length-N);
  input.shift();
  var e = input.map(i => i.split(" ").map(i => parseInt(i)));
  var map = new Array(N+1);
  for(var i=0;i<N+1;i++){
    var tmp=[i,0];
    map[i]=tmp;
  }
  for(var i=0;i<N-1;i++){
    map[e[i][0]][1]++;
    map[e[i][1]][1]++;
  }
  map.sort(function(a,b){
    if (a[1] < b[1]) return 1;
    if (a[1] > b[1]) return -1;
  return 0;})
  stem=map[0][0];
  var anssub=new Array(N).fill(-1);
  anssub[stem-1]=0;
  var queue=[stem];
  var num=1;
  while(queue.length!=0){
    for(var i=0;i<N-1;i++){
      if(e[i][0]==queue[0]){
        if(anssub[e[i][1]-1]==-1){
          anssub[e[i][1]-1]=num;
          num++;
          queue.push(e[i][1]);
        }
      }else if(e[i][1]==queue[0]){
        if(anssub[e[i][0]-1]==-1){
          anssub[e[i][0]-1]=num;
          num++;
          queue.push(e[i][0]);
        }
      }
    }
    queue.shift();
  }
  var anssub2=new Array();
  for(var i=0;i<N;i++){
    anssub2[i]=c[anssub[i]];
  }
  var ans2=[0];
  for(var i=0;i<N-1;i++){
    ans2[0]+=Math.min(anssub2[e[i][0]-1],anssub2[e[i][1]-1]);
  }
  var ans3=anssub2.join(" ");
  ans2.push(ans3);
  var ans=ans2.join("\n");

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 16740
/*
 * 
 * */

#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout << #x << ":\t" << x << endl
#define _ << " " <<

#define s_time clock_t time_start = clock()
#define t_time cout << double(clock() - time_start) / 1000 << endl

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int N = 2e5 + 3;

int n, h[N], a[N];
ll seg[N << 1], res;

void update(int v, ll x) {
	for (seg[v += n] = x; v > 1; v >>= 1) {
		seg[v >> 1] = max(seg[v], seg[v ^ 1]);
	}
}

ll query(int l, int r) {
	ll res = 0;
	for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
		if (l & 1) res = max(res, seg[l++]);
		if (r & 1) res = max(res, seg[--r]);
	}
	return res;
}

int main(int argc, char** argv) {
//	mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> h[i];
	for (int i = 1; i <= n; ++i) cin >> a[i];
	
	res = 0;
	for (int i = 1; i <= n; ++i) {
		ll mx = query(0, --h[i]);
		update(h[i], a[i] + mx);
		res = max(res, a[i] + mx);
	}
	cout << res;
	
	return 0;
}

/*
 * 
 * */


Measured memory_bytes: 4992
n = int(input())
*bLst, = input().split()
iLst = bLst[:]

for i in range(n):
    for j in range(n-1,i,-1):
        if bLst[j][1] < bLst[j-1][1]:
            bLst[j],bLst[j-1] = bLst[j-1],bLst[j]

print(*bLst)
print("Stable")

for i in range(n):
    min = i
    for j in range(i,n):
        if iLst[j][1] < iLst[min][1]:
            min = j
    iLst[i],iLst[min] = iLst[min],iLst[i]

print(*iLst)
if bLst == iLst:
    print("Stable")
else:
    print("Not stable")


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
// const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

ll a[100010];
map<ll,int> ma;

int main () {

    int n;cin>>n;
    ll t;cin>>t;

    rep(i,n) cin>>a[i];

    ll cur_min = a[0];
    ll cur_dif=0;

    for (int i=1;i<n;i++) {
        if (a[i]<cur_min) {
            cur_min=a[i];
        } else {
            if (a[i]-cur_min<cur_dif) continue;
            ma[a[i]-cur_min]++;
            cur_dif=a[i]-cur_min;
        }
    }

    cout<<ma[cur_dif]<<endl;

}

Measured memory_bytes: 7296
import fractions
n,x=map(int,input().split())
y=list(map(int,input().split()))
lis=[]
if n==1:
  lis.append(abs(x-y[0]))
else:
  for i in range(n-1):
    lis.append(fractions.gcd(abs(x-y[i]),abs(x-y[i+1])))
print(min(lis))

Measured memory_bytes: 16244
from collections import deque

n, k = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))

loop = []
visited = set()
s = set([1])
loop_creating = False
last = 1

while True:
  if loop_creating and len(visited) == 0:
    break
  
  if k == len(s) - 1:
    print(last)
    exit(0)

  nex = a[last - 1]

  if nex in visited:
    visited.remove(nex)
    loop.append(nex)
    loop_creating = True
  elif nex in s:
    visited.add(nex)
  else:
    s.add(nex)

  last = nex

rem = k - len(s)
print(loop[rem % len(loop)])


Measured memory_bytes: 42616
//#define _USE_MATH_DEFINES
//#include <math.h>
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    
    string T;
    while(cin >> T){
        if(T == "-") break;
        int m = 0;
        cin >> m;
        for(int i = 0; i < m; i++){
            int a = 0;
            cin >> a;
            T = T.substr(a) + T.substr(0,a);
        }
        cout << T << endl;
    }
}



Measured memory_bytes: 3220
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

s64 N, A, B, C, D;
map<s64, s64> m;

s64 dfs(s64 n)
{
    if (n == 0) return 0;
    if (n == 1) return D;
    if (m.count(n) > 0) return m[n];

    s64 ret = 1e18;
    if (n < ret / D) ret = n * D;
    vs64 temp(6);
    static const s64 div[3] = {2, 3, 5};
    s64 c[3] = {A, B, C};
    rep (i, 3)
    {
        temp[2 * i] = abs(n - (n / div[i]) * div[i]) * D + c[i] + dfs(n / div[i]);
        temp[2 * i + 1] = abs(n - CEIL(n, div[i]) * div[i]) * D + c[i] + dfs(CEIL(n, div[i]));
    }

    rep (i, 6) ret = min(ret, temp[i]);
    m[n] = ret;
    return ret;
}

void solve()
{
    cin >> N >> A >> B >> C >> D;

    m.clear();
    cout << dfs(N) << "\n";
}

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

    int t;
    cin >> t;
    rep (CASE, t)
    {
        solve();
    }

    return 0;
}



Measured memory_bytes: 4372
#include<iostream>
#include<iomanip>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <numeric>
typedef long long int ll;
using namespace std;

int main(){
	ll K,N,b,c,d;
	vector<ll> A;
	vector<ll> B;
	cin>>K>>N;
	for(ll i=0;i<N;i++){
		cin>>b;
		A.push_back(b);
	}
	for(ll i=0;i<N-1;i++){
		c=A[i+1]-A[i];
		B.push_back(c);
	}
	d=*max_element(B.begin(),B.end());
	c=K-A[N-1]+A[0];
	B.push_back(c);
	if(d>c){
		cout<<K-d<<endl;
	}else{
		cout<<A[N-1]-A[0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4848
h,w=map(int,input().split())
l=[list(input()) for i in range(h)]
hs=set()
ws=set()
for i in range(h):
    for j in range(w):
        if l[i][j]=="#":
            hs.add(i)
            ws.add(j)
for i in hs:
    for j in ws:
        print(l[i][j],end="")
    print()

Measured memory_bytes: 4468
#include<iostream>
#include<vector>
int main(){
  int n;
  std::cin>>n;
  std::vector<int> a(n),b(n);
  for(int i=0;i<n;++i){
    std::cin>>a[i]>>b[i];
  }
  bool yes = false;
  for(int i=0;i+2<n;++i){
    if(a[i]==b[i] and a[i+1]==b[i+1] and a[i+2]==b[i+2])yes=true;
  }
  std::cout<<(yes?"Yes":"No")<<std::endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define var auto
#define ll long long
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++) 
#define inp(a) int a; cin >> a;
#define inps(s) std::string s; cin >> s;
#define out(a) cout<<a<<endl;
#define pb(a) push_back((a))
#define endl "\n"
#define vi vector<int>


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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
    }

    int count = 0;
    int maxv = 0;

    rep(i, N) {
        if(A[i] == 1) {
            count++;
            maxv = max(count, maxv);
        } else
            count = 0;
    }

    cout << (maxv + 1) << endl;
	return 0;
}



Measured memory_bytes: 3228
#include <iostream>
#include <cstring>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXSIZE 500
#define CENTER (MAXSIZE / 2)

// ?????´(= 0)????????´ (= 1)????????´ (= 2)????????´ (= 3)
int dx[4] = {-1, 0, 1, 0};
int dy[4] = { 0,-1, 0, 1};

int main(int argc, const char * argv[]) {
    while(1){
        int n; cin >> n;
        if(!n) break;
        
        int left, right, top, bottom;
        left = right = top = bottom = CENTER;
        
        vector<pair<int, int> > tableIndex;
        tableIndex.push_back(make_pair(CENTER, CENTER));
        
        for(int i = 1; i < n; i++){
            int m, d; cin >> m >> d;
            
            int x = tableIndex[m].first + dx[d];
            int y = tableIndex[m].second + dy[d];
            tableIndex.push_back(make_pair(x, y));
            
            left = min(left, x);
            right = max(right, x);
            top = min(top, y);
            bottom = max(bottom, y);
        }
        
        cout << right - left + 1 << " " << bottom - top + 1 << endl;
    }
}

Measured memory_bytes: 1204
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N,X,Y;
    cin >> N >> X >>Y;
    ll ans[N];
    ll i,j;
    for(i=0;i<N;i++){
        ans[i]=0;
    }
    for(i=1;i<N;i++){
        for(j=i+1;j<=N;j++){
            if(i<X&&j<X)++ans[j-i];
            if(i>Y&&j>Y)++ans[j-i];
            if(i<X&&j>Y)++ans[j-Y+X-i+1];
            if(i<X&&j>=X&&j<=Y)++ans[X-i+min(Y-j+1,j-X)];
            if(i>=X&&i<=Y&&j<=Y)++ans[min(j-i,Y-j+i-X+1)];
            if(i>=X&&i<=Y&&j>Y)++ans[min(j-i,j-Y+i-X+1)];
        }
    }
    for(i=1;i<N;i++){
        cout << ans[i] <<endl;
    }
    return 0;
}


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

def prime_factorization(n):
    arr=[]
    temp=n

    for i in range(2,int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp//=i
            arr.append([i,cnt])

    if temp!=1:
        arr.append([temp,1])
    
    if arr==[]:
        arr.append([n,1])
    
    return arr
  
def solve():
    if N==1:
        print(0)
        return

    pri_arr=prime_factorization(N)
    ans=0

    for i in range(len(pri_arr)):
        e=pri_arr[i][1]
        temp=0
        cur=1

        while e>=cur:
            e-=cur
            cur+=1
            temp+=1
        
        ans+=temp

    print(ans)
    
if __name__ == "__main__":
     solve()

Measured memory_bytes: 63396
#include<bits/stdc++.h>
using namespace std;
int a[128];
int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	int i = 0, k = 0;
	while(i != n){
		if(a[i] == 0){
			i ++;
			continue;
		}
		int j = i;
		while(a[j]){
			a[j] --;
			j ++;
		}
		k ++;
	}
	cout << k;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
int main(){
    cs;
    int a,b,x,t=1;
    cin>>x>>a;
    rep(i,x-1){
        cin>>b;
        if(b>=a) t++;
        a=max(a,b);
    }
    cout<<t;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, h: "List[int]"):
    dp=[]
    dp.append(0)
    dp.append(abs(h[0]-h[1]))
    for i in range(2,N):
        dp.append(min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i])))

    print(dp[N-1])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, h)

if __name__ == '__main__':
    main()


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

using namespace std;

#define int long long

vector<pair<int,int>> adj[100005];
int n;
int col[100005], deg[100005];
int ans;

void dfs(int s, int p, int c){

  for(auto i:adj[s]){
    if(i.first==p)continue;
    c = (c+1)%ans;
    col[i.second] = c;
      dfs(i.first, s, c);
  }
}
signed main(){
  cin >> n;

  for(int i = 1;i<n;i++){
    int x,y;
    cin >> x >> y;

    adj[x].push_back({y,i});
    adj[y].push_back({x,i});
    deg[x]++;
    deg[y]++;
  }
  for(int i = 1;i<=n;i++){
    ans = max(ans,deg[i]);
  }

  dfs(1, -1, 0);

  cout << ans << endl;

  for(int i = 1;i<n;i++){
    cout << col[i]+1 << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 9472
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

long long int dp1[200005], dp2[200005];

long long int INF = 99999999999999;

string S;

int main(void) {


	for (int i = 0; i <= 2; i++) {
		dp1[i] = -INF;
		dp2[i] = -INF;
	}

	dp1[1] = 1;
	dp2[2] = 1;

	cin >> S;

	int N = S.size();

	S = "#" + S + "#";

	

	for (int i = 1; i <= N - 1; i++) {
		if (S.substr(i, 1) != S.substr(i + 1, 1)) { dp1[i + 1] = max(dp1[i + 1], dp1[i] + 1); }
		else {
			dp2[i + 2] = max(dp2[i + 2], dp2[i] + 1);
		}
		dp2[i + 2] = max(dp2[i + 2], dp1[i] + 1);
		dp1[i + 1] = max(dp1[i + 1], dp2[i] + 1);
	}


	cout << max(dp1[N], dp2[N]) << endl;

	/*for (int i = 1; i <= N; i++) {
		cout << "dp1[" << i << "]= " << dp1[i] << endl;
		cout << "dp2[" << i << "]= " << dp2[i] << endl;
	}*/

	return 0;
}

Measured memory_bytes: 3648
import java.util.Map;
import java.util.TreeMap;
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    Map<Integer,int[]> sortup = new TreeMap<>();
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] P = new int[N];
    String[] ans = new String[M];
    for(int i = 0;i < M ;i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      int[] c = new int[2];
      c[0] = a;
      c[1] = i;
      sortup.put(b,c);
    }
    for(int key : sortup.keySet()){
      int[] c = sortup.get(key);
      ans[c[1]] = String.format("%06d%06d",c[0],++P[c[0]-1]);
    }
    for(int i = 0;i < M ;i++){
      System.out.println(ans[i]);
    }
  }
}

Measured memory_bytes: 163128
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>

#define fin stdin
#define fout stdout

using namespace std;

//FILE *fin = fopen("x.in", "r"), *fout = fopen("x.out", "w");

typedef long long i64;

const int nmax = 2e5;

int f[nmax + 1];
vector< int > val;

inline bool cmp (int x, int y) {
    return f[ x ] > f[ y ];
}

int main() {
    int n, k;
    fscanf(fin, "%d%d", &n, &k);

    for (int i = 1; i <= n; ++ i) {
        int x;
        fscanf(fin, "%d", &x);
        ++ f[ x ];

        if (f[ x ] == 1)
            val.push_back( x );
    }

    sort(val.begin(), val.end(), cmp);

    int s = 0;
    for (int i = 0; i < k && i < (int)val.size(); ++ i) {
        s += f[ val[ i ] ];
    }

    fprintf(fout, "%d\n", n - s);
    return 0;
}


Measured memory_bytes: 2168
from collections import deque
de = deque()
n,m,q = map(int,input().split())
queries = []
for i in range(q):
    a,b,c,d = map(int,input().split())
    queries.append((a,b,c,d))
de.append([1])
maxscore = 0
while de: 
    li = de.popleft()
    if len(li) < n:
        for i in range(li[-1],m+1):
            new_li = li + [i]
            de.append(new_li)
    else:
        score = 0
        for i in range(q):
            a,b,c,d = queries[i]
            if li[b-1]-li[a-1] == c:
                score += d
        maxscore = max(maxscore,score)
print(maxscore)


Measured memory_bytes: 84836
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
S = np.frombuffer(readline().rstrip(),'S1')
Q = int(readline())
query = map(int,read().split())

isD = S == b'D'
isM = S == b'M'
isC = S == b'C'

cumD = isD.cumsum(dtype=np.int64)
cumM = isM.cumsum(dtype=np.int64)

def F(K):
    """
    ・Cごとに数える。
    ・そのためには(i-K,i] 内のDMの個数を調べる（負インデックスには関係ない文字があると思っておく）
    ・区間内のDの個数、Mの個数が取得できれば、差分が取得できるので最後に累積和
    """
    # (i-K,i]内のDの個数、Mの個数
    D = cumD.copy(); D[K:] -= cumD[:-K]
    M = cumM.copy(); M[K:] -= cumM[:-K]
    # 最後がMのとき、Dの個数分増える
    DM = isM * D
    # 左端のDを捨てるとき、Mの個数分減る
    DM[K:] -= isD[:-K] * M[K-1:-1]
    np.cumsum(DM,out=DM)
    # Cごとに集計
    return (DM*isC).sum()

print('\n'.join(str(F(K)) for K in query))

Measured memory_bytes: 63324
#include <cstdio>
#include <algorithm>
using namespace std;
struct node {
    int x;
    int y;
    const bool operator< (const node &a) const {
        return x < a.x;
    };
};

node o[100010];

int main() {
    long long ans = 0;
    int n, m;
    scanf("%d %d",&n,&m);
    for(int i = 0; i < n; i++) scanf("%d %d",&o[i].x,&o[i].y);
    sort(o, o + n);
    for(int i = 0; i < n; i++) {
        if(m == 0) break;
        if(m - o[i].y < 0) {
            ans += (long long)o[i].x * m;
            m = 0;
        }
        else {
            ans += (long long)o[i].x * o[i].y;
            m -= o[i].y;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main(){

  int a[10],b[10];;
  for(int i=0;i<10;i++)cin>>a[i];
  for(int i=0;i<10;i++)cin>>b[i];

  sort(a,a+10);
  sort(b,b+10);
  cout << a[9]+a[8]+a[7]<<" "<<b[9]+b[8]+b[7]<<endl;
  return 0;
}

Measured memory_bytes: 1180
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define MOD 998244353
using namespace std;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

inline int tasu(int a, const int &b) {return (a += b) >= MOD ? a - MOD : a;}

int n, R[4005], B[4005], f[4005][4005];
char S[2005];

int main(){
	scanf("%s", S + 1), n = strlen(S + 1);
	for(register int i = 1; i <= n; i++){
		R[i] = R[i - 1] - S[i] + '2';
		B[i] = B[i - 1] + S[i] - '0';
	}
	for(register int i = n + 1; i <= (n << 1); i++){
		R[i] = R[i - 1];
		B[i] = B[i - 1];
	}
	n <<= 1, f[0][0] = 1;
	for(register int i = 1; i <= n; i++)
		for(register int j = max(0, i - B[i]); j <= R[i]; j++)
			f[i][j] = tasu(f[i - 1][j - 1], f[i - 1][j]);
	return printf("%d\n", f[n][R[n]]), 0;
}


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

#define endl '\n'

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}
const int MAXN = 2e5 + 5 ;
int t[MAXN] ; 
int main(int argc,char* argv[]) { 
    io() ;
    #ifndef ONLINE_JUDGE
      //  freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    int n, T ;
    cin >> n >> T ;
    for(int i = 1 ; i <= n ; i++){
        cin >> t[i] ;
    }
    long long ans = 0 ;
    long long prevt = 0 ;
    long long curt = T ;
    for(int i = 2 ; i <= n ; i++){
        ans = ans + min(curt,1ll*t[i]) - t[i -1] ;
        curt = t[i] + T ;
    }   
    ans = ans + curt - t[n] ;
    cout << ans << endl ;
    return 0 ; 
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
		String t = scn.next();
      	char[] ss = s.toCharArray();
      	Arrays.sort(ss);
      	String sss = new String(ss);
      	char[] tt = t.toCharArray();
      	Arrays.sort(tt);
      	String T = new String(tt);
      	String ttt = new StringBuilder(T).reverse().toString();
      	if (sss.compareTo(ttt) < 0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 35704
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,num;
  num=1;
  cin>>N;
  cin>>K;
  for(int i=0;i<N;i++){
   if(num*2>num+K){
    num=num+K; 
   }else{
    num=num*2; 
   } 
  }
  cout<<num<<endl;
}

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

int main(void)
{
    int n;
    int p, d1, d2;
    int max_p = 0, max = 0;
    
    while (1) {
        max_p = max = 0;
        scanf("%d", &n);
        if (n == 0) break;
        
        for (int i = 0; i < n; i++){
            scanf("%d %d %d", &p, &d1, &d2);
            if (max < (d1 + d2)){
                max = d1 + d2;
                max_p = p;
            }
        }
        
        printf("%d %d\n", max_p, max);
    }
    
    return (0);
}

Measured memory_bytes: 764
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
using namespace std;

bitset<2000> win[2000],dpL[2000],dpR[2000];
bitset<2000> dpLL[2000],dpLR[2000],dpRL[2000],dpRR[2000];

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(20);
    int n;cin >> n;
    win[0][0] = 1;
    for(int i = 1;i < n;i++){
        win[i][i] = 1;
        string s;cin >> s;
        REP(j,i){
            win[i][j] = (s[j] == '1');
            win[j][i] = !win[i][j];
        }
    }
    for(int i = 0;i < n;i++){
        dpL[i][i] = dpR[i][i] = true;
        dpLL[i][i] = dpRL[i][i] = true;
    }
    for(int d = 1;d < n;d++){
        for(int i = 0;i + d < n;i++){
            bitset<2000> merged = (win[i] & dpLL[i+d] & dpRL[i+1]);//これの[i+1,i+d]にあるか？
            if(merged.count() == 0)continue; 
            dpL[i][i+d] = true;
            dpLL[i+d][i] = true;
        }
        for(int i = n-1;i - d >= 0;i--){
            bitset<2000> merged = (win[i] & dpRL[i-d] & dpLL[i-1]);//これの[i-d,i-1]にあるか？
            if(merged.count() == 0)continue;
            dpR[i][i-d] = true;
            dpRL[i-d][i] = true;
        }
    }

    int ans = 0;
    for(int i = 0;i < n;i++){
       // cout << dpR[i] << '\n';
        if(dpR[i][0] & dpL[i][n-1])ans++;
    }
    cout << ans << '\n';
    return 0;
}


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

long mod = 1000000007;

long long modpow(long long a, long long b) {
    if (b == 0) return 1;
    if (b % 2 == 0) {
        return modpow(a, b / 2) * modpow(a, b / 2) % mod;
    }
    else {
        return a * modpow(a, b - 1) % mod;
    }
}

long long comb(long long a, long long b) {
    long long n = 1;
    long m = 1;
    long long ax = a;
    long long bx = b;
    for (int i = 0; i < b; i++) {
        n *= ax;
        n %= mod;
        ax--;
        m *= bx;
        m %= mod;
        bx--;
    }
    long long ret = n * modpow(m, mod - 2) % mod;
    return ret;
}

int main() {
    int n,m;
    cin >> n >> m;
    int m2 = m;
    vector<int> num_of_prime_factor(400000);
    int a = 0;
    bool flag;
    for(int i = 2; i * i <= m2; i++) {
        flag = false;
        while (m % i == 0) {            
            flag = true;
            m /= i;
            num_of_prime_factor.at(a)++;
        } 
        if (flag) a++;
        if (m <= 1) break;
    }
    if (m > 1) {
            num_of_prime_factor.at(a)++;        
    }    
        
    long long ans = 1;
    int i = 0;
    while(num_of_prime_factor.at(i) != 0) {
        ans *= comb(num_of_prime_factor.at(i) + n - 1, num_of_prime_factor.at(i));
        ans %= 1000000000 + 7;
        i++;
    }
    cout << ans << endl;
}

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

using namespace std;

long long dp[51][5001],ans;

int main()
{
	int n,a,x;
	cin >> n >> a;
	dp[0][2500]=1;
	for (int i=1; i<=n; i++)
	{
		cin >> x;
		x -= a;
		for (int s=0; s<=5000; s++)
			dp[i][s]=dp[i-1][s]+
				(s-x >=0 && s-x <= 5000 ? dp[i-1][s-x] : 0);
	}
	cout << dp[n][2500]-1;
	return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a > 9 || b > 9) System.out.println(-1);
        else System.out.println(a*b);
    }
}

Measured memory_bytes: 35656
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int N, M;
  int ans = 0;
  string s;

  cin >> N >> M;

  vector<int> l(M);
  vector<int> r(M);
  for(int i = 0; i < M; i++){
    cin >> l[i] >> r[i];
  }

  int sl, sr;
  int len = 0;
  for(int i = 0; i < M; i++){
    if(i == 0){
      sl = l[i]; 
      sr = r[i];
      len = sr - sl;
    }else{
      if(r[i] < sl || l[i] > sr){
        cout << 0 << endl;
        return 0;
      }else if(sl >= l[i] && l[i] <= sl <= r[i] && r[i] <= sr){
        sl = sl;
        sr = r[i];
        len = sr - sl;
      }else if(sl <= l[i] &&  sl <= l[i] <= sr && r[i] >= sr){
        sl = l[i];
        sr = sr;
        len = sr - sl;
      }
    }
    if(len < 0){
      cout << 0 << endl;
      return 0;
    }
    // cout << "sl = " << sl << ", sr = " << sr << endl;
  }
  cout << len+1 << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 25
#define f first
#define s second

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

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

char grid[oo][oo];

bool valid(int row,int col,int H,int W){
	return(row>=0 && col>=0 && row<H &&
		col<W && grid[row][col]=='.');
}

void BFS(int row,int col,int H,int W,int& ans){
	vector<vector<int>> dist(H,vector<int>(W,-1));
	dist[row][col]=0;
	queue<pair<int,int>> q;
	q.push({row,col});

	while(!q.empty()){
		pair<int,int> nodo=q.front();
		q.pop();

		for(int i=0;i<4;i++){
			pair<int,int>dir = {nodo.f+dx[i],nodo.s+dy[i]};
			if(valid(dir.f,dir.s,H,W) && dist[dir.f][dir.s]==(-1)){
				dist[dir.f][dir.s]=dist[nodo.f][nodo.s]+1;
				q.push({dir.f,dir.s});
				ans=max(ans,dist[dir.f][dir.s]);
			}
		}
	}
}


int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	int H,W;
	cin>>H>>W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>grid[i][j];
		}
	}

	int ans=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(grid[i][j]=='.')
				BFS(i,j,H,W,ans);
		}
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    string s;
    map<string, long long int> mp;
    for(int n=0; n<N; n++) {
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    long long int ans=0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        ans += (itr->second-1)*itr->second/2;
    }
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 11136
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K;
  cin>>N>>K;
  if(K>(N-1)*(N-2)/2) {
    cout<<-1<<endl;
    return 0;
  }
  vector<pair<int, int> > edge;
  for(int i=1;i<N;++i) edge.push_back(mp(0, i));
  int num = (N-1)*(N-2)/2;
  for(int i=1;i<N;++i) {
    for(int j=i+1;j<N;++j) {
      if(num==K) break;
      edge.push_back(mp(i, j));
      num--;
    }
  }
  cout<<edge.size()<<endl;
  for(int i=0;i<edge.size();++i) {
    cout<<edge[i].fi+1<<" "<<edge[i].se+1<<endl;
  }
}



Measured memory_bytes: 3672
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
using namespace std;
pair<string,string> e[1000000];
int main(){
int i,j,n,f,m,o=0,r,l,b;
pair<string,string> a;
set<pair<string,string> > g;
set<pair<string,string> >::iterator t;

set<string>::iterator w;
multiset<pair<string,string> > d;
string s[10],q[2];
scanf("%d%d",&n,&f);
for(i=0;i<n;i++){
scanf("%d",&m);
for(j=0;j<m;j++){
cin>>s[j];
}
for(r=0;r<m;r++){
for(l=r+1;l<m;l++){
set<string> u;
u.insert(s[r]);
u.insert(s[l]);

b=0;
for(w=u.begin();w!=u.end();++w){
q[b]=*w;
b++;
}
a.first=q[0];
a.second=q[1];
d.insert(a);
g.insert(a);
}
}
}
for(t=g.begin();t!=g.end();++t){
if(d.count(*t)>=f){
e[o]=*t;
o++;
}
}
printf("%d\n",o);
for(i=0;i<o;i++){
cout<<e[i].first<<' '<<e[i].second<<endl;
}
return 0;
}






Measured memory_bytes: 19548
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

pii p[100000];

int main() {
	int n, a, b, ax = -1, bx = -1;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p + n);

	cout << p[n - 1].first + p[n - 1].second << endl;

	return 0;
}

Measured memory_bytes: 1656
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll MOD = 1000000007;
const int mod = 1000000007;
ll INF = 1LL << 60;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
   for (auto &v : vec)
      is >> v;
   return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
   os << "[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vec)
{
   os << "deq[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{
   os << "(" << pa.first << "," << pa.second << ")";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
};
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
   fill((T *)array, (T *)(array + N), val);
}


ll a[202020];
int solve()
{
   ll n, m;
   cin >> n >> m;
   if(abs(n - m) > 1){
      cout << 0 << endl;
   }else{
      ll ans;
      ll fact[101010];
      fact[0] = 1;
      for (int i = 1; i <= 100005; i++)
      {
         fact[i] = (fact[i - 1] * i) % MOD;
      }
      ans = (fact[n] * fact[m]) % MOD;
      if(abs(n - m) == 0)
         ans = (ans * 2) % MOD;
      cout << ans << endl;
   }

   return 0;
}

int main()
{
   //cout.precision(10)
   ios::sync_with_stdio(false);
   cin.tie(0);

   solve();
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli a, b;
    cin >> a >> b;
    out((a * b) / 2);
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
const long long INF = INT_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, cnt = 0, w, h;
string s;
vector<ll> v;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
set<ll> st;
map<char, ll> mp;

/*--------------------template--------------------*/

int main()
{
	cin >> n;
	cout << n * 800 - (n / 15) * 200 << endl;
}

Measured memory_bytes: 768
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner input = new Scanner (System.in);
        long Max,Min,sum;
        int n = input.nextInt();
        Max = -1000000;
        Min = 1000000;
        sum = 0;
        for(int i=0;i<n;i++){
            int a = input.nextInt();
            Min = Math.min (Min, a);
            Max = Math.max (Max, a);
            sum+=a;
        }
       System.out.println(Min+" "+Max+" "+sum);
    }
}


Measured memory_bytes: 41444
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.sort()
y.sort()
i=x[-1]
j=y[0]
if i<j:
    for k in range(i+1,j+1):
        if X<k<=Y:
            print("No War")
            break
    else:
        print("War")
    
else:
    print("War")

Measured memory_bytes: 77444
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;


int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,q;
  cin>>n>>q;
  vector<ll> qs={n};
  rep(i,q){
    ll x;
    cin>>x;
    while(qs.size() && qs.back()>=x) qs.pop_back();
    qs.pb(x);
  }
  //cout<<qs;
  map<ll,ll> cnt;
  ll sum=qs.back();
  cnt[qs.back()]=1;
  rrep(i,qs.size()-1){
    map<ll,ll> tmp;
    for(auto it=cnt.lower_bound(qs[i]);it!=cnt.end();++it){
      tmp[it->X%qs[i]]+=it->Y;
      //cout<<*it<<"->"<<it->X%qs[i]<<endl;
      //cout<<sum<<"=>";
      sum-=it->X*it->Y;
      sum+=(it->X%qs[i])*it->Y;
      //cout<<sum<<endl;
    }
    cnt.erase(cnt.lower_bound(qs[i]),cnt.end());
    for(auto p:tmp) cnt[p.X]+=p.Y;
    cnt[qs[i]]+=(qs.back()-sum)/qs[i];
    //cout<<qs.back()-sum<<","<<qs[i]<<","<<(qs.back()-sum)%qs[i]<<endl;
    sum=qs.back();
    //  for(auto p:cnt) cout<<p;cout<<endl;
  }
  vector<ll> re(n+1);
  for(auto p:cnt) re[p.X]=p.Y;
  //cout<<re;
  ll s=accumulate(all(re),0ll);
  ll ast=0;
  rep(i,n){
    s-=re[i];
    cout<<s<<endl;
    ast+=s;
  }
  assert(ast==qs.back());
  return 0;
}


Measured memory_bytes: 11636
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int n, k, d;
    cin >> n >> k;
    vint sunuke(n,0);
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int a;
            cin >> a;
            sunuke[a-1] += 1;
        }
    }
    int ans=0;
    rep(i,n){
        if(sunuke[i] == 0) ans++;
    }
    cout << ans <<endl;
;}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int a[3][3];
bool b[3][3];
int main()
{
	int p=0,i,j,k,l,n,t;
	memset(b,0,sizeof(b));
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		scanf("%d",&a[i][j]);
	}
	scanf("%d",&n);
	for(l=0;l<n;l++)
	{
		scanf("%d",&t);
		for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		if(a[i][j]==t)
		b[i][j]=1;
	}
	}
	for(i=0;i<3;i++)
	{
		if(b[i][0]==1&&b[i][1]==1&&b[i][2]==1)
		{
			p=1;
			break;
		}
		if(b[0][i]==1&&b[1][i]==1&&b[2][i]==1)
		{
			p=1;
			break;
		}
	}
	if(b[0][0]==1&&b[1][1]==1&&b[2][2]==1)
	{
		p=1;
	}
	if(b[2][0]==1&&b[1][1]==1&&b[0][2]==1)
	{
		p=1;
	}
	if(p)
	printf("Yes");
	else
	printf("No");
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a:i32,
        b: i32,
        c:i32,
    }

    println!("{} {} {}", c, a, b);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define pb push_back
#define PI acos(-1)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << "\n";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 1e18 + 100;
int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(20);
	int n, k;
	cin >> n >> k;
	vi h(n);
	for(int i = 0;i < n;i++){
		cin >> h[i];
	}
	vi dp(n, inf);
	dp[0] = 0;
	for(int i = 1;i < n;i++){
		for(int j = 1;j <= k;j++){
			if(i - j >= 0){
				dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
			}
		}
	}
	cout << dp[n - 1] << "\n";
	return 0;
}


Measured memory_bytes: 1024
module Main where

import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Char

main :: IO ()
main = do
  [n, k] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  hs <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ length $ filter (>=k) hs

Measured memory_bytes: 1660
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		double r = sc.nextDouble();
		
		System.out.print(String.format("%.6f", r*r*Math.PI));
		System.out.print(" ");
		System.out.print(String.format("%.6f", 2*r*Math.PI)); 
	}
}



Measured memory_bytes: 28280
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int main(){
	int N,M;
	scanf("%d %d",&N,&M);

	int s[M];
	int c[M];

	int num[3] ={0};
	if(N > 1){
		num[0] = 1;
	}
	
	int miss = -1;

	for(int i=0; i<M; i++){
		scanf("%d %d",&s[i],&c[i]);
	}

	if(N > 1){
		for(int i=0; i<M; i++){
			if(s[i] == 1 && c[i] == 0){
				printf("%d\n",miss);
				return 0;
			}
		}
	}
	if(N == 3){
		for(int i=0; i<M; i++){
			if(s[i] == 2 && c[i] == 0){
				printf("%d\n",miss);
				return 0;
			}	
		}
	}
	
	for(int i=0; i<M; i++){
		for(int j=0; j<M; j++){
			if(s[j] > N){
				printf("%d\n",miss);
				return 0;
			}
			else if(s[i] == s[j] && i != j && c[i] != c[j]){
				printf("%d\n",miss);
				return 0;
			}
		}	
	}
	for (int i = 0; i < M; i++){
		num[s[i]-1] = c[i];
	}
	
	for(int i=0; i<N; i++){
		printf("%d",num[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 128
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
double dp[310][310][310] = {};
ll N;

double calc(ll c1, ll c2, ll c3){
    double &v = dp[c1][c2][c3];
    if(v >= -0.1){
        return v;
    }
    v = 0.0;
    ll sum = c1 + c2 + c3;
    double tt = 1.0;
    if(c3 > 0){
        tt += calc(c1, c2+1, c3-1) * (double) c3 / (double) N; 
    }
    if(c2 > 0){
        tt += calc(c1+1, c2-1, c3) * (double) c2 / (double) N;
    }
    if(c1 > 0){
        tt += calc(c1-1, c2, c3) * (double) c1 / (double) N;
    }
    if(sum == N){
        v = tt;
        return v;
    }else{
        double p = 1.0 - (double) (N-sum) / (double) N;
        tt /= p;
        v = tt;
        return v;
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    ll a[310];
    rep(i,0,N) cin >> a[i];
    rep(i,0,N+1){
        rep(j,0,N+1){
            rep(k,0,N+1){
                dp[i][j][k] = -1.0;
            }
        }
    }
    dp[0][0][0] = 0.0;
    ll c1 = 0, c2 = 0, c3 = 0;
    rep(i,0,N){
        if(a[i] == 1) c1++;
        if(a[i] == 2) c2++;
        if(a[i] == 3) c3++;
    }

    double ans = calc(c1,c2,c3);
    cout << setprecision(12) << ans << endl;
    

}

Measured memory_bytes: 227584
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if((i*j)==n){
                cout<<"Yes\n";
                cnt++;
                break;
            }
        }
        if(cnt) break;

    }
    if(cnt==0)cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256