akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;


#define MAXN 100001

vector<int> g[MAXN];
int n, ans;

int dfs(int u, int p) {
  if (g[u].size()==1) return 1;
  int ret = 0;
  for (auto v : g[u]) {
    if (v==p) continue;
    ret += dfs(v, u);
  }
  if (g[u].size()==2 && ret) return 1;
  if (ret) {
    ans += ret-1;
  }
  return 0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n-1; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  if (n==2) {
    cout << 1 << endl;
    return 0;
  }
  for (int u = 0; u < n; ++u) {
    if (g[u].size()>1) {
      ans += dfs(u, -1);
      break;
    }
  }

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


Measured memory_bytes: 11904
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] costs = new int[n][n];
		int[] starts = new int[m];
		int[] ends = new int[m];
		int[] cArr = new int[m];
		for (int i = 0; i < n; i++) {
		    Arrays.fill(costs[i], Integer.MAX_VALUE / 10);
		    costs[i][i] = 0;
		}
		for (int i = 0; i < m; i++) {
		    starts[i] = sc.nextInt() - 1;
		    ends[i] = sc.nextInt() - 1;
		    cArr[i] = sc.nextInt();
		    costs[starts[i]][ends[i]] = cArr[i];
		    costs[ends[i]][starts[i]] = cArr[i];
		}
		for (int i = 0; i < n; i++) {
		    for (int j = 0; j < n; j++) {
		        for (int k = 0; k < n; k++) {
		            costs[j][k] = Math.min(costs[j][k], costs[j][i] + costs[i][k]);
		        }
		    }
		}
		int count = 0;
		for (int i = 0; i < m; i++) {
		    if (costs[starts[i]][ends[i]] != cArr[i]) {
		        count++;
		    }
		}
		System.out.println(count);
   }
}




Measured memory_bytes: 25708
t = []
H = 0
W = 0

def is_bomb(h, w):
    if 0 <= h and h < H and 0 <= w and w < W:
        if t[h][w] == '#':
            return 1

    return 0


def count_bomb(h, w):
    global t

    num = 0
    if is_bomb(h - 1, w - 1):
        num += 1

    if is_bomb(h - 1, w):
        num += 1

    if is_bomb(h - 1, w + 1):
        num += 1

    if is_bomb(h, w + 1):
        num += 1

    if is_bomb(h + 1, w + 1):
        num += 1

    if is_bomb(h + 1, w):
        num += 1

    if is_bomb(h + 1, w - 1):
        num += 1

    if is_bomb(h, w - 1):
        num += 1

    t[h][w] = str(num)
        

def do_main():
    global H, W, t

    H, W = list(map(int, input().rstrip().split()))

    t = []

    for i in range(H):
        t.append(list(input().rstrip()))

    for h in range(H):
        for w in range(W):
           if t[h][w] != '#':
                count_bomb(h, w) 


    for h in range(H):
        print(''.join(t[h]))


do_main()


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <ios>

using namespace std;

vector<int> match_KMP(const string & T, const string & P);
vector<int> preprocess_KMP(const string & P);


int main()
{
    ios::sync_with_stdio(false);
    string T;
    string P;
    cin >> T;
    cin >> P;
    auto result = match_KMP(T, P);
    for (auto pos : result) cout << pos << '\n';
    return 0;
}

vector<int> match_KMP(const string & T, const string & P){
    int n = T.size();
    int m = P.size();
    auto pi = preprocess_KMP(P);
    vector<int> result;
    int q = 0;
    for (int i = 0; i != n; ++i){
        while (q > 0 and T[i] != P[q]){
            q = pi[q];
        }
        if (T[i] == P[q]) ++q;
        if (q == m){
            result.push_back(i - m + 1);
            q = pi[q];
        }
    }
    return result;
}

vector<int> preprocess_KMP(const string & P){
    int m = P.size();
    vector<int> pi(m + 1, 0);
    int k = 0;
    for (int q = 1; q != m; ++q){
        while (k > 0 and P[q] != P[k]){
            k = pi[k];
        }
        if (P[q] == P[k]) ++k;
        pi[q + 1] = k;
    }
    for (int i = 1; i != m; ++i){
        if (pi[i] and P[pi[i]] == P[i]) pi[i] = pi[pi[i]];
    }
    return pi;
}

Measured memory_bytes: 9076
#include<stdio.h>
int main(){

  int n,m;//人数、料理の個数
  int i,l,h;
  int k[32];
  int a[32];
  int count[32]={};
  int x=0;
  scanf("%d",&n);
  scanf("%d",&m);

  for(i=0;i<n;i++){

    scanf("%d",&k[i]);
    for(l=0;l<k[i];l++){

        scanf("%d",&a[l]);


        for(h=0;h<=m;h++){

          if(a[l]==h){
            count[h]++; //
          }

        }



    }

  }


  for(i=0;i<=m;i++){

      if(count[i]==n){
        x++;
      }

  }


  printf("%d",x);

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int j = 0;
  for (int i; i < N; i++){
    string color;
    cin >> color;
    if (color == "Y")
      j++;
  }
  if (j > 0)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#define N_MAX 10000
using namespace std;

int N;
int M[N_MAX];

int del(int m[]) {
  int delNum = 0;
  int cnt[4];
  int bfr = -1;
  int pos[4];
  for(int i = 0; i < N; i++) {
    if(m[i] == 0) continue;
    if(m[i] != bfr) {
      cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
    }
    if(cnt[m[i]] < 4) pos[cnt[m[i]]] = i;
    cnt[m[i]]++;
    bfr = m[i];

    if(cnt[bfr] > 4) {
      m[i] = 0;
      delNum++;
    }
    if(cnt[bfr] == 4) {
      for(int j = 0; j < 4; j++) {
	m[pos[j]] = 0;
	delNum++;
      }
    }
  }
  return delNum;
}

int high(int m[]) {
  int h = 0;
  for(int i = N-1; i >= 0; i--) {
    if(m[i] != 0) h++;
  }
  return h;
}

void cp(int m[]) {
  for(int i = 0; i < N; i++) {
    m[i] = M[i];
  }
}

int solve() {
  int mini = N;
  int m[N_MAX];

  int qsize = 0;
  int qp[N_MAX];
  int qc[N_MAX];

  int cnt[4];
  int bfr = -1;
  int pos[4];
  for(int i = 0; i < N; i++) {
    if(M[i] != bfr) {
      cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
    }
    if(cnt[M[i]] < 3) pos[cnt[M[i]]] = i;
    cnt[M[i]]++;
    bfr = M[i];
    if(cnt[bfr] == 3) {
      if(pos[0]-1 >= 0) {
	qp[qsize] = pos[0]-1;
	qc[qsize] = bfr;
	qsize++;
      }
      if(pos[3]+1 < N) {
	qp[qsize] = pos[2]+1;
	qc[qsize] = bfr;
	qsize++;
      }
    }
  }

  for(int i = 0; i < qsize; i++) {
    cp(m);
    m[qp[i]] = qc[i];
    while(del(m));
    mini = min(mini, high(m));
  }
  return mini;
}

int main() {
  while( ( cin >> N ) && N ) {
    for(int i = 0; i < N; i++) {
      cin >> M[i];
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 956
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int LCM(int a, int b){
   return (a * b)/(GCD(a, b));
}

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

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

   vector<int> dp(n+10, INF);
   dp[0] = 0;

   for(int i = 0; i < n; i++){
      chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
      if(i > 1){
         chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
      }
   }

   cout << dp[n-1] << endl;



   return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
void sort(int data[],int n);
int main(void){
    
    int i,n,d[100],s=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&d[i]);
    }

    sort(d,n);

    for(i=0;i<n;i++){
        if(d[i]!=d[i+1]) s++;
    }

    printf("%d\n",s);
    
}
void sort(int data[],int n){
        
    int i,j,tmp;
        
    for(i=1;i<n;i++){
    for(j=n-1;j>=1;j--){
        if(data[j]>data[j-1]){
            tmp=data[j-1];
            data[j-1]=data[j];
            data[j]=tmp;
            }
        }
    }
    
}

Measured memory_bytes: 1684
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,a[100005],s[100005];
ll sum,turn;
bool flag=1;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
    n=read();
    for(int i=1;i<=n;++i) a[i]=read(),sum+=a[i];
    if(sum%(1ll*n*(n+1)/2)) return 0*puts("NO");
    turn=sum/(1ll*n*(n+1)/2);
    for(int i=1;i<=n;++i) s[i]=a[i%n+1]-a[i];
    for(int i=1;i<=n;++i) if(s[i]-turn>0||(-s[i]+turn)%n) flag=0;
    if(flag) puts("YES");
	else puts("NO");
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, C, X = map(int, readlines())
count = 0

for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            total = 500 * i + 100 * j + 50 * k
            if total == X:
                count += 1

print(count)


Measured memory_bytes: 2940
#include <deque>
#include <iostream>
#include <tuple>

using namespace std;

using ll = long long;

// (追加した文字, 構築された文字列)を返す
pair<ll, deque<ll>> rec(ll N) {
    ll n;
    deque<ll> ret;

    if (N == 1) {
        ret = {1};
        return make_pair(1, ret);
    }

    if (N % 2 == 1) {
        tie(n, ret) = rec(N / 2);
        ret.push_back(++n);
    } else {
        tie(n, ret) = rec(N - 1);
        ret.push_front(++n);
    }

    return make_pair(n, ret);
}

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

    deque<ll> ans = rec(N).second;

    cout << ans.size() * 2 << endl;

    // 前半は作った1~lenの順列
    for (ll n : ans) {
        cout << n << " ";
    }

    // 後半は1~lenの昇順列
    for (ll i = 1; i <= ans.size(); ++i) {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 384
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)

#const
dxdy=((1,0),(0,1))
# my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    x,y,z=(pin())
    print(z,x,y)
"""         
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じ,るの忘れてるだろ
"""
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1 2 3"""
        output = """3 1 2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """100 100 100"""
        output = """100 100 100"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """41 59 31"""
        output = """31 41 59"""
        self.assertIO(input, output)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 5576
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
map<int,int> mp;
void GG(){
	puts("No");
	exit(0);
}
map<int,int>::iterator g(int x){
	map<int,int>::iterator r=mp.begin();
	while(x--)r++;
	return r;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		mp[a]++;
	}
	if(mp.size()>3)GG();
	if(mp.size()==1){
		if(g(0)->first){
			GG();
		}
	}
	else if(mp.size()==2){
		if(n%3==0){
			if(!g(0)->first&&g(1)->second==2*g(0)->second){}
			else if(!g(1)->first&&g(0)->second==2*g(1)->second){}
			else GG();
		}
		else{
			GG();
		}
	}
	else{
		if(n%3!=0)GG();
		if(g(0)->first^g(1)->first^g(2)->first){
			GG();
		}
		if(g(0)->second==g(1)->second&&g(0)->second==g(2)->second){}
		else GG();
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;cin>>s;
    int n = s.size()+1;
    vector<int> a(n,0),b(n,0);
    for(int i=1; i<n; i++){
        if(s[i-1]=='<')a[i]=a[i-1]+1;
        //else a[i]=0;

        if(s[n-i-1]=='>')b[n-i-1]=b[n-i]+1;
        
    }
    ll ans = 0;
    rep(i,n)ans+=max(a[i],b[i]);
    cout<<ans<<endl;
    //rep(i,n)cout<<max(a[i],b[i]);
    return 0;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int N, K;

void minus1(vec &a, int &n){
    if(n == a.size()){
        if(a[n - 1] >= 2){
            a[n - 1]--;
        }else{
            n--;
        }
        return;
    }
    if(a[n - 1] >= 2){
        a[n - 1]--;
        FOR(i, n, a.size()){
            a[i] = K;
        }
        n = a.size();
    }else{
        n--;
    }
}

signed main(){

    cin >> K >> N;

    if((K & 1) == 0){
        cout << K / 2 << " ";
        REP(i, N - 1) cout << K << " ";
        return 0;
    }

    int n = N;
    vec ans(N, (K + 1) / 2);
    REP(i, N / 2){
        minus1(ans, n);
    }

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


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 4608
from fractions import gcd

N = int(input())
a_list = list(map(int, input().split()))

gcd_num = a_list[0]
for a in a_list[1:]:
    gcd_num = gcd(gcd_num, a)

b_list = []

for a in a_list:
    b_list.append(a // gcd_num)

first = False
b_list.sort(reverse=True)
gcd_b = b_list[0]
for i, b in enumerate(b_list[1:]):
    tmp = gcd(gcd_b, b)
    if tmp == 1:
        if not first:
            first = True
            if i == 0:
                gcd_b = max(gcd_b, b)
            gcd_b = gcd_b
        else:
            gcd_b = 1
            break
    else:
        gcd_b = tmp
first = False
gcd_b3 = b_list[1]
b_list.append(b_list[0])

for i, b in enumerate(b_list[1:]):
    tmp = gcd(gcd_b3, b)
    if tmp == 1:
        if not first:
            first = True
            gcd_b3 = gcd_b3
        else:
            gcd_b3 = 1
            break
    else:
        gcd_b3 = tmp

print(gcd_num * max(gcd_b, gcd_b3))


Measured memory_bytes: 16156
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;

int main(){
	int n,a,t;int s;
	int ans;
	double minn=0x3f3f3f;
	scanf("%d %d %d",&n,&t,&a);
	for(int i=1;i<=n;i++){
		scanf("%d",&s);
		double tt=t-s*0.006;
		if(abs(tt-a)<minn){
			minn=abs(tt-a);
			ans=i;
		}
//		printf("%d\n",minn);
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    a = N % 10
    if a in (2,4,5,7,9): print('hon')
    elif a in (0,1,6,8): print('pon')
    else: print('bon')

if __name__ == '__main__':
    main()

Measured memory_bytes: 68880
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) when x < y -> Node (y, doit l, r)
    | Node (y, l, r) -> Node (y, l, doit r)
  in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> (f x; doit l; doit r)
  in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> (doit l; f x; doit r)
  in
  doit t

let print t =
  let f e = print_string " "; print_int e in
  inorder f t;
  print_newline ();
  preorder f t;
  print_newline ()

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, _, _) when x = y -> true
    | Node (y, l, _) when x < y -> doit l
    | Node (_, _, r) -> doit r
  in
  doit t

let delete x t =
  let rec dudu = function
    | Nil -> exit 1
    | Node (x, Nil, _) -> x
    | Node (_, l, _) -> dudu l
  and wa = function
    | Nil -> exit 1
    | Node (_, Nil, r) -> r
    | Node (x, l, r) -> Node (x, wa l, r)
  and doit = function
    | Nil -> exit 1
    | Node (y, l, r) when x = y ->
        if l = Nil then r
        else if r = Nil then l
        else Node (dudu r, l, wa r)
    | Node (y, l, r) when x < y -> Node (y, doit l, r)
    | Node (y, l, r) -> Node (y, l, doit r)
  in
  doit t

let split str delim =
  let rec doit s acc =
    match
      try Some (String.rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s1 (s2 :: acc)
  in
  doit str []

let () =
  let m = read_int () in
  let rec read i t =
    if i < m then begin
      match split (read_line ()) ' ' with
      | ["insert"; n] -> read (i + 1) (insert (int_of_string n) t)
      | ["find"; n] -> (print_endline (if find (int_of_string n) t then "yes" else "no"); read (i + 1) t)
      | ["delete"; n] -> read (i + 1) (delete (int_of_string n) t)
      | _ -> (print t; read (i + 1) t)
    end
  in
  read 0 (create ())

Measured memory_bytes: 25144
#include <stdio.h>
#include <string.h>

int main(void) {
    char str[1001]={'\0'}, buf[10]={'\0'}, rep[1001]={'\0'};
    int a, b, q, i;

    scanf("%s\n%d", str, &q);
    while (q>0) {
        scanf("%s", buf);
        if (strcmp(buf, "replace")==0) {
            scanf("%d %d %s", &a, &b, rep);
            for (i=a;i<=b;i++) str[i]=rep[i-a];
        }
        if (strcmp(buf, "reverse")==0) {
            scanf("%d %d", &a, &b);
            for (i=a;i<=b;i++) rep[b-i]=str[i];
            for (i=a;i<=b;i++) str[i]=rep[i-a];
        }
        if (strcmp(buf, "print")==0) {
            scanf("%d %d", &a, &b);
            for (i=a;i<=b;i++) printf("%c", str[i]);
            printf("\n");
        }
        for (i=0;i<sizeof(buf);i++) buf[i]='\0';
        q--;
    }
    for (i=0;i<sizeof(str);i++) str[i]='\0', rep[i]='\0';

    return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int main()
{
	int A ,B;
	scanf("%d%d",&A ,&B);
	if(A<=13 && A>=1){
		if(B<=13 && B>=1){
			if(A>B && B!=1){
				printf("Alice\n");
			}
			else if(A>B && B==1){
				printf("Bob\n");
			}
			if(A<B && A!=1){
				printf("Bob\n");
			}
			else if(A<B && A==1){
				printf("Alice\n");
			}
			else if(A==B){
				printf("Draw\n");
			}
		
		}
		else{
			printf("Error\n");
	 		
		}
	}
	else{
			printf("Error\n");
		}
	return 0;
}

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

#define ll long long
#define eb emplace_back
#define nl '\n'
#define deb(x) cerr << #x" = " << x << nl
#define in() ( { int a ; scanf("%d", &a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;


int32_t main()
{
    int n = in();
    map<string , int > mp; int m = 0;
    while(n--){
        string s; cin >> s; mp[s]++; m =max(m , mp[s]);
    }
    for(auto x: mp) if(x.second == m) cout << x.first << nl;
    return 0;
}


Measured memory_bytes: 25216
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

#define POS(i,j) ((i)*w+(j))

void run(void){
  int h,w;
  scanf("%d%d",&h,&w);
  char *s=(char *)calloc(h*w+1,sizeof(char));
  int i;
  for(i=0;i<h;i++) scanf("%s",s+i*w);
  char *used=(char *)calloc(h*w,sizeof(char));
  int *stack=(int *)calloc(h*w,sizeof(int));
  int64 ans=0;
  for(i=0;i<h*w;i++){
    if(used[i]) continue;
    used[i]=1;
    int cnt[2]={0,0};
    cnt[s[i]=='#']++;
    int top=0;
    stack[top++]=i;
    while(top>0){
      const int p=stack[--top];
      const int x=p/w;
      const int y=p%w;
      const int d[4]={-1,0,1,0};
      for(int j=0;j<4;j++){
	int a=x+d[j];
	int b=y+d[j^1];
	if(0<=a && a<h && 0<=b && b<w && s[POS(x,y)]!=s[POS(a,b)] && !used[POS(a,b)]){
	  used[POS(a,b)]=1;
	  cnt[s[POS(a,b)]=='#']++;
	  stack[top++]=POS(a,b);
	}
      }
    }
    ans+=(int64)cnt[0]*cnt[1];
  }
  printf("%lld\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<n;++i)
#define Sort(a) sort(a.begin(),a.end())
const ll INF = 1e15+7;

int main(){
  ll N,sum=0;
  cin >> N;
  vi a(N);
  rep(i,N){
    cin >> a.at(i);
    sum += a.at(i);
  }
  ll dif = INF;
  ll num = 0,num2 = 0;
  rep(i,N-1){
    num += a.at(i);
    num2 = sum - num;
    dif = min(abs(num-num2),dif);
  }
  cout << dif << endl;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

char c[200010];

signed main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int cnt0=0,cnt1=0;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		if(c[i]=='W') cnt0++;
		if(c[i]=='R') cnt1++;
	}
	int ans=n,now0=0,now1=0;
	for(int i=0;i<=n;i++){
		int nxt0=cnt0-now0,nxt1=cnt1-now1;
		ans=min(ans,max(now0,nxt1));
		if(i<n){
			if(c[i+1]=='W') now0++;
			if(c[i+1]=='R') now1++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Vertex
{
    vector<int> node;
    int depth = 0;
    int par = 0;
};

Vertex V[100005];
int C[100005];

int main()
{
    int N;
    cin >> N;
    FOR(i, N, 1)
    {
        ll a;
        cin >> a;
        V[--a].node.push_back(i);
        V[i].par = a;
    }

    queue<int> q;
    REP(i, N)
    {
        if (V[i].node.size() == 0)
            q.push(i);
    }
    while (!q.empty())
    {
        int t = q.front();
        q.pop();
        sort(V[t].node.begin(), V[t].node.end(), [&](int a, int b) { return V[a].depth > V[b].depth; });
        ll maxDep = 0;
        REP(i, V[t].node.size())
        {
            int n = V[t].node[i];
            maxDep = std::max(maxDep, i + 1 + V[n].depth);
        }
        V[t].depth = maxDep;

        int par = V[t].par;
        if (++C[par] == V[par].node.size())
            q.push(par);
    }

    cout << V[0].depth << endl;
    return 0;
}

Measured memory_bytes: 6912
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;

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


int main()
{
	int n;
	int t[100009], x[100009], y[100009];
	cin >> n;
	t[0] = x[0] = y[0] = 0;
	rep(i, n) {
		cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
	}
	bool can = true;
	rep(i, n) {
		int dt = t[i + 1] - t[i];
		int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
		if (dt < dist) can = false;
		if (dist % 2 != dt % 2) can = false;
	}
	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define MN 1000000
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
bool D[MN+5];
char s[MN+5],S[MN+5],CH[3],ch[3];
int n,N,L[MN+5],R[MN+5],m,num[3],ls[MN+5];
inline int Get(int x)
{
    int res=0;
    for(int i=0;i<3;++i) if(num[i]<num[x]||(num[i]==num[x]&&i<x)) ++res;
    return res;
}
inline int Del(int l,int r,int flag=0)
{
    if(l>r) return 0;int len=r-l+1;
    if(l==r) return s[l]=='C'&&bool(flag);
    if(len&1) return s[l]=='C'?2:0;
    else return 1;
}
void Delete()
{
    int Num=num[2]-num[1];
    for(int i=1;i<=m;++i)
    {
        int now=Del(L[i],R[i],i==1||i==m);
        if(now==2) assert(s[L[i]]=='C'&&s[R[i]]=='C');
      //  cout<<i<<" "<<now<<" "<<num[1]<<" "<<num[2]<<endl;
        if(now==2&&Num>=2) {++L[i];--R[i];Num-=2;num[2]-=2;}
        else if(now&&Num)
        {
            if(now==2) {++L[i];--Num;num[2]-=1;}
            else {s[L[i]]=='C'?++L[i]:--R[i];Num-=1;num[2]-=1;}
        }
    }
}
void Print()
{
    for(int i=1;i<=m;++i)
    {
        for(int j=L[i];j<=R[i];++j) printf("%c",ch[s[j]-'A']);
        if(i!=m&&!D[i]) printf("%c",ch[0]);
    }
}
void Work()
{
    int last=m;
    for(int i=m-1;i;--i) if(!D[i]) {last=i;break;}
    for(int i=1,find=0;i<=m;++i)
    {
        while((R[i]-L[i]+1>=3||(R[i]-L[i]+1>=2&&(!find||i>last)))&&num[1]>num[0])
            L[i]+=2,--num[1];
        if(!D[i]) find=1;
    }
    Print();
}
inline bool Null(int x){return L[x]>R[x];}
int main()
{
    scanf("%s",S+1);N=strlen(S+1);
    for(int i=1;i<=N;++i) if(S[i]!=S[i-1]) ++num[S[i]-'A'];
    if(!num[0]||!num[1]||!num[2]) return 0*puts("");
    for(int i=0;i<3;++i) CH[i]=Get(i)+'A',ch[CH[i]-'A']=i+'A';
    num[0]=num[1]=num[2]=0;
    for(int i=1;i<=N;++i) if(S[i]!=S[i-1]) s[++n]=CH[S[i]-'A'],++num[s[n]-'A']; 
    for(int i=1,last=0;i<=n+1;++i) if(i>n||s[i]=='A')
        L[++m]=last+1,R[m]=i-1,last=i;
  //  cout<<num[0]<<" "<<num[1]<<" "<<num[2]<<endl;
    Delete();
  //  cout<<"Delete OK "<<num[1]<<" "<<num[2]<<endl;
    if(num[2]==num[1]) return Work(),0;
    for(int i=1;i<=m;++i) ls[i]=i;
  //  Print();cout<<"   ------- "<<endl;
    for(int i=1;i<m&&num[2]>num[1];++i)
    {
        int b=i+1,a=Null(i)?(ls[i]=ls[i-1]):i;
        if(Null(b)||!a) continue;
        if(s[R[a]]=='C'||s[L[b]]=='C')
        {
         //   cout<<"Delete"<<i<<" "<<a<<" "<<b<<endl;
            D[i]=1;--num[2];--num[0];
            if(s[R[a]]=='C') --R[a];
            else ++L[b];
        }
        if(Null(a)) ls[i]=ls[a-1];
    }
    Work();
    return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define ll  long long int
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    fast;
   
  
    ll a,b,c,x=0,y=0;
    cin>>a>>b>>c;

    if(a==5)
        x++;
    else if(a==7)
        y++;
    if(b==5)
        x++;
    else if(b==7)
        y++;
    if(c==5)
        x++;
    else if(c==7)
        y++;
    if(x==2&&y==1)
        cout<<"YES\n";
    else cout<<"NO\n";




}



Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
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; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, M;
        cin >> N >> M;
        vector<pair<ll, pair<ll, ll> > > data(M);
        rep(i, 0, M) {
                ll p, y;
                cin >> p >> y;
                data[i] = pair<ll, pll>(p, pll(y, i));
        }
        sort(all(data));
        vector<pair<ll, string> > ids;
        ll cnt = 0;
        ll nowpref = data[0].first;
        rep(i, 0, M) {
                ll pref = data[i].first;
                if (nowpref != pref) {
                        nowpref = pref;
                        cnt = 0;
                }
                ++cnt;
                //cout << pref << endl;
                //ll year = data[i].second.first;
                ll id = data[i].second.second;
                char str[20];
                sprintf(str, "%06lld%06lld", pref, cnt);

                string tmp(str);
                pair<ll, string> x(id, tmp);
                ids.push_back(x);
                //cout << cnt << endl;
        }
        sort(all(ids));
        rep(i, 0, len(ids)) {
                cout << ids[i].second << endl;
        }
}

Measured memory_bytes: 10096
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define st first
#define nd second
#define INF 1000000007LL
using namespace std;

int main(){
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll a;
  cin >> a;
  cout << a + a * a + a * a * a << '\n';  
}

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

struct v
{
    int i,j;
};

v a[5000];
int n;
long long dp[5000][5002];

bool comp(v x, v y)
{
    return((x.i+x.j)<(y.i+y.j));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int i,j,k,r=1;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i].i>>a[i].j;
    sort(a,a+n,comp);
    dp[0][1]=a[0].j;
    dp[0][2]=1e13;
    for(i=1;i<n;i++)
    {
        k=i+2;
        for(j=1;j<k;j++)
        {
            dp[i][j]=1e13;
            if(dp[i-1][j-1]<=a[i].i)
            {
                dp[i][j]=dp[i-1][j-1]+a[i].j;
                r=max(r,j);
            }
            dp[i][j]=min(dp[i][j],dp[i-1][j]);
        }
        dp[i][j]=1e13;
    }
    cout<<r;
    return 0;
}

Measured memory_bytes: 193920
#include <stdio.h>

int main(){

  int n,q,i,j,cnt=0;
  int s[10000],t[500];

  scanf("%d",&n);

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

  scanf("%d",&q);

  for(i=0;i<=q-1;i++){
    scanf("%d",&t[i]);
  }

  for(i=0;i<=q-1;i++){
    for(j=0;j<=n-1;j++){
      if(t[i]==s[j]){
	cnt++;
	break;
      }
    }
  }

  printf("%d\n",cnt);

  return 0;
}



Measured memory_bytes: 2108
#include "bits/stdc++.h"
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)

int main(){
    long long cnt=0;
    string s;
    cin>>s;
    if(s.size()<3){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<s.size()-2;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            int k=i;long long c=1;
            while(1){
                if(k==0||s[k-1]!='A')break;
                k--;c++;
            }
            cnt+=c;
            int p=i+3;
            while(p+1<s.size()){
                if(s[p]=='A'){
                    c++;
                    p++;
                }else if(s[p]=='B'&&s[p+1]=='C'){
                    cnt+=c;
                    p+=2;
                }else break;
            }
            i=p;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 640
lst = list(input())
lst1 = []
lst1.append(lst[0]+lst[1])
lst1.append(lst[2]+lst[3])

if (int(lst1[0]) >=13 and int(lst1[1]) >=13) or (int(lst1[0]) >=13 and lst1[1] =="00") or (lst1[0] =="00" and int(lst1[1]) >=13) or (lst1[0] =="00" and lst1[1] == "00"):
  print("NA")
  
elif (0<int(lst1[0])<=12 and 0<int(lst1[1])<=12):
      print("AMBIGUOUS")
      
elif 0<int(lst1[0]) <=12:
      print("MMYY")
elif 0<int(lst1[1])<=12:
      print("YYMM")

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

static const ll MOD = 1000000007;
ll N,M;

ll factorial(ll n,ll mod){
  ll ret = 1;
  for(ll i=1;i<=n;i++){
    ret = (ret*i)%mod;
  }
  return ret;
}

ll inv_mod(ll n,ll mod){
  ll a = n%mod,b = mod-2,ret=1;
  while(b>0){
    if(b&1) ret = (ret*a)%mod;
    a = (a*a)%mod;
    b >>= 1;
  }
  return ret;
}

ll nPr(ll n,ll r,ll mod){
  ll ret = 1;
  for(ll i=n;i>=n-r+1;i--){
    ret = ret * (i % mod) % mod;
  }
  return ret;
}

ll nCr(ll n,ll r,ll mod){
  return nPr(n,r,mod) * inv_mod( factorial(r,mod),mod ) % mod;
}

ll nHr(ll n,ll r,ll mod){
  return nCr(n+r-1,r,mod);
}

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

  ll x = 2;
  ll num = M;
  vector<ll> v;
  while(num >= x*x){
    if(num%x == 0){
      v.push_back(x);
      num /= x;
    }else{
      x++;
    }
  }
  if(num != 1) v.push_back(num);

  map<ll,ll> cnt;
  REP(i,v.size()){
    cnt[v[i]]++;
  }

  ll ans=1;
  for(auto itr:cnt){
    ans *= nHr(N,itr.second,MOD);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    a, b = [int(s) for s in input().split()]

    big = a if a > b else b
    small = b if a >= b else a
    sum = 0
    for i in range(0, 2):
        sum += big
        big -= 1
        if big <= small:
            big = small

    print(sum)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
int N, K;
int x[101];

int main(){

  std::cin >> N;
  std::cin >> K;
  for(int i = 0; i < N; i++) std::cin >> x[i];

  int ans=0;

  for(int i = 0; i < N; i++){

    int dis = (K - x[i]);
    if(dis<0) dis *= -1;

    ans += std::min(x[i], dis);

  }

  std::cout << ans*2 <<'\n';

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {
		OriginScanner os = new OriginScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int h = os.nextInt();
		int i = os.nextInt();
		
		for (int n = 0; n < i; n++) {
			int a = os.nextInt();
			h -= a;
		}
		String result = h < 1 ? "Yes" : "No";
		pw.println(result);
		pw.close();
	}
	
	static class OriginScanner {
		private BufferedReader br;
		private StringTokenizer st;
		
		public OriginScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String nextLine() {
			String str = null;
			try {
				str = br.readLine();
			}
			catch (IOException e) {
				System.out.println(e);
			}
			return str;
		}
		String next() {
			if (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(nextLine());
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 32732
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,j;
    cin>>n;
    vector<int> a(n);
    vector<vector<long long>> dp(n,vector<long long>(n,__LONG_LONG_MAX__));
    for(int i=0;i<n;i++)cin>>a[i];
    auto sum = [&](int i,int j){
        long long res = 0LL;
        for(int k=i;k<=j;k++){
            res+=a[k];
        }
        return res;
    };
    for(int i=n-1;i>=0;i--){
        for(int j=i;j<n;j++){
            if(i==j){
                dp[i][j]=0;
            }else{
                long long s = sum(i,j);
                for(int k=i;k<=j-1;k++){
                    dp[i][j] = min(dp[i][j],dp[i][k]+dp[k+1][j]+s);
                }

            }
        }
    }
    cout<<dp[0][n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<functional>
#include<utility>
using namespace std;

int n, rnk[101];//not use 0;
pair<int, int> point[101];

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) point[i].second = i;
	for (int i = 0; i < n * (n - 1) / 2; i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		if (c>d) point[a].first += 3;
		else if (c < d) point[b].first += 3;
		else point[a].first += 1, point[b].first += 1;
	}
	sort(point + 1, point + n + 1, greater<pair<int, int> >());
	int now, p = 100000;
	for (int i = 1; i <= n; i++){
		if (p != point[i].first) p = point[i].first, now = i;
		rnk[point[i].second] = now;
	}
	for (int i = 1; i <= n; i++) cout << rnk[i] << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
int main(){
int N,M;
  cin>>N>>M;
  Graph G(N);
  for(int i=0;i<M;i++){
  int x,y,z;
    cin>>x>>y>>z;
    x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }vector<int>color(N+1,0);
  int a=0;
  int ans=0;
  
  for(int i=1 ; ;i++){
  
    for(int j=a;j<=N;j++)
  if(color.at(j)==0){a=j; break;}
    if(a==N)break;
      ans=i;
    queue<int>que; que.push(a);
   color.at(a)=i;
    while(!que.empty()){
    int v=que.front();
      que.pop();
      for(auto u:G[v]){
      if(color.at(u)!=0)
        continue;
        else{
          color.at(u)=i;
          que.push(u);
        }
      }
    
    } 
    
  }cout<<ans<<endl;
  
   return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
#define str(n) to_string(n)
#define int(w) stoi(w)
#define len(l) l.size()
#define append(l,i) l.push_back(i)
vector< long long > divisor(long long n) {
  vector< long long > ret;
  for(long long i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main() {
    long long n;
    cin>>n;
    vector<long long> l=divisor(n);
    int ans=100000;
    rep(i,l.size()/2+1){
        long long a=l.at(i);
        long long b=n/l.at(i);
        int ans1=10000;
        ans1=str(max(a,b)).size();
        ans=min(ans,ans1);
    }
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;




int main(){
  vector <vector <int> > vvi;
  vvi = vector <vector <int> >(26, vector<int>());
  string s;
  cin >> s;
  int r = -1,l = -1;
  bool f = false;
  int pos[26];
  REP(i,26){
    pos[i] = -1;
  }
  REP(i,s.size()){
    if(pos[s[i]%26] == -1)
      pos[s[i]%26] = i;
  }
  REP(i,s.size()){
    if((i-pos[s[i]%26]+1)/2 < 2 && i != pos[s[i]%26]){
      f = true;
      r = pos[s[i]%26]+1;
      l = i+1;
    }
    if(f)
      break;
    pos[s[i]%26] = i;
  }
  /*
  REP(i,s.size()){
    vvi[s[i]%26].pb(i);
  }
  REP(i,26){
    char c = 'a'+i;
    
    //int r = -1,l = -1;
    
    REP(j,a.size()){
      cout << a[j] << " ";
    }
    cout << endl;
        
    REP(j,vvi[i].size()){
      for(int k = j+1;k < vvi[i].size();k++){
	if((vvi[i][k]-vvi[i][j]+1)/(k-j+1) < 2){
	  r = vvi[i][j]+1;
	  l = vvi[i][k]+1;
	  f = true;
	}
	if(f)
	  break;
      }
      if(f)
	break;
    }
    if(f)
      break;
  }  
*/
  cout << r << " " << l << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main(){
    long int n,k;
    cin >> n >> k;
    vector<double> p(n);
    F(i,0,n) cin >> p[i];

    F(i,0,n){
        p[i]=(p[i]+1)/2.0;
    }
    vector<double> sum(n+1,0);
    F(i,0,n){
        sum[i+1]=sum[i]+p[i];
    }
    double ans=0;
    F(i,0,n-k+1){
        if(ans<sum[i+k]-sum[i])
            ans=sum[i+k]-sum[i];
    }
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 3328
using System;
using static System.Console;
using System.Collections.Generic;

namespace abc167
{
    class Program
    {
        static int[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            if (line.Length == 1 && string.IsNullOrEmpty(line[0]))
            {
                return new int[0];
            }
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]) - 1;
            }
            return numList;
        }
        static void Main()
        {
            var nk = ReadLine().Split(' ');
            var n = int.Parse(nk[0]);
            var k = long.Parse(nk[1]);
            var aList = ReadNumList();
            var history = new int[n];
            var checker = new HashSet<int>();

            var pos = 0;
            history[0] = 0;
            checker.Add(0);
            var loopStart = 0;
            var loopSize = 0;
            var rest = k;
            for (var i = 1; i < n && i <= k; ++i)
            {
                pos = aList[pos];
                history[i] = pos;
                if (checker.Contains(pos))
                {
                    for (var p = 0; p < i; ++p)
                    {
                        if (history[p] == pos)
                        {
                            loopStart = p;
                            break;
                        }
                    }
                    loopSize = i - loopStart;
                    rest -= i;
                    break;
                }
                else
                {
                    checker.Add(pos);
                }
            }
            if (loopSize > 0)
            {
                WriteLine(history[loopStart + rest % loopSize] + 1);
            }
            else
            {
                WriteLine(history[k] + 1);
            }
        }
    }
}


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

int main()
{
	int n, m;
	cin >> n >> m;
	int in;
	for (int i = 0; i < m; ++i)
	{
		cin >> in;
		n -= in;
	}
	cout << (n>=0?n:-1) << endl;
	return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;


ll dp[3005][3005][5][2];

int main(){
  int R, C, K;
  cin >> R >> C >> K;
  vector<vector<int>> board(R, vector<int>(C, 0));
  REP(i, K){
    int r, c, v;
    cin >> r >> c >> v;
    r--, c--;
    board[r][c] = v;
  }
  REP(i, R){
    REP(j, C){
      REP(k, 4){
        REP(m, 2){
          dp[i+1][j][0][0] = max(dp[i+1][j][0][0], dp[i][j][k][m]);
          dp[i][j+1][k][0] = max(dp[i][j+1][k][0], dp[i][j][k][m]);
          if(m == 0){
            dp[i][j][k+1][1] = max(dp[i][j][k+1][1], dp[i][j][k][0] + board[i][j]);
          }
        }
      }
    }
  }
  ll ans = 0;
  REP(i, 4){
    REP(j, 2){
      ans = max(ans, dp[R-1][C-1][i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 742980
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    unsigned long long X,Y;
    cin >>X>>Y;
    unsigned long long count =1;
    for(;;){
        X*=2;
        if(X>Y){
            break;
        }
        else{
            count++;
        }
    }
    cout <<count<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    string S; cin >> S;
    bool ok = false;
    if (S[0] != S[1]) ok = true;
    if (S[1] != S[2]) ok = true;
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

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

using namespace std;

int main(){
	int coin[] = {1000, 500, 100};

	int a, b;
	while(cin >> a >> b, a|b){
		int r = b-a;
		int n[3];
		rep(i, 3){
			n[i] = r/coin[i];
			r %= coin[i];
		}
		rep(i, 3){
			cout << (i?" ":"") << n[2-i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
using namespace std;

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin,(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n,m;

int main(){
  cin >> n >> m; 
  vector<pair<ll, ll>> ab(n);
  rep(i,n)cin >> ab[i].first >> ab[i].second;
  VSORT(ab);
  
  ll ans = 0;
  int i=0;
  while(m-ab[i].second>0){
    ans+=ab[i].first*ab[i].second;
    m-=ab[i].second;
    i++;
  }
  ans +=ab[i].first*m;

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


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

using namespace std;

struct range {
    int type, left, right;

    range() {}
    range(int _type, int _left, int _right): type(_type), left(_left), right(_right) {}
};

range intersec(range x, range y) {
    if (x.type == 0 || y.type == 0) {
        return range(0, -1, -1);
    }
    if (x.type == 2) {
        return y;
    }
    if (y.type == 2) {
        return x;
    }
    if (x.left % 2 != y.left % 2) {
        return range(0, -1, -1);
    }
    range res(1, max(x.left, y.left), min(x.right, y.right));

    if (res.left > res.right) {
        return range(0, -1, -1);
    }
    return res;
}

void dfs(int u, int p, vector <vector <int> > &G, vector <int> &A, vector <range> &res) {
    res[u] = A[u] == -1 ? range(2, -1, -1) : range(1, A[u], A[u]);

    for (int to: G[u]) {
        if (to != p) {
            dfs(to, u, G, A, res);

            range now = res[to];

            if (now.type == 1) {
                now.left--;
                now.right++;
            }
            res[u] = intersec(res[u], now);
        }
    }
}

void dfs2(int u, int p, int num, vector <vector <int> > &G, vector <int> &A, vector <range> &res) {
    if (A[u] == -1) {
        A[u] = intersec(p == -1 ? range(2, -1, -1) : range(1, num - 1, num + 1), res[u]).left;
    }

    for (int to: G[u]) {
        if (to != p) {
            dfs2(to, u, A[u], G, A, res);
        }
    }
}

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

    int n;
    cin >> n;
    vector <vector <int> > G(n);
    vector <int> A(n, -1);

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int k;
    cin >> k;

    for (int i = 0; i < k; i++) {
        int v, p;
        cin >> v >> p;
        v--;
        A[v] = p;
    }
    vector <range> res(n);
    dfs(0, -1, G, A, res);

    if (res[0].type != 0) {
        dfs2(0, -1, -1, G, A, res);

        cout << "Yes\n";

        for (int x: A) {    
            cout << x << "\n";
        }
    } else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 18944