akhauriyash/Code-Regression huggingface dataset:
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)*}
    };
}

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

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")
    };
}
use std::collections::HashMap;
fn main(){
    input!{
        n:usize,
        an:[usize;n],
    }
    let mut map = HashMap::new();
    for &a in &an{
        *map.entry(a).or_insert(0) += 1;
    }
    let mut ans = 0;
    for (&k,&v) in &map {
        if k > v {
            ans += v;
        } else if k < v {
            ans += (v-k);
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 12540
#include <bits/stdc++.h> //AtCoder
#include <iostream> //Codeforces
#include <vector> //Codeforces

#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Vc vector<char>
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}//最大公約数
int lcm(int a,int b){return a/gcd(a,b)*b;}//最小公倍数

/****************************** START ******************************/

signed main(){
  string N;
  cin >> N;
  
  int sum = 0;
  rep(i,0,N.size()){
    sum += N.at(i) - 48;
  }
  if (sum % 9 == 0){
    cYes;
  } else {
    cNo;
  }
}

Measured memory_bytes: 3748
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n';
#define no cout<<"No"<<'\n';
using namespace std;

int main()
{
    godspeed
    ll  i,j,k,l,n,r,ans=0;
    string s;
    cin>>n;
    while(n--)
    {
        cin>>l>>r;
        ans+=abs(l-r)+1;
    }
    cout<<ans<<endl;

    return 0;
}





Measured memory_bytes: 3604
#include<iostream>
#include<utility>
#include<algorithm>
#include <vector>
using namespace std;

int n;
int a[1000000];
int b[1000000];
vector <pair<int,int> > v;

bool comp(pair<int,int> a,pair <int,int> b){
    if(a.second != b.second){
        return a.second<b.second;
    }
    else{
        return a.first < b.first;
    }
}
int main(){
    cin >> n;
   
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        v.push_back(make_pair(a,b));
    }
    
    sort(v.begin(),v.end(),comp);
/*
    for(int i =0;i<n;i++){
        cout << v[i].first << " " <<v[i].second << endl;
    }
  
  */  int now = 0;
    for(int i=0;i<n;i++){
        if(v.at(i).second >=(v.at(i).first+now)){
            now += v.at(i).first;
        }
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;

}

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010;
const double eps = 1e-6;

int n, k;

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

    double res = 0.0;
    for(int i = 1; i <= n; i++)
    {
        int s = i;
        double rate = 1.0;
        while(s < k)
        {
            s *= 2;
            rate *= 0.5;
        }
        res += rate;
    }

    printf("%.9f\n", res / (double)n);
    return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    string s;
    int ans = 0;
    cin >> s;
    sort(s.begin(), s.end());
    for (int i = 1; i < s.length(); i++) {
        if (s[i] == s[i - 1]) {
            ans++;
        }
    }
    if (ans == 2) {
        cout << "Yes" << "\n";
    } else {
        cout <<"No" << "\n";
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int a, b, c;
    cin >> a >> b >> c;

    int x = max(a, max(b, c));
    int ans = a + b + c - x + x * 10;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<stdio.h>
#include<vector>
#include<map>
using namespace std;

char s[4];
char tmp;
int a, b;

int main() {
	for (int i = 0; i < 4; i++) {
		cin >> s[i];
	}
	sort(s, s + 4);
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2] &&s[1]!=s[3]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
n,x=map(int,input().split())
X=list(map(int,input().split()))
for i in range(n):
  X[i]=abs(X[i]-x)
def gcd(p,q):
  if q==0:
    return p
  else:
    return gcd(q,p%q)
stack=X[0]
for i in range(n-1):
  stack=gcd(stack,X[i+1])
print(stack)

Measured memory_bytes: 15020
#include<stdio.h>
#define N 1e10
int main(){
    int n, x=N, y, Ans=-N, i;
    scanf("%d", &n);
    scanf("%d",&y);

    for(i=1; i<n; i++){
        if(x > y) x = y;
        scanf("%d",&y);
        if(Ans < (y - x)) Ans = (y - x);
    }
    printf("%d\n",Ans);
    
    return 0;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

static const int MAX = 200000;

int main()
{
    //int R[MAX];
    lol n; cin >> n;
    //int k; cin >> k;
    
    vector<int> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }

    int maxv = -2000000000;
    int minv = a[0];

    FOR(i, 1, n - 1)
    {
        maxv = max(maxv, a[i] - minv);
        minv = min(minv, a[i]);
    }
    

    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3528
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: u32 = read();
    //println!("{:#?}", (1..2).len());
    let ans = (1..n + 1).filter(|x| {
        (x).to_string().len() % 2 == 1
    }).count();
    println!("{:#?}", ans)
}


fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }


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

    int a, b; char op;
   
   while(cin >> a >> op >> b) {
       if(op == '?') return 0;
       if(op == '+') cout << a + b << endl;
       if(op == '-') cout << a - b << endl;
       if(op == '*') cout << a * b << endl;
       if(op == '/') cout << a / b << endl;
   }

    
}


Measured memory_bytes: 3088
#include <iostream>
using namespace std;
int main(){
	int a , b;
	cin >> a >> b;
	if(a>b) {
		cout << "a > b" << endl;
	} else if (a<b) {
		cout << "a < b" << endl;
	} else {
		cout << "a == b" << endl;
	}
	return 0;
}

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

int main() {
    ll n,m,i,j;
    cin>>m>>n;
    ll a[n+1];
    for(i=1;i<=n;i++)    cin>>a[i];
    sort(a+1,a+n+1);
    ll difs=0;
    priority_queue<ll> pq;
    for(i=1;i<=n;i++)
    {
        if(i>1 && i<n)
        {
            //pq.push(min({a[i]-a[i-1],a[i+1]-a[i]),i});
        }
        if(i>1)    
        {
            difs += a[i]-a[i-1];
            pq.push(a[i]-a[i-1]);
        }
    }
    if(m==1)
        cout<<difs;
    else
    {
        m--;
        while(m-- && !pq.empty())
        {
            
            //pll pnt = pq.top();
            //p[pnt.second] = 1;
            pq.pop();
        }
        ll ans = 0;
        while(!pq.empty())
        {
            ans += pq.top();
            pq.pop();
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 2168
import java.util.Scanner;

class Main{
	public static void main(String[] ag) {
		Scanner sc=new Scanner(System.in);
		int max=0;
		int nagasa=sc.nextInt();
		int point=0;
		String a=sc.next();

		for(int i=0; i<nagasa; i++) {
			if(a.charAt(i)=='D') {
				point--;
			}
			else if(a.charAt(i)=='I') {
				point++;
				if(point>max) {
					max=point;
				}
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL f[55][5210],x[55];
LL cl(LL k){return k+2500LL;}
int main()
{
	LL n,A,i,j;
	scanf("%lld %lld",&n,&A);
	for(i=1;i<=n;i++){scanf("%lld",&x[i]);x[i]-=A;}
	
	//f[i][j]前i个,凑出j的方案数
	memset(f,0,sizeof(f)); 
	f[0][cl(0)]=1;
	for(i=1;i<=n;i++)
	{
		for(j=-2500;j<=2500;j++)
		{
			if(j-x[i]>=-2500)f[i][cl(j)]+=f[i-1][cl(j-x[i])];
			f[i][cl(j)]+=f[i-1][cl(j)];
		}
	}
	printf("%lld",f[n][cl(0)]-1LL);
	return 0;
}

Measured memory_bytes: 2432
package main

import (
  "fmt"
)

func main() {
  var s string
  fmt.Scan(&s)

  fmt.Println(task(s))
}

func task(s string) string {
  var a,b int
  a = (len(s)-1)/2
  b = ((len(s)+3)/2)-1

  if s != reverse(s) {
    return "No"
  }
  if s[:a] != reverse(s[:a]) {
    return "No"
  }
  if s[b:] != reverse(s[b:]) {
    return "No"
  }
  return "Yes"
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int k = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		
		if(b-a+1 < k) 
			if(a%k > 0 &&  a%k <= b%k) {
				System.out.println("NG");
				return;
			}
		
		System.out.println("OK");
	}

}

Measured memory_bytes: 35776
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>

int main() {

   int N;
   std::cin >> N;
   int X[N];
   int X2[N];
   for (int i = 0; i < N; i++) {
      std::cin >> X[i];
      X2[i] = X[i];
   }
   std::sort(X, X+N);
   
   int tmp = N/2 - 1;
   int Xtmp = X[tmp];
   for (int i = 0; i < N; i++) {
        if (X2[i] <= Xtmp) std::cout << X[tmp + 1] << std::endl;
        else std::cout << X[tmp] << std::endl;
   }
   return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j;
	int num[3], k;

	for (i = 0; i < 3; i++) {
		cin >> num[i];
	}

	cin >> k;

	int maxn = 0, index = 0;

	for (i = 0; i < 3; i++) {
		if (maxn < num[i]) {
			maxn = num[i];
			index = i;
		}
	}

	for (i = 0; i < k; i++) {
		maxn = maxn * 2;
	}

	for (i = 0; i < 3; i++) {
		if (i == index)continue;
		maxn = maxn + num[i];
	}

	cout << maxn << endl;









	getchar();
	getchar();
	return 0;
}

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

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

    int low = 0;
    int high = 2*N;
    while (low < high)
    {
        int mid = (low+high)/2;
        int price = (double)mid * 1.08;
        if (price < N)
            low = mid+1;
        else
            high = mid;
    }
    int price = (double)low * 1.08;
    if (price == N)
        cout << low << endl;
    else 
        cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
from itertools import compress
MAXN = 1000001
p = [True]*MAXN
p[0] = p[1] = False
for i in xrange(int(MAXN**0.5)+1):
    if p[i]:
        for j in xrange(i+i,MAXN,i):
            p[j] = False
while True:
    n = input()
    if n == 0:
        break
    print sum(1 for i in compress(xrange(n/2+1),p) if p[n-i])

Measured memory_bytes: 12220
#include <stdio.h>

int main () {
    int A, B, C, K;
    scanf("%d %d %d", &A, &B, &C);
    scanf("%d", &K);

    for (int i = 0; i < K ; i++) {
        if (A > B && A > C) {
            A *= 2;
        } else if (B > C) {
            B *= 2;
        } else {
            C *= 2;
        }
    }
    int sum = A + B + C;

    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;
typedef long long ll;


int main(){
        string S;
        cin >> S;
        for(int i=0; i<S.size(); i++){
                if(i%2 == 0) cout << S[i];
        }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
  }
  long long ans=0;
  for(int i=n-1;i>=0;i--){
    ans+=(a[i]+ans+b[i]-1)/b[i]*b[i]-(ans+a[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1532
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    long n;
    cin >> n;
    n--;
    string ans = "";
    long q;
    long r;
    while(n >= 0)
    {
        q = n/26;
        r = n%26;
        ans.push_back((char)('a'+r));
        
        if(n<26) break;
        
        n = q-1;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    for(int i = 0; i < k; i++){
        if(a >= b) b *= 2;
        else if(b >= c) c *= 2;
    }
    //cout << a << b << c;
    if(a < b && b < c) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3640
s = input()

for i, c in enumerate(s):
    if (i + 1) % 2 == 0:
        if not (c == 'L' or c == 'U' or c == 'D'):
            print('No')
            break
    elif (i + 1) % 2 != 0:
        if not (c == 'R' or c == 'U' or c == 'D'):
            print('No')
            break
else:
    print('Yes')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
int main() {
    ll N;
    cin >> N;
    
    vector<ll> dp(N+1);
    dp[0] = 1;
    dp[1] = 1;
    rep3(i,2,N+1){
        dp[i] = dp[i-1] + dp[i-2];
    }

       
    cout << dp[N] << endl;



    return 0;
    

}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384626433832795

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}
struct node {
	vi to;
	int dist = -1;
	bool visited = false;
};

vector<node> g;
int t = 0;

void bfs(int n) {
	queue<pii> q;
	q.push({n,0});
	while (!q.empty()) {
		int dis = q.front().sc;
		int node = q.front().fs;
		q.pop();
		if (g[node].visited)continue;
		//cout << node + 1 << endl;
		g[node].dist = dis;
		g[node].visited = true;
		rep(i, g[node].to.size()) {
			if (!g[g[node].to[i]].visited)q.push({ g[node].to[i],dis + 1 });
		}
	}
}

int main(){
	int n,in,inn;
	cin >> n;
	g.resize(n);
	rep(i, n) {
		cin >> in;
		cin >> in;
		rep(j, in) {
			cin >> inn;
			g[i].to.push_back(inn-1);
		}
	}
	rep(i, n) {
		if (!g[i].visited) {
			bfs(0);
		}
	}
	rep(i, n) {
		cout <<i+1<<" "<< g[i].dist <<endl;
	}
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

int main() {
    ll N;
    cin >> N;
    vector<ll> bukas(N + 1, 0);
    for (ll i = 2; i <= N; i++) {
        ll a;
        cin >> a;
        bukas[a]++;
    }
    for (ll i = 1; i <= N; i++) {
        print(bukas[i]);
    }
}


Measured memory_bytes: 4848
/* bimillahir rahmanir rahim...
 * AUTHOR
 * mubin_akib */
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair <int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b) - 1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a) - 1; i >= 0; i--)
#define REP(i, a, b) for(int i = a; i <= (b); ++i)
#define trav(a,x) for(auto& a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const char nl = '\n';

int solve() {
    ll n, m;
    cin >> n >> m;
    if(n == m){
        cout << "Yes" << nl;
    }
    else{
        cout << "No" << nl;
    }
    return 0;
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll n,ans,ch[4000],L,A,B;
vector<ll> r,g,b,v;
int main(void){
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='R')r.push_back(i);
        else if(s[i]=='G')g.push_back(i);
        else{
            b.push_back(i);
            ch[i]=1;
        }
    }
    for(int i=0;i<r.size();i++){
        for(int j=0;j<g.size();j++){
            A=r[i],B=g[j];
            if(A<B)swap(A,B);
            L=A+(A-B);
            if(0<=L&&L<4000&&ch[L]==1)ans--;
            L=B-(A-B);
            if(0<=L&&L<4000&&ch[L]==1)ans--;
            if((A-B)%2==0){
                L=(A+B)/2;
                if(0<=L&&L<4000&&ch[L]==1)ans--;
            }
            ans+=(ll)b.size();
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3744
#include<stdio.h>
int main(void)
{
	int n;
	scanf("%d",&n);
	if(n>=65&&n<=90){
		printf("1\n");
	}
	else if(n>=97&&n<=122){
		printf("2\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}


Measured memory_bytes: 2052
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();
    static int K;
    public static void main(String[] args){
        K = in.i();
        LinkedList<Long>[][] list = new LinkedList[11][10];
        for (int d = 0; d <= 10; d++) {
            list[d] = new LinkedList[10];
            for (int i = 0; i < 10; i++) {
                list[d][i] = new LinkedList<>();
            }
        }
        for (int i = 0; i < 10; i++) {
            list[1][i].add((long)i);
        }
        int count = 9;
        if (K < 10) {
            out.println(K);
            return;
        }
        for (int d = 2; d <= 10; d++) {
            for (int i = 0; i < 10; i++) {
                if (i - 1 >= 0) {
                    for (long x : list[d-1][i-1]) {
                        count = f(list, d, i, x, count);
                    }                     
                } 
                for (long x : list[d-1][i]) {
                    count = f(list, d, i, x, count);
                }    
                if (i + 1 <= 9) {
                    for (long x : list[d-1][i+1]) {
                        count = f(list, d, i, x, count);
                    }                     
                } 
            }
        }
    }

    static int f(LinkedList<Long>[][] list, int d, int i, long x, int count){
        long y = i * pow10(d - 1) + x;
        if(i != 0) {
            count++;
        }
        if (count == K) {
            out.println(y);
            System.exit(0);
        } else {
            list[d][i].add(y);              
        }
        return count;
    }
    
    static long pow10(int d){
        long ret = 1;
        for (int i = 0 ; i < d; i++) {
            ret *= 10;
        }
        return ret;
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 25556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define invrep(i, n) for(int i = (n)-1; i >= 0; i--)        // n-1, n-2, ..., 0
#define invREP(i, x, n) for(int i = (n)-1; i >= (x; i--)    // n-1, n-2, ..., x
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define PB push_back

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

int main(){
    int N; cin >> N;
    vector<pi> red(N), blue(N);
    rep(i, N) cin >> red[i].second >> red[i].first; // (y, x) 
    rep(i, N) cin >> blue[i].first >> blue[i].second; // (x, y)
    sort(ALL(red), greater<pi>()); sort(ALL(blue)); 
    int ans = 0;

    int M = N;
    rep(i, N){
        rep(j, M){
            if(blue[i].first > red[j].second && blue[i].second > red[j].first){
                red.erase(red.begin() + j);
                ans++;
                M--;
                break;
            }
        }
    }
    COUT(ans);
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-     
import sys

s = input()
dstx, dsty = list(map(int,input().split()))
x = []
y = []
tmp = 0
xy = 0
for i in range(len(s)):
    if(s[i]=='F'):
        tmp += 1
    elif(s[i]=='T' and xy==0):
        x.append(tmp)
        tmp = 0
        xy = 1
    elif(s[i]=='T' and xy==1):
        y.append(tmp)
        tmp = 0
        xy = 0
else:
    if(xy==0):
        x.append(tmp)
    else:
        y.append(tmp)
dpx = [{} for i in range(len(x))]
dpy = [{} for i in range(len(y)+1)]
dpx[0][x[0]] = True
dpy[0][0] = True
for i, dx in enumerate(x[1:]):
    for j in dpx[i]:
        dpx[i+1][j+dx] = True
        dpx[i+1][j-dx] = True
if(dstx not in dpx[-1]):
    print('No')
    sys.exit()
for i, dy in enumerate(y):
    for j in dpy[i]:
        dpy[i+1][j+dy] = True
        dpy[i+1][j-dy] = True
    
if(dstx not in dpx[-1] or dsty not in dpy[-1]):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 388264
def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    ans = [0] * (N+1)
    num = [1] * (N+1)
    ans[1] = 1
    for _ in range(M):
        x, y = map(int, input().split())
        num[x] -= 1
        num[y] += 1
        if ans[x]:
            ans[y] = 1
            if num[x] == 0:
                ans[x] = 0
    print(sum(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 42348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    string s;
    cin >> s;
    string ans;

    rep(i, s.length())
    {
        if (s[i] == '0')
        {
            ans += '0';
        }
        if (s[i] == '1')
        {
            ans += '1';
        }
        if (s[i] == 'B')
        {
            if (!ans.empty())
            {
                ans.erase(ans.length() - 1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

long long x, y;
long long a, b;
long long xx = 1, yy = 1, zz;

long long ff(long long h, long long g)
{
	long long rr = 1;
	
	while(g > 0)
	{
		if(g % 2 == 1)
		{
			rr *= h;
			rr %= 1000000007;
		}
		
		h *= h;
		h %= 1000000007;
		g /= 2;
	}
	
	return rr;
}

int main(void)
{
	scanf("%lld %lld", &a, &b);
	
	if((a + b) % 3 != 0)
	{
		printf("0");
		return 0;
	}
	
	y = (2 * a - b) / 3;
	x = (2 * b - a) / 3;
	
	if(x < 0 || y < 0)
	{
		printf("0");
		return 0;
	}
	
	for(int i = 1 ; i <= x + y ; i++)
	{
		xx = (xx * i) % 1000000007;
	}
	
	for(int i = 1 ; i <= x ; i++)
	{
		yy = (yy * i) % 1000000007;
	}
	
	for(int i = 1 ; i <= y ; i++)
	{
		yy = (yy * i) % 1000000007;
	}
	
	zz = ff(yy, 1000000005);
	
	printf("%lld", (zz * xx) % 1000000007);
	return 0;
}

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

int main(){
while(1){
	bool T[205],F[205];
	fill(T,T+205,false);
	fill(F,F+205,false);
	int n,t,f,in,c=0;
	scanf("%d",&n);
	if(n==0)break;
	t=n; f=n;
	for(int i=0;i<n;i++){scanf("%d",&in); T[in]=true;}
	for(int i=1;i<=2*n;i++)if(!T[i])F[i]=true;
	while(1){
		for(int i=c+1;;i++){
			if(T[i]){t--; T[i]=false; c=i; break;}
			if(i>2*n){c=0; break;}
		}
		if(t==0)break;
		for(int i=c+1;;i++){
			if(F[i]){f--; F[i]=false; c=i; break;}
			if(i>2*n){c=0; break;}
		}
		if(f==0)break;
	}
	printf("%d\n%d\n",f,t);
}
}

Measured memory_bytes: 1172
s=input()
if s == "ABB" :
    print("Yes")
elif s == "AAB" :
    print("Yes")
elif s == "ABA" :
    print("Yes")
elif s == "BAA" :
    print("Yes")
elif s == "BBA" :
    print("Yes")
elif s == "BAB" :
    print("Yes")
else :
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

vector<ll> sizes;

ll solve(ll n,ll x){
    if(n==0) return 1;
    if(x<=1) return 0;
    if(x<=1+sizes[n-1]) return solve(n-1,x-1);
    if(x==2+sizes[n-1]) return solve(n-1,sizes[n-1])+1;
    if(x<sizes[n]-1){
        ll zan=x-2-sizes[n-1];
        return solve(n-1,sizes[n-1])+solve(n-1,zan)+1;
    }
    else return solve(n-1,sizes[n-1])*2+1;
}

int main(){
    ll n,x; cin >> n >> x;
    sizes.resize(51);
    sizes[0]=1;
    rep(i,51){
        sizes[i+1]=sizes[i]*2+3;
    }
    ll ans=solve(n,x);
    cout << ans << endl;
return 0;
}


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

num = 0

if N == 100000:
    num = 90909
elif 9999 < N < 100000:
    num = 909 + N -9999
elif 999 < N  <= 9999:
    num = 909
elif 99 < N <= 999:
    num = 9 + N -99
elif 9 < N <= 99:
    num = 9
else:
    num = N

print(num)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int zyo[4][3][10]={0},mune,kai,hidari,n,hito;
int in(){
cin>>n;
for(int a=0;a<n;a++){
cin>>mune>>kai>>hidari;
cin>>hito;
zyo[mune-1][kai-1][hidari-1]+=hito;
}
}
int out(){
for(int a=0;a<4;a++){
for(int b=0;b<3;b++){
for(int c=0;c<10;c++){
cout<<" "<<zyo[a][b][c];
}
cout<<endl;
}
if(a<3)
cout<<"####################"<<endl;
}
}
int main(){
in();
out();
return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

struct edge{int to;ll cap;int rev;};

int MAX_V=20050;
int tmp1,tmp2;

vector<vector<edge>> g(MAX_V);//グラフの隣接リスト表現
vin level(MAX_V);//distance form s
vin iter(MAX_V);//どこまで調べたか

void add_edge(int from,int to,ll cap=(ll)inf){
    tmp1=g[to].size();tmp2=g[from].size();
    g[from].push_back((edge){to,cap,tmp1});//g[to]のg[to].size()番目にfromが入っている
    g[to].push_back((edge){from,0,tmp2});//g[from]のg[from].size()-1番目にtoが入っている
}

void bfs(int s){
    fill(all(level),-1);
    queue<int> q;
    q.push(s);
    level[s]=0;
    while(q.size()){
        int v=q.front();q.pop();
        for(auto& e:g[v]){
            if(e.cap>0&&level[e.to]<0){
                level[e.to]=level[v]+1;
                q.push(e.to);
            }
        }
    }
}

//増加パスをdfsで探す
//v:今見てる頂点 t:終点 f:流量
int dfs(int v,int t,ll f){
    if(v==t)return f;
    for(int& i=iter[v];i<(int)g[v].size();i++){
        edge& e=g[v][i];
        if(e.cap>0&&level[v]<level[e.to]){
            ll d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                g[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

//sからtへの最大流を求める
int max_flow(int s,int t){
    ll flow=(ll)0;
    ll f;
    for(;;){
        bfs(s);
        if(level[t]<0)return flow;
        fill(all(iter),0);
        while((f=dfs(s,t,inf))>0)flow+=f;
    }
}

int main(){
    int h,w;cin>>h>>w;
    vstr S(h);
    rep(i,h)cin>>S[i];
    //各マスinとoutを2つ用意
    //(i,j)のinは2(i*w+j)で, outは2(i*w+j)+1で表される
    int s=2*h*w;//s→ヤギ
    int t=s+1;//追加したグリッドのマス(ゴール)→t
    int tmp;
    rep(i,h)rep(j,w){
        tmp=2*(i*w+j);
        if(S[i][j]=='X'){
            if(i==0||i==h-1||j==0||j==w-1){
                cout<<-1<<endl;
                return 0;
            }
            add_edge(tmp,tmp+1);
            add_edge(s,tmp);
        }
        else add_edge(tmp,tmp+1,(ll)1);
        if(i>0)add_edge(tmp+1,tmp-2*w);
        if(i<h-1)add_edge(tmp+1,tmp+2*w);
        if(j>0)add_edge(tmp+1,tmp-2);
        if(j<w-1)add_edge(tmp+1,tmp+2);
        if(i==0||i==h-1||j==0||j==w-1)add_edge(tmp+1,t);
    }
    cout<<max_flow(s,t)<<endl;
}

Measured memory_bytes: 7744
n,k=map(int,input().split())
mod=10**9+7
kaidan=[1]*(n+5)
gyaku=[1]*(n+5)
for i in range(n+3):
    kaidan[i+1]=((i+1)*kaidan[i])%mod
for i in range(n+3):
    gyaku[i+1]=pow(kaidan[i+1],mod-2,mod)
def comb(a,b):
    if a<=b:
        return 1
    else:
        return (kaidan[a] * gyaku[a-b] * gyaku[b])%mod
for i in range(1,k+1):
    if n-k+1<i:
        print(0)
    else:
        print((comb(n-k+1,i) * comb((k-i)+i-1, i-1))%mod)


Measured memory_bytes: 3444
#include<iostream>
#include<algorithm>

int R, C;
int senbei[11][10001];


int main(){
	while (std::cin >> R >> C, R|C){
		for (int i = 0; i < R; ++i) for (int j = 0; j < C; ++j)
			std::cin >> senbei[i][j];

		int ans = 0;
		for (int S = 0; S < 1 << R; ++S)
		{
			int cnt = 0;
			for (int j = 0; j < C; ++j)
			{
				int t = 0;
				for (int i = 0; i < R; ++i)
					t += senbei[i][j] ^ (S >> i & 1);

				cnt += std::max(t, R - t);
			}
			ans = std::max(ans, cnt);
		}

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

Measured memory_bytes: 1552
# 自分より左側には自分より小さい数しかないよってやつを調べる min更新
n = int(input())
arr = list(map(int, input().split()))
ans = 0
tmp = 10 ** 10
for a in arr:
    if tmp >= a:
        ans += 1
        tmp = min(tmp, a)
print(ans)


Measured memory_bytes: 24744
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define M 100010

int main(){
    
    ll a,b;cin>>a>>b;
    ll c=a*b;
    cout<<c;
    
    
    
    return 0;
}

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

int a[3];
int sol = 1e9;

int main(){

    cin >> a[0] >> a[1] >> a[2];

    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
            for (int k = 0; k < 3; k++){
                if (i == j || i == k || j == k) continue;
                sol = min(sol, abs(a[j]-a[i]) + abs(a[k]-a[j]));
            }

    cout << sol;

}


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

using namespace std;

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

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

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

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

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

using namespace std;

int main(){
    int n;
    while(cin>>n,n){
        vector<int>v(n);
        vector<vector<int>>dp(n+1,vector<int>(n+1,0));
        for(int i=0;i<n;++i){
            cin>>v[i];
        }
        for(int l=2;l<=n;++l){
            for(int i=0;i+l<n+1;++i){
                if(abs(v[i]-v[i+l-1]) < 2 && dp[i+1][i+l-1]==l-2)dp[i][i+l]=l;
                for(int j=1;j<l;++j){
                    dp[i][i+l]=max(dp[i][i+j]+dp[i+j][i+l],dp[i][i+l]);
                }
            }
        }
        cout<<dp[0][n]<<endl;
    }
}

Measured memory_bytes: 3248
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N, K = map(int, input().split())
    H = list(sorted([int(input()) for _ in range(N)]))
    ans = INF
    for i in range(N - K + 1):
        ans = min(ans, H[i + K - 1] - H[i])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9068
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int k; cin >> k;
    out(k/2 * (k-k/2));

    return 0;
}

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

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


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

int main() {
	string s; cin >> s;
	vector<int>ans(s.size());

	for (int rep = 0; rep < 2; rep++) {
		int cnt = 0;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == 'R')cnt++;
			else {
				ans[i] += cnt / 2;
				ans[i - 1] += (cnt + 1) / 2;
				cnt = 0;
			}
		}
		reverse(s.begin(), s.end());
		reverse(ans.begin(), ans.end());
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == 'L')s[i] = 'R';
			else s[i] = 'L';
		}
	}
	for (auto&& x : ans)cout << x << ' ';
	cout << endl;

	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;
    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
nums = ['3', '5', '7']
cnt = 0

def dfs(cur, s):
    global cnt
    if len(cur) > 0 and '3' in cur and '5' in cur and '7' in cur:
        cnt += 1
    for c in nums:
        cur.append(c)
        if int(''.join(cur)) > int(s):
            return
        newcur = cur.copy()
        dfs(newcur, s)
        cur.pop()

def main():
    s = S()
    N = len(s)
    cur = []
    dfs(cur, s)
    print(cnt)

main()



Measured memory_bytes: 6344
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
  int cnt=0,A[3];
  cin>>A[0]>>A[1]>>A[2];
  while(1){
    if(A[2]==A[1]&&A[1]==A[0]) break;
    sort(A,A+3);
    if(A[2]-A[1]>=1){
      A[1]++;
      A[0]++;
    }else A[0]+=2;
    cnt++;
  } 
  cout<<cnt<<endl;
}

Measured memory_bytes: 256