akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int) 1e9 : (int) 1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> void cmin(T &a, const S &b) {
    if (a > b) a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
    if (a < b) a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
    return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
    auto inner = vectors(tail...);
    return vector<decltype(inner)>(x, inner);
}
template <class T> void join(T a) {
    for (auto itr : a) {
        if (itr != *a.begin()) cout << " ";
        cout << itr;
    }
}
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
auto out(int a, int b) {
    (a > b ? a += 1 : b += 1);
    cout << a << " " << b << endl;
}
main() {
    string s;
    while (cin >> s, s != "0") {
        int a = 0, b = 0;
        rep(i, (int) s.size()) {
            if (i == 0) continue;
            (s[i] == 'A' ? a += 1 : b += 1);
        }
        out(a, b);
    }
}


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

int main(){
string N;
cin >> N;
int sum = 0;
for(int i = 0; i < N.size(); i++){ 
     sum += N[i] - '0';
}

int x = stoi(N);

if(x % sum == 0) cout << "Yes" << endl;
else cout << "No" << endl;  

}

Measured memory_bytes: 256
#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.at(i);
  
  vector<int> flag(1);
  flag.at(0) = A.at(0);
  
  for(int i=1; i<N; i++){
    if(A.at(i) <= flag.at(flag.size()-1)){
      flag.push_back(A.at(i));
      continue;
    }else if(A.at(i) > flag.at(0)){
      flag.at(0) = A.at(i);
      continue;    
    }else if(A.at(i) > flag.at(1)){
      flag.at(1) = A.at(i);
      continue;
    }
     
    int right = flag.size()-1;
    int left = 0;
    while(right-left != 1){
      if( flag.at((right+left)/2) >= A.at(i) )
        left = (right+left)/2;
      else
        right = (right+left)/2;
    }
    flag.at(right) = A.at(i);
  }

  cout << flag.size() << endl;

}

Measured memory_bytes: 1276
#include <stdio.h>

int main(int argc, char *argv[])
{
	int S;
	scanf("%d", &S);

	int h = S / 3600;
	S = S % 3600;
	int m = S / 60;
	int s = S % 60;

	printf("%d:%d:%d\n",h,m,s);
}


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

#pragma GCC optimization_level 3
#define _GLIBCXX_DEBUG

using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;



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

    vector<ll> d(n);
    ll ans;

    for (size_t i = 0; i < n; i++)
    {
        cin>>d.at(i);
    }

    sort(d.begin(),d.end());

    ans = d.at(d.size()/2) - d.at(d.size()/2-1);

    cout<<ans<<endl;
    
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(ll i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
//const ll MOD = 1000000007ll;
const ll MOD = 998244353ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう

int main(){
    int n,m;
    std::cin >> n;
    VEC(int,a,n);
    std::cin >> m;
    VEC(int,b,m);
    multiset<int> s;
    rep(i,n){
        s.insert(a[i]);
    }
    bool ans=1;
    erep(i,b){
        if(s.find(i)==s.end())ans=0;
        else{
            s.erase(s.find(i));
        }
    }
    if(ans)std::cout << YES << std::endl;
    else std::cout << NO << std::endl;
}

Measured memory_bytes: 11136
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var input = ReadArrayInt();
            var aans = input[0];
            var bans = input[1];
            var cans = input[2];
            for (int i = 1; i < N; i++)
            {
                input = ReadArrayInt();
                var a = input[0];
                var b = input[1];
                var c = input[2];
                var asum = aans;
                var bsum = bans;
                var csum = cans;
                if (a + bans >= a + cans) asum = a + bans;
                else asum = a + cans;
                if (b + aans >= b + cans) bsum = b + aans;
                else bsum = b + cans;
                if (c + aans >= c + bans) csum = c + aans;
                else csum = c + bans;
                aans = asum;
                bans = bsum;
                cans = csum;
            }

            Console.WriteLine(Math.Max(aans, Math.Max(bans, cans)));
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 17448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n, a, b;
  cin >> n >> a >> b;

  ll cnt = n / (a + b);

  ll ans = cnt * a;

  ll rest = n - cnt * (a + b);

  ans += min(rest, a);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD  998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
#define int long long
vector<int>a;
int solve(int now,int cnter) {
	if (cnter == 0) return 1;
	int tmp = a[a.size() - cnter] - now;
	auto bobo = lower_bound(a.begin(), a.end(), now - tmp);
	int geko = bobo - a.begin();
	int cnt = a.size() - geko;
	cnt -= cnter;
	if (cnt+1 < cnter) {
		return 0;
	}
	else if (cnt+1 == cnter) {
		return 1;
	}
	else if (cnt+1 >	 cnter) {
		return 2;
	}
}
long long ruiseki[200000];
long long bobo_ruiseki[200000];
#undef int
int main(){
#define int long long
	int n, query;
	cin >> n >> query;
	REP(i, n) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
		ruiseki[i + 1] = ruiseki[i];
		ruiseki[i + 1] += tmp;
		bobo_ruiseki[i + 1] = bobo_ruiseki[i];
		if ((n + 1) % 2 == i % 2) {
			bobo_ruiseki[i + 1] += tmp;
		}
	}
	sort(a.begin(), a.end());
	REP(tea, query) {
		int b;
		cin >> b;
		int bot = 0;
		int top = a.size();
		while (top - bot > 1) {
			int mid = (top + bot) / 2LL;
			if (solve(b, mid) != 0) {
				bot = mid;
			}
			else {
				top = mid;
			}
		}
		int ans = 0;
		ans += ruiseki[n];
		ans -= ruiseki[n - bot];
		ans += bobo_ruiseki[n - bot * 2];
		cout << ans << endl;
	}
}

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

int main(){
    int a, b, c, x, ans = 0;
    cin >> a >> b >> c >> x;
    rep(i, a+1){  //0からaまで
        rep(j, b+1){  //0からbまで
            rep(k, c+1){  //0からcまで
                if(x == k*50 + j*100 + i*500) ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
const ll MOD = 1000000007;

template <std::uint_fast64_t Mod>
class ModInt {
  using u64 = std::uint_fast64_t;
 public:
  u64 val;
  constexpr ModInt(const u64 x = 0) noexcept : val(x % Mod) {}
  constexpr ModInt operator*(const ModInt rhs) const noexcept {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const noexcept {
    return ModInt(*this) /= rhs;
  }
  constexpr ModInt &operator*=(const ModInt rhs) noexcept {
    val = val * rhs.val % Mod;
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) noexcept {
    u64 exp = Mod - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = ModInt<MOD>;

int main() {
  int X, Y;
  mint ans{};
  cin >> X >> Y;
  if ((X+Y)%3==0) {
    int n = (X+Y)/3, d = X-Y;
     if (abs(d) <= n) {
      int a = (n+d)/2;
      ans = 1;
      for (int i = 0; i != a; ++i) ans = ans * (n-i) / (i+1);
    }
  }
  cout << ans.val << endl;
}


Measured memory_bytes: 3516
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/*
 public class ab079a {

 }

 */
public class Main {
  public void solve() throws FileNotFoundException {
    InputStream inputStream = System.in;

    InputHelper in = new InputHelper(inputStream);

    // actual solution
    String s = in.read();

    int n = s.length();

    int c = 1;

    for (int i = 1; i < n; i++) {
      if (s.charAt(i) == s.charAt(i - 1)) {
        c++;
        if (c >= 3) {
          System.out.println("Yes");
          return;
        }
      } else {

        c = 1;
      }
    }

    System.out.println("No");
    // end here
  }

  public static void main(String[] args) throws FileNotFoundException {
    (new Main()).solve();
  }

  class InputHelper {
    StringTokenizer tokenizer = null;
    private BufferedReader bufferedReader;

    public InputHelper(InputStream inputStream) {
      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
      bufferedReader = new BufferedReader(inputStreamReader, 16384);
    }

    public String read() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          String line = bufferedReader.readLine();
          if (line == null) {
            return null;
          }
          tokenizer = new StringTokenizer(line);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      return tokenizer.nextToken();
    }

    public Integer readInteger() {
      return Integer.parseInt(read());
    }

    public Long readLong() {
      return Long.parseLong(read());
    }
  }
}


Measured memory_bytes: 20692
N, T = map(int, input().split())

min_cost = 100000
for n in range(N):
    c, t = map(int, input().split())
    if  t > T:
        continue
    if c < min_cost:
        min_cost = c
if min_cost == 100000:
    print('TLE')
else:
    print(min_cost)

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

int main()
{
	string s,t,s1;
	int ans=-1000;
	cin>>s>>t;
	if (t.size()>s.size())//t比s大，会越界 
	{
		cout <<"UNRESTORABLE";
		return 0;
	}
	for(int j=0;j<s.size()-t.size()+1;j++)// 循环所有的可能 
	{
		int f=0; 
		s1=s.substr(j,t.size());//定义s1的长度 
		for(int i=0;i<t.size();i++)
		{
			if(s1[i]!=t[i])
			f=1;
		}
		if(f==0)
		{
			for(int i=0;i<s.size();i++)
			{
				if(s[i]=='?') s[i]='a';
			}
			cout<<s;
			return 0;
		}
	}
	for(int i=s.size()-t.size();i>=0;i--)
	{
		int F=1;
		if(t[0]==s[i]||s[i]=='?')
		{
			F=0;
			for(int j=i;j<i+t.size();j++)
			{
				if(!(s[j]==t[j-i]||s[j]=='?'))
				{
					F=1;
					break;
				}
			}
		}
		if(F==0)
		{
			ans=i;
			break;
		}
	}
	if(ans==-1000)
	{
		cout<<"UNRESTORABLE";
		return 0;
	}
	for(int i=ans;i<ans+t.size();i++)
	{
		s[i]=t[i-ans];
	}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='?') s[i]='a';
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 3624
inputarray = input().split(' ')
N = int(inputarray[0])
A = int(inputarray[1])
B = int(inputarray[2])
blue = 'b'
red = 'r'
amari = N % (A+B)
if A >= amari: 
    countnum = N // (A+B) * A +amari
else:
    countnum = N // (A+B) * A +A
print(countnum)

Measured memory_bytes: 3064
package main

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

const INF = (1 << 31) - 1

func main() {
	sc.Split(bufio.ScanWords)
	N, M, R := nextInt(), nextInt(), nextInt()
	r := nextIntArray(R)
	g := make([][]int, N)
	for i := 0; i < N; i++ {
		g[i] = make([]int, N)
		for j := 0; j < N; j++ {
			g[i][j] = INF
		}
		g[i][i] = 0
	}
	for i := 0; i < M; i++ {
		A := nextInt() - 1
		B := nextInt() - 1
		C := nextInt()
		g[A][B] = C
		g[B][A] = C
	}
	for k := 0; k < N; k++ {
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				g[i][j] = min(g[i][j], g[i][k]+g[k][j])
			}
		}
	}
	m := shift(R)
	dp := make([][]int, m)
	for i := 0; i < m; i++ {
		dp[i] = make([]int, R)
		for j := 0; j < R; j++ {
			dp[i][j] = INF
		}
	}
	for i := 0; i < R; i++ {
		dp[shift(i)][i] = 0
	}
	for bits := 0; bits < m; bits++ {
		for from := 0; from < R; from++ {
			if bits&shift(from) == 0 {
				continue
			}
			for next := 0; next < R; next++ {
				if bits&shift(next) != 0 {
					continue
				}
				nbits := bits | shift(next)
				ncost := dp[bits][from] + g[r[from]-1][r[next]-1]
				dp[nbits][next] = min(dp[nbits][next], ncost)
			}
		}
	}
	res := INF
	for i := 0; i < R; i++ {
		res = min(res, dp[m-1][i])
	}
	fmt.Println(res)
}

// -------- Library --------
var sc = bufio.NewScanner(os.Stdin)

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

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

func nextIntArray(size int) []int {
	res := make([]int, size)
	for i := 0; i < size; i++ {
		res[i] = nextInt()
	}
	return res
}

func min(a int, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func shift(p int) int {
	return 1 << uint(p)
}


Measured memory_bytes: 1280
#include<stdio.h>
int main()
{
    int X,Y;
    scanf("%d %d",&X,&Y);
    if(Y%2)
    {printf("No\n");
        return 0;
    }

    if(Y>=2*X&&Y<=4*X)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 1644
# -*- coding: utf-8 -*-
a=[]
ans="Yay!"
for _ in range(6):
  a.append(int(input()))
for i in range(5):
  for j in range(i+1,5):
    if abs(a[i]-a[j])>a[5]:
      ans=":("
      break
print(ans)

Measured memory_bytes: 3316
// https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    double a;
    cin >> a;
    int b = ceil(a / 1.08);
    if (a == (int)(b * 1.08)) {
        cout << b << endl;
    } else {
        cout << ":(\n";
    }

    return 0;
}


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

#define INF 100000000
#define MOD9(a) (a%1000000009)
#define MOD7(a) (a%1000000007)
#define ABS(a) (a<0?-(a):a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define REP(i,a) for(int i=0;i<a;i++) 

using namespace std;
int main(){
  int X;
  cin >> X;
  if(X < 1200){
    cout << "ABC" << endl;
  }else{
    cout << "ARC" << endl;
  }

}



Measured memory_bytes: 256
def fn1(s):
	return s == s[::-1]
def fn2(s):
	n = len(s)
	x = s[:(n-1)//2]
	return x == x[::-1]
def fn3(s):
	n = len(s)
	x = s[(n+1)//2:]
	return x == x[::-1]

s = input()

if fn1(s) and fn2(s) and fn3(s):
	print('Yes')
else:
	print('No')


Measured memory_bytes: 38256
n,k=map(int,input().split())
l=tuple(map(int,input().split()))
dp=[-1]*(n+1)
dp[1]=0
for i in range(2,min(n,k)+1):
  dp[i]=abs(l[i-1]-l[0])
if k>=n:
  print(dp[n])
else:
  dp[k+1]=abs(l[0]-l[k])
  for i in range(k+2,n+1):
    min=10**10
    for j in range(i-k,i):
      if min>dp[j]+abs(l[j-1]-l[i-1]):
        min=dp[j]+abs(l[j-1]-l[i-1])
    dp[i]=min
  print(dp[n])

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

int main(){
	#ifndef ONLINE_JUDGE
		freopen ("../input.txt", "r", stdin);
		freopen ("../output.txt", "w", stdout);
	#endif

    string s, t; cin>>s>>t;
    int ans = t.length();
    for(int i=0 ; i<=(s.length() - t.length()) ; i++){
        int ma = 0;
        for(int j=0, r=i ; j<t.length() ; j++, r++){
            if(s[r]!=t[j]) ma++;
        }
        ans = min(ans, ma);
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3604
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    const N = lines[0] - 0
    const a = lines[1].split(" ").map(Number)

    let count = 0;
    for (let i = 0; i <= N; i += 2) {
        if (a[i] % 2 === 1) count++
    }

    console.log(count)

})(input)


Measured memory_bytes: 29704
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

int ctoi(const char c);

int main()
{
    string str;
    cin >> str;

    int left = ctoi(str[0])*10 + ctoi(str[1]);
    int right = ctoi(str[2])*10 + ctoi(str[3]);

    bool left_MM = (0 < left && left < 13);
    bool right_MM = (0 < right && right < 13);

    string ans;

    if(left_MM && right_MM) ans = "AMBIGUOUS";
    else if(!left_MM && right_MM) ans = "YYMM";
    else if(left_MM && !right_MM) ans = "MMYY";
    else ans = "NA";

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

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_DALEN_BRAINS_
#define _USE_MATH_DEFINES_
// You don't know me 
#define ll long long
#define ins Not Needed Thing
// The Dalen
#define ull unsigned long long
#define ld long double
// Yeah Yeah
#define Accepted 0
#define pb push_back
// Ora Ora, Ora Ora, Ora fat
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
// Aydin day aydirinday
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
// @Im@5@Im@5 @Im@5@Im@5
#define F first
#define S second
// Skyrim dlya nordov (c) Roflakopter
#define SORRY FUL Accepted 
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// Skr Skr v chernih Naykax (c) ZzzzZzzzzZz
#define Toktama Kazakhstan
// TOKTAMA!

using namespace std;

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;                                          
const int PRI = 555557;
const int pri = 997;

int tests = 1;
int n, m, k;

string s;
int cnt[31];
ll cur,res;
int ans;

inline void Solve () {
	//easy (c) Dalen
	ll n;
	cin >> n;
	while (n >= (cur * 10) + 9) {
		cur *= 10;
		cur += 9;
		res += 9;
	} 	
	int kk = 0;
	while (pow(10ll, kk + 1) <= n) kk ++;

	ll now = pow(10ll, kk);
	for (int i = 1; i <= 9; i ++) {
		if (i * now + cur > n) break;
		res ++;
	}

	cout << res;
}

int main () {
	SpeedForce;
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);	
	//cin >> tests;
	while(tests --) {
		Solve ();
		// Ee Zadrot (P.S. Dalen)
	}

	return Accepted; 
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())

using namespace std;
typedef long long ll;


void solve(long long N, long long D){
  printf("%.0f\n", ceil((double) N / (2 * D + 1)));
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long D;
  scanf("%lld",&D);
  solve(N, D);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[100009];
int main()
{
   string s;
   while(cin>>s){
   int i=0;
   while(s[i]!='A' && i<s.size())i++;
   int j=s.size()-1;
   while(s[j]!='Z' && j>0)j--;
   ll ans=0;
   //cout<<s[i]<<" "<<s[j]<<endl;
   if(s[i]=='A' && s[j]=='Z')
   {
   i++,j++;
   ans=abs(i-j);
   ans++;
   }
   else
    ans=0;
   cout<<ans<<endl;
   }
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double pi=3.141592653589793;
    double rad=(30.0*h+m*0.5-m*6.0)*pi/180.0;
    rad=cos(rad);
    cout<< fixed <<setprecision(10);
cout<<pow(a*a+b*b-2*a*b*rad,0.50);
}




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

int main()
{
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> b(m);
	for (int i = 0; i < m; i++)
		cin >> b[i];

	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		int sum = 0;
		for (int j = 0; j < m; j++)
		{
			int a;
			cin >> a;
			sum += a * b[j];
		}
		if (sum + c > 0)
			ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int a[50],b[50],c[50],d[50],q,n,m;

long score(int *ar){
    register int i;
    long res = 0;
    for(i = 0;i < q;i++)if(ar[b[i]-1] - ar[a[i]-1] == c[i])res += d[i];
    return  res;
}

void dfs(int *ar,int dep,long *max){
    register int i;
    if(dep == n){
        long tmp = score(ar);
        *max = *max < tmp?tmp:*max;
        return;
    }
    for(i = dep == 0?1:ar[dep-1];i <= m;i++){
        ar[dep] = i;
        dfs(ar,dep+1,max);
    }
}

int main(void){
    register int i;
    scanf("%d%d%d",&n,&m,&q);
    for(i = 0;i < q;i++)scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
    int ar[n];
    long cnt = 0;
    dfs(ar,0,&cnt);
    printf("%ld",cnt);
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 10000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;
Graph G(100010);

queue<ll> Q;

void bfs(ll s,vector<ll>& table){ 
  for(int i = 0;i < table.size();i++){
    table[i] = INF;
  }
  table[s] = 0;
  Q.push(s);
  while(Q.size()){
    ll x = Q.front();
    ll n = G[x].size();
    Q.pop();
    for(ll i = 0;i < n;i++){
      ll y = G[x][i];
      if(table[y] == INF){
        table[y] = table[x] + 1;
        Q.push(y);
      }
    }
  }
  return;
}

int main(){
 ll N,U,V;
 cin >> N >> U >> V;
 U--;V--;
 vector<ll> par(N);
 for(int i = 0;i < N-1;i++){
   ll a,b;cin >> a >> b;
   a--;b--;
   par[max(a,b)] = min(a,b);
   G[a].push_back(b);
   G[b].push_back(a);
 }
 vector<ll> tableA(100010),tableT(100010);
 vector<bool> frag(100010);
 for(int i = 0;i < 100010;i++){
   frag[i] = 1;
 }
 bfs(V,tableA);
 bfs(U,tableT);
 
 ll ans = 0;
 for(int i = 0;i < N;i++){
   if(tableT[i] < tableA[i]){
     ans = max(ans,tableA[i]);
   }
 }
 cout << ans - 1 << endl;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e15;
signed main(){
	int n;
	scanf("%lld",&n);
	int ans=inf;
	for(int i=1;i*i<=n;i++){
		if(n%i==0)ans=min(ans,i+n/i-2);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
from math import sqrt

n,m = map(int,input().split())

ans = 1
for i in range(1, int(sqrt(m)+1)):
  if m % i == 0:
    if n * i <= m:
      ans = max(ans,i)
    if n * (m//i) <= m:
      ans = max(ans, m//i)
                           
print(ans)    

Measured memory_bytes: 3060
N = int(input())

XYH = [list(map(int, input().split())) for _ in range(N)]


for cx in range(0, 101):
    for cy in range(0, 101):

        prev = None
        flg = False
        zeros = []
        for x, y, h in XYH:
            if h == 0:
                zeros.append((x, y, h))
                continue

            cur_h = h + abs(x - cx) + abs(y - cy)

            if prev is not None:
                if prev != cur_h:
                    flg = True
                    break

            prev = cur_h

        if not flg:
            for x, y, h in zeros:
                if max(0, cur_h - abs(x - cx) - abs(y - cy)) != 0:
                    flg = True
                    break

            if not flg:
                print(cx, cy, cur_h)
                exit()



Measured memory_bytes: 9172
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
    }
    for x in 0..n+1 {
        let v = (x as f64 * 1.08).floor() as usize;
        if v == n {
            return puts!("{}\n", x);
        }
    }
    puts!("{}\n", ":(");
}


Measured memory_bytes: 4352
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		if ((a + b) % 2 == 1) {
			System.out.print((a + b) / 2 + 1);
		} else {
			System.out.print((a + b) / 2);
		}
	}
}


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

int main() {
  int N, M; cin >> N >> M;
  vector<int> X(M), Y(M), cnt(N, 1);
  for (int i = 0; i < M; i++) cin >> X.at(i) >> Y.at(i);
  vector<bool> B(N, false);
  B.at(0) = true;
  for (int i = 0; i < M; i++) {
    int x = X.at(i);
    int y = Y.at(i);
    cnt.at(x-1)--;
    cnt.at(y-1)++;
    if (B.at(x-1)) B.at(y-1) = true;
    if (cnt.at(x-1) == 0) B.at(x-1) = false;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (B.at(i)) ans++;
  }
  cout << ans << endl;
}

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

int N, M, Q;
vector<int> a, b, c, d;

int score(vector<int> A) {
    int res = 0;
    rep(i, Q) if (A[b[i]] - A[a[i]] == c[i]) res += d[i];
    return res;
}

int main(){
  cin >> N >> M >> Q;
  a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
  rep(i, Q){
      cin >> a[i] >> b[i] >> c[i] >> d[i];
      a[i]--, b[i]--;
  }

  vector<int> X(N+M-1, 1);
  rep(i, M-1) X[i] = 0;

  int ans = 0;
  do{
    int cnt = 1;
    vector<int> A;
    rep(i, X.size()){
      if (X[i]==1) A.push_back(cnt);
      else cnt++;
    }

    ans = max(ans, score(A));

  }
  while (next_permutation(X.begin(), X.end()));

  cout << ans << endl;
}


Measured memory_bytes: 3588
class UnionFind:
    def __init__(self, size):
        self.parents = [-1 for _ in range(size)]

    def root(self, index):
        parent = self.parents[index]
        if ( parent < 0):
            return index
        root = self.root(parent)
        self.parents[index] = root
        return root

    def size(self, index):
        return -1 * self.parents[self.root(index)]

    def add(self, A, B):
        A = self.root(A)
        B = self.root(B)
        if (A == B):
            return
        if (self.size(A) < self.size(B)):
            A, B = B, A
        self.parents[A] += self.parents[B]
        self.parents[B] = A

N, M = [int(x) for x in input().split()]
AB_list = [[int(x)-1 for x in input().split()] for _ in range(M)]
ans = [N * (N-1) // 2]
uf = UnionFind(N)
for A, B in reversed(AB_list):
    if (uf.root(A) != uf.root(B)):
        ans.append(ans[-1] - uf.size(A) * uf.size(B))
        uf.add(A, B)
    else:
        ans.append(ans[-1])
for c in reversed(ans[:-1]):
    print(c)


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

int main(void) {
    constexpr long MOD = 1e9 + 7;

    long n, k;
    cin >> n >> k;

    vector<long> a(n);
    for(auto &e: a) cin >> e;
    sort(a.begin(), a.end());

    vector<long> fact(n+1);
    fact[0] = 1;
    for(long i=1; i<=n; i++)
        fact[i] = fact[i-1] * i, fact[i] %= MOD;

    vector<long> ifact(n+1);
    {
        long r = 1, a = fact[n], b = MOD-2;
        while(b) {
            if(b&1) r *= a, r %= MOD;
            a *= a, a %= MOD;
            b >>= 1;
        }
        ifact[n] = r;

    }
    for(long i=n-1; i>=0; i--)
        ifact[i] = ifact[i+1] * (i+1), ifact[i] %= MOD;

    auto comb = [&](long a, long b) {
        if(a < b) return 0l;
        long r = 1;
        r *= fact[a], r %= MOD;
        r *= ifact[a-b], r %= MOD;
        r *= ifact[b], r %= MOD;
        return r;
    };

    long r = 0;

    for(long i=k-1; i<n; i++) {
        long m = i;
        long t = a[i];
        t *= comb(m, k-1);
        t %= MOD;

        r += t;
        r %= MOD;
    }
    for(long i=0; i+k<=n; i++) {
        long m = n-1-i;
        long t = a[i];
        t *= comb(m, k-1);
        t %= MOD;

        r += MOD-t;
        r %= MOD;
    }

    cout << r << endl;
}


Measured memory_bytes: 2560
n=int(input())
town=[]
for i in range(n):
  x,y=map(int,input().split())
  town.append([x,y,i])

  
X=sorted(town,key=lambda x:x[0])

Y=sorted(town,key=lambda x:x[1])
es=[]
for i in range(1,n):
  es.append((min(abs(X[i][0]-X[i-1][0]),abs(X[i][1]-X[i-1][1])),X[i][2],X[i-1][2]))
  #es.append((min(abs(X[i][0]-X[i-1][0]),abs(X[i][1]-X[i-1][1])),X[i-1][2],X[i][2]))
  es.append((min(abs(Y[i][0]-Y[i-1][0]),abs(Y[i][1]-Y[i-1][1])),Y[i][2],Y[i-1][2]))
  #es.append((min(abs(Y[i][0]-Y[i-1][0]),abs(Y[i][1]-Y[i-1][1])),Y[i-1][2],Y[i][2]))
es.sort(key=lambda x:x[0])


#Union-Find木
#par[i]:iの親　deep[i]:iの深さ　size[i]:iの大きさ
par=[i for i in range(n)]
deep=[1]*n
size=[1]*n

#親を見つける
def find(x):
  if par[x]==x:
    return x
  else:
    return find(par[x])

#二つのグループを統合する
def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return
  if deep[x]<deep[y]:
    par[x]=y
    size[y]+=size[x]
  else:
    par[y]=x
    size[x]+=size[y]
    if deep[x]==deep[y]:
      deep[x]+=1

#xとyが同じグループに属するかどうか
def same(x,y):
  return find(x)==find(y)

#xが属するグループの要素数を返す
def group_count(x):
  return size[find(x)]
  
#クラスカル法
#esは重みで小さい順にsort済み
#es[i]:[重み、始点、終点]
def kruskal(n,es):
  ans=0
  for to in es:
    if not same(to[1],to[2]):
      ans+=to[0]
      unite(to[1],to[2])
  return ans

      
  
print(kruskal(n,es))


Measured memory_bytes: 143824
#include<bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int N = 4003, mod = 998244353;
template<typename T>
void read(T &x){
	int ch = getchar(); x = 0; bool f = false;
	for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
	for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
	if(f) x = -x;
}
void qmo(int &x){x += (x >> 31) & mod;}
int ksm(int a, int b){
	int res = 1;
	for(;b;b >>= 1, a = (LL) a * a % mod) if(b & 1) res = (LL) res * a % mod;
	return res;
}
template<typename T>
inline bool chmax(T &a, const T &b){if(a < b) return a = b, 1; return 0;}
template<typename T>
inline bool chmin(T &a, const T &b){if(a > b) return a = b, 1; return 0;}
char s[10];
bool query(int x, int y){printf("? %d %d\n", x, y); fflush(stdout); scanf("%s", s); return s[0] == 'Y';}
int a, b, stk[N], top; bool ans[N];
int main(){
	read(a); read(b);
	if(a <= b){puts("Impossible"); return 0;}
	for(Rint i = 0;i < a + b;++ i){
		if(!top || query(stk[top], i)) stk[++ top] = i;
		else -- top;
	}
	for(Rint i = 0;i < a + b;++ i) ans[i] = query(stk[top], i);
	printf("! "); for(Rint i = 0;i < a + b;++ i) printf("%d", ans[i]); putchar('\n');
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

const ll mod=1e9+7;
ll mu(ll a,ll b){
  return (ll)a*b%mod;
}
ll ad(ll a,ll b){
  if((a+=b)>=mod)a-=mod;
  return a;
}
ll pw(ll a,ll b,ll c=1LL){
  for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
  return c;
}
ll dv(ll a,ll b){
  return mu(a,pw(b,mod-2));
}


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

  int n;
  cin >> n;
  int x[n];
  rep(i,n) cin>>x[i];
  int kara=0;
  int iru=0;
  vector<int> k;
  int c=2;
  rep(i,n){
    if(x[i]-i-1+c==i+1){
      k.pb(i+1);
      c+=2;
    }
  }
  ll ans=1;
  rep(i,k.size()){
    ans = mu(ans,k[i]-i);
  }
  rep1(i,n-k.size()){
    ans = mu(ans,i);
  }
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 1024
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=2005;
const int mlog=14;
int n,m,k;
vector<int>edge[maxn];
bitset<maxn>b[maxn],d[maxn],s[maxn],t,p,all;
queue<pii>q;
int par[maxn][mlog],dep[maxn];

void dfs(int x,int p,int de){
	dep[x]=de;
	par[x][0]=p;
	REP(j,mlog-1)par[x][j]=par[par[x][j-1]][j-1]; 
	d[x][x]=s[x][x]=1;
	rep(i,edge[x].size()){
		int y=edge[x][i];
		if(y==p)continue;
		d[y]|=d[x];
		dfs(y,x,de+1);
		s[x]|=s[y];
	}
}

int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	int diff=dep[x]-dep[y];
	for(int i=mlog-1;i>=0;i--)if((diff>>i)&1)x=par[x][i];
	if(x==y)return x;
	for(int i=mlog-1;i>=0;i--){
		if(par[x][i]!=par[y][i]){
			x=par[x][i];
			y=par[y][i];
		}
	}
	return par[x][0];
} 

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	REP(i,n)b[i][i]=all[i]=1;
	REP(i,n-1){
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u].pb(v);
		edge[v].pb(u);
	}
	dfs(1,0,0);
	REP(i,m){
		int u,v;
		scanf("%d%d",&u,&v);
		q.push(mp(u,v));
		b[u][v]=b[v][u]=1;
	}
	int ans=0;
	while(!q.empty()){
		ans++;
		int x=q.front().fst,y=q.front().snd;
		q.pop();
		if(dep[x]<dep[y])swap(x,y);
		int z=lca(x,y);
		if(z==y){
			int ox=x;
			for(int i=mlog-1;i>=0;i--)if(par[ox][i]&&dep[par[ox][i]]>dep[y])ox=par[ox][i];
			p=all^s[ox];
			p|=s[x]|d[x];
		}
		else p=s[x]|s[y]|(d[x]^d[y]),p[z]=1;
		t=(b[y]&~b[x])&p;
		while(t.any()){
			z=t._Find_next(0);
			b[x][z]=b[z][x]=1;
			q.push(mp(x,z));
			t[z]=0;
		}
		t=(b[x]&~b[y])&p; 
		while(t.any()){
			z=t._Find_next(0);
			b[y][z]=b[z][y]=1;
			q.push(mp(y,z));
			t[z]=0;
		}
	}
	printf("%d\n",ans);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/

Measured memory_bytes: 18484
N,K = map(int,input().split())
h = [0]+list(map(int,input().split()))
dp = [10**10]*(N+1)
dp[1] = 0
for i in range(1,N+1):
    for j in range(1,K+1):
        if i-j>0:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])
        else:
            break
print(dp[N])

Measured memory_bytes: 52448
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{	int n,k;
	int c;
	cin>>n;
	if(n<=3)
	{
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<=100;i++)
	for(int j=0;j<=100;j++)
	if(j*4+i*7==n)
	{cout<<"Yes"<<endl;
	return 0;}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=a;i<(b);i++)
using namespace std;
class SUM{
public:
  int dflt;
  SUM() : dflt(0) {;}
  int merge  (int a, int b){ return a + b; }
  int update (int &node, int v){ node = v; }
};

template <typename T, typename Updater>
class SegmentTree{
  int N;
  vector<T> tree;
  Updater updater;
public:
  SegmentTree(){;}
  SegmentTree(int n, Updater f) : updater(f) {
    N = 1;
    while(N < n) N *= 2;
    tree.resize( 2 * N - 1, updater.dflt);
  }
  SegmentTree(int n, Updater f, vector<T> &vs) : updater(f) { // vsで初期化
    N = 1;
    while(N < n) N *= 2;
    tree.resize( 2 * N - 1, updater.dflt );
    int i;
    for(i = 0; i < vs.size(); i++)
      tree[i + N - 1] = vs[i];
    for(int k = N - 2; k >= 0; k--){
      tree[k] = updater.merge(tree[2 * k + 1], tree[2 * k + 2]);
    }
  }
  void update(int k, T a){
    k += N - 1;
    updater.update(tree[k], a);
    while(k > 0){
      k = (k-1) / 2;
      tree[k] = updater.merge(tree[2 * k + 1], tree[2 * k + 2]);
    }
  }
  T query(int a, int b, int k, int l, int r){
    if( r <= a || b <= l ) return updater.dflt;
    if( a <= l && r <= b ) return tree[k];
    return updater.merge( query(a, b, 2 * k + 1, l, (r + l) / 2),
			  query(a, b, 2 * k + 2, (r + l) / 2, r) );
  }
  T query(int a, int b){ return query(a, b, 0, 0, N); }
};

int N;
int main(){
  cin >> N;
  vector< tuple<long long,int> > A;
  REP(i,N){
    long long a;
    cin >> a;
    A.emplace_back( a, i );
  }
  long long ans = 0;
  SegmentTree<int, SUM> st( N, SUM() );
  sort( A.begin(), A.end() );
  for( auto a : A ){
    long long v, i;
    tie(v,i) = a;
    st.update( i, 1 );
    int l1 = 0, l2 = i + 1;
    REP(k,30){
      int m = (l1 + l2) / 2;
      if( st.query(m, i + 1) > 1 ) l1 = m;
      else l2 = m;
    }
    int r1 = i+1, r2 = N + 1;
    REP(k,30){
      int m = (r1 + r2) / 2;
      if( st.query(i, m) > 1 ) r2 = m;
      else r1 = m;
      //cout << "i=" << i << " m=" << m << " st=" << st.query(i,m) << endl;
    }
    int L = i - l2 + 1, R = r1 - i;
    //cout << "v=" << v << " l=" << l2 << " r=" << r1 << endl;
    //cout << "v=" << v << " L=" << L << " R=" << R << endl;
    ans += (long long)L * (long long)R * v;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans[200000] = {};

int main()
{
ll n,q;
scanf("%ld %ld", &n, &q);
vector<vector<ll>> g(n);
rep(i, n-1)
{
    ll a,b;
    scanf("%ld %ld", &a, &b);
    g[a-1].push_back(b-1);
    g[b-1].push_back(a-1); //無向辺
}
ll po[n]={};
rep(i,q){
ll p , x ;
scanf("%ld %ld", &p, &x);
po[p-1]+=x;
}
stack<ll> s;
bool see[n]={};
s.push(0);
s.push(0);
ll now=0;
while(s.size()!=0){
  ll te=s.top();
  s.pop();
  if(!see[te]){
    see[te]=1;
    now+=po[te];
    ans[te]=now;
    for (auto p : g[te])
    {
      if (see[p])
          continue;
      s.push(p);
      s.push(p);
    }
  }
  else{
    now-=po[te];
  }
}
rep(i,n)
printf("%ld ",ans[i]);
return 0;
}


Measured memory_bytes: 21232
C = []
for i in range(3):
    C.append(list(map(int,input().split())))
flag = 0
for j in range(2):
    if (C[j+1][0]-C[j][0]) == (C[j+1][1]-C[j][1]) and (C[j+1][1]-C[j][1]) == (C[j+1][2]-C[j][2]):
        pass
    else:
        flag = 1
        break
for k in range(2):
    if (C[0][k+1]-C[0][k]) == (C[1][k+1]-C[1][k]) and (C[1][k+1]-C[1][k]) == (C[2][k+1]-C[2][k]):
        pass
    else:
        flag = 1
        break
if flag == 0:
    print("Yes")
else:
    print("No")
        

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	FOR(i, 1, 5) {
		int a;
		cin >> a;
		if (a == 0) {
			pv(i);
		}
	}
	return 0;
}

Measured memory_bytes: 3568
import sys
input=sys.stdin.readline
from heapq import *
from collections import defaultdict
x, y, z, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a = sorted(a, reverse = True)
b = sorted(b, reverse = True)
c = sorted(c, reverse = True)

ans = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]
heapify(ans)
log = defaultdict(lambda :0)

d = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
for i in range(k):
    temp, s, t, u = heappop(ans)
    temp = temp * (-1)
    print(temp)
    for ds, dt, du in d:
        ns = s + ds
        nt = t + dt
        nu = u + du
        if not(0 <= ns < x and 0 <= nt < y and 0 <= nu < z):continue
        if log[(ns, nt, nu)]:continue
        heappush(ans, [-(a[ns] + b[nt] + c[nu]), ns, nt, nu])
        log[(ns, nt, nu)] = 1


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

int main() {
    int h, n;
    cin >> h >> n;

    int sum = 0, tmp;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        sum += tmp;
    }

    if (h <= sum) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define rep(i,n) for (ll i=0; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;

struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
  vector<int> r;
 
  UnionFind(int N) {
    r = vector<int>(N, -1);
  }
 
  ll root (ll x) {
    if (r[x] < 0) return x;
    return r[x] = root(r[x]);
  }
 
  bool unite (ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (r[x] > r[y]) swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }
 
  ll size (ll x) {
    return -r[root(x)];
  }
};

int main() {
  ll n, m;
  cin >> n >> m;
  
  UnionFind uf(n);
  
  rep(i,m) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    uf.unite(a,b);
  }
  ll ans = 0;
  rep(i,n) ans = max(uf.size(i), ans);
  cout << ans << endl;
}


Measured memory_bytes: 4052
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include <stdio.h>
#include <string.h>

using namespace std;

typedef long long ll;
typedef double db;

const ll INF = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const db PI = 4 * atan((db)1);

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define F0R(i,a) for(int i=0;i<a;i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main()
{/*
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b;cin >> a >> b;
	ll temp = (a+b) % b;
	a = min(temp, b - temp);
	cout << a << "\n";
}



Measured memory_bytes: 888