akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;

//パスカルの三角形 O(n^2)
long long combination(int n, int r)
{
    if(n < r)
        return 0;
    if(n-r < r)
        r = n-r;
    long long ret = 1;
    for(int i=0; i<r; i++){
        ret *= (n--);
        ret /= i+1;
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,p;
    cin >> n >> p;
    int even = 0, odd = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(a%2 == 0) even++;
        else odd++;
    }
    int ans = 0;
    if(p == 0){
        ll fi = 0, se = 0;
        for(int i = 0; i <= even; i++){
            fi += combination(even,i);
        }
        for(int i = 0; i <= odd; i += 2){
            se += combination(odd,i);
        }
        cout << fi * se << endl;
    }else{
        ll fi = 0, se = 0;
        for(int i = 0; i <= even; i++){
            fi += combination(even,i);
        }
        for(int i = 1; i <= odd; i += 2){
            se += combination(odd,i);
        }
        cout << fi * se << endl;        
    }
}

Measured memory_bytes: 256
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

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

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define LEFT(x) (x<<1)
#define RIGHT(x) (x<<1|1)

#define INF 1e18
#define MOD 1000000007

using namespace std;

vi adj[200010];
ll a[200010];
ll tree[200010*4];
int ans[200010];
int n;
ll val_ant;

void update(int i, int l, int r, ll val, bool volta) {
    if(l == r) {
        if(volta) tree[i] = val_ant;
        else {
            val_ant = tree[i];
            tree[i] = val;
        }
    }else {
        int mid = (l+r)>>1;
        if(tree[LEFT(i)] < val)
            update(RIGHT(i), mid+1, r, val, volta);
        else
            update(LEFT(i), l, mid, val, volta);
        tree[i] = max(tree[LEFT(i)], tree[RIGHT(i)]);
    }
}

ll query(int i, int l, int r) {
    if(l == r) return (tree[i] < INF ? l : l-1);
    else {
        int mid = (l+r)>>1;
        if(tree[LEFT(i)] < INF)
            return query(RIGHT(i), mid+1, r);
        else
            return query(LEFT(i), l, mid);
    }
}

void dfs(int u, int p) {
    update(1, 1, n, a[u], false);
    ll va = val_ant;
    ans[u] = query(1, 1, n);
    for(int v : adj[u]) {
        if(v == p) continue;
        dfs(v, u);
    }
    val_ant = va;
    update(1, 1, n, a[u], true);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 0; i < 200010 * 4; i++) tree[i] = INF;
    for(int i = 0; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].PB(b);
        adj[b].PB(a);
    }

    dfs(1, 1);
    for(int i = 1; i <= n; i++) cout << ans[i] << "\n";
}


Measured memory_bytes: 37464
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
const int INF = 1e9;
int dp[100010];

int main(){
  int n;
  cin >> n;
  rep(i,n+1) dp[i] = INF;
  dp[0] = 0;
  queue<int> q;
  q.push(0);

  while(!q.empty()){
    int now = q.front();q.pop();
    for (int pow6 = 1; pow6 + now <= n; pow6*=6){
      if(dp[pow6 + now] == INF) {
        q.push(pow6+now);
        dp[pow6 + now] = dp[now] + 1;
      }
    }
    for (int pow9 = 1; pow9 + now <= n; pow9*=9){
      if (dp[pow9 + now] == INF){
        q.push(pow9+now);
        dp[pow9 + now] = dp[now] + 1;
      }
    }
  }
  cout << dp[n] << endl;
  

  
  return 0;
  
}


Measured memory_bytes: 4072
import java.util.*;

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

        String str = "";
        int[] cnt = new int[26];

        while(sc.hasNext()) {
            str = sc.nextLine();
            str = str.toLowerCase();
            char[] c = str.toCharArray();
            for(int i = 0; i < c.length; i++) {
                if('a' <= c[i] && c[i] <= 'z') {
                    cnt[c[i] - 'a']++;
                }
            }
        }
        for(int i = 0; i < 26; i++) {
            System.out.println(((char)(i + 'a')) + " : " + cnt[i]);
        }
    }
}

Measured memory_bytes: 26152
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  string s;
  cin >> s;
  
  int mx = 0;
  vector<int> vec(s.size());
  rep(i, s.size()) {
    vec[i] = s[i] - '0';
    mx += s[i] - '0';
  }
  
  for(int i = 0; i <= s.size()-1; i++) {//i要素目を１つ下げてi+1以降は9
    if (vec[i] == 0) continue;
    int cnt = 0;
    for (int j = 0; j <= i; j++) {
      cnt += vec[j];
    }
    cnt--;
    cnt += 9*(s.size() - (i+1));
    mx = max(mx, cnt);
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
		cout<<"OK";
		return 0;
		}
	}
	cout<<"NG";
	
}


Measured memory_bytes: 3584
//
// LIS and LDS
//
// verified:
//   ARC 091 E - LISDL
//     https://beta.atcoder.jp/contests/arc091/tasks/arc091_c
//

/*
    0 〜 N-1 の順列であって
    LIS (最長増加部分列) の長さが A
    LDS (最長減少部分列) の長さが B
    となるものを 1 つ求める
 
    
*/


#include <iostream>
#include <vector>
using namespace std;


// LIS and LDS
// A + B <= N+1, AB >= N are necessarily and sufficient
vector<long long> LISLDS(long long N, long long A, long long B) {
    vector<long long> res;
    for (long long i = B-1; i >= 0; --i) res.push_back(i);
    
    if (A == 1) return res;
    
    long long rem = N - B;  //  残りの数字の数
    long long p = rem / (A-1);  //  
    long long r = rem % (A-1);  // 
    
    long long b = r;
    long long c = A-1-b;
    
    for (int i = 0; i < b; ++i) {
        int size = (int)res.size();
        for (int j = 0; j < p+1; ++j) {
            res.push_back(size + p+1 - 1 - j);
        }
    }
    for (int i = 0; i < c; ++i) {
        int size = (int)res.size();
        for (int j = 0; j < p; ++j) {
            res.push_back(size + p - 1 - j);
        }
    }
    
    return res;
}

int main() {
    long long N, A, B; cin >> N >> A >> B;
    if (A + B > N+1 || A * B < N) cout << -1 << endl;
    else {
        vector<long long> res = LISLDS(N, A, B);
        for (int i = 0; i < res.size(); ++i) {
            cout << res[i] + 1;
            if (i != (int)res.size() - 1) cout << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 6384
#include<bits/stdc++.h>
int cmp(int a[],char bb[],int n)
{
	char aa[10];
	for(int i=0;i<n;i++){
		aa[i]=a[i]-'0';
	}
	aa[n]='\0';
	if(strcmp(aa,bb)==0){
		return 1;
	}
	return 0;
}
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[10],b[10],c[10],d[10];
	for(int i=1;i<=n;i++){
		a[i-1]=i;
		d[i-1]=i;
	}
	char bb[10],cc[10];
	for(int i=0;i<n;i++){
		scanf("%d",&b[i]);
		bb[i]=b[i]-'0';
	}
	for(int i=0;i<n;i++){
		scanf("%d",&c[i]);
		cc[i]=c[i]-'0';
	}
	bb[n]='\0';cc[n]='\0';
	int aaa=0,bbb=0;
	while(cmp(a,bb,n)!=1){
		aaa++;
		next_permutation(a,a+n);
	}
	while(cmp(d,cc,n)!=1){
		bbb++;
		next_permutation(d,d+n);
	}
	cout<<abs(aaa-bbb)<<endl;
	return 0;
}

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

class Hello
{
    static void Main()
    {
        var Z = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long X = Z[0], A = Z[1], B = Z[2];


        var a = B - A;
        if (a > X)
        {
            Console.WriteLine("dangerous");
        }
        else if(a > 0)
        {
            Console.WriteLine("safe");
        }
        else
        {
            Console.WriteLine("delicious");
        }

    }
}

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

int main() {
  int n; cin>>n;
  vector<int> a(3*n);
  rep(i, 3*n) cin>>a[i];

  vector<ll> sum1(n+1), sum2(n+1);
  priority_queue<int, vector<int>, greater<int>> que1;
  priority_queue<int> que2;
  rep(i, n) {
    sum1[0] += a[i];
    que1.push(a[i]);
    sum2[n] += a[3*n-i-1];
    que2.push(a[3*n-i-1]);
  }
  rep(i, n) {
    int tmp1=que1.top();
    if (tmp1<a[n+i]) {
      que1.push(a[n+i]);
      sum1[1+i] = sum1[i]+a[n+i]-tmp1;
      que1.pop();
    }
    else sum1[1+i] = sum1[i];
    int tmp2=que2.top();
    if (tmp2>a[2*n-1-i]) {
      que2.push(a[2*n-1-i]);
      sum2[n-1-i]=sum2[n-i]+a[2*n-1-i]-que2.top();
      que2.pop();
    } else sum2[n-1-i]=sum2[n-i];
  }
  ll ans=-1e16;
  rep(i, n+1) ans=max(ans, sum1[i]-sum2[i]);
  cout<<ans<<endl;
}


Measured memory_bytes: 3964
N=int(input())
P=list(map(int, input().split() ))
Q=[0]*N
Q[0]=P[0]
cnt=0
       
for i in range(1,N):
 Q[i]=min(Q[i-1],P[i])
       
for j in range(N):
  #print(Q[j],P[j])
  if Q[j]==P[j]:
    cnt+=1
       
print(cnt)

Measured memory_bytes: 24744
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << endl;
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define wh while
#define ve vector
#define mp make_pair
#define tp tuple
#define mt make_tuple
#define pb push_back
#define pof pop_front
#define pob pop_back
#define pf push_front
#define fr front
#define ft first
#define sc second
#define tos to_string
#define len length
#define rt return
#define br break
#define con continue
#define lcm(n, m) (n * m / __gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m) - 1;i>=(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) n.begin(), n.end()
#define allr(n) n.rbegin(), n.rend()
#define sp(n) cout << fixed << setprecision(n)
#define pi 3.14159265358979323846
#define inf 1000000007
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

ve<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};

int main() {
  st s;
  ci(s);
  int cnt = 0;
  rep(i, sz(s) - 1){
    if(s.at(i + 1) != s.at(i)){
      cnt++;
    }
  }
  co(cnt);
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  string S, T;
  cin >> S >> T;
  sort(S.begin(),S.end());
  sort(T.rbegin(), T.rend());
  //cout << S << " " << T << endl;
  if(S < T){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Red or Not
            int a = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            if (a >= 3200)
            {
                Console.WriteLine(s);
            }
            else
            {
                Console.WriteLine("red");
            }
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int n;
vl v;

ll solve(int k) {
	vl back_up = v;
	ll diff = 0;
	ll cnt = 0;
	ll sign = k;
	rep(i,0,n) {
		v[i] += diff;
		if(sign * v[i] > 0) {

		} else if(sign * v[i] < 0) {
			ll x = abs(v[i] - sign);
			diff += x * sign;
			cnt += x;
		} else if(sign * v[i] == 0) {
			diff += sign;
			cnt += abs(sign);
		}
		sign *= -1;
	}
	v = back_up;
	return cnt;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	v.resize(n);
	rep(i,0,n) {
		cin >> v[i];
	}
	rep(i,1,n) {
		v[i] = v[i-1]+v[i];
	}
	ll ret = solve(1);
	ret = min(ret, solve(-1));
	cout << ret << '\n';
	return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M, std::vector<long long> A)
{
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        sum += A[i];
    }

    sort(A.begin(), A.end());

    if (A[N - M] * (4 * M) >= sum)
    {
        cout << YES << endl;
    }
    else
    {
        cout << NO << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	int ntmp = n;
	int sumdigit = ntmp%10;
	for(int i=0;i<10;i++){
		ntmp = ntmp/10;
		sumdigit = sumdigit + ntmp%10;
	}
	
	if(n%sumdigit==0)	cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int H, W, i, j;
	while(1){
		cin >> H >> W;
		if(H == 0 and W == 0){
			break;
		}else{
			for(i = 0; i < H; i++){
				for(j = 0; j < W; j ++){
					cout << "#";
				}
				cout << endl;
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3104
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
 
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
 
int n,m;
int main() {
	int k;
	ll S;
	scanf("%d%d%lld", &n, &k, &S);
	REP(i, k) printf("%lld ", S);
	int rem = n-k;
	REP(i, rem) {
		printf("%lld ", (ll)(S>500000000 ? 1 : 1000000000));
	}

 
	return 0;
}


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

int main()
{
    int n,k,m;
    cin>>n>>k>>m;
    bool f = false;;
   for(int i =k;i<=m;i++){
    if(i%n == 0){
        f= true;
    }
   }
   if(f)cout<<"OK\n";
   else cout<<"NG";

    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a ,  b;
    cin >> a;
    b = a;
    reverse( a.begin() , a.end() );
    if( a == b ) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {

	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;

	int m = 0;
	int b = 0;
	vector<int> l;
	for(int i = 0; i < N; i++) {
		int t = S[i] - '0';
		if(t != b) {
			l.push_back(i);
			b = t;
		}
		int n, j;
		//calc n
		if(t == 0) {
			j = K * 2;
		} else {
			j = K * 2 + 1;
		}
		if(j > l.size()) n = i + 1;
		else n = i - l[l.size() - j] + 1;
//		cout << i << " " << j << " " << n << endl;
		m = max(n, m);
	}

//	for(auto x: l) cout << x << " ";
//	cout << endl;
	cout << m << endl;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  
  int i;
  vector<char> a(s.size()), b(t.size());
  for(i = 0; i < s.size(); i++)  a.at(i) = s.at(i);
  for(i = 0; i < t.size(); i++)  b.at(i) = t.at(i);
  
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  
  int frag = 1;
  for(i = 0; i < min(a.size(), b.size()); i++){
    if(a.at(i) < b.at(i)){
      cout << "Yes" << endl;
      frag = 0;
      break;
    }
    else if(a.at(i) > b.at(i)){
      cout << "No" << endl;
      frag = 0;
      break;
    }
  }
  
  if(frag){
    if(a.size() < b.size()) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int N=sc.nextInt();
	int B[]=new int[N-1];
	for(int i=0;i<B.length;i++) {
		B[i]=sc.nextInt();
	}
	int ans=B[0];
	for(int i=1;i<B.length;i++) {
		if(B[i-1]>B[i]) {
			ans+=B[i];
		}else {
			ans+=B[i-1];
		}
	}
	ans+=B[N-2];
	System.out.println(ans);

}
}


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

int arr[1010];

int main()
{
      int i, id, d, N, T, A;
      cin >> N >> T >> A;
      i = N;
      for (int i = 0; i < N; i++)
      {
            cin >> arr[i];
            arr[i] = 1000 * T - 6 * arr[i];
      }
      i = 0;
      id = 1;
      d = abs(1000 * A - arr[i++]);
      while (i < N)
      {
            if (abs(1000 * A - arr[i++]) < d)
            {
                  d = abs(1000 * A - arr[i - 1]);
                  id = i;
            }
      }
      i = 0;
      cout << id;
      return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 5005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
char s[5005];
int dp[5005][5005],N,L;

void Solve() {
    read(N);
    scanf("%s",s + 1);
    L = strlen(s + 1);
    dp[0][0] = 1;
    for(int i = 0 ; i < N ; ++i) {
	for(int j = 0 ; j <= N ; ++j) {
	    if(j == 0) update(dp[i + 1][j],dp[i][j]);
	    else update(dp[i + 1][j - 1],mul(dp[i][j],2));
	    update(dp[i + 1][j + 1],dp[i][j]);
	}
    }
    out(dp[N][L]);enter;
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 98048
#include <stdio.h>
int main(void)
{
    int i,n,j,k,l,m,x[7],side[5]={2,3,5,4,2};
    char o[7][3]={"","","N","W","E","S","NN"};
    
    for(i=1;i<7;i++) scanf("%d",&x[i]);
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%d %d",&l,&m);

        for(j=1;x[j]!=l;j++);
        
        for(k=0;o[j][k]!='\0';k++){
            x[0]=x[1];
        
            switch(o[j][k]){
            
                case 'W':
                    x[1]=x[3];
                    x[3]=x[6];
                    x[6]=x[4];
                    x[4]=x[0];
                    break;
            
                case 'E':
                    x[1]=x[4];
                    x[4]=x[6];
                    x[6]=x[3];
                    x[3]=x[0];
                    break;
            
                case 'S':
                    x[1]=x[5];
                    x[5]=x[6];
                    x[6]=x[2];
                    x[2]=x[0];
                    break;
            
                case 'N':
                    x[1]=x[2];
                    x[2]=x[6];
                    x[6]=x[5];
                    x[5]=x[0];
                    break;
            }
        }
        for(j=0;m!=x[side[j]];j++);
        
        printf("%d\n",x[side[j+1]]);
    }
    
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <cstdio>
#include <math.h>
#include <map>
#include <algorithm>
#include <deque>
#include <stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>pa;
const int N =3e4+100;
const int inf=0x3f3f3f3f;


int main()
{
    int n;scanf("%d",&n);
    int a[1000];
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int sum=0;
    for(int i=2;i<n;i++) {
        if((a[i]>a[i+1]&&a[i]<a[i-1])||(a[i]>a[i-1]&&a[i]<a[i+1]))
            sum++;
    }
    printf("%d\n",sum);
    return 0;
}



Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b)-1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep(i, n) for(int i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T>& p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T>& vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;
constexpr ll MOD = 1000000007;

int N, M;
constexpr int MAX = 3001;
ll dp[MAX][MAX][2];//m個取り出したあとにn個の赤球、左端経験

int main()
{
    cin >> N >> M;

    if(N == 1){
        ll ans = 2;
        rep(i, M){
            ans = (ans*2)%MOD;
        }
        cout << ans << endl;
        return 0;
    }

    rep(r, N+1){
        if(r == 0){
            dp[0][0][1] = 1;
        } else {
            dp[0][r][0] = 1;
        }
    }
    rep1(m, M){
        rep(r, N+1){
            if(r == 0){
                dp[m][0][1] = (dp[m-1][0][1]+dp[m-1][1][0]+dp[m-1][1][1]) % MOD;
            } else if (r == N){
                dp[m][N][0] = (dp[m-1][N][0] + dp[m-1][N-1][0])%MOD;
                dp[m][N][1] = (dp[m-1][N][1] + dp[m-1][N-1][1])%MOD;
            } else if(r == 1){
                dp[m][1][0] = (dp[m-1][1][0] + dp[m-1][2][0])%MOD;
                dp[m][1][1] = (dp[m-1][0][0] + dp[m-1][1][0] + dp[m-1][0][1] + 2*dp[m-1][1][1] + dp[m-1][2][1])%MOD;
            } else {
                dp[m][r][0] = (dp[m-1][r-1][0] + 2*dp[m-1][r][0] + dp[m-1][r+1][0])%MOD;
                dp[m][r][1] = (dp[m-1][r-1][1] + 2*dp[m-1][r][1] + dp[m-1][r+1][1])%MOD;
            }
        }
    }
    ll sum = 0;
    rep(i, N+1){
        sum= (sum + dp[M][i][1])%MOD;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 140928
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
m = h * w
X = []

for i, ai in enumerate(a):
    X += [i + 1 for _ in range(ai)]

for hi in range(h):
    if hi % 2 == 0:
        print(*X[hi * w:(hi + 1) * w])
    else:
        print(*X[hi * w:(hi + 1) * w][::-1])


Measured memory_bytes: 3884
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

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

int main() {
	int N;
	cin >> N;
	vector<int> s(N);
	int sum_point = 0;

	REP(i, N) {
		cin >> s[i];
	}

	sort(s.begin(), s.end());

	REP(i, N) {
		sum_point += s[i];
	}

	if (sum_point % 10 != 0) {
		cout << sum_point << endl;
	}
	else {
		bool flag_non_ten = false;
		REP(i, N) {
			if (s[i] % 10 != 0) {
				sum_point -= s[i];
				flag_non_ten = true;
				break;
			}
		}
		if (flag_non_ten) {
			cout << sum_point << endl;
		}
		else {
			cout << 0 << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    ll a[n],b[n];
    REP(i,n){
        cin >> a[i];
    }
    REP(i,n){
        cin >> b[i];
    }
    ll inc = 0, dec = 0;
    REP(i,n){
        if(a[i] < b[i]){
            inc += (b[i] - a[i]) / 2;
        }else{
            dec += a[i] - b[i];
        }
    }
    if(inc >= dec){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        switch (sc.nextLine()){
            case "SUN":
                System.out.println(7);
                break;
            case "MON":
                System.out.println(6);
                break;
            case "TUE":
                System.out.println(5);
                break;
            case "WED":
                System.out.println(4);
                break;
            case "THU":
                System.out.println(3);
                break;
            case "FRI":
                System.out.println(2);
                break;
            case "SAT":
                System.out.println(1);
                break;
        }
    }
}


Measured memory_bytes: 23124
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

class Main {
	public static void main(String[] args)
			throws IOException {

		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));
		String number = br.readLine();
		String s = br.readLine();
		StringTokenizer st;
		int count = 0;
		ArrayList<String> list = new ArrayList<>();

		while (!(s == null || "".equals(s))) {
			st = new StringTokenizer(s);
			Integer[] tri = new Integer[3];
			tri[0] = Integer.parseInt(st
					.nextToken());
			tri[1] = Integer.parseInt(st
					.nextToken());
			tri[2] = Integer.parseInt(st
					.nextToken());

			Arrays.sort(tri, Collections
					.reverseOrder());

			String yesno = new String();
			yesno = "NO";

			double compare = Math.pow(tri[0], 2)
					- Math.pow(tri[1], 2) - Math
							.pow(tri[2], 2);
			if (compare == 0) {
				yesno = "YES";
			}

			list.add(count++, yesno);
			s = br.readLine();

		}
		for (String string : list) {
			System.out.println(string);
		}

	}

}

Measured memory_bytes: 25868
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;
const int N = 1e5 + 5 , mod = 1e9 + 7;

int A[N];

int main()
{
    ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n , sum = 0; cin >> n;
    for (int i=0; i<n; i++)
        cin >> A[i];
    sort(A , A+n);
    for (int i=0; i<n-1; i++)
        sum += A[i];
    sum += A[n-1]/2;
    cout << sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
int n;
ll N[maxn];
int main()
{
    ios::sync_with_stdio(false);
    ll sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> N[i];
        sum += N[i];
    }
    ll ans = min(abs(sum - 2 * N[n-1]), abs(sum - 2 * N[0])), get = N[0];
    for (int i = 1; i < n - 1; i++)
    {
        ans = min(ans, abs(sum - get - get));
        get += N[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
int f[11111];
int d[11111];
bool v[11111];
vector<int>b[11111];
vector<int>c[11111];
vector<int>a[11111];
void spfa()
{
    queue<int>q;
    while (!q.empty()) q.pop();
    memset(d,63,sizeof(d));
    memset(v,0,sizeof(v));
    q.push(1);
    d[1] = 0; v[1] = 1;
    int x;
    while (!q.empty())
    {
        x = q.front();
        q.pop();
        for (int i = 0; i < b[x].size(); i++)
          if (d[b[x][i]] > d[x] + c[x][i])
          {
              d[b[x][i]] = d[x] + c[x][i];
              if (!v[b[x][i]])
              {
                  v[b[x][i]] = 1;
                  q.push(b[x][i]);
              }
          }
        v[x] = 0;
    }
}
void fspfa()
{
    queue<int>q;
    while (!q.empty()) q.pop();
    memset(f,63,sizeof(f));
    memset(v,0,sizeof(v));
    q.push(1);
    f[1] = 0; v[1] = 1;
    int x;
    while (!q.empty())
    {
        x = q.front();
        q.pop();
        for (int i = 0; i < b[x].size(); i++)
          if (d[b[x][i]] == d[x] + c[x][i] && f[b[x][i]] > a[x][i])
          {
              f[b[x][i]] = a[x][i];
              if (!v[b[x][i]])
              {
                  v[b[x][i]] = 1;
                  q.push(b[x][i]);
              }
          }
        v[x] = 0;
    }
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    while (!(n == 0 && m == 0))
    {
        int x,y,z,t;
        for (int i = 1; i <= n; i++)
        {
            a[i].clear();
            b[i].clear();
            c[i].clear();
        }
        for (int i = 1; i <= m; i++)
        {
            scanf("%d%d%d%d",&x,&y,&z,&t);
            b[x].push_back(y);
            b[y].push_back(x);
            c[x].push_back(z);
            c[y].push_back(z);
            a[x].push_back(t);
            a[y].push_back(t);
        }
        spfa();
        fspfa();
        int ans = 0;
        for (int i = 1; i <= n; i++) ans += f[i];
        printf("%d\n",ans);
        scanf("%d%d",&n,&m);
    }
    return 0;
}

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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pvec;

typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;

typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

ll gcd(ll x, ll y){
    ll r = x%y;
    if(r == 0) return y;
    else return gcd(y, r);
} 

ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >>c; 
    string ans="No";
    if(a==b && a!=c) ans="Yes";
    if(a==c && a!=b) ans="Yes";
    if(b==c && a!=b) ans="Yes";
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
///////////////////// author : TrEbLeCleF /////////////////////
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
#define FOr(i, a, b) for (int i=a; i<(b); i++)
#define For(i, a) for (int i=0; i<(a); i++)
#define FOrr(i,a,b) for (int i = (b)-1; i >= a; i--)
#define Forr(i,a) for (int i = (a)-1; i >= 0; i--)
/////////////////////////// ..... ///////////////////////////
#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args){
cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }
/////////////////////////// ..... ///////////////////////////
#define int ll
#define pb(x) push_back(x)
#define print(v,s,e) for(int i = s; i < e; i++)cout << v[i]<<" ";cout<<"\n";
#define INF 1e17
#define PI 3.14159265358979323846 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
/////////////////////////// GLOBAL ///////////////////////////
const int N = 3001;
int dp[N+1][N+1];
int a[N+1];
/////////////////////////// GLOBAL ///////////////////////////
void solve(){
	int n;cin >> n;
	FOr(i,1,n+1)cin >> a[i];
	FOrr(L,1,n+1){
		FOr(R,1,n+1){
			if(L==R)dp[L][R]=a[L];
			else
			dp[L][R] = max(a[L]-dp[L+1][R],a[R]-dp[L][R-1]);
		}
	}
	cout << dp[1][n] <<"\n";

}

int32_t main(){ 
	#ifndef ONLINE_JUDGE
		clock_t tStart = clock();
		freopen("TC", "r", stdin);
		//freopen("output.txt","w",stdout);
	#endif 
    ios_base:: sync_with_stdio(false); 
   	cin.tie(0); 
	int t=1;
	//cin >> t;
	for(int tt=1;tt<=t;tt++){
		//cout << "Case #"<<tt<<": ";
		solve();
	}
	#ifndef ONLINE_JUDGE
    	cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
    #endif
}

Measured memory_bytes: 74024
N,K = map(int,input().split())
MOD = pow(10,9)+7
ans = 0
for i in range(K,N+2): #KからN+1
  MAX = i*(2*N-i+1)//2
  MIN = i*(i-1)//2
  #print(i,MIN,MAX)
  ans += (MAX-MIN+1)%MOD
print(ans%MOD)

Measured memory_bytes: 9032
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val x = sc.nextLong()
    val a = (0 until n).map { sc.next().toLong() }
    println(problem109c(n, x, a))
}

fun problem109c(n: Int, x: Long, a: List<Long>): Long {
    /**
     * 最大公約数
     * @param big 2つの値の大きな方
     * @param small 2つの値の小さな方
     */
    fun computeGreatestCommonDivisor(big: Long, small: Long): Long {
        val rest = big % small
        return if (rest == 0L) small else computeGreatestCommonDivisor(small, rest)
    }

    if(n == 1) {
        return Math.abs(x - a[0])
    }

    val list = mutableListOf<Long>()
    for (i in 0 until n) {
        list.add(Math.abs(x - a[i]))
    }
    val divs = mutableListOf<Long>()
    var min = Long.MAX_VALUE
    for (i in 0 until n - 1) {
        min = Math.min(min, computeGreatestCommonDivisor(list[i], list[i + 1]))
        divs.add(min)
    }
//    debugLog(list)
//    debugLog(divs)
    return divs.min()!!
}

Measured memory_bytes: 47232
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x;
    cin>>x;
    vector<int>vec(x);
    for(int i=0;i<x;i++){
        cin>>vec[i];
    }
    reverse(vec.begin(),vec.end());
    for(int i=0;i<x-1;i++){
        cout<<vec[i]<<" ";
    }
    cout<<vec[x-1]<<endl;
    
}


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

int main() {
	int n, m;
	char *conv_from, *conv_to;
		
	while(cin >> n, n){
		conv_from = new char [n];
		conv_to = new char [n];
		for(int i=0; i<n; i++){
			cin >> conv_from[i] >> conv_to[i];
		}
		cin >> m;
		for(; m; m--){
			char c;
			cin >> c;
			for(int i=0; i<n; i++){
				if(c == conv_from[i]){
					c = conv_to[i];
					break;
				}
			}
			cout << c;
		}
		cout << endl;
	}
		
	return 0;
}

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

using namespace std;

int main()
{
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	
	int rec1 = a * b;
	int rec2 = c * d;
	
	if(rec1 > rec2)
		printf("%d\n", rec1);
	else
		printf("%d\n", rec2);
	
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;

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

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

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

	vector<int> dp(n, INF);

	dp.at(0) = 0;

	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j <= k; j++)
		{
			if (i - j < 0)
			{
				break;
			}
			chmin(dp.at(i), dp.at(i - j) + abs(h.at(i) - h.at(i - j)));
		}
	}

	cout << dp.back() << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>

#define v vector
#define ll long long 
#define vpll vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
#define mod 1000000007
#define MAXN 200001
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


void solve()
{
    ll n;
    cin>>n;
    set<ll> factors1;
    set<ll> factors2;
    set<ll> ans;
    if(n == 2)
    {
        cout<<1<<endl;
        return;
    }
    for (ll i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            factors1.insert(i);
            factors1.insert(n/i);
        } 
    }
    for (ll i=1; i<=sqrt(n-1); i++) 
    { 
        if ((n-1)%i == 0) 
        { 
            ans.insert(i);
            ans.insert((n-1)/i);
        } 
    }
    ans.erase(ans.begin());
    std::set<ll>::iterator it;
    for(it = factors1.begin() ; it != factors1.end() ; it++)
    {
        if(*it == 1)
        {
            continue;
        }
        ll temp = n;
        while(temp%(*it) == 0)
        {
            temp /= *it;
        }
        if(temp == 1)
        ans.insert(*it);
        if(temp > 1 && (temp-1)%(*it) == 0)
        ans.insert(*it);
    }
    cout<<ans.size()<<endl;
}

int main()
{
    int t;
    // cin>>t;
    t = 1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(void){
  int a[3];
  cin >> a[0];
  cin >> a[1];
  cin >> a[2];
  sort(a, a+3);
  cout << (a[2] * 10 + a[1] + a[0]);
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
long long n,zs;
string st;
char s[10005];
int main()
{
	cin>>st;
	for (int i=0;i<st.size();i++)
	  {
	  	if (st[i]=='C'||st[i]=='F') s[++n]=st[i];
	  }
	for (int i=1;i<=n;i++)
	  if (s[i]=='C'&&s[i+1]=='F') zs++;
	if (zs>0) cout<<"Yes"<<endl;else
	  cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
while True:
         a,b,c= map(str,input().split())
         if b == "+":
                  print(int(a)+int(c))
         elif b == "-":
                  print(int(a)-int(c))
         elif b == "*":
                  print(int(a)*int(c))
         elif b == "/":
                  print(int(a)//int(c))
         else:
                  break
         



Measured memory_bytes: 5592
integer(16) A,B
integer(16) g,gf,i
integer(16) cnt

read*,A,B
g=gcd(A,B)
gf=g
cnt=1
do i=2,int(sqrt(real(gf)))+1
  if(mod(g,i)==0)then
    do while(mod(g,i)==0)
      g=g/i
    end do
    cnt=cnt+1
  endif
end do
if(g/=1)cnt=cnt+1
print"(i0)",cnt

contains
pure function gcd(a,b)
integer(16),intent(in)::a,b
integer(16) gcd
integer(16) s,t
s=a
gcd=b
t=mod(s,gcd)
do while(t/=0)
  s=gcd
  gcd=t
  t=mod(s,gcd)
end do
end function gcd

end

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

int main(){
  int q;
  cin >> q;
  REP(i, q){
    int n;
    cin >> n;
    int res = 0;
    while(n >= 10){
      int divisor = 10;
      int maxim = 0;
      REP(j, 6){
        if(divisor >= n) break;
        maxim = max(maxim, (n / divisor) * (n % divisor));
        divisor *= 10;
      }
      n = maxim;
      res++;
      // cout << n << endl;
      if(res > 100) { res = -1; break; }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for (int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second

typedef long long ll;

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

void solve1() {
    int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;

    int ud = abs(sy-ty);
    int rl = abs(sx-tx);
    rep(i, ud) {
        cout << 'U';
    }

    rep(i, rl) {
        cout << 'R';
    }

    rep(i, ud)
    {
        cout << 'D';
    }

    rep(i, rl)
    {
        cout << 'L';
    }

    cout << 'L';

    rep(i, ud+1)
    {
        cout << 'U';
    }

    rep(i, rl+1)
    {
        cout << 'R';
    }

    cout << 'D';
    cout << 'R';

    rep(i, ud+1)
    {
        cout << 'D';
    }

    rep(i, rl+1)
    {
        cout << 'L';
    }

    cout << 'U' << endl;;
}

int main()
{
    solve1();
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, m;
    cin >> n >> m;
    vector<int> a(m), OpenSet(m, 0);
    for(int i = 0; i < m; ++i){
        int b;
        cin >> a[i] >> b;
        for(int j = 0; j < b; ++j){
            int c;
            cin >> c;
            --c;
            OpenSet[i] |= 1 << c;
        }
    }

    vector<vector<int>> dp(1 << n, vector<int>(m + 1, INF));
    dp[0][0] = 0;
    for(int bit = 0; bit < (1 << n); ++bit){
        for(int i = 0; i < m; ++i){
            if(dp[bit][i] == INF)   continue;
            chmin(dp[bit][i + 1], dp[bit][i]);
            chmin(dp[bit | OpenSet[i]][i + 1], dp[bit][i] + a[i]);
        }
    }

    int ans = dp[(1 << n) - 1][m];
    if(ans == INF)  ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 16384
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("test.txt","r",stdin);
	ll h,w;
	cin>>h>>w;
	char arr[h+1][w+1];
	for(ll i=1;i<=h;i++)
	{
		for(ll j=1;j<=w;j++)
			cin>>arr[i][j];
	}
	/*for(ll i=1;i<=h;i++)
	{
		for(ll j=1;j<=w;j++)
			cout<<arr[i][j]<<" ";
		cout<<endl;
	}*/
	ll dp[h+1][w+1];
	bool flag=false;
	for(ll i=1;i<=w;i++)
	{
		if(arr[1][i]=='#')
			flag=true;
		if(flag==0)
			dp[1][i]=1;
		else
			dp[1][i]=0;
	}
	flag=false;
	for(ll i=1;i<=h;i++)
	{
		if(arr[i][1]=='#')
			flag=true;
		if(flag==0)
			dp[i][1]=1;
		else
			dp[i][1]=0;
	}
	for(ll i=2;i<=h;i++)
	{
		for(ll j=2;j<=w;j++)
		{
			if(arr[i][j]=='#')
				dp[i][j]=0;
			else
				dp[i][j]=((dp[i-1][j]%mod)+(dp[i][j-1]%mod))%mod;
		}
	}
	cout<<dp[h][w]<<endl;



}

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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define eof !cin.eof()
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define ull unsigned long long
#define ll long long
#define ld long double
#define sz(a) a.size()
#define all(s) s.begin(), s.end()
#define rall(s, n) s, s + n
#define x first
#define y second
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ii pair <int, int>
#define iii pair <int, ii>
#define vi vector <int>
#define vit vector <int> :: iterator
#define vlt vector <ll> :: iterator
#define vl vector <ll>
#define vii vector <ii>
#define viii vector <iii>
#define vd vector <double>
#define vull vector <ull>
#define vc vector <char>
#define vs vector <string>
#define vb vector <bool>
#define vvi vector <vector <int>>
#define vvl vector <vector <ll>>
#define EPS 1e-10
#define INF 1000000000
#define mod 1000000007
#define reset(a, nilai) memset(a, nilai, sizeof(a))
#define minof min_element
#define maxof max_element
using namespace std;

ll n, a;
int main () {
	IOS;
	
	scanf("%lld", &n);
	a = 1e18;
	for (int i = 1; (ll) i * i <= n; i++) {
		if (n % i == 0) {
			a = min(a, n / i);
		}
	}
	printf("%lld\n", ((n / a) - 1) + (a - 1));
	return 0;
}


Measured memory_bytes: 384