akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
    using namespace std;
    #define lint long long
    #define inf 100000000000000000
    #define mod 1000000007
    #define MAX 200005
    #define pb push_back
    #define vit vector<int>::iterator
  
    lint A[MAX];
    int main()
    {
        ios::sync_with_stdio(0);
        cin.tie(0);
        lint n,ans,ns,ne;
        cin>>n;
        for(lint i=1;i<=n;i++) cin>>A[i];
        ans=1000;
        ns=ans/A[1];
        ne=ans%A[1];
        for(lint i=2;i<=n;i++){
            if(A[i]>A[i-1]){
                ans=max(ans,ns*A[i]+ne);
            }
            else{
                ns=ans/A[i];
                ne=ans%A[i];
            }
        }
        cout<<ans;
        return 0;
    }

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		int ans = n % 1000;
		if (ans == 0) {
			System.out.println(0);
		} else {
			System.out.println(1000 - ans);
		}
	}
}


Measured memory_bytes: 35832
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let k: usize = s.next().unwrap().parse().unwrap();
	let a: Vec<u32> = s.map(|a| a.parse().unwrap()).collect();
	let a: Vec<_> = (0..n).flat_map(|i| a[i..].iter().scan(0u64, |s, &a|{ *s += a as u64; Some(*s) })).collect();
	let msb = 63 - a[n - 1].leading_zeros();
	let mut ans = 0;
	let mut g: Vec<_> = (0..a.len()).collect();
	for bit in (0..msb + 1).rev() {
		let index: Vec<_> = g.iter().filter(|&&i| a[i] & (1 << bit) != 0).map(|&i| i).collect();
		if index.len() >= k {
			g = index;
			ans |= 1u64 << bit;
		}
	}
	println!("{}", ans);
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N,0);
  for(int i = 0; i<N;i++){
    cin >> vec.at(i);
  }
  
  vector<int> list(N,0);
  int ans;
  int times = 1;
  int pos = 1;
  while(1){
    if(list.at(pos-1) == 1){
      ans = -1;
      break;
    }
    int x = vec.at(pos-1);
    if(x == 2){
      ans = times;
      break;
    }
    times += 1;
    list.at(pos-1) = 1;
    pos = x;
  }
  
  cout << ans <<endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
bool pairCompare(const pairint& firstElof, const pairint& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x>>y>>z;
if(x<z){
  if(x+y>=z)std::cout << "YES" << '\n';
  else std::cout << "NO" << '\n';
}else if(x==z){
  std::cout << "YES" << '\n';
}else{
  std::cout << "NO" << '\n';
}

}


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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int gcd(ll a, ll b){
  if(b == 0){
    return a;
  }else{
    return gcd(b,a%b);
  }
}

vector<ll> sieve(ll n){
  vector<bool> is_prime(n+1,true);
  vector<ll> res;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      res.push_back(i);
      for(int j=2*i;j<=n;j+=i){
        is_prime[j] = false;
      }
    }
  }
  return res;
}

vector<ll> divisor(ll n){
  vector<ll> list;
  for(int i=1;i*i<=n;i++){
    if(n%i==0){
      list.push_back(i);
      if(n/i != i){
        list.push_back(n/i);
      }
    }
  }
  return list;
}

umap<int,int> prime_factor(ll n){
  umap<int,int> fac;
  for(int i=2;i*i<=n;i+=2){
    if(n%i == 0){
      int count = 0;
      while(n%i == 0){
        count++;
        n /= i;
      }
      fac[i] = count;
    }
  }
  if(n!=1)fac[n] = 1;
  return fac;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  string s;
  cin >> s;
  int n = (int)s.length();
  vector<bool> appear(26,false);
  REP(i,n){
    appear[s[i]-'a'] = true;
  }
  
  if(n < 26){
    REP(i,26){
      if(!appear[i]){
        cout << s+(char)('a'+i) << endl;
        return 0;
      }
    }
  }else {
    REP(i,26)appear[i] = false;
    REPD(i,n){
      for(int j=s[i]+1-'a' ; j < 26 ; j++){
		if(appear[j]){
          cout << s.substr(0,i) + (char)(j+'a') << endl;
          return 0;
        }
      }
      appear[s[i]-'a'] = true;
    }
  }
  
  cout << -1 << endl;
  
  return 0;
}


Measured memory_bytes: 3556
def fighting_over_candies(a: int, b: int, c: int)->bool:
    return (a + b) == c or (b + c) == a or (c + a) == b


if __name__ == "__main__":
    a, b, c = map(int, input().split())
    yes = fighting_over_candies(a, b, c)
    print('Yes' if yes else 'No')


Measured memory_bytes: 2940
#include<stdio.h>
#include<math.h>

typedef struct{
  double x,y;
}P;

void ko(int,P,P);

int main(){
  P a,b;
  int n;

  scanf("%d",&n);

  a.x = a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%f %f\n",a.x,a.y);

  ko(n,a,b);

  printf("%f %f\n",b.x,b.y);
  return 0;
}

void ko(int n,P a,P b){
  P s,t,u;
  double th = M_PI * 60.0 / 180.0;

  if(n==0)return;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x -s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x -s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  ko(n-1,a,s);
  printf("%f %f\n",s.x,s.y);
  ko(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
  ko(n-1,u,t);
  printf("%f %f\n",t.x,t.y);
  ko(n-1,t,b);
}



Measured memory_bytes: 2084
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main(){
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  
  string t;
  cin >> t;
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  
  if(s < t) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
//線形探索//O(q log n)のアルゴリズム
using System;
using System.Linq;

namespace tst
{
    class Program
    {
        public static void Binary(ref int cnt, int n, int[]S, int key)
        {
            int left = 0;
            int right = n;
            while (left < right)
            {
                int mid = (left + right) / 2;
                if (S[mid] == key)
                {
                    cnt++;
                    break;
                }else if (key < S[mid])
                {
                    right = mid;
                }
                else
                {
                    left = mid+1;
                }
            }
        }
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string text1 = Console.ReadLine();
            string[] SS = text1.Split(' ');
            int[] S = SS.Select(s => int.Parse(s)).ToArray();
            int q = int.Parse(Console.ReadLine());
            string text2 = Console.ReadLine();
            string[] TT = text2.Split(' ');
            int[] T = TT.Select(s => int.Parse(s)).ToArray();

            int cnt = 0;

            for(int i=0; i<q; i++)
            {
                Binary(ref cnt, n, S, T[i]);

            }

            Console.WriteLine(cnt);
        }

    }
}


Measured memory_bytes: 31312
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define INF (2e9)
const int maxv=100000+10;
const int maxe=500000+10;
int V,E,S;
struct Edge{int from, to,cost;};
int d[maxv];
Edge es[maxe];

void bellman_ford(int s)
{
    for(int i=0;i<V;i++) d[i]=INF;
    bool bUpdate=true;
    d[s]=0;
    while(true)
    {
        bUpdate=false;
        for(int i=0;i<E;i++)
        {
            Edge &e=es[i];
            if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost)
            {
                d[e.to]=d[e.from]+e.cost;
                bUpdate=true;
            }
        }
        if(!bUpdate) break;
    }
    for(int i=0;i<V;i++)
    {
        if(d[i]!=INF)  printf("%d\n",d[i]);
        else printf("INF\n");


    }
}
int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    scanf("%d%d%d",&V,&E,&S);
    int u,v,dd;
    for(int i=0;i<E;i++)
    {
        scanf("%d%d%d",&u,&v,&dd);
        es[i].from=u;
        es[i].to=v;
        es[i].cost=dd;
    }
    bellman_ford(S);

    return 0;
}

Measured memory_bytes: 9348
import math

a, b, h, m = map(int, input().split())

a_angle = h * 30 + m / 2
b_angle = m * 6
cos_x = math.cos(math.radians(a_angle-b_angle))
d = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * cos_x)
print(d)


Measured memory_bytes: 62200
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("Yes\n")
#define NO printf("No\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 1000005
int main()
{
    //sync;
    lld a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a-c) <= d) YES;
    else if(abs(a-b) <= d and abs(b-c) <= d) YES;
    else NO;
    return 0;
}

Measured memory_bytes: 256
use std::io::Read;
fn main() {
    let (h,w,a,b)= {
        let inputstr = {
            let mut inputstr = String::new();
            std::io::stdin().read_to_string(&mut inputstr).unwrap();
            inputstr
        };
        let mut inputiter = inputstr.split_whitespace();
        let h =  inputiter.next().unwrap().parse::<usize>().unwrap();
        let w =  inputiter.next().unwrap().parse::<usize>().unwrap();
        let a =  inputiter.next().unwrap().parse::<usize>().unwrap();
        let b =  inputiter.next().unwrap().parse::<usize>().unwrap();
        (h,w,a,b)
    };

    for y in 1..h+1{
        for x in 1..w+1{
            let output = if (x>a) ^ (y>b) {1} else {0};
            print!("{}",output)
        }
        print!("\r\n")
    }
}


Measured memory_bytes: 5244
/*
 * a.cpp
 *
 *  Created on: 2019/06/08
 *      Author: MEIP-users
 */




#include <bits/stdc++.h>
#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>
using namespace std;
#define MOD (long long int)(1e9+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)(1e9+10)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main() {
	string s;
	int k;
	cin >> k;
	cin >> s;
	if(k >= s.size()){
		cout << s <<endl;
	}else{
		rep(i, k){
			cout <<s[i];
		}
		cout << "..."<<endl;
	}
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int num, limit;
	vector<int> height;
	cin >> num >> limit;
	
	for(int i=0; i<num; i++)
	{
		int temp;
		cin >> temp;
		height.push_back(temp);
	}

	int ans = 0;
	for(auto it=height.begin(); it != height.end(); it++)
	{
		if((*it - limit) >= 0)
		{
			ans++;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const int INF = INT_MAX/10;
const ll MOD = 1e9+7;

int a[212345],opt[212345],dp[1<<26];
int main(){
  string s;cin >> s;
  int N = s.length();
  repeat(i,N){
    a[i+1] = a[i]^(1<<(s[i]-'a'));
  }
  //debugArray(a,N+1);
  fill(opt,opt+N+1,INF);
  fill(dp,dp+(1<<26),INF);
  opt[0] = 0;
  dp[0] = 0;
  for(int i=1;i<=N;i++){
    opt[i] = dp[a[i]]+1;
    for(int x=1;x<1<<26;x<<=1){
      opt[i] = min(opt[i],dp[a[i]^x]+1);
      //debug(opt[8]);
    }
    dp[a[i]]=min(dp[a[i]],opt[i]);
  }
  //debugArray(opt,N+1);
  cout << opt[N] << endl;
  return 0;
}


Measured memory_bytes: 264324
#　変数 n, m, k, arr1, arr2, acum1, acum2, ans

n, m, k = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

acum1 = [0]
for i in range(n):
    acum1.append(acum1[-1] + arr1[i])
acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1] + arr2[i])

ans = 0
j = m
for i in range(n+1):
    if acum1[i] > k:
        break
    while acum2[j] > k - acum1[i] and j > 0:
        j -= 1
    ans = max(ans, i+j)
print(ans)




















Measured memory_bytes: 47552
from collections import deque
from itertools import product

H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x)-1, input().split())
Dh, Dw = map(lambda x: int(x)-1, input().split())
maze = [list(input()) for _ in range(H)]
walkFrom = deque([(Ch, Cw)]) # 歩く出発地点の候補集
warpFrom = deque() # ワープ出発地点の候補集
WalkRange = [(1, 0), (-1, 0), (0, 1), (0, -1)]
WarpRange = list(filter(lambda x: x != (0, 0), product(range(-2, 3), repeat=2)))
warpCount = 0

def move(h_from, w_from, moveRange):
  for h, w in moveRange:
    h_to, w_to = h_from + h, w_from + w
    if 0 <= h_to < H and 0 <= w_to < W and maze[h_to][w_to] == '.':
      maze[h_to][w_to] = warpCount
      walkFrom.append((h_to, w_to))


while walkFrom:
  # 歩ける範囲をすべて歩く
  while walkFrom:
    h, w = walkFrom.popleft()
    warpFrom.append((h, w))
    move(h, w, WalkRange)
  # ワープする
  warpCount += 1
  while warpFrom:
    h, w = warpFrom.popleft()
    move(h, w, WarpRange)

goal = maze[Dh][Dw]
print('-1') if goal in ['.', '#'] else print(goal)


Measured memory_bytes: 176284
<?php

$arr = array(
    array(3550, 3750, 4000, 4300, 5000, 5500, 7000),
    array(7100, 7700, 8300, 8900, 10500, 11600, 14800)
);
$rank = explode(',', 'AAA,AA,A,B,C,D,E,NA');

while (($line = trim(fgets(STDIN))) !== '') {
    sscanf($line, '%f %f', $a, $b);
    $a = (int)($a * 100);
    $b = (int)($b * 100);
    $key = 7;
    for ($i = 0; $i < 7; $i++) {
        if ($a < $arr[0][$i] && $b < $arr[1][$i]) {
            $key = $i;
            break;
        }
    }

    echo $rank[$key], PHP_EOL;
}

Measured memory_bytes: 6640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n=1):n(n), f(n+1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i]) continue;
primes.push_back(i);
f[i] = i;
for (ll j = i*i; j <= n; j += i) {
if (!f[j]) f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x;}
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0) return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
int main(){
    int n;cin >> n;
    Sieve s(1005000);
    vector<int> a(n);
    map<int,int> mp;
    for(int i=0; i<n; i++){
        cin >> a[i];
        vector<P> v=s.factor(a[i]);
        for(auto p: v){
            mp[p.first]=max(mp[p.first],p.second);
        } 
    }
    mint lcm=1;
    for(auto p: mp){
        for(int i=0; i<p.second; i++){
            lcm*=p.first;
        }
    }
    mint ans=0;
    for(int i=0; i<n; i++){
        mint b=lcm/a[i];
        ans+=b;
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 4984
input()
a=list(map(int,input().split()))
b=list(map(int,input().split()))
fa=lambda n:1 if n==0 else n*fa(n-1)
in1=1
in2=1
li=[i+1 for i in range(len(a))]
li2=[i+1 for i in range(len(a))]
for i in a:
  in1+=fa(len(li)-1)*li.index(i)
  del li[li.index(i)]
for i in b:
  in2+=fa(len(li2)-1)*li2.index(i)
  del li2[li2.index(i)]
print(abs(in1-in2))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
using namespace std;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
template<class T> void print(const T& x){cout << x << endl;}
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(c % gcd(a, b) == 0) cout << "YES";
    else cout << "NO";
    cout << endl;
    
    return 0;
}




Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using llong = long long;

const int INF = 100100100;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;

    cout << N * N << "\n";

    return 0;
}


Measured memory_bytes: 256
import sys
import random
import time
import numpy as np

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def prob(e1,e2,T):
    if e2 < e1:
        return 1
    else:
        return np.exp((e1-e2)/T)

def solve():
    D = ni()
    c = nl()
    s = [nl() for _ in range(D)]
    m = 26
    start = time.time()
    dT = 0.995
    T = 200

    def calc(sche, m=26):
        last = [-1] * m
        ans = 0
        for i in range(D):
            t = sche[i]
            ans += s[i][t]
            last[t] = i
            for j in range(m):
                ans -= c[j] * (i - last[j])
        return ans

    def change(d, q, sc):
        b = sche[d]
        fq, bq = -1, D
        fb, bb = -1, D
        for i in range(d):
            if sche[i] == q:
                fq = i
            if sche[i] == b:
                fb = i
        for i in range(D-1, d, -1):
            if sche[i] == q:
                bq = i
            if sche[i] == b:
                bb = i
        sc += ((bb - d) * (bb - d - 1) // 2 + (d - fb) * (d - fb - 1) // 2) * c[b]
        sc += ((bq - fq) * (bq - fq - 1) // 2) * c[q]
        sc -= s[d][b]
        sc -= ((bq - d) * (bq - d - 1) // 2 + (d - fq) * (d - fq - 1) // 2) * c[q]
        sc -= ((bb - fb) * (bb - fb - 1) // 2) * c[b]
        sc += s[d][q]
        return sc

    sche = [0] * D
    for i in range(D):
        sche[i] = s[i].index(max(s[i]))
    sc = calc(sche)
    bestst = sche[:]
    best = sc

    while time.time() - start < 1.8:
        for _ in range(300):
            d = random.randint(0, D-1)
            q = random.randint(0, m-1)
            nsc = change(d, q, sc)
            if best < nsc:
                bestst = sche[:]
                best = sc
            if random.random() < prob(sc, nsc, T):
                sche[d] = q
                sc = nsc
        T *= dT
    prn([1 + x for x in bestst])

    return

solve()

Measured memory_bytes: 27696
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int ans = 0;
    if(2 * c < a + b){
        ans += min(x,y)*2*c;

        if(x > y){
            if(a < 2*c){
                ans += (x-y)*a;
            }else{
                ans += (x-y)*2*c;
            }

        }else{
            if(b < 2*c){
                ans += (y-x)*b;
            }else{
                ans += (y-x)*2*c;
            }

        }

    }else{
        ans += x*a+y*b;
    }

    cout << ans << endl;

}

Measured memory_bytes: 3596
#include <stdio.h>
 
int main(){
    
    long long n, sum = 0;
    scanf("%lld", &n);
    for(long long i = 1 ; i <= n ; i++){
    	if(i%3 != 0 && i%5 != 0){
    		sum+=i;
		}
	}
    printf("%lld\n", sum);
    
    return 0;
}

Measured memory_bytes: 1736
"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

var re = /\s+|$/;
reader.on('close', () => {
    console.log(aux(lines));
});

function aux(lines)
{
    var m, n;
    var mat = [];
    var b = [];
    var l = 0;
    //console.log('lines: ', lines.join('\n'));
    [m, n] = lines[l++].trim().split(' ').map(Number);
    //console.log('m,n: ', m, n);
    for (var i=0; i<m; i++) {
	mat[i] = new Array(n);
    }
    for (var i=0; i<m; i++) {
	var ln = lines[l++].trim().split(' ').map(Number);
	mat[i] = ln;
    }
    b = new Array(n);

    //console.log('mat: ');
/*
    for (var i=0; i<m; i++) {
	console.log(mat[i].map(String).join(' '));
    }
*/
    for (var j=0; j<n; j++) {
	//console.log('j: ', j, 'lines[j]: ', lines[l]);
	b[j]  = Number(lines[l++]);
    }
    //console.log('b: ', b.map(String).join(' '));

    var c = new Array(m);
    for (var i=0; i<m; i++) {
	var s = 0;
	for (var j=0; j<n; j++) {
	    s += mat[i][j]*b[j];
	}
	//console.log('s: ', s);
	c[i] = s;
	
    }
    //console.log('c: ', c);

    return(c.map(String).join('\n'));
}


Measured memory_bytes: 20328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int E[5001], n[5001], C[5001], H[2501];
bool vis[2501];
void dfs(int v) {
	vis[v] = true;
	for (int p = H[v]; p; p = n[p]) {
		int to = E[p];
		if (!vis[to]) dfs(to);
	}
}

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


	int N, M, P;
	cin >> N >> M >> P;
	rep1(i, M) {
		int a;
		cin >> a >> E[i] >> C[i];
		n[i] = H[a];
		H[a] = i;
	}
	ll D[2501];
	rep1(i, N) D[i] = -2e9;
	D[1] = 0;
	int q[2501] = {};
	q[1] = 1;

	//こんな明らかに正しくない提出をして何をしたいというのかこの男は
	int mae = 0;
	int renzoku = 0;

	rep1(k, N) {
		int cnt = 0;
		rep1(i, N) {
			if (q[i] == k) {
			cnt++;
				for (int p = H[i]; p; p = n[p]) {
					int to = E[p];
					ll d = D[i] + C[p] - P;
					if (D[to] < d) {
						D[to] = d;
						q[to] = k + 1;
					}
				}
			}
		}
		if (mae == cnt) renzoku++;
		else renzoku = 0;
		if (renzoku >= 100 && cnt >= 1500) break;
		mae = cnt;
	}

	rep1(i, N) {
		if ((q[i] == N + 1) && !vis[i]) dfs(i);
	}

	if (vis[N]) co(-1);
	else co(max(0ll, D[N]));

	Would you please return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}

//int ()



int main()
{
  int a ,b, c, d, e, X, Y;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  int  A[100003]={};
  int  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans=0;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  long long  tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d", &a);

  scanf("%d", &A[0]);
  for(i=1;i<a;i++){
  scanf("%d", &A[i]);
    if(A[i-1]==A[i]-1)
    { B[A[i-1]-1]=1;
//  printf("%d", B[i]);
     
    }

  }
  for(i=0;i<a;i++){
    scanf("%d", &A[i]);
    cnt=cnt+A[i];
//    printf("%d ", cnt);
  }
  for(i=0;i<a-1;i++){
    scanf("%d", &A[i]);
    if(B[i]==1) cnt=cnt+A[i];
//    printf("%d ", cnt);
  }
 
  

    
//    printf("%s %d %d\n", s[i],C[i][0],C[i][1]);
   // printf("%d\n", C[i][1]);
/*  for(i=0;i<addr;i++){
//  scanf("%lld%lld", &B[0][i],&B[1][i]);
//    ans=ans+A[i];
    printf("%lld ", A[i]);
  }
*/
    printf("%d ", cnt);
   

return 0;
}


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

int main()
{
  int n;
  cin >> n;
  pair<pair<string, int>, int> p[110];

  for (int i = 0; i < n; i++)
  {
    string s;
    int score;
    cin >> s >> score;
    p[i] = make_pair(make_pair(s, -score), i + 1);
  }

  sort(p, p + n);
  for (int i = 0; i < n; i++)
  {
    cout << p[i].second << endl;
  }
}

Measured memory_bytes: 256
def myAnswer(A:int,B:int,C:int) ->int:
   if(A == B and B == C):
      if(A % 2 == 0):
         return -1
      else:
         return 0
   counter = 0
   while A%2 == 0 and B%2 == 0 and C%2 == 0:
      A, B, C = ((B//2 + C//2), (A//2 + C//2), (A//2 + B//2))
      counter += 1
   return counter

def modelAnswer():
   tmp=1
def main():
   A,B,C = map(int,input().split())
   print(myAnswer(A,B,C))

if __name__ == '__main__':
   main()

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

int main() {
  double N;
  cin >> N;
  vector<pair<double, double>> xy(N);
  vector<vector<double>> dist(N, vector<double>(N, 0));
  double kai = 1;
  for (double i = 0; i < N; ++i) {
    kai *= i + 1;
    cin >> xy.at(i).first >> xy.at(i).second;
  }
  for (int i = 0; i < N; ++i) {
    double xi = xy.at(i).first, yi = xy.at(i).second;
    for (int j = 0; j < N; ++j) {
      double xj = xy.at(j).first, yj = xy.at(j).second;
      dist.at(i).at(j) = pow(pow(xi - xj, 2) + pow(yi - yj, 2), 0.5);
    }
  }
  vector<int> v(N);
  iota(v.begin(), v.end(), 0);
  double sum = 0;
  do {
    for (int i = 1; i < N; ++i) {
      double prev = v.at(i - 1);
      double next = v.at(i);
      sum += dist.at(prev).at(next);
    }
  } while (next_permutation(v.begin(), v.end()));
  double result = sum / kai;
  cout << setprecision(10) << result << endl;
}

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

using namespace std;

int main(){
  int N,tmp,res=0;
  vector<int> L;
  cin >> N;
  for (int i = 0; i < 2*N; i++) {
    cin >> tmp;
    L.push_back(tmp);
  }
  sort(L.begin(), L.end());
  for (int i = 0; i < 2*N; i+=2) {
    res += min(L[i],L[i+1]);
  }
 cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> P(A), Q(B), R(C);
    for (int i = 0; i < A; i++) cin >> P[i];
    for (int i = 0; i < B; i++) cin >> Q[i];
    for (int i = 0; i < C; i++) cin >> R[i];

    sort(P.begin(), P.end(), greater<int>());
    sort(Q.begin(), Q.end(), greater<int>());

    vector<int> D;
    for (int i = 0; i < X; i++) D.push_back(P[i]);
    for (int i = 0; i < Y; i++) D.push_back(Q[i]);
    for (int i = 0; i < C; i++) D.push_back(R[i]);
    sort(D.begin(), D.end(), greater<int>());

    long long res = 0;
    for (int i = 0; i < X + Y; i++) res += D[i];

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3572
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 1000003
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


Max = mod
#二項係数とその逆元テーブルを作る前処理
fac = [0]*(Max)
finv = [0]*(Max)
inv = [0]*(Max)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,Max):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
#O(1)でmod計算した組合せ数を計算
def Comb(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod


Q = int(input())
def query(x,d,n):
    if x == 0:
        return 0
    if d == 0:
        return pow(x,n,mod)
    k = (x*inv[d])%mod
    if k+n-1 >= mod:
        return 0
    ans = fac[k+n-1]*finv[k-1]%mod
    ans *= pow(d,n,mod)
    ans %= mod
    return ans
for i in range(Q):
    x,d,n = map(int,input().split())
    print(query(x,d,n))

Measured memory_bytes: 77276
n = int(input())
a = list(map(int,input().split()))
dp = [0 for i in range(3)]
for i in range(1,n+1):
  ai = a[i-1]
  if i%2:
    dp[1] = max(dp[0],dp[1])
    dp[0] += ai
  if i%2 == 0:
    dp[2] = max(dp[1],dp[2])
    dp[1] += ai
  if i >= 3 and i%2:
    dp[2] += ai
if n%2 == 0:
  print(max(dp[0],dp[1]))
else:
  print(max(dp[1],dp[2]))

Measured memory_bytes: 31416
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()

using ll = long long;

int main()
{
	int N;

	cin >> N;

	int ans = 0;
	for (int i = 1; i <= N; i++)
	{
		if (to_string(i).size() % 2 != 0)
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  vector<int> a;
  a.resize(10);
  for(int i=0;i<10;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  cout<<a[9]<<endl<<a[8]<<endl<<a[7]<<endl;
}

Measured memory_bytes: 1212
n = int(input())
s = list(input())

#E(東)を向いてる人数
ruiseki = [0]
for i in range(n):
    if s[i] == "E":
        ruiseki.append(ruiseki[i] + 1)
    else:
        ruiseki.append(ruiseki[i])

INF = float("inf")
ans = INF
for i in range(n):
    if s[i] == "E":
        sub = -1
    else:
        sub = 0
    change = i - (ruiseki[i] - ruiseki[0] - sub)
    change += ruiseki[-1] - ruiseki[i]
    ans = min(ans, change)

print(ans)

Measured memory_bytes: 17528
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	auto V=vecin(N);
	reverse(ALL(V));

	REP(i,N-1){
		cout << V[i] << ' ';
	}
	out(V[N-1]);

	return 0;
}



Measured memory_bytes: 3112
list = []
N = int(input())
list = [input() for i in range(N)]
print("AC x " +  str(list.count('AC')))
print("WA x  " +  str(list.count("WA")))
print("TLE x  " +  str(list.count("TLE")))
print("RE x  " +  str(list.count("RE")))

Measured memory_bytes: 16252
fun main(args: Array<String>) {
    val n = readInputLine().toInt()
    
    val list = mutableListOf<Triple<Int, String, Int>>()
    
    for (i in 1..n) {
        val (s, p) = readInputLine().split(" ")
        list.add(Triple(i, s, p.toInt()))
    }
    
    list.sortByDescending{it.third}
    list.sortBy{it.second}
    
    for (l in list) {
        println(l.first)
    }
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37932
n = int(input())
h = list(map(int, input().split()))
tmp = h[-1]
for i in range(n-1)[::-1]:
	if h[i] <= tmp:
		tmp = h[i]
	elif h[i] == tmp+1:
		continue
	else:
		print("No")
		exit()
print("Yes")


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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define reps(i, s, n) for(int i = (int)s; i < (int)n; i++)
#define in(i) std::cin >> i;
#define print(i) std::cout << i;
#define println(i) std::cout << i << std::endl;

int main() {
    rep(i, 5) {
        int t;
        in(t)
        if(t == 0) {
            print(i + 1);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <set>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> da(n),li(n);
    rip(i,n,0){
        cin >> da[i];
        li[da[i]-1]=i;
    }
    multiset<int> se;
    se.insert(-1);
    se.insert(-1);
    se.insert(n);
    se.insert(n);
    long long ans=0;
    rip(i,n,0){
        int no=n-1-i;
        auto itr=se.lower_bound(li[no]);
        int w=*++itr;
        itr--;
        int z=*itr;
        int y=*--itr;
        int x=*--itr;
        //printf("%d %d %d %d\n",x,y,z,w);
        ans+=(ll)(no+1)*((y-x)*(z-li[no])+(w-z)*(li[no]-y));
        se.insert(li[no]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int q;
    scanf("%d", &q);
    while(q--){
        string n;
        cin >> n;
        set<string> S;
        int cnt = 0;
        while(n.size() > 1){
            if(S.find(n) != S.end()){
                cnt = -1;
                break;
            }
            S.insert(n);
            int tmp = 0;
            For(i, 1, n.size()){
                chmax(tmp, stoi(n.substr(0, i)) * stoi(n.substr(i)));
            }
            ++cnt;
            n = to_string(tmp);
        }
        printf("%d\n", cnt);
    }
}


Measured memory_bytes: 3344
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 2010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    ll l,r,l1 = 1,l2 = 1e9,r1 = 1,r2 = 1e9;
    ll ans = 0;
    vector<P> p;
    cin >> n;
    rep(i,n){
        cin >> l >> r;
        chmax(ans,r-l+1);
        p.push_back(P(l,r));
        chmax(l1,l);
        chmin(r2,r);
    }
    ans += max(r2-l1+1,0ll);
    rep(i,n){
        tie(l,r) = p[i];
        if (l1 == l) chmax(r1,r);
        if (r2 == r) chmin(l2,l);
    }
    SORT(p);
    bool flagl = 1,flagr = 1;
    vector<ll> left,right;
    left.push_back(1);
    right.push_back(1e9);
    rep(i,n){
        tie(l,r) = p[i];
        bool con = 0;
        if (flagl && l == l1 && r == r1){
            flagl = 0;
            con = 1;
        }
        if (flagr && l == l2 && r == r2){
            flagr = 0;
            con = 1;
        }
        if (con) continue;
        left.push_back(l);
        right.push_back(r);
    }
    left.push_back(1);
    right.push_back(1e9);
    ll m = left.size();
    //array_output(all(left));
    //array_output(all(right));
    rep(i,m-2){
        chmin(right[m-i-2],right[m-i-1]);
    }
    rep(i,m-1){
        //PRINT("................");
        //cout << r2 << " " << l1 << endl;
        //cout << max(left[i],l2) << " " << min(right[i+1],r1) << endl;
        chmax(ans,r2-max(left[i],l2)+1+min(right[i+1],r1)-l1+1);
    }
    PRINT(ans);
}


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

s = [0, 0, 0, 0, 0]    
for i in range(N):
    S = input()
    if S[0] == "M":
        s[0] += 1
    elif S[0] == "A":
        s[1] += 1
    elif S[0] == "R":
        s[2] += 1
    elif S[0] == "C":
        s[3] += 1
    elif S[0] == "H":
        s[4] += 1
        
ans = 0

for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += s[i] * s[j] * s[k]

print(ans)

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

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;



const int N = 1e6+5;
vi g[N];
int vis[N];

void pre(){
  rep(i,2,N){
    if(sz(g[i]))
       continue;
    for(int j = i; j<N; j+=i)
      g[j].pb(i);
  }
}



void solve() {

   pre();
   int n,gcd,ok=1;
   cin>>n;
   vi a(n);
   rep(i,0,n){
     cin>>a[i];
     if(i)
       gcd=__gcd(gcd,a[i]);
     else
       gcd=a[i];
     trav(x,g[a[i]]){
        if(vis[x])
          ok=0;
        vis[x]=1;
     }
   }
   
   if(ok)
     done("pairwise coprime")
  
   
   if(gcd==1)
      cout<<"setwise coprime";
   else
      cout<<"not coprime";
 
   
  
}


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
   // cin >> t;
    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}



int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}


int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}


int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

typedef long long ll;

using namespace std;

int main(){
    int n,k,a,b;
    
    scanf("%d%d",&n,&k);
    
    for(int i=0;i<k;i++){
        scanf("%d%d",&a,&b);
        if(a>n/2) a=n+1-a;
        if(b>n/2) b=n+1-b;
        
        printf("%d\n",min(a-1,b-1)%3+1);
        
    }
    
    return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#define int long long int
using namespace std;


int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    string s,t; cin>>s>>t;
    int i,j;
    int n=s.size(),m=t.size();

    int dp[n+1][m+1];
    for(i=0;i<=n;i++) dp[i][0]=0;

    for(j=0;j<=m;j++) dp[0][j]=0;

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }


//    for(i=0;i<=n;i++)
//    {
//        for(j=0;j<=m;j++)
//        {
//            cout<<dp[i][j]<<"  ";
//        }
//        cout<<"\n";
//    }

    list<char> res;
    i=n,j=m;
    while(i-1>=0 && j-1>=0)
    {
        if(s[i-1]==t[j-1])
        {
            res.push_front(s[i-1]);
            i=i-1;
            j=j-1;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
            {
                i--;
            }
            else
                j--;
        }

    }
    for(char x:res)
        cout<<x;

    return 0;
}



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

using namespace std;

int n, a[3005];
vector<int> g[3005];

bool dfs(int u, int p) {
	bool win = false;
	for (int v : g[u]) if (v != p && !dfs(v, u) && a[v] < a[u]) win = true;
	return win;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for (int i = 1, u, v; i < n; ++i) {
		scanf("%d%d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for (int i = 1; i <= n; ++i) if (dfs(i, 0)) printf("%d ", i);
	return 0;
}

Measured memory_bytes: 640