akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	//int a;
	//int b;
	//int c;
	//int d;
	int e;
	//cin >> a >> b;
	string s;
	string p;
	std::cin >> s;
	std::cin >> p;
	if (s[0] == p[2]  &&  s[1] == p[1]  &&  s[2] == p[0]) {
		cout << "YES" << "\n";
	}
	else {
		cout << "NO" << "\n";
	}
	std::cin >> e;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;

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

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize, m: usize,
        ab: [(usize1, usize1); m],
    }
    let mut cnt = vec![0; n];
    for &(a, b) in &ab {
        cnt[a] += 1;
        cnt[b] += 1;
    }
    println!(
        "{}",
        if cnt.iter().filter(|&x| *x % 2 == 1).count() > 1 {
            "NO"
        } else {
            "YES"
        }
    );
}


Measured memory_bytes: 6396
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
    long long dp[1000000] = {0};
    int n;
    cin >> n;

    dp[0] = 1;
    
    for (int i = 2;i <= n;i++)
    {
        if (i % 3 == 0 || i % 5 == 0)
        {
            dp[i - 1] = dp[i -2];
        }
        else
        {
            dp[i - 1] = dp[i - 2] + i;
        }
    }

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


Measured memory_bytes: 11436
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <cmath>
#include <queue>
#include <ctime>
#include <utility> // std::pair
#include <functional> // std::greater <int> ()
#define int long long
#define inf 1000000000000000001
#define BASE 29 // hashings mod, can be rand'd
#define mod 998244353 // can be 1000000007
#define pi 3.1415926535897
#define pii pair <int, int>
#define fii first
#define see second

typedef long long ll;
typedef long double ld;
using namespace std;

int n;
int cnt=0;

// functions
bool chk(int i){
	int cnt=0;
	while(i>0){
		cnt++;
		i/=10;
	}
	if(cnt%2==0){
		return false;
	}
	return true;
}

void input(){
	cin >> n;
	return;
}

void solve(){
	for(int i=1; i<=n; i++){
		cnt+=chk(i);
	}
	return;
}

void output(){
	cout << cnt;
	return;
}

signed main(){
/*
//  REMEMBER TO TURN OFF IFDEF IN PROBLEMS WITH FILE I/O
*/
//#ifdef sheeep
//	freopen("forces.inp", "r", stdin);
//	freopen("forces.out", "w", stdout);
//#endif
	ios_base::sync_with_stdio(false);
//	int t;
//	cin >> t;
//	for(int i=1; i<=t; i++){
		input();
		solve();
		output();
//	}
	return 0;
}
// Author: NamSPro


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const ll mod=1e9+7;
const int MAXN=200010;
ll fact[200010];
ll mod_pow(ll x,ll n){//xのn乗
    if(n%2==0){
        if(n==0){
            return 1;
        }else{
            ll c=mod_pow(x,n/2);
            return c*c%mod;
        }
    }else{
        if(n==1){
            return x;
        }else{
            ll c=mod_pow(x,(n-1)/2);
            return (c*c%mod)*x%mod;
        }
    }
}
ll comb(ll n,ll i){
    ll ret=(((fact[n]*mod_pow(fact[i],mod-2))%mod)*mod_pow(fact[n-i],mod-2))%mod;
    return ret;
}

int main(){
    fact[0]=fact[1]=1;
    for(int i=2;i<MAXN;i++){
        fact[i]=(fact[i-1]*i)%mod;
    }
    ll B,W;
    cin>>B>>W;
    ll p[200001],q[200001];
    p[0]=0; q[0]=0;
    for(int i=1;i<=B+W;i++){
        //p[i]の計算
        p[i]=(2*p[i-1])%mod;
        if(i>=W){
            p[i]+=comb(i-1,W-1);
            p[i]=p[i]%mod;
        }
        //q[i]の計算
        q[i]=(2*q[i-1])%mod;
        if(i>=B){
            q[i]+=comb(i-1,B-1);
            q[i]=q[i]%mod;
        }
        //cout<<p[i]<<' '<<q[i]<<endl;
        //答えの計算
        ll x=mod_pow(2,i+1);
        ll y=(mod_pow(2,i)+2*p[i-1]-2*q[i-1]+2*mod)%mod;
        ll ans=(mod_pow(x,mod-2)*y)%mod;
        cout<<ans<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 6912
fun main(args: Array<String>){
    val (n, m, x) = readLine()!!.split(' ').map{ it.toInt() }
    val a = readLine()!!.split(' ').map { it.toInt() }
    val left = a.count{ it < x}
    val right = a.count{ it > x}
    println(Math.min(left, right))
}

Measured memory_bytes: 38364
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
  
N=int(input())
divs=make_divisors(N)
print(len(str(divs[len(divs)//2])))

Measured memory_bytes: 3060
N,M = gets.chomp.split.map(&:to_i)  # スペースで区切られた複数の整数
ary = gets.chomp.split.map(&:to_i)  # スペースで区切られた複数の整数

N.freeze
M.freeze

#得票数足切り
wk = 0
for num in 0..N-1 do
  wk = wk + ary[num]
end
wk =  wk.to_f * (1.to_f / (4 * M).to_f)

#降順ソート
ary.sort!.reverse!

for num in 0..M-1 do
  if ary[num] < wk then
    puts "No"
    exit
  end
end
puts ("Yes")

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#define db(x) cout << "> " << #x << " = " \
	<< (x) << '\n'
#define db2(x, y) cout << "> " << #x << " = " \
	<< (x) << ", " << #y << " = " << (y) << '\n'
#define db3(x, y, z) cout << "> " << #x << \
	" = " << (x) << ", " << #y << " = " << \
	(y) << ", " << #z << " = " << (z) << '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
typedef map<int, int> mii;
typedef set<int> si;

const int MX = 1e5 + 5;
int n, m, s, t, dist[MX][3];
vvi adj(MX);

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin >> n >> m;
	int u, v;
	for (int i = 0; i < m; ++i) {
		cin >> u >> v;
		adj[u].pb(v);
	}
	cin >> s >> t;
	for (int i = 0; i < MX; ++i) {
		for (int j = 0; j < 3; ++j) {
			dist[i][j] = OO;
		}
	}
	queue<pii> q;
	q.push(mp(s, 0));
	dist[s][0] = 0;
	int lvl;
	while(!q.empty()) {
		pii pr = q.front();
		q.pop();
		u = pr.fs, lvl = pr.sc;
		for (auto& v : adj[u])
			if (dist[v][(lvl + 1) % 3] == OO)
				q.push(mp(v, (lvl + 1) % 3)), dist[v][(lvl + 1) % 3] = dist[u][lvl] + (lvl == 2);
	}
	cout << (dist[t][0] == OO ? -1 : dist[t][0]) << '\n';
	return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char const* argv[])
{
  int n, ts[100], m, p, x;

  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> ts[i];
    sum += ts[i];
  }
  cin >> m;

  while (m--) {
    cin >> p >> x;
    cout << sum - ts[p-1] + x << endl;
  }

  return 0;
}

Measured memory_bytes: 256
//arc063_d.cpp
//Thu Jul  4 23:06:24 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int a[n];
	for (int i=0;i<n;i++){
		cin >> a[i];
	}

	int tempmax = a[n-1];
	int maxdif = 0;
	int ans = 0;
	for (int i=n-2;i>=0;i--){
		if (a[i]>tempmax){
			tempmax = a[i];
		}
		if (tempmax-a[i]==maxdif){
			ans++;
		}else if (tempmax-a[i]>maxdif){
			ans = 1;
			maxdif = tempmax-a[i];
		}
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 640
x, n = map(int, input().split())

p_i = list(map(int, input().split()))

answer_numbers = [[1, 1] for i in range(101)]

for i in range(len(p_i)):
    if x - p_i[i] == 0:
        answer_numbers[0][0] = 0
        answer_numbers[0][1] = 0

    elif x - p_i[i] > 0:
        answer_numbers[abs(x-p_i[i])][0] = 0
    elif x - p_i[i] < 0:
        answer_numbers[abs(x-p_i[i])][1] = 0

for i in range(len(answer_numbers)):
    if not answer_numbers[i] == [0, 0]:
        if answer_numbers[i][0] == 1:
            print(x - i)
            break
        elif answer_numbers[i][1] == 1:
            print(x + i)
            break



Measured memory_bytes: 9168
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define repit(i,a) for(__typeof((a).begin()) i=(a).begin();i!=(a).end();i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

void solve(int a, int l) {
    int cnt = 0;
    map<int, int> m;
    while(true) {
        if(m.find(a) != m.end()) {
            cout << m[a] << " " << a << " " << cnt-m[a] << endl;
            return;
        }
        m[a] = cnt++;
        vector<int> v;
        rep(i, l) {
            v.pb(a%10);
            a /= 10;
        }
        int b = 0, c = 0;
        sort(all(v));
        rep(i, l) {
            b *= 10;
            b += v[i];
        }
        
        sort(rall(v));
        rep(i, l) {
            c *= 10;
            c += v[i];
        }

        a = c - b;
    }
    
}

int main()
{
    int a, l;
    while(cin >> a >> l, a||l) {
        solve(a, l);
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<double> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  
  vector<double> B(N);
  for(int i=0; i<N; i++){
    B.at(i) = 1 / A.at(i);
  }
  double sum;
  for(int i=0; i<N; i++){
    sum += B.at(i);
  }
  cout << 1 / sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cnt[2][214514];
int main(){
	ll n;
	string s;
	cin>>n>>s;
	if(s[0]=='#')cnt[0][0]++;
	else cnt[1][0]++;
	for(int i=1;i<n;i++){
		cnt[0][i]=cnt[0][i-1];
		cnt[1][i]=cnt[1][i-1];
		if(s[i]=='#')cnt[0][i]++;
		else cnt[1][i]++;
	}
	ll ans=cnt[1][n-1];
	for(int i=0;i<n;i++){
			ans=min(ans,cnt[0][i]+cnt[1][n-1]-cnt[1][i]);
	}
	cout<<ans;
	return 0;
}


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

using namespace std;

int main()
{
   string s,t;cin>>s>>t;
   int ans=t.size();
   for(int i=0;i<=s.size()-t.size();i++){
       int diff=0;
       for(int j=0;j<t.size();j++){
           if(t[j]!=s[i+j]) diff++;
       }
       ans=min(ans,diff);
   }
   cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    string t_ = "";
    rep(i, t.size()-1) t_ += t[i];
    (s == t_) ? puts("Yes") : puts("No");
    return 0;
}

Measured memory_bytes: 3628
// 1807
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

char a[105][105];
 
int32_t main()
{
    fast;
    int h, w; cin >> h >> w;
    For(i, 0, w + 2) cout << '#';
    cout << "\n";
    For(i, 0, h) {
        cout << '#';
        For(j, 0, w) {
            cin >> a[i][j];
            cout << a[i][j];
        }
        cout << "#\n";
    }
    For(i, 0, w + 2) cout << '#';
    
    
    return 0;
}

Measured memory_bytes: 3544
#include <stdio.h>

int main()
{
	long long a, v, b, w, t;
	scanf ("%lld %lld %lld %lld %lld", &a, &v, &b, &w, &t);
	long long d = a - b;
	if (d < 0) d = -d;
	puts(t * (v - w) >= d ? "YES" : "NO");

	return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <numeric>
using namespace std;

#define ll signed long long

int gcd(int a, int b) {
  if (a % b == 0) {
    return(b);
  }
  return (gcd(b, a % b));
}

int main() {
  int K;
  cin >> K;
  ll cnt = 0;
  for (int i = 1; i <= K; ++i) {
    for (int j = 1; j <=K; ++j) {
      for (int k = 1; k <= K; ++k) {
        int t = gcd(i, j);
        cnt += gcd(t, k);
      }
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <bits/stdc++.h>
// Input macros
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%lld",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
// Useful constants
#define INF                         (int)1e9
#define EPS                         1e-9
// Useful hardware instructions
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
// Useful container manipulation / traversal macros
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
// Some common useful functions
#define maX(a,b)                     ( (a) > (b) ? (a) : (b))
#define miN(a,b)                     ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)                ( (n >> b) & 1)
#define DREP(a)                      sort(all(a)); a.erase(unique(all(a)),a.end())
#define INDEX(arr,ind)               (lower_bound(all(arr),ind)-arr.begin())
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;



int main()
{
    int n, x;
    vi a;
    s(n);
    forall(i,0,n){
        s(x);
        a.pb(x);
    }
    sort(a.begin(), a.end());
    int ans = unique(a.begin(), a.end()) - a.begin();
    if(ans & 1){
        cout<<ans;
    } else{
        cout<<ans-1;
    }
    return 0;
}


Measured memory_bytes: 892
import Data.List
import Data.Ord
 
split :: [Int] -> [(Int, Int)]
split [] = [(0, 0)]
split [x] = [(x, 0)]
split (x:y:xys) = (x, y) : split xys
 
main :: IO ()
main = do
    n <- readLn :: IO Int
    cards <- (map read) . words <$> getLine :: IO [Int]
    let phases = split $ sortBy (comparing Down) cards
    let folded = foldl (\(f1, s1) (f2, s2) -> (f1+f2, s1+s2)) (0, 0) phases
    print $ fst folded - snd folded

Measured memory_bytes: 1020
package main
import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a)
	fmt.Scan(&b)

	var t1, t2, t3 bool = false, false, false
	if a == 1 || b == 1 {
		t1 = true
	}
	if a == 2 || b == 2 {
		t2 = true
	}

	if t1 == false {
		fmt.Println(1)
	} else if t2 == false {
		fmt.Println(2)
	} else if t3 == false {
		fmt.Println(3)
	}
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int k, x;
  cin >> k >> x;
  cout << (k * 500 >= x ? "Yes\n" : "No\n");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define ll long long int 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define md 1000000007
double PI=3.1415926535;
const int N =  (int)(1 * 1e6 + 10);
using namespace std;

int main()
{   
    string s , t;
    cin>>s>>t;
    ll cnt = 0;
    for(ll i = 0 ; i < s.length() ; i++)
    {
        if(s[i]!=t[i])cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3924
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
typedef long long ll;
const int INFTY = 1001001001;

int main()
{
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for(int i=0;i<N;++i){
        cin >> A[i] >> B[i];
    }
    vector< vector<ll> > dp(N+1 ,vector<ll>(H+1, INFTY));
    for(int i=1;i<=N;++i){
        dp[i][0] = 0;
        for(int j=1; j<=H; ++j){
            dp[i][j] = min(dp[i-1][j], dp[i][max(j - A[i-1], 0)] + B[i-1]);
        }
    }
    cout << dp[N][H] << endl;
}


Measured memory_bytes: 78592
MAX = 1000001

class Query:
    def __init__(self, l, r, idx): 
        self.l = l 
        self.r = r 
        self.idx = idx 
  
# updating the bit array 
def update(idx, val, bit, n): 
    while idx <= n: 
        bit[idx] += val 
        idx += idx & -idx 
  
# querying the bit array 
def query(idx, bit, n): 
    summ = 0
    while idx: 
        summ += bit[idx] 
        idx -= idx & -idx 
    return summ 
  
def answeringQueries(arr, n, queries, q): 
  
    # initialising bit array 
    bit = [0] * (n + 1) 
  
    # holds the rightmost index of  
    # any number as numbers of a[i] 
    # are less than or equal to 10^6 
    last_visit = [-1] * MAX
  
    # answer for each query 
    ans = [0] * q 
  
    query_counter = 0
    for i in range(n): 
  
        # If last visit is not -1 update -1 at the 
        # idx equal to last_visit[arr[i]] 
        if last_visit[arr[i]] != -1: 
            update(last_visit[arr[i]] + 1, -1, bit, n) 
  
        # Setting last_visit[arr[i]] as i and  
        # updating the bit array accordingly 
        last_visit[arr[i]] = i 
        update(i + 1, 1, bit, n) 
  
        # If i is equal to r of any query store answer 
        # for that query in ans[] 
        while query_counter < q and queries[query_counter].r == i: 
            ans[queries[query_counter].idx] = query(queries[query_counter].r + 1, bit, n) -query(queries[query_counter].l, bit, n)
            query_counter += 1
  
    # print answer for each query 
    for i in range(q): 
        print(ans[i]) 
  
# Driver Code 
if __name__ == "__main__": 
    n,q = map(int,input().split())
    a = list(map(int,input().split()))
    # n = len(a)
    queries = []
    for i in range(q):
        l,r = map(int,input().split())
        queries.append(Query(l-1,r-1,i))
    # queries = [Query(0, 4, 0),
    #            Query(1, 3, 1),
    #            Query(2, 4, 2)]
    # q = len(queries)
  
    queries.sort(key = lambda x: x.r) 
    answeringQueries(a, n, queries, q)


Measured memory_bytes: 243780
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

int main() {
    int a, b, c, d; std::cin >> a >> b >> c >> d;

    int min = std::min({a, b, c, d});
    int max = std::max({a, b, c, d});

    int ans = 0;

    for(int i = min; i <= max; i++) {
        if(i >= a && i <= b && i >= c && i <= d) {
            ans ++;
        }
    }

    if(ans) ans --;
    
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <stack>
#include <cstring>
#include <algorithm>

using namespace std;

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

const int WIDTH = 3001;
const int HEIGHT = 51;

int main()
{
	int* dp = new int[HEIGHT * WIDTH];
	
	int n, m, s;
	while(scanf("%d%d%d", &n, &m, &s), n){
		n *= n;
		fill_n(dp, HEIGHT*WIDTH, 0);
		dp[0] = 1;

		reep(i, 1, m+1){
			for(int j=n; j>=0; --j){
				for(int k=s; k>=0; --k){
					if(j && i <= k){
						dp[j*WIDTH + k] = (dp[j*WIDTH + k] + dp[(j-1)*WIDTH + k-i]) % 100000;
					}
				}
			}
		}

		//	rep(i, n+1){
		//		rep(j, s+1)
		//			printf("%d\t", dp[i][j]);
		//		puts("");
		//	}

		printf("%d\n", dp[n*WIDTH + s]);
	}

	delete dp;

	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int res = 0;
    for (int a = 0; a <= A; ++a) {
        for (int b = 0; b <= B; ++b) {
            for (int c = 0; c <= C; ++c) {
                if (X == 500*a + 100*b + 50*c) ++res;
            } 
        }
    }
    cout << res << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<pii, ll> ppiil;
typedef pair<pii, int> ppiii;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define rrep(i, a, b) for (ll i=(a); i>(b); i--)
#define btoe(obj) (obj).begin(), (obj).end()
#define pb push_back
#define str to_string
#define mkp make_pair
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
void chmax(ll &a, ll b) { a = max(a, b); }
void chmin(ll &a, ll b) { a = min(a, b); }

template<typename T>
void print(T out) {
    cout << out << '\n';
}

template<typename T1, typename T2>
void print(pair<T1, T2> out) {
    cout << out.first << ' ' << out.second << '\n';
}

template<typename T>
void print(vector<T> A) {
    rep(i, 0, A.size()) {
        cout << A[i];
        cout << (i == A.size()-1 ? '\n' : ' ');
    }
}

template<typename T>
void print(set<T> S) {
    vector<T> A(btoe(S));
    print(A);
}

ll sum(vector<ll> A) {
    ll res = 0;
    for (ll a: A) res += a;
    return res;
}

ll max(vector<ll> A) {
    ll res = -INF;
    for (ll a: A) chmax(res, a);
    return res;
}

ll min(vector<ll> A) {
    ll res = INF;
    for (ll a: A) chmin(res, a);
    return res;
}

ll sum(ll A[], int len) {
    ll res = 0;
    rep(i, 0, len) res += A[i];
    return res;
}

ll max(ll A[], int len) {
    ll res = -INF;
    rep(i, 0, len) chmax(res, A[i]);
    return res;
}

ll min(ll A[], int len) {
    ll res = INF;
    rep(i, 0, len) chmin(res, A[i]);
    return res;
}

ll toint(string s) {
    ll res = 0;
    for (char c : s) {
        res *= 10;
        res += (c - '0');
    }
    return res;
}

int toint(char c) {
    return c - '0';
}

ll Q, tp, a, b, l, r, mid, asum, bsum, ln;
multiset<ll> S1, S2;

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

    cin >> Q;
    cin >> tp >> a >> b;

    mid = a;
    asum = 0;
    bsum = b;
    ln = 1;
    S1.insert(a);

    rep(_, 1, Q) {
        cin >> tp;
        if (tp == 1) {
            cin >> a >> b;
            bsum += b;
            l = *(--S1.end());
            r = *S2.begin();
            if (ln % 2 == 1) {
                asum += abs(a - l);
                if (a < mid) {
                    S1.insert(a);
                    S2.insert(*(--S1.end()));
                    S1.erase(--S1.end());
                } else {
                    S2.insert(a);
                }
            } else {
                if (a < l) {
                    asum += abs(a - l);
                } else if (a > r) {
                    asum += abs(a - r);
                }
                if (a > mid) {
                    S2.insert(a);
                    S1.insert(*S2.begin());
                    S2.erase(S2.begin());
                } else {
                    S1.insert(a);
                }
            }
            ln++;
            mid = *prev(S1.end());
        } else {
            print(mkp(mid, asum + bsum));
        }
    }
    return 0;
}


Measured memory_bytes: 9600
import java.util.Scanner;

class Main{

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        String a = scanner.next();

        switch(a){
            case "Sunny":
                System.out.println("Cloudy");
                break;
            case "Cloudy":
                System.out.println("Rainy");
                break;
            case "Rainy":
                System.out.println("Sunny");
                break;
            
        }
    
        
    }

    
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s,t; cin>>s>>t;
    vector <string> bit1(26),bit2(26);
    for(int i=0;i<26;i++){
        for(int j=0;j<s.size();j++){
            if(s[j]=='a'+i) bit1[i]+="1";
            else bit1[i]+="0";
        }
    }
    for(int i=0;i<26;i++){
        for(int j=0;j<t.size();j++){
            if(int(t[j])=='a'+i) bit2[i]+="1";
            else  bit2[i]+="0";
        }
    }
   sort(bit1.begin(),bit1.end());
   sort(bit2.begin(),bit2.end());
    bool can=true;
    for(int i=0;i<26;i++){
        if(bit1[i]!=bit2[i]) can=false;
    }
    if(can) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 10968
#include<bits/stdc++.h>
#define f first
#define s second
#define inf 999999999999
#define N  500009
#define M  (L+R)/2
#define ll long long
#define pb push_back
using namespace std;

ll a[5],b[5],fix[5],one,two;

int main()
{

	ios::sync_with_stdio(0);
	
	cin>>a[1]>>b[1];
	cin>>a[2]>>b[2];
	cin>>a[3]>>b[3];
	fix[a[1]]++;
	fix[a[2]]++;
	fix[a[3]]++;
	fix[b[1]]++;
	fix[b[2]]++;
	fix[b[3]]++;
	
	for(int i=1;i<=4;i++)
	{
		if(fix[i]==1)one++;
		if(fix[i]==2)two++;
		
	}
	
	if(one==2 && two==2)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	

	return 0;
}






Measured memory_bytes: 256
n,m = map(int,input().split())
ab = []
for _ in range(m):
  ab.append(list(map(lambda x:int(x)-1, input().split())))
ab.reverse()
pre = [-1 for _ in range(n)]
num = [ 1 for _ in range(n)]
ans = n * (n-1) // 2
out = []
for i in range(m):
  out.append(ans)
  x,y = ab[i]
  X = []
  while pre[x] != -1:
    X.append(x)
    x = pre[x]
  Y = []
  while pre[y] != -1:
    Y.append(y)
    y = pre[y]
  if x != y:
    ans -= num[x] * num[y]
    if x > y:
      pre[y] = x
      num[x] += num[y]
    else:
      pre[x] = y
      num[y] += num[x]
out.reverse()
for o in out:
  print(o)

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

using namespace std;

typedef pair<double, string> pds;

bool hikaku(pds lhs, pds rhs)
{
    if (lhs.first > rhs.first)
        return true;
    else if (lhs.first == rhs.first)
        return lhs.second < rhs.second;
    else
        return false;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    while (cin >> n, n)
    {
        string l;
        double p, a, b, c, d, e, f, s, m;
        vector<pds> v;
        for (int i = 0; i < n; i++)
        {
            cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
            double eff = (f * s * m - p) / (a + b + c + m * (d + e));
            v.push_back(make_pair(eff, l));
            //cout<<eff<<" "<<l<<endl;
        }
        sort(v.begin(), v.end(), hikaku);
        for (int i = 0; i < n; i++)
        {
            cout << v[i].second << endl; //<< " "<<v[i].first<< endl;
        }
        cout << "#" << endl;
    }
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main(){
  double a, b, x;
  cin >> a >> b >> x;
  double s = x/a;
  double theta;
  if(s > a*b/2){
    theta = atan(2*(a*b-s)/(a*a));
    theta = theta/M_PI*180;
  }else{
    theta = atan(b*b/(2*s));
    theta = theta/M_PI*180;
  }
  cout << std::setprecision(10) << theta << endl;
  return 0;
}

Measured memory_bytes: 3960
//package AtCoder;
//package ;
import java.io.*;
import java.util.*;

public class Main {
	static long dp(int i)
	{
		if(i==n-1)
			return 0;
		if(dp[i]!=-1)return dp[i];
		long first=(long)Math.abs(a[i]-a[i+1])+dp(i+1);
		long second=(long)1e9;
		if(i+2<n)
			second=(long)Math.abs(a[i]-a[i+2])+dp(i+2);
		return dp[i]=Math.min(first, second);
	}
	static int n;
	static long dp[],a[];
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		n=sc.nextInt();
		a=new long[n];
		for(int i=0;i<n;i++)a[i]=sc.nextLong();
		dp=new long[n];
		Arrays.fill(dp, -1);
		System.out.println(dp(0));
		pw.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		boolean hasnext() throws IOException {
			return br.ready();
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] a = new Integer[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		char[] nextCharArray() throws IOException {
			return br.readLine().toCharArray();
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] ans = new double[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextDouble();
			return ans;
		}

	}
}


Measured memory_bytes: 48220
#include<bits/stdc++.h>
		using namespace std;
		#define ll long long
		#define endl "\n"
		void solve();
		int main()
		{
			ios_base::sync_with_stdio(false);
			cin.tie(NULL);

		/*#ifndef ONLINE_JUDGE
			freopen("input.txt","r",stdin);
			freopen("output.txt","w",stdout);
		#endif*/
		
			int t=1;
			//cin>>t;
			while(t--){
			solve();
			cout << endl;
			}

			cerr << "time taken : "	<< (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
			return 0;		
		}
		void solve(){
			string s;
			cin>>s;
			for (int i = 0; i < s.size(); ++i)
			{
				if(s[i]==','){
					s[i]=' ';
				}
			}
			cout<<s;
		}
	

Measured memory_bytes: 256
import itertools

N,K = map(int,input().split())

x = (N-1)*(N-2)//2

if x < K:
    print(-1)
    exit()
    
edge = [(1,n) for n in range(2,N+1)]
edge += list(itertools.combinations(range(2,N+1), 2))[:x-K]


print(len(edge))
for x,y in edge:
    print(x,y)

Measured memory_bytes: 3992
using System;

namespace CA {
	class Prg {
		static void Main() {
			string[] str = new string[2];
			string f, m;
			int h, w;
			while (true)
            {
                str = Console.ReadLine().Split(' ');
                h = int.Parse(str[0]);
                w = int.Parse(str[1]);
                if (h <= 0 || w <= 0) break;
                f = new string('#', w);
				m = "#" + new string('.', w - 2) + "#";
                Console.WriteLine(f);
                for (int i = 0; i < h - 2; i++) Console.WriteLine(m);
                Console.WriteLine(f);
                Console.WriteLine();
            }
        }
	}
}

Measured memory_bytes: 8964
#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;
  vector<int> X(N);
  rep(i, N) cin >> X[i];
  sort(X.begin(), X.end());
  int sum = 0;
  int min = 99999999;
  rep(i, 100+1){
    int P = i;
    sum = 0;
    rep(j, N){
      sum += pow(X[j] - P, 2);
    }
    if(min > sum) min = sum;
  }
  cout << min << endl;
  return 0;

}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    string S, T; cin >> S >> T;
    int ans = 0;
    F0R(i, sz(S)) if (S[i] != T[i]) ans++;
    cout << ans << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3824
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}



int main(void){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int sum = a*x + b*y;
    int max = (x>y)?x:y;

    for(int i=2;i<=2*max;i+=2){
        int subsum = 0;
        if(x-(i/2)>0 && y-(i/2)>0){
            subsum = a*(x-(i/2))+b*(y-(i/2))+c*i;
        }else if(x-(i/2)<=0 && y-(i/2)<=0){
            subsum = c*i;
        }else if(x-(i/2) <= 0){
            subsum = b*(y-(i/2)) + c*i;
        }else if(y-(i/2) <= 0){
            subsum = a*(x-(i/2)) + c*i;
        }

        if(sum>subsum){
            sum = subsum;
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
using mp = map<int,int>;
const int MN = 2e5+2, MOD = 1e9+7;
map<ll,int> cnt;
ll psa[MN];
int main () {
	//(psa[i]-psa[j]) mod k == i-j
	//)psa[i] mod k - psa[j] mod k == i-j
	//(psa[i] mod k) - i == (psa[j] mod k) - j
	int n,k;
	scanf ("%d %d",&n,&k);
	ll ret = 0;
	cnt[0] = 1;
	for (int i = 1; i <= n; i++) {
		scanf ("%lld",&psa[i]);
		psa[i] += psa[i-1];
		if (i >= k) cnt[(psa[i-k]%k-(i-k)%k+k)%k]--;
		ret += cnt[(psa[i]%k-i%k+k)%k]++;
	}
	printf ("%lld\n",ret);
    return 0;
}


Measured memory_bytes: 14336
s = str(input())
tf = True
for i,letter in enumerate(s):
  if (i) % 2 == 0:
    if letter not in ['R','U','D']:
      tf = False
  if (i) % 2 == 1:
    if letter not in ['L','U','D']:
      tf = False
if tf:
  print('Yes')
else:
  print('No')


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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){

    bool flag=false;

    int h,w,k;
    cin>>h>>w>>k;

    vector<vector<char>> ck(h,vector<char>(w));
    vector<vector<int>> ans(h,vector<int>(w,0));
    
    vector<bool> st(h,false);
    vector<int> rowgl(h,0);

    rep(i,h){
        rep(j,w){
            cin>>ck[i][j];
            if(ck[i][j]=='#')st[i]=true;
        }
    }


    bool fistb=false;
    int rowglcnt=0;
    vector<vector<int>>rowlist(1);

    rep(i,h){
        if(st[i] && !fistb){
            fistb=true;
        }
        else if(st[i]){
            rowglcnt++;
            rowlist.push_back( vector<int>() );
        }
        rowgl[i] = rowglcnt;
        rowlist.back().push_back(i); 

        //db2(i,rowgl[i]);ln;
    }


    int glcnt=0;
    rep(i,h){
        if(!st[i])continue;
        ++glcnt;

        fistb=false;
        rep(j,w){

            if(ck[i][j]=='#' && !fistb){
                fistb=true;
            }else if(ck[i][j]=='#'){
                glcnt++;
            }

            ans[i][j] = glcnt;
        }

        int curgl = rowgl[i];
        for(int row : rowlist[curgl]){
            if(row!=i)ans[row]=ans[i];
        }
    }

    rep(i,h){
        rep(j,w)cout<<ans[i][j]<<" ";
        ln;
    }

    /*
    int cnt=0;
    for(vector<int> vc:rowlist){
        cout<<cnt<<"  :   ";
        for(int rowi:vc)cout<<rowi<<" ";
        ++cnt;ln;
    }
    */



    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e16+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll h,w;
	cin >> h >> w;
	ll ans = INF;
	FOR(i,1,h){
		ll s1 = i*w;
		ll s2,s3;
		if((h-i)%2==0||w%2==0){
			s2 = s3 = w*(h-i)/2;
		}else{
			ll x = max(h-i,w)/2;
			ll y = max(h-i,w)/2+1;
			ll z = min(h-i,w);
			s2 = x*z;
			s3 = y*z;
		}
		ans = min(ans,max({s1,s2,s3})-min({s1,s2,s3}));
	}
	swap(h,w);
	FOR(i,1,h){
		ll s1 = i*w;
		ll s2,s3;
		if((h-i)%2==0||w%2==0){
			s2 = s3 = w*(h-i)/2;
		}else{
			ll x = max(h-i,w)/2;
			ll y = max(h-i,w)/2+1;
			ll z = min(h-i,w);
			s2 = x*z;
			s3 = y*z;
		}
		ans = min(ans,max({s1,s2,s3})-min({s1,s2,s3}));
	}
	cout << ans << endl;
}	

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        q: usize,
        a: [u64; n],
    }

    let mut t = FenwickTree::from_vec(a);
    for _ in 0..q {
        input! { f: usize };
        if f == 1 {
            input! { l: usize, r: usize }
            println!("{}", t.sum(l, r));
        } else {
            input! { p: usize, x: u64 }
            t.add(p, x);
        }
    }
}

struct FenwickTree<T> {
    v: Vec<T>,
}

use std::ops::AddAssign;
use num::{Integer, zero};

impl<T: Copy + AddAssign + Integer> FenwickTree<T> {
    fn new(n: usize) -> Self {
        Self {
            v: vec![zero(); n],
        }
    }

    fn from_vec(v: Vec<T>) -> Self {
        let n = v.len();
        let mut t = Self::new(n);
        for i in 0..n {
            let v = t.v[i] + v[i];
            t.v[i] = v;
            let p = i + ((i + 1) & (i + 1).wrapping_neg());
            if p < n {
                t.v[p] += v;
            }
        }
        t
    }

    fn add(&mut self, i: usize, v: T) {
        let mut i = i;
        while i < self.v.len() {
            self.v[i] += v;
            i += (i + 1) & (i + 1).wrapping_neg();
        }
    }

    fn sum(&self, l: usize, r: usize) -> T {
        self.get(r) - self.get(l)
    }

    fn get(&self, mut i: usize) -> T {
        let mut v = zero();
        while i > 0 {
            v += self.v[i - 1];
            i -= i & i.wrapping_neg();
        }
        v
    }
}


Measured memory_bytes: 22996
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  int n; cin >> n;
  int64 c; cin >> c;
  
  vector<int64_t> x(n), v(n);
  rep(i, n) cin >> x[i] >> v[i];

  int64 ans = -INF64;

  // clockwise
  int64 sum1 = 0;
  int64 get1[101010] = {};
  int64 mx1[101010] = {};
  for (int i = 0; i < n; ++i) {
    sum1 += v[i];
    get1[i] = sum1 - x[i];
  }

  int64 m1 = -INF64;
  for (int i = 0; i < n; ++i) {
    mx1[i] = max(m1, get1[i]);
    chmax(m1, get1[i]);
  }

  //counterclockwise
  int64 sum2 = 0;
  int64 get2[101010] = {};
  int64 mx2[101010] = {};
  for (int i = n - 1; i >= 0; --i) {
    sum2 += v[i];
    get2[i] = sum2 - (c - x[i]);
  }

  int64 m2 = -INF64;
  for (int i = n - 1; i >= 0; --i) {
    mx2[i] = max(m2, get2[i]);
    chmax(m2, get2[i]);
  }

  ans = max({mx1[n - 1], mx2[0], (int64)0});

  // A : right, B : left
  // fix A
  for (int i = 0; i <= n - 2; ++i) {
    chmax(ans, get1[i] + mx2[i + 1] - x[i]);
  }

  // fix B
  for (int i = n - 1; i >= 1; --i) {
    chmax(ans, get2[i] + mx1[i - 1] - c + x[i]);
  }

  print(ans);

  return 0;
}

Measured memory_bytes: 4992
N=int(input())
an=sorted(list(map(int,input().split())))
dic={}

for ai in an:
  if ai not in dic:dic[ai]=1
  else:dic[ai]+=1
  pass

max_v=0
for x in range(an[0],an[-1]+1):
  v=0
  if x-1 in dic: v+=dic[x-1]
  if x   in dic: v+=dic[x]
  if x+1 in dic: v+=dic[x+1]
  max_v=max(max_v,v)
print(max_v)

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

int main(){
  int n;
  cin >> n;
  long long X=0,x=0,ans=1e18;
  vector<long long> a(n);
  for (int i=0;i<n;i++){
    cin >> a[i];
    X+=a[i];
  }
  for(int i=0;i<n;i++){
    x+=a[i];
    if (i<n-1) ans=min(ans,abs(X-2*x));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int k = sc.nextInt();
		TreeSet<String> set = new TreeSet<>();
		for (int i = 0; i < str.length(); i++) {
		    for (int j = 1; j <= k && i + j <= str.length(); j++) {
		        set.add(str.substring(i, i +j));
		    }
		}
		int idx = 1;
		for (String s : set) {
		    if (idx == k) {
		        System.out.println(s);
		        return;
		    }
		    idx++;
		}
	}
}


Measured memory_bytes: 25300
#include<algorithm>
#include<limits.h>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>


int main(void) {
	int N = 0, M = 0;
	char A[52][52] = { "\0" };
	char B[52][52] = {"\0"};
	scanf("%d%d", &N, &M);

	for (int i = 0; i < N; i++) {
		scanf("%s", A[i]);
	}
	for (int i = 0; i < M; i++) {
		scanf("%s", B[i]);
	}
	for (int i = 0; i <= N - M; i++) {
		for (int j = 0; j <= N - M; j++) {
			bool tf = false;
			for (int k = 0; k < M; k++) {
				for (int l = 0; l < M; l++) {
					if (A[i + k][j + l] != B[k][l])
						goto NEXT;
				}
			}
			tf = true;
		NEXT:;
			if (tf == true) {
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
n_k = input().split(' ')

n = [0]*int(n_k[0])
k = int(n_k[1])

for k_ in range(k):
    d = int(input())
    l = input().split(' ')
    for d_ in range(d):
        n[int(l[d_])-1] += 1

count = 0
for i in n:
    if i == 0:
        count += 1

print(count)

Measured memory_bytes: 9216
#include <stdio.h>

#define S(num)	((num) * (num))
#define H(n)	((5.0) * (n) - (5.0))

int main(void)
{
	float in_data;
	float time;
	float high;
	int i;
	
	while (scanf("%f", &in_data) != EOF){
		time = in_data / 9.8;
		high = 4.9 * S(time);
		i = 0;
		while (1)if (H(++i) >= high)break;
		
		printf("%d\n", i);
	}
	
	return (0);
}

Measured memory_bytes: 0