akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s;
int p,q,r,i;
int dfs(){
  int t[2]={},c=0,m=0,w=0,k=0,a=0;
  if(s[i]=='(')i++;
  for(;i<s.size();i++){
    if(s[i]=='(')t[c++]=dfs(),a++;
    else if(s[i]>='0'&&s[i]<='2')t[c++]=s[i]-'0',a++;
    else if(s[i]=='P')t[c++]=p,a++;
    else if(s[i]=='Q')t[c++]=q,a++;
    else if(s[i]=='R')t[c++]=r,a++;
    else if(s[i]=='-')m++;
    else if(s[i]=='+')w++,a=0;
    else if(s[i]=='*')k++,a=0;
    if(m%2&&a){
     t[c-1]=abs(t[c-1]-2);
     a=m=0;
   }
    if(s[i]==')'){
      if(w)return max(t[0],t[1]);
      if(k)return min(t[0],t[1]);
    }
  }
  return t[0];
}
int main(){
  while(cin>>s,s!="."){
      int res=0;
      r(x,3)r(y,3)r(z,3){
	p=x;q=y;r=z;i=0;
	if(dfs()==2)res++;
      }
      cout<<res<<endl;
  }
}

Measured memory_bytes: 3172
function main(input){
    var tmp;
    input = input.split("\n");
    tmp = input[0].split(" ");
    var N = Number(tmp[0]);
    var M = Number(tmp[1]);
    var p1 = new Array(input.length);
    var p2 = new Array(input.length);
    p1.fill(false);
    p2.fill(false);

    for(var i=0; i<input.length; i++){
        tmp = input[i].split(" ");
        if(Number(tmp[0])==1){
            p1[Number(tmp[1])] = true;
        }
        if(Number(tmp[1])==N){
            p2[Number(tmp[0])] = true;
        }
    }

    var index = -1;
    while(true){
        var index = p1.indexOf(true, index+1);
        if(index<0){
            console.log("IMPOSSIBLE");
            return;
        }else{
            if(p2[index]){
                console.log("POSSIBLE");
                return;
            }
        }
    }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 38840
a, b = map(int, input().split())

cnt = b - a + 1
cnt -= (a % 2 == 1) + (b % 2 == 0)
a, b = a * (a % 2 == 1), b * (b % 2 == 0)
print((cnt // 2 % 2) ^ a ^ b)


Measured memory_bytes: 61896
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := map[int]int{}
	for i := 0; i < n; i++ {
		a[nextInt()]++
	}

	x := 0
	for i := range a {
		if x < i && a[i] >= 2 {
			x = i
		}
	}
	a[x] -= 2

	y := 0
	for i := range a {
		if y < i && a[i] >= 2 {
			y = i
		}
	}
	a[y] -= 2

	puts(x * y)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


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

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

  string s;
  cin >> s;

  int ans = 0;
  for (auto c : s) if (c == '1') ++ans;

  cout << ans << '\n';

  return (0);
}


Measured memory_bytes: 3588
#include <iostream>
#include <cmath>
#include <string>

int main(void){
    std::string S;
    int N, ans=1000;
    std::cin >> S;

    N = S.size();

    for (int i=0; i<N-2; ++i){
        std::string s = "";
        s += S[i];
        s += S[i + 1];
        s += S[i + 2];
        int tmp = std::stoi(s);
        if (ans > abs(tmp - 753)){
            ans = abs(tmp - 753);
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  int c[10][10], A[205][205];
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
    }
  }
  for (int k = 0; k <= 9; k++) {
    for (int i = 0; i <= 9; i++) {
      for (int j = 0; j <= 9; j++) {
        if (c[i][j] > c[i][k] + c[k][j]) {
          c[i][j] = c[i][k] + c[k][j];
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A[i][j] == -1 || A[i][j] == 1) {
      } else {
        ans = ans + c[A[i][j]][1];
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main() {
    int k;
    cin >> k;
    string ans = "";
    rep(i, k){
        ans += "ACL";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
n, a, b = gets.chomp.split(" ").map(&:to_i)
def digit_sum(n)
  sum = 0
  while n > 0 do
    sum += n % 10
    n /= 10
  end
  sum
end
ary = []
(1..n).each do |c|
  e = digit_sum(c)
  if a <= e && b >= e 
   ary << c
  end
end
p ary.sum

Measured memory_bytes: 14268
def f(n,cnt):
    if n==0:
        return cnt
    popcnt = bin(n).count('1')
    return f(n%popcnt,cnt+1)

n = int(input())
x = input()

m = int(x,2)
m_cnt = x.count('1')

mp = m%(m_cnt+1)
mm = m%(m_cnt-1) if m_cnt > 1 else 0

for i,s in enumerate(x):
    i = n-1-i
    num = None

    if s == '0':
        mod = m_cnt+1
        num = (mp+pow(2,i,mod))%mod
    elif m_cnt > 1:
        mod = m_cnt-1
        num = (mm-pow(2,i,mod))%mod
    else:
        print(0)
        continue

    print(1+f(num,0))

Measured memory_bytes: 9584
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
A.append(0)
if A[0]!=0:
    print(-1)
    exit()
a0 = 0
res = 0
for a in A:
    if a0 >= a:
        res += a0
    elif a - a0 >= 2:
        print(-1)
        exit()
    a0 = a
print(res)

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n, k;
vector<int> pos, neg;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>k;
    for (int i=0; i<n; i++) {
	int x; cin>>x;
	if (x==0) {
	    k--; continue;
	}
	if (x>0) {
	    pos.push_back(x);
	}
	if (x<0) {
	    neg.push_back(-x);
	}
    }

    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());

    if (k==0) out(0);


    int ans = 2e9;

    for (int i=0; i<=k; i++) {
	if (i-1 >= (int)pos.size()) break;
	int j = k - i;
	if (j-1 >= (int)neg.size()) continue;
	int walk = (i-1<0 ? 0 : pos[i-1]*2) + (j-1<0 ? 0 : neg[j-1]);
	ans = min(walk, ans);
    }

    swap(neg, pos);


    for (int i=0; i<=k; i++) {
	if (i-1 >= (int)pos.size()) break;
	int j = k - i;
	if (j-1 >= (int)neg.size()) continue;
	int walk = (i-1<0 ? 0 : pos[i-1]*2) + (j-1<0 ? 0 : neg[j-1]);
	ans = min(walk, ans);
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,i,c,j;
    string s;char cc;
    cin>>a>>b>>c;
    if(a%b==0)
    {
        cout<<(a/b)*c<<endl;
    }
    else
    {

        cout<<((a/b)+1)*c<<endl;

    }

}


Measured memory_bytes: 3612
# coding: utf-8
from math import ceil
H, W = map(int, input().split())
if H == 1 or W == 1:
    print(1)
else:
    ans = 0
    ans += ceil(W / 2) * ceil(H / 2)
    ans += (W // 2) * (H // 2)
    print(ans)

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

using namespace std;

long long dp[123456][3];

int main () {
	int n;
	cin >> n;
	vector<vector<int>> v(n);
	for(int i = 0; i < n; i++) v[i] = vector<int>(3);

	memset(dp, -1, sizeof dp);
	for(int i = 0; i < n; i++) {
		cin >> v[i][0] >> v[i][1] >> v[i][2];
	}

	dp[0][0] = v[0][0];
	dp[0][1] = v[0][1];
	dp[0][2] = v[0][2];

	for(int i = 1; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			dp[i][j] = max(dp[i-1][(j+2)%3], dp[i-1][(j+1)%3]) + v[i][j];
		}
	}
	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
}


Measured memory_bytes: 8576
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int l,r=1e6,n,m,a,b;

int main() {
	
	cin>>n>>m;
	while(m--){
		cin>>a>>b;
		l = max(l,a);
		r = min(r,b);
	}

if(r-l+1<0) cout<<0;	
else cout<<r-l+1;
	return 0;
}

Measured memory_bytes: 256
let s = read_line ()
let f l r = Printf.printf "%d %d\n" (l + 1) (r + 1); exit 0
let _ = String.(iteri (fun i c -> if i > 0 && s.[i - 1] = c then f (i - 1) i) s; iteri (fun i c -> if i > 1 && s.[i - 2] = c then f (i - 2) i) s); print_endline "-1 -1"

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;  cin >> a >> b >> c;
    int ans;
    if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a) ) {
      ans = 2;
    } else if (a == b && b == c) {
      ans = 1;
    } else {
      ans = 3;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
    int d, g;
    cin >> d >> g;
    int p[d], c[d];
    int sum = 0, num_mn = 1001;
    bool ach;
    for (int i = 0; i < d; i++) cin >> p[i] >> c[i];

    for (int bit = 0; bit < (1 << d); bit++) {
        int num_tmp = 0;
        sum = 0;
        ach = false;
        for (int i = 0; i < d; i++) {
            if (bit & (1 << i)) {
                num_tmp += p[i];
                sum += ((i + 1) * 100 * p[i] + c[i]);
            }
        }
        // cout << "1st sum:" << sum << " num_tmp:" << num_tmp << endl;
        if (sum < g) {
            for (int i = d - 1; i >= 0; i--) {
                if (!(bit & (1 << i))) {
                    if (g - sum <= (i + 1) * 100 * (p[i] - 1)) {
                        ach = true;
                        num_tmp += ((g - sum) / ((i + 1) * 100));
                        if ((g - sum) % ((i + 1) * 100) != 0) num_tmp++;
                        break;
                    } else {
                        sum += (i + 1) * 100 * (p[i] - 1);
                        num_tmp += (p[i] - 1);
                    }
                }
            }
        } else
            ach = true;
        if (!ach) num_tmp = 1001;
        num_mn = min(num_mn, num_tmp);
    }

    cout << num_mn << endl;

    return 0;
}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        String A, B, C;

        Scanner input = new Scanner(System.in);

        A = input.next();
        B = input.next();
        C = input.next();

        int lengthA = A.length();
        int lengthB = B.length();
        int len3 = C.length();

        char Astringlastchar = A.charAt(lengthA - 1);

        char Bstringfirstchar = B.charAt(0);

        char Bstringlastchar = B.charAt(lengthB - 1);

        char Cstringfirstchar = C.charAt(0);

        if (Astringlastchar == Bstringfirstchar && Bstringlastchar == Cstringfirstchar) {

            System.out.println("YES");
        } else {

            System.out.println("NO");
        }

    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	ll A,B,C;
	A=B=C=0;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		if(x<=a){
			A++;
		}
		else if(x>=b+1){
			C++;
		}
		else{
		B++;
		}
	}
	cout << min({A,B,C});
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
from sys import stdin

n,q = map(int,stdin.readline().split())
s = input()
lr = [list(map(int,stdin.readline().split())) for i in [0]*q]

posac = []
for i in range(1,n):
    if s[i-1]+s[i]=="AC":
        posac.append(i)
posac.append(n+1)

idx = 0
loc = 0
numac = [0 for i in [0]*n]
for i in range(n):
    if posac[idx]==i:
        loc += 1
        idx += 1
    numac[i] = loc
numac.append(loc)

#print(numac)
for i in lr:
    l,r = i[0]-1,i[1]-1
    print(numac[r]-numac[l])

Measured memory_bytes: 32424
import sys

sys.setrecursionlimit(10**7)


def dfs(s, to, ans, p=-1):
    for v in to[s]:
        if v == p: continue
        ans[v] += ans[s]
        dfs(v, to, ans, s)


def main():
    N, Q = map(int, input().split())
    to = [[] for _ in range(N)]
    ans = [0] * N

    for _ in range(N - 1):
        a, b = map(int, input().split())
        a, b = a - 1, b - 1
        to[a].append(b)
        to[b].append(a)
    
    for _ in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
    dfs(0, to, ans)
    
    print(*ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 283152
import java.util.Scanner;

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

	try (Scanner sc = new Scanner(System.in)) {
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < w; i++) {
			values[i] = i + 1;
		}
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			int c = values[a];
			values[a] = values[b];
			values[b] = c;
		}
		for (int i = 0; i < values.length; i++) {
			System.out.println(values[i]);
		}
	}
	}
}


Measured memory_bytes: 26100
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cmath>

using namespace std;
#define ll long long

bool pattern(vector<vector<int>>& ans,int N, int K, int now, int value){
    if (now == N) {
        return (value == 0);
    }
    for (auto i=0; i<K; i++) {
        if(pattern(ans,N,K,now+1, value^ans[now][i]))return true;
    }
    
    return false;
}
int max_h(const vector<int>& hs){
    int hmax =-1;
    auto hssize=hs.size();
    for (auto i=0;i<hssize;i++) {
        if (hs[i]>hmax) {
            hmax = hs[i];
        }
       
    }
    return hmax;
}



int main(int argc, const char * argv[]) {
    // insert code here...
    
    string S;
    cin >> S;
    
    int count = 1;
    string prechank = "";
    prechank += S[0];
    string chank ="";
    for (auto i=1; i<S.size(); i++) {
        chank += S[i];
        if(prechank == chank){
            continue;
        }else{
            //cout << chank << endl;
            prechank = chank;
            chank = "";
            count+=1;
        }
    }
    
    cout << count << endl;
    
    return 0;
}

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

const int N = 100005;

long long x[N], c[N], cc[N], cmx[N], ccmx[N], v[N];

int main() {
	int n; long long C; cin >> n >> C;
	for (int i = 1; i <= n; i++)cin >> x[i] >> v[i];

	for (int i = 1; i <= n; i++) {
		c[i] = c[i - 1] + v[i] - (x[i] - x[i - 1]);
		cmx[i] = max(cmx[i - 1], c[i]);
	}
	x[n + 1] = C;
	for (int i = n; i >= 1; i--) {
		cc[n - i + 1] = cc[n - i] + v[i] - (x[i + 1] - x[i]);
		ccmx[n - i + 1] = max(ccmx[n - i], cc[n - i + 1]);
	}
	long long ans = 0;
	for (int i = 0; i <= n; i++) {
		ans = max(ans, c[i] - x[i] + ccmx[n - i]);
		ans = max(ans, cc[i] - (C - x[n - i + 1]) + cmx[n - i]);
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

bool dp[30005][4][1000];

void Main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    dp[0][0][0] = true;
    rep(i, N) {
        int num = S[i] - '0';
        rep(j, 4) {
            rep(k, 1000) {
                if (dp[i][j][k]) {
                    if (j != 3 && 10 * k + num < 1000) {
                        dp[i + 1][j + 1][10 * k + num] = true;
                    }
                    dp[i + 1][j][k] = true;
                }
            }
        }
    }
    int cnt = 0;
    rep(i, 1000) {
        if (dp[N][3][i]) cnt++;
    }
    cout << cnt << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 117504
#include <bits/stdc++.h>
using namespace std;
int n, k;
const int maxn = 1e4;
int d[maxn];
int a[maxn];
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    // Failed to predict input format
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> d[i];
        for (int j = 1; j <= d[i]; j++)
        {
            int x;
            cin >> x;
            a[x] = 1;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        if (a[i] == 0)
            ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
using System; 
class Program
    {
        static void Main(string[] args)
        {
            int N;
            int T;

            var line1 = Console.ReadLine().Split(' ');
            if(int.TryParse(line1[0],out N)&&int.TryParse(line1[1],out T))
            {
                if(N >= 1 && N <= 100 && T >= 1 && T <= 1000)
                {
                    var min = int.MaxValue;
                    for(int i = 0; i< N; i++)
                    {
                        int cost;
                        int time;
                        var lines = Console.ReadLine().Split(' ');
                        if (int.TryParse(lines[0], out cost) && int.TryParse(lines[1], out time))
                        { 
                            if(cost >= 1 && cost <= 1000 && time >= 1 && time <= 1000)
                            {
                                if(min > cost && time <= T)
                                {
                                    min = cost;
                                }
                            }
                        }

                    }

                    if(min == int.MaxValue)
                    {
                        Console.WriteLine("TLE");
                    }
                    else
                    {
                        Console.Write(min);
                    }
                }
            }
        }
    }

Measured memory_bytes: 11092
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int main() {
	int n;
	int *t, *x, *y;
	scanf("%d", &n);
	t = (int *)malloc((n + 1) * sizeof(int));  /* メモリ領域の確保 */
	x = (int *)malloc((n + 1) * sizeof(int));
	y = (int *)malloc((n + 1) * sizeof(int));
	int tf = 1;

	int i;
	t[0] = 0;
	x[0] = 0;
	y[0] = 0;
	for (i = 1; i < n + 1; i++) {
		scanf("%d %d %d", &t[i], &x[i], &y[i]);
	}
	for (i = 0; i < n ; i++) {
		if ((fabs(x[i + 1] - x[i]) + fabs(y[i + 1] - y[i])) > (t[i + 1] - t[i])|| ((int)(fabs(x[i + 1] - x[i]) + fabs(y[i + 1] - y[i])) +(t[i + 1] - t[i]))%2==1) {
			printf("No");
			tf = 0;
			break;
		}
	}
	if (tf == 1)printf("Yes");
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;

  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  bool flag = true;
  for(int i=0; i<n; i++){
  	if(a[i] % 2 == 0){
      if(a[i] % 3 != 0 && a[i] % 5 != 0) flag = false;
    }
  }
  if(flag){
  	cout << "APPROVED" << endl;
  }else{
  	cout << "DENIED" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n,L;
void o(int x,int y){cout<<x<<' '<<y<<'\n';}
int main(){
	scanf("%d",&n);
	if(n==(n&-n)) return puts("No"),0;
	puts("Yes");
	for(int i=2;i+1<=n;i+=2){
		o(i,i+1),o(i+1,1);
		o(1,n+i),o(n+i,n+i+1);
	}o(n+1,2);L=1<<31-__builtin_clz(n);
	if(!(n&1)) o(n,L+n),o(n+n,L^n^1);
}

Measured memory_bytes: 2304
n, a, b = [int(i) for i in input().split()]


summ=0
for i in range(1,n+1):
  s = str(i)
  lists = list(s)
  array = list(map(lambda x: int(x), lists))
  
  if sum(array)>=a and sum(array)<=b:
    summ += i
    
print(summ)

Measured memory_bytes: 3060
import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    let nm = readWords { Int($0)! }
    let n = nm[0]
    let m = nm[1]
    
    if n >= m {
        print(0)
        return
    }

    let X = readWords { Int($0)! }.sorted()

    // 区間が得られる。
    // 問題を簡単にしてみる。
    // コマが1つなら答えは X[m-1] - X[0]
    // コマが複数あるなら、訪れない区間ができるのでそのうち一番広い区間を選択すれば良い。
    // コマが2つなら、訪れない区間は1つ。-> 全体から最も広い区間を1つ引く。
    // コマがn個なら、訪れない区間はn-1個。 -> 全体から広い区間をn-1個引く。

    var distances = (1..<m).map { X[$0] - X[$0-1] }
    distances.sort(by: >)

    print(distances.reduce(0, +) - distances[..<(n-1)].reduce(0, +))
}


main()

Measured memory_bytes: 18724
#include <iostream>

using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	int ans,tmp=2;
	if(m!=1){
		for(int i=m-1;i>0;i--){
			tmp*=2;
		}
	}
	ans=(m*1900)+((n-m)*100);
	ans*=tmp;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  
  string A, B, C;
  
  cin >> A >> B >> C;
  
  int an = A.size();
  int bn = B.size();
  
  if(A.at(an-1) == B.at(0) && B.at(bn-1) == C.at(0)) {
    
    cout << "YES" << endl;
    
  } else {
    
    cout << "NO" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int N;
  cin >> N;
  vector<vector<int>> abc2(N, vector<int>(3));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> abc2.at(i).at(j);
    }
  }
  
  vector<vector<int>> dp(N, vector<int>(3, -INF));
  for (int i = 0; i < 3; i++)
  {
    dp.at(0).at(i) = abc2.at(0).at(i);
  }

  for (int i = 1; i < N; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      for (int k = 0; k < 3; k++)
      {
        if (j != k) chmax(dp.at(i).at(j), dp.at(i - 1).at(k) + abc2.at(i).at(j));
      }
    }
  }
  
  int ans = -INF;
  for (int i = 0; i < 3; i++)
  {
    chmax(ans, dp.at(N - 1).at(i));
  }
  
  cout << ans << endl;
}

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

#define MAXN 100005

typedef long long lint;

using namespace std;

const int mod = 1e9 + 7;
int n, a[MAXN], val[MAXN], deg[MAXN];
int sum[MAXN];
lint f[MAXN];
bool oncir[MAXN];
int visit[MAXN];
lint ans = 1;

int read() {
    char c = getchar();
    int x = 0;
    while (!isdigit(c))
        c = getchar();
    while (isdigit(c)) {
        x = (x << 3) + (x << 1) + c - '0';
        c = getchar();
    }
    return x;
}

void calc(int u) {
    vector<int> g;
    while (oncir[u]) {
        oncir[u] = false;
        g.push_back(u);
        u = a[u];
    }
    reverse(g.begin(), g.end());
    int first = -1, last = -1;
    for (int i = 0; i < (int)g.size(); ++i) {
        int u = g[i];
        if (val[u]) {
            if (!(~first)) {
                last = first = i;
                continue;
            }
            int l1 = val[g[last]], l2 = i - last;
            ans = ans * ((l2 > l1) + (l2 >= l1)) % mod;
            last = i;
        }
    }
    if (~first && first == last) {
        int l1 = val[g[last]], l2 = (int)g.size();
        ans = ans * ((l2 > l1) + (l2 >= l1)) % mod;
    }
    else if (~first) {
        int l1 = val[g[last]], l2 = (int)g.size() - last + first;
        ans = ans * ((l2 > l1) + (l2 >= l1)) % mod;
    }
    else
        ++sum[(int)g.size()];
}

void solve() {
    for (int i = 1; i <= n; ++i)
        if (oncir[i])
            calc(i);
    for (int i = 1; i <= n; ++i) {
        f[0] = 1;
        for (int j = 1; j <= sum[i]; ++j) {
            if ((i & 1) && i != 1)
                f[j] = f[j - 1] * 2 % mod;
            else
                f[j] = f[j - 1];
            if (j > 1)
                f[j] = (f[j] + f[j - 2] * i % mod * (j - 1) % mod) % mod;
        }
        ans = ans * f[sum[i]] % mod;
    }
}

int main() {
//    freopen("1_12.txt", "r",stdin);
    n = read();
    for (int i = 1; i <= n; ++i) {
        a[i] = read();
        ++deg[a[i]];
    }
    for (int i = 1; i <= n; ++i) {
        int u = i;
        if (visit[u])
            continue;
        while (!visit[u]) {
            visit[u] = i;
            u = a[u];
        }
        if (visit[u] != i)
            continue;
        while (!oncir[u]) {
            oncir[u] = true;
            u = a[u];
        }
    }
    for (int i = 1; i <= n; ++i)
        if ((oncir[i] && deg[i] > 2) || (!oncir[i] && deg[i] > 1)) {
            puts("0");
            return 0;
        }
    for (int i = 1; i <= n; ++i) {
        if (deg[i])
            continue;
        int u = i, d = 0;
        while (!oncir[u]) {
            u = a[u];
            ++d;
        }
        val[u] = d;
    }
    solve();
    printf("%lld\n", ans);
}



Measured memory_bytes: 2556
#include <bits/stdc++.h>
 
using namespace std;
 
#define ull unsigned long long
#define ll long long
#define int long long
#define ld long double
 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define MX LLONG_MAX
#define MN LLONG_MIN

const int N=1e5+5;
const ll mod=1e9+7;
 
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}          
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

int32_t main()                  
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    ll arr[N]={0};
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        arr[x]++;
        arr[y+1]--;
    }
    ll ans=0;
    for(ll i=1;i<N;i++)
    {
        arr[i] += arr[i-1];
        if(arr[i]==m)
            ans++;
    }
    cout<<ans;
    return 0;
}  

Measured memory_bytes: 1024
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
long long A[5002];
long long B[5002][201] = {};
long long go[201] = {};
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	REP(i, n-1) {
		scanf("%lld", &A[i]);
	}
	REP(i, n) {
		REP(q, m) {
			scanf("%lld", &B[i][q]);
		}
	}
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		long long now_ans = 0;
		for (int q = 0; q < m; ++q) {
			go[q] = 0;
		}
		for (int q = i; q < n; ++q) {
			for (int j = 0; j < m; ++j) {
				if (go[j] < B[q][j]) {
					now_ans += B[q][j] - go[j];
					go[j] = B[q][j];
				}
			}
			ans = max(ans, now_ans);
			now_ans -= A[q];
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 8320
import scala.io.StdIn.{readInt,readLine}

object Main {
  def main(args:Array[String]) = {
    val n = readInt
    val s = for(i<-1 to n) yield {
      val l = readLine.split(" ").map(_.toInt)
      val x = l(0)*l(2)+l(1)*l(3)
      val y = (l(0)*(if(l(2)<5) 5 else l(2)) + l(1) * (if(l(3)<2) 2 else l(3)))*0.8
      if(x<y) x.toInt else y.toInt
    }
    println(s.mkString("\n"))
  }
}

Measured memory_bytes: 44216
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr 12 21:00:01 JST 2020
 **/

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    if (n % 2 == 0) {
        auto dp = make_vec<Int>(n + 1, 2, 0);
        REP(i, n) {
            dp[i + 1][0] = dp[i][0] + (i % 2 ? 0 : a[i]);
            dp[i + 1][1] = std::max(dp[i][0], dp[i][1] + (i % 2 ? a[i] : 0));
        }
        std::cout << std::max(dp[n][0], dp[n][1]) << std::endl;
    } else {
        auto dp = make_vec<Int>(n + 1, 3, 0);
        REP(i, n) {
            dp[i + 1][0] = dp[i][0] + (i % 2 ? 0 : a[i]);
            dp[i + 1][1] = std::max(dp[i][0], dp[i][1] + (i % 2 ? a[i] : 0));
            dp[i + 1][2] = std::max({dp[i][1], dp[i][2] + (i % 2 || i == 0 ? 0 : a[i])});
        }
        std::cout << std::max({dp[n - 2][0], dp[n][1], dp[n][2]}) << std::endl;
    }
}


Measured memory_bytes: 15568
#include <stdio.h>
#define NIL -1

typedef struct Node{int p,l,r;}tree;
tree T[10000];
int ten;

void preParse(int u){
  if(u==NIL)return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if(u==NIL)return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u){
  if(u==NIL)return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(){
  int i,v,l,r,root;

  scanf("%d",&ten);

  for(i=0;i< ten;i++)T[i].p=NIL;

  for(i=0;i<ten;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l=l; T[v].r=r;
    if(l!=NIL) T[l].p=v;
    if(r!=NIL) T[r].p=v;
  }

  for(i=0;i<ten;i++)if(T[i].p==NIL)root=i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
  return 0;
}



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

struct ele{double x, y;};
bool cmp(const ele &a, const ele &b){
    return atan2(a.x, a.y) < atan2(b.x, b.y);
}

int main() {
    int N;
    cin >> N;
    vector<ele> e;
    int k = 0;
    for (int i = 0; i < N; ++i) {
        double x, y;
        cin >> x >> y;
        if(x == 0 && y == 0) {
            k++;
            continue;
        }
        e.push_back({x, y});
    }
    N -= k;
    if(N == 0){
        cout << 0 << "\n";
        return 0;
    }
    sort(e.begin(), e.end(), cmp);
    double ans = 0;
    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j < N; ++j) {
            double x=0, y=0;
            for (int k = 0; k < i; ++k) {
                int id = (k+j) % N;
                x += e[id].x;
                y += e[id].y;
            }
            double temp = sqrt(x*x + y*y);
            ans = max(ans, temp);
        }
    }
    cout << setprecision(30) << ans;
    return 0;
}

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

int n;
string s;
vector<int> g[100005];
int tot = 1;
vector<int> sizes;

void out() {
	cout << -1; exit(0);
}

void dfs(int u,int id) {
	if (id == sizes.size() - 1) return;
	int sz = sizes[id] - sizes[id + 1] - 1;
	for (int i = 1; i <= sz + 1; ++i) g[u].push_back(++tot);
	dfs(tot, id + 1); 
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> s; n = s.size(); s = '~' + s;
	if (s[1] == '0') out();
	if (s[n] == '1') out();
	for (int i = 1; i <= n - 1; ++i) if (s[i] != s[n - i]) out();
	sizes.push_back(n);
	for (int i = n - 1; i >= 1; --i) if (s[i] == '1') sizes.push_back(i);
	// for (int sz : sizes) cout << sz << ' '; cout << '\n';
	dfs(1, 0);
	for (int u = 1; u <= n; ++u) {
		for (int v : g[u]) {
			cout << u << ' ' << v << '\n';
		}
	}  
}


Measured memory_bytes: 7400
#include<stdio.h>
int main(void)
{
    int count = 0,n,p[200000],i,min;
    scanf("%d",&n);
    for(i = 0; i < n ; i++)
    {
        scanf("%d",&p[i]);
    }
    for(i = 0 ; i < n ; i++)
    {
        if(i == 0)
        {
            min = p[0];
            count++;
        }
        else
        {
            if(min > p[i])
            {
                min = p[i];
                count++;
            }
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 2484
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int a, b, c; cin >> a >> b >> c;
    vector<int> odd(3);
    int add = a + b + c;
    int ud;
    int mx = max(a, max(b, c));
    if (add % 2 == mx % 2) ud = mx;
    else ud = mx + 1;

    odd[0] = ud - a;
    odd[1] = ud - b;
    odd[2] = ud - c;

    int ki = 0;
    bool k = false;
    int ans = 0;

    for (auto& n : odd) if (n % 2) {
        --n;
        k = true;
    }
    if (k) ++ans;

    for (auto n : odd) ans += n / 2;

    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
my $n = <STDIN> - 0;
my $k = <STDIN> - 0;
my @x = split / /, <STDIN>;
@x = map { $_ - 0 } @x;

my $dist = 0;
for(my $i = 0;$i < $n; $i++){
    my $xpos = $x[$i];
    if($xpos < $k - $xpos){
        $dist += $xpos;
    }else{
        $dist += $k - $xpos;
    }
}

print $dist * 2;

Measured memory_bytes: 512
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define pm(m) for(auto itr=(m).begin();itr!=(m).end();itr++){itr->first<<" "<<itr->second<<"\n";}
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
#define bug(x) cout<<(x)<<" ";exit(0);
int mod = 1000000007;
int mod1 = 998244353;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void u(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb]){
            v[ra] = v[rb];
            sz[rb]+=sz[ra];
        }else{
            v[rb]=v[ra];
            sz[ra]+=sz[rb];
        }
    }
    bool f(int a,int b){
        //same set
        return (root(a)==root(b));
    }
   
    
};
vector<int> matmul(vector<int> a,vector<int> b){
    vector<int> c(4,0);
    c[0] = (a[0]%mod*b[0]%mod + a[1]%mod*b[2]%mod)%mod;
    c[1] = (a[0]%mod*b[1]%mod + a[1]%mod*b[3]%mod)%mod;
    c[2] = (a[2]%mod*b[0]%mod + a[3]%mod*b[2]%mod)%mod;
    c[3] = (a[2]%mod*b[1]%mod + a[3]%mod*b[3]%mod)%mod;
    return c;
}
vector<int> id={1,0,0,1};


int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
	int a,b,c;
	cin>>a>>b>>c;
	int k=0;
	cin>>k;
	int ans=0;
	while(b<=a){
	    b*=2;
	    ans++;
	}
	while(c<=b){
	    c*=2;
	    ans++;
	}
	if(ans>k)cout<<"No\n";
	else cout<<"Yes\n";
}

Measured memory_bytes: 5996
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    ll N;
    cin >> N;

    ll A = 0;

    for (ll i = 1; i * i <= N; i++)
    {
        if (N % i == 0) A = i;
    }

    ll B = N / A;

    ll count = 0;
    while (B > 0)
    {
        count++;
        B /= 10;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  int N, K, sum=0;
  cin >> N >> K;
  int data[N];

  REP(i, N) cin >> data[i];
  sort(data,data+N,greater<int>());

  REP(i, K) sum += data[i];
  cout << sum << endl;
}


Measured memory_bytes: 3560
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

struct Edge {
	int to, pair;
	bool has_flow;
};
void bfs(const std::vector<std::vector<Edge>>& nodes, std::vector<int>& depth, std::queue<int> &queue, const int source) {
	queue.push(source);
	std::fill(depth.begin(), depth.end(), -1); depth[source] = 0;
	while (!queue.empty()) {
		auto top = queue.front(); queue.pop();
		for (const auto e : nodes[top]) if (e.has_flow && depth[e.to] == -1) {
			depth[e.to] = depth[top] + 1;
			queue.push(e.to);
		}
	}
}
bool dfs(std::vector<std::vector<Edge>>& nodes, const std::vector<int> &depth, std::vector<int>& searching, const int current, const int sink) {
	if (current == sink) return true;
	while (searching[current] < nodes[current].size()) {
		auto e = nodes[current][searching[current]];
		if (e.has_flow && depth[current] < depth[e.to] && dfs(nodes, depth, searching, e.to, sink)) {
			nodes[current][searching[current]].has_flow = false;
			nodes[e.to][e.pair].has_flow = true;
			return true;
		}
		++searching[current];
	}
	return false;
}
int max_matching(std::vector<std::vector<Edge>> nodes, const int source, const int sink) {
	std::queue<int> queue;
	std::vector<int> depth(nodes.size()), searching(nodes.size(), 0);
	int count = 0;
	bool has_flow = true;
	while (has_flow) {
		has_flow = false;
		bfs(nodes, depth, queue, source);
		std::fill(searching.begin(), searching.end(), 0);
		while (dfs(nodes, depth, searching, source, sink)) {
			has_flow = true;
			++count;
		}
	}
	return count;

}
void add_edge(std::vector<std::vector<Edge>>& nodes, int from, int to) {
	nodes[from].push_back(Edge{ to, (int)nodes[to].size(), true });
	nodes[to].push_back(Edge{ from, (int)nodes[from].size() - 1, false });
}
int main() {
	int n; std::cin >> n;
	std::vector<std::unordered_map<std::string, int>> groups(10);
	for (auto i = 0; i < n; ++i) {
		std::string name; std::cin >> name;
		groups[name.size() - 1].emplace(name, i);
	}
	std::vector<std::vector<Edge>> nodes(n + 2);
	for (int l = 9; l > 0; --l) {
		for (const auto& pair : groups[l]) {
			if (l % 2 == 0) {
				add_edge(nodes, n, pair.second);
			}
			else {
				add_edge(nodes, pair.second, n + 1);
			}
			for (auto i = 0; i <= l; ++i) {
				auto target = pair.first; target.erase(i, 1);
				auto find = groups[l - 1].find(target);
				if (find != groups[l - 1].end()) {
					if (l % 2 == 0) {
						add_edge(nodes, pair.second, find->second);
					}
					else {
						add_edge(nodes, find->second, pair.second);
					}
				}
			}
		}
	}
	for (const auto& pair : groups[0]) {
		add_edge(nodes, n, pair.second);
	}
	std::cout << max_matching(nodes, n, n + 1) << '\n';
}



Measured memory_bytes: 76580
//#define DEBUGGING  // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifndef DEBUGGING
#define debug(...)
#define DEBUG(...)
#else
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    debug(__VA_ARGS__);                \
    cerr << endl;                      \
  } while (0)
#endif

// auto mod int

const i64 MOD = 998244353;

struct mint {
  long long x;
  mint(long long 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 { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long 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 { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  vector<vector<mint>> dp(C + 1, vector<mint>(D + 1, 0));
  dp[A][B] = 1;
  for (int c = B + 1; c <= D; ++c) {
    dp[A][c] = dp[A][c - 1] * A;
  }
  for (int r = A + 1; r <= C; ++r) {
    dp[r][B] = dp[r - 1][B] * B;
  }
  REP(i, C - A) {
    int r = A + 1 + i;
    mint mr = r - 1;
    REP(j, D - B) {
      int c = B + 1 + j;
      mint mc = c - 1;
      dp[r][c] =
          (dp[r - 1][c] * c + dp[r][c - 1] * r - dp[r - 1][c - 1] * (mr * mc));
    }
  }

  cout << dp[C][D] << endl;
}


Measured memory_bytes: 73648
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

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


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

    int x; cin >> x;
    cout << !x << endl;

    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;




int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin>>s;
    
    int n=s.size();
    vector<int> vi(26,1000);
    for(char c:s){
        vector<int> dist(s.size());
        for(int i=0; i<n; i++){
            dist[i]=n-i;
        }
        for(int i=0; i<n; i++){
            for(int j=i; j<n; j++){
                if(s[j]==c){
                    dist[i]=min(j-i,dist[i]);
                }
            }
        }
        vi[c-'a']=*max_element(dist.begin(),dist.end());
    }
    cout<<*min_element(vi.begin(),vi.end());
    
    
    
    
    return 0;
}

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

class Program
{
    static readonly long INF = 100100100100;
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
        long res = 1;
        if (a.Min() == 0)
        {
            Console.WriteLine(0);
            return;
        }
        foreach (long i in a)
        {
            if (1000000000000000000 / res < i)
            {
                Console.WriteLine(-1);
                return;
            }
            res *= i;
        }
        Console.WriteLine(res);
    }
}


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

int main()
{
  int h , a;
  cin >> h >> a;
  int m[a];

  for(int i = 0 ; i < a; i++)
  {
    cin >> m[i];
  }

  sort(m , m+a);
  bool flag = false;


  for(int i = a-1 ; i > -1 ; i--)
  {
    h = h - m[i];
    //cout << h << " ";
    if(h < 1)
    {
      flag = true;
      break;
    }
  }
  if(flag == true)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}


Measured memory_bytes: 640