akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;

constexpr 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;
  }

  // for prime mod
  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;
  }
};

// 高速nCk（n == 10**9まで対応）
mint nCk(int n, int k) {
  mint x = 1, y = 1;
  for (int i = 0; i < k; i++) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

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

  int n, a, b;
  cin >> n >> a >> b;

  mint total = mint(2).pow(n);
  total -= 1;
  total -= nCk(n, a);
  total -= nCk(n, b);

  cout << total.x << ln;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	int s;
	cin >> s;
	lli ans = 0;
	for(int i=1; i<1000; i++){
		lli si = i *(i+1) /2;
		for(int j=1; j<1000; j++){
			lli sj = j *(j+1) /2;
			if(si*sj > s) break;
			for(int k=0; ; k++){
				lli curr = si*sj +k*sj*i;
				if(curr > s) break;
				if((s-curr) %((si+k*i)*j) == 0){
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3096
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        PriorityQueue<Work> queue = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Work(sc.nextInt(), sc.nextInt()));
        }
        int cur = 0;
        while (queue.size() > 0) {
            Work w = queue.poll();
            cur += w.cost;
            if (cur > w.time) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
    
    static class Work implements Comparable<Work> {
        int cost;
        int time;
        
        public Work(int cost, int time) {
            this.cost = cost;
            this.time = time;
        }
        
        public int compareTo(Work another) {
            return time - another.time;
        }
    }
}

Measured memory_bytes: 67056
// https://atcoder.jp/contests/dp/tasks/dp_g
#include <iostream>
#include <map>
#include <stack>
#include <vector>
using namespace std;

int N, M;
vector<vector<int>> adjlist(100004);
vector<int> memo(100004);

int depth(int start)
{
    if (memo[start] > 0)
        return memo[start];

    int res = 0;
    for (auto& next : adjlist[start]) {
        res = max(res, 1 + depth(next));
    }
    return memo[start] = res;
}

int main()
{
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int tmpx, tmpy;
        cin >> tmpx >> tmpy;
        adjlist[tmpx].push_back(tmpy);
    }


    int res = 0;
    for (int i = 1; i <= N; ++i)
        res = max(res, depth(i));

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 100005
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

int main() {

	LL n, d, x, y, ans = 0,i;
	cin>>n>>d;

	while(n--) {

		cin>>x>>y;

		if(sqrt(x*x + y*y) <= d) ans++;
	}

	cout<<ans<<endl;

	return 0;
}

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

int main(){
  vector<int> x(3,0);
  REP(i,3) cin>>x.at(i);
  if(x.at(0)+x.at(1)>=x.at(2)) cout<<"Yes";
  else cout<<"No";
}

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

using namespace std;
using ll = long long;


ll Q;
ll szs[2];
ll P[2][100010];

int main(){
    for(ll j = 0; j < 2; j++) cin >> szs[j];
    cin >> Q;
    for(ll j = 0; j < 2; j++)
        for(ll i = 0; i < szs[j]; i++)
            cin >> P[j][i];
    for(ll i = 0; i < Q; i++){
        ll X;
        cin >> X;
        ll ans = 1LL << 60;
        for(int l = 0; l < 2; l++){
            int now = l;
            int nxt = now ^ 1;
            // 一番近い神社に行ってから寺に行く場合
            // 一番近い寺に行ってから神社にいく場合
            // SとTをswapして考える必要あり
            ll pos1 = lower_bound(P[now], P[now] + szs[now], X) - P[now];
            ll pos2 = pos1 - 1;
            for(ll pos : {pos1, pos2}){
                if(pos >= szs[now] || pos < 0) continue;
                ll dist = abs(X - P[now][pos]);
                ll p1 = lower_bound(P[nxt], P[nxt] + szs[nxt], P[now][pos]) - P[nxt];
                ll p2 = p1 - 1;
                for(ll p : {p1, p2}){
                    if(p >= 0 && p < szs[nxt]) 
                        ans = min(ans, dist + abs(P[now][pos] - P[nxt][p]));
                }
            }
        }
        cout<< ans << endl;
    }

    return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <cmath>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

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



int main()
{

	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,t;
	cin >> n >>t;
	VI a(n), p(n);
	rep(i,n) cin >> a[i];
	int mn=a[0], mx=0;
	rep(i,n){
		mn = min(mn, a[i]);
		p[i] = a[i] - mn;
		mx = max(mx, p[i]);
	}
	int ans =0;
	rep(i,n) if(p[i]==mx) ans++;
	//for(auto x :p) printf("%d, ",x); puts("");
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int count =1;
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
			count *=3;
		}
		int no = 1;
		for (int i=0;i<N;i++) {
			if (A[i]%2==0) {
				no *=2;
			}
		}
		System.out.println(count -no);
	}
}

Measured memory_bytes: 35888
import math


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

    if temp != 1:
        arr.append(temp)

    if not arr:
        arr.append(n)

    return arr


A, B = map(int, input().split())

gcd = math.gcd(A, B)
f = factorization(gcd)
print(len(f))


Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc174/abc174_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, D;
  cin >> N >> D;

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

  int ans = 0;
  rep(i, N) {
    double dis = sqrt(pow(p[i], 2) + pow(q[i], 2));
    if (dis <= D) {
      ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 4652
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fill(v, h) memset((v), h, sizeof(v))
using namespace std;
const int MOD = 1000000007;

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;
}

int main(void)
{
    int x;
    cin >> x;
    double ans = 1;
    for (int b = 2; pow(b, 2) <= x; b++)
    {
        for (int p = 2; pow(b, p) <= x; p++)
        {
            ans = max(ans, pow(b, p));
            cerr << ans << " ";
        }
    }
    cout << ans << endl;
    return 0;
}

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

bool Check(int start, int end, string s){
  for( int i = start; i < end; i++){
    if(s.at(i) != s.at((end-1) - i))
      return true;
  }
  return false;
}

int main(void){
  int n;
  bool flag = false;
  string s;
  cin >> s;
  n = s.size();
  
  flag = Check(0, n, s);
  if(!(flag)){
   // cout << "1#" << endl;
  	flag = Check(0, ((n - 1) / 2), s);
  }
  if(!(flag)){
    //cout << "2#" << endl;
   flag = Check((n + 3) / 2, n, s);
  }
  
  if(flag)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  
  
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N, X, Y = [int(i) for i in input().split()]

K = [int(0) for i in range(N-1)]
for i in range(1, N+1):
    for j in range(i+1, N+1):
        K[min(j-i, abs(i-X)+1+abs(j-Y))-1] += 1
for k in K:
    print(k)


Measured memory_bytes: 3444
#include<cstdio>
#include<cstring>

char map[10][10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

int main(void) {
    char in[2000];
    int n;
    scanf("%d",&n);
    while(~scanf("%s", in)) {
        char c;
        int pos=0;
        while(c=in[pos]) {
            int i=0;
            while(c==in[pos+(++i)]);
            if(c-'0') printf("%c", map[c-'0'][(i-1)%strlen(map[c-'0'])]);
            pos += i;
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

ll mod = 1000000007;

ll mypow(ll a, ll b)
{
    if (b == 1)
    {
        return a;
    }
    else
    {
        return a * mypow(a, b - 1);
    }
}

signed main()
{
    ll n, p;
    cin >> n >> p;
    map<ll, ll> m;
    for (ll i = 2; i * i <= p; i++)
    {
        while (p % i == 0)
        {
            m[i]++;
            p /= i;
        }
    }
    if (p != 1)
    {
        m[p]++;
    }
    ll ans = 1;
    for (auto &i : m)
    {
        if (i.second >= n)
        {
            ans *= mypow(i.first, i.second / n);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i,0,(n))
#define pb(n) push_back(n)
#define mp(n,m) make_pair(n, m)
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;


int dp[11][400][(1<<10)];


int main(){
	int n, s;
	while(cin>>n>>s){
		if(s > 385 || n > 10) {
			cout<<0<<endl;
			continue;
		}
		for(int i = 0; i < 11; i++){
			for(int j = 0; j < 400; j++){
				for(int k = 0; k < (1<<10); k++){
					dp[i][j][k] = -1;
				}
			}
		}
		dp[0][0][0] = 1;
		for(int i = 1; i <= n; i++){
			for(int j = 0; j < 400; j++){
				for(int k = 0; k < 10; k++){
					for(int l = 0; l < 1<<10; l++){
						if(j+k*i >= 400 || dp[i-1][j][l] < 0 || (l & 1 << k)) continue;
						dp[i][j+k*i][l|1<<k] = max(0, dp[i][j+k*i][l|1<<k]);
						dp[i][j+k*i][l|1<<k] += dp[i-1][j][l];
					}
				}
			}
		}
		int ans = 0;
		for(int i = 0; i  < 1 << 10; i++){
			ans += max(0, dp[n][s][i]);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 20596
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val n = in.readLine().toInt

    val min = Math.ceil(n / 1.08).toInt
    val max = Math.ceil((n + 1) / 1.08).toInt

    System.out.println(
      if (min == max) {
        ":("
      } else {
        min
      }
    )
  }
}


Measured memory_bytes: 27324
n = int(input())
ID = input()[::-1]
m = int(input())
a_lst = list(map(int, input().split()))
dp = [[0] * 10 for _ in range(n + 1)]
dp[0][0] = 1


def fix(a):
    if a < 10:return a
    return a % 10 + a // 10


for i in range(n):
    c = ID[i]
    mag = 1 if i % 2 == 0 else 2
    for j in range(10):
        if c == "*":
            for a in a_lst:
                a = fix(a * mag)
                dp[i + 1][(j + a) % 10] += dp[i][j]
        else:
            a = fix(int(c) * mag)
            dp[i + 1][(j + a) % 10] += dp[i][j]
print(dp[n][0])




Measured memory_bytes: 42276
#include "bits/stdc++.h"
using namespace std;
const int INF = 1001001001;
int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> dist(N, vector<int>(N, INF));
	for (int n = 0; n < N; ++n) {
		dist[n][n] = 0;
	}
	vector<int>X(M); 
	vector<int>Y(M); 
	vector<int>Z(M);
	for (int n = 0; n < M; ++n) {
		int a, b, c;
		cin >> a >> b >> c;
		--a;
		--b;
		X[n] = a;
		Y[n] = b;
		Z[n] = c;
		dist[b][a] = c;
		dist[a][b] = c;
	}
	//わーしゃるふろいど
	for (int k = 0; k < N; ++k) {
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}

	int ans = 0;
	for (int n = 0; n < M; ++n) {
		bool b = true;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (dist[i][j] == (dist[i][X[n]] + Z[n]+ dist[Y[n]][j])) {
					b = false;
				}
			}
		}
		if (b) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n-1];
  vector<int>ans(n,0);
  for(int i=0; i<n-1; i++){
    cin >> a[i];
    ans.at(a[i]-1)++;
  }
  for(int i=0; i<n; i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
using namespace std;




void solve(){
	int a,b,c; cin>>a>>b>>c;
	if ((a+b+c)<22) cout<<"win";
	else cout<<"bust";
}

int main(){
	fast;
	solve();
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int64_t N;
  cin >> N;
  if(N % 2 == 1){
    cout << 0 << endl;
    return 0;
  }
  int64_t cnt = 0;
  bool fst = true;
  while(N > 0){
    if(fst){
      fst = false;
      N /= 10;
    }
    cnt += N;
    N /= 5;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int n,ans;

char ch[100002];

int main()
{
	scanf("%s",ch);
	while(ch[n])++n;
	--n;
	if((ch[0]==ch[n])^((n+1)%2))
		printf("First\n");
	else printf("Second\n");
	return 0;
}

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

int main(){
  int n,d;
  int ans=0;
  double x[100];
  cin>>n>>d;
  for(int i=0;i<n*d;i++)cin>>x[i];
  
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      double stk=0;
      for(int k=0;k<d;k++){
        stk+=pow(x[i*d+k]-x[j*d+k],2);
      }
      if(ceil(sqrt(stk))==floor(sqrt(stk)))ans++;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[1000001];
char s[1000001];
signed main()
{
	int t;
	scanf("%d%d",&n,&t);
	if(n>=10)
		printf("%d",t);
	else
		printf("%d",t+100*(10-n));
	return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

template<typename T> inline void _tostr(const T t, string& s){ostringstream o;o<<t;s=o.str();}
template<typename T> inline string _tostr(const T t){ostringstream o;o<<t;return o.str();}
template<typename T> inline void _toint(const string s, T& n){istringstream i(s);i>>n;}
template<typename T> inline T _toint(const string s){istringstream i(s);T n;i>>n;return n;}

int Q, N;
string s;

int main()
{
  cin >> Q;

  while(Q--){
    cin >> N;
    int res = 0;
    while(N > 9){
      int mx = 0;
      res += 1;
      s = _tostr(N);
      rep(i, s.size()-1){
        string l = s.substr(0, i+1);
        string r = s.substr(i+1, s.size()-i-1);
        maxup(mx, _toint<int>(l) * _toint<int>(r));
      }
      N = mx;
    }
    cout << res << endl;
  }

  return 0;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

#define MAX_V 100
#define INF INT_MAX

int cost[MAX_V][MAX_V];
int mincost[MAX_V];
bool used[MAX_V];
int V;

int prim(){
    for(int i=0;i<V;++i){
        mincost[i]=INF;
        used[i]=false;
    }
    mincost[0]=0;
    int res=0;
    while(true){
        int v=-1;
        rep(u,V){
            if(!used[u] && (v==-1 || mincost[u] <mincost[v])) v=u;
        }
        if(v==-1) break;
        used[v]= true;
        res+=mincost[v];
        rep(u,V){
            mincost[u]=min(mincost[u],cost[v][u]);
        }
    }
    return res;
}
int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0&&m==0){
            break;
        }
        V=n;    
    rep(i,MAX_V){
        rep(j,MAX_V){
            cost[i][j]=INF;
        }
    }
    int a,b,c;
    rep(i,m){
        cin>>a>>b>>c;
        cost[a][b]=c;
        cost[b][a]=c;
    }
    cout<<prim()<<endl;
    }
    return 0;
}

Measured memory_bytes: 2996
#include <stdio.h>

int n, array[50];

bool Solve(int i, int m) {
	if (m == 0) return true;
	if (i >= n || m < 0) return false;
	bool res = Solve(i + 1, m) || Solve(i + 1, m - array[i]);
	return res;
}


//complete and including everything: exhaustive
int main() {

	int q, M, i;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &array[i]);
	}

	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &M);

		if (Solve(0, M)) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}

	}


	return 0;
}



Measured memory_bytes: 2624
#include <iostream>
#include <stdio.h>

int main(){
	while(true){
		int result=0;
		char c;
		while(true){
			scanf("%c",&c);
			if(result==0&&c=='0'){
				break;
			}
			if(c=='\n'){
				break;
			}
			result+=c-0x30;
		}
		if(result==0&&c=='0'){
				break;
		}
		std::cout<<result<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int n = read();
    vector<int> P(n);
    for (auto& p:P) {
        p = read();
    }
    int ans = 0;
    for (int i = 1; i<n-1; i++) {
        if ((P[i-1] < P[i] && P[i] <= P[i+1]) || (P[i+1] < P[i] && P[i] <= P[i-1])) ans++;
    }
    printf("%d\n", ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
S = input()

chars = set(S)

res = len(S)
for char in chars:
    max_c = 0
    c = 0
    for s in S:
        if s != char:
            c += 1
        else:
            max_c = max(c, max_c)
            c = 0
    max_c = max(c, max_c)
    res = min(res, max_c)

print(res)


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

int main(){
	double a,b;cin>>a>>b;
    double a1=a/0.08;
    double a2=(a+1)/0.08;
    double b1=b/0.1;
    double b2=(b+1)/0.1;
    vector <int>vec;
    for(double i=a1;i<a2;i++){
        if(i<b2&&i>=b1){
            if(i==a1&&a1>((int)a1))
            vec.push_back(i+1);
            else vec.push_back(i);
        }
    }
    sort(vec.begin(),vec.end());
    if(vec.empty())cout<<"-1";
    else cout<<vec[0];

}


Measured memory_bytes: 256
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=r(1);r(2)(n.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,r){"use strict";var n=r(3),i=r(5);t.exports=function(t){var e=new n(t);i(e)}},function(t,e,r){"use strict";var n=r(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new n(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,r){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,r){"use strict";t.exports=function(t){for(var e=t.in(),r=t.in(),n=new Array(e),i=0;i<e;i++){var o=t.in(),s=t.in();n[i]={a:o,b:s}}n.sort(function(t,e){return t.a-e.a});for(var u=0,c=0;c<e;c++){if(u+n[c].b>=r)return void console.log(n[c].a);u+=n[c].b}}}]);

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

using namespace std;

int
main(void){
	int x, n; cin >> x >> n;
	vector<int> vec(n);
	for(int i = 0; i < n; i++) cin >>vec[i];
	int val = INT_MAX;
	int ans = -1;
	for(int i = 0; i <= 101; i++){
		bool is = true;
		for(int j = 0; j < n; j++){
			if(vec[j] == i) is = false;
		}
		if(is){
			if(val > abs(i - x)){
				val = abs(i - x);
				ans = i;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<cmath>
#define MAX 1000000000
using namespace std;

int main(){
    int q;
    cin >> q;
    vector<long long> a(q),b(q);
    for(int i = 0;i < q;i++){
        cin >> a.at(i) >> b.at(i);
        
        if(a.at(i) < b.at(i)){
            swap(a.at(i),b.at(i));
        }
        
    }
    /**/
    
    for(int i = 0;i < q;i++){
        long long ans,sq;
        sq = sqrt(a.at(i)*b.at(i));
        if(a.at(i) == b.at(i)){
            cout << a.at(i)*2 - 2 <<  endl;
        }
        else{
            if(sq*(sq + 1) < a.at(i)*b.at(i)){
                cout << sq*2 - 1 << endl;
            }
            else if(sq*sq == a.at(i)*b.at(i)){
                cout << sq*2 - 3 << endl;
            }
            else{
                cout << sq*2 - 2 << endl;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next() + sc.next();
		int val = Integer.parseInt(str);
		int val2 = (int)Math.sqrt(val);
		if(val == (val2 * val2)){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

const ld pi = 3.141592653589793;

ll n, a, c;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    while (a % 2 == 0) {
      c++;
      a /= 2;
    }
  }

  cout << c << endl;
}

Measured memory_bytes: 3628
S = gets.chomp
K = gets.to_i

wc = ''
wl = 0
ls = []
(S + ' ').chars do |c|
  if c == wc
    wl += 1
  else
    ls << wl if wl > 0
    wc = c
    wl = 1
  end
end

ans = 0
if ls.size == 1
  ans = ls[0] * K / 2
elsif ls.size > 2 && S[0] == S[-1]
  ans = ls[0] / 2
  ans += ls[1..-2].reduce(0) { |a, l| a + l / 2 * K }
  ans += (ls[0] + ls[-1]) / 2 * (K - 1)
  ans += ls[-1] / 2
else
  ans = ls.reduce(0) { |a, l| a + l / 2 * K }
end

puts ans


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

#define INF 100000000
#define EPS 1e-9

using namespace std;

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

#define MAX_N 100
int N;
map<string, int> M;
map<string, int> id;

string contents[MAX_N];

vector<int> vec[MAX_N];

vector<int> ans_list;

int solve(int number){
	
	int ans = 0;
	for (int i = 0; i < vec[number].size(); i++){
		ans += solve(vec[number][i]);
	}

	if (ans == 0)
		return M[contents[number]];
	else
		return min(ans, M[contents[number]]);

}

int main(){

	while (true){
	
		cin >> N;
		if (N == 0)
			break;

		map<string, int> m;
		for (int i = 0; i < N; i++){
			vec[i].clear();
			string str;
			int cost;
			cin >> str >> cost;
			m[str] = cost;
			id[str] = i;
			contents[i] = str;
		}

		M = m;

		int num;
		cin >> num;
		for (int i = 0; i < num; i++){
			string s;
			int k;
			cin >> s >> k;
			int id_number = id[s];
			for (int j = 0; j < k; j++){
				string str1;
				cin >> str1;
				int number = id[str1];
				vec[id_number].push_back(number);
			}
		}

		string ans;
		cin >> ans;

		ans_list.push_back(solve(id[ans]));
	
	}

	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}

	return 0;

}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, K; cin >> N >> K;
    int cnt[N+1] = {};
    rep(i, N){
        int a; cin >> a;
        cnt[a]++;
    }
    sort(cnt, cnt+(N+1));
    reverse(cnt, cnt+(N+1));
    int ans = N;
    rep(i, K) ans -= cnt[i];
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const int inf=0x3f3f3f3f;
string a,b;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>a>>b;
	int ans=0;
	rep(i,0,a.size())
		ans+=(a[i]!=b[i]);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

map<string,ll> weight;
ll pos;
string s;
bool flag;

ll num() {
    ll ret = 0;
    while('0' <= s[pos] && s[pos] <= '9') {
        ret *= 10;
        ret += s[pos]-'0';
        pos++;
    }
    return ret;
}

ll atom() {
    string t = "";
    t += s[pos], pos++;
    if(pos < (ll)s.size() && 'a' <= s[pos] && s[pos] <= 'z') {
        t += s[pos];
        pos++;
    }
    if(weight.find(t) != weight.end()) {
        dump(t, weight[t]);
        return weight[t];
    }
    dump(t, weight[t], "unknown");
    flag = false;
    return 0;
}

ll mole() {
    ll pre = 0, ret = 0;
    while(pos < (ll)s.size() && s[pos]!=')') {
        if(s[pos]=='(') {
            pos++;
            ll vl = mole();
            pos++;
            ll vr = num();
            pre = 0;
            ret += vl*vr;
        } else {
            pre = atom();
            if('0' <= s[pos] && s[pos] <= '9') {
                ll v = num();
                ret += pre * v;
                pre = 0;
            } else {
                ret += pre;
                pre = 0;
            }
        }
    }
    return ret;
}

int main(void) {
    while(1) {
        string s;
        cin >> s;
        if(s == "END_OF_FIRST_PART") break;
        ll w;
        cin >> w;
        weight[s] = w;
    }

    while(1) {
        cin >> s;
        if(s=="0") break;
        dump(s);

        pos = 0;
        flag = true;
        ll ret = mole();
        if(!flag) cout << "UNKNOWN" << endl;
        else cout << ret << endl;
    }

    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)  
    {if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;  }  return res;  
}
bool sortinrev(const pair<vector<int>,int>&a,const pair<vector<int>,int>&b){if(a.fi==b.fi)return b.se>a.se;return a.fi>b.fi;}
void dfs(int i,int j,int n,int m,vector<vector<int>>a,vector<vector<int>>&vis,set<pair<int,int>>&temp)
{
    vis[i][j]=1;
    if(i>0 && j>0 && vis[i-1][j-1]==0 && a[i-1][j-1]==1)
    {
        temp.insert({i-1,j-1});
        dfs(i-1,j-1,n,m,a,vis,temp);
    }
    if(i<n-1 && j<(m-1) && vis[i+1][j+1]==0 && a[i+1][j+1]==1)
    {
        temp.insert({i+1,j+1});
        dfs(i+1,j+1,n,m,a,vis,temp);
    }
    if(i<(n-1) && vis[i+1][j]==0 && a[i+1][j]==1)
    {
        temp.insert({i+1,j});
        dfs(i+1,j,n,m,a,vis,temp);
    }
    if(i>0 && vis[i-1][j]==0 && a[i-1][j]==1)
    {
        temp.insert({i-1,j});
        dfs(i-1,j,n,m,a,vis,temp);
    }
    if(j<(m-1) && vis[i][j+1]==0 && a[i][j+1]==1)
    {
        temp.insert({i,j+1});
        dfs(i,j+1,n,m,a,vis,temp);
    }
    if(j>0 && vis[i][j-1]==0 && a[i][j-1]==1)
    {
        temp.insert({i,j-1});
        dfs(i,j-1,n,m,a,vis,temp);
    }
    if(i>0 && j<(m-1) && vis[i-1][j+1]==0 && a[i-1][j+1]==1)
    {
        temp.insert({i-1,j+1});
        dfs(i-1,j+1,n,m,a,vis,temp);
    }
    if(j>0 && i<(n-1) && vis[i+1][j-1]==0 && a[i+1][j-1]==1)
    {
        temp.insert({i+1,j-1});
        dfs(i+1,j-1,n,m,a,vis,temp);
    }
}
void run(vector<int>v){for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
int main() 
{ 
    FIO;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll n,k,c=0;
    cin>>n>>k;
    ll a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    vector<int>count(n+1,0);unordered_map<int,vector<int>>mp;vector<int>ans;
    count[1]=1;int pos=1;mp[1].pb(0);ans.pb(1);
    for(int i=0;i<n;i++)
    {
        count[a[pos]]++;
        c++;
        mp[a[pos]].pb(c);
        if(count[a[pos]]==2)
        {
            break;
        }
        ans.pb(a[pos]);
        pos = a[pos];
    }
    // run(ans);
    // for(auto x:mp)
    // {
    //     cout<<x.fi<<"->";
    //     for(auto y:x.second)
    //         cout<<y<<" ";
    //     cout<<endl;
    // }
    ll dur = mp[a[pos]][1]-mp[a[pos]][0];
    ll start = mp[a[pos]][0],end = mp[a[pos]][1];
    // cout<<end<<endl;
    if(k<end)
    {
        cout<<ans[k];
    }
    else
    {
        cout<<ans[(k-start)%(dur)+start]<<endl;
    }


   return 0; 
} 

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

int main(){

    ll n,k;
    cin >> n >> k;
    ll ans=0;

    for(ll i=k;i<=n+1;i++){
        ll min = (i - 1) * i / 2;
        ll max = (n + n - i + 1) * i / 2;
        ans += (max - min + 1);
        ans %= mod;
    }
    printf("%lld\n", ans );

    return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<vector>
#define Lens 1000005
#define Nil -1
using namespace std;

int N, sum;
int a[Lens];
vector<int> b, G;
void selectionsort(int a[], int g)
{
	for (int i = g; i < N; i++)
	{
		int j = i - g;
		int mini = a[i];
		while (j >= 0 && a[j] > mini)
		{

			a[j + g] = a[j];
			sum++;
			j -= g;
		}
		a[j + g] = mini;
	}
}

void shell()
{
	int h = 1;
	while (h <= N)
	{
		G.push_back(h);
		h = 3 * h + 1;
	}
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	shell();
	sum = 0;
	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--)
	{

		cout << G[i];
		if (i > 0)
			cout << ' ';
		if (i == 0)
			cout << endl;
	}


	for (int i = G.size() - 1; i >= 0; i--)
	{
		int g = G[i];
		selectionsort(a, g);
	}
	cout << sum << endl;
	for (int i = 0; i < N; i++)
	{
		cout << a[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 7024
#include<iostream>
#include<math.h>
using namespace std;

int isPrime(int x) {
	if (x <= 1) return false;
	if (x>2&&x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}
int main() {
	int N;
	long long int a;
	cin >> N;
	int num = 0;
	for (int i = 0;i < N;i++) {
		cin >> a;
		if (isPrime(a)) {
			num++;
		}
	}
	cout << num << endl;

}

Measured memory_bytes: 1168
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define print(x) cout << (x) << '\n'

const int n_max = 8;
bool graph[n_max][n_max];

int dfs(int v, int n, bool visited[n_max]){
    bool all_visited = true;
    
    if (any_of(visited, visited + n, [](int x){return x == false;})) all_visited = false;
    if (all_visited) return 1;

    int cnt = 0;

    rep(i, n){
        if (!graph[v][i]) continue;
        if (visited[i]) continue;
        visited[i] = true;
        cnt += dfs(i, n, visited);
        visited[i] = false;
    }

    return cnt;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m; cin >> n >> m;
    int a[m], b[m];
    rep(i, m) {
        cin >> a[i] >> b[i];
        --a[i]; --b[i];
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    bool visited[n_max] = {};

    visited[0] = true;
    print(dfs(0, n, visited));
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

int main() {
    long long n, sum = 0;
    cin >> n;
    vector<long long> as(n);
    map<long long, long long> cnt;
    map<long long, long long> cntcheck;
    for (long long i = 0; i < n; i++) {
        cin >> as[i];
        cnt[as[i]]++;
    }
    for (long long i = 0; i < n; i++) {
        if (cntcheck[as[i]] == 0) {
            cntcheck[as[i]]++;
            sum += ((cnt[as[i]] * (cnt[as[i]] - 1)) / 2);
        }
    }
    //    cout << sum << "hoge" << endl;
    for (long long i = 0; i < n; i++) {
        cout << sum - cnt[as[i]] + 1 << endl;
    }
}

Measured memory_bytes: 20992
def main():
    A, B, C, D = map(int,input().split())
    if A <= C:
        if B-C <= 0:
            ans = 0
            return ans
        elif B-C > 0 and B <= D:
            ans = B-C
            return ans
        elif B-C > 0 and B > D:
            ans = D-C
            return ans

    elif A > C and A < D:
        if B <= D:
            ans = B-A
            return ans
        elif B > D:
            ans = D-A
            return ans

    elif A >= D:
        ans = 0
        return ans

print(main()) 


Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return a % 1000000007;
}


int main(){
  map<string,ll> table; ll n; cin >> n;
  
  for(ll i=0; i < n; i++){
    string s; cin >> s;
    if(table.count(s)) table[s]++;
    else table[s] = 1;
  }
  
  ll maxvote = 0;
  
  for(auto p : table){
    ll vote = p.second;
    maxvote = max(maxvote,vote);
  }
  
  for(auto p : table){
    if(p.second == maxvote)  cout << p.first << endl;
  }
  
}

Measured memory_bytes: 25216
def lcs(X, Y):
    a = len(X)
    b = len(Y)
    c1 = [0] * (b + 1)
    for i in range(a):
        e1 = X[i]
        c2 = c1[:]
        for j in range(b):
            if e1 == Y[j]:
                c1[j+1] = c2[j] + 1
            elif c1[j+1] < c1[j]:
                c1[j+1] = c1[j]
    return c1[-1]

n = int(input().rstrip())
ret = []
for i in range(n):
    s1 = input()
    s2 = input()
    ret.append(lcs(s1, s2))
print(*ret, sep = '\n')


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

using namespace std;

typedef long long ll;
typedef long double ld;
const ll inf = 1e15 + 10;
const ll maxn = 1e5 + 163;
const ll alf = 26;
const ll dlm = 1e9+7;
const ll del = 10979 ;
const int eps = 1e-7 ;
const int maxq = 1e2+132 ;

ll w[maxq] , v[maxq] ;
ll dp[maxq][maxn] ;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    int N,W;
    cin>>N>>W;
    int sum = 0 ;
    for(int i=1;i<=N;i++){
        cin>>w[i]>>v[i];
        sum+=v[i] ;
    }
    for(int i=0;i<=N;i++){
        for(int j=0;j<=sum;j++){
            dp[i][j] = inf;
        }
    }
    dp[0][0] = 0 ;
    for(int i=1;i<=N;i++){
        for(int j=0;j<=sum;j++){
            if((j-v[i])<0){
                dp[i][j] = dp[i-1][j] ;
                continue;
            }
            dp[i][j] = min(dp[i-1][j] , (dp[i-1][j-v[i]] + w[i]) ) ;
        }
    }

    int ans  = 0;
    for(int j=0;j<=sum;j++){
       // cout<<j<<" "<<dp[N][j]<<" "<<W<<endl;
        if(dp[N][j]<=W){
            ans  = j ;
        }
    }
    cout<<ans;
    return 0;
}



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

int main() {
    int n;cin>>n;
    if(n>=2800)cout<<"AGC"<<endl;
    else if(n>=1200)cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
	return 0;
}

Measured memory_bytes: 3624
si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))

# ----------

S = si()
N = len(S)
a = [0] * (N + 1)

for i in range(N):
    if S[i] == "<":
        a[i+1] = max(a[i+1], a[i]+1)

for i in reversed(range(N)):
    if S[i] == ">":
        a[i] = max(a[i+1]+1, a[i])

print(sum(a))



Measured memory_bytes: 23336
#include <iostream>
#include <cstdio> 　　　　 //定义输入／输出函数
#include <stack>　　　　　 //STL 堆栈容器
#include <map>　　　　　　 //STL 映射容器
#include <vector>　　　　　//STL 动态数组容器
#include <string>　　　　　//字符串类
#include <iterator>        //STL迭代器
#include <cstdlib> 　　　　//定义杂项函数及内存分配函数
#include <cstring> 　　　　//字符串处理ed
#include<algorithm>
#include<queue>
#include<cmath>
#include<ctime>
#include<climits>
#include<iomanip>
#include<sstream>
using namespace std;
#define FOR(ITER,BEGIN,END)  for(int  ITER=BEGIN;ITER<END;ITER++)
#define PER(ITER,TIMES) FOR(ITER,0,TIMES)
#define TIME(TIME_NUMBER) PER(_PETER_MRSCO_ITER_,TIME_NUMBER)	
#define  ll  long long
#define close_stdin  ios::sync_with_stdio(false)
#define inf 0x3f3f3f3f
const int maxn = 100000;
void solve() {
	int n,m,sum;
	cin >> n>>m>>sum;
	if (sum == 1000000000) {
		n -= m;
		while (m--) { cout << 1000000000 << " "; }
		for (int i = 1;i <= n;i++) { cout << 1 << " "; }
		cout << "\n";
	}
	else {
		n -= m;
		while (m--) { cout << sum << " "; }
		for (int i = 1;i <= n;i++) { cout << sum + 1 << " "; }
		cout << "\n";
	}
}
int main() {
	close_stdin;
	solve();
}

Measured memory_bytes: 3624
I=float('inf')
for e in iter(input,'0 0'):
 n,k=map(int,e.split())
 F=[[I]*-~n for _ in[0]*-~n]
 for i in range(1,n+1):F[i][i]=0
 for _ in[0]*k:
  f=input();g=map(int,f[2:].split())
  if'0'==f[0]:a,b=g;A=F[a][b];print([A,-1][A==I])
  else:
   c,d,e=g
   if e<F[c][d]:
    for i in range(2,n+1):
     for j in range(1,i):
      F[i][j]=F[j][i]=min(F[i][j],F[i][c]+e+F[d][j],F[i][d]+e+F[c][j])


Measured memory_bytes: 5784
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        k: usize, q: usize,
        d: [i64; k],
        nxm: [(i64, i64, i64); q],
    }
    for (n, x, m) in nxm {
        let qq = (n - 1) / k as i64;
        let r = n - qq * k as i64 - 1;
        let mut sum = x;
        let mut pos = 0;
        for i in 0..k {
            let cnt = qq + if i < r as usize { 1 } else { 0 };
            sum += (d[i] % m) * cnt;
            if d[i] % m > 0 {
                pos += cnt;
            }
        }
        puts!("{}\n", pos - (sum / m - x / m));
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572