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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin >> a>> b >> c >> d;
    if(abs(a-b)<=d&&abs(b-c)<=d || abs(a-c)<=d)YES;
    else NO;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=505;
struct data{
	int x,id,now;
}a[N],b[N];
bool cmp(data a,data b){
	return a.x<b.x;
}
int n,now,x[N*N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].x);
		if(a[i].x<i){
			puts("No");
			return 0;
		}
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		while(a[i].now<a[i].id-1){
			now++;
			if(x[now]){
				continue;
			}
			x[now]=a[i].id;
			a[i].now++;
		}
		if(now>=a[i].x){
			puts("No");
			return 0;
		}
		x[a[i].x]=a[i].id;
		a[i].now++;
	}
	now=n*n+1;
	for(int i=n;i>=1;i--){
		while(a[i].now<n){
			now--;
			if(x[now]){
				continue;
			}
			x[now]=a[i].id;
			a[i].now++;
		}
		if(now<=a[i].x){
			puts("No");
			return 0;
		}
		x[a[i].x]=a[i].id;
		a[i].now++;
	}
	puts("Yes");
	for(int i=1;i<=n*n;i++){
		printf("%d ",x[i]);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 2048
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (n, m) = {
      let v: Vec<usize> = read_vec();
      (v[0], v[1])
    };

    let mut ks: Vec<Vec<i64>> = Vec::new();
    for _ in 0..m {
      let v: Vec<i64> = read_vec();
      ks.push(v);
    }

    let p: Vec<i64> = read_vec();
    let ans = dfs(n as i64, Vec::new(), &ks, &p);
    println!("{}", ans);
}


fn dfs(n: i64, v: Vec<i64>, ks: &Vec<Vec<i64>>, p: &Vec<i64>) -> i64 {
  if n == 0 {
    return count(v, ks, p);
  }

  let mut v1 = v.clone();
  v1.push(0);
  let mut v2 = v.clone();
  v2.push(1);
  let c1 = dfs(n-1, v1, ks, p);
  let c2 = dfs(n-1, v2, ks, p);

  return c1 + c2;
}

fn count(v: Vec<i64>, ks: &Vec<Vec<i64>>, p: &Vec<i64>) -> i64 {
  let m: usize = ks.len();


  let mut count = 1;

  for i in 0..m {
    let mut temp = 0;
    for j in 1..ks[i][0] as usize + 1 {
      if v[ks[i][j] as usize - 1] == 0 {
        temp += 1;
      }
    }
    if temp % 2 != p[i] {
      count = 0;
    }
  }
  return count;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int main(){
  uli x,y;
  cin>>x>>y;
  if(x%y==0){
    puts("-1");
    return 0;
  }
  for(uli v=x;v<=uli(1e18);v+=x){
    if(v%y!=0){
      printf("%lld\n",v);
      return 0;
    }
  }
  puts("-1");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define trav(v, x) for (auto v : x)
#define re(x, y, z) for (int x=y; x<z; ++x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
const int maxn = 3010;
int t[maxn][maxn];
long long memo[maxn][maxn][5];

int main() {
    int r, c, k;
    scanf("%d %d %d", &r, &c, &k);
    for (int i = 0; i < k; ++i) {
        int x, y, v;
        scanf("%d %d %d", &x, &y, &v);
        t[x-1][y-1] = v;
    }
    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            for (int l = 0; l <= 3; ++l) {
                if (i == 0 && j == 0) {
                    if (l == 1) memo[i][j][1] = t[i][j]; 
                    continue;
                }
                if (j > 0) {
                    memo[i][j][l] = memo[i][j-1][l];
                    if (l > 0) {
                        memo[i][j][l] = max(memo[i][j][l], memo[i][j-1][l-1] + t[i][j]);
                    }
                } 
                if (i > 0) {
                   memo[i][j][0] = max(memo[i][j][0], memo[i-1][j][l]);
                    if (l > 0) {
                        memo[i][j][1] = max(memo[i][j][1], memo[i-1][j][l] + t[i][j]);
                    } 
                }
            }    
        }    
    }
    cout << *max_element(memo[r-1][c-1], memo[r-1][c-1] + 4) << endl;
    return 0;
}

Measured memory_bytes: 391300
# frozen_string_literal: true

n, m = gets.split.map(&:to_i)
s, c = m.times.map { gets.split.map(&:to_i) }.transpose

nums = Array.new(n + 1, 0)

m.times do |i|
  if s[i] == 1 && c[i] == 0 && n >= 2 || (nums[s[i]] != 0 && nums[s[i]] != c[i])
    puts -1
    exit 0
  end

  nums[s[i]] = c[i]
end

if n >= 2 && nums[1] == 0
  puts [1, *nums[2..n]].join('')
else
  puts nums[1..n].join('')
end


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        String str = sc.nextLine();
        char[] cha = str.toCharArray();
        for(int i = 0; i < cha.length; i++)
            if(Character.isLowerCase(cha[i])){
                build.append(Character.toUpperCase(cha[i]));
            }else if(Character.isUpperCase(cha[i])){
                build.append(Character.toLowerCase(cha[i]));
            }else{
                build.append(cha[i]);
        }
        System.out.println(build.toString());
    }
}

Measured memory_bytes: 25996
#include<iostream>
using namespace std;
int main() {
int N,M,K,j,countend,a;
  
  cin >> N;
  cin >> M;
  
  int A[N+1][M+1];
  int count[M+1]={0};
  
  int n=1;
  while (n<=N) {
  cin >> K;
  int k=1;
    
          while (k<=K) {
          cin >> a;
            int m=1;
            while (m<=M) {
            if (a==m) count[m]=count[m]+1;
            m=m+1;
            }
          k=k+1;
           }
    n=n+1;
    
  }

  countend=0;
  int m=1;

  while (m<=M) {
  
 if (count[m]==N) countend = countend +1;
  m=m+1;
  }
  cout << countend;
  cout << endl;
    
return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[300010],ans;
signed main(){
  int N;
  scanf("%ld",&N);

  for(int i=0;i<3*N;i++){
    scanf("%ld",&a[i]);
  }
  int t=3*N;
  sort(a,a+t);

  for(int i=t-2;i>=N;i-=2){
  //  cout<<a[i]<<endl;
    ans+=a[i];
    //cout<<ans<<endl;
  }
  cout<<ans<<endl;


  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<char>s(n);
    rep(i,n)cin >> s[i];
    int ans = 0;
    for(int i = 0;i < n-1;i++){
        int sum = 0;
        vector<bool>al1(26),al2(26);
        rep(j,n){
            al1[j]=false; al2[j] = false;
        }
        for(int j = 0;j<n;j++){
            if(j<=i)al1[s[j]-'a']=true;
            else al2[s[j]-'a']=true;
        }
        rep(j,26){
            if(al1[j]&&al2[j])sum++;
        }
        ans = max(ans,sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))

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

ans = []
for i in range(m - 1, 0, -1):
    ans.append(x[i] - x[i - 1])

ans = sorted(ans, reverse=True)
print(sum(ans[n-1:]))

Measured memory_bytes: 13696
#include<iostream>
#include<stdio.h>

using namespace std;

int main(void){

    int y, m, d;

    scanf("%d/%d/%d", &y, &m, &d);

    if(y <= 2019 && m <= 4){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#include <variant>
#define endl codeforces
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec<decltype(v)>(s, v); }
template <typename T, std::size_t Head, std::size_t... Tail> struct multi_dem_array { using type = std::array<typename multi_dem_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dem_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t... Args> using mdarray = typename multi_dem_array<T, Args...>::type;
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }

int main() {
    ll n;
    std::cin >> n;
    std::map<ll, ll> cnts;
    ll ans = 0;
    vec<ll> av(n);
    for (ll &e : av) std::cin >> e;
    for (ll i = 0; i < n; i++) {
        ll a = av[i];
        ans += cnts[-((i + 1) - a)];
        cnts[-(i + 1) - a]++;
    }
    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 27364
#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 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
 
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);    
	
    int N; cin >> N;
    ll A[N]; F0R(i, N) cin >> A[i];
    F0R(i, N) {
        if (A[i] == 0) {
            cout << 0 << nl; return 0;
        }
    }
    ld L = 0;
    F0R(i, N) {
        L += log10(A[i]);
    }
    if (L > 18.1) {
        cout << -1 << nl; return 0;
    }
    ll ans = 1; F0R(i, N) ans *= A[i];
    if (ans > 1000000000000000000) {
        cout << -1 << nl; return 0;
    }
    cout << ans << nl;
	
	return 0;
}
 


Measured memory_bytes: 4628
import sys


def integral(x, d):
    ds = range(d, x, d)
    ds2 = map((lambda a: a**2 * d), ds)
    ds3 = reduce((lambda b, c: b + c), ds2, 0)
    return ds3


#input_file = open(sys.argv[1], "r")

#for line in input_file:
for line in sys.stdin:
    d = int(line)
    area = integral(600, d)
    print area

Measured memory_bytes: 4340
import java.util.*;

public class Main {

    public static double result = 0;
  
	public static void main(String[] args) {

		// argumentの取得
		Scanner sc = new Scanner(System.in);
		double x = sc.nextInt();
      
        // 奇数の数 ÷ 数全体
        // 5の場合 3 / 5
        // 任意の整数Nが含む奇数の数は 1 + (N-1)/2個
      
        if ((x % 2) == 0) {
          //System.out.println("偶数");
          result = ((x / 2) / x);
        } else {
          //System.out.println("奇数");
          if (x == 1) {
            result = 1;
          } else {
            result = ((((x -1)/2) + 1) / x);
          }
        }
      
		// 戻り値の返却
		System.out.println(String.format("%.10f", result));
	
	} 
}

Measured memory_bytes: 21972
#include <iostream>

using namespace std;

int main()
{

int a, b;

cin >> a >> b;

if(a - b > 0)
{
cout << "a > b" << endl;
}
else if(b - a > 0)
{
cout << "a < b" << endl;
}
else if(a == b)
{
cout << "a == b" << endl;
}

return 0;

}

Measured memory_bytes: 3092
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := make([]int, n+1)
	for i := range a {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}

	ans := 0
	for i := 0; i < n; i++ {
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())
		if b <= a[i] {
			ans += b
			continue
		}
		ans += a[i]
		b = b - a[i]

		if b <= a[i+1] {
			a[i+1] -= b
			ans += b
			continue
		}
		ans += a[i+1]
		a[i+1] = 0
	}
	fmt.Println(ans)
}


Measured memory_bytes: 4608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  int answer = 999, i, temp_number;
  char str[11];
  char convert_str[4];
  scanf("%s", str);
  for(i = 0; i < strlen(str) - 2; i++) {
    convert_str[0] = str[i];
    convert_str[1] = str[i+1];
    convert_str[2] = str[i+2];
    temp_number = atoi(convert_str);
    temp_number = abs(temp_number - 753);
    if(answer > temp_number) {
      answer = temp_number;
    }
  }
  printf("%d\n", answer);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define double long double
using namespace std;
typedef pair<ll, ll>P;
double mypow(double x, ll y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1) * x;
	else return mypow(x, y / 2) * mypow(x, y / 2);
}
signed main() {
	ll n, k;
	string s;
	cin >> n >> k >> s;
	s[k - 1] = s[k - 1] - 'A' + 'a';
	cout << s << endl;
	ggr
}


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

#define lowbit(x) ((x) & -(x))

const int maxn = 1e5 + 20;
const int MOD = (int) 1e9 + 7;

int n, m;
int s[20];
int ss;

void work()
{
    memset(s, 0, sizeof(s));
    ss = 0;
    cin >>n >>m;
    for(int i = 0; i < m; i++)
    {
        int c;
        cin >>c;
        for(int j = 0; j < c; j++)
        {
            int x; cin >>x; x--;
            s[x] |= (1 << i);
        }
    }

    for(int i = 0; i < m; i++)
    {
        int x; cin >>x;
        ss |= (x << i);
    }

    int cnt = 0;
    for(int i = 0; i < (1 << n); i++)
    {
        int t = 0;
        for(int j = 0; j < n; j++)
            if(i & (1 << j))
                t ^= s[j];

        if(t == ss) cnt++;
    }

    cout <<cnt <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
    int tc = 1;
//    cin >>tc;
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

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

vector< vector<int> > Graph;
vector< int > value;



int main(int argc, const char * argv[]) {
    
    
    cin.tie(0);
    ios::sync_with_stdio(false);
   
    
    int n,m,x,y; cin >> n >> m >> x >> y;
    vector<int> xtown(n);
    vector<int> ytown(m);
    rep(i,n) cin >> xtown[i];
    rep(i,m) cin >> ytown[i];
    
    sort(xtown.begin(),xtown.end());
    sort(ytown.begin(),ytown.end());
    
    if(   max(x,xtown.back()) <  min(y,ytown.front())    ) cout << "No War" << endl;
    else cout << "War" << endl;
    
    
    
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

int main()
{
  string n; cin >> n;
  string ans = "No";
  REP(i, SIZE(n)) {
    if (n[i] == '7') {
      ans = "Yes";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
long long int com(long int n,long int r){
  long long int re=1;
  long long int pre=1;
  for(long long int i=0; i<r; i++){
    re*=n-i;
    if(re%(r-i)==0){
      re/=r-i;
    }else{
      pre*=r-i;
    }
    if(re%pre==0){
      re/=pre;
      pre=1;
    }
  }
  re/=pre;
  return re;
}
int main(void){
  int n,p;
  cin>>n>>p;
  vector<long long int> a(n);
  int ki=0;
  int gu=0;
  for(long long int i=0; i<n; i++){
    cin>>a.at(i);
    if(a.at(i)%2==0){
      gu++;
    }else{
      ki++;
    }
  }

  long long int pre=pow(2,gu);
  long long int zero=0;
  long long int one=0;
  for(int i=0; i<=ki; i++){
    if(i%2==0){
      zero+=com(ki,i);
    }else{
      one+=com(ki,i);
    }
  }
  zero*=pre;
  one*=pre;
  
  if(p==0){
    cout<<zero<<endl;
  }else{
    cout<<one<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		boolean match = true;
		String s;
		match = match && S.substring(0, 1).equals("A");
		int cntC = 0;
		for (int i = 1; i < S.length(); i++) {
			s = S.substring(i, i + 1);

			if (i >= 2 && i < S.length() - 1) {
				if (s.equals("C")) {
					cntC++;
				}
			}
			if (!s.equals("C")) {
				match = match && s.matches("[a-z]");
			}
		}
		match = match && cntC == 1;
		System.out.println(match ? "AC" : "WA");
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 200005, INF = 0x3f3f3f3f3f3f3f3f;
struct ii {
    ll a, b;
    bool operator < (ii o) const {
        return tie(a, b) < tie(o.a, o.b);
    }
    bool operator > (ii o) const {
        return tie(a, b) > tie(o.a, o.b);
    }
};

ll N, K, cnt[MAXN];
vector<ll> col[MAXN];

ll sumTwo(const vector<ll> &v) {
    return v[0]+v[1];
}

ll sumThree(const vector<ll> &v) {
    return v[0]+v[1]+v[2];
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> N >> K;
    for (ll i = 1; i <= N; i++) {
        ll c, v;
        cin >> c >> v;
        col[c].push_back(2*v);
    }
    
    vector<ii> arr;
    arr.push_back({INF, INF});
    set<ii> in[5], out[5];
    for (ll i = 1; i <= K; i++) {
        sort(col[i].begin(), col[i].end(), greater<ll>());
        col[i][0] = col[i][1] = sumTwo(col[i])/2;
        in[2].insert({sumTwo(col[i]), i});
        if (col[i].size() >= 3) in[3].insert({sumThree(col[i]), i});
        
        for (int j = 0; j < (int)col[i].size(); j++) {
            arr.push_back({col[i][j], i});
        }
    }
    sort(arr.begin(), arr.end(), greater<ii>());
    //~ for (auto i: arr) cerr << i.a << " " << i.b << "\n";
    
    ll sum = 0;
    for (ll i = 1; i <= N; i++) {
        if (in[2].find({sumTwo(col[arr[i].b]), arr[i].b}) == in[2].end()) {
            cout << (sum+arr[i].a)/2 << "\n";
        } else {
            ll ans = -2;
            if (!in[1].empty()) {
                ans = max(ans, sum+in[1].rbegin()->a);
            }
            if (!in[2].empty() && !out[1].empty()) {
                ans = max(ans, sum+out[1].rbegin()->a+in[2].rbegin()->a);
            }
            if (!in[3].empty() && !out[2].empty()) {
                ans = max(ans, sum+out[2].rbegin()->a+in[3].rbegin()->a);
            }
            cout << ans/2 << "\n";
        }
        int c = arr[i].b;
        cnt[c]++;
        sum += arr[i].a;
        if (cnt[c] == 1) {
            out[1].insert({-arr[i].a, c});
            //~ cerr << -arr[i].a << " " << c << " masuk\n";
            in[2].erase({sumTwo(col[c]), c});
            if (col[c].size() >= 3) in[3].erase({sumThree(col[c]), c});
        }
        if (cnt[c] == 2) {
            // valuenya pasti sama kayak yang in
            out[1].erase({-arr[i].a, c});
            out[2].insert({-sumTwo(col[c]), c});
        }
        if (cnt[c] >= 2) {
            if (cnt[c] >= 3) in[1].erase({col[c][cnt[c]-1], c});
            if ((int)col[c].size() > cnt[c]) in[1].insert({col[c][cnt[c]], c});
        }
        if (cnt[c] == 3) {
            out[2].erase({-sumTwo(col[c]), c});
        }
        if (cnt[c] >= 3) {
            if (cnt[c] >= 4) out[1].erase({-col[c][cnt[c]-2], c});
            out[1].insert({-col[c][cnt[c]-1], c});
        }
        if (cnt[c] >= 4) {
            if (cnt[c] >= 5) out[2].erase({-col[c][cnt[c]-2]-col[c][cnt[c]-3], c});
            out[2].insert({-col[c][cnt[c]-1]-col[c][cnt[c]-2], c});
        }
    }
}


Measured memory_bytes: 24428
package main

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

func main() {
	S := readS()
	if S[2] == S[3] && S[4] == S[5] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

/*-----------Utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

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

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}


Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<a[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
	public static void main(String[] args) {

		InputStreamReader sr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(sr);
        try{
	        String[] str = br.readLine().split(" ");
			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[1]);
			int c = Integer.parseInt(str[2]);	
			int count = 0;

			for (;a <= b; a++ ) {
				if (0 == c % a) {
					count++;
				}
			}

			System.out.println(count);
			
		}	
		catch(IOException e) {
            e.printStackTrace();
        }
	}
}

Measured memory_bytes: 24468
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
    int h, w;
    cin >> h >> w;
    int a[500][500];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int d;
            cin >> d;
            a[i][j] = d;
        }
    }
    vector<vector<int> > v;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w - 1; j++) {
            if (a[i][j] % 2 == 1) {
                a[i][j]--;
                a[i][j+1]++;
                vector<int> vv;
                vv.push_back(i);
                vv.push_back(j);
                vv.push_back(i);
                vv.push_back(j+1);
                v.push_back(vv);
            }
        }
    }
    for (int i = 0; i < h - 1; i++) {
        if (a[i][w-1] % 2 == 1) {
            a[i][w-1]--;
            a[i+1][w-1]++;
            vector<int> vv;
            vv.push_back(i);
            vv.push_back(w-1);
            vv.push_back(i+1);
            vv.push_back(w-1);
            v.push_back(vv);
        }
    }
    cout << v.size() << endl;
    for (int i = 0; i < v.size(); i++) {
        printf("%d %d %d %d\n", v[i][0]+1, v[i][1]+1, v[i][2]+1, v[i][3]+1);
    }
    return 0;
}


Measured memory_bytes: 9904
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    if(N % 1000 == 0) cout << 0 << endl;
    else cout << 1000 - (N % 1000) << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int L = S.size();
  for(int i = 0; i < N -1;i++){
  if(S.at(i) == S.at(i+1)){
  L -= 1;
  }
  }
  cout << L;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;


int main(void){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    bool isTakahasi = true;
    while(true){
        if(a <= 0){
            cout<<"No"<<endl;
            break;
        }
        if(c <= 0){
            cout<<"Yes"<<endl;
            break;
        }
        if(isTakahasi == true){
            c -= b;
        }
        else{
            a -= d;
        }
        isTakahasi = !isTakahasi;
    }
}

Measured memory_bytes: 3636
class PriorityQueue
  attr_reader :values

  def initialize(&comparator)
    @values = [nil]
    @pos = 0
    @comparator = comparator || -> (a, b) { a <=> b }
  end

  def push(value)
    @pos += 1
    @values[@pos] = value

    i = @pos

    while i >= 2 && @comparator.call(@values[i], @values[i / 2]) < 0
      @values[i], @values[i / 2] = @values[i / 2], @values[i]
      i /= 2
    end
  end

  def pop
    return nil if @pos < 1

    ret = @values[1]
    @values[1] = @values[@pos]
    @pos -= 1

    i = 1

    loop do
      l = i * 2
      r = l + 1

      j = l <= @pos && @comparator.call(@values[i], @values[l]) > 0 ? l : i
      j = r <= @pos && @comparator.call(@values[j], @values[r]) > 0 ? r : j

      break if j == i

      @values[i], @values[j] = @values[j], @values[i]

      i = j
    end

    ret
  end
end

if $PROGRAM_NAME == __FILE__
  queue = PriorityQueue.new do |a, b|
    b <=> a
  end

  while line = gets
    line = line.chomp

    break if line == 'end'

    command, value = line.split
    value = value.to_i if value

    case command
    when 'insert'
      queue.push(value)
    when 'extract'
      puts queue.pop
    else
      raise "unknown command: #{command}"
    end
  end
end

Measured memory_bytes: 16616
n,m = map(int, input().split())

list = []
for i in range(m):
	line = map(int, input().split())
	for l in line:
		list.append(l)

list.sort()

for i in range(1,n+1):
	cnt = 0
	for elem in list:
		if i == elem:
			cnt += 1
	print(cnt)


Measured memory_bytes: 2940
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	int p;
	cin >> p;
	int res = p / 1.08;
	if ((int)(res * 1.08) == p) 
		cout << res << endl;
	else if ((int)(res * 1.08 + 1.08) == p)
		cout << res + 1 << endl;
	else
		cout << ":(" << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ACはうれCすぎてうれD */

int main(void){ 
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    vector<int> RG;
    for(int i=0; i<=(n/r); i++){
        for(int j=0; j<=(n/g); j++){
            int r_plus_g = r*i + g*j;
            RG.push_back(r_plus_g);
        }
    }
    sort(RG.begin(), RG.end());

    int ans = 0;
    for(int i=0; i<=(n/b); i++){
        int obj = n - b*i;
        if(binary_search(RG.begin(), RG.end(), obj)){
            ans += upper_bound(RG.begin(), RG.end(), obj) - lower_bound(RG.begin(), RG.end(), obj);
        }
    }

    cout << ans;
    return 0;
}

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

int main()
{
	int h,a,sum =0; cin >> h>>a;
	while (a--) {
		int x; cin >> x; sum += x;
	}
	if (sum >= h) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

int n;

void dfs(string s, char maxi, int len) {
  if (len == n) {
    outl(s);
    return;
  }

  for (char c = 'a'; c <= maxi + 1; c++) {
    dfs(s + ctos((char)c), max(maxi, c), len + 1);
  }
}

void solve() {
  cin >> n;
  dfs("a", 'a', 1);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long 
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

ll power(ll x , ll y){
	if(y==0)return 1;
	ll ps = power(x,y/2)%mod;
	ll ss = (ps%mod*ps%mod)%mod;
	if(y&1)ss=(ss%mod*x%mod)%mod;
	return ss;
}
ll ncr(ll n , ll r){
	if(n<r)return 0;
	if(n-r<r)r=n-r;
	ll p=1 , k=1;
	if(r!=0){
		while(r>0){
			p=(p%mod*n%mod)%mod;
			k=(k%mod*r%mod)%mod;
			n--;r--;
		}
	}
	ll ans = (p%mod*power(k,mod-2)%mod)%mod;
	return ans ;
}

int main(){
	//mahakal();fast;

	ll n , a, b ;
	cin>>n>>a>>b;
	ll ans = power(2,n)-1;
	ans = (ans + mod)%mod;
	ans = ans - ncr(n , a)-ncr(n,b);
	ans = (ans+2*mod)%mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int n;
    scanf("%d", &n);
    int v[n], c[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &v[i]);
    }
    for(int i = 0; i < n; i++){
        scanf("%d", &c[i]);
    }

    int ans = 0;;
    for(int i = 0; i < n; i++){
        if(v[i] - c[i] > 0){
            ans += v[i] - c[i];
        }
    }

    printf("%d\n", ans);

    return 0;
}

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

int main() {
    ll n;
    cin>>n;
    string s;
    ll a=0;
    ll b=0;
    ll c=0;
    ll d=0;
    ll g=0;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s[0]=='M'){
            a++;
        }
        if(s[0]=='A'){
            b++;
        }
        if(s[0]=='R'){
            c++;
        }
        if(s[0]=='C'){
            d++;
        }
        if(s[0]=='H'){
            g++;
        }
    }
    cout<<(a)*(b)*(c)+(a)*(b)*(d)+(a)*(b)*(g)+(a)*(c)*(g)+(a)*(d)*(g)+(b)*(d)*(g)+(c)*(d)*(g)+a*c*d+b*c*d+b*c*g;
    return 0;
}


Measured memory_bytes: 256
a, b = map(int, input().split())

ans = 0
for x in range(10):
    for y in range(10):
        for z in range(1, 10):
            num = 10000*z + 1000*y + 100*x + 10*y + z
            if a <= num and num <= b:
                ans += 1

print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=998244353;
const int maxn=(1e5)+10;
int n,mi[maxn],ans;
void update(int &x,int y) {
	x+=y; if (x>=mod) x-=mod;
}
struct Graph {
	int tot,m,head[maxn],nxt[maxn*2],to[maxn*2];
	int sg[maxn],vis[maxn],cnt[maxn];
	void add(int x,int y) {
		tot++; nxt[tot]=head[x];
		head[x]=tot; to[tot]=y;
	}
	void init() {
		read(m);
		int x,y;
		while (m--) {
			read(x); read(y);
			if (x>y) swap(x,y);
			add(x,y);
		}
		tot=0;
		for (int i=n;i>=1;i--) {
			tot++;
			for (int j=head[i];j;j=nxt[j]) vis[sg[to[j]]]=tot;
			for (;vis[sg[i]]==tot;sg[i]++);
			update(cnt[sg[i]],mi[i]);
		}
	}
} T[3];
int main() {
	//freopen("1.txt","r",stdin);
	mi[0]=1; mi[1]=(ll)(1e18)%mod;
	read(n);
	for (int i=2;i<=n;i++) mi[i]=(ll)mi[i-1]*mi[1]%mod;
	for (int i=0;i<3;i++) T[i].init();
	for (int i=0;i<=1000;i++)
	for (int j=0;j<=1000;j++)
		update(ans,(ll)T[0].cnt[i]*T[1].cnt[j]%mod*T[2].cnt[i^j]%mod);
	printf("%d\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N, u, v;
	cin >> N >> u >> v;
	--u; --v;
	vector< vector<int> > g(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}

	vector<int> dA(N, -1);
	dA[v] = 0;
	deque<int> que;
	que.emplace_back(v);
	while (!que.empty()) {
		int s = que.front(); que.pop_front();
		for (auto t : g[s]) {
			if (dA[t] >= 0) { continue; }
			dA[t] = dA[s] + 1;
			que.emplace_back(t);
		}
	}

	int ans = 0;
	vector<int> dT(N, -1);
	que.emplace_back(u);
	while (!que.empty()) {
		int s = que.front(); que.pop_front();
		for (auto t : g[s]) {
			if (dT[t] >= 0) { continue; }
			ans = max(ans, dA[t] - 1);
			dT[t] = dT[s] + 1;
			if (dA[t] > dT[t]) { que.emplace_back(t); }
			else { dT[t] = 1e9; }
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6656
#include<stdio.h>
int main(){
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
 
if((A>=1&&A<=9)&&(B>=1&&B<=9)&&(C>=1&&C<=9)){
    if(A==B&&A==C&&B==C){
        printf("No\n");
    }
 
     else if(A==B&&A!=C){
            printf("Yes\n");
        }
    else if(B==C&&A!=B){
        printf("Yes\n");
 
    }
    else if(A==C&&B!=C){
        printf("Yes\n");
    }
else{
    printf("No\n");
}
  }  return 0;
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using i64=long long;

template <class T>
void chmax(T &x,T y)
{
    x=max(x,y);
}

main()
{
    int n; cin>>n;
    i64 ans=0;
    for(i64 i=1; i<=n; i++)
    {
        i64 j=n/i;
        ans+=i*j*(j+1)/2;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	int N;
	int D;
	cin >> N;
	cin >> D;

	int ans = N / (2 * D + 1);
	
	if (N % (2 * D + 1) > 0) {
		ans += 1;
	}

	cout << ans << endl;
	
	return 0;
}

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

int main(){
	// sengen
	int n,m;
	// nyuryoku
	cin >> n >> m;
	int l,r;
	int under=1,upper=n;
	for(int i=0;i<m;i++){
		cin >> l >> r;
		under = max(under,l);
		upper = min(upper,r);
	}
	// keisan
	if(under > upper){
		cout << '0' << endl;
	}else{
		cout << upper - under + 1 << endl;
	}
	// syutsuryoku
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;


bool is_prime(ll n){
	if(n==1)return false;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0)return false;
	}
	return true;
}
vector<ll>divisor(ll n){
	vector<ll>res;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			res.push_back(i);
			if(i!=n/i)res.push_back(n/i);
		}
	}
	return res;
}
map<ll,int>prime_factor(ll n){
	map<ll,int>res;
	for(ll i=2;i*i<=n;i++){
		while(n%i==0){
			res[i]++;
			n/=i;
		}
	}
	if(n!=1)res[n]++;
	return res;
}
vector<ll>prime_enum(int n){
	vector<bool>is_prime(n+1,true);
	is_prime[0]=is_prime[1]=false;
	vector<ll>res;
	for(int i=2;i<=n;i++){
		if(!is_prime[i])continue;
		res.push_back(i);
		for(int j=2*i;j<=n;j+=i){
			is_prime[j]=false;
		}
	}
	return res;
}
int main(){
	ll s;cin>>s;
	ll ok=1e9,ng=0;
	while(ok-ng>1){
		ll t=(ok+ng)/2;
		if(t*t>=s)ok=t;
		else ng=t;
	}
	ll d=ok*ok-s;
	if(d==0){
		cout<<0<<' '<<0<<' '<<0<<' '<<ok<<' '<<ok<<' '<<0<<endl;
		return 0;
	}
	auto v=divisor(d);
	ll x=-1,y=-1;
	for(auto i:v){
		if(i<=1e9&&d/i<=1e9){
			x=i;
			y=d/i;
			break;
		}
	}
	cout<<0<<' '<<0<<' '<<ok<<' '<<x<<' '<<y<<' '<<ok<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var n4 = 0;
            var n2 = 0;
            var odd = 0;
            for (var i = 0; i < A.Length; i++)
            {
                if (A[i] % 2 == 1)
                {
                    odd++;
                }
                else
                {
                    var tmp = A[i] / 2;
                    if (tmp % 2 == 1) n2++;
                    else n4++;
                }
            }
            if (n2 > 0) odd++;
            Console.WriteLine(n4 >= odd - 1 ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 38524
n  = int(input())
k = 2
num = list(map(int,input().split()))
numval = list()
for data in range(n):
    numval.append(1000000000)
numval[0] = 0
i = 0
if(n<k):
    k = n-1
for i in range(0,n):
    for data in range(1,k+1):
        if(i+data)>=n:
            break
        numval[i+data] = min(numval[i+data],numval[i]+abs(num[i]-num[i+data]))
    i += 1
print(numval[n-1])        

Measured memory_bytes: 20568
/* Coached by Dukkha */
#include <stdio.h>
#include <stdlib.h>

#define N 200000

int xx[N];

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return xx[i] - xx[j];
}

int main() {
	static int ii[N];
	int n, i, a, b;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &xx[i]);
		ii[i] = i;
	}
	qsort(ii, n, sizeof *ii, compare);
	a = xx[ii[n / 2]];
	b = xx[ii[n / 2 - 1]];
	for (i = 0; i < n; i++)
		xx[ii[i]] = i < n / 2 ? a : b;
	for (i = 0; i < n; i++)
		printf("%d\n", xx[i]);
	return 0;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	vector<char>v;
	while(n)
	{
		n--;
		v.push_back(n%26+'a');
		n/=26;
	}
	reverse(v.begin(),v.end());
	for(char c:v)
		cout<<c;
	return 0;
}

Measured memory_bytes: 3616
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int num[] = new int[n];
		int count = 0;
		for(int i=0 ; i<n ; i++){
			num[i] = sc.nextInt();
		}
		
		Arrays.sort(num);
		for(int i=0;i<n;i++){
			count+=(i%2==0)?num[n-1-i]:-num[n-1-i];
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define int long long 
#define all(x) x.begin(), x.end()
using namespace std ;
const int INF = 1e18 ;
int32_t main(){
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ; cout.tie(0) ; 
	int a,b,q ;
	cin >> a >> b >> q ;
	vector<int> s(a+2) , t(b+2), Q(q);
	for(int i = 0 ; i < a ; i++)
		cin >> s[i] ;
	for(int i = 0 ; i < b ; i++)
		cin >>  t[i] ;
	s[a] = -INF ; s[a+1] = INF ; t[b] = -INF ; t[b+1] = INF ;
	for(int& i : Q)
		cin >> i ;
	
	sort(all(s)) ;		
	sort(all(t)) ;
	for(int i = 0 ; i < q ; i++){
		int target = Q[i] ;
		auto rs = lower_bound(all(s),target) ;
		auto ls = rs - 1 ;
		auto rt = lower_bound(all(t),target) ;
		auto lt = rt - 1 ;
		int shrine[] = {*ls,*rs} ;
		int temple[] = {*lt,*rt} ;
		int d = 1e20 ;
		for(int i = 0 ; i < 2 ; i++){
			for(int j = 0 ; j < 2 ; j++){
				d = min(abs(target - shrine[i]) + abs(shrine[i] - temple[j]) , d ) ;
				d = min(abs(target - temple[j]) + abs(temple[j] - shrine[i]) , d ) ;
			}
		}
		cout << d << endl ;		
	}
}

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

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

  int ans=1;
  for(int i=0; i<N; i++){
   if(ans+K>ans*2){ans*=2;}
   else{ans+=K;} 
  }
  cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if(min(a, b) <= c && c <= max(a, b)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    string s,t;
    cin>>s>>t;
    bool flag=true;
    rep(i,s.size()){
        if(s[i]!=t[i])flag=false;
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
bool notp[maxn];
int presum[maxn];
void init()
{
    notp[0]=notp[1]=1;
    for(int i=2;i<maxn;i++)
    {
        if(!notp[i])
        {
            if(i>maxn/i)continue;
            for(int j=2*i;j<maxn;j+=i)
            {
                notp[j]=1;
            }
        }
    }
    for(int i=1;i<maxn;i++)
    {
        presum[i]=presum[i-1];
        if((i&1)&&(!notp[i])&&(!notp[(i+1)/2]))
            presum[i]++;
    }
}

int main()
{
    init();
    int q;
    int l,r;
    cin>>q;
    while(q--)
    {
        scanf("%d%d",&l,&r);
        cout<<presum[r]-presum[l-1]<<endl;
    }
    return 0;
}


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

#undef false
#undef true

using namespace std;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* [💭] [💡] [🎈] */

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

    ll n, k;
    cin >> n >> k;
    int c = 0;
    while (n) {
        c++;
        n /= k;
    }
    cout << c;

    return 0;
}

Measured memory_bytes: 256
# D - Blue and Red Balls

# 青いボールを並べる→赤いボールを青いボールの間に挿入する→残りの赤いボールを両端に置く

N, K = map(int, input().split())
MOD = 10**9 + 7

# nCkを漸化式で求め、メモしておく
combinations_table = [[0]*(N+1) for _ in range(N+1)]
for idx in range(N+1):
    combinations_table[0][idx] = 1
    combinations_table[idx][0] = 1
    combinations_table[idx][1] = idx
for n in range(2, N+1):
    for k in range(2, n+1):
        combinations_table[n][k] = combinations_table[n-1][k-1] + combinations_table[n-1][k]

# 連続した同色のボールの数nと、それらを何分割するか示すaを与えると、分割のパターン数を返す関数
def separate_balls(n,a):
    return combinations_table[n-1][a-1]

ans_list = []
for n_separate in range(1,K+1):
    if N-K < n_separate-1: # 赤いボール不足でi分割不可
        ans_list.append(0)
    elif n_separate == 1:
        ans_list.append(N-K+1)
    else:
        tmp_blue = separate_balls(K, n_separate) % MOD  # K個の青いボールをi分割するパターン数
        tmp_red = 0
        for n_red_ball in range(n_separate-1, N-K+1): # 青いボールの分割に使う赤いボールの個数
            tmp_red_inner = separate_balls(n_red_ball, n_separate-1)  # j個の赤いボールをi-1分割して青いボールの隙間に入れるパターン数
            tmp_red_side = N-K-n_red_ball+1 # N-K-j個の赤いボールを両端に置くパターン数
            tmp_red += (tmp_red_inner * tmp_red_side) % MOD
        ans_list.append((tmp_blue * tmp_red) % MOD)  # 青いボールの置き方*赤いボールの置き方

for x in ans_list:
    print(x)

Measured memory_bytes: 481020