akhauriyash/Code-Regression huggingface dataset:
def main():
    while True:
        data = input()
        data = data.split(" ")
        
        for i in range(len(data)):
            data[i] = int(data[i])

        if data == [0, 0]:
            return 

        
        man = data[0]
        donst = data[1]
        print(game(man, donst))

def game(man, donst):
    manst = [0 for j in range(man)]

    while True:
        for j in range(len(manst)):
            if donst != 0:
                donst -= 1
                manst[j] += 1

                if donst == 0:
                    zerocount = 0
                    for item in manst:
                        if item == 0:
                            zerocount += 1

                    if zerocount == man - 1:
                        return j

            else:
                donst = manst[j]
                manst[j] = 0
main()



Measured memory_bytes: 5596
N,M = map(int,input().split())
X = list(map(int,input().split()))

X = sorted(X)

gaps = sorted([X[i+1]-X[i] for i in range(len(X)-1)],reverse=True)

if N > len(gaps):
  print(0)
else:
  print(X[-1]-X[0]-sum(gaps[:N-1]))

Measured memory_bytes: 13960
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i = 0; i < (n); ++i)
#define rng(i,l,r) for(ll i = (l); i < (r); ++i)
#define down(i,r,l) for(ll i = (r); i >= (l); --i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;

#define X first
#define Y second

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;
    vi a(n);
    forn(i, n) {
        cin >> a[i];
    }
    set<int> s;
    int nuniq = 0;
    int nasc = 0;
    int smol = 0;

    for(int i = 0; i < k; i++) s.insert(a[i]);
    for(int i = 1; i < k; i++) smol += a[i] > a[i - 1];
    if (smol == k - 1) nasc = 1; else nuniq++;

    for(int i = k; i < n; i++) {
        // for each i we see
        smol -= (a[i - k + 1] > a[i - k]);
        smol += a[i] > a[i - 1];
        if (! (a[i - k] == *s.begin() && a[i] > *s.rbegin()) ) {
            if (smol < k - 1) nuniq++; else nasc = 1;
        }
        s.erase(a[i - k]);
        s.insert(a[i]);
    }
    cerr << nuniq << " " << nasc << endl;
    cout << nuniq + nasc << endl;


}

Measured memory_bytes: 11264
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

const int MAX = 50 * 99;
const int INF = 50000000;

int d[100][100];
int temp[100][100];

int main()
{
	int n,m;
	int a[MAX] = {0}, b[MAX] = {0}, c[MAX] = {0};

	cin >> n >> m;

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if (i != j)
			{
				d[i][j] = INF;
			}else
			{
				d[i][j] = 0;
			}
		}
	}

	for(int i = 0; i < m; i++)
	{
		cin >> a[i] >> b[i] >> c[i];

		d[a[i]-1][b[i]-1] = c[i];
		d[b[i]-1][a[i]-1] = c[i];

		temp[a[i]-1][b[i]-1] = c[i];
		temp[b[i]-1][a[i]-1] = c[i];
	}

	for(int k = 0; k < n; k++)
	{
		for(int j = 0; j < n; j++)
		{
			for(int i = 0; i < n; i++)
			{
				d[j][i] = min(d[j][i], d[j][k] + d[k][i]);
			}
		}
	}

	int cnt;

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if (temp[i][j] == 0)
			{
				temp[i][j] = d[i][j];
			}
		}
	}

	for(int i = 0; i < n; i++)
	{
		for(int j = i; j < n; j++)
		{
			//printf("temp[%d][%d] = %d  ", i+1,j+1,temp[i][j]);
			//printf("d[%d][%d] = %d\n", i+1,j+1,d[i][j]);

			if (temp[i][j] != d[i][j])
			{
				cnt++;
			}
		}
	}

	cout << cnt << endl;

	return 0;
}
	

Measured memory_bytes: 384
n, a, b = map(int, input().split())
MOD = 10**9 + 7


def comb(n: int, k: int, MOD: int) -> int:
    if n < k or n < 0 or k < 0:
        return 0
    k = min(k, n - k)
    if k == 0:
        return 1
    iinv = [1] * (k + 1)
    ans = n
    for i in range(2, k + 1):
        iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
        ans *= (n + 1 - i) * iinv[i] % MOD
        ans %= MOD
    return ans


ans = ((1 << n) - 1) % MOD
ans -= comb(n, a, MOD)
ans -= comb(n, b, MOD)
ans %= MOD
print(ans)


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

public class Hello
{
    public static void Main()
    {
        List<int> stoppedTrain = new List<int>();
        List<int> exitTrain = new List<int>();

        string str;
        while (!((str = Console.ReadLine()) == null))
        {
            int number = int.Parse(str);
            int trainNumber = stoppedTrain.Count();
            if (number == 0)
            {
                for (int i = trainNumber - 1; i >= trainNumber - 1; i--)
                {
                    if (i == trainNumber - 1)
                    {
                        exitTrain.Add(stoppedTrain[trainNumber-1]);
                        stoppedTrain.RemoveAt(i);
                    }
                }
            }
            else
            {
                stoppedTrain.Add(number);
            }
        }

        foreach(double item in exitTrain)
        {
            Console.WriteLine(item);
        }
    }

}



Measured memory_bytes: 16204
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int t=n;
	int sum;
	while(t)
	{
		sum+=t%10;
		t/=10;
	}
	if(!(n%sum)) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

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

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var K = input[1];
        var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

        for (int i = K; i < A.Length; i++)
        {
            if (A[i - K] < A[i])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 46256
f=lambda:list(map(int,input().split()))
l=f()+f()+f()
n=int(input())
s=set()
for i in range(n):
  b=int(input())
  if b in l: s|={l.index(b)}
print(['No','Yes'][any(t<=s for t in [{0,1,2},{0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}])])

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int n;
  cin >> n;
  VI a(n);
  VI sol(n);
  REP(i, 0, n) {
    int b;
    cin >> b;
    a[b]++;
  }
  ll tot = 1;
  REP(i, 0, n / 2) {
    sol[n  - 2*i-1] = 2;
  }
  if (n % 2==1) {
    sol[0] = 1;
  }
  REP(i, 0, n) {
    if (a[i] == sol[i]) {
      tot *= a[i] == 2 ? 2 : 1;
      tot %= mod;
    } else {
      tot = 0;
    }
  }
  cout << tot << endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String[] inputs = reader.readLine().split(" ");
        long N = Long.parseLong(inputs[0]);
        long M = Long.parseLong(inputs[1]);
        long answer = ((N-M) * 100 + 1900 * M) * (long)Math.pow(2,M);
        System.out.println(answer);
    }
}

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

int main(){
  ll n,k,i;
  cin >> n >> k;
  ll ans=0;
  vector<ll> num(k,0);
  for(ll i=1;i<=n;++i) num[i%k]++;
  for(int a=0;a<k;++a){
    ll b=(k-a)%k;
    ll c=(k-a)%k;
    if((b+c)%k!=0)continue;
    ans+=num[a]*num[b]*num[c];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll cnt[12345];

int main(void){
	int n,p,i,r=0,d=1;
	ll ans = 0ll;
	string s;
	cin >> n >> p;
	cin >> s;
	for(i=0; i<n; ++i){
		s[i] -= '0';
	}
	if(p==2 || p==5){
		for(i=0; i<n; ++i){
			if(s[i]%p==0){
				ans += (i+1);
			}
		}
		cout << ans << endl;
		return 0;
	}
	reverse(s.begin(),s.end());
	++cnt[0];
	for(i=0; i<n; ++i){
		r += s[i]*d%p;
		d *= 10; d %= p;
		r %= p;
		ans += cnt[r];
		++cnt[r];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 644
<?php
for($i = 1, $n = trim(fgets(STDIN)); $i <= $n; $i++) {
    echo "Case ", $i, ":", PHP_EOL;
    $num = trim(fgets(STDIN));
    for($j = 0; $j < 10; $j++) {
        $num = substr(str_pad($num *= $num, 8, "0", STR_PAD_LEFT), 2, 4);
        printf("%d" . PHP_EOL, $num);
    }
}

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

struct job {
    int cost, ddl;
    bool operator < (job a) {
    return ddl < a.ddl;
    }
};

int main() {
    int N;
    cin >> N;
    job jobs[N];
    for (int i = 0; i < N; i++) {
        cin >> jobs[i].cost >> jobs[i].ddl;
    }
    sort(jobs, jobs+N);
    for (int i = 0, time = 0; i < N; i++) {
        time += jobs[i].cost;
        if (time > jobs[i].ddl) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


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

int main(){
    int w, h, n;
    cin >> w >> h >> n;
    int xmn = 0, xmx = w, ymn = 0, ymx = h;
    rep(i, n){
        int a, x, y;
        cin >> x >> y >> a;
        if (a == 2) xmx = min(xmx, x);
        else if (a == 1) xmn = max(xmn, x);
        else if (a == 4) ymx = min(ymx, y);
        else if (a == 3) ymn = max(ymn, y);
    }
    cout << max(xmx - xmn, 0) * max(ymx - ymn, 0) << endl;
    return 0;
}

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

def main():
    N, M, K = map(int, input().split())
    for i in range(N+1):
        a = K - i * M
        b = N - 2*i
        if b == 0:
            if K == i*M:
                print('Yes')
                exit()
        elif a % b == 0 and 0 <= a // b <= M:
            print('Yes')
            exit()
    print('No')
            

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];
 
  UnionFind(int n) {
    init(n);
  }
 
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(int x, int y) {
    return root(x) == root(y);
  }
 
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
const ll MAX = 510000;
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(ll n, ll 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() {
ll a,b,c,k; cin>>a>>b>>c>>k;
ll f = 0;
for(ll i=0; i<=k; i++){
ll bb = b;
ll cc = c;
bb*=pow(2,i);
cc*=pow(2,k-i);
if(a<bb&&bb<cc){
f++;
break;}
}
if(f==1) cout << "Yes" << endl;
else cout << "No" << endl;}

Measured memory_bytes: 4100
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>
using namespace std;
int s[1111][111];
main(){
  while(1){
    int n,m,a;
    scanf("%d %d %d",&n,&m,&a);
    if(!n && !m && !a) break;
    memset(s,0,sizeof(s));
    int st = 0;
    for(int i=0;i<m;i++){
      int h,p,q;
      scanf("%d %d %d",&h,&p,&q);
      s[h][p]=q;
      s[h][q]=p;
      st = max(st,h);
    }
    int P = a;
    for(int i=st+1;i>0;i--){
      if(s[i][P]!=0)
	P=s[i][P];
    }
    printf("%d\n",P);
  }
}

Measured memory_bytes: 1676
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <list>
#include <math.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
void printArr(int *a, int len){for(int i=0; i<len; i++){if(i)cout << " ";cout << a[i];}cout << endl;}
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (1ll<<32);
static const int MAX = 100001;

int arr[MAX];

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    ll n;
    cin >> n;
    vector<ll> a;
    ll sum = 0;
    rep(i, n){
        ll b = 0;
        cin >> b;
        a.push_back(b);
        sum += b;
    }
    ll nowSum = 0;
    ll mi = LLINF;
    rep(i, n-1){
        nowSum+=a[i];
        mi = min(abs((sum-nowSum)-nowSum), mi);
    }
    cout << mi << endl;
    
    
    return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>
int main()
{
	int ret;
	int N;
	int a[200000];

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

	int maxVal = 0;
	int secVal = 0;
	for (int i = 0; i < N; i++) {
		int val = a[i];
		if (maxVal <= val) {
			secVal = maxVal;
			maxVal = val;
		}
		else if (secVal <= val) {
			secVal = val;
		}
	}
	
	for (int i = 0; i < N; i++) {
		int val = a[i];
		if (val == maxVal) {
			//2位を表示
			printf("%d\n", secVal);
		}
		else {
			printf("%d\n", maxVal);
		}
	}

	return 0;
}



Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int n, p[50],m=0,tmp;
    cin >> n;
    for (int i = 0; i < n;i++) {
        cin >> p[i];
    }
    for (int i = 1;i < n; i++) {
        if (p[i] < p[i - 1]) {
            tmp = p[i-1];
            p[i-1] = p[tmp-1];
            p[tmp - 1] = tmp;
            break;
        }
    }
    for (int i = 0; i < n; i++) {
        if (p[i] != i + 1) m++;
    }
    if (m!=0) cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
nx = str(n)[0]
ny = str(n)[-1]
digit = len(str(n))
is_full = [1, 11, 111, 1111, 11111]

for i in range(1, n + 1):
    x = str(i)[0]
    y = str(i)[-1]
    if y == "0":
        continue
    #digit = len(str(i))
    if x == y:
        ans += 1
        if y < nx:
            if digit - 2 < 0:
                continue
            ans += is_full[digit - 2]
        elif y == nx:
            if digit - 3 >= 0:
                ans += is_full[digit - 3]
            for num, k in enumerate(list(str(n))[1: -1], 1):
                ans += int(k) * 10 ** (digit - 2 - num)

            if digit == 2:
                if int(x + y) <= n:
                    ans += 1
            if digit >= 3 and x <= ny:
                ans += 1

        else:
            if digit - 3 < 0:
                continue
            ans += is_full[digit - 3]
    else:
        if y < nx:
            if digit - 2 < 0:
                continue
            ans += is_full[digit - 2]
        elif y == nx:
            if digit - 3 >= 0:
                ans += is_full[digit - 3]
            for num, k in enumerate(list(str(n))[1: -1], 1):
                ans += int(k) * 10 ** (digit - 2 - num)
            if digit == 2:
                if int(x + y) <= n:
                    ans += 1
            if digit >= 3 and x <= ny:
                ans += 1
        else:
            if digit - 3 < 0:
                continue
            ans += is_full[digit - 3]

print(ans)

Measured memory_bytes: 70888
w,a,b =[int(i) for i in input().split()]
if(b+w>=a):
    if(b>a):
        if(a+w>=b):#2
            print(0)
        else:#1
            print(b-(a+w))
    else:#4
        print(0)
else:#3
    print(a-(b+w))

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<__int128_t,__int128_t> P;

void solve() {
	ll n, d;
	cin >> n;
	vector<ll> v(3);REP(i, 3)cin >> v[i];
	cin >> d;
	vector<ll> g = {2, 3, 5};
	__int128_t ans = (__int128_t)n * (__int128_t)d;
	queue<P> pq;
	map<__int128_t, __int128_t> mp;
	pq.push(MP(n, 0));
	while(!pq.empty()){
		auto now = pq.front();pq.pop();
		if(ans < now.SE)continue;
		ans = min(ans, now.SE + now.FI * d);

		REP(i, 3){
			__int128_t tmp = (now.FI % g[i]) * d + v[i];
			__int128_t nxt = now.FI / g[i];
			if(mp.find(nxt) == mp.end() || now.SE + tmp < mp[nxt]){
				pq.push(MP(now.FI / g[i], now.SE + tmp));
				mp[nxt] = now.SE + tmp;
			}
		}
		REP(i, 3){
			__int128_t tmp = (g[i] - now.FI % g[i]) * d + v[i];
			__int128_t nxt = now.FI / g[i] + 1;
			if(mp.find(nxt) == mp.end() || now.SE + tmp < mp[nxt]){
				pq.push(MP(now.FI / g[i] + 1, now.SE + tmp ));
				mp[nxt] = now.SE + tmp;
			}
		}
	}

	cout << (ll)ans << endl;
}

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

	ll t;cin >> t;
	REP(i, t)solve();

	return 0;
}


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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

#define fr pair<ll, ll>

void red(fr& a) {
	if(a.fi == 0) a.se = 1;
	else if(a.se == 0) a.fi = 1;
	else {
		if(a.se < 0) a.fi = -a.fi, a.se = -a.se;
		ll g = __gcd(abs(a.fi), abs(a.se));
		a.fi /= g; a.se /= g;
	}
}

map<fr, int> cnt;
set<fr> t;
ll qp[200005];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; gi(n);
	int ex = 0;
	qp[0] = 1;
	rep1(i, n+1) qp[i] = 2*qp[i-1] % MOD;
	rep(i, n) {
		fr v;
		gi(v.fi), gi(v.se);
		if(v.se == 0 && v.fi == 0) {
			ex++;
			continue;
		}
		red(v);
		cnt[v]++;
		t.insert(v);
	}
	ll ans = 1;
	for(auto& k:t) {
		fr A = k;
		fr B{-A.se, A.fi}; red(B);
		ans = ans * (qp[cnt[A]] + qp[cnt[B]] - 1) % MOD;
		cnt[A] = cnt[B] = 0;
	}
	print((ans+ex+MOD-1)%MOD);
}


Measured memory_bytes: 44760
#include<bits/stdc++.h>
using namespace std;
main(){
  long long n;
  cin>>n;
  for(int i=0;i<n;i++){
    long long r,t;
    cin>>t>>r;
    if(r%30==0&&t%100==0){
      cout<<r/30*5+t/100<<endl;
    }
    if(r%30!=0&&t%100==0){
      cout<<r/30*5+t/100<<" "<<(r/30+1)*5+t/100<<endl;
    }
    if(r%30==0&&t%100!=0){
      cout<<r/30*5+t/100<<" "<<r/30*5+t/100+1<<endl;
    }
    if(r%30!=0&&t%100!=0){
      cout<<r/30*5+t/100<<" "<<r/30*5+t/100+1<<" "<<(r/30+1)*5+t/100<<" "<<(r/30+1)*5+t/100+1<<endl;
    }
  }
}

Measured memory_bytes: 3060
#include <stdio.h>
#define LONG_MAX 2147483647

long s[500001];
long L[500001];
long R[500001];

long n, cnt;

void merge(long left, long mid, long right) {
    long i, j, k, n1, n2;

    n1 = mid - left;
    n2 = right - mid;
    for (i = 0; i < n1; i++)
        L[i] = s[left + i];
    for (i = 0; i < n2; i++)
        R[i] = s[mid + i];
    L[n1] = LONG_MAX;
    R[n2] = LONG_MAX;
    i = 0;
    j = 0;
    for (k = left; k < right; k++) {
        cnt++;
        if (L[i] <= R[j]) {
            s[k] = L[i];
            i++;
        } else {
            s[k] = R[j];
            j++;
        }
    }
}

void mergeSort(long left, long right) {
    long mid;
    if (left+1 < right) {
        mid = (left + right) / 2;
        mergeSort(left, mid);
        mergeSort(mid, right);
        merge(left, mid, right);
    }
}

int main() {
    long i;

    scanf("%ld", &n);
    for (i = 0; i < n; i++)
        scanf("%ld", &s[i]);

    cnt = 0;
    mergeSort(0, n);

    for (i = 0; i < n; i++) {
        printf("%ld", s[i]);
        if (i < n-1)
            printf(" ");
        else
            printf("\n");
    }
    printf("%ld\n", cnt);
}



Measured memory_bytes: 9504
//E - Red and Green Apples

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int x, y, a, b, c;

    cin >> x >> y >> a >> b >> c;

    vector<long long> p;
    vector<long long> q;
    vector<long long> r;
    
    long long tmp;
    for(int i=0; i<a; i++){
        cin >> tmp;
        p.push_back(tmp);
    }
    for(int i=0; i<b; i++){
        cin >> tmp;
        q.push_back(tmp);
    }
    for(int i=0; i<c; i++){
        cin >> tmp;
        r.push_back(tmp);
    }

    sort(p.begin(), p.end(), std::greater<long long>());
    sort(q.begin(), q.end(), std::greater<long long>());
    sort(r.begin(), r.end(), std::greater<long long>());

    int rCnt = 0;
    int gCnt = 0;

    int pidx = 0;
    int qidx = 0;
    int ridx = 0;

    long long ans = 0;

    for(int i=0; i<x+y; i++){
        if ((p[pidx] >= q[qidx]) && (p[pidx] >= r[ridx]) && (x > rCnt)) {
            ans += p[pidx];
            pidx++;
            rCnt++;

            if(x==rCnt){
                for(int j=0;j<p.size();j++){
                    p[j]=0;
                }
            }
        }else if ((q[qidx] > p[pidx]) && (q[qidx] >= r[ridx]) && (y > gCnt)){
            ans += q[qidx];
            qidx++;
            gCnt++;

            if(y==gCnt){
                for(int j=0;j<q.size();j++){
                    q[j]=0;
                }
            }
        }else{
            ans += r[ridx];
            ridx++;
        }
    }


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


Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int n, k[100005];
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) { cin >> k[i]; }
	sort(k, k + n);
	if (k[n - 1] - k[0] >= 2) {
		cout << "No" << endl;
		return 0;
	}
	string ans = "No";
	if (k[n - 1] == k[0]) {
		if (k[0] == n - 1 || k[0] * 2 <= n) {
			ans = "Yes";
		}
		cout << ans << endl;
	}
	else {
		int mon = 0;
		for (int i = 0; i < n; ++i) {
			if (k[i] == k[n - 1] - 1) { ++mon; }
			else { break; }
		}
		if (mon < k[n - 1] && (k[n - 1] - mon) * 2 <= n - mon) { ans = "Yes"; }
		cout << ans << endl;
	}
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    int H,A,i;
    cin>>H>>A;
    for(i=1;i<=10000;i++)
    {
        H=H-A;
        if(H<=0)
        {
            cout<<i;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
def asum(a1,a2)
  na = []
  0.upto(a1.size-1) do |i|
    na[i] = a1[i] + a2[i]
  end
  return na
end

def check(arr, k)
  arr.each do |val|
    return 0 if val < k
  end
  return 1
end

n,m,x = gets.chomp.split(" ").map{|i|i.to_i}
c=[]
a=[[]]
n.times do |i|
  c[i], *a[i] = gets.chomp.split(" ").map{|i|i.to_i}
end

bin = Array.new(n, 0)
price = 0
min = 100000000
0.upto(2**n - 1) do |i|
  sum = Array.new(m, 0)
  price = 0
  b = i.to_s(2).split("").map{|i|i.to_i}
  bin[(n-b.size)..(n-1)] = b
  bin.each_with_index do |val, i|
    if val == 1
      sum = asum(sum, a[i])
      price += c[i]
    end
  end
  if check(sum, x) == 1 && price < min
    min = price
  end
end

if min == 100000000
  puts -1
else
  puts min
end

Measured memory_bytes: 14624
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int k, s;

int main() {
	cin >> k >> s;
	LL ans = 0;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			int z = s - x - y;
			if (z >= 0&&z<=k)ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(void){
    int K;
    string S;
    cin >> K >> S;
    if(S.size()<=K) cout << S << endl;
    else cout << S.substr(0, K) << "..." << endl;
    return 0;
}


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

bool used[1001001];
int dist[1001001];
vector<int> adj[1001001];

int dfs(int i) {
    used[i] = true;
    int ans = 0;
    for (int j : adj[i]) {
        if (used[j] && dist[j] == -1) return dist[i] = -1;
        else if (used[j]) ans = max(ans, dist[j]);
        else {
            int ret = dfs(j);
            if (ret == -1) return dist[i] = -1;
            else ans = max(ans, ret);
        }
    }
    return dist[i] = ans + 1;
}

int n;
int nd(int i, int j) { if (i < j) swap(i, j); return i * n + j; }
void addedge(int i1, int j1, int i2, int j2) {
    adj[nd(i1, j1)].push_back(nd(i2, j2));
}

int main() {
    cin >> n;
    int a[n][n-1];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n-1; j++) cin >> a[i][j], a[i][j]--;
    for (int i = 0; i < n; i++)
        for (int j = 1; j < n-1; j++) addedge(i, a[i][j-1], i, a[i][j]);

    fill(dist, dist+1001001, -1);
    int ans = -1;
    for (int i = 0; i < n; i++) {
        int v = nd(i, a[i][0]);
        if (!used[v]) dfs(v);
        if (dist[v] == -1) { ans = -1; break; }
        else ans = max(ans, dist[v]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 48256
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    int ct = 0;
    while(true) {
        sort(a, a+3);
        if(a[0]==a[2]) break;
        ct++;
        if(a[0]==a[1]) {
            a[0]++;
            a[1]++;
        } else {
            a[0] += 2;
        }
    }
    cout << ct << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[320];
int f[320][320][320]; // [i, j] 修改k个
int m;
int main() {
	scanf("%s", s);
	scanf("%d", &m);
	int n = strlen(s);
	for (int l = 0; l < n; l++) {
		for (int i = 0; i + l < n; i++) {
			int j = i + l;
			for (int k = 0; k <= m; k++) {
				if (i < j) {
					f[i][j][k] = max(f[i][j - 1][k], f[i + 1][j][k]);
				}
				if (s[i] == s[j]) {
					if (i == j) {
						f[i][j][k] = max(f[i][j][k], 0 + 1);
					} else {
						f[i][j][k] = max(f[i][j][k], f[i + 1][j - 1][k] + 2);
					}
				}
				if (k > 0 && i < j) {
					f[i][j][k] = max(f[i][j][k], f[i + 1][j - 1][k - 1] + 2);
				}
			}
		}
	}
	printf("%d\n", f[0][n - 1][m]);
	return 0;
}

Measured memory_bytes: 120960
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn gcd(a: u64, b: u64) -> u64{
    if a == 0{
        return b;
    }

    return gcd(b%a, a);
}

fn main(){
    let k: u64 = read_as_vec()[0];

    let mut ans: u64 = 0;
    for a in 1..k+1{
        for b in 1..k+1{
            for c in 1..k+1{
                ans += gcd(a, gcd(b, c));
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2120
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n;
map<int,int> mp;
int a[200111];
bool vis[200111];
vector<int> v;
int main()
{
	geti(n);
	for (int i=1; i<=n; i++)
	{
		geti(a[i]);
		mp[a[i]]++;
		v.PB(a[i]);
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	int ans = 0;
	for (auto x: v)
	{
		if (!mp[x]) continue;
		for (ll s=1; s<=(1ll<<32); s<<=1)
		{
			if (s-x>0)
			{
				ll y = s-x;
				if (mp.find(y)==mp.end()) continue;
				if (x==y)
				{
					ans += mp[x]/2;
					mp[x] %= 2;
				}
				else
				{
					int t = min(mp[x], mp[y]);
					mp[x] -= t;
					mp[y] -= t;
					ans += t;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 11252
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <cassert>

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define PI acos(-1.0)

typedef std::pair <int, int> pii;
typedef long long ll;
typedef std::vector <ll> vll;

using namespace std;

int dp[1 << 26];
int opt[200001];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string str;
	cin >> str;
	for (int i = 0; i < (1 << 26); i++) dp[i] = -1;
	dp[0] = 0;
	for (int i = 0; i <= str.length(); i++) opt[i] = INF;
	opt[0] = 0;
	int mask = 0;
	for (int i = 0; i < str.length(); i++) {
		mask ^= (1 << (str[i] - 'a'));
		if (dp[mask] != -1) 
			opt[i + 1] = min(opt[i + 1], opt[dp[mask]] + 1);
		for (int j = 0; j < 26; j++) {
			if (dp[mask ^ (1 << j)] != -1) {
				opt[i + 1] = min(opt[i + 1], opt[dp[mask ^ (1 << j)]] + 1);
			}
		}
		if (dp[mask] == -1)
			dp[mask] = i + 1;
		else if (opt[dp[mask]] > opt[i + 1])
			dp[mask] = i + 1;
	}
	cout << opt[str.length()] << endl;
	return 0;
}

Measured memory_bytes: 263556
#include<iostream>

using namespace std;

int main() {
	long a, b;
	cin >> a >> b;
	if(a == 1 && b == 1) cout << 1 << endl;
	else if (a == 1 && b != 1) cout << b-2 << endl;
	else if (a != 1 && b == 1) cout << a - 2 << endl;
	else cout << (a - 2)*(b - 2) << endl;
}

Measured memory_bytes: 256
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);
const bool DEBUG = 0;

int main()
{
	int i, j;

	string s;

	cin >> s;

	s[5] = ' ';
	s[13] = ' ';

	cout << s;


	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define mp make_pair
#define M 1000000007
#define F first
#define S second
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}

// #define ncr_nikalo
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
}
ll modinv(ll a,ll m)
{
    return power(a,m-2,m);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll int t=1;
    //cin>>t;
    #ifdef ncr_nikalo
        initialvalues();
    #endif
        
    for(ll int g=0;g<t;g++)
    {
    	ll int n;
    	cin>>n;
    	string s;
    	map<string,ll int>m;
    	while(n--)
    	{
    		cin>>s;
    		m[s]++;
    	}
    	cout<<"AC"<<" "<<'x'<<" "<<m["AC"]<<endl;
    	cout<<"WA"<<" "<<'x'<<" "<<m["WA"]<<endl;
    	cout<<"TLE"<<" "<<'x'<<" "<<m["TLE"]<<endl;
    	cout<<"RE"<<" "<<'x'<<" "<<m["RE"]<<endl;

    }
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,x,y,m,q;

int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n;
      if(n>=30)cout<<"Yes";
      else cout<<"No";
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#define rep(i, x, y) for (int i = (x); i <= (y); i ++)
#define drep(i, x, y) for (int i = (x); i >= (y); i --)
using namespace std;

typedef long long LL;
const int N = 2005;
const LL mod = 924844033;

LL C[N][N], dp[N], fac[N];

inline void pre() {
  rep(i, 0, N - 1) {
    C[i][0] = 1;
    rep(j, 1, i) {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
      if (C[i][j] >= mod) C[i][j] -= mod;
    }
  }
}

int main() {
  pre();
  int n, k, t;
  cin >> n >> k;
  dp[0] = 1;
  rep(i, 1, k) {
    t = (n - i) / k + 1;
    drep(k, n, 1) {
      rep(j, 1, min(k, t >> 1)) {
	(dp[k] += dp[k - j] * C[t - j][j]) %= mod;
      }
    }
    drep(k, n, 1) {
      rep(j, 1, min(k, t >> 1)) {
	(dp[k] += dp[k - j] * C[t - j][j]) %= mod;
      }
    }
  }
  fac[0] = 1;
  rep(i, 1, n) fac[i] = fac[i - 1] * i % mod;
  LL ans = 0, sgn = 1;
  rep(i, 0, n) {
    ans = (ans + sgn * dp[i] * fac[n - i] % mod + mod) % mod;
    sgn *= -1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 30208
object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)
    val w, h, x, y, r = scanner.nextInt
    val top = h - r
    val bottom = r
    val left = r
    val right = w - r
    val in = (left <= x) && (x <= right) && (bottom <= y) && (y <= top)
    println(if(in) "Yes" else "No")
  }
}


Measured memory_bytes: 45120
/** Which of the favors of your Lord will you deny ? **/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>using indexed_set = tree<TIn, null_type, less<TIn>,rb_tree_tag, tree_order_statistics_node_update>;

/**

PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 1e3+7;
const LL LINF = 1e17;

template <class T>
string to_str(T x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

string grid[nmax];
LL dp[nmax][nmax];

bool isOk(int i,int j,int r,int c)
{
    if(i>=0 && i<r && j>=0 && j<c)
    {
        if(grid[i][j]!='#')
            return true;
    }

    return false;
}

LL mod = 1e9+7;

int main()
{
    optimizeIO();

    int r,c;
    cin>>r>>c;

    for(int i=0;i<r;i++)
        cin>>grid[i];

    dp[0][0] = 1;

    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            if(isOk(i-1,j,r,c)) dp[i][j]  = (dp[i][j] + dp[i-1][j])%mod;
            if(isOk(i,j-1,r,c)) dp[i][j]  = (dp[i][j] + dp[i][j-1])%mod;
        }
    }

    cout<<dp[r-1][c-1]<<endl;
    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}




Measured memory_bytes: 9216
N = int(input())
A = list(map(int, input().split()))

ans = 0

for k in range(60):
  cnt = [0] * 2
  for i in range(N):
    ans += cnt[(A[i] >> k & 1) ^ 1] << k
    cnt[A[i] >> k & 1] += 1

print(ans % (10 ** 9 + 7))



Measured memory_bytes: 122808
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    double d; cin >> d;
    double ans = sqrt(2) * d;
    for(int x = 1; x <= 10; x++)
    {
        if(d * d - x * x >= 0)
        {
            double y = sqrt(max(0.0, d * d - x * x));
            double tmp = x;
            if(y < 1.0) tmp += 1.0;
            else tmp += y;
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int tmp;
  cin>>n;
  int ans=0;
  for(int i=1;i<=n;i++){
    cin >>tmp;
    if(i%2==1&&tmp%2==1)ans++;
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 3588
from collections import deque
N, K = [int(x) for x in input().split()]

def point(sl, num):
  p = ''
  ret = 0
  for i, s in enumerate(sl):
    if s == p:
      ret += num[i]
    else:
      ret += num[i] - 1
  return ret
  
S = input()
num = deque([])
sl = deque([])
c = 0
pre = S[0]
for s in S:
  if s == pre:
    c += 1
  else:
    sl.append(pre)
    num.append(c)
    pre = s
    c = 1
else:
  sl.append(pre)
  num.append(c)
  
if sl.count('R') > sl.count('L'):
  f = 'L'
  t = 'R'
else:
  f = 'R'
  t = 'L'

k = 0
sl2 = deque([])
num2 = deque([])
pre = sl[0]
c = 0
for i, s in enumerate(sl):
  if s == pre:
    c += num[i]
  else:
    if k < K:
      c += num[i]
      k += 1
    else:
      sl2.append(pre)
      num2.append(c)
      pre = s
      c = num[i]
else:
  sl2.append(pre)
  num2.append(c)
print(point(sl2, num2))

Measured memory_bytes: 6516
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  def genStr(s:String) = {
    val a = new ArrayBuffer[String]
    var i = 0

    while(i<s.length) {
      var c = s(i)
      var j = i
      var cnt = 0
      while(j<s.length && s(i)==s(j)) { j+=1;cnt+=1 }
      a += cnt.toString+s(i)
      i = j
    }
    a.mkString
  }
  Iterator.continually(readInt).takeWhile(_!=0).foreach { n =>
    var s = readLine
    (0 until n).foreach { _ => s = genStr(s) }
    println(s)
  }
}

Measured memory_bytes: 69496
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] ab = scanner.nextLine().split(" ", 2);
        String a = ab[0];
        String b = ab[1];

        boolean truthTeller;
        if (a.equals("H")) { // b is truth
            truthTeller = b.equals("H");
        }
        else { // b is inverse
            truthTeller = !b.equals("H");
        }
        if (truthTeller) {
            System.out.println("H");
        }
        else {
            System.out.println("D");
        }
    }
}


Measured memory_bytes: 20564