akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int home[4][3][10]={{{}}};
    for(int i=0;i<n;i++){
        int a,b,c,v;
        cin>>a>>b>>c>>v;
        home[a-1][b-1][c-1]+=v;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                cout<<" "<<home[i][j][k];
            }
            cout<<endl;
        }
    if(i<3){
        cout<<"####################"<<endl;
    }
    }
}


Measured memory_bytes: 3084
#include<stdio.h>
int main(void){
int n;
  scanf("%d",&n);
  int h[n];
  for(int i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
  int max=0,count=0,i=0;
while(i<=n-1){
    while(h[i]>=h[i+1]&&i<n-1){
      count++;
      i++;
    }
  if(count>max)max=count;
  count=0;
  i++;
}
  printf("%d",max);
  return 0;
}

Measured memory_bytes: 512
import sys
import itertools
# import numpy as np
import time
import math
import heapq
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

n = int(input())

adj = [[] for i in range(n)]

for i in range(n):
    line = list(map(int, input().split()))
    u = line[0]
    for j in range(line[1]):
        v = line[2 + j]
        adj[u - 1].append(v - 1)


# BFS
import queue
q = queue.Queue()
visited = [False] * n
dist = [-1] * n

visited[0] = True
dist[0] = 0
q.put(0)
while not q.empty():
    v = q.get()
    for u in adj[v]:
        if visited[u]:
            continue
        visited[u] = True
        dist[u] = dist[v] + 1
        q.put(u)

for i in range(n):
    val = dist[i]
    print(i + 1, val)


Measured memory_bytes: 7080
n = int(input())
a,b,ab,ans = 0,0,0,0
for i in range(n):
    s = input()
    ans += s.count("AB")
    if s[-1] == "A" and s[0] == "B":
        ab += 1
    elif s[0] == "B":
        b += 1
    elif s[-1] =="A":
        a += 1
if ab >= 1:
    print(ans+ab-1+min(a,1)+min(b,1)+min(max(a-1,0),max(b-1,0)))
else:
    print(ans+min(a,b))


Measured memory_bytes: 44136
#include <cmath>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n; double x[100000], y[100000];
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++)
    {
        scanf("%lf", &x[i]);
        scanf("%lf", &y[i]);
    }
    
    pair<double, double> p1[100000], p2[100000];
    
    for(int i = 0; i < n; i++)
    {
        p1[i] = make_pair(x[i], y[i]);
    }
    
    for(int i = 0; i < n; i++)
    {
        p2[i] = make_pair(y[i], x[i]);
    }
    
    sort(p1, p1 + n);
    sort(p2, p2 + n);
    
    double sqr_ans = 100000000.0;
    
    for(int i = 0; i < n - 1; i++)
    {
        int r = min(188, n - i - 1);
        
        for(int j = 1; j <= r; j++)
        {
            double distance_ = (p1[i + j].first - p1[i].first) * (p1[i + j].first - p1[i].first) + (p1[i + j].second - p1[i].second) * (p1[i + j].second - p1[i].second);
        
            sqr_ans = min(distance_, sqr_ans);
        }
    }
    
    for(int i = 0; i < n - 1; i++)
    {
        int r = min(188, n - i - 1);
        
        for(int j = 1; j <= r; j++)
        {
            double distance_ = (p2[i + 1].first - p2[i].first) * (p2[i + 1].first - p2[i].first) + (p2[i + 1].second - p2[i].second) * (p2[i + 1].second - p2[i].second);
        
            sqr_ans = min(distance_, sqr_ans);
        }
    }
    
    printf("%.15f\n", sqrt(sqr_ans));
    
    return 0;
}

Measured memory_bytes: 7396
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector<vector<int>> cnt(4*K+1,vector<int>(4*K+1,0));
	
	for(int i=0;i<N;i++){
		int x,y;
		char c;
		cin>>x>>y>>c;
		if(c=='B')x+=K;
		
		x%=2*K;
		y%=2*K;
		x++;
		y++;
		cnt[y][x]++;
		cnt[y+2*K][x]++;
		cnt[y][x+2*K]++;
		cnt[y+2*K][x+2*K]++;
	}
	
	for(int i=0;i<=4*K;i++){
		for(int j=1;j<=4*K;j++){
			cnt[i][j] += cnt[i][j-1];
		}
	}
	
	for(int i=1;i<=4*K;i++){
		for(int j=0;j<=4*K;j++){
			cnt[i][j] += cnt[i-1][j];
		}
	}
	
	
	int ans = 0;

	for(int i=0;i<=2*K;i++){
		for(int j=0;j<=2*K;j++){
			int y = i+K;
			int x = j+K;
			int a = cnt[y][x]-cnt[y][j]-cnt[i][x]+cnt[i][j];
			int b = cnt[y+K][x+K]-cnt[y+K][x]-cnt[y][x+K]+cnt[y][x];
			ans = max(ans,a+b);
		}
	}
	
	cout<<ans<<endl;
		
    return 0;
}


Measured memory_bytes: 62976
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int[] aka = new int[100005];
		int[] ryou = new int[100005];
		
		for(int i = 0; i < 100005; i++){
			ryou[i] = 1;
			aka[i] = 0;
		}
		aka[0] = 1;
		
		
		
		int N = scan.nextInt();
		int M = scan.nextInt();
		
		
		
		for(int i = 0; i < M; i++){
			int a = scan.nextInt();
			int b = scan.nextInt();
			a--;
			b--;
			
			ryou[a]--;
			ryou[b]++;
			if(aka[a] == 1){
				aka[b] = 1;
				if(ryou[a] == 0){
					aka[a] = 0;
				}
			}
			
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++){
			if(aka[i] == 1){
				ans++;
			}
		}
		
		System.out.println(ans);
		
	}
}

Measured memory_bytes: 24252
#include <iostream>
#include <cctype>

int main(void) {
  std::string s;

  std::getline(std::cin, s);

  for (int i =  0; i < s.size(); i++) {
    if (!std::isalpha(s[i])) {
      continue;
    }
    
    if (isupper(s[i])) {
      s[i] = std::tolower(s[i]);
    } else {
      s[i] = std::toupper(s[i]);
    }
  }

  std::cout << s << std::endl;
  
  return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <string>

int main()
{
    std::string s;
    getline(std::cin, s);
    for (int i = 0; i < s.size(); i++) {
        if (int(s[i]) >= 65 && int(s[i]) <= 90) {
            std::cout << char(s[i] + 32);
        }
        else if (int(s[i]) >= 97 && int(s[i]) <= 122) {
            std::cout << char(s[i] - 32);
        }
        else {
            std::cout << s[i];
        }
    }
    std::cout << std::endl;
}


Measured memory_bytes: 3180
# coding: utf-8
# 50
import collections

S = list()
for i in range(100):
    try:
        S.append(int(input()))
    except:
        break

A = list()

for j in range(len(collections.Counter(S).most_common())):
    if collections.Counter(S).most_common()[0][1] == collections.Counter(S).most_common()[j][1]:
        A.append(collections.Counter(S).most_common()[j][0])
A.sort()       
for z in range(len(A)):
    print(A[z])


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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define int long long

int cnt, A[1000100];

void insertionSort(int A[],int n, int g){
	int v,j;
	for(int i = g; i < n; i++){
		v = A[i];
		j = i-g;
		while(j >= 0 && A[j] > v){
			A[j+g]=A[j];
			j-=g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int n){
	int m=0,temp=n,j=1, G[100] = {};
	for(int i = 1; ; i++){
		G[i] = 3*G[i-1]+1;
		if(G[i] > n)break;
		j++;
	}
	j--;
	cout<<j<<endl;
	for(int i = j,k=0; i; i--){
		if(k++)cout<<" ";
		cout<<G[i];
	}cout<<endl;
	for(int i = j; i; i--){
		insertionSort(A,n, G[i]);
	}
}

signed main(){
	int n;
	cin>>n;
	for(int i = 0; i < n; i++)
		cin>>A[i];
	shellSort(A,n);
	cout<<cnt<<endl;
	for(int i = 0; i < n; i++)
		cout<<A[i]<<endl;
	
	
	return 0;
}


Measured memory_bytes: 10904
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<utility>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
//#define t ll t;cin>>t;while(t--)
#define nn cout<<endl;
#define ff(a,n) for(ll i=a;i<n;i++)
#define fr(x, a) for(auto &x:a)
#define cY cout<<"YES\n"
#define cN cout<<"NO\n"
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
#define sc second
#define fs first
#define c(a) cout<<a<<endl
ll mx=-1e18;
ll mn=1e18;
ll M=1e9+7;

ll mod(ll x)
{
	return ((x%M+M)%M);
}

void solve()
{//cartesian set
	ll n; cin>>n;
	ll a=1,b=1,c=1;
	ff(1,n+1)
		a=mod(mod(a)*mod(10));
		
	ff(1,n+1)
		//b=((b%mod)*(9%mod))%mod;
		b=mod(mod(b)*mod(9));
	//b=((b%mod)*(2%mod))%mod;
	b=mod(mod(b)*mod(2));
	
	ff(1,n+1)
	//	c=((c%mod)*(8%mod))%mod;
		c=mod(mod(c)*mod(8));
	
	//a-b+c
	//ll ans=((a%mod)-(b%mod)+(c%mod))%mod;
	ll ans=mod(mod(a)-mod(b)+mod(c));
	
	cout<<ans;
}

int main()
{
	solve();
}
/*




*/


Measured memory_bytes: 3540
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

import sys
sys.setrecursionlimit(4100000)
input = sys.stdin.readline

N,M = Ints()

from collections import defaultdict
Graph = defaultdict(list)

for i in range(M):     #ABC = [now, to, cost] のリストを想定
    A,B = Ints()
    Graph[A].append([B,1])
    Graph[B].append([A,1])

def dijkstra_heap(s,Graph,N):
    import heapq
    que = []
    INF = 10**18
    MIN = [INF]*(N+1)    #N: 頂点数, 1,Nの場合も考慮してる
    From = [-1]*(N+1)
    
    heapq.heappush(que,[0,s])

    while que != []:
        nowc,to = heapq.heappop(que)
        MIN[to] = min(nowc, MIN[to])
        if MIN[to] >= nowc:
            for (b,c) in Graph[to]:
                if nowc+c < MIN[b]:
                    From[b] = to
                    MIN[b] = nowc+c
                    heapq.heappush(que,[nowc+c,b])
    return MIN,From

MIN,From = dijkstra_heap(1,Graph,N+1)

print('Yes')
for i in range(N-1):
    print(From[i+2])

Measured memory_bytes: 143328
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> H;
	vector< int > A(N), B(N);
	rep(i, N) cin >> A[i] >> B[i];
	sort(A.rbegin(), A.rend());
	sort(B.rbegin(), B.rend());
	int ans = 0;
	int best = A[0];
	rep(i, N) {
		if (B[i] < best)
			break;
		H -= B[i];
		ans++;
		if (H <= 0)
			break;
	}
	if (H > 0) {
		ans += (H + best - 1) / best;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    int even = 0, odd = 0;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        (a % 2 ? odd : even)++;
    }
    cout << (odd % 2 == 0 ? "YES" : "NO") << '\n';
    return 0;
}

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

using namespace std;
struct node {
    int id, point;
} node[1<<18];
int n, a[131100];

void add(int id, int x)
{
    id=n-1+id;
    node[id].point+=x;

    while (id>0) {
        id=(id-1)/2;
        int c1=2*id+1, c2=2*id+2;
        if (node[c1].point>=node[c2].point)
            node[id]=node[c1];
        else
            node[id]=node[c2];
    }
}

void print()
{
#ifdef DEBUG
    int k=1;
    int x=0;
    while (true) {
        for(int i=0;i<k;++i) printf("(%d %d)", node[x+i].id, node[x+i].point);
        puts("");
        x+=k;
        k<<=1;
        if (x>=n) break;
    }
    puts("");
#endif
}

int main()
{
    int m, r, l;
    scanf("%d%d%d", &m, &r, &l);
    n=1;
    while (n<m) n<<=1;
    for(int i=0;i<m;++i) node[n-1+i].id=i;

    int pt=0;
    for(int i=0;i<r;++i) {
        int d, t, x;
        scanf("%d%d%d", &d, &t, &x);

        if (pt<t) {
            int id=node[0].id;
            a[id]+=t-pt;
        }
        add(d-1, x);
        print();
        pt=t;
    }
    print();
    a[node[0].id]+=l-pt;
#ifdef DEBUG
    for(int i=0;i<n;++i) printf("%d ", a[i]); puts("");
#endif
    printf("%d\n", 1+(max_element(a, a+n)-a));
}

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

long long n;

long long solve();

int main() {
  cin >> n;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0, N = n;
  for (long long i = 2; i * i <= N; ++i)
    if (N % i == 0) {
      long long now = 0;
      while (N % i == 0) {
        ++now;
        N /= i;
      }
      long long cnt = 1;
      while (cnt <= now) {
        ++res;
        now -= cnt;
        ++cnt;
      }
    }
  if (N != 1) ++res;
  return res;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

struct temp
{
    int rank;
    int p;
    int y;
}a[100005];

int cmp(temp x, temp y)
{
    if(x.p != y.p)
        return x.p<y.p;
    else
        return x.y<y.y;
}

int main()
{
    int n,m;
    while(cin >> n >> m)
    {
        int b[100005];
    for(int i = 0; i< m; i++)
    {
        a[i].rank = i;
        cin >> a[i].p >> a[i].y;
        b[i] = a[i].p;
    }

    sort(a,a+m,cmp);
    int f = a[0].p,flag = 1;
    int x[100005];

    for(int i = 0; i < m; i++)
    {
        if(a[i].p != f)
        {
            flag = 1;
            f = a[i].p;
        }
        x[a[i].rank] = flag++;
    }

    for(int i = 0; i < m; i++)
        printf("%06d%06d\n",b[i],x[i]);

    }
    return 0;
}


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

int main() {
  int H1,M1,H2,M2,K;
  cin>>H1>>M1>>H2>>M2>>K;
  int hun1 = H1*60+M1;
  int hun2 = H2*60+M2;
  int ans = (hun2-hun1)-K;
  cout<<ans<<endl;

}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main()
{
    int n;cin >> n;
    int d;cin >> d;
    int i = d,cnt = 1;
    while(d < n)
    {
        i = i + d + 1;
        if(i < n)
        {
            cnt++;
            i = i + d;
        }
        else
            break;
    }
    cout << cnt;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
string s;
map<string ,int> mp;

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) {
		cin >> s;
		mp[s]++;
	}
	
	int maxCnt = 0;
	for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
		int cnt = it->second;
		maxCnt = max(maxCnt, cnt);
	}
	
	for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
		int cnt = it->second;
		if (cnt == maxCnt) {
			cout << it->first << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 27264
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	string s;
	cin >> s;
	int c = 0;
	if (s[0] == '1') {
		c = c + 1;
	}
	if (s[1] == '1') {
		c = c + 1;
	}
	if (s[2] == '1') {
		c = c + 1;
	}
	cout << c << 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);

		while (true) {
			int N = sc.nextInt();
			int X = sc.nextInt();

			if (N == 0 && X == 0) {
				break;
			}

			int sum = 0;

			for (int i=1; i<=N; i++) {
				for (int j=i+1; j<=N; j++) {
					for (int k=j+1; k<=N; k++) {
						if (i + j + k == X) {
							sum++;
						}
					}
				}
			}
				System.out.println(sum);
		}
	}
}


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

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  for (auto& x : X) cin >> x;
  vector<int> X_ascend = X;
  sort(X_ascend.begin(), X_ascend.end());
  int left = X_ascend[N / 2 - 1];
  int right = X_ascend[N / 2];
  for (int i = 0; i < N; ++i) {
    if (X[i] <= left)
      cout << right << endl;
    else
      cout << left << endl;
  }
}


Measured memory_bytes: 3712
#include <iostream>
    #include <string>
     
    using namespace std;
     
    int main(){
     
      int A,B;
      string S,T,U;
      
      cin>>S>>T;
      cin>>A>>B;
      cin>>U;
     
      if(S==U){
        cout<<A-1<<" "<<B<<endl;
      }
      else{
        cout<<A<<" "<<B-1<<endl;
      }
      return 0;
    }

Measured memory_bytes: 256
h,w,k=map(int,input().split())
mod=10**9+7
dp=[[0]*w for _ in range(h+1)]
dp[0][0]=1
for i in range(1,h+1):
  for j in range(2**(w-1)):
    tmp=format(j,'b')
    if len(tmp)!=w-1:
      tmp=(w-1-len(tmp))*'0'+tmp
    flag=True
    for l in range(1,w-1):
      if tmp[l]=='1' and tmp[l-1]=='1':
        flag=False
        break
    if flag==False:
      continue
    else:
      arr=[i for i in range(1,w+1)]
      for m in range(w-1):
        if tmp[m]=='1':
          arr[m],arr[m+1]=arr[m+1],arr[m]
      for m in range(w):
        dp[i][m]+=dp[i-1][arr[m]-1]%mod
print(dp[h][k-1]%mod)

Measured memory_bytes: 3064
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
# s = list(input())
s = input()
s = s.lower()
# print(s)
alpha = [chr(ord('a') + i) for i in range(26)]
# print(alpha)
# print(alpha)
# alpha
# for i in srange(n):
# m = n % 25
ans = []
for c in s:
  for i, p in enumerate(alpha):
    if c == p:
      # print(i)
      i = i + n
      i = i % 26
      ans.append(alpha[i].upper())
      # print(i)
      # m = (i+m) % 25
      # print(alpha[m])
# print(ans)
ans = "".join(ans)
print(ans)




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

using namespace std;

#define fi first
#define se second

using ll = long long;

const int N = (int)2e5 + 5;
int n, a[N], b[N];
ll ans;
priority_queue< pair<int, int> > pq;

int nxt(int i) { return i == n - 1 ? 0 : i + 1; }
int prv(int i) { return i == 0 ? n - 1 : i - 1; }

void kill() { printf("-1"); exit(0); }

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", a + i);
    for (int i = 0; i < n; ++i) {
        scanf("%d", b + i);
        if (b[i] < a[i]) kill();
        else if (b[i] > a[i]) pq.push( { b[i], i } );
    }

    while (!pq.empty() ) {
        int i = pq.top().se; pq.pop(); int l = prv(i), r = nxt(i);
        if (b[i] <= b[l] + b[r]) kill();
        int nB = b[i] % (b[l] + b[r]);
        if (nB >= a[i]) {
            ans += b[i] / (b[l] + b[r]);
            b[i] = nB;
            if (b[i] > a[i]) pq.push( { b[i], i } );
        }
        else {
            if ( (b[i] - a[i]) % (b[l] + b[r]) ) kill();
            else {
                ans += (b[i] - a[i]) / (b[l] + b[r]);
                b[i] = a[i];
            }
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3700
def can(d,g,p,c, maxPick):
	# n問解いてg点獲得できるか？

	# パーフェクトを狙う問題の組み合わせを生成
	for i in range(0, 2**(d-1)):

		# このパーフェクトのとり方で条件が達成できるか？
		point = 0
		picked = 0
		for j in range(0, d-1):
			if i & (2**j) != 0:
				point += (j+1) * 100 * p[j] + c[j]
				picked += p[j]

		if picked > maxPick:
			#print (i, " is un")
			continue
		#print ("i", i , "picked", picked, "point", point)

		# 残り個数分だけ、点数の高い問題をとる
		t = d-1
		while(picked < maxPick):
			if i & (2**t) != 0:
				t -= 1
				continue
			pick = min(p[t], (maxPick - picked))
			picked += pick
			point += (t+1)*100 * pick
			if pick == p[t]:
				point += c[t]
			#print ("t", t, "pick", pick, "picked", picked, "point", point)
			t -= 1

		if point >= g:
			return True
		else:
			pass
			#print (point)
	return False


def bin(d,g,p,c):
	left = 1
	right = sum(p)
	while left != right:
		cen = (left + right) // 2
		#print ("left", left, "cen", cen, "right", right)
		if(can(d,g,p,c,cen)):
			right = cen
		else:
			left = cen + 1
	return right


s = input().split(" ")
d = int(s[0])
g = int(s[1])

p = []
c = []

for i in range(0, d):
	s = input().split(" ")
	p.append(int(s[0]))
	c.append(int(s[1]))

print(bin(d,g,p,c))

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

int main(){
    string s;
    cin >> s;
    int wa,rs=0;
    bool Cflag = false;

    wa = s.size();

    for(int i = 0;i < wa;i++){
        if(s.at(i) != 'A' and i == 0)
            break;
        if(s.at(i) == 'C' and (i == 1 or i == (wa -1))){
            break;
        }

        if(Cflag){
            if(s.at(i) == 'C'){
                Cflag = false;
                break;
            }
        }
       if(s.at(i) == 'C' and isupper(s.at(i))){
            Cflag = true;
        }else if(s.at(i) != 'C' && isupper(s.at(i)) and i >= 1){
            Cflag = false;
            break;
        }
    }
    

    if(Cflag)
        cout << "AC" << endl;
    else
    {
        cout << "WA" << endl;
    }
    
    

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int n;
  cin>>n;
  int X[n],Y[n];
  for(int i=0; i<n; i++){
    cin>>X[i];}
  for(int i=0; i<n; i++){
    cin>>Y[i];}
  
  bool p=false;
  bool m=false;
  int psum=0;
  
  for(int i=0; i<n; i++){
    int d=X[i]-Y[i];
    if(d>0){
      p=true;
      psum+=d;}
    else
      m=true;
  }
  if(p==true)
    cout<<psum<<endl;
  else 
    cout<<0<<endl;
}


Measured memory_bytes: 256
#include <atcoder/fenwicktree>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N, Q;
    cin >> N >> Q;
    fenwick_tree<ll> fw(N);
    ll a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        fw.add(i, a);
    }

    int q, p, x;
    for (int i = 0; i < Q; i++) {
        cin >> q;
        if(q == 0){
            cin >> p >> x;
            fw.add(p, x);
        }
        else{
            cin >> p >> x;
            printf("%lld\n", fw.sum(p, x));
        }
    }

}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    int N, Y;
    int A = 0; // 10000
    int B = 0; // 5000
    int C = 0; // 1000

    cin >> N >> Y;

    A = Y / 10000;
    bool flag = false;
    while (A >= 0) {
        int n = N - A;
        int y = Y - A * 10000;
        B = y / 5000;
        while (B >= 0) {
            int nb = n - B;
            int yb = y - B * 5000;

            C = yb / 1000;

            if (A + B + C == N) {
                flag = true;
                break;
            }

            B--;
        }
        if (flag) break;
        A--;
    }

    if (!flag) {
        cout << "-1 -1 -1" << endl;
        return 0;
    }
    cout << A << ' ' << B << ' ' << C << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
void Digvijay()
{
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> pref(n+2,0);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
       
    }
    pref[n]=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
        pref[i+1]=pref[i+2]+a[i];
        pref[i+1]%=mod;
    }

    int ans=0;
    //for(auto it:pref)cout<<it<<" ";
    for(int i=1;i<=n;i++)
    {
        ans = (ans%mod + (a[i-1]%mod*pref[i+1]%mod)%mod)%mod;
    }
    cout<<ans<<"\n";

}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    //cin>>_;
    for(int __=1;__<=_;__++)
    {
        Digvijay();
    }
}



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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll A[int(2e5+5)], ans, now;

int main(){
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  now = A[0];
  
  for (int i = 1; i < N; i++){
    if (now <= A[i]) now = A[i];
    else ans += (now - A[i]);
  }
  cout << ans << endl;

  return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();

    vector<vector<int>> is(26);
    rep(i, n) is[s[i] - 'a'].push_back(i);
    rep(i, n) is[s[i] - 'a'].push_back(i + n);

    ll ans = 0;
    int p = 0; // after p
    rep(i, m) {
        int c = t[i] - 'a';
        if (is[c].size() == 0) {
            puts("-1");
            return 0;
        }

        p = *lower_bound(is[c].begin(), is[c].end(), p) + 1;
        if (p >= n) {
            p -= n;
            ans += n;
        }
    }
    ans += p;
    cout << ans << endl;
}


Measured memory_bytes: 1852
s = input()
sb = s[:2]
sa = s[2:]
if 1<=int(sb)<=12 and (13 <= int(sa) or int(sa)==0):
    print('MMYY')
elif 1<=int(sa)<=12 and (13 <= int(sb) or int(sb)==0):
    print('YYMM')
elif 1<=int(sb)<=12 and 1<=int(sb)<=12:
    print('AMBIGUOUS')
else:
    print('NA')


Measured memory_bytes: 9020
# -*- coding: utf-8 -*-
import sys
N = int(input())
a = list(map(int, input().split()))

S = [0]*3 
for i in a:
    if i % 4 == 0:
        S[2] += 1
    elif i % 2 == 0:
        S[1] += 1
    else:
        S[0] += 1

if len(a) % 2 == 1 and S[2] + 1 == S[0]:
    print("Yes")
    sys.exit()

if S[2] < S[0]:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 15020
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
		try(Scanner sc =new Scanner(System.in)){
			while(true){
				int num = sc.nextInt();
				if(num==0){
					break;
				}
				int max=0;
				int min=0;
				int sum=0; 
				for(int i=0; i<num; i++){
					int object = sc.nextInt();
					if(i==0){
						max = object;
						min = object;
					}
					sum += object;
					if(max < object){
						max = object;
					}
					if(min > object){
						min = object;
					}
				}
				sum = sum - max - min;
				sum = sum/(num-2);
				System.out.println(sum);
			}
			sc.close();
		}
	}
}


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

typedef long long ll;
const ll MOD = 1e9+7;
const int N = 100;

int n,m,a[N][N];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }

    int ans=0;

    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            int c=0;
            for(int k=1;k<=m;k++){
                c+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
            }
            int r=(int)sqrt((double)c);
            if(r*r==c)ans++;
        }
    }

    cout<<ans;
    return 0;
}


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

int main() {
	int H,W,K,a=INF;
	string f;
	cin >> H >> W >> K;
	vector<vector<int>> w(H, vector<int>(W,0)), c(H, vector<int>(W,0));

	rep(i,H) {
		cin >> f;
		rep(j,W)
			if(f.at(j) == '1')
				w.at(i).at(j) = 1;
	}

	rep(i,H)
		rep(j,W)
			if(j == 0)
				c.at(i).at(j) = w.at(i).at(j);
			else
				c.at(i).at(j) = c.at(i).at(j-1)+w.at(i).at(j);

	rep(i,H-1)
		rep(j,W)
			c.at(i+1).at(j) += c.at(i).at(j);
	
	rep(i,1<<H-1) {
		vector<vector<int>> r;
		int x=0, p=-1;
		bool ok=1;

		rep(j,H-1)
			if(i & 1<<j) {
				r.push_back(vector<int>(W,0));
				rep(k,W)
					if(p == -1)
						r.at(r.size()-1).at(k) = c.at(j).at(k);
					else
						r.at(r.size()-1).at(k) = c.at(j).at(k)-c.at(p).at(k);
				p = j;
			}
		
		r.push_back(vector<int>(W,0));
		rep(k,W)
			if(p == -1)
				r.at(r.size()-1).at(k) = c.at(H-1).at(k);
			else
				r.at(r.size()-1).at(k) = c.at(H-1).at(k)-c.at(p).at(k);

		p = -1;
		rep(j,W) {
			int m=0;

			rep(k,r.size())
				m = max(m, ((p==-1) ? r.at(k).at(j) : r.at(k).at(j)-r.at(k).at(p)));
			if(m <= K)
				continue;

			p = j-1;
			if(p < 0) {
				ok = 0;
				break;
			}
			++x;
		}

		if(ok)
			a = min(a, (int)(x+r.size()-1));
	}

	cout << a << endl;
}

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

using namespace std;

const long long int INF = 1LL<<60;

using Graph = vector<vector<int>>;

int dfs(const Graph &G, int v, vector<int> &dp) {
  if(dp[v] != -1) {
    return dp[v];
  }

  int loc_max = 0;
  for(auto next : G[v]) {
    loc_max = max(loc_max, dfs(G, next, dp) + 1);
  }

  return dp[v] = loc_max;
}

int main() {
  int N, M;
  cin >> N >> M;
  Graph G(N+1);
  for(int i=0; i<M; i++){
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
  }


  vector<int> dp(N+1, -1);
  int res=0;
  for(int i=1; i<=N; i++) {
    dp[i] = dfs(G, i, dp);
    res = max(res, dp[i]);
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main(){
    int H,W,K;
    cin >> H >> W >> K;
    char mp[H][W];
    REP(i,H){
        REP(j,W){
            cin >> mp[i][j];
        }
    }

    int ans = 0;
    for(int h = 0; h < (1 << H); h++){
        for(int w = 0; w < (1 << W); w++){
            int red = 0;
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    if(((h >> i) & 1) && ((w >> j) & 1) && ('#' == mp[i][j])){
                        red++;
                    }
                }
            }
            if(K == red){
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int a, b, max;
    cin >> a >> b;
    max = a + b;
    if(a-b > max) max = a-b;
    if(a*b > max) max = a*b;
    cout << max << endl;
}

Measured memory_bytes: 888
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF (1<<28)
inline void cmax(int &a, int b) { if (a < b) a = b; }

int n, m, S, f[32][32], _sum[40][40];

inline int sum(int x1, int y1, int x2, int y2) {
    return _sum[x2+1][y2+1]-_sum[x2+1][y1]-_sum[x1][y2+1]+_sum[x1][y1];
}

int dp[32][32][32][32];

int solve(int lb) {
    for (int w = 0; w < n; w++) rep (x1, n-w) {
        const int x2 = x1+w;
        for (int h = 0; h < m; h++) rep (y1, m-h) {
            const int y2 = y1+h;
            if (sum(x1, y1, x2, y2) < lb) {
                dp[x1][x2][y1][y2] = -INF;
                continue;
            }
            dp[x1][x2][y1][y2] = 1;
            for (int i = x1; i < x2; i++) {
                cmax(dp[x1][x2][y1][y2], dp[x1][i][y1][y2]+dp[i+1][x2][y1][y2]);
            }
            for (int i = y1; i < y2; i++) {
                cmax(dp[x1][x2][y1][y2], dp[x1][x2][y1][i]+dp[x1][x2][i+1][y2]);
            }
        }
    }
    return dp[0][n-1][0][m-1];
}

int main() {
    for (;;) {
        scanf("%d%d%d", &n, &m, &S);
        if (n == 0) return 0;
        rep (i, n) rep (j, m) scanf("%d", f[i]+j);
        rep (i, n) rep (j, m) {
            _sum[i+1][j+1] = f[i][j]+_sum[i+1][j]+_sum[i][j+1]-_sum[i][j];
        }
        const int tot = sum(0, 0, n-1, m-1);
        const int ans = solve(tot-S);
        int l = 0, r = S+1;
        while (r-l>1) {
            const int mid = (l+r) / 2;
            if (solve(tot-S+mid) >= ans) l = mid;
            else r = mid;
        }
        printf("%d %d\n", ans, l);
    }
}

Measured memory_bytes: 3004
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

const int INF = 1001001001;

void bfs(vector< vector<int> >& edges, vector<int>& d, int node)
{
    d[node] = 0;
    queue<int> Q;
    Q.push(node);
    while(!Q.empty())
    {
        node = Q.front();
        Q.pop();
        for(int e : edges[node])
        {
            if(d[e] == INF)
            {
                d[e] = d[node] + 1;
                Q.push(e);
            }
        }
    }
}

int main()
{
    int n, u, k, v;
    cin >> n;
    vector<int> d(n);
    vector< vector<int> > edges(n);
    for(int i=0;i<n;++i)
    {
        d[i] = INF;
        cin >> u >> k;
        --u;
        for(int j=0;j<k;++j)
        {
            cin >> v;
            edges[u].push_back(--v);
        }
    }
    bfs(edges, d, 0);
    for(int i=0;i<n;++i)
    {
        cout << i+1 << " ";
        if(d[i] == INF) cout << -1;
        else cout << d[i];
        cout << endl;
    }
}


Measured memory_bytes: 3156
import math
n=int(input())
x=[]
y=[]
for i in range(n):
  xi,yi=map(int,input().split())
  x.append(xi)
  y.append(yi)
total=0
for i in range(n-1):
  for j in range(i+1,n):
    total+=math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
print(total*2/n)

Measured memory_bytes: 3064
import Data.List ((\\))

allcards :: [([Char], Integer)]
allcards = concat $ map cards ["S","H","C","D"]
             where
               cards s = zip (repeat s) [1..13]


tupleToString :: ([Char], Integer) -> String
tupleToString (s,n) = s ++ " " ++ show n

allcardsList :: [String]
allcardsList = map tupleToString allcards

main = do
  s' <- getContents
  let s = tail $ lines s'
  putStr $ unlines $ allcardsList \\ s

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

using namespace std;

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N);
    vector<int> y(M);
    for(int i = 0; i < N; i++) cin >> x.at(i);
    for(int i = 0; i < M; i++) cin >> y.at(i);

    int max_x = -100;
    for(int i = 0; i < N; i++) max_x = max(max_x, x.at(i));
    int min_y = 100;
    for(int i = 0; i < M; i++) min_y = min(min_y, y.at(i));

    for(int i = X + 1; i <= Y; i++){
        if(max_x < i and min_y >= i){
            puts("No War");
            return 0;
        }
    }
    puts("War");
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
bool p[1121];vector<int> vp;int ca[1121][200][15],s;
int dfs(int n,int mx,int k){
	if(ca[n][mx][k]>=0)return ca[n][mx][k];
	int r=0;
	rep(i,mx){
		if(vp[i]>n)break;
		if(k==1&&vp[i]==n)r+=1;
		else if(k>1)r+=dfs(n-vp[i],i,k-1);
	}
	return ca[n][mx][k]=r;
}
int main(){
	int i,j;
	for(i=2;i*i<1121;i++)if(!p[i])for(j=i+i;j<1121;j+=i)p[j]=1;
	for(i=2;i<1121;i++)if(!p[i])vp.push_back(i);s=vp.size();
	rep(i,1121)rep(j,200)rep(k,15)ca[i][j][k]=-1;
	int n,k; while(cin>>n>>k,n)cout<<dfs(n,s,k)<<endl;
	return 0;
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define FOR(i, l, r) for(int i = l ; i<= r; ++i)
#define FORD(i, l, r) for(int i = l; i>= r; --i)
#define REP(i, l) for(int i = 0; i< (int)l; ++i)
#define REPD(i, l) for(int i = (int)l - 1; i>=0; --i)
#define fi first
#define se second
#define pb push_back
#define si size
#define name "A"

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, ii> iiii;
template <class T> int getbit(T x,int y) {return x << (y-1) & 1;}
template <class T> T offbit(T x, int y) {return x | 1 <<(y-1);}
template <class T> T onbit(T x, int y) {return x & (~1<<(y-1));}
template <class T> T sqr(T x) {return x*x;}
const ll mod = 1e9 + 7;

int readint() { int res = 0; char ch = getchar(); bool minus = false; while(true) {if(ch == '-' || (ch >= '0' && ch <= '9')) break; ch = getchar();} if(ch == '-') minus = true; else res = ch -'0'; while(true) {ch = getchar(); if(ch < '0' || ch >'9') break;res = res * 10 + ch -'0';}if(minus) return -res;return res;}

ll sum[200];

int main()
{
    //freopen(name".INP", "r", stdin);
    //freopen(name".OUT", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    if(n <= 9) return cout<<n , 0;
    ll m = n;

    int cs = 0;
    while(m) {
        cs++;
        m /= 10;
    }
    ll s = 0;
    string x = "";
    m = n;
    while(m) {
        int cs = m%10;
        m /= 10;
        x = char(cs + '0') + x;
    }
    int dodai = x.length();
    x = " " + x;
    FOR(i, 1, dodai) {
        sum[i] = sum[i-1] + x[i] - '0';
    }
    FOR(i, 1, dodai) {
        if(x[i] == '0') continue;
        s = max(s, 1LL*sum[i-1] + x[i]-'0'-1 + 9 * (dodai - i));
        //cout<<s<<" "<<dodai-i<<endl;
    }
    s = max(s, sum[dodai]);
    cout<<s;
    return 0;
}


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

template <typename T>
vector<T> factors(T n) {
  vector<T> ret;
  for (T i = 1; i * i <= n; i++) {
    if (n % i == 0) ret.push_back(i);
  }
  return ret;
}

int digits(ll n) {
  int ret = 1;
  while (n >= 10) {
    ret++;
    n /= 10;
  }
  return ret;
}

int f(ll a, ll b) { return max(digits(a), digits(b)); }

int main() {
  ll n;
  cin >> n;

  int ans = 1000;
  auto fs = factors(n);
  for (ll a : fs) {
    ll b = n / a;
    ans = min(ans, f(a, b));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
x = 1
L=[]
n= 0
s=0
while x is not 0:
    x = int(input())
    L.append(x)
N=1
L.remove(0)
for i in L:
    while i >=N:

        N=10*N
        n =i%N
        s+=(n/N*10)
        i-=n
    print (int(s))
    s=0
    N = 1

Measured memory_bytes: 7724
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

vector<int> ans;
G g(200005);

void dfs(int v, int p = -1) {
  for (int u: g[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main() {
  IOS;
  int n,q; cin >> n >> q;
  REP(i,n-1) {
    int a,b; cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ans.resize(n);
  REP(i,q) {
    int p,x; cin >> p >> x;
    p--;
    ans[p] += x;
  }
  dfs(0);

  REP(i,n) {
    if (i > 0) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 24204
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 300000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
		ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	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;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	ll n, a, b,ans;
	cin >> n >> a >> b;
	ans = b * (n-1)+a - a * (n-1)-b + 1;
	if (a > b)
		ans = 0;
	if (n == 1 && a != b)
		ans = 0;
	cout << ans << endl;
}

Measured memory_bytes: 4992
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()
import sys
sys.setrecursionlimit(10**7)

show_flg=False
#show_flg=True
def devisors(x):
    rt=[1,x]
    for i in range(2,int(x**0.5+1)):
        if x%i==0:
            rt.append(i)
            if x//i!=i:rt.append(x//i)
    return rt
    
n,k=MI()
a=LI()
A=sum(a)
ds=devisors(A)
ans=1

for d in ds:
    r=[j%d for j in a]
    show(r,d)
    if sum(r)%d!=0:
        continue
    r.sort()
    ac=[0]
    for j in range(n):
        ac.append(ac[-1]+r[j])
    for j in range(1,n):
        if ac[j]==(n-j)*d-(ac[n]-ac[j]) and ac[j]<=k:
            ans=max(d,ans)
            show(j,d,ans)

print(ans)
show(ds)
    


Measured memory_bytes: 43740
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
#define Length 80000
using namespace std;
typedef pair<ll, ll> P;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

bool used[110];

bool cmp(const pair<int,int> &a,const pair<int,int> &b) {
	return a.first * a.first + a.second * a.second > b.first*b.first + b.second * b.second;
}

void solve(int n) {
	vector<pair<int, int>>p(n), q(n);
	for (int i = 0;i < n;i++) {
		cin >> p[i].first >> p[i].second;
	}
	for (int i = 0;i < n;i++) {
		cin >> q[i].first >> q[i].second;
	}
	int dist = Length, flag = 0;
	int ans = 0;
	sort(p.begin(), p.end());
	for (int i = 0;i < n;i++) {
		dist = Length;
		flag = 0;
		for (int j = 0;j < n;j++) {
			if (!used[j]) {
				int x = q[j].first - p[i].first;
				int y = q[j].second - p[i].second;
				if ((x > 0) && (y > 0) && y < dist) {
					dist = y;
					flag = j;
				}
			}
		}
		if (dist < Length) {
			ans++;
			used[flag] = true;
		}
	}
	cout << ans << endl;
}

char board[110][110];
	
int main(void){
	int a, b;
	cin >> a >> b;
	if (a > 0)cout << "Positive" << endl;
	else {
		if (a == 0) {
			cout << "Zero" << endl;
		}
		else {
			if (b < 0) {
				int num = b - a + 1;
				if (num % 2 == 0)cout << "Positive" << endl;
				else cout << "Negative" << endl;
			}
			else cout << "Zero" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256