akhauriyash/Code-Regression huggingface dataset:
#include<cmath>
#include<cstdio>

int main(void){
	double x1, y1, x2, y2;
	scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
	printf("%f\n", sqrt(pow(x1-x2, 2)+pow(y1-y2, 2)));
	return(0);
}


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll N,A;
  cin>>N>>A;
  string s = "Yes";
  N=N%500;
  if(N>A) s="No";

  cout<<s<<endl;
}


Measured memory_bytes: 256
<?php
  $n = trim(fgets(STDIN));
  $s = trim(fgets(STDIN));
  for($i=0; $i<$n; $i++){
      $cnt[$s[$i]][] = $i+1;
  }
//   print_r($cnt);
  $r = $cnt["R"];
  $g = $cnt["G"];
  $b = $cnt["B"];
  $lenr = count($r);
  $leng = count($g);
  $lenb = count($b);
  $ans = $lenr*$leng*$lenb;
  
  for($i=0; $i<$n; $i++){
      for($j=$i; $j<$n; $j++){
          $k = $j+$j-$i;
        //   echo $cal."\n";
          if(isset($s[$k]) && $s[$i] != $s[$j] && $s[$i] != $s[$k] && $s[$j] != $s[$k] ){
              $ans--;
          }
      }
  }
  echo $ans;

Measured memory_bytes: 16204
n=int(input())
D=[int(i) for i in input().split()]
mod=998244353
import collections
DD=collections.Counter(D)
d=max(D)
ans=1
if D[0]!=0:
  print(0)
else:
  if DD[0]>1:
    ans=0
  else:
    for i in range(1,d+1):
      if DD[i]==0:
        ans=0
      else:
        ans=(ans*(DD[i-1]**DD[i]))%mod
  print(ans)



Measured memory_bytes: 18976
<?php
    
    list($N,$M,$X) = array_map('intval',explode(" ",trim(fgets(STDIN))));
    
    for($i=0;$i<$N;$i++){
        $array[$i] = array_map('intval',explode(" ",trim(fgets(STDIN))));
        $book_fee[$i] =  array_shift($array[$i]);
    }
    // var_dump($book_fee);
    // var_dump($array);
    
    $min_sum=INF;
    //全ての本について買う場合買わない場合があるので2のN乗ループで間に合う
    //全ビット探査する
    for($bit=0;$bit<(1<<$N);$bit++){
        //理解度達成フラグ
        $flg=0;
        $fee_sum = 0;
        $unst_sum = array_fill(0,$M,0);
        for($k=0;$k<$N;$k++){
            //あるビットパターンについてビットが立っているとき
            if($bit & (1<<$k)){
                $fee_sum += $book_fee[$k];
                for($n=0;$n<$M;$n++){
                    $unst_sum[$n] += $array[$k][$n];
                }
                
            }
        }
        //調査が終わった時点で理解度の合計がすべて達成しているか
        foreach($unst_sum as $value){
            if($value < $X){
                //理解度が足りてないときに立つフラグ
                $flg = 1;
            }
        }
        //理解度達成していれば金額を比較して小さいものを残していく
        if($flg==0){
            if($min_sum > $fee_sum){
                $min_sum = $fee_sum;
                // $comb    = $bit;
            }
        }
    }
    if($min_sum == INF){
        echo "-1\n";
    }else{
        echo $min_sum;
    }

?>

Measured memory_bytes: 16196
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll L;
ll A[200010];
ll dp[200010][10];

ll cost( ll i, ll k ) {
  if( !k || k == 4 ) {
    return A[i];
  }
  else if( k == 1 || k == 3 ) {
    if( A[i] > 0 && A[i] % 2 == 0 )
      return 0;
    else if( A[i] > 0 )
      return 1;
    else
      return 2;
  } else {
    if( A[i] % 2 == 1 )
      return 0;
    else
      return 1;
  }
}

int main() {
  std::cin >> L;

  rep( i, L )
    std::cin >> A[i];

  rep( i, L+1 ) rep( j, 5 )
    dp[i][j] = INF;

  dp[0][0] = 0;

  rep( i, L ) rep( j, 5 ) repi( k, j, 5 ) {
    chmin( dp[i+1][k], dp[i][j]+cost( i, k ) );
  }

  ll ans = INF;

  rep( j, 5 )
    chmin( ans, dp[L][j] );

  std::cout << ans << endl;

  return 0;
}

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

using namespace std;

typedef long long int lli;

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

    int n, h[100000], dp[100001] = { 0 };

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

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

    return 0;
}


Measured memory_bytes: 1024
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	x := getNextInt(scanner)
	y := getNextInt(scanner)

	fmt.Fprintln(writer, gcd(x, y))
	writer.Flush()
}

func gcd(m, n int) int {
	if n == 0 {
		return m
	}
	return gcd(n, m%n)
}



Measured memory_bytes: 1136
from collections import Counter

H, W = map(int, input().split())
four, two, any = 0, 0, 0
if H % 2:
    if W % 2:
        two = H // 2 + W // 2
        any = 1
    else:
        two = W // 2
else:
    if W % 2:
        two = H // 2
four = (H * W - two * 2 - any) // 4
s = ''
for _ in range(H):
    s += str(input())
c = Counter(s)
d = {'four': 0, 'two': 0}
for v in c.values():
    d['four'] += v // 4
    v -= 4 * (v // 4)
    d['two'] += v // 2
if d['four'] >= four:
    d['two'] += (d['four'] - four) * 2
    if d['two'] == two:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 3444
def sarch(n, S, T, i):
    if S[n - i:] == T[0:i]:
        i
    else:
        i = sarch(n, S, T, i - 1)
    return i

N = int(input())
s = input()
t = input()
print(N * 2 - sarch(N, s, t, N))


Measured memory_bytes: 3060
x,n = map(int,input().split())
p_L = list(map(int,input().split()))
p_L = set(p_L)
sa = 101
for i in range(0,200):
    if i not in p_L:
        if sa > min(sa,abs(i-x)):
            sa = abs(x-i)
            ans = i

print(ans)

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

int main(){
  int N,Q;
  cin >> N >> Q;

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

  vector<int> cumsumL(N+1);
  vector<int> cumsumR(N+1);
  for(int i=1; i <= N; i++){
    cumsumL.at(i)= cumsumL.at(i-1)+ data.at(i-1);
    cumsumR.at(i)= cumsumR.at(i-1)+ data.at(N-i);
  }

  int QpopMAX= min(N, Q);
  int ans= 0;
  for(int Qpop=0; Qpop <= QpopMAX; Qpop++){
    for(int QpopL=0; QpopL <= Qpop; QpopL++){
      int QpopR= Qpop- QpopL;
      priority_queue<int, vector<int>, greater<int>> items;
      for(int i=0; i<QpopL; i++){
        items.push(data.at(i));
      }
      for(int i=1; i<=QpopR; i++){
        items.push(data.at(N-i));
      }

      int cand= cumsumL.at(QpopL)+ cumsumR.at(QpopR);
      ans= max(ans, cand);

      int Qpush= min(Q- Qpop, Qpop);
      for(int q=0; q<Qpush; q++){
        int cut_cand= items.top();
        if(cut_cand < 0){
          items.pop();
          cand-= cut_cand;
          ans= max(ans, cand);
        }
        else{
          break;
        }
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3588
#include <stdio.h>
#define MAX 100005
#define NIL -1

typedef struct
{
  int parent, left, right;
} Node;

Node Tree[MAX];
int n, Depth[MAX];

int getDepth(int);
void print(int);

int child[MAX];

int main(void)
{
  int i, j;
  int degree, vertex;

  scanf("%d", &n);

  for (i = 0; i < n; i++)
  {
    Tree[i].parent = NIL;
    Tree[i].left = NIL;
    Tree[i].right = NIL;
  }

  for (i = 0; i < n; i++)
  {
    scanf("%d %d", &vertex, &degree);
    for (j = 0; j < degree; j++)
    {
      scanf("%d", &child[j]);

      Tree[child[j]].parent = vertex;

      //rightを決める基準となる。
      if (j == 0)
        Tree[vertex].left = child[0];

      else
        Tree[child[j - 1]].right = child[j];
    }
  }

  for (i = 0; i < n; i++)
    Depth[i] = getDepth(i);

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

  return 0;
}

int getDepth(int u)
{
  int d = 0;

  while (Tree[u].parent >= 0)
  {
    u = Tree[u].parent;
    d++;
  }

  return d;
}

void print(int u)
{

  int i, cnt = 0;

  printf("node %d: parent = %d, depth = %d, ", u, Tree[u].parent, Depth[u]);

  if (Tree[u].parent == NIL)
    printf("root, [");

  else if (Tree[u].left == NIL)
    printf("leaf, [");

  else
    printf("internal node, [");

  u = Tree[u].left;
  while (u != NIL)
  {
    if (cnt == 0)
      printf("%d", u);

    else
      printf(", %d", u);

    u = Tree[u].right;
    cnt++;
  }

  printf("]\n");
}



Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <map>
#include <bitset>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;

const int kMaxN = 1e5 + 10;

int main(int argc, char const *argv[]) {
  int ans = 0;
  int n, m, p;
  vector<int> v(4);

  cin >> n;
  int i = 3;
  while (n) {
    v[i--] = n % 10;
    n /= 10;
  }

  for (int j = 0; j < 8; ++j) {
    vector<int> opt(3);
    int k = j;
    int l = 2;
    while (k) {
      opt[l--] = k % 2;
      k /= 2;
    }

    int sum = v[0];
    for (int m = 0; m < 3; ++m) {
      if (opt[m]) { sum += v[m + 1]; }
      else { sum -= v[m + 1]; }
    }

    if (sum == 7) {
      ostringstream ss("");
      for (int p = 0; p < 3; ++p) {
        ss << v[p];
        if (opt[p]) { ss << "+"; }
        else { ss << "-"; }
      }
      ss << v[3] << "=7";
      cout << ss.str() << endl;
      return 0;
    }
  }

  return 0;
}


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

int main()
{
	int t = 0;
	for (int x = 1; x <= 10000; x++)
	{
		cin >> t;
		if (t == 0)
		{
			break;
		}
		else
		{
			cout << "Case " << x << ": " << t << endl;
		}
	}
}


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

int main() {
  int N;
  cin >> N;
  int A[N];
  
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] % 2 == 1) {
      cout << 0 << endl;
      return 0;
    }
  }
  
  for (int max = 1; ; ++max) {
    for (int i = 0; i < N; ++i) {
      A[i] >>= 1;
      if (A[i] % 2 == 1) {
        cout << max << endl;
        return 0;
      }
    }
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,l;
  cin>>n>>l;
  string s[n];
  for(int i=0;i<n;i++)  cin>>s[i];
  int a[n][2];
  memset(a,0,sizeof(a));
  for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
          if(s[i]>s[j]){
              string temp=s[i];
              s[i]=s[j];
              s[j]=temp;
          }
      }
  }
  string ans;
  for(int i=0;i<n;i++){
      ans+=s[i];
  }
  cout<<ans<<"\n";
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    int n; cin >> n;

    if(n%2) {
        cout << (n-1)/2*n << endl;
    } else {
        cout << n/2*(n-1) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
flag = false
cnt = 0
n.times do
  d1, d2 = gets.split.map(&:to_i)
  if d1 == d2
    cnt += 1
  else
    cnt = 0
  end
  if cnt >= 3
    flag = true
    break
  end

end
puts flag ? "Yes" : "No"

Measured memory_bytes: 14256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;


int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long X, A, B;
	cin >> X;
	cin >> A;
	cin >> B;

	long long d;
	d = (X -A) / B;
	long long ans = X - A - (B * d);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3768
import sys

N, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().rsplit()))
mod = 10 ** 9 + 7

cnt = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            cnt += 1
res = (K * cnt) % mod
cnt2 = 0
for i in range(N):
    for j in range(i):
        if A[i] > A[j]:
            cnt2 += 1
    for j in range(i + 1, N):
        if A[i] > A[j]:
            cnt2 += 1
res += (cnt2 * ((K * (K - 1)) // 2)) % mod
print(res % mod)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
	string s;
	int n;
	cin>>n;
	cin>>s;
	int ls = s.length();
	if(ls%2 == 1){
		cout<<"No\n";return 0;
	}
	string a,b;
	for(int i = 0;i<ls/2;i++) a+=s[i];
	for(int i = ls/2;i<ls;i++) b+=s[i];
	if(a == b) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  set<string> st{};
  string s;
  for(int i =0 ;i<n;++i){
    cin >> s;
    st.insert(s);
  }
  cout << st.size()<< endl;
}


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

int GetDigit(int num){
    int digit = 0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main(){
    int N;
    cin >> N;
    int count=0;
    for(int i=1; i<=N; i++){
        if(GetDigit(i)%2 ==1){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>
int main()
{
    int a,b,c,x,i,j,k,s=0;
    scanf("%d\n%d\n%d\n%d",&a,&b,&c,&x);
    for(i=0;i<=a;i++)
        for(j=0;j<=b;j++)
        for(k=0;k<=c;k++)
    {

            if(i*500+j*100+k*50==x)s++;
    }
    printf("%d\n",s);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() 
{
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll q=x/d;
    ll ans=0;
    if(k<=q){
        ans=x-(k*d);
    }else{
        k-=q;
        if(k%2==0){
            ans=x-(q*d);
        }else{
            ans=x-(q*d)-d;
        }
    }
    cout<<abs(ans)<<endl;
    
	return 0;
}


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

using namespace std;

#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,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)
#define ALL(x) (x).begin(),(x).end()

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

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int h,w;cin >> h >> w;
   vector<string> c(h);
   for(int i=0;i<h;i++){
      cin >> c[i];
      rep(j,2)cout << c[i] << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 8
#define NOT_FREE 1
#define FREE 0

int putQueen(int);
int  Board[N][N] = {};
int row[N] = {}, col[N] = {}, dpos[2*N-1] = {}, dneg[2*N-1] = {};
int main()
{
  int i, j;
  int k, r, c;
  
  scanf("%d", &k); // number of Queen
  for(i = 0; i < k; i++)
    {
      scanf("%d %d", &r, &c); // Queen row and Queen col
      Board[r][c] = row[r] = col[c] = dpos[r+c] = dneg[r-c+N-1] = NOT_FREE;
    }
  
  putQueen( 0 );
  return 0;
}
int putQueen(int i)
{
  int j, k, l;
  if(i == N)
    {
      for(k = 0; k < N; k++)
	{
	  for(l = 0; l < N; l++)
	    {
	      if(Board[k][l] == FREE) printf(".");
	      else printf("Q");
	    }
	  printf("\n");
	}
      return;
    }
  if(row[i] == NOT_FREE) putQueen(i+1);
  else
    {
      for(j = 0; j < N; j++)
	{
	  if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE) continue;
	  col[j] = dpos[i+j] = dneg[i-j+N-1] = Board[i][j] = NOT_FREE;
	  putQueen(i+1);
	  col[j] = dpos[i+j] = dneg[i-j+N-1] = Board[i][j] = FREE;
	}
    }
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a > 0 && b > 0) {
		cout << "Positive" << endl;
		return 0;
	}
	else if (a <= 0 && b >= 0) {
		cout << "Zero" << endl;
		return 0;
	}
	else if ((b - a) % 2 == 0) {
		cout << "Negative" << endl;
		return 0;
	}
	cout << "Positive" << endl;
	return 0;
}

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


#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;
typedef vector<vector<int>> Graph;

struct Edge {
    int from;
    int to;
    ll cost;
};

// https://qiita.com/ta-ka/items/a023a11efe17ab097433
ll dijkstra(int start, int end, int vertex_count, vector<vector<Edge>> &edges) {
    vector<ll> distances(vertex_count, INF);
    distances[start] = 0;  // 始点sへの最短距離は0

    priority_queue<P, vector<P>, greater<P>> que;  // 距離が小さい順に取り出せるようgreater<P>を指定
    que.push(P(0, start));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;  // 更新した頂点の中で距離が最小の頂点v
        if (distances[v] < p.first) {
            continue;
        }
        for (auto e : edges[v]) {  // 頂点vから出る辺eを走査
            if (distances[e.to] > distances[v] + e.cost) {
                distances[e.to] = distances[v] + e.cost;
                que.push(P(distances[e.to], e.to));
            }
        }
    }
    return distances[end];
}

int main() {

    int n;
    cin >> n;
    vector<Edge> distance;

    rep(a, n)
        rep(b, n) {
            ll d;
            cin >> d;
            if (b >= a)continue;
            distance.push_back({a, b, d});
        }

    sort(distance.begin(), distance.end(), [&](Edge e, Edge f) {
        return e.cost < f.cost;
    });

    vector<vector<Edge>> edges(n);

    for (Edge e : distance) {
        ll length = dijkstra(e.from, e.to, n, edges);
        if (length > e.cost) {
            edges[e.from].push_back({e.from, e.to, e.cost});
            edges[e.to].push_back({e.to, e.from, e.cost,});
        } else if (length == e.cost) {

        } else {
            cout << -1 << endl;
            return 0;
        }
    }


    ll ans = 0;
    for (auto es : edges) {
        for (auto e : es) {
            ans += e.cost;
        }
    }

    cout << (ans / 2) << endl;

}

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

int main(){
    ll r, g, b, n; cin >> r >> g >> b >> n;

    ll ans = 0;
    for(int i = 0; i <= n / r; i++){
        for(int j = 0; j <= n / g; j++){
            if((n - (i * r + j * g)) % b == 0 and (n - (i * r + j * g)) >= 0){
                ans++;
                //cout << "i:" << i  << "j:" << j  << endl;
            }
        }
    }
    put(ans);
}

Measured memory_bytes: 3572
#include<iostream>
#include<vector>

using namespace std;

int maxX_Y(int N,vector<int> &V,vector<int> &C){
    int max = 0;
    for (int i = 0; i < N; i++){
        if(V[i]>C[i])
        max += V[i] - C[i];
    }
    return max;    
}

int main(){
    int N;
    cin >> N;
    vector<int> V(N , 0);
    vector<int> C(N , 0);
    
    for (int i = 0; i < N; i++){
        cin >> V[i];
    }
    for (int i = 0; i < N; i++){
        cin >> C[i];
    }
    cout << maxX_Y(N,V,C) << endl;
    return 0;
     
}

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

using namespace std;

int main() {
    while(true) {
        int n;
        cin >> n;
        if(!n) break;
        vector<int> cards(2*n+1, 1);
        vector<int> rem(2, n);
        for(int i = 0; i < n; ++i) {
            int c;
            cin >> c;
            cards[c] = 0;
        }

        int field = 0;
        int turn = 0;
        while(true) {
            bool played = false;
            for(int i = field+1; i <= 2*n; ++i) {
                if(cards[i] == turn) {
                    if(--rem[turn] == 0) goto end;
                    cards[i] = -1;
                    turn = 1-turn;
                    field = i;
                    played = true;
                    break;
                }
            }
            if(!played) {
                field = 0;
                turn = 1-turn;
            }
        }
end:
        cout << rem[1] << endl;
        cout << rem[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**9)
INF = 10**18


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int,input().split())
    S = input()
    print(S[:K-1]+S[K-1].lower()+S[K:])


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
from collections import deque
n = int(input())
edge = []
for i in range(n+1):
    edge.append([])
for i in range(n-1):
    u,v,w = map(int,input().split())
    edge[u].append([v,w])
    edge[v].append([u,w])
ans = [0] * (n+1)


def breadth_first_search(edge):
    work_q = deque([1])
    visited = set()
    visited.add(1)
    while work_q:
        here = work_q.popleft()
        col = ans[here]
        for i in edge[here]:
            if i[0] not in visited:
                work_q.append(i[0])
                visited.add(i[0])
                if i[1] % 2 == 0 and col == 0:
                    ans[i[0]] = 0
                elif i[1] % 2 != 0 and col == 0:
                    ans[i[0]] = 1
                elif i[1] % 2 == 0 and col == 1:
                    ans[i[0]] = 1
                elif i[1] % 2 != 0 and col == 1:
                    ans[i[0]] = 0


breadth_first_search(edge)
for i in range(1,n+1):
    print(ans[i])



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

using namespace std;

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vpll;


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];
    int cnt = 0;
    forn(i, n) {
        if (i % 2 == 0 && a[i] & 1) cnt++;
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3596
import math
N, M = map(int,input().split())

res = 0
if N == M:
	res = (2 * math.factorial(N) * math.factorial(M)) % (10**9 + 7)
elif N == M - 1 or N == M + 1:
	res = (math.factorial(N) * math.factorial(M)) % (10**9 + 7)
else:
	res = 0

print(res)

Measured memory_bytes: 5184
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    int n; cin >> n;

    vector<vector<pair<int, int>>> node;

    for(int i=0; i<n+1; i++){
        vector<pair<int, int>> vemp;
        node.push_back(vemp);
    }


    for(int i=1; i<n; i++){
        int u, v, w;
        cin >> u >> v >> w;
        // cout << u << " " << v << " " << w << endl;
        node[u].push_back(make_pair(v, w));
        node[v].push_back(make_pair(u, w));
    }

    int chk[n+1] = {};
    for(int i=1; i<n; i++){
        for(int j=0; j<node[i].size(); j++){
            chk[node[i][j].first]++;
        }
    }

    int st = 0;
    for(int i=1; i<n; i++){
        if(chk[i] == 1){
            st = i;
        }
    }

    // cout << st << endl;

    stack<int> stk;
    stk.push(st);
    int c[n+1];
    fill(c, c+n+1, -1);
    c[st] = 1;

    while(!stk.empty()){
        int u = stk.top();

        if(node[u].size() == 0){
            stk.pop();
            continue;
        }
        else{
            int v = node[u][0].first;
            int w = node[u][0].second;
            
            if(c[v] == -1){
                // cout << u << " " << v << " " << w << endl;
                
                if(w%2 == 0){
                    c[v] = c[u];
                }
                else{
                    c[v] = 1 - c[u];
                }
            }
            node[u].erase(node[u].begin());
            stk.push(v);
        }
    }

    for(int i=1; i<=n; i++){
        cout << c[i] << endl;
    }



    return 0;
}

Measured memory_bytes: 7792
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

bool isKaibun(string S) {
    for (int i = 0; i <= S.length() / 2; i++) {
        if (S.substr(i, 1) != S.substr(S.length()-1 - i, 1))   return false;
    }
    return true;
}


int main()
{
    string s;

    cin >> s;
    if (isKaibun(s) == true) {
        if (isKaibun(s.substr(0, s.length() / 2))) {
            if (isKaibun(s.substr((s.length()+2) / 2, s.length() / 2))) {
                cout << "Yes";
            } else {
                cout << "No";
            }
        } else {
            cout << "No";
        }
    } else {
        cout << "No";
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
char str[1010];
char ss[1010];
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",str);
    int num1=0,num2=0;
    int suml=0,sumr=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]==')')
        {
            if(num1==0)
                num2++;
            else
                num1--;
        }
        if(str[i]=='(')
        {
            if(num2)
            {
                suml+=num2;
                num2=0;
                num1=1;
            }
            else
            {
                num1++;
            }
        }
    }
    suml+=num2;
    for(int i=0;i<suml;i++)
        printf("(");
    printf("%s",str);
    if(num1)
    {
        for(int i=0;i<num1;i++)
            printf(")");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define reg register
char str[1000005];
int n,f[1000005][2]; 
int main () {
	scanf("%s", str), n = strlen(str);
	f[0][0] = 0, f[0][1] = 1;
	for (int i = 0; i < n; i++) {
		int d = str[i] - '0';
		f[i + 1][0] = min(f[i][0] + d, f[i][1] + 10 - d);
		f[i + 1][1] = f[i][1] + 9 - d;
		if (d < 9) f[i + 1][1] = min(f[i + 1][1], f[i][0] + d + 1);
	}
	printf("%d\n", f[n][0]);
	return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265359

int main() {
    string s;
    cin >> s;
    bool f = false;
    int ans = 0, count = 0;
    for(char c : s){
        if(c == 'R'){
            if(f) count++;
            else count = 1;
            f = true;
        }else{
            f = false;
            count = 0;
        }
        ans = max(ans, count);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
/* ~ CoderMehraJ ~ */
#include <bits/stdc++.h>
using namespace std;

#define show(x) cout << #x << " = " << x << '\n';

int diff(int a, int b){
    return max(a,b)-min(a,b);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b;
    cin>>a>>b;
    if(diff(a,b)<2) cout<<"Yay!\n";
    else cout<<":(\n";
	return 0;
}


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

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

    int n, count = 1;
    cin >> n;
    vector<string> s(n);
    rep(i, n)
    {
        cin >> s.at(i);
    }
    sort(s.begin(), s.end());
    rep(i, n - 1) if (s.at(i) != s.at(i + 1)) count++;
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 9440
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

a, b, k = input_a
cnt = 0
ar = []
100.times do |i|
  if a % (i + 1) == 0 && b % (i + 1) == 0
    ar.push(i + 1)
  end
end
puts ar[(-1 * k)]


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		int x3 = x2 + y1 - y2;
		int y3 = y2 + x2 - x1;
		int x4 = x3 + y2 - y3;
		int y4 = y3 + x3 - x2;
		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);

	}

}


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

int b(int n, int k, vector<int> p);

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for(int i=0;i<n;i++) {
    cin >> p[i];
  }
  cout << b(n, k, p);
}

int b(int n, int k, vector<int> p) {
  sort(p.begin(), p.end());
  int sum = 0;
  for(int i=0;i<k;i++) {
    sum += p[i];
  }
  return sum;
}

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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

class Sg {
public:
    int n;
    vector<ll> nodes;
    Sg(int _n) {
        n = 1;
        while (n < _n) n *= 2;
        nodes.resize(n*2-1, 0);
    }
    void add(int i, int x) {
        i += n-1;
        nodes[i] += x;
        while (i > 0) {
            i = (i-1)/2;
            nodes[i] = nodes[i*2+1] + nodes[i*2+2];
        }
    }
    ll sum(int l, int r) {
        return _sum(l, r, 0, 0, n);
    }
    ll _sum(int l, int r, int k, int tl, int tr) {
        if (l <= tl && tr <= r) return nodes[k];
        if (tr <= l || r <= tl) return 0;
        ll sl = _sum(l, r, k*2+1, tl, (tl+tr)/2);
        ll sr = _sum(l, r, k*2+2, (tl+tr)/2, tr);
        return sl + sr;
    }
};

// 中央値がk以下となる部分列を数える
ll f(vector<int> &a, int k) {
    int N = a.size();
    vector<int> t(N);
    for (int i=0; i<N; ++i) {
        t[i] = (a[i] <= k) ? 1 : -1;
    }

    vector<int> cu(N+1);
    cu[0] = 0;
    for (int i=0; i<N; ++i) {
        cu[i+1] = cu[i] + t[i];
    }
    Sg sg(N*2+1);
    ll ret = 0;
    for (int i=0; i<N+1; ++i) {
        ret += sg.sum(0, cu[i]+N);
        sg.add(cu[i]+N, 1);
    }
    return ret;
}

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

    ll N;
    cin >> N;
    vector<int> a(N);
    for (int i=0; i<N; ++i) cin >> a[i];

    ll p = (N*(N+1)/2)/2+1;
    int l = 0;
    int r = 1000000001;
    while (r - l > 1) {
        int mid = (l+r)/2;
        if (f(a, mid) >= p) r = mid;
        else l = mid;
    }
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 5508
import { readFileSync } from "fs";

const { cin, nCin, biCin } = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return { cin: cin, nCin: () => Number(cin()), biCin: () => BigInt(cin()) };
})();

const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);

type Color = "Black" | "White";

{
  const [H, W, K] = [nCin(), nCin(), nCin()];

  const cnt = (() => {
    const css: Color[][] = range(H).map(() =>
      cin()
        .split("")
        .map((c) => (c === "#" ? "Black" : "White") as Color)
    );

    const getBlackCnt = (picksH: [number, boolean][], picksW: [number, boolean][]): number =>
      picksH
        .filter(([, b]) => b)
        .map(([i]) =>
          picksW
            .filter(([, b]) => b)
            .map(([j]) => (css[i][j] === "Black" ? 1 : 0) as number)
            .reduce((acc, x) => acc + x, 0)
        )
        .reduce((acc, x) => acc + x, 0);

    const initialBlackCnt = getBlackCnt(
      range(H).map((i) => [i, true]),
      range(W).map((j) => [j, true])
    );

    const pickWFn = (n: number, picksH: [number, boolean][], picksW: [number, boolean][]): number =>
      n >= W
        ? (() => {
            const cntH = getBlackCnt(
              range(H).map((i) => [i, true]),
              picksW
            );
            const cntW = getBlackCnt(
              picksH,
              range(W).map((j) => [j, true])
            );
            const cntHW = getBlackCnt(picksH, picksW);

            return initialBlackCnt - (cntH + cntW - cntHW);
          })() === K
          ? 1
          : 0
        : pickWFn(n + 1, picksH, picksW) +
          pickWFn(
            n + 1,
            picksH,
            picksW.map(([j, b]) => (j === n ? [j, true] : [j, b]))
          );

    const pickHFn = (n: number, picksH: [number, boolean][]): number =>
      n >= H
        ? pickWFn(
            0,
            picksH,
            range(W).map((j) => [j, false] as [number, boolean])
          )
        : pickHFn(n + 1, picksH) +
          pickHFn(
            n + 1,
            picksH.map(([i, b]) => (i === n ? [i, true] : [i, b]))
          );

    return pickHFn(
      0,
      range(H).map((i) => [i, false] as [number, boolean])
    );
  })();

  console.log(cnt);
}


Measured memory_bytes: 37448
def main():
    from collections import deque
    n, m, *ab = map(int, open(0).read().split())
    r = range(n+1)
    l = [[] for _ in r]
    for i, j in zip(*[iter(ab)] * 2):
        l[i].append(j)
        l[j].append(i)

    ll = [0 for _ in r]
    vis = [False for _ in r]
    que = deque()
    que.append(1)
    vis[1] = True
    while que:
        now = que.popleft()
        nx = l[now]
        for i in nx:
            if vis[i]:
                continue
            vis[i] = True
            ll[i] = now
            que.append(i)
    if all(vis[1:]):
        print("Yes")
        s = "\n".join(map(str, ll[2:]))
        print(s)
    else:
        print("No")



if __name__ == '__main__':
    main()


Measured memory_bytes: 56528
/* 
	Author: ankrypt
*/

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

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define fi(a, b, c, d) for(int a = b; i < c; i += d)
#define fl(a, b, c, d) for(ll a = b; i < c; i += d)
#define quit exit(0)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
ll X;

int main() {
	scanf("%lld", &X);
	ll temp = X / 500;
	X -= 500 * (X / 500);
	ll temp2 = X / 5;
	ll ans = temp * 1000;
	ans += temp2 * 5;
	printf("%lld", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<climits>
#include<algorithm>
#include<vector>
#include<valarray>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iostream>
#include<iomanip>
using namespace std;


#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define DREP(i,n) for(int i=n;i>0;i--)
#define Rep(i,m,n) for(int i=m;i<n;i++)
#define ReP(i,m,n) for(int i=m;i<=n;i++)
#define scani(a) scanf("%d",&a)
#define scand(a) scanf("%lf",&a)
#define scans(s) scanf("%s",s)
#define readi(a) int a;scanf("%d",&a)
#define printi(a) printf("%d",a)
#define prints(s) printf("%s",s)
#define even(n) (((n)+1)%2)
#define odd(n) ((n)%2)
#define sg(x) ((x)?1:0)
#define LF printf("\n")
#define SPACE printf(" ")
#define pb push_back
#define mp make_pair
#define bs binary_search
#define all(a) (a).begin(),(a).end()
#define forall(itr,a) for(auto itr=(a).begin();itr!=(a).end();++itr)

typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<double,double> pdd;
typedef pair<int,int> pii;

const double pi = acos(-1.0);
double rad(double t){return t*pi/180.0;}
double deg(double d){return d*180.0/pi;}
template<typename T>T GCD(T x,T y){return y?GCD(y,x%y):x;}
template<typename T>T LCM(T x,T y){return x/GCD(x,y)*y;}
template<class T>ostream& operator<<(ostream& os,const set<T>& s){os<<"{";for(auto itr=s.begin();s.end() != itr;++itr){if(itr!=s.begin())os<<',';os<<*itr;}os<<"}";return os;}
template<class S,class T>ostream& operator<<(ostream& os,const pair<S,T>& p){os<<'('<<p.first<<','<<p.second<<')';return os;}
const int MOD = (int)pow(10,9) +7;


//begin global variable
//


//
//end   global variable

int main(){
  ios::sync_with_stdio(false);
  //begin main()
  //
  int N,K,ans = 1;
  cin >> N >> K;
  rep(i,N)
    if( i == 0 ) ans *= K;
    else         ans *= K-1;
  cout << ans << endl;
  //
  //end   main()
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}


int main() {
    int n;
    cin >> n;
    string ans = "No";
    for(int i = 1;i <= 9;i++){
        for(int j = 0;j <= 9;j++){
            if(i*j == n){
                ans = "Yes";
            }
        }
    }
    cout << ans << endl;
}





Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
inline int read(){
	int ret=0,p=1;
	char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') p=-1;ch=getchar();}
	while (ch>='0' && ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret*p;
}
int n;
char a[5000+3];
int s[100000+3];
void print(int l){
	int ans[10],m=0;
	while (l){
		ans[++m]=l%27;l/=27;
	}
	for (int i=m;i;i--){
		if (ans[i]!=0) printf("%c",ans[i]+'a'-1);
	}
	puts("");
}
int main(){
	scanf("%s",a);
	n=read();
	int t=0;
	int l=1;
	for (int j=1;j<=n;j++) l*=27;
	for (int i=0;i<strlen(a);i++){
		int p=0,q=l;
		for (int j=0;j<n;j++){
			if (i+j>=strlen(a)) break;
			p=p*27+a[i+j]-'a'+1;
			q/=27;
			s[++t]=p*q;
		}
	}
	sort(s+1,s+t+1);
	l=0;
	for (int i=1;i<=t;i++){
		if (s[i]!=s[i-1]) l++;
		if (l==n){l=i;break;}
	}
	print(s[l]);
	return 0;
}

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

using namespace std;

int main() {
    string s; cin >> s;
    int n = s.size();
    
    int ret = 0;
    for (int it = 0; it < 2; ++it) {
        int now = n;
        for (int i = 0; i < n; ++i) {
            if (s[i] == '1') {
                int v1 = min(i + 1, n - i);
                int v2 = i;
                int v3 = n - i - 1;
                int ans = max(v1, max(v2, v3));
                now = min(now, ans);
            }
            s[i] ^= ('1' ^ '0');
        }
        ret = max(ret, now);
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> p(51), b(51);

ll f(ll n, ll x) {
	if (x == 0) return 0;
	if (n == 0) return 1;
	if (x <= 1 + b[n-1])
		return f(n-1, x-1);
	else if (x == (2 + b[n-1]))
		return p[n-1] + 1;
	else if (x <= 2 + 2 * b[n-1])
		return p[n-1] + 1 + f(n-1, x-2-b[n-1]);
	return 2 * p[n-1] + 1;
}

int main() {
	ll n; cin >> n;
	ll x; cin >> x;
	p[0] = b[0] = 1;
	for (int i = 0; i < 50; i++) {
		b[i+1] = b[i] * 2 + 3;
		p[i+1] = p[i] * 2 + 1;
	}
	cout << f(n, x) << '\n';
	return 0;
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Xor,A[2],Ans;
inline void pre(){
    ll N,Tmp;
    cin>>N>>A[0]>>A[1];
    for(int i=3;i<=N;i++)
        cin>>Tmp,Xor^=Tmp;
}
inline bool alw(){
    if(A[0]+A[1]-Xor<0||(A[0]+A[1]-Xor&1))
        return 0;
    ll B[2]={ A[0]+A[1]-Xor>>1 , A[0]+A[1]-Xor>>1 };
    for(ll Bit=40;Bit>=0;Bit--)
        if( (Xor>>Bit)&1 ){
            if(B[0]+(1ll<<Bit)<=A[0])
                B[0]+=(1ll<<Bit);
            else B[1]+=(1ll<<Bit);
        }
    Ans=A[0]-B[0];
    return Ans>=0&&Ans<A[0]&&(B[0]^B[1]^Xor)==0&&B[0]+B[1]==A[0]+A[1];
}
int main(){
    pre();
    if( alw() )
        cout<<Ans;
    else cout<<-1;
    return 0;
}

Measured memory_bytes: 3504
n,m = map(int, raw_input().split())
s = [map(int, raw_input().split()) for _ in range(m)]
c = 0
s.sort()
cur = s[0]
for u,v in s[1:]:
	if cur == []:
		cur = [u,v]
	if cur[1] <= u:
		cur = [u,v]
		c += 1 
	else:
		cur[0] = max(u, cur[0])
	 	cur[1] = min(v, cur[1])
		if cur[1] - cur[0] == 0: 
			c +=1
			cur = []
print c + (1 if cur else 0)


"""
---- ------
     4    9
       ---
       5 6
       ------?
       5 

       5 ----- 10
"""

Measured memory_bytes: 90320
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

I = list(map(int, input().split()))
I.sort(reverse=True)
print(I[0] * 10 + sum(I[1:3]))

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

int main(){
	int n,d;
	cin>>n>>d;
	int a[n][d];
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < d; ++j){
			cin>>a[i][j];
		}
	}

	int ans=0;
	for (int i = 0; i < n-1; ++i){
		for (int j = i+1; j < n; ++j){
			int sum=0;
			for (int k = 0; k < d; ++k){
				sum+=pow(abs(a[i][k]-a[j][k]),2);
			}
			if((int)sqrt(sum)*(int)sqrt(sum)==sum)ans++;
		}
		
		
	}

	cout<<ans<<endl;

}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	string S; cin >> S;
	bool first = false;
	bool end = false; 
	if(S.substr(0,2) >= "01" and S.substr(0,2) <= "12") first = true;
	if(S.substr(2,2) >= "01" and S.substr(2,2) <= "12") end = true;
	
	if(first == true and end == false) cout << "MMYY" << endl;
	else if(first == false and end == true) cout << "YYMM" << endl;
	else if(first == false and end == false) cout << "NA" << endl;
	else cout << "AMBIGUOUS" << endl;


	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

typedef vector <string> VS;
typedef vector <VS> VVS;
typedef set <string> SS;
typedef map <string, int> MSI;

VS groups;
MSI G2I;
VVS members;

void cut( string& s ) {
    replace( s.begin(), s.end(), ':', ' ' );
    replace( s.begin(), s.end(), ',', ' ' );
    replace( s.begin(), s.end(), '.', ' ' );
}

VS convert( string& s ) {
    VS answer;
    istringstream is(s);
    string term;
    while ( is >> term ) {
        answer.push_back( term );
    }
    return answer;
}

bool isNotGroup( string s ) {
    return G2I.find(s) == G2I.end();
}

SS V;
SS E;
void solve( int g ) {
    for ( int i = 0; i < (int)members[g].size(); i++ ) {
        string member = members[g][i];
        if ( isNotGroup( member ) ) {
            E.insert( member );
        } else if ( V.find( member ) == V.end() ) {
            V.insert( member );
            solve( G2I[member] );
        }
    }
}

int main() {
    int n;
    while ( cin >> n && n ) {
        cin.clear();
        cin.ignore();

        G2I.clear();
        groups = VS(n);
        members = VVS(n);
        for ( int i = 0; i < n; i++ ) {
            string line;
            getline( cin, line );
            cut(line);
            VS terms = convert(line);

            groups[i] = terms[0];
            G2I[groups[i]] = i;
            for ( int j = 1; j < (int)terms.size(); j++ ) {
                members[i].push_back( terms[j] );
            }
        }

        V.clear();
        E.clear();
        solve( 0 );
        cout << E.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 1040
class FactMod:

    def __init__(self, n, mod):
        self.mod = mod
        self.f = [1] * (n + 1)
        for i in range(1, n + 1):
            self.f[i] = self.f[i - 1] * i % mod

        self.inv = [pow(self.f[-1], mod - 2, mod)]
        for i in reversed(range(1, n + 1)):
            self.inv.append(self.inv[-1] * i % mod)
        self.inv.reverse()

    def fact(self, n):
        """
        :return: n!
        """
        return self.f[n]

    def comb(self, n, r):
        """
        :return: nCr
        """
        return self.f[n] * self.inv[n - r] * self.inv[r] % self.mod


N, K = map(int, input().split())

mod = 10 ** 9 + 7

fc = FactMod(3000, mod)

for i in range(1, K + 1):
    if N - K + 1 < i:
        print(0)
        continue

    if i == 1 or i == K:
        print(fc.comb(N - K + 1, i) % mod)
    else:
        cnt = 0
        print(fc.comb(N - K + 1, i) * fc.comb(K - 1, i - 1) % mod)
        # for j in range(1,  K // 2 + 1):
        #     # print(j, N - K+ 1)
        #     if j == K // 2:
        #         cnt += fc.comb(N - K + 1, i) % mod
        #     else:
        #         cnt += (fc.comb(N - K + 1, i) * i) % mod
        # print(cnt % mod)


Measured memory_bytes: 3572
#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];
  }
  
  int num = 0;
  int num2 = 1e9;
  int num3 = 1;
  
  for(int i = 0;i < N;++i){
    while(true){
      num3 = num3 * 2;
      if(A[i] % num3 == 0){
        num++;
      }
      else{
        break;
      }
    }
    num2 = min(num,num2);
    num = 0;
    num3 = 1;
  }
  cout << num2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#define input std::cin

using vector = std::vector<int>;
using lint = long long int;
using string = std::string;

int main() {
  int n; input >> n;
  int max_sum = INT_MIN, min_sum = INT_MAX;
  int max_dif = INT_MIN, min_dif = INT_MAX;
  for (int i=0; i<n; i++) {
	int x,y; input >> x >> y;
	int sum = x + y;
	int dif = x - y;
	if (sum > max_sum)
	  max_sum = sum;
	if (sum < min_sum)
	  min_sum = sum;
	if (dif > max_dif)
	  max_dif = dif;
	if (dif < min_dif)
	  min_dif = dif;
  }
  std::cout << std::max(max_sum-min_sum, max_dif-min_dif) << std::endl;
}



Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main()
{
    int d, n;

    cin >> d >> n;

int x = 1;
for(int i = 0; i < d; ++i)
{
    x *= 100;
}

if(n == 100)
{
    ++n;
}

cout << x * n << endl;

}

Measured memory_bytes: 256