akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>

int main()
{
	int n;
	while( std::cin >> n, n )
	{
		std::vector<int> v( n );
		for( int i = 0; i != n; ++i )
		{
			int a;
			std::cin >> a;
			v[i] = a;
		}

		int r = 32, p = 0;
		bool turn = false;
		while( r )
		{
			if( !turn )
				r -= std::min( r, ( r - 1 ) % 5 );
			else
				r -= std::min( r, v[p] ), p = ( p + 1 ) % n;

			std::cout << r << std::endl;

			turn ^= true;
		}
	}

	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int x;
	cin >> x;
	cout << 1 - x << endl;
	return 0;
}


Measured memory_bytes: 3600
//                              ______  ______  ______
// .-----..-----..-----..-----.|    __||__    ||  __  |
// |     ||  _  ||     ||  _  ||  __  ||    __||  __  |
// |__|__||___  ||__|__||___  ||______||______||______|
//        |_____|       |_____|
//
# include <bits/stdc++.h>
using namespace std;
using msi = map<string, int>;

int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    msi mp;
    mp[s] = a;
    mp[t] = b;
    string u;
    cin >> u;
    mp[u]--;

    printf("%d %d\n", mp[s], mp[t]);

    return 0;
}

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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a)
#define INF 1e16
#define mod 1e9+7


int main() {
  ll n;
  cin>>n;
  vll v(n);
  FOR(i,0,n){
    cin>>v[i];
  }
  SORT(v);
  ll ans=0;
 // FOR(i,0,n){
  //  co(v[n/2]);
 // }
  ans=v[n/2]-v[n/2-1];
  co(ans);
}
  

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;
  
#define MP make_pair
#define PB push_back
#define MAX_N 2001000
#define SIZE 2000
#define X first
#define Y second
  
const int STX = 1000, STY = 1000;
  
int id[SIZE][SIZE];
bool is_prime[MAX_N+1];
vector<pair<int, int> > coord;

void Sieve() {
  fill(is_prime, is_prime+MAX_N+1, true);
  is_prime[0] = is_prime[1] = false;
  for(int i=2; i*i<=MAX_N; i++) {
    if(is_prime[i]) {
      for(int j=i*i; j<=MAX_N; j+=i) {
	is_prime[j] = false;
      }
    }
  }
}

void MakeMap() {
  int x = STX, y = STY;
  int cnt = 0;
  
  coord.PB(MP(0, 0)); // no use
  cnt ++;
  coord.PB(MP(x, y)); // cnt = 1
  
  fill(id[0], id[0]+SIZE*SIZE+1, -1);
  
  const int dx[] = {0,-1,0,1};
  const int dy[] = {-1,0,1,0};
  
  int a = 0; x = STX+1; y = STY+1;
  while(cnt <= MAX_N) {
    a += 2;
    for(int turn=0; turn<4; turn++) {
      for(int i=0; i<a; i++) {
	x += dx[turn], y += dy[turn];
	coord.PB(MP(x, y));
	id[y][x] = ++ cnt;
      }
    }
    x++, y++;
  }
}

int dp[MAX_N+1];

int main() {
  
  Sieve();
  MakeMap();
  
  int m, n;

  while(cin >> m >> n && (m|n)) {
    
    //bool ok = false;
    
    fill(dp, dp+MAX_N+1, -1);
    dp[n] = is_prime[n];
    pair<int, int> ans(dp[n], n);
    
    queue<pair<int, int> > que;
    que.push(coord[n]);
    queue<int> q_dp;
    q_dp.push(dp[n]);
    while(!que.empty()) {
      pair<int, int> now = que.front(); que.pop();
      int tmp = q_dp.front(); q_dp.pop();
      int tmpid = id[now.Y][now.X];
      if(tmp < dp[tmpid]) continue;
      
      int noid = id[now.Y][now.X];
      
      for(int i=-1; i<=1; i++) {
	pair<int, int> nex = MP(now.X+i, now.Y+1);
	if(nex.X < 0 || SIZE <= nex.X || nex.Y < 0 || SIZE <= nex.Y) continue;
	int neid = id[nex.Y][nex.X];
	if(neid <= m) {
	  if(dp[neid] < dp[noid] + is_prime[neid]) {
	    dp[neid] = dp[noid] + is_prime[neid];
	    //if(is_prime[neid]) ok = true;
	    ans = max(ans, make_pair(dp[neid], neid));
	    que.push(nex);
	    q_dp.push(dp[neid]);
	  }
	}
      }

    }
    
    /*
    int res = dp[n], lastid = -1;
    if(is_prime[n]) lastid = n;
    
    for(int i=1; i<=m; i++) {
      if(res <= dp[i] && is_prime[i]) {
	res = dp[i];
	lastid = max(lastid, i);
      }
    }
    */
    if(ans.first == 0) cout << "0 0" << endl;
    else {
      int ans2 = 2;
      cout << ans.first << " ";
      for(int i=1; i<=m; i++) {
	if(ans.first == dp[i] && is_prime[i]) {
	  ans2 = max(ans2, i);
	}
      }
      cout << ans2 << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 42544
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second


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

main(){
  int t;
  cin>>t;
  while(t--){
    int gx,gy,p;
    cin>>gx>>gy>>p;
    ll heian[gx+1][gy+1];
    memset(heian,0,sizeof(heian));
    heian[0][0]=1;
    
    set<pair<PI,PI> > mata;
    rep(i,p){
      int x1,y1,x2,y2;
      cin>>x1>>y1>>x2>>y2;
      mata.insert(mp(mp(x1,y1),mp(x2,y2)));
      mata.insert(mp(mp(x2,y2),mp(x1,y1)));
    }

    rep(i,gx+1){
      rep(j,gy+1){
        ll t=0;
        if(i && mata.count(mp(mp(i-1,j),mp(i,j)))==0)t+=heian[i-1][j];
        if(j && mata.count(mp(mp(i,j-1),mp(i,j)))==0)t+=heian[i][j-1];
        if(!i && !j)t=1;
        heian[i][j]=t;
      }
    }
    if(heian[gx][gy]==0)puts("Miserable Hokusai!");
    else cout<<heian[gx][gy]<<endl;
  }
}

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

int main() {
    int N, a;
    char b;
    cin >> N;
    set<string> S;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        if (i == 0) {
            b = s.at(s.size() - 1);
            S.insert(s);
            continue;
        }
        S.insert(s);
        if (s.at(0) != b || a == S.size()) {
            cout << "No" << endl;
            return 0;
        }
        if (i == N - 1) {
            cout << "Yes" << endl;
            return 0;
        }
        b = s.at(s.size() - 1);
        a = S.size();
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int getsum(int x){
   int t=0;
   while(x>0)
   {
   	 t+=x%10;
   	 x/=10;
   }
   return t;
}
int main(){
  int n,y,ans=100000;
  cin>>n;
  for(int i=1;i<=n/2+1;i++){
  	 y=getsum(i)+getsum(n-i);
  	 if(y<ans)
  	   ans=y;
  }
  printf("%d",ans);
  return 0;
} 

Measured memory_bytes: 256
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::cmp::{max, min};
fn main() {
    input!{
        n: i64,
        a: i64,
        b: i64,
    }
    println!("{} {}", min(a, b), max((min(a, b) - (n - max(a, b))), 0));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;}

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

int K; cin >> K;

if (K <= 9) {
    cout << K << "\n";
    return 0;
}

queue<i64> q;
rep(i, 1, 10) q.push(i);
int n = 9;

while (1){
    i64 p = q.front();
    q.pop();
    
    int pm = p % 10;
    if (pm == 0) {
        q.push(10 * p);
        if (++n == K) break;
        q.push(10 * p + 1);
        if (++n == K) break;
    }
    else if (pm == 9){
        q.push(10 * p + 8);
        if (++n == K) break;
        q.push(10 * p + 9);
        if (++n == K) break;
    }
    else {
        q.push(10 * p + pm - 1);
        if (++n == K) break;
        q.push(10 * p + pm);
        if (++n == K) break;
        q.push(10 * p + pm + 1);
        if (++n == K) break;
    }
}


cout << q.back() << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 768
#include<stdio.h>
int main(void){
  int a = 0,b = 0,c = 0;

  while(1){
  scanf("%d %d",&a,&b);

  if( a == 0 && b == 0){
    return 0;
  }

  if (a < b){
    printf("%d %d\n",a,b);
  } else {
    printf("%d %d\n",b,a);
  }
  }
  return 0;
}

Measured memory_bytes: 600
#include"bits/stdc++.h"

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	string S;
	cin >> N;
	cin >> S;
	vector<int>vW(N + 1, 0), vE(N + 1, 0);
	for (int i = 0; i < N; i++)
	{
		vW[i + 1] = vW[i];
		if (S[i] == 'W') {
			vW[i + 1]++;
		}
		vE[i + 1] = vE[i];
		if (S[i] == 'E') {
			vE[i + 1]++;
		}
	}
	int ans = 1e9;
	for (int i = 0; i < N; i++)
	{
		int now = vW[i] + (vE[N] - vE[i + 1]);
		if (ans > now) {
			ans = now;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2964
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define srt(x) sort((x).begin(), (x).end())
#define rsrt(x) sort((x).rbegin(), (x).rend())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vc = vector<char>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long double doublepi = M_PI * 2.0;
const long double halfpi = M_PI / 2.0;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long MOD = 1e9 + 7;



ll MAX = 200010;
vllvll Mat(MAX,vll(0));
vll seen(MAX, 0);
vll counts(MAX, 0);

void rec(ll node, ll prev)
{
    seen[node] = 1;
    if (prev != node) {
        counts[node] += counts[prev];
    }
    for (ll adj : Mat[node]) {
        if (seen[adj] == 1) continue;
        rec(adj, node);
    }
}

void dfs(ll start)
{
    fill(seen.begin(), seen.end(), 0);
    rec(start, start);
}

int main()
{
    ll N, Q;
    cin >> N >> Q;
    rep(i, 0, N-1) {
        ll a, b;
        cin >> a >> b;
        Mat[a].push_back(b);
        Mat[b].push_back(a);
    }
    rep(i, 0, Q) {
        ll p, x;
        cin >> p >> x;
        counts[p] += x;
    }


    dfs(1);


    rep(i, 1, N+1) {
        if (i != N) {
            cout << counts[i] << ' ';
        }
        else {
            cout << counts[i] << '\n';
        }
    }
}





Measured memory_bytes: 22656
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
#define MAX_A (1000000010LL)
#define MAX_DIFF (MAX_A*MAX_A)
ll A, B, C;
int main()
{
    ll ans = MAX_DIFF;

    scanf("%lld %lld %lld", &A, &B, &C);

    if ( (A % 2) == 0 || (B % 2) == 0 || (C % 2) == 0 ) {
	printf("0\n");
    }
    else {
	ll min_mult = MAX_DIFF;
	min_mult = min( min_mult, A * B );
	min_mult = min( min_mult, B * C );
	min_mult = min( min_mult, C * A );	
	printf("%lld\n", min_mult);
    }
    
    return 0;
}


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

using namespace std;

int dp[100005];
int h[100005];
int n,k;

const int INF = 1e9;

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

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

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;


public class Main {
	
	Scanner cin = new Scanner(System.in);
	
	public static void main(String[] args) {
		new Main().run(); 
	}
	
	public void run() {		
		
		/*input*/
		
		String input = cin.nextLine();
		
		/*start*/
		
		Stack<Character> st = new Stack<>();
		
		for (int i = 0; i < input.length(); i ++) {
			
			char ch = input.charAt(i);
			
			if (ch == 'B') {
				if (!st.isEmpty()) {
					st.pop();
				}
			}
			
			else {
				st.push(ch);
			}				
		}
		
		
		/*finish*/
		for (char ch: st) {
			System.out.print(ch);
		}
	}
}



Measured memory_bytes: 21844
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iostream> 
#include <cmath>
 
using namespace std;
typedef long long ll;
typedef long double ld;

//repetition
#define REP(i,n)  for(ll i=0;i<n;i++)

ll P_POW(ll i, ll n) {
  if(n==0) return 1;

  n--;
  ll rep = i;

  while(n) {
    rep = rep * i;
    n--;
  }
  return rep;
} 

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
 
unsigned binarySearch(ll target, ll max, ll min) {
  while((max - min) > 1) {
      if((max + min)/2 > target) {
        max = (max + min)/2;
        min = min;
      } else {
        max = max;
        min = (max + min)/2;
      }
    }
}

ll n;


long long solve2(long long N) {
    if (N % 2 == 1) return 0;

    long long res = 0;
    N /= 2;
    while (N) {
        res += N / 5;
        cout << "N/5: " << N/5 <<  endl;
        cout << "res1: " << res <<  endl;
        N /= 5;
    }
    return res;
}


ll solve(ll n) {
    if (n % 2 == 1) return 0;

    ll res = 0;
    n /= 2;
    int c = 1;

    while (n/P_POW(5,c)) {
      res += n/P_POW(5,c);
      c++;
    }
    return res;
}

int main() {
  ll n;
  cin >> n;
  cout << solve(n) << endl;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> h(n);
  for (auto i = 0; i < n; i++) {
    cin >> h[i];
  }
  int cnt = 0;
  for (auto hh = 100; hh > 0; hh--) {
    for (auto i = 0; i < n; i++) {
      if (h[i] == hh) {
	cnt++;
	h[i]--;
	for (auto j = i + 1; j < n; j++) {
	  if (h[j] == hh) {
	    h[j]--;
	  } else {
	    break;
	  }
	}
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
x, y, z, k = gets.split.map(&:to_i)

a = gets.split.map(&:to_i).sort!.reverse!
b = gets.split.map(&:to_i).sort!.reverse!
c = gets.split.map(&:to_i).sort!.reverse!

buf = []
x.times do |ix|
  y.times do |iy|
    break unless ix * iy < k
    z.times do |iz|
      break unless ix * iy * iz < k
      buf << a[ix] + b[iy] + c[iz]
    end
  end
end

buf.sort!.reverse!

k.times do |i|
  p buf[i]
end


Measured memory_bytes: 37504
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n+1];
	int dp[n+1];
	for (int i = 1; i <=n; ++i)
	{
		cin>>a[i];
	}
	dp[1]=0;
	dp[2]=abs(a[2]-a[1]);
	for (int i = 3; i <=n; ++i)
	{
		dp[i]=std::min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);

	}
	cout<<dp[n]<<endl;
	return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    for (int c = 1; c < 4; c++)
    {
        int n = a * b * c;
        if (n % 2 == 1)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
using namespace std;
int main()
{
	int N;
	cin>>N;
	bool can=false;
	for(int i=0;i<18;i++)
	{
		if(i*7>N)
		break;
		else
		{
			if((N-i*7)%4==0)
			{
			can=true;
			break;
		}
		}
	}
	if(can)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
 } 

Measured memory_bytes: 256
//ABC 077
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };

int n;
vector<ll> a, b, c;
//bの上にのる数、cの上に載る数を格納
ll bup[100010] = {}, cup[100010] = {};


signed main() {

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

	cin >> n;
	ll kari;
	REP(i, n) {
		cin >> kari;
		a.push_back(kari);
	}
	REP(i, n) {
		cin >> kari;
		b.push_back(kari);
	}
	REP(i, n) {
		cin >> kari;
		c.push_back(kari);
	}

	VSORT(a);
	VSORT(b);
	VSORT(c);

	ll ans = 0;
	REP(i, n) {
		ans += distance(a.begin(), lower_bound(ALL(a), b[i]))*distance(upper_bound(ALL(c), b[i]), c.end());
	}

	cout << ans << endl;






	return 0;
}

Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> L(N); for(auto& in:L) cin >> in;
    sort(L.begin(),L.end());
    
    for(int i = 0; i < N;i++){
        for(int j = i+1;j < N;j++){
            if(L[i] == L[j]) continue;;
            for(int k = j+1; k < N;k++){
                if(L[i] == L[k]) continue;
                if(L[j] == L[k]) continue;
                
                if(L[i]+L[j]>L[k])res++;
            }
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
long long x, k, d;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> x >> k >> d;
    x = abs(x);
    long long xd = x / d;
    if(xd >= k)
        cout << x - d * k << "\n";
    else
    {
        k -= xd;
        if(k % 2 == 0)
            cout << x - xd * d << "\n";
        else
            cout << abs(x - (xd + 1) * d) << "\n";
    }

}


Measured memory_bytes: 3652
N = int(input())
table = {
	"AC": 0,
	"WA": 0,
	"TLE": 0,
	"RE" : 0,
}
for _ in range(N):
	table[input().strip()] += 1

for name in ("AC", "WA", "TLE", "RE"):
	print(name, "x", table[name])


Measured memory_bytes: 9176
H,W = map(int,input().split())
S = [list(input()) for i in range(H)]

A = [[False]*W for i in range(H)]

Q = [(0,0,(5,4,1,3,6,2))]

while Q:
    q = Q.pop()
    h,w,s = q[0],q[1],q[2]
    if min(h,w)<0 or h>=H or w>=W:continue
    if S[h][w]=="#":continue
    if A[h][w]:continue
    if int(S[h][w])!=s[4]:continue
    A[h][w] = True
    Q.append((h-1,w,(s[2],s[1],s[5],s[3],s[0],s[4])))
    Q.append((h+1,w,(s[4],s[1],s[0],s[3],s[5],s[2])))
    Q.append((h,w-1,(s[0],s[2],s[3],s[4],s[1],s[5])))
    Q.append((h,w+1,(s[0],s[4],s[1],s[2],s[3],s[5])))
print("YES" if A[H-1][W-1] else "NO")


Measured memory_bytes: 7760
n = int(input())
lis = list(map(int,input().split()))
cnt = 0
two = 0
for i in lis:
    if i % 4 == 0:
        cnt += 1
    elif i % 4 == 2:
        two += 1

if n//2 <= cnt:
    print("Yes")
elif two >= 2 and (n-(two-1))//2 <= cnt:
    print("Yes")
else:
    print("No")


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

int main(){
  int a,b,c;
  cin >> a >> b >> c ;
  cout << c << " " << a << " " << b << endl;
  return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#define INFILE freopen("input.txt", "r", stdin)
#else
#define debug(x)
#define INFILE
#endif

#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll INF = 1LL << 60;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

ll_ll dp[410][410];  // first -> value, second -> cost

int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  vector<ll> v(n);
  scan(v);

  REP(i, 0, n) { dp[i][i + 1] = ll_ll(v[i], 0); }
  REP(i, 2, n + 1) {
    REP(first, 0, n - i + 1) {
      int last = first + i;

      ll_ll result{INF, INF};
      REP(middle, first + 1, last) {
        ll_ll v1 = dp[first][middle];
        ll_ll v2 = dp[middle][last];
        ll cost = v1.first + v2.first + v1.second + v2.second;

        if (cost > result.second) continue;
        result.first = v1.first + v2.first;
        result.second = cost;
      }

      dp[first][last] = result;
    }
  }

  cout << dp[0][n].second << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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 A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


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

namespace ConsoleApp20
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] ABCK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long[] ABC = new long[3] { ABCK[0] - ABCK[1], 0, ABCK[2] - ABCK[1] };
            for (long i = 0; i < ABCK[3]%4; i++)
            {
                long a, c;
                a = -ABC[0];
                c = -ABC[2];
                ABC[0] = a;ABC[2] = c;
            }
            Console.WriteLine(ABC[0]);
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
const int INF = 1e9;
const int MO = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#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 FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define rt return
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)
#define s second
#define f first

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int N;cin >> N;
    vector<pair<int,int>> ans;
    if(N%2 == 1){
    for(int a = 0;a < N-1;a++){
        for(int b = a+1;b < N;b++){
            if(N-b-1 != a+1){
                ans.push_back({a+1,b+1});
            }
        }
    }
    }else{
        for(int a = 0;a < N-1;a++){
            for(int b = a+1;b < N;b++)
            {
                if(a == 0 && b == N-1)continue;
                if(N-b != a+1){
                    ans.push_back({a+1,b+1});
                }
            }
        }
    }
    cout<<ans.size()<<endl;
    for(int a = 0;a < ans.size();a++){
        cout<<ans.at(a).first<<" "<<ans.at(a).second<<endl;
    }
}


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

const int mod = 1e9+7;

ll qpow(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b&1)
            res = res*a%mod;
        a = a*a%mod;
        b >>= 1;
    }
    return res;
}

ll C(ll n, ll m) {
    ll A = 1, B = 1;
    for(int i=1; i<=m; i++) {
        A = A*(n-i+1)%mod;
        B = B*i%mod;
    }
    return A*qpow(B, mod-2)%mod;
}

int main() {
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    ll ans = qpow(2, n);
    printf("%lld\n", (ans-C(n, a)-C(n, b)-1+2*mod)%mod);
    return 0;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int>H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  vector<int>A(M);
  vector<int>B(M);
  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
  }
  
  vector<int>count(N,0);
  for (int i = 0; i < M; i++) {
    if (H.at(A.at(i)-1) >= H.at(B.at(i)-1)){
      count.at(B.at(i)-1)++;
    }
    if (H.at(A.at(i)-1) <= H.at(B.at(i)-1)){
      count.at(A.at(i)-1)++;
    }
  }
  
  int C = 0;
  for (int i = 0; i < N; i++) {
    if (count.at(i) == 0){
      C++;
    }
  }
  cout << C << endl;
}
  
  
  

Measured memory_bytes: 4836
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
ans = 1
while N >= K:
	ans += 1
	N//=K
print(ans)


Measured memory_bytes: 5700
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#define N 500005
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
using namespace std;
 
int n, last, ans, dp[N][4];
char s[N];
vector<int> v;
 
void calc(){
	int n = v.size();
	fi(i, 0, n){
		dp[i][0] = dp[i][1] = dp[i][2] = dp[i][3] = -1e9;
	}
	if(v[1] == 1){
		dp[1][3] = dp[1][1] = 0;
		dp[1][2] = -1e9;
		dp[1][0] = v[0];
	}else{
		dp[1][3] = 0;
		dp[1][2] = v[0];
		dp[1][1] = v[1] - 1;
		dp[1][0] = v[1];
	}
	fi(i, 2, n){
		// rtl
		if(v[i] > 1) {
			dp[i][2] = max(dp[i][2], dp[i - 1][3] + v[i - 1]);
			dp[i][2] = max(dp[i][2], dp[i - 1][2] + v[i - 1] - 1);
			dp[i][2] = max(dp[i][2], dp[i - 1][1] + 1);
		}else{
			dp[i][0] = max(dp[i][0], dp[i - 1][3] + v[i - 1]);
			dp[i][0] = max(dp[i][0], dp[i - 1][2] + v[i - 1] - 1);
			dp[i][0] = max(dp[i][0], dp[i - 1][1] + 1);
		}
		
		// ltr
		dp[i][0] = max(dp[i][0], max(dp[i - 1][3], max(dp[i - 1][1], dp[i - 1][2])) + v[i]);
		
		dp[i][3] = max(max(dp[i - 1][0], dp[i - 1][1]), max(dp[i - 1][2], dp[i - 1][3]));
		if(v[i] > 1){
			dp[i][1] = dp[i][0] - 1;
		}
		else{
			dp[i][1] = dp[i][3];
		}	
	}
	int delta = -1e9;
	fi(i, 0, 4) delta = max(delta, dp[n - 1][i]);
	ans += delta;
}
 
int main(){
	scanf("%d %s", &n, s);
	
	fi(i, 0, n){
		if(s[i] == '0'){
			if(i && s[i - 1] == '0'){
				if(v.size() > 1) calc();
				v.clear();
			}else{
				if(last) v.push_back(last);
				last = 0;
			}
		}else{
			last++;
		}
	}
	
	if(last) v.push_back(last);
	if(v.size() > 1) calc();
	
	printf("%d\n", ans);
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten53 300005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


int main(void)
{
    ll m,n,i,j,k=0,d,sum=0;
    string s;
    cin>>n;
    cin>>s;
    for(i=0;i<n;i++)
    {
        if(s[i]=='I')
            k++;
        else
            k--;
        sum=max(k,sum);
    }
    cout<<sum;
    return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  int n, m; // n:頂点数 m:辺数
  cin >> n >> m;
  
  vector<vector<int>> G(n); // G:頂点数nのグラフの隣接リスト
  
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
  //G[v].emplace_back(u); // 有向グラフではコメントアウト
  }
  
  int s, t;
  cin >> s >> t;
  s--;
  t--;
  
  vector<vector<int>> dp(n, vector<int>(3, 1e9));
  dp.at(s).at(0) = 0;
  queue<pair<int, int>> q;
  q.push(make_pair(s, 0));
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    for (int i = 0; i < G[p.first].size(); i++) {
      if (dp.at(G[p.first][i]).at((p.second + 1) % 3) <= dp.at(p.first).at(p.second) + 1) continue;
      dp.at(G[p.first][i]).at((p.second + 1) % 3) = dp.at(p.first).at(p.second) + 1;
      q.push(make_pair(G[p.first][i], (p.second + 1) % 3));
    }
  }
  
  if (dp.at(t).at(0) == 1e9) cout << "-1\n";
  else cout << dp.at(t).at(0) / 3 << '\n';
}

Measured memory_bytes: 11264
#include "bits/stdc++.h"

using namespace std;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};

//using Graph = vector<vector<Edge>>
using Graph = vector<vector<int>>;

// header area

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

    int N;
    cin >> N;
    vector<int> A(N);
    for (auto& i : A) cin >> i;

    unordered_map<int, int> mp;

    long long ans = 0;
    for (int i = N -1; i >= 0; --i) {
        ans += mp[A[i] + i];
        // j>iなのでそいつよりも大きい添え字の情報だけ保持してればよい
        mp[i - A[i]]++;

    }
    cout << ans << endl;
}


Measured memory_bytes: 19308
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#define NUM_OF_BALLS 10
using namespace std;

int N;
queue<int> A;

//並べられるかどうかの判定とB,Cの値の更新
bool dfs(int B,int C){
	int ball;
	if(A.empty()) return true;
	else{
		ball = A.front();A.pop();
		if(ball <= min(B,C)){
			while(!A.empty())A.pop();
			return false;
		}
		if(ball > B)return dfs(ball,C);
		if(ball > C)return dfs(B,ball);

		printf("e\n");return false;
	}
}

void solve(){
	if(dfs(0,0))printf("YES\n");
	else printf("NO\n");
	return;
}

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

	for(int n = 0;n < N;n++){
		for(int i = 0;i < NUM_OF_BALLS;i++){
			scanf("%d",&tmp);
			A.push(tmp);
		}

		solve();
	}
   

    return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main() {
    int N;
    cin >> N;
    vector<P> v(N);
    for (int i = 0; i < N; i++) {
        int X, L;
        cin >> X >> L;
        v[i] = P(X + L, X - L);
    }
    int cnt = 0;
    int point = -2e9;
    sort(v.begin(), v.end());
    for (int i = 0; i < N; i++) {
        if (point <= v[i].second) {
            cnt++;
            point = v[i].first;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
#define MN 2005
using namespace std;
int n,m,k,val[MN],c[MN][2],fa[MN],id[MN],ht[MN],sz[MN],ans=0x3f3f3f3f;bool now[MN];
bool cmp(int x,int y){return val[x]>val[y];}
multiset<int> s;
multiset<int>::iterator it;
int merge(int x,int y){
	if((!x)||(!y))return x+y;
	if(val[x]>val[y])swap(x,y);
	c[x][1]=merge(c[x][1],y);
	if(ht[c[x][0]]<ht[c[x][1]])swap(c[x][0],c[x][1]);
	ht[x]=ht[c[x][1]]+1,sz[x]=sz[c[x][0]]+sz[c[x][1]]+1;return x;
}
int getfa(int x){return fa[x]==x?x:fa[x]=getfa(fa[x]);}
int main(){
	scanf("%d%d%d",&n,&m,&k);int x,y,tmp;
	for(int i=1;i<=n;i++)scanf("%d",&val[i]),ht[i]=0,sz[i]=1,fa[i]=i,id[i]=i;sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;i++){
		now[id[i]]=1;
		if(now[id[i]-1]){
			x=getfa(id[i]),y=getfa(id[i]-1);
			if(val[x]>val[y]&&sz[y])swap(x,y);if(sz[y])fa[y]=x;merge(x,y);
		}
		if(now[id[i]+1]){
			x=getfa(id[i]),y=getfa(id[i]+1);
			if(val[x]>val[y]&&sz[y])swap(x,y);if(sz[y])fa[y]=x;merge(x,y);
		}tmp=getfa(id[i]);
		while(sz[tmp]>=m)s.insert(val[tmp]),y=merge(c[tmp][0],c[tmp][1]),fa[tmp]=y,fa[y]=y,tmp=y;
		while(s.size()>k)it=s.end(),--it,s.erase(it);
		if(s.size()==k)it=s.end(),--it,ans=min(ans,(*it)-val[id[i]]);
	}printf("%d\n",ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


// uniteが呼ばれる度に時刻tが1進む
struct PPUnionFind {
  const int n;

  PPUnionFind(const V<>& x) : n(x.size()), curr(0), time(n, V<>(1)), dat(n) {
    for (int v = 0; v < n; ++v) {
      dat[v] = {-x[v]};
    }
  }

  bool same(int u, int v, int t) const {
    assert(0 <= u and u < n);
    assert(0 <= v and v < n);
    assert(0 <= t and t <= curr);
    return find(u, t) == find(v, t);
  }
  bool same(int u, int v) const {
    return same(u, v, curr);
  }

  lint size(int v, int t) const {
    assert(0 <= v and v < n);
    assert(0 <= t and t <= curr);
    v = find(v, t);
    return -dat[v][distance(begin(time[v]), --upper_bound(begin(time[v]), end(time[v]), t))];
  }
  lint size(int v) const {
    return size(v, curr);
  }

  void unite(int u, int v) {
    assert(0 <= u and u < n);
    assert(0 <= v and v < n);
    ++curr;
    if ((u = find(u, curr)) == (v = find(v, curr))) return;
    time[u].push_back(curr);
    time[v].push_back(curr);
    if (-dat[u].back() < -dat[v].back()) {
      dat[v].push_back(dat[v].back() + dat[u].back());
      dat[u].push_back(v);
    } else {
      dat[u].push_back(dat[u].back() + dat[v].back());
      dat[v].push_back(u);
    }
  }

private:
  int curr;
  VV<> time;
  VV<lint> dat;

  int find(int v, int t) const {
    return dat[v].back() < 0 or time[v].back() > t ? v : find(dat[v].back(), t);
  }
};

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> x(n); for (int i = 0; i < n; ++i) cin >> x[i];
  struct Edge {
    int u, v, y;
    bool operator<(const Edge& rhs) { return y < rhs.y; }
  };
  V<Edge> es(m);
  for (int i = 0; i < m; ++i) {
    int u, v, y; cin >> u >> v >> y, --u, --v;
    es[i] = {u, v, y};
  }
  sort(begin(es), end(es));
  PPUnionFind uf(x);
  for (const auto& e : es) {
    uf.unite(e.u, e.v);
  }
  int res = 0;
  V< set<int> > g(n);
  for (const auto& e : es) {
    g[e.u].insert(e.v);
    g[e.v].insert(e.u);
  }
  V<bool> ok(n);
  auto dfs = [&](const auto& dfs, int v) -> void {
    ok[v] = true;
    for (int w : g[v]) if (!ok[w]) {
      dfs(dfs, w);
    }
  };
  for (int i = m - 1; i >= 0; --i) {
    if (ok[es[i].u] or ok[es[i].v]) continue;
    if (es[i].y > uf.size(es[i].u, i + 1)) {
      ++res;
      g[es[i].u].erase(es[i].v);
      g[es[i].v].erase(es[i].u);
    } else {
      dfs(dfs, es[i].u);
    }
  }
  cout << res << '\n';
}

Measured memory_bytes: 30064
L, R = gets.chomp.split(" ").map(&:to_i)
numbers = []
tmp = 0
(L..R).each do |num|
  numbers << num % 2019
  tmp += 1
  if tmp >= 2019
    break
  end
end

mods = []
numbers.each do |num1|
  numbers.each do |num2|
    if num1 == num2
      next
    end
    mods << (num1 * num2) % 2019
  end
end

puts mods.min

Measured memory_bytes: 35580
import java.util.*;

public class Main {

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		int num = (x - z) / (y + z);
		System.out.println(num);
	}
}


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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

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

    ll x; cin >> x;
    ll m = 100;
    int ans = 0;
    while (m < x) {
        m = floor((double)m * 1.01);
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#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 pb push_back

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<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;

bool is_prime(int N){
    for(int i=2;i<=sqrt(N);i++){
        if(N%i==0){
            return false;
        }
    }
    return true;
}


int main(){

    ll X;
    cin>>X;
    while(1){
        if(is_prime(X)==true){
            cout<<X<<endl;
            return 0;
        }else{
            X++;
        }
    }
    return 0;
}


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

void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    vector<int> w, r;
    for(int i = 0; i < n; i++)
    {
        if(s[i] == 'W')
            w.push_back(i);
        else
            r.push_back(i);
    }

    int wind = 0, rind = r.size() - 1;

    while(w.size() && r.size() && w[wind] < r[rind])
    {
        wind++;
        rind--;
        cnt++;
    }
    cout << cnt;


}


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

//wwrwrrwr






Measured memory_bytes: 4776
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>

using namespace std;
const long long P = 1000000007;

int main() {
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  if(s == t) {
    cout << s.size() << endl;
    return 0;
  }
  int same = 0;
  string tmp = "";
  for(int i = 0; i < t.size(); i++) {
    tmp += t[i];
    if(s.find(tmp) <= s.size()) {
      same++;
    }else {
      break;
    }
  }
  cout << s.size() + t.size() - same << endl;
  return 0;
}

Measured memory_bytes: 256