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

int main() {
	string s;
	cin >> s;
	int lookfor = -1;
	bool ans = true;
	for (int i = 0; i < s.length(); i++){
		//cout << lookfor << endl;
		if (lookfor != -1) {
			if (lookfor == 1) {
				if (i <= s.length() - 4 && s[i] == 'r' && s[i+1] == 'e' && s[i+2] == 'a' && s[i+3] == 'm'){
					if (i <= s.length() - 6 && s[i+4] == 'e' && s[i+5] == 'r'){
						if (s[i+6] == 'a'){
							i += 3;
							lookfor = -1;
						}else{
							i += 5;
							lookfor = -1;
						}
					}else {
						i += 3;
						lookfor = -1;
					}
				}else{
					ans = false;
				}
			}
			if (lookfor == 2) {
				if (i <= s.length() - 4 && s[i] == 'r' && s[i+1] == 'a' && s[i+2] == 's' && s[i+3] == 'e'){
					if (i <= s.length() - 5 && s[i+4] == 'r'){
						i += 4;
						lookfor = -1;
					}else {
						i += 3;
						lookfor = -1;
					}
				}else{
					ans = false;
				}
			}
		}else {

			if (s[i] == 'd') lookfor = 1;
			else if (s[i] == 'e') lookfor = 2;
			else ans = false;
		}
		if (!ans)
			break;
	}
	if(ans)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 512
import bisect
import sys

input = sys.stdin.readline
num2alpha = lambda c: chr(c + 97)
alpha2num = lambda c: ord(c) - ord("a")


class SegTreeMax:
    def __init__(self, l):
        self.N = 1
        while self.N < l:
            self.N *= 2
        self.L = [0 for _ in range(self.N * 2 - 1)]

    def update(self, k, v):
        k += self.N - 1
        self.L[k] = v
        while k > 0:
            k = (k - 1) // 2
            self.L[k] = max(self.L[k * 2 + 1], self.L[k * 2 + 2])

    def append(self, k, v):
        k += self.N - 1
        self.L[k] += 2 ** v
        while k > 0:
            k = (k - 1) // 2
            self.L[k] = self.L[k * 2 + 1] | self.L[k * 2 + 2]

    def delete(self, k, v):
        k += self.N - 1
        self.L[k] -= 2 ** v
        while k > 0:
            k = (k - 1) // 2
            self.L[k] = self.L[k * 2 + 1] | self.L[k * 2 + 2]

    def query(self, a, b):
        return self.inquiry(0, self.N, 0, a, b)

    def inquiry(self, l, r, k, a, b):
        if r <= a or l >= b:
            return 0
        if a <= l and b >= r:
            return self.L[k]
        vl = self.inquiry(l, (l + r) // 2, k * 2 + 1, a, b)
        vr = self.inquiry((l + r) // 2, r, k * 2 + 2, a, b)
        return vl | vr


def main():
    N = int(input())
    Stri = input()
    L = []
    for c in Stri:
        L.append(c)
    Q = int(input())
    S = SegTreeMax(N)
    for i in range(N):
        S.append(i, alpha2num(L[i]))

    for _ in range(Q):
        a, b, c = input().split()
        if a == "1":
            i = int(b) - 1
            S.delete(i, alpha2num(L[i]))
            L[i] = c
            S.append(i, alpha2num(c))

        else:
            l = int(b) - 1
            r = int(c)
            res = S.query(l, r)
            p = 0
            for i in range(26):
                p += res & 1
                res >>= 1
            print(p)


main()


Measured memory_bytes: 118084
from fractions import gcd
n,m=map(int,input().split())
s=input()
t=input()
p=gcd(n,m)
ans=n*m//p 
for i in range(n):
	if abs((i*(ans//n)/(ans//m))-int(i*(ans//n)/(ans//m)))<=10**(-7):
		if s[i]==t[(i*(ans//n)//(ans//m))]:
			continue
		else:
			print(-1)
			exit()
print(ans)


Measured memory_bytes: 5432
#include <iostream>
using namespace std;
int n,s;

int dfs(int pos,int selected,int sum){
	if(selected == n)return (sum == s)?1:0;
	if(pos == 10)return 0;
	return dfs(pos+1,selected,sum)+dfs(pos+1,selected+1,sum+pos);
}

int main(){
	while (1) {
		cin>>n>>s;
		if(!(n+s))break;
		cout<<dfs(0,0,0)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define PDD pair<LD,LD>
#define eps 1e-9
#define HH1 402653189
#define HH2 1610612741

int a, b;

int main () {
	
	scanf("%d%d", &a, &b);
	
	if (a == 1) a = 14;
	if (b == 1) b = 14;
	
	if (a > b) printf("Alice\n");
	if (a < b) printf("Bob\n");
	if (a == b) printf("Draw\n");
	
	return 0;
	
}

Measured memory_bytes: 256
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


A,B=nm()
print(A*B)

Measured memory_bytes: 10456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VL;
typedef vector<pair<ll, ll>> VPI;
typedef pair<ll, ll> PLL;
typedef map<ll, ll> MLL;
#define EPS 1e-9
#define pb push_back
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h, w;
    cin >> h >> w;
    char s[h + 1][w + 1];
    FOR(i, 1, h + 1)
    {
        FOR(j, 1, w + 1)
        {
            cin >> s[i][j];
        }
    }
    ll dp[h + 1][w + 1] = {0};
    FOR(i, 1, h + 1)
    if (s[i][1] == '.')
    {
        dp[i][1] = 1;
    }
    else
        break;
    FOR(i, 1, w + 1)
    if (s[1][i] == '.')
        dp[1][i] = 1;
    else
        break;
    FOR(i, 2, h + 1)
    {
        FOR(j, 2, w + 1)
        {
            if (s[i][j] == '.')
            {

                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
            }
        }
    }
    std::cout << dp[h][w];
    return 0;
}


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

#define PI acos(-1)
#define hell 1000000007
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define endl "\n"
#define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define line cout<<endl
#define bug(n) {outl(n);return;}
#define N 100005
ll x;
void solve(){
    cin>>x;
    bug(3*x*x);
}
void prep(){
    
}
int main(){
    io;
    ll t=1;
    // cin>>t;
    prep();
    fix(12);
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
s=input()
f=int(s[:2])
b=int(s[2:])
if 0<= f <=99 and  1<= b <=12:
  if 1<= f <=12:
    print("AMBIGUOUS")
  else:
    print("YYMM")
elif 1<= f <= 12 and 0<= b <=99:
  if 1<= b <=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:print("NA")

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, A, B;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> A >> B;
	cout << N / (A + B) * A + min(N % (A + B), A);
}


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

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    int a, b;

    for(a = 1; a <= 3500; a ++)
    {
        for(b = 1; b <= 3500; b ++)
        {
           // if(a == 1)
           // printf("ALO %d %d\n", a, b);

            long long cs = 1LL * 4 * a * b - 1LL * n * (a + b);
            long long rez = 1LL * n * (a * b);

           // if(a == 1 && b == 2)
          //      printf("AVEM C %lld\n", rez / cs);

            if(cs > 0 && rez > 0 && rez % cs == 0)
            {
                printf("%lld %lld %lld\n", 1LL*a, 1LL*b, rez / cs);

                exit(0);
            }
        }
    }
    return 0;
}


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

using namespace std;

long long n;

int main() {
	cin >> n;
	if(n & 1) {
		puts("0");
	} else {
		long long ans = 0;
		while(n) {
			ans += n / 10;
			n /= 5;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
// #include <variant>

// Yay!!
#define endl codeforces

// macros for iterator
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)

// alias
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;

// variadic min/max
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }

// variadic chmin/chmax
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

// multi demension array
template <typename T, std::size_t Head, std::size_t... Tail> struct multi_dim_array { using type = std::array<typename multi_dim_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dim_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t... Args> using mdarray = typename multi_dim_array<T, Args...>::type;

// fill container
// template <typename T, typename F, typename... Args> 
// void fill_seq(T &t, F f, Args... args) { if constexpr (std::is_invocable<F, Args...>::value) { t = f(args...); } else { for (ssize_t i = 0; i < t.size(); i++) fill_seq(t[i], f, args..., i); } }

// make multi dimension vector
template <typename T> vec<T> make_v(ssize_t sz) { return vec<T>(sz); }
template <typename T, typename... Tail> auto make_v(ssize_t hs, Tail&&... ts) { auto v = std::move(make_v<T>(std::forward<Tail>(ts)...)); return vec<decltype(v)>(hs, v); }

// init
namespace init__ { 
struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; 
}


int main() {
    ll n;
    std::cin >> n;
    ll ans = n + 10;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i) continue;
        ll a = i, b = n / i;
        ll tmp = a - 1 + b - 1;
        chmin(ans, tmp);
    }
    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())
A = list(map(int, input().split()))

count_l = 0
count_r = 0

for a in A:
    if a > x:
        count_r += 1
    else:
        count_l += 1

ans = min(count_l, count_r)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int g[15][15];
    int n;
    cin>>n;
    rep(i,n)rep(j,n)g[i][j]=-1;
    rep(i,n){
        int a;
        cin>>a;
        rep(j,a){
            int x,y;
            cin>>x>>y;
            --x;
            g[i][x]=y;
        }
    }
    int ans=0;
    rep(i,1<<n){
        vector<int>d(n);
        rep(j,n){
            if(i>>j&1){
                d[j]=1;
            }
        }
        bool ok=true;
        rep(j,n){
            if(d[j]==1){
                rep(k,n){
                    if(g[j][k]==-1)continue;
                    if(g[j][k]!=d[k])ok=false;
                }
            }
        }
        if(ok==true)ans=max(ans,__builtin_popcount(i));
    }
    cout<<ans<<endl;
}

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

int main() {
  int N;
  cin >> N;
  int i;
  bool flag = true;
  for (i = 0;; ++i) {
    int x = i * 1.08;
    if (x == N) {
      break;
    } else if (x > N) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << i << endl;
  } else {
    cout << ":(" << endl;
  }
}


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

using namespace std;

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

    long long res = 0;

    for(int i=0; i<N + 1; i++){
        if(i % 3 == 0 || i % 5 == 0) continue;
        else{
            res += i;
        }
    }


    cout << res << endl;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){
  
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  ll sum = 0;
  REP(i,n)cin >> a[i];
  REP(i,n)sum += a[i];
  ll count = 0;
  REP(i,n){
    if(1ll*a[i]*4*m >= sum)count++;
  }
  if(count >= m)cout << "Yes" << endl;
  else cout << "No" << endl;






  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll k,a,b;cin>>k>>a>>b;
  if(b > a){
    ll num = k-a+1;
    ll ans = a + num%2 + (b-a)*(num/2);
    cout<<max(ans,k+1)<<endl;
  }else{
    cout<<k+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
a.sort(key=lambda x: x[1])
t=0
for i in range(n):
  t+=a[i][0]
  if t>a[i][1]:
    print("No")
    break
  elif i==n-1:
    print("Yes")


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int>h(n) ;
  for(int i=0;i<n;i++){
    cin >> h.at(i);
  }
  
  vector<int>dp(n,0);
  dp.at(1)=abs(h.at(1)-h.at(0));
  for(int i=2;i<n;i++){
    int mindp= dp.at(i-1)+abs(h.at(i)-h.at(i-1));
    for(int j=max(i-k,0);j<i-1;j++){
      mindp= min(dp.at(j)+abs(h.at(i)-h.at(j)),mindp);
    }
    dp.at(i)=mindp;
  }
cout<< dp.at(n-1)<< endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    string s;
    cin >>s;
    bool ok = true;
    rep(i, s.size()) {
        if (i % 2 == 0) {
            if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {

            }
            else {
             //   println(i)
             //   println(s[i]);
                ok = false;
                break;
            }
        }
        else {
            if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {

            }
            else {
             //   println(i)
             //   println(s[i]);
                ok = false;
                break;
            }
        }
    }
    yorn(ok)
    return 0;
}

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

int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  if (k > a + b) {
    a = 0;
    b = 0;
  }
  else if (k > a) {
    b = a + b - k;
    a = 0;
  }
  else {
    a = a - k;
  }
  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn a() {
    let n = read!(usize);
    println!("{}", n.pow(3));
}

fn b() {
    let n = read!(usize);
    let a = read!([usize]);
    let b = read!([usize]);
    let c = read!([usize]);
    let mut ans = 0;
    for i in 0..n {
        if i == 0 {
            ans += b[a[i] - 1];
        } else {
            ans += b[a[i] - 1];
            if a[i - 1] + 1 == a[i] {
                ans += c[a[i - 1] - 1];
            }
        }
    }
    println!("{}", ans);
}

fn c() {
    let n = read!(usize);
    let b: Vec<usize> = read![[usize]];

    //    if n == 2 {
    //        println!("{}", b[0] * 2);
    //        return;
    //    }

    let mut v = Vec::with_capacity(n + 1);
    v.push(INF as usize);
    v.extend(b);
    v.push(INF as usize);

    let mut ans = 0;
    for i in 1..(n + 1) {
        ans += min(v[i - 1], v[i]);
    }
    println!("{}", ans);

    //    let mut a = Vec::with_capacity(n);
    //    if b[0] <= b[1] {
    //        a.push(b[0]);
    //        a.push(b[0]);
    //    } else {
    //        a.push(b[1]);
    //        a.push(b[0]);
    //    }
    //    for i in 0..(n - 1) {
    //
    //    }
}

fn d() {
    unimplemented!();
}

fn e() {
    unimplemented!();
}

fn f() {
    unimplemented!();
}

fn main() {
    c();
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
#include <map>
#include <cassert>
using namespace std;

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

typedef pair<int, int> P;

struct Point{
  int x, y;
  Point(int a, int b){
    x = a, y = b;
  }
};

const int MAX = 510;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

char field[MAX][MAX];
bool found[26];
vector<Point> alpha[26];
int H, W;

bool checkH(int x1, int x2, int y, char c){
  if(x1 > x2) swap(x1, x2);
  for(int j = x1 ; j <= x2 ; j++){
    if(field[y][j] != '.' && field[y][j] != c) return false;
  }
  return true;
}

bool checkW(int y1, int y2, int x, char c){
  if(y1 > y2) swap(y1, y2);
  for(int i = y1 ; i <= y2 ; i++){
    if(field[i][x] != '.' && field[i][x] != c) return false;
  }
  return true;
}

int main(){
  while(cin >> H >> W){
    rep(i, H) cin >> field[i];
    
    memset(alpha, 0, sizeof(alpha));
    memset(found, 0, sizeof(found));
    
    rep(i, H){
      rep(j, W){
	if(isalpha(field[i][j])){
	  int c = field[i][j]-'A';
	  if(!found[c]){
	    found[c] = true;
	    alpha[c].push_back(Point(j, i));
	    //alpha[c].x1 = j, alpha[c].y1 = i;
	  }
	  else{
	    alpha[c].push_back(Point(j, i));
	    //alpha[c].x2 = j, alpha[c].y2 = i;
	  }
	}
      }
    }
    
    vector<Point> cross[26];
    rep(i, 26){
      if(found[i]){
	cross[i].push_back(Point(alpha[i][0].x, alpha[i][1].y));
	cross[i].push_back(Point(alpha[i][1].x, alpha[i][0].y));
	//cross[i].x1 = alpha[i].x1, cross[i].y1 = alpha[i].y2;
	//cross[i].x2 = alpha[i].x2, cross[i].y2 = alpha[i].y1;
      }
    }
    
    rep(i, 26){
      assert(alpha[i].size() == 2 || alpha[i].size() == 0);
    }
    
    rep(i, H){
      rep(j, W){
	rep(k, 4){
	  int nx = j+dx[k], ny = i+dy[k];
	  if(nx < 0 || nx > W || ny < 0 || ny > H) continue;
	  if(field[i][j] == field[ny][nx]) found[field[i][j]-'A'] = false;
	}
      }
    }
    
    int ans = 0;
    for(; ;){
    Start:;
      bool flag = false;
      rep(i, 26){
	if(found[i]){	  
	  int X1 = cross[i][0].x, Y1 = cross[i][0].y, X2 = cross[i][1].x, Y2 = cross[i][1].y;
	  int x1 = alpha[i][0].x, y1 = alpha[i][0].y, x2 = alpha[i][1].x, y2 = alpha[i][1].y;
	  char c = 'A'+i;
	  
	  if(x1 == x2){
	    flag = checkW(y1, y2, x1, c);
	  }
	  else if(y1 == y2){
	    flag = checkH(x1, x2, y1, c);	    
	  }
	  else{
	    if(((checkH(X1, x2, Y1, c) && (checkW(Y1, y1, X1, c)))) ||
	       ((checkH(X2, x1, Y2, c) && (checkW(Y2, y2, X2, c))))){
	      flag = true;
	    }
	  }
	  
	  if(flag){
	    //cout << c << endl;
	    found[i] = false;
	    ans += 2;
	    field[y1][x1] = '.', field[y2][x2] = '.';	    
	    goto Start;
	  }
	  
	}
      }
      if(!flag) break;
    }
    cout << ans << endl;
  }  
  return 0;
}

Measured memory_bytes: 1452
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoderTemplate.MyInputOutputs;

namespace AtCoderTemplate {
    public class Program {
        public static void Main (string[] args) {
            var NK = ReadLongs ();
            var N = NK[0];
            var K = NK[1];
            var ab = ReadIntColumns ((int) N);
            var a = ab[0];
            var b = ab[1];

            var sortIndex = a.SortIndex ().ToList ();
            var sortB = sortIndex.Select (i => (long) b[i]);
            var cumsum = sortB.Scanl1 ((x, y) => x + y);
            var ansIndex = cumsum.TakeWhile (cum => cum < K).Count () + 1 - 1;
            Print (a[sortIndex[ansIndex]]);
        }
    }

    public static class MyInputOutputs {
        /* Input & Output*/
        public static List<int> ReadInts () {
            return Console.ReadLine ().Split (' ').Select (c => int.Parse (c)).ToList ();
        }
        public static List<long> ReadLongs () {
            return Console.ReadLine ().Split (' ').Select (c => long.Parse (c)).ToList ();
        }
        public static List<List<int>> ReadIntColumns (int n) {
            /*
            入力例
            A1 B1
            A2 B2
            ...
            An Bn

            出力例
            [[A1,A2,...,An], [B1,B2,...,Bn]]
            */
            var rows = Enumerable.Range (0, n).Select (i => ReadInts ()).ToList ();
            var m = rows.FirstOrDefault ()?.Count () ?? 0;
            return Enumerable.Range (0, m).Select (i => rows.Select (items => items[i]).ToList ()).ToList ();
        }
        public static void Print<T> (T item) {
            Console.WriteLine (item);
        }
    }

    public static class MyExtensions {

        /// <summary>
        /// 累積項を要素にもつシーケンスを得る（初項は、source.First()）
        /// <para>O(N)</para>
        /// </summary>
        /// <param name="source">元のシーケンス</param>
        /// <param name="func">2引数関数f</param>
        /// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example>
        public static IEnumerable<T> Scanl1<T> (this IEnumerable<T> source, Func<T, T, T> func) {
            var list = source.ToList ();
            var result = new List<T> { list[0] };
            foreach (var i in Enumerable.Range (1, source.Count () - 1)) {
                result.Add (func (result[i - 1], list[i]));
            }
            return result;
        }

        /// <summary>
        /// 昇順にソートしたインデックスを得る
        /// </summary>
        /// <para>O(N * log N)</para>
        public static IEnumerable<int> SortIndex<T> (this IEnumerable<T> source) {
            return source
                .Select ((item, i) => new { Item = item, Index = i })
                .OrderBy (x => x.Item)
                .Select (x => x.Index);
        }
    }
}

Measured memory_bytes: 36452
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	VE d(k); rep(i, k)cin >> d[i];
	vector<char>copy(k); rep(i, k)copy[i] = d[i] + '0';
	for (int i = n; i <= 10 * n; i++) {
		string tmp = to_string(i);
		bool ok = true;
		rep(j, tmp.size()) {
			rep(t, k) {
				if (tmp[j] == copy[t])ok = false;
			}
		}
		if (ok) {
			cout << tmp << endl; return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
    FastIO;
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> red(a), greeen(b), free(c);
    rep(i, a) cin >> red[i];
    rep(i, b) cin >> greeen[i];
    rep(i, c) cin >> free[i];

    sort(rall(red));
    sort(rall(greeen));
    sort(rall(free));
    int ri = x-1, gi = y-1;
    int i = 0;
    while(i < c){
        bool rOk = (ri >= 0), gOk = (gi >= 0);
        bool ch = false;
        if (rOk && gOk){
            if (red[ri] > greeen[gi]){
                if (greeen[gi] < free[i]){
                    ch = true;
                    greeen[gi] = free[i];
                    gi--;
                }
            }else{
                if (red[ri] < free[i]){
                    ch = true;
                    red[ri] = free[i];
                    ri--;
                }
            }
        }else if(rOk){
            if (red[ri] < free[i]){
                ch = true;
                red[ri] = free[i];
                ri--;
            }
        }else if(gOk){
            if (greeen[gi] < free[i]){
                ch = true;
                greeen[gi] = free[i];
                gi--;
            }
        }
        if (!ch) break;
        i++;
    }
    ll ans = 0;
    rep(i, x) ans += red[i];
    rep(i, y) ans += greeen[i];
    cout << ans << endl;
}

Measured memory_bytes: 4468
#include <algorithm>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef vector<int> VI;

/*
 * Suffix Array.
 * Required Headers: algorithm, cassert, string, vector
 * Verified by: http://arc050.contest.atcoder.jp/submissions/818745
 * Reference: http://mayokoex.hatenablog.com/entry/2016/04/03/145845
 */
struct compare_sa {
  const std::vector<int> &rank;
  int n, k;
  compare_sa(const std::vector<int> &rank, int n, int k) : rank(rank), n(n), k(k) {}
  bool operator () (int i, int j) {
    if (rank[i] != rank[j]) {
      return rank[i] < rank[j];
    }
    int ri = i + k <= n ? rank[i + k] : -1;
    int rj = j + k <= n ? rank[j + k] : -1;
    return ri < rj;
  }
};

std::vector<int> create_sa(const std::string& s) {
  int n = s.length();
  std::vector<int> sa(n + 1, -1);
  std::vector<int> rank(n + 1, -1);
  std::vector<int> tmp(n + 1, -1);
  
  for (int i = 0; i <= n; ++i) {
    sa[i] = i;
    rank[i] = i < n ? s[i] : -1;
  }
  
  for (int k = 1; k <= n; k *= 2) {
    compare_sa cp = compare_sa(rank, n, k);
    std::sort(sa.begin(), sa.begin() + n + 1, cp);
    tmp[sa[0]] = 0;
    for (int i = 1; i <= n; ++i) {
      tmp[sa[i]] = tmp[sa[i - 1]] + (cp(sa[i - 1], sa[i]) ? 1 : 0);
    }
    for (int i = 0; i <= n; ++i) {
      rank[i] = tmp[i];
    }
  }
  return sa;
}

int main(void){
  int k;
  string s;
  cin >> k >> s;
  if (k == 0) {
    cout << s << endl;
    return 0;
  }
  int n = s.length();
  VI sa = create_sa(s);
  VI sa_inv(n + 1);
  REP(i, 0, n + 1) {
    sa_inv[sa[i]] = i;
  }
  VI sat;
  int q = (n + k) / (k + 1);
  int r = q * (k + 1) - n; // 0 <= r <= k
  REP(i, 0, sa.size()) {
    int w = sa[i];
    if (w <= n - q) {
      sat.push_back(w);
    }
  }
  int lo = -1;
  int hi = n - q + 1;
  while (hi - lo > 1) {
    int mid = (hi + lo) / 2;
    // try to divide, so that all the divided strings <= s[sat[mid]..]
    // We want to avoid making more than r strings of length q - 1.
    int rem = r;
    REP(i, 0, k + 1) {
      if (rem < 0) {
	break;
      }
      int idx = i * q - r + rem;
      if (idx >= n - q + 1) {
	break;
      }
      if (sa_inv[idx] > sa_inv[sat[mid]]) {
	rem--;
      }
    }
    if (rem >= 0) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout << s.substr(sat[hi], q) << endl;
}


Measured memory_bytes: 2032
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef vector<int> ivec;
typedef vector<string> svec;

int a[200020];
int main(){
	int K,N;
	int sa=0;
	cin>>K>>N;
	for(int i=0;i<N;i++)cin>>a[i];
	for(int i=0;i<N-1;i++)
	{
		sa=max(sa,a[i+1]-a[i]);
	}
	sa=max(sa,a[0]-a[N-1]+K);
	cout<<K-sa<<endl;
	
} 


Measured memory_bytes: 1024
def stream():
    n,m=map(int,input().split())
    x=[int(i) for i in input().split()]

    x.sort()

    if n>=m:
        print(0)
        exit()

    L=[0]*(m-1)

    for i in range(m-1):
        L[i]=x[i+1]-x[i]

    L.sort(reverse=True)

    ans=sum(L[n-1:])


    return ans
print(stream())

Measured memory_bytes: 52904
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll n,h[100010],b=-1e18,ans=0;

void init(){
	cin>>n;
	rep(i,n)cin>>h[i];
	cerr<<"初期化終了"<<endl;
}

int main(void){
	init();
	rep(i,n){
		if(b<=h[i]){
			ans++;
			b=h[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int main() {
  int N;
  cin >> N;
  vector<int> x(N + 1, 0), y(N + 1, 0), t(N + 1, 0);
  rep(i, N) cin >> t.at(i + 1) >> x.at(i + 1) >> y.at(i + 1);

  bool can = true;

  rep(i, N) {
    int a = abs(x[i] - x[i + 1]) + abs(y[i] - y[i + 1]);
    int b = t[i + 1] - t[i];
    if (a > b || a % 2 != b % 2) {
      can = false;
      break;
    }

  }

  cout << (can ? "Yes" : "No") << endl;
}


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

int main()
{
   string s,t;
   cin>>s>>t;
   int n = s.size();
   int n2 = t.size();
   for(int i=0;i<n;i++)
   {
       if(s[i]!=t[i])
       {
           cout<<"No"<<endl;
           return 0;
       }
   }
   if(n2!=n+1) cout<<"No"<<endl;
   else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3592
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    MOD = 998244353

    def makeBIT(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        data = [0] * (numPow2+1)
        return data, numPow2
    def setInit(As):
        for iB, A in enumerate(As, 1):
            data[iB] = A
        for iB in range(1, numPow2):
            i = iB + (iB & -iB)
            data[i] += data[iB]
    def addValue(iA, A):
        iB = iA + 1
        while iB <= numPow2:
            data[iB] += A
            iB += iB & -iB
    def getSum(iA):
        iB = iA + 1
        ans = 0
        while iB > 0:
            ans += data[iB]
            iB -= iB & -iB
        return ans
    def getRangeSum(iFr, iTo):
        return getSum(iTo) - getSum(iFr-1)


    N, K = map(int, input().split())
    LRs = [tuple(map(int, input().split())) for _ in range(K)]

    data, numPow2 = makeBIT(N)

    addValue(0, 1)

    for i in range(1, N):
        v = 0
        for L, R in LRs:
            x, y = i-R, i-L
            if y < 0:
                continue
            if x < 0:
                x = 0
            v += getRangeSum(x, y) % MOD
            v %= MOD
        addValue(i, v)

    ans = getRangeSum(N-1, N-1) % MOD
    print(ans)


solve()


Measured memory_bytes: 71080
#abc139c
N = int(input())
list_H = list(map(int, input().split()))

ans =[]
move_count=0

if N!=1:
    for i in range(1,N,1):
        if list_H[i-1]>=list_H[i]:
            move_count+=1

            if i==N-1:
                ans.append(move_count)
        else:
            ans.append(move_count)
            move_count=0

    if len(ans)!=0:
        print(max(ans))
    else:
        print("0")
else:
    print("0")

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

int main() {
  int n;
  while(cin >> n, n) {
    int m; cin >> m;
    string s; cin >> s;

    int len = 2*n + 1;
    string io = "I";
    for(int i = 0; i < n; i++) io += "OI";


    int ans = 0;
    for(int i = 0; i < m-len; i++) {
      if(io == s.substr(i, len)) ans++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2124
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


vec h(100010);
bool simu(ll num){
    ll choice = 0, bomb = B * num;
    rep(i,N){
        if(bomb < h[i]) {
            choice += 1 + (h[i] - bomb - 1)/(A - B);
        }
    }
    return num >= choice;
}

int main() {
    cin>>N>>A>>B;
    rep(i,N) cin>>h[i];
    ll lb = 0, ub = (1e+9) + 1;
    while(ub - lb > 1){ // (lb,ub]
        ll cen = (ub + lb)/2;
        (simu(cen) ? ub : lb) = cen;
    }
    cout<<ub<<endl;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;

  using ll = long long;
  ll ans = 0, min_n = 0, i = 0;
  while (i < s.size()) {
    if (s[i] == '<') {
      ans += min_n++;
      i++;
    } else {
      ll j = i, len = 1;
      while (j < s.size() && s[j] == s[i]) {
        j++;
        len++;
      }

      ll mx = max(min_n, len - 1);
      ans += mx;
      // len == 1: 0
      // len == 2: 0, 1
      // len == 3: 0, 1, 2
      ans += (len - 1) * (len - 2) / 2;
      min_n = 0;
      i += len - 1;
    }
  }

  if (s.back() == '<') {
    ans += min_n;
  }

  cout << ans << '\n';
  return 0;
}

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

// @@ !! LIM(UnionFind)
// --> UnionFind
// ---- inserted library file UnionFind.cc

class UnionFind {
protected:
  int size;
  vector<int> _leader;
  vector<int> _rank;
  vector<int> _gsize;
  unordered_map<int, vector<int>> _groups;
  
public:
  UnionFind(int s);
  int leader(int i);
  int merge(int i, int j);
  int groupSize(int i);
  const unordered_map<int, vector<int>>& groups();
  const vector<int>& group(int i);
};

UnionFind::UnionFind(int s) {
  size = s;
  _leader = vector<int>(size);
  for (int i = 0; i < size; i++) { _leader.at(i) = i; }
  _rank = vector<int>(size, 1);
  _gsize = vector<int>(size, 1);
}

int UnionFind::leader(int i) {
  int cur = i;
  int nxt = _leader.at(cur);
  vector<int> seen;
  while (cur != nxt) {
    seen.push_back(cur);
    cur = nxt;
    nxt = _leader.at(cur);
  }
  for (auto j : seen) _leader.at(j) = cur;
  return cur;
}

int UnionFind::merge(int i0, int j0) {
  if (!_groups.empty()) {
    cerr << "merge() cannot be called after group() or groups()." << endl;
    exit(1);
  }
  int li = leader(i0);
  int lj = leader(j0);
  if (li == lj) return li;
  int ri = _rank.at(li);
  int rj = _rank.at(lj);
  int rep = li;
  int other = lj;
  if      (ri <  rj) swap(rep, other);
  else if (ri == rj) _rank.at(rep)++;
  _leader.at(other) = rep;
  _gsize.at(rep) += _gsize.at(other);
  return rep;
}

int UnionFind::groupSize(int i) {
  return _gsize.at(leader(i));
}

const unordered_map<int, vector<int>>& UnionFind::groups() {
  if (_groups.empty()) {
    for (int i = 0; i < size; i++) _groups[leader(i)].push_back(i);
  }
  return _groups;  
}

const vector<int>& UnionFind::group(int i) { return groups().at(leader(i)); }



// ---- end UnionFind.cc
// @@ !! LIM  -- end mark --

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, Q; cin >> N >> Q;
  UnionFind uf(N);
  for (ll _q = 0; _q < Q; _q++) {
    ll t, u, v; cin >> t >> u >> v;
    if (t == 0) uf.merge(u, v);
    else {
      cout << (uf.leader(u) == uf.leader(v) ? 1 : 0) << "\n";
    }
  }


  return 0;
}



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

int main(){
    string a[3] = {"Sunny", "Cloudy", "Rainy"};
    string in;
    cin >> in;
    for(int i = 0 ; i < 3; i++) {
        if(in == a[2]) {
            cout << a[0];
            break;
        }
        if(in == a[i]){
            cout << a[i+1];
        }
    }
    return 0;
}


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

int main() {
	int R,G,B,N,cont=0;
	cin>>R>>G>>B>>N;
	for(int i=0;i*R<=N;i++){
		for(int j=0;j*G<=N;j++){
			if((N-i*R-j*G)>=0 and (N-i*R-j*G)%B==0) cont++;
		}
	}
	cout<<cont;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main(){
ll N;cin >> N;
vector<ll> V(N);
vector<ll> Ans(N);

rep(i, 0, N){

    cin >> V[i];

    if(i%2 == 0)Ans[0] += V[i];

    else Ans[0] -= V[i];

}

rep(i, 0, N - 1){

    Ans[i + 1] = 2*V[i] - Ans[i];

}

for(auto ans : Ans )cout << ans << " ";

}

Measured memory_bytes: 4840
import math
eps = 10**(-8)
N,K = map(int,input().split())
L = min(N,K-1)
cnt = 0
for i in range(1,L+1):
    a = math.log(K/i)/math.log(2)
    if abs(a-round(a))<eps:
        a = round(a)
    else:
        b = int(a)
        if a>b+eps:
            a = b+1
        else:
            a = b
    cnt += 2**(-a)
print(max(1-(K-1)/N,0)+cnt/N)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){

	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;

	if(W>=x+r && H>=y+r && 0<=x-r && 0<=y-r){

		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}




	return 0;
}


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

int main() {
	int n;
	cin >> n;
	tuple<string, int, int> s[111];
	for (int i = 0; i < n; i++) {
		string a;
		int b;
		cin >> a >> b;
		s[i] = tuple<string, int, int>(a, -b, i + 1);
	}
	sort(s, s + n);
	for (int i = 0; i < n; i++)
		cout << get<2>(s[i]) << '\n';
	cout << flush;
	return 0;
}


Measured memory_bytes: 256
import math
n, k = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]

min_place = a.index(1) + 1
left = math.ceil((min_place - 1) / (k-1)) 
left_lest = 0
if left != 0 and (min_place - 1) % (k-1) != 0:
  left_lest = (k-1) - (min_place - 1) % (k-1)
  
right = math.ceil((n - min_place - left_lest) / (k-1))
print(left + right)

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

int main() {
  int a[11] = {};
  int b;
  for( int i = 0; i < 4; ++i ) {
    cin >> b;
    a[b]++;
    
  }
  
  if( a[1] == 1 && a[7] == 1 && a[4] == 1 && a[9] == 1 ) cout << "YES";
  else cout << "NO";
  cout << endl;
  
  return 0;
  
}

    
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++) cin >> q[i];
    vector<int> a(n);
    for(int i = 0; i < n; i++) a[i] = i+1;
    map<vector<int>, int> mp;
    do{
        mp[a] = mp.size();
    }while(next_permutation(a.begin(), a.end()));
    
    int ans = abs(mp[p] - mp[q]);
    cout << ans;
    
}


Measured memory_bytes: 5248
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Reachable Towns
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

struct Trpl {
  int y, x, i;
  Trpl() {}
  Trpl(int _y, int _x, int _i): y(_y), x(_x), i(_i) {}

  bool operator<(const Trpl &t) const { return y < t.y; }
};

struct UFT {
  int links[MAX_N], ranks[MAX_N], sizes[MAX_N];
  UFT() {}

  void init(int n) {
    for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1;
  }

  int root(int i) {
    int i0 = i;
    while (links[i0] != i0) i0 = links[i0];
    return (links[i] = i0);
  }

  int rank(int i) { return ranks[root(i)]; }
  int size(int i) { return sizes[root(i)]; }
  bool same(int i, int j) { return root(i) == root(j); }

  int merge(int i0, int i1) {
    int r0 = root(i0), r1 = root(i1), mr;
    if (r0 == r1) return r0;
    if (ranks[r0] == ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      ranks[r0]++;
      mr = r0;
    }
    else if (ranks[r0] > ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      mr = r0;
    }
    else {
      links[r0] = r1;
      sizes[r1] += sizes[r0];
      mr = r1;
    }
    return mr;
  }
};

/* global variables */

Trpl ts[MAX_N];
UFT uft;
int q[MAX_N], cs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++)
    scanf("%d%d", &ts[i].x, &ts[i].y), ts[i].i = i;
  sort(ts, ts + n);

  uft.init(n);

  int qt = 0;
  for (int i = 0; i < n; i++) {
    int xi = ts[i].x, j = -1;
    while (qt > 0 && ts[q[qt - 1]].x < xi) {
      if (j < 0) j = q[qt - 1];
      uft.merge(ts[q[--qt]].i, ts[i].i);
    }
    q[qt++] = (j >= 0) ? j : i;
  }

  for (int i = 0; i < n; i++) cs[ts[i].i] = uft.size(ts[i].i);
  for (int i = 0; i < n; i++) printf("%d\n", cs[i]);
  return 0;
}


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

int n;

void init(){
 n=0;
}

bool input(){
  cin>>n;
  if(n==-1)return false;
  return true;
}

string ans(){
  string res="";
  while(n!=0){
    res=char(n%4+'0')+res;
    n/=4;
  }
  if(res.size()==0)res="0";
  return res;
}

int main(){
  while(init(),input()){
    string a=ans();
    cout<<a<<endl;
  }
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#define N 1005
using namespace std;
typedef long long ll;
ll n,v,a[N],b[N],c[N],d[N];
vector<ll> X,Y;

int main(){
  cin>>n>>v;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<n;i++)cin>>c[i];
  for(int i=0;i<n;i++)cin>>d[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      X.push_back(a[i]+b[j]);
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      Y.push_back(c[i]+d[j]);
  Y.push_back((1e17));
  sort(Y.begin(),Y.end());
  ll ans=0;
  for(int i=0;i<X.size();i++){
    vector<ll>::iterator x=upper_bound(Y.begin(),Y.end(),v-X[i]);
    vector<ll>::iterator y=lower_bound(Y.begin(),Y.end(),v-X[i]);
    ans+=x-y;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 23068