akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e18+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}



int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n,k;cin>>n>>k;
  vector<ll> A(n);
  ll sum = 0;
  rep(i,n){
    cin>>A[i];
    sum += max(0ll, A[i]);
  }
  int b = 0;
  int e = 0;
  ll pK = 0, mK = 0;
  while(e < k){
    if(A[e] < 0){
      mK += abs(A[e]);
    }else{
      pK += A[e];
    }
    e++;
  }
  ll ans = LINF;
  chmin(ans, min(mK, pK));
  while(e < n){
    if(A[b] < 0){
      mK -= abs(A[b]);
    }else{
      pK -= A[b];
    }
    b++;
    if(A[e] < 0){
      mK += abs(A[e]);
    }else{
      pK += A[e];
    }
    e++;
    chmin(ans, min(mK, pK));
  }
  cout<<sum - ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    vector<vector<vector<int>>> m(4,vector<vector<int>>(3,vector<int>(10,0)));
    int b,f,r,v;
    for(int i=0;i<n;i++) {
        scanf("%d%d%d%d",&b, &f, &r, &v);
        m[b-1][f-1][r-1]+=v;
    }    
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                cout<<" ";
                cout<<m[i][j][k];
            }
            cout << endl;
        }
        if(i != 3) cout << "####################" << endl; 
    }
}


Measured memory_bytes: 3220
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = __int64_t;

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

int h, w;
char s[55][55];


bool aaa(int x, int y){
  for(int i = 0; i < 4; i++){
    if(s[x+dx[i]][y+dy[i]] == '#'){
      return true;
    }
  }
  return false;
}

void solve(){
  cin >> h >> w;
  for(int i = 1; i < h+1; i++){
    for(int j = 1; j < w+1; j++){
      cin >> s[i][j];
    }
  }

  for(int i = 1; i < h+1; i++){
    for(int j = 1; j < w+1; j++){
      if(s[i][j] == '#'  && !aaa(i, j)){
        cout << "No" << endl;
        return;
      }
    }
  }
  cout << "Yes" << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
int main()
{
	int a,b,c,d,s=0;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a>b)
	{
		s+=b;
	}
	else
	{
		s+=a;
	}
	if(c>d)
	{
		s+=d;
	}
	else
	{
		s+=c;
	}
	printf("%d",s);
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#if __has_include(<local.h>)
#include <local.h>
#endif
using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define LOG(a) cout << a << "\n"
#else
#define TEST
#define LOG(a)
#endif

const double PI = M_PI;
const long long INF = int(999999999);
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;

#ifndef LOCAL_H
    const bool DO_BENCHMARK = false;
#endif
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    void solve();
    if(DO_BENCHMARK){
        clock_t clock_start = clock();
        solve();
        clock_t clock_end = clock();
        const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
        cout << "\n" << time << "[ms]\n";
    }
    else solve();
}

void solve(){
    vector<int> vec (3);
    cin >> vec[0] >> vec[1] >> vec[2];
    SORT(vec);
    REP(i,3)LOG(vec[i]);
    if(vec[0] == 5 && vec[1] == 5 && vec[2] == 7){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
x=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n=int(input())
for i in range(n):
	a=list(map(int,input().split()))
	x[a[0]-1][a[1]-1][a[2]-1]+=a[3]

for i in range(4):
	for j in range(3):
		print(' '+' '.join(map(str,x[i][j])))
	if i<3:
		print('####################')
			
	


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int distAB = abs(a-b);
    int distAC = abs(a-c);
    int distBC = abs(b-c);

    if(distAC <= d || (distAB <= d && distBC <= d)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
bl = [int(input())-1 for _ in range(m)]
l = [i for i in range(n)]
cnt = 0
for num in bl:
    del l[num-cnt]
    cnt +=1
    
mod = 1000000007

al = [0]*n
if 0 in l and 1 in l:
    al[0] = 1
    al[1] = 2
elif 0 in l:
    al[0] =1
elif 1 in l:
    al[1] = 1
else:
    print(0)
    exit()
    
li = [i for i in l if i>=2]
for i in li:
    al[i] = al[i-1] + al[i-2]
    if al[i] == 0:
        print(0)
        exit()

print(al[-1]%mod)

Measured memory_bytes: 464792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

ll N,A,B,C,D;
map<ll,ll> memo;

ll dfs(ll n){
    if(!n)return 0;
    if(memo.count(n)) return memo[n];
    auto f2 = [&](ll nn) {
        if (nn >= n) return ll(1e18+100);
        return dfs(nn);
    };
    ll m = 1e18+100;
    if(ll(1e18+100)/D > n) m = n*D;
    if(n%2 == 0){
        cmin(m, A+f2(n/2));
        cmin(m, A+D*2+f2(n/2+2));
    }else{
        cmin(m, A+D+f2((n+1)/2));
        cmin(m, A+D+f2((n-1)/2));
    }
    if(n%3 == 0){
        cmin(m, B+f2(n/3));
        cmin(m, B+D*3+f2(n/3+3));
    }else{
        ll r = n%3;
        cmin(m, B+D*r+f2((n-r)/3));
        cmin(m, B+D*(3-r)+f2((n+3-r)/3));
    }
    if(n%5 == 0){
        cmin(m, C+f2(n/5));
        cmin(m, C+D*5+f2(n/5+5));
    }else{
        ll r = n%5;
        cmin(m, C+D*r+f2((n-r)/5));
        cmin(m, C+D*(5-r)+f2((n+5-r)/5));
    }
    memo[n] = m;
    return m;
}

int main(){
    ll T;
    cin >> T;
    rep(i,T){
        memo = map<ll,ll>();
        cin >> N >> A >> B >> C >> D;
        if(N==0){
            cout << 0 << endl;
            continue;
        }
        cout << dfs(N) << endl;
    }
}

Measured memory_bytes: 6240
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n, m, q; cin >> n >> m >> q;
    vector<vector<int>> ar(q,vector<int>(4));
    rep(i,q) cin >> ar[i][0] >> ar[i][1] >> ar[i][2] >> ar[i][3];
    stack<vector<int>> st;
    vector<vector<int>> ka;
    repp(i,m+1,1){
        vector<int> pq;
        pq.emplace_back(i);
        st.push(pq);
    }
    //cout << st.top()[0] << endl;
    while (!st.empty()){
        vector<int> p = st.top(); st.pop();
        if (p.size() == n) ka.emplace_back(p);
        else {
            //cout << "!" << endl;
            repp(i,m+1,p[p.size()-1]){
                vector<int> ans = p;
                ans.emplace_back(i);
                st.push(ans);
            }
        }
    }
    //printvvec(ka);
    int ma = -10000000;
    rep(i,ka.size()){
        vector<int> tai = ka[i];
        int sco = 0;
        rep(j,q){
            if (tai[ar[j][1]-1] - tai[ar[j][0]-1] == ar[j][2]) sco += ar[j][3];
        }
        ma = max(ma,sco);
    }
    cout << ma << endl;
}

Measured memory_bytes: 9812
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
n, d = gets_i_list

combi = (0...n).to_a.combination(2).to_a

xlist = []
n.times do
  xlist.push gets_i_list
end

count = 0
combi.each do |i, j|
  ans = 0
  d.times do |k|
    ans += (xlist[i][k] - xlist[j][k]) ** 2
  end
  ans = ans ** 0.5
  if ans.to_i == ans.ceil
    count += 1
  end
end

puts count

Measured memory_bytes: 14920
from itertools import combinations
from math import factorial

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

cnt = 0
for i, j in combinations(range(N), 2):
    cnt += ((X[i][0] - X[j][0]) ** 2 + (X[i][1] - X[j][1]) ** 2) ** 0.5

print(factorial(N - 1) * 2 * cnt / factorial(N))







    


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

const int N = 200010;

struct Edge{
    int start, end;

    bool operator <(const Edge &e)const{
        return end < e.end;
    }
};

int a[N], b[N];

int main(){
    int h, w;
    scanf("%d%d", &h, &w);
    for (int i = 0; i < h; ++ i){
        scanf("%d%d", &a[i], &b[i]);
    }
    std::set <Edge> set;
    for (int i = 1; i <= w; ++ i){
        set.insert(Edge{i, i});
    }
    std::multiset <int> answer;
    for (int i = 1; i <= w; ++ i){
        answer.insert(0);
    }
    for (int i = 0; i < h; ++ i){
        auto u = set.lower_bound(Edge{0, a[i]});
        int max = 0;
        while (u != set.end() && u -> end <= b[i] + 1){
            auto v = answer.find(u -> end - u -> start);
            answer.erase(v);
            max = std::max(max, u -> start);
            u = set.erase(u);
        }
        if (max > 0 && b[i] + 1 <= w){
            set.insert(Edge{max, b[i] + 1});
            answer.insert(b[i] + 1 - max);
        }
        if (answer.empty()){
            puts("-1");
            continue;
        }
        printf("%d\n", *(answer.begin()) + i + 1);
    }
    return 0;
}

Measured memory_bytes: 24084
import sys
input = sys.stdin.readline

n = int(input())
l = list(map(int,input().split()))

l.sort()
c = 0

import bisect

for i in range(n):
    for j in range(i+1,n):
        ind = bisect.bisect_left(l,l[i]+l[j])
        c += max((ind-j)-1 , 0)
        
print(c)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
using namespace std;

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

    deque<int> input;

    rep(i, n) {
        int val;
        cin >> val;
        input.push_back(val);
    }

    // queueのtop or backから n - a個取って、
    // a個適当にしまう、とも言いかえられる
    // しまった場合、その端からは取れなくなる、とも言える

    // 操作回数kの最大値は100なので、
    // 5050通り.全探索でゴリ押せそうかな？
    int max_value = 0;

    // queueから0個とる、1個とる... k個とる
    rep(i , k + 1) {
        int pick = i;
        int push = k - i;
        rep (j, pick + 1) {
            deque<int> tmp_deq = input;
            priority_queue<int, vector<int>, greater<int>> result_queue;
            int result = 0;
            // 左からpick_l個、右からpick_r = pick - pick_l個取ってみる
            int pick_l = j;
            int pick_r = pick - pick_l;
            int tmp_push = push;

            while(pick_l > 0 && !tmp_deq.empty()) {
                result_queue.push(tmp_deq[0]);
                tmp_deq.pop_front();
                pick_l--;
            }

            while(pick_r > 0 && !tmp_deq.empty()) {
                result_queue.push(tmp_deq[tmp_deq.size() - 1]);
                tmp_deq.pop_back();
                pick_r--;
            }

            while(tmp_push > 0 && result_queue.size() > 0 ) {
                if (result_queue.top() > 0 ) {
                    // もう抜かないほうが値がでかくなる
                    break;
                }
                result_queue.pop();
                tmp_push--;
            }

            while(!result_queue.empty()) {
                result += result_queue.top();
                result_queue.pop();
            }
            max_value = max(max_value, result);
        }

    }

    cout << max_value << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    S = SI()
    N = len(S)
    A = "gp" * (N//2 + 1)
    ans = 0
    for i in range(N):
        if S[i] == A[i]:
            continue
        if S[i] == "g":
            ans += 1
            continue
        ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

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

int main() {
  int N,A,B,plan1,plan2;
  cin >> N >> A >> B;
  plan1 = N * A;
  plan2 = B;
  if (plan1 < plan2) {
    cout << plan1 << endl;
  }
  else if (plan1 > plan2) {
    cout << plan2 << endl;
  }
  else {
    cout << (plan1 + plan2) / 2 << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	while ( true ) {
	    final int n = stdin.nextInt();
	    if ( n == 0 ) {
		break;
	    }

	    final int[] val = new int[n];
	    for ( int i = 0; i < n; i++ ) {
		val[i] = stdin.nextInt();
	    }

	    final int target = stdin.nextInt();

	    int left = 0;
	    int right = n - 1;
	    int count = 0;
	    while ( left <= right ) {

		final int middle = ( left + right ) / 2;
		count++;
		if ( target < val[middle] ) {
		    right = middle - 1;
		} else if ( target > val[middle] ) {
		    left = middle + 1;
		} else {
		    break;
		}
	    }

	    System.out.println( count );	    
	}
	
    }    
}

Measured memory_bytes: 20328
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int64_t ans = 0;
  int64_t memo = 0;
  for (int i = 1; i < N; i++) {
    if (S.at(i) == 'E') {
      memo++;
      ans++;
    }
  }
  for (int i = 1; i < N; i++) {
    if (S.at(i) == 'E') {
      memo--;
    }    
    if (S.at(i - 1) == 'W') {
      memo++;
    }
    ans = min(ans, memo);
  }
  cout << ans << endl;          
}
          

Measured memory_bytes: 3924
#include <stdio.h>

int main(void) {

  long n;
  scanf("%ld", &n);
  long size = 1000000;
  long list[size+1];
  for (long i = 0; i <= size; i++) {
    list[i] = 0;
  }
  long a;
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a);
    list[a]++;
  }
  long count = 0;
  for (long i = 0; i <= size; i++) {
    if (list[i] != 0) {
      for (long j = 2; i*j <= size; j++) {
        list[i*j] = 0;
      }
      if (list[i] == 1) {
        count++;
      }
    }
  }
  printf("%ld\n", count);

  return 0;
}

Measured memory_bytes: 9544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(ll (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
    a *= 100;
    b *= 100;

    ld MAX = 0;
    ll x = a, y = 0;
    for (ll i = 0; i * a <= f; ++i) {
        for (ll j = 0; j * b <= f - i * a; ++j) {
            for (ll k = 0; k * c <= f - i * a - j * b; ++k) {
                for (ll p = 0; p * d <= f - i * a - j * b - k * c; ++p) {
                    ll wat = i * a + j * b;
                    ll sug = k * c + p * d;
                    if (f < wat + sug)continue;
                    if (wat / 100 * e < sug)continue;
                    if (chmax(MAX, ld(sug) / ld(wat + sug) - eps)) {
                        x = wat + sug;
                        y = sug;
                    }
                }
            }
        }
    }
    cout << x << " " << y << "\n";
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
        	int n = in.nextInt();
        	int a[] = new int [n];
        	for (int i = 0; i < a.length; i++) {
        		a[i] = in.nextInt();
        	}
        	
        	int num = 0;
        	boolean flag = true;
        	while (flag) {
        		flag = false;
        		for (int i = a.length - 1; i > 0; i --) {
        			if (a[i] < a[i-1]) {
        				int t = a[i];
        				a[i] = a[i-1];
        				a[i-1] = t;
        				flag = true;
        				num += 1;
        			}
        		}
        	}
        	
        	String s = new String();
        	for (int i = 0; i < a.length; i++) {
        		s = s.concat(Integer.toString(a[i]));
        		if (i + 1 != a.length) s = s.concat(" ");
        	}
        	
        	out.println(s);
        	out.println(num);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

Measured memory_bytes: 24308
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,x,t;
    
    
    cin>>n>>x>>t;
    
    if(n%x==0){
        cout<<n/x * t<<endl;
    }else{
        cout<<(n/x +1)*t<<endl; 
    }
}


Measured memory_bytes: 3648
import java.util.Scanner;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int H = input.nextInt();
        int W = input.nextInt();
        int[][] c = new int[10][10];
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                c[i][j] = input.nextInt();
            }
        }
        int[][] A = new int[H][W];
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                A[i][j] = input.nextInt();
            }
        }        
        int cost = 0;
        int costs[][];
        costs = Cost(c);
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(A[i][j] !=-1 && A[i][j] != 1){
                    int temp = A[i][j];
                    cost = cost + costs[temp][1];
                }
            }
        }       
        System.out.println(cost);
    }

    private static int[][] Cost(int[][] cost){
        for(int k = 0; k < cost.length; k++){
            for(int i = 0; i < cost.length; i++){
                for(int j = 0; j < cost.length; j++){
                    if(cost[i][k] + cost[k][j] < cost[i][j]){
                        cost[i][j] = cost[i][k] + cost[k][j];
                    }
                }
            }
        }
        return cost;
    }
}

Measured memory_bytes: 48320
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	ll N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;

	for(ll i = 0; i < N; i++) {
		if(A + i * C - (N - i - 1) * D <= B and B <= A + i * D - (N - i - 1) * C) {
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;
}


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

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

#include <vector>
#include <utility>


#include <algorithm>


char reps[] = {'.', '#'};
char knowup[320];
char knowdown[320];
char response[320];

bool query(int u, int d, bool after) {
	if (!after) printf("%c", reps[u]);
	printf("%s", knowup);
	if (after) printf("%c", reps[u]);
	printf("\n");

	if (!after) printf("%c", reps[d]);
	printf("%s", knowdown);
	if (after) printf("%c", reps[d]);
	printf("\n");

	fflush(stdout);

	scanf("%s", response);
	return !(response[0] == 'F');
}

void solve() {
	int n;
	scanf("%d", &n);

	int total = 0;

	while (total != n) {
		bool found = false;
		REP(up, 2) {
			REP(down, 2) {
				if (query(up, down, true)) {
					found = true;
					
					knowup[total] = reps[up];
					knowdown[total] = reps[down];
					total++;

					goto out;
				}
			}
		}

		break;
		out: continue;
	}

	while (total != n) {
		bool found = false;
		REP(up, 2) {
			REP(down, 2) {
				if (query(up, down, false)) {
					found = true;

					for (int i = total-1; i >= 0; i--) {
						knowup[i+1] = knowup[i];
						knowdown[i+1] = knowdown[i];
					}
					knowup[0] = reps[up];
					knowdown[0] = reps[down];
					total++;

					goto out2;
				}
			}
		}

		out2: continue;
	}


}


int main() {
    solve();
}




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

#define ll long long int
#define endl                 "\n"
#define space                " "
#define TLE_na_ho            ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MAX_SIZE             1024
#define MOD                  1000000007
#define pb                   push_back
#define fi                   first
#define se                   second
#define rep(i,a,n)           for(int i=a;i<n;i++)
#define repe(i,a,n)          for(int i=a;i<=n;i++)
#define repr(i,a,n)          for(int i=a;i>=n;i--)
#define ain(arr,n)           for(int i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n)          for(int i1=0;i1<n;i1++ ) cout<<arr[i1]<<space



int main()
{
    TLE_na_ho;
    ll n;
    cin>>n;
    ll a[n];
    ll b[n+1]={0};
    rep(i,0,n){
    	cin>>a[i];
    	b[i+1]+=b[i]+a[i];
    }
    ll ans=0;
    rep(i,0,n)
    {
    	ll sum=(b[n]-b[i+1])%MOD;
    	ans+=a[i]*sum;
    	ans%=MOD;
    }

    cout<<ans;

}


Measured memory_bytes: 6692
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    S = list(input())
    S = [1 if c == 'A' else 2 if c=='B' else 3 for c in S]
    N = len(S)
    ans = 0
    continuous_one = 0
    i = 0

    while i < N-1:
        if S[i] == 1:
            continuous_one += 1
            i += 1
        elif S[i] == 2 and S[i+1] == 3:
            ans += continuous_one
            i += 2
        else:
            continuous_one = 0
            i += 1
    

    



    print(ans)



    
main()

Measured memory_bytes: 61552
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    int x=0;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
        chmax(x,a[i]);
    }
    int l=0;
    int r=x;
    while(l+1<r){
        int c=(l+r)/2;
        int cnt=0;
        for (int i = 0; i < n; i++)
        {
            cnt+=(a[i]+c-1)/c -1;
        }
        //cerr<<c<<" "<<cnt<<endl;
        if(cnt<=k){
            r=c;
        }
        else{
            l=c;
        }
    }
    cout<<r<<endl;
    return 0;
}

Measured memory_bytes: 4748
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
using namespace std;
#define dbg(x) cerr << #x " = " << x <<endl;
typedef pair<int, int> P;
typedef long long ll;

const int MAXN = 1e5+5;
int a[MAXN];
int MIN[MAXN];
int main()
{
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	MIN[n-1] = a[n-1];
	for(int i = n-2; i >= 0; i--)
	{
		MIN[i] = min(MIN[i+1], a[i]);
	}
	for(int i = 0; i < n-1; i++)
	{
		if(a[i] - MIN[i+1] >= 2)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <algorithm>
#include <time.h>
#define l(x) x<<1
#define r(x) ((x<<1) | 1)
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int inf = 2*(1e9) + 10;
const long long MOD = 1000000009;
const int NMAX = 1000005;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};


int n;
int dp[NMAX];
int main(){
    int rs = 0;
    cin>>n;
    for(int i=1; i<=n; ++i){
        int a;
        cin>>a;
        dp[a] = dp[a-1] + 1;
        rs = max(rs, dp[a]);
    }
    cout<<n-rs<<"\n";

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A.at(i);
  }
  
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  
  int sa=0,sb=0;
  
  for (int i=0; i<N; i++) {
    if (i%2==0) {
      sa += A.at(i);
    }
    else {
      sb += A.at(i);
    }
  }
  
  cout << sa-sb << endl;
}

Measured memory_bytes: 3632
//ProblemE

//#define USE_STDIO
//#define USE_LOG
//#define FILE_ERR

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#ifndef debug
#define debug(...)
#endif // !LOG

#ifndef REDIRECT_STDIO
#define REDIRECT_STDIO {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
#endif // REDIRECT_STDIO

//include
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

//int
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;

//pair
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

//vector
template<typename T> using vt = std::vector<T>;
template<typename T> using vvt = vt<vt<T>>;
template<typename T> using vvvt = vt<vvt<T>>;
using vi = vt<int>;
using vvi = vvt<int>;
using vvvi = vvvt<int>;
using vl = vt<ll>;
using vvl = vvt<ll>;
using vvvl = vvvt<ll>;
using vb = vt<bool>;
using vpii = vt<pii>;

static inline void Solve();

int main(int argc, char* argv[]) {
	REDIRECT_STDIO;

	Solve();
	return 0;
}

constexpr ll MOD = 998244353;
ll fpow(ll a, ll n) {
	ll ans = 1;
	while(n) {
		if(n & 1) ans = (ans * a) % MOD;
		a = (a * a) % MOD;
		n >>= 1;
	}
	return ans;
}

vl fact, ifact, pow2;
ll Cnk(int n, int k) {
	if (k < 0) return 0;

	ll ans = (fact[n] * ifact[k]) % MOD;
	ans = (ans * ifact[n - k]) % MOD;
	return ans;
}

void init(int n) {
	fact.resize(n+1); ifact.resize(n+1); pow2.resize(n+1);
	fact[0] = ifact[0] = 1;
	pow2[0] = 1;
	for(int i = 1; i < n+1; i++) {
		fact[i] = (fact[i-1] * i) % MOD;
		ifact[i] = fpow(fact[i], MOD - 2);
		pow2[i] = (pow2[i-1] * 2) % MOD;
	}
}

//ProblemE
void Solve() {
	int k, n;
	cin >> k >> n;

	init(n + k * 2);
	for(int i = 2; i <= 2 * k; i ++) {
		int a = i <= k ? i - 1 : 2 * k + 1 - i;
		int b = k - a;

		int x = a / 2;
		ll ans = 0;
		for(int j = 0; j <= min(x, n); j++) {
			ans += (pow2[j] * Cnk(x, j)) % MOD * Cnk(n+b-1, b+j-1);
			if(i % 2 == 0 && j <= n - 1) {
				ans += (pow2[j] * Cnk(x, j)) % MOD * Cnk(n+b-2, b+j-1);
			}
			ans %= MOD;
		}

		cout << ans << '\n';
	}
	cout << flush;
}


Measured memory_bytes: 384
// Author : SAGORIKA DAS
#include <bits/stdc++.h>
#define F first
#define S second
#define MOD 1000000007
#define pb push_back
#define MAX 200002
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define mp make_pair
#define CLEAR(a) memset(a,0,sizeof a)
#define pii pair< int , int >
#define fr freopen("input.txt", "r", stdin)
#define fw freopen("output.txt", "w", stdout)
using namespace std;

int main()
{
    //fr;fw;
    string s;
    cin >> s;
    string ret = "11111111111";
    int j = 0;
    for(int i=0;i<s.size();i++){
        if(s[i] == '1') ret[j++] = '1';
        else if(s[i] == '0') ret[j++] = '0';
        else {
          if(j > 0) j--;
        }
    }
    for(int i = 0;i < j;i++) cout << ret[i];
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(long long i = 0;i < n;++i)
#define FOR(i,a,b) for(long long i = a;i < b;++i)
using namespace std;
using ll = long long;
using point = pair< int,int >;

int main(){
    int a,b,dif;
    scanf("%d%d",&a,&b);
    dif = b - a;
    int data[1000];
    data[0] = 0;
    FOR(i,1,1000){
        data[i] = data[i - 1] + i;
    }
    printf("%d\n", data[dif] - b);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    ll s;cin>>s;
    cout<<0<<" "<<0<<" ";
    ll x1,y1,x2,y2;
    ll u=1000000000,d=0;
    while(u-d>1){
        ll mid=(u+d)/2;
        if(mid*mid>=s){
            u=mid;
            
        }
        else d=mid;
    }
    ll r=u;
    u=1000000000;
    d=0;
    while(u-d>1){
        ll mid=(u+d)/2;
        if(mid*r<s){
            d=mid;
            continue;
        }
        if(mid*r>=s)u=mid;
    }
    x1=r;
    y2=u;
    x2=1;
    y1=r*u-s;
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >>d;
  if(a+b-c-d>0){
    cout << "Left" <<endl;
  }
  else if(a+b-c-d==0){
    cout << "Balanced" <<endl;
  }
  else{
    cout << "Right" <<endl;
  }
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String[] tmpArray = br.readLine().split(" ");

			if(tmpArray[0].equals("#")){
				break;
			}

			String eraName = tmpArray[0];

			int y = Integer.parseInt(tmpArray[1]);
			int m = Integer.parseInt(tmpArray[2]);
			int d = Integer.parseInt(tmpArray[3]);

			boolean newEra = false;
			if(y >= 32){
				newEra = true;
			}

			if(y == 31){
				if(m >= 5){
					newEra = true;
				}
			}

			if(newEra){
				System.out.println("? "+(y-30)+" "+m+" "+d);
			}
			else {
				System.out.println(eraName+" "+y+" "+m+" "+d);
			}
		}
	}

}



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

int main() {
    long long n;
    cin >> n;
    long long a[n];
    for (int i = 0; cin >> a[i]; i++) {
    }
    auto solve = [&]() {
        long long result = 0;
        for (long long i = 0, sum = 0; i < n; i++) {
            long long current = a[i];
            if (sum > 0) {
                if (sum + current >= 0) {
                    result += sum + current + 1;
                    current -= sum + current + 1;
                }
            } else if (sum < 0) {
                if (sum + current <= 0) {
                    result += 1 - sum - current;
                    current += 1 - sum - current;
                }
            }
            sum += current;
        }
        return result;
    };
    long long old = a[0];
    if (a[0] == 0) {
        a[0] = 1;
    }
    long long result = solve() + a[0] - old;
    if (a[0] > 0) {
        a[0] = -1;
    } else {
        a[0] = 1;
    }
    cout << min(result, solve() + abs(a[0] - old));
    return 0;
}


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

typedef long long ll;
ll num_count[100005];

int main() {
    int N;
    ll K, a;
    ll b, count = 0;
    cin >> N >> K;
    for (int i = 1; i < 100005; i++) num_count[i] = 0;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        num_count[a] += b;
    }
    for (int i = 1; i < 100005; i++) {
        if (num_count[i] >= K) {
            cout << i << endl;
            break;
        }
        K -= num_count[i];
    }
    return 0;
}

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

vector<long long int>memo;
set<long long int>S;

long long int saiki( long long int N ) {
	if( S.find( N ) != S.end() ) {
		return memo[N] = -1;
	}
	S.insert( N );
	if( N < 10 ) {
		return 0;
	}
	if( memo[N] != -1 ) {
		return memo[N];
	}
	long long int now = 1;
	long long int ret = INT_MAX;
	long long int next = 0;
	while( true ) {
		now *= 10;
		long long int a = N / now;
		long long int b = N%now;
		if( a == 0 ) {
			break;
		}
		next = max( next, a*b );
	}
	ret = min( ret, saiki( next ) + 1 );
	return memo[N] = ret;
}

int main() {
	long long int Q;
	cin >> Q;
	memo = vector<long long int>( 1e6 + 1, -1 );
	for( size_t i = 0; i < Q; i++ ) {
		long long int N;
		S.clear();
		cin >> N;
		cout << saiki( N ) << endl;
	}
}

Measured memory_bytes: 10748
#include <iostream>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <string>
#include <iostream>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (vec.at(i) >= M) {
			ans += 1;
			continue;
		}
	}

		cout << ans << endl;
	}
	    

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;



int main() {
  int n;
  scanf("%d",&n);
  string s;
  rep(i,n) s += "ACL";
  cout<<s<<endl;
  return 0;
}






















Measured memory_bytes: 3684
import java.util.*;

public class Main{

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = Integer.parseInt(sc.next());
    int r = Integer.parseInt(sc.next());

    if (n>=10)
      System.out.println(r);
    else
      System.out.println(r + 100*(10-n));

  }
}


Measured memory_bytes: 21716
#include<iostream>
#include<array>
#include<vector>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <utility>
#include <set>

using llint = long long int;
using namespace std;

namespace CsF {
#define MIN_INT -2147483648
#define MAX_INT 2147483647

#define nfor(I,J,K) for(int I = 0;I < J;I+=K)


	string ConvertBit(int N, int e) {
		string s = "";
		int r = 0;
		while (N != 0) {
			r = N % e;
			s = to_string(r) + s;
			N -= r;
			N /= e;
		}
		return s;
	}

	int GCD(int a, int b) {
		if (a < b)swap(a, b);
		int r = a % b;
		while (r != 0) {
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}

	int LCM(int a, int b) {
		int n = a * b;
		return (n / GCD(a, b));
	}

	int Count(string s, char c) {
		int cou = 0;
		nfor(i, s.length(), 1) {
			if (s[i] == c)cou++;
		}
		return cou;
	}
}

using namespace CsF;


int main() {
	int H, W;
	cin >> H >> W;
	string s[100];
	bool w[100];
	bool h[100];
	nfor(i, H, 1) {
		cin >> s[i];
	}
	nfor(i, H, 1) {
		if (s[i][0] == '.' && Count(s[i], s[i][0]) == W) {
			h[i] = false;
		}
		else h[i] = true;
	}
	bool flag = true;
	nfor(i, W, 1) {
		if (s[0][i] == '#') {
			w[i] = true;
			continue;
		}
		flag = true;
		nfor(j, H, 1) {
			if (s[0][i] != s[j][i]) {
				flag = false;
				break;
			}
		}
		if (flag) {
			w[i] = false;
		}
		else w[i] = true;
	}
	bool write = false;
	nfor(i, H, 1) {
		if (!h[i])continue;
		write = false;
		nfor(j, W, 1) {
			if (h[i] && w[j]) {
				cout << s[i][j];
				write = true;
			}
		}
		if (write)cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;
#define INF 1e+18
//#define int long long

signed main() {
	int N, M;
	while (cin >> N >> M, N) {
		vector<LL>S;
		vector<LL>big(N), sml(N);
		for (int i = 0; i < M; ++i) {
			LL s; cin >> s;
			S.push_back(s);
			int k;
			cin >> k;
			for (int j = 0; j < k; ++j) {
				int pe; cin >> pe;
				pe--;
				big[pe] += s;
				if (k == 1) {
					sml[pe] += s;
				}
			}
		}
		multiset<LL, greater<LL>>Big;
		for (int i = 0; i < N; ++i) {
			Big.insert(big[i]);
		}
		LL ans = 0;
		for (int i = 0; i < N; ++i) {
			Big.erase(Big.find(big[i]));
			LL tmp = *Big.begin() - sml[i];
			ans = max(ans, tmp);
			Big.insert(big[i]);
		}
		cout << ans + 1 << endl;
	}
}


Measured memory_bytes: 3404