akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

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

fn dfs(v: usize, par: usize, g: &[Vec<usize>]) -> i64 {
    let mut a = 0;
    let mut cnt = vec![0; 60];
    for &w in &g[v] {
        if w == par { continue; }
        let sub = dfs(w, v, g);
        a |= sub;
        for i in 0..60 {
            if (sub & 1 << i) != 0 {
                cnt[i] += 1;
            }
        }
    }
    let mut twomax = 0;
    for i in 0..60 {
        if cnt[i] >= 2 {
            twomax = i;
        }
    }
    (a + (1 << twomax)) & (-1) << twomax
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        ab: [(usize1, usize1); n - 1],
    }
    let mut g = vec![vec![]; n];
    for &(a, b) in &ab {
        g[a].push(b);
        g[b].push(a);
    }
    let ret = dfs(0, n, &g);
    //eprintln!("ret = {}", ret);
    let mut ma = 0;
    for i in 0..60 {
        if (ret & 1 << i) != 0 {
            ma = i;
        }
    }
    puts!("{}\n", ma);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 39176
import math

def F(a, b):
  return len(str(a)) if a > b else len(str(b))

def main():
  N = int(input())
  ans = len(str(N))
  n_sq = math.floor(math.sqrt(N))

  for i in range(n_sq, 0, -1):
    if(N % i == 0):
      j = N // i
      ans = F(i, j)
      break

  print(ans)

if __name__ == "__main__":
    main()

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t a, b, c;
  std::cin >> a >> b >> c;
  std::set<int64_t> s;
  s.insert({a, b, c});

  if (s.size() == 2) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

vector<pair<ll,ll>> factors;
#include <queue>
void getPrimeFactorize(ll n_max) {
    for (long long a = 2; a * a <= n_max; ++a) {
        if (n_max % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (n_max % a == 0) {
            ++ex;
            n_max /= a;
        }

        // その結果を push
        factors.push_back({a, ex});
    }

    // 最後に残った数について
    if (n_max != 1) factors.push_back({n_max, 1});
}


ll llmin(ll a,ll b){
    if(a>=b) return b;
    return a;
}
ll llmax(ll a,ll b){
    if(a<=b) return b;
    return a;
}

vll yakusu;
void getYakusu(ll N){
    for( ll ni = 1 ; ni*ni <=N ; ni++ ){
        if(N%ni==0){
            yakusu.push_back(ni);
            if(N/ni!=ni) yakusu.push_back(N/ni);
        }
    }
    sort(yakusu.begin(),yakusu.end());
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    cin >> K;
    ll sumA=0;
    rep(ni,N){
        cin >> ltmp;
        A.push_back(ltmp);
        sumA+=ltmp;
    }

    ll ans = 0;
    getYakusu(sumA);
    rep(yi,yakusu.size()){
        ll tmpans = yakusu[yakusu.size()-1-yi];
        vll mods;
        rep(ni,N)  mods.push_back(A[ni]%tmpans);
        sort(mods.begin(),mods.end());
        ll left = 0;
        ll right = N-1;
        ll sum_l = 0;
        ll sum_r = 0;
        while(left<=right){
            if(sum_l<=sum_r){
                sum_l+=mods[left];
                left++;
            }else{
                sum_r += tmpans-mods[right];
                right--;
            }
        }
        if(sum_l==sum_r && sum_r <= K){
            ans = tmpans;
            break;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define rep(i,x) for(int (i)=1;(i)<=(x);(i)++)
#define repp(i,x,y) for(int (i)=(x);(i)<=(y);(i)++)
#define per(i,x,y) for(int (i)=(x);(i)>=(y);(i)--)
#define forn(i,x) for(int (i)=0;(i)<(x);(i)++)
#define foreach(i,x) for(auto i:x)
using namespace std;
typedef pair<int,int>pii;
int n,m,q;
vector<int>G[100010];
int v[100010],d[100010],c[100010],col[100010];
int now;
int used[100010];
inline void read(int &x){
    int f=1;x=0;char s=getchar();
    while(s<'0'||s>'9'){s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
}
inline void dfs(int x,int d){
	if(used[x]>=d)return;
	used[x]=d;
	if(!col[x])col[x]=now;
	foreach(to,G[x])if(d)dfs(to,d-1);
}
int main(){
	memset(used,-1,sizeof(used));
	read(n),read(m);
	for(int i=1,x,y;i<=m;i++){
		read(x),read(y);
		G[x].pb(y),G[y].pb(x);
	}
	read(q);
	rep(i,q)read(v[i]),read(d[i]),read(c[i]);
	reverse(v+1,v+q+1);
	reverse(d+1,d+q+1);
	reverse(c+1,c+q+1);
	for(int i=1;i<=q;i++){
		now=c[i];
		dfs(v[i],d[i]);
		// rep(i,n)cout<<col[i]<<' ';
		// puts("");
	}
	rep(i,n)cout<<col[i]<<endl;
	return 0;
}
/*
7 7
1 2
1 3
1 4
4 5
5 6
5 7
2 3
2
6 1 1
1 2 2
*/

Measured memory_bytes: 8440
A, B, C, K = map(int, input().split())


if A>= K:
    print(K*1)
    exit()
    
elif A < K and A+B >= K:
    print(A*1)
    exit()
    
elif A+B < K and A+B+C >= K:
    print(A*1 + (K-A-B)*(-1))


Measured memory_bytes: 9052
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(a==0){
        cout<<1;
        return 0;
    }
    else if(b==0){
        cout<<2;
        return 0;
    }
    else if(c==0){
        cout<<3;
        return 0;
    }
    else if(d==0){
        cout<<4;
        return 0;
    }
    else if(e==0){
        cout<<5;
        return 0;
    }

    
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  string s;
  cin >> s;
  int N = s.size();
  cout << s[0] << N-2 << s[N-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const ll INF = 1e18;
ll cost[2005][2005]; //d[u][v]は辺e = (u, v)のコスト。存在しない場合はINF,ただしd[i][j]=0とする。
int counts[2005][2005];
int N, M, Q;
ll L;

void warshall_floyd_cost() {
  rep(k, N){
    rep(i, N){
      rep(j, N) cost[i][j] =min(cost[i][j], cost[i][k]+cost[k][j]);
    }
  }
}

void warshall_floyd_counts() {
  rep(k, N){
    rep(i, N){
      rep(j, N) counts[i][j] =min(counts[i][j], counts[i][k]+counts[k][j]);
    }
  }
}

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

  cin >> N >> M >> L;
  int a,b;
  ll c;
  rep(i, N) rep(j, N) cost[i][j] = INF;
  rep(i, M) {
    cin >> a >> b >> c;
    a--;b--;
    cost[a][b] = c;
    cost[b][a] = c;
  }
  warshall_floyd_cost();
  rep(i, N) {
    rep(j, N) {
      if (cost[i][j] <= L) counts[i][j] = 1;
      else counts[i][j] = 1e9;
    }
  }
  cin >> Q;
  warshall_floyd_counts();
  int s, t;
  rep(i, Q) {
    cin >> s >> t;
    s--;t--;
    int ans=counts[s][t]=counts[s][t]==1e9?-1:counts[s][t]-1;
    cout << ans << "\n";
  }

  return 0;
}

Measured memory_bytes: 10112
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#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 chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  double A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  double con = 0;
  double sw = 0;
  double sug = 0;
  rep(i, F/(100*A) +1){
    rep(j, F/(100*B) +1){
      rep(k, F/C +1){
        rep(l, F/D +1){
          if(100*A*i + 100*B*j + C*k + D*l <= F){
            if((C*k + D*l)/(100*A*i + 100*B*j + C*k + D*l) >= con &&
              (A*i + B*j)*E >= (C*k + D*l)){
              sw = 100*A*i + 100*B*j + C*k + D*l;
              sug = C*k + D*l;
              con = (C*k + D*l)/(100*A*i + 100*B*j + C*k + D*l);
            }
          }
        }
      }
    }
  }
  cout << sw << " " << sug << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


//k!
ll facctorialMethod(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum = sum%MOD*i%MOD;
    }
    return sum%MOD;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int n;cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    int dp[100010];
    Fill(dp,INF);
    dp[0] = 0;
    for(int i = 1;i < n;i++){
        dp[i] = dp[i-1]+abs(v[i]-v[i-1]);
        if(i > 1)dp[i] = min(dp[i],dp[i-2]+abs(v[i] - v[i-2]));
    }
    cout << dp[n-1] << endl;
}



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

using ll=long long;
using namespace std;

int main(){
    ll n;cin>>n;
    ll a=0;

    for(ll i=2;i*i<=n;i++)
        if(n%i==0)a=i;
    cout<<(a!=0?(a+(n/a)-2):n-1);
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll mod = 1000000007;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, m; 
	cin>>n>>m;
	vector<ll> x(n), y(m);
	for(auto &a : x){
		cin>>a;
	}
	for(auto &b : y){
		cin>>b;
	}
	ll ansx = 0, ansy = 0;
	{
		ll sum = accumulate(x.begin(), x.end(), 0LL);
		for(int i = 0; i + 1 < n; i++){
			sum -= x[i];
			ansx += sum - (n - 1 - i)*x[i];
			ansx %= mod;
		}
	}
	{
		ll sum = accumulate(y.begin(), y.end(), 0LL);
		for(int i = 0; i + 1 < m; i++){
			sum -= y[i];
			ansy += sum - (m - 1 - i)*y[i];
			ansy %= mod;
		}
	}
	cout<<(ansx*ansy%mod)<<'\n';

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

const ll mod = 1000000007;
ll mod_pow(ll x, ll n){
    ll ret = 1;
    while(n > 0){
        if(n & 1){
            ret *= x;
            ret %= mod;
        }
        x *= x;
        x %= mod;
        n >>= 1;
    }
    return ret;
}

ll mod_inv(ll a){
    
    ll b = mod, u = 1, v = 0;
    while(b){
        ll t = a / b;
        a -= t * b; 
        swap(a, b);
        u -= t * v; 
        swap(u, v);
    }
    u %= mod;
    if (u < 0){
        u += mod;
    } 
    return u;
}


int main() {

    int n, a, b;
    cin >> n >> a >> b;

    ll ans = mod_pow(2, n);
    --ans;

    ll finv[200001] = {};
    finv[0] = finv[1] = 1;
    for (int i = 2; i <= min(200000, b); ++i){
        finv[i] = finv[i - 1] * i % mod;
    }

    ll fac[200001] = {};
    fac[1] = n;
    int idx = 2;
    for(ll i=n-1; i>=n-min(200000, b); --i){
        fac[idx] = fac[idx-1] * i;
        fac[idx] %= mod;
        idx++;
    }

    ll inva = mod_inv(finv[a]);
    ll invb = mod_inv(finv[b]);

    ans -= (fac[a] * inva) % mod;
    if(ans < 0){
        ans += mod;
    }
    ans -= (fac[b] * invb) % mod;
    if(ans < 0){
        ans += mod;
    }
    
    cout << ans % mod << endl;

    return 0;
}

Measured memory_bytes: 3328
import java.util.*;
import java.io.*;
class Main {
    static void dfs(int src, ArrayList<Integer>[] graph, boolean[] visited, int[] dist) {
        visited[src] = true;
        for(int i: graph[src]) {
            if(!visited[i])
                dfs(i, graph, visited, dist);
            dist[src] = Math.max(dist[src], dist[i]+1);
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Integer>[] graph = new ArrayList[n];
        for(int i = 0; i<n; i++)
            graph[i] = new ArrayList<>();
        for(int i = 0; i<m; i++) {
            int u = sc.nextInt()-1;
            int v = sc.nextInt()-1;
            graph[u].add(v);
        }
        int[] dist = new int[n];
        boolean[] visited = new boolean[n];
        for(int i = 0; i<n; i++) 
            if(!visited[i])
                dfs(i, graph, visited, dist);
        System.out.println(Arrays.stream(dist).max().getAsInt());
    }
}

Measured memory_bytes: 107616
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e6 + 10; 

vector<int> F[N];
int cnt[N];

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   f(i,1,N){
      for(int j = i; j < N; j+= i){
         F[j].pb(i);
      }
   }
   int n;
   cin >> n;
   vector<int> A(n);
   f(i,0,n){
      cin >> A[i];
      cnt[A[i]] += 1;
   }
   int ans = 0;
   f(i,0,n){
      int x = A[i];
      int v = -1;
      for(auto &e : F[x]){
         v += cnt[e];
      }
      if(v == 0) ans++;
   }
   cout << ans << '\n';
   return 0;
} 

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

int main() {
  int n;
  cin>>n;
  int ruiE[300005],ruiW[300005];
  ruiE[0]=0;ruiW[0]=0;
  string s;
  cin>>s;
  rep(i,n){
    if(s[i]=='W'){
      ruiW[i+1]=ruiW[i]+1;
      ruiE[i+1]=ruiE[i];
    }else{
      ruiE[i+1]=ruiE[i]+1;
      ruiW[i+1]=ruiW[i];
    }
  }
  int min_chng=900010;
  rep(i,n){
    int chng;
    chng=ruiW[i]+(ruiE[n]-ruiE[i+1]); 
    min_chng=min(min_chng,chng);
  }
  cout<<min_chng<<endl;
}

Measured memory_bytes: 2948
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC066B
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();

            int l = S.Length;

            if (l % 2 == 0)
                l -= 2;
            else
                l--;

            for (; l > 0; l -= 2)
            {
                string s = S.Substring(0, l);
                string t = s.Substring(0, l / 2);
                string u = s.Substring(l / 2, l / 2);
                if (t == u)
                {
                    Console.WriteLine(l);
                    break;
                }
            }

        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int a[40],b[40],c[40];
int n,ma,mb;

const int nmax=40;
const int abmax=10;
const int inf=10000000;
int dp[41][400+1][400+1];



int main(){
   
    cin>>n>>ma>>mb;
    
    rep(i,n){
        cin>>a[i]>>b[i]>>c[i];
    }
    
    for(int i=0;i<=n;i++){
        for(int j=0;j<=nmax*abmax;j++){
            for(int k=0;k<=nmax*abmax;k++){
                dp[i][j][k]=inf;
            }
        }
    }
    dp[0][0][0]=0;
    
    for(int i=0;i<n;++i){
        for(int ca=0;ca<=nmax*abmax;++ca){
            for(int cb=0;cb<=nmax*abmax;++cb){
                if(dp[i][ca][cb]==inf)continue;
                dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb]);
                dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]);
            }
        }
    }
   
    
    int ans=inf;
    for(int ca=1;ca<=nmax*abmax;++ca){
        for(int cb=1;cb<=nmax*abmax;++cb){
            if(ca*mb==cb*ma)ans=min(ans,dp[n][ca][cb]);
        }
    }
    
    if(ans==inf)ans=-1;
    cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 25984
#include<iostream>
using namespace std;
const int MAXN=105;
int A[MAXN];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	int res=0;
	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(A[j]<A[j-1]){
				swap(A[j],A[j-1]);
				res++;
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<A[i];
		if(i!=n-1)cout<<" ";
	}
	cout<<endl;
	cout<<res<<endl;
	return 0;
}



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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(b-a == c-b){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
//#include<stdlib.h>
using namespace std;
int main() {
	int i,t=0,s=0;
	cin >> i;
	vector<int>h(i);
	for (int a = 0; a < i; a++) { cin >> h[a]; }
	for (int a = 0; a < i; a++)
	{
		if (t <= h[a]) { t = h[a]; s++; }
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int N;
	string S;
	cin >> N >> S;
	int min = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == '.') min++;
	}
	int ans = min;
	for (int i = 0; i < N; i++) {
		if (S[i] == '#') {
			min++;
		}
		else if (S[i] == '.') {
			min--;
		}
		if (min < ans) ans = min;
	}
	cout << ans << endl;
}


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

#define int long long
#define INF 1000000007
const int n1=500;
int32_t main()
{
    //int p1=100000000000;
    //int p2=100000000000;
    //cout<<p1+p2<<endl;
    int diff=0;
    int diff1=0;
    int diff2=0;
    int n;
    cin>>n;
    int first=0;
    int second=0;
    vector<int> v;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        v.push_back(a);
    }
    vector<int> result;
  
        for(int i=0;i<1;i++)
        {
            first+=v[i];
        }
        for(int i=1;i<n;i++)
        {
            second+=v[i];
        }
        result.push_back(std::abs(first-second));
        for(int i=1;i<n-1;i++)
        {
            first+=v[i];
            second-=v[i];
            result.push_back(std::abs(first-second));
        }

  sort(result.begin(),result.end());
cout<<result[0]<<endl;
return 0;
}


Measured memory_bytes: 5488
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;

int n;
vector<int> adj[MAXN];

int d[MAXN];
int q[MAXN],qhead,qtail;

int farthest(int s) {
	REP(i,n) d[i]=INT_MAX;
	qhead=qtail=0; d[s]=0; q[qhead++]=s;
	while(qtail<qhead) { int at=q[qtail++]; REPSZ(i,adj[at]) { int to=adj[at][i]; if(d[to]==INT_MAX) d[to]=d[at]+1,q[qhead++]=to; } }
	return q[qhead-1];
}

bool solve() {
	int a=farthest(0);
	int b=farthest(a);
	int diam=d[b]+1;
	return diam>=3&&diam%3!=2||diam==1;
}

void run() {
	scanf("%d",&n);
	REP(i,n-1) { int a,b; scanf("%d%d",&a,&b), --a,--b; adj[a].PB(b); adj[b].PB(a); }
	printf("%s\n",solve()?"First":"Second");
}

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


Measured memory_bytes: 13556
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
    int s , w;
    cin >> s >>w;
    if(w>=s){
    	cout <<"unsafe" <<'\n';
	}
	else
	{
		cout << "safe" <<'\n';
	}

  }


Measured memory_bytes: 3664
import java.util.Scanner;

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        System.out.println((A + B) % 24);
    }
}

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

using namespace std;

void __print(int x) { cerr << x; }

void __print(long x) { cerr << x; }

void __print(long long x) { cerr << x; }

void __print(unsigned x) { cerr << x; }

void __print(unsigned long x) { cerr << x; }

void __print(unsigned long long x) { cerr << x; }

void __print(float x) { cerr << x; }

void __print(double x) { cerr << x; }

void __print(long double x) { cerr << x; }

void __print(char x) { cerr << '\'' << x << '\''; }

void __print(const char *x) { cerr << '\"' << x << '\"'; }

void __print(const string &x) { cerr << '\"' << x << '\"'; }

void __print(bool x) { cerr << (x ? "true" : "false"); }

template<typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}

template<typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i: x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}

void _print() { cerr << "]\n"; }

template<typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
#define INF 1e18
#define MOD 1e9+7
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

inline void solve() {
    int n,m;
    cin>>n>>m;
    vector<int> adj[n+1];
    for(int i=1;i<=m;i++) {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    queue<int> q;
    int ans[n+1];
    q.push(1);
    vector<int> vis(n+1);
    vis[1]=1;
    while(!q.empty()) {
        int x=q.front();
        q.pop();
        for(auto it:adj[x]) {
            if(!vis[it]) {
                ans[it]=x;
                q.push(it);
                vis[it]=1;
            }
        }
    }
    cout<<"Yes\n";
    for(int i=2;i<=n;i++) {
        cout<<ans[i]<<"\n";
    }
    cout<<"\n";
}

signed main() {
    IOS
    int t=1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 13748
#def main(S, b):

if __name__ == '__main__':
    a, b = map(int, input().split())

    ans = -1
    for i in range(2000):
        j = i + 1
        if (int(j * 0.08) == a and int(j * 0.1) == b):
            ans = j
            break

    print(ans)


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

signed main()
{
  int N; cin>>N;
  multiset<int> st;
  for(int i=0;i<N;i++){
    int x; cin>>x;
    auto itr=st.lower_bound(x);
    if(itr!=st.begin()){
      st.erase(prev(itr));
    }
    st.insert(x);
  }
  cout<<st.size()<<endl;

  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int a[1050010];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	
	int l=1,r=1;int now=a[1];
	long long ans=0;
	int last=0;
	while(r<=n)
	{
		int flag=0;
		while((now+a[r+1])==(now^a[r+1])&&r<n) 
		{
			r++,now+=a[r];
		}
		int len=r-l+1;
		ans+=(long long)(1+len)*len/2;
		len=last-l+1;
		if(len>0) ans-=(long long)(1+len)*len/2;
		last=r;
		if(r==n) break;
		while((now+a[r+1])!=(now^a[r+1])&&l<=r) now-=a[l],l++;
		if(r<l) now+=a[l],r++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
def rewrite(s, t):
	
	min = len(t)

	for i in range(len(s) - len(t) + 1):
		count = 0
		for j in range(len(t)):
			if s[j + i] != t[j]:
				count  += 1
		
		if min > count:
			min = count

	return min


str_s = input()
str_t = input()
rewrite_word = rewrite(str_s, str_t)
print(rewrite_word)

Measured memory_bytes: 9068
#include <iostream>
int main(){
    int N;
    std::cin >> N;
    int L[N];
    for(int i=0;i<N;i++){
        std::cin >> L[i];
    }
    int max=0, sum=0, index;
    for(int i=0;i<N;i++){
        if(L[i] > max){
            max = L[i];
            index = i;
        }
    }
    for(int i=0;i<N;i++){
        if(i!=index){
            sum += L[i];
        }
    }
    if(sum>max){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 














int main()
{
     int n,q;
     cin>>n>>q;
     string s;
     cin>>s;
     int ct[n+1]={0};
     for(int i=1;i<n;i++)
     {
          if(s[i]=='C'&&s[i-1]=='A')ct[i+1]=1;
     }
     for(int i=1;i<=n;i++)ct[i]+=ct[i-1];
     while(q--)
     {
          int l,r;cin>>l>>r;
          cout<<ct[r]-ct[l];
          cout<<"\n";
     }

}




















 
 
 
 
 

















Measured memory_bytes: 1408
#include <iostream>
#include <math.h>
#include <string>
#define ll long long
#define mod 1000000007
using namespace std;
int main(){
    string s;
    cin>>s;
    ll rain=0,sun=0;
    for(ll i=0;i<3;i++){
        if(s[i]=='R'){
            rain++;
        }else{
            sun++;
        }
    }
    if(rain==3||rain==1||rain==0){
        std::cout << rain<< std::endl;
    }else if(s[1]=='R'){
        std::cout << 2 << std::endl;
    }else{
        std::cout << 1 << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3188
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		a: usize,
		b: usize,
		c: usize,
	}

	println!("{}", a+b+c-max(a,max(b,c)));
}



Measured memory_bytes: 2124
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main(){
    int N;
    cin >> N;
    int x[N], y[N];
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i];
    }

    double r;
    r=0;
    for(int i=0; i<N-1; i++){
        for(int j=i+1; j<N; j++){
            r+=sqrt( (double) (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]) );
        }
    }

    r= (double) r*2*(N-1)/( N*(N-1) );

    cout << setprecision(12) << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    //入力
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<long long> A(X), B(Y), C(Z);
    for (int i = 0; i < X; i++) cin >> A[i];
    for (int i = 0; i < Y; i++) cin >> B[i];
    for (int i = 0; i < Z; i++) cin >> C[i];
    
    vector<long long> AB;
    for (int i = 0; i < X; i++){
        for (int j = 0; j < Y; j++){
            AB.push_back(A[i] + B[j]);
        }
    }
    
    sort(AB.begin(), AB.end());
    reverse(AB.begin(), AB.end());
    
    vector<long long> ABC;
    
    for (int i = 0; i < min(K, int(AB.size())); i++){
        for (int j = 0; j < Z; j++){
            ABC.push_back(AB[i] + C[j]);    
        }
    }
    
    sort(ABC.begin(), ABC.end());
    reverse(ABC.begin(), ABC.end());
    
    for (int i = 0; i < K; i++){
            cout << ABC[i] << endl;
    }
    
    
    
        
}

Measured memory_bytes: 42984
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF INT_MAX / 2

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    vector<int> n(3);
    cin>>n[0]>>n[1]>>n[2];
    sort(ALL(n));
    if(n[0]+n[1]==n[2]){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}
/*

*/


Measured memory_bytes: 3568
#include <stdio.h>

#include <math.h>

int hantei(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4);

int main(){
    
	double x1,x2,x3,x4,y1,y2,y3,y4;
    
	int result=0,i,n;
    
	scanf("%d",&n);
    
	for(i=0;i<n;i++){
        
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
        
		result= hantei(x1,y1,x2,y2,x3,y3,x4,y4);
        
		if(result==1){
            
			puts("YES");
            
		}else puts("NO");
        
	}
    
    
    
    
    
    return 0;
    
}

int hantei(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4){
    
	double kata1,kata2;
    
	kata1=(y1-y2)/(x1-x2);
    
	kata2=(y3-y4)/(x3-x4);
    
	if(kata1==kata2){
        
		return 1;
        
	}else{
        
		return 0;
        
	}
    
    
    
}

Measured memory_bytes: 1048
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=60;
    static const ll MOD=1e9+7;
    int N;
    char s1[MAXN];
    char s2[MAXN];
    vector<int>pat;
    void solve(){
        cin>>N>>s1>>s2;
        for(size_t u=0;u<N;u++){
            if(u!=N-1){
                if(s1[u]==s1[u+1]){
                    pat.push_back(0);
                    u++;
                }
                else pat.push_back(1);
            }
            else pat.push_back(1);
        }
        // for(auto p:pat)cout<<p<<" ";
        ll ans=1;
        int pre=-1;
        for(size_t u=0;u<pat.size();u++){
            if(u==0){
                if(pat[u]==1)ans=(ans*3)%MOD;
                else ans=(ans*6)%MOD;
            }
            else{
                if(pat[u]==1){
                    if(pre==1)ans=(ans*2)%MOD;
                }
                else {
                    if(pre==1)ans=(ans*2)%MOD;
                    else ans=(ans*3)%MOD;
                }
            }
            pre=pat[u];
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  int differ = 0;
  int same = 0;
  for(int i=0; i<N-1; i++){
    if(S.at(i) == S.at(i+1)){
      same++;
    }
    else{
      differ++;
    }
  }
  
  int ans = 0;
  if((differ+1)/2 > K){
    ans = same + 2*K;
  }
  else{
    ans = N-1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
main(){long long int x,k,d,a;
scanf("%lld%lld%lld",&x,&k,&d);x=labs(x);
if(x/d>=k)a=x-k*d;//1111
else{a=x%d;if((k-(x/d))%2==1)a=d-a;}
 printf("%lld",a);}


Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
ll a[61];
void add(ll x){
    for(int i=60;i>=0;i--) if(x>>i&1){
        if(a[i]) x ^= a[i];
        else{
            a[i] = x; break;
        }
    }
}
bool check(ll x){
    for(int i=60;i>=0;i--) if(x>>i&1) x ^= a[i];
    return x==0;
}
ll x[N];
char s[N];
int main(){
    ios::sync_with_stdio(0);
    int T; cin>>T;
    while(T--){
        memset(a,0,sizeof(a));
        int n; cin>>n;
        for(int i=1;i<=n;i++) cin>>x[i];
        cin>>(s+1);
        int ok = 1;
        for(int i=n;i>=1;i--){
            if(s[i]=='0') add(x[i]);
            else ok &= check(x[i]);
        }
        cout<<!ok<<endl;
    }
}


Measured memory_bytes: 3660
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String... args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int y = Integer.parseInt(sc.next());
		sc.close();

		List<Integer> result = new ArrayList<Integer>();
		boolean hasItem = false;

		// 10000円札の枚数
		for (int i = 0; i <= n; i++) {

			// 5000円札の枚数
			for (int j = 0; j <= n - i; j++) {

				int total = 10000 * i + 5000 * j + 1000 * (n - i - j);

				if (total == y) {
					System.out.println(i + " " + j + " " + (n - i - j));
					hasItem = true;
					break;
				}

			}

			if (hasItem) {
				break;
			}
		}

		if (!hasItem) {
			System.out.println("-1 -1 -1");
		}

	}
}


Measured memory_bytes: 23124
N=int(input())
W=list(map(int,input().split()))

tmp_arr = []
for i, w in enumerate(W):
  s1 = sum(W[0:i])
  s2 = sum(W[i:])
  tmp_arr.append(abs(s1-s2))

tmp_arr.sort()
print(tmp_arr[0])

Measured memory_bytes: 3060
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()]for j in range(m)][1:]
ans = [0]*(m-1)+[int(n*(n-1)/2)]
l = [i for i in range(1,n+1)]
s = {i:1 for i in range(1,n+1)}
 
def serch_l(num):
  if l[num]==num+1:
    return l[num]
  else:
    leader = serch_l(l[num]-1)
    l[num]=leader
    return leader
    
for k,i in enumerate(ab[::-1]):
  k = m-1-k
  l_a,l_b = serch_l(i[0]-1),serch_l(i[1]-1)
  if l_a==l_b:
    ans[k-1]=ans[k]
  else:
    
    s_a,s_b = s[l_a],s[l_b]
    
    if s_a > s_b:
      (s_a,s_b) = (s_b,s_a)
      (l_a,l_b) = (l_b,l_a)
    c = s_a*s_b
    s[l_b]+=s_a
    s[l_a]=0
    l[l_a-1]=l_b
    ans[k-1]=ans[k]-c
for i in ans:
  print(i)

Measured memory_bytes: 39788
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  static int[] A;
        static void Main(string[] args)
        {
          //入力を受け取る
          var N = int.Parse(Console.ReadLine());
          A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          var type = 0;
          type = IsZeroRange(1,399);
          for(int i = 1;i <=7;i++){
            type += IsZeroRange(400*i,400*(i+1)-1);
          }
          var red = A.Where(num => num >= 3200).ToArray().Length;
          var maxtype = type+red;
          var mintype = type;
          if(type ==0 && red > 0){
            mintype = 1;
          }
          
          Console.WriteLine(mintype+" "+maxtype);
        }
  
  static int IsZeroRange(int l,int r){
   // Console.WriteLine(l+" "+r);
    if(A.Where(num => num >= l && num <= r).ToArray().Length != 0){
      return 1;
    }else{
      return 0;
    }
  }
}


Measured memory_bytes: 13396
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

a,b=map(int,input().split())
print(a%b)


Measured memory_bytes: 5988
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
								`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	s := next()
	t := next()
	n := len(s)

	ans := "Yes"

	used := make(map[byte]int)

	for i := 0; i < n; i++ {
		if s == t {
			break
		}
		if s[0] != t[0] {
			_, us := used[s[0]]
			if us {
				ans = "No"
				break
			} else {
				used[s[0]] = 1
			}
			_, ut := used[t[0]]
			if ut {
				ans = "No"
				break
			}

			si := s[0 : 0+1]
			ti := t[0 : 0+1]

			t = strings.Replace(t, ti, "!", -1)
			t = strings.Replace(t, si, "#", -1)
			t = strings.Replace(t, "!", si, -1)
			t = strings.Replace(t, "#", ti, -1)
		} else {
			used[s[0]] = 1
		}
		s = s[1:]
		t = t[1:]
		//fmt.Fprintln(out, "[DEBUG]", t)
	}

	//fmt.Fprintln(out, "[DEBUG]", a)
	fmt.Fprintln(out, ans)
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

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

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}


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

main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }

    int c=1;
    for(int i=1;i<=n;i++){
        if(arr[i]==i){
            continue;
        }

        if(arr[arr[i]]==i and c==1){
            swap(arr[i],arr[arr[i]]);
            c--;
        }
        else{
            cout<<"NO";
            return 0;
        }
    }

    cout<<"YES";
    return 0;
}

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

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

    map<string, int> str_map;
    string str;
    int max = 0;
    for (int i = 0; i < N; ++i) {
        cin >> str;
        str_map[str]++;

        if (max < str_map[str]) {
            max = str_map[str];
        }
    }

    for (auto &&pair : str_map) {
        if (pair.second == max) {
            cout << pair.first << endl;
        }
    }
}

Measured memory_bytes: 25216
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B&lang=jp

#define MAXN 100005
#define MAXQ 50005

int N;
int A[MAXN];

static bool bin(int x) {
    int l = 0, r = N;
    while (l < r) {
        int mid = (l+r)/2;
        if (A[mid] == x) return true;
        if (A[mid] < x) l = mid + 1;
        if (A[mid] > x) r = mid;
    }
    return false;
}

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];
    int q; cin >> q;
    int ans = 0;
    REP(i, q) {
        int a; cin >> a;
        if (bin(a)) ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3472
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
p = [i-1 for i in p]
MINI = -10**9-1

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


union_find = UnionFind(n)
score_map = {}
for i in range(n):
    union_find.union(i, p[i])

for root in union_find.roots():
    n_c = p[root]
    score = c[n_c]
    while n_c != root:
        n_c = p[n_c]
        score += c[n_c]
    score_map[root] = score

ans = MINI
for i in range(n):
    mx = MINI
    score = 0
    m = k
    root = union_find.find(i)
    lap_score = score_map[root]
    if lap_score > 0:
        _d = (k // union_find.size(root)) - 1
        score += lap_score*_d
        mx = max(mx, score)
        m -= _d*union_find.size(root)
    else:
        m = min(k, union_find.size(root))
    if m == 0:
        ans = max(mx, ans)
        continue
    n_c = p[i]
    score += c[n_c]
    mx = max(mx, score)
    m -= 1
    while m > 0:
        n_c = p[n_c]
        score += c[n_c]
        mx = max(mx, score)
        m -= 1
    ans = max(mx, ans)
print(ans)




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

vector<vector<int> > ms;

void pf(int n,int max,vector<int> &a) {
    if (n == 0) {
        ms.push_back(a);
        return;
    }
    for (int i=min(n,max); i>0; --i) {
        a.push_back(i);
        pf(n-i, i, a);
        a.erase(a.end()-1);
    }
}

int n;

signed main() {
    while (true) {
        cin >> n;
        if (n == 0) break;

        ms.clear();

        vector<int> temp;
        pf(n, n, temp);

        rep(i,ms.size()) {
            rep(j,ms[i].size()) {
                cout << ms[i][j];
                if (j != ms[i].size() - 1) cout << " ";
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 1796