akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;(i)<(n);++(i))
using namespace std;

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

const int limit = 100010;
using edge = struct{int to, color, cost;};
vector<edge> graph[limit];

int x[limit], y[limit], uv[limit][3];
int val[limit][3];

const int root = 0;
const int limit_log = 17;
int par[limit_log + 1][limit];
int depth[limit];

void dfs(int v, int p, int d){
	par[0][v] = p;
	depth[v] = d;
	for(auto &e: graph[v]) {
		if(e.to == p) continue;
		dfs(e.to, v, d + 1);
	}
}

using query = tuple<int, int, int, int>;
vector<query> que[limit];

int num[limit], total_cost[limit];

void dfs2(int v, int p, int dist){
	for(auto &q: que[v]){
		int color, cost, idx, pos;
		tie(color, cost, idx, pos) = q;
		val[idx][pos] = dist;
		val[idx][pos] -= total_cost[color];
		val[idx][pos] += num[color] * cost;
	}

	for(auto &e: graph[v]){
		if(e.to == p) continue;
		num[e.color]++;
		total_cost[e.color] += e.cost;
		dfs2(e.to, v, dist + e.cost);
		num[e.color]--;
		total_cost[e.color] -= e.cost;
	}
}

int main(void){
	int n, q;
	cin >> n >> q;

	rep(i, n - 1){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--, b--, c--;
		graph[a].push_back({b, c, d});
		graph[b].push_back({a, c, d});
	}

	dfs(root, -1, 0);
	
	rep(k, limit_log) rep(v, n){
		const int tmp = par[k][v];
		par[k + 1][v] = (tmp == -1) ? -1 : par[k][tmp];
	}

	rep(i, q){
		cin >> x[i] >> y[i] >> uv[i][0] >> uv[i][1];
		x[i]--, uv[i][0]--, uv[i][1]--;
		int cu = uv[i][0], cv = uv[i][1];

		if(depth[cu] - depth[cv] < 0){
			swap(cu, cv);
			swap(uv[i][0], uv[i][1]);
		}

		int diff = depth[cu] - depth[cv];

		rep(_k, limit_log + 1) {
			const int k = limit_log - _k;
			if(diff >> k &1){
				cu = par[k][cu];
				diff -= (1 << k);
			}
		}

		if (cu != cv) {
			rep(_k, limit_log + 1) {
				const int k = limit_log - _k;
				if(par[k][cu] != par[k][cv]){
					cu = par[k][cu];
					cv = par[k][cv];
				}
			}
		}

		uv[i][2] = (cu == cv) ? cu : par[0][cu];
		rep(j, 3) que[uv[i][j]].push_back(query(x[i], y[i], i, j));
	}

	dfs2(root, -1, 0);

	rep(i, q){
		const int ans = val[i][0] + val[i][1] - 2 * val[i][2];
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 30708
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define ABSS(a, b) (a > b ? a - b : b - a)

static void rotateString(char * S) {
	char buf[2];
	const size_t len = strlen(S);
	buf[1] = S[len - 1];
	for (uint32_t i = 0; i < len; i++) {
		buf[i%2] = S[i];
		S[i] = buf[(i + 1)%2];
	}
}

int main(void) {
	char S[101], T[101];

	scanf("%s\n%s", S, T);

	bool match = false;
	for (uint32_t i = 0; i < strlen(S); i++) {
		if (strcmp(S, T) == 0) {
			match = true;
			break;
		}
		rotateString(S);
	}

	puts((match ? "Yes" : "No"));

	return 0;
}


Measured memory_bytes: 128
/* ex 5_4 AtCoder Beginner Contest 122 B
   nk777 */

#include <stdio.h>

int main(void){
    // 入力される文字列string, 探す場所を示すポインタsearch
    char string[11], *search;
    // カウントの最大値を記録するmax
    int max = 0;
    // 文字列の受け取り
    scanf("%s", string);
    search = string;
    // searchがNULL文字になるまで繰り返す
    while (*search)
    {
        // ACGT文字列の長さをカウントするcount
        int count = 0;
        while (*search == 'A' || *search == 'G' || *search == 'C' || *search == 'T')
        {
            // 文字列がAGCTのとき
            count++;
            search++;
        }
        if (count > max)
        {
            // 今までの最大文字数より大きいとき
            max = count;
        }
        // AGCTじゃなかったとき探すのは次の文字から
        search++;
    }
    printf("%d\n", max);
    return 0;
}

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


void solve(long long N, long long K, long long C, std::string S){
    int left[K] ={};
    int last = -C-1;
    int index = 0;
    for(int i=0;i<N;i++){
        
        if(S[i] =='o'){
            // cerr <<"judge" <<  i <<endl;
            if(i-last> C){
                // cerr << "left " << index <<"="<<i<<endl;
                left[index] = i;
                index++;
                last = i;
            }
        }
        if(index ==K){
            break;
        }
        if(i == N-1){
            cout << endl;
            return;
        }
    }
    int right[K] = {};
    last = N+C;
    index = K-1;
    for(int i=N-1;i>=0;i--){
       
        if(S[i] == 'o'){
            if(last -i >C){
                // cerr << "right " << index <<"="<<i<<endl;
                right[index] = i;
                index--;
                last = i;
            } 
        }
        if(index <0){
            break;
        }
    }
    int ans =0;

    for(int i=0;i<K;i++){
        if(left[i] == right[i]){
            cout << left[i]+1 << endl;
            ans++;
        }
    }
    if(ans == 0){
        cout << endl;
    }

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long C;
    scanf("%lld",&C);
    std::string S;
    std::cin >> S;
    solve(N, K, C, S);
    return 0;
}


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

int main()
{
ll n , d , a ;
cin >> n >> d >> a ;
vector<pair<ll,ll>> v(n);
rep(i,n){
  cin >> v[i].first >> v[i].second;
  v[i].second=(v[i].second+a-1)/a;
}
sort(v.begin(),v.end());
ll at=0;
queue<pair<ll, ll>> q;
rep(i,n){
  while(!q.empty()){
    auto r=q.front();
    if(r.first<v[i].first){
      q.pop();
      at-=r.second;
    }
    else break;
  }
  if(v[i].second>at){
    ans+=v[i].second-at;
    q.push({v[i].first+2*d,v[i].second-at});
    at+=v[i].second-at;
  }
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
int main(void){
  int n,i;
  double x,sum=0;
  char u[4];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf %s",&x,u);
    if(u[0]=='J'){
      sum+=x;
    }else{
      sum+=x*380000;
    }
  }
  printf("%lf",sum);
  return 0;
}

Measured memory_bytes: 128
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

    ll n, m;
    cin >> n >> m;

    ll a;
    priority_queue<ll> q;

    for(int i = 0; i < n; i++){
        cin >> a;
        q.push(a);
    }

    for(int i = 0; i < m; i++){
        a = q.top();
        q.pop();
        a >>= 1;
        q.push(a);
    }

    ll ans = 0;

    while(!q.empty()){
        ans += q.top();
        q.pop();
    }

    cout << ans;
}


Measured memory_bytes: 4168
import sys
import os

OK = 'APPROVED'
NG = 'DENIED'


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, X = list(map(int, sys.stdin.buffer.readline().split()))

    print('YES' if A <= X and X - A <= B else 'NO')


if __name__ == '__main__':
    main()


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<ll,ll>;

ll N, H;
ll hs[100100];
ll life[100100];
std::priority_queue<P> pq;

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

    std::cin >> N >> H;

    life[0] = H;
    for(int i=0;i<N-1;++i){
        ll d;
        std::cin >> d >> hs[i];

        life[i+1] = life[i] - d;
    }

    // for(int i=0;i<10;++i){
    //     std::cout << i << ": " << life[i] << std::endl;
    // }
    
    int last = -1;
    ll recovery = 0ll, counter = 0ll;

    for(int i=0;i<N-1;++i){
        pq.emplace(min(hs[i], H - (life[i] + recovery)), -i);

        // std::cout << "In " << i << " th floor" << std::endl;
        while(life[i+1] + recovery <= 0){
            ll h, idx;
            tie(h, idx) = pq.top();
            idx = -idx;
            pq.pop();

            if(idx < last){continue;}
            ll needs = -(life[i+1] + recovery) + 1,
                rest = H - (life[idx] + recovery);
            if(rest < h){
                if(rest > 0){
                    pq.emplace(rest, -idx);
                }
                continue;
            }

            ll t = min((needs + h - 1) / h, rest / h);
            recovery += min(h * t, rest);
            counter += t;
            ll new_h = min(h, H - (life[idx] + recovery));
            if(new_h > 0){
                pq.emplace(new_h, -idx);
            }
            last = idx;

            // std::cout << "Recovery " << min(h * t, rest) << " min(" << rest << ", " << h << " * " << t << ")" << " in " << idx << std::endl;
            // std::cout << "Change " << h << " -> " << new_h << std::endl;
        }
    }

    std::cout << counter << std::endl;
}

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

const int mod = 1e9 + 7;

int main() {
    int n; cin >> n;
    for(int i=1; i<=9; i++){
        for(int j=1; j<=9; j++){
            if(i*j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
n = int(input())
s = input()

res = [0] * (n + 1)

for i in range(1, n+1):
    if s[i-1] == 'I':
        res[i] = res[i-1] + 1
    else:
        res[i] = res[i-1] - 1

#print(res)
print(max(res))

Measured memory_bytes: 3064
n = gets.to_i
ary = gets.strip.split.map(&:to_i)
odd = []
even = []
n.times do |i|
  if i%2==0
    odd << ary[i]
  else
    even << ary[i]
  end
end
rec1 = Array.new(10**5,0)
rec2 = Array.new(10**5,0)
for i in 0..n/2-1
  rec1[odd[i]-1] += 1
end
for i in 0..n/2-1
  rec2[even[i]-1] += 1
end
recs1 = rec1.sort
recs2 = rec2.sort
if rec1.count(recs1[-1])==1 && rec2.count(recs2[-1])==1
  if rec1.index(recs1[-1]) == rec2.index(recs2[-1])
    puts [n-recs1[-2]-recs2[-1],n-recs1[-1]-recs2[-2]].min
  else
    puts n-recs1[-1]-recs2[-1]
  end
else
  puts n-recs1[-1]-recs2[-1]
end

Measured memory_bytes: 25640
package main

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


var sc = bufio.NewScanner(os.Stdin)
func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func main() {
  sc.Split(bufio.ScanWords)
  var a [3][3]int
  for i := 0; i < 3; i++ {
    for j := 0; j < 3; j++ {
      a[i][j] = nextInt()
    }
  }
  n := nextInt()
  var b map[int]bool = map[int]bool{}
  for i := 0; i < n; i++ {
    b[nextInt()] = true
  }
  // fmt.Println()
  var ids map[int]bool = map[int]bool{}
  for i := 0; i < 3; i++ {
    for j := 0; j < 3; j++ {
      if b[a[i][j]] {
        ids[3*i+j] = true
      }
    }
  }

  if ids[0] && ((ids[1] && ids[2]) || (ids[3] && ids[6]) || (ids[4] && ids[8])) {
    fmt.Println("Yes")
  } else if ids[1] && ids[4] && ids[7] {
    fmt.Println("Yes")
  } else if ids[2] && ((ids[4] && ids[6]) || (ids[5] && ids[8])) {
    fmt.Println("Yes")
  } else if ids[3] && ids[4] && ids[5] {
    fmt.Println("Yes")
  } else if ids[6] && ids[7] && ids[8] {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a, b) printf(a, b);
#define c(s) cout << (s) << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define cyn(c) cout << (c ? "Yes" : "No") << endl;
#define cYN(c) cout << (c ? "YES" : "NO") << endl;
#define pyn(c) printf("%s\n", c ? "Yes" : "No");
#define pYN(c) printf("%s\n", c ? "YES" : "NO");
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> P;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}
ULL mod = 1e9 + 7;

int main() {
    string a,b; cin>>a>>b;
    if(a.size()>b.size()){
        c("GREATER");
    }else if(a.size()<b.size()){
        c("LESS");
    }else{
        if(a>b){
            c("GREATER");
        }else if(a<b){
            c("LESS");
        }else{
            c("EQUAL");
        }
    }
}

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

int main() {
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    for (auto& e : v) std::cin >> e;

    if (std::prev_permutation(v.begin(), v.end())) {
        for (int i = 0; i < v.size(); ++i) {
            std::cout << v[i] << " \n"[i == v.size() - 1];
        }
    }
    std::next_permutation(v.begin(), v.end());
    for (int i = 0; i < v.size(); ++i) {
        std::cout << v[i] << " \n"[i == v.size() - 1];
    }
    if (std::next_permutation(v.begin(), v.end())) {
        for (int i = 0; i < v.size(); ++i) {
            std::cout << v[i] << " \n"[i == v.size() - 1];
        }
    }
}



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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

int solution_sort(vector<pair<int,int>>& dish, int T)
{
    int N = dish.size();
    sort(dish.begin(), dish.end());
    
    int ans = 0;
    vector<int> dp(T, 0);
    for(int i = 0; i < N; ++i){
        int A = dish[i].first;
        int B = dish[i].second;
        ans = max(ans, dp[T-1]+B);
        for(int j = T-1; j >= A; --j) dp[j] = max(dp[j], dp[j-A]+B);
    }
    return ans;
}

int solution_dp(vector<pair<int,int>>& dish, int T)
{
    int N = dish.size();
    
    vector<vector<int>> dp(N+1, vector<int>(T, 0)), dpr(N+1, vector<int>(T, 0));
    for(int i = 1; i < N+1; ++i){
        int A = dish[i-1].first;
        int B = dish[i-1].second;
        for(int j = 0; j < T; ++j){
            if(j >= A) dp[i][j] = max(dp[i-1][j], dp[i-1][j-A]+B);
            else dp[i][j] = dp[i-1][j];
        }
    }
    for(int i = N-1; i >= 1; --i){
        int A = dish[i].first;
        int B = dish[i].second;
        for(int j = 0; j < T; ++j){
            if(j >= A) dpr[i-1][j] = max(dpr[i][j], dpr[i][j-A]+B);
            else dpr[i-1][j] = dpr[i][j];
        }
    }
    
    int ans = 0;
    for(int i = 0; i < N; ++i){
        int B = dish[i].second;
        for(int j = 0; j < T; ++j) ans = max(ans, dp[i][j]+dpr[i][T-j-1]+B);
    }
    
    return ans;
}

int main()
{
    int N, T;
    cin >> N >> T;
    vector<pair<int,int>> dish(N);
    REP(i, N) cin >> dish[i].first >> dish[i].second;

    cout << solution_dp(dish, T) << endl;

    return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
int main() {
    while (cin >> N) {
        long long res = 0;
        for (int i = 0; i < N; ++i) {
            long long a, b;
            cin >> a >> b;
            res += (b-a) + 1;
        }
        cout << res << endl;
    }
}



















Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
char _;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#ifdef _getchar_nolock
#define getchar _getchar_nolock
#endif
#ifdef _putchar_nolock
#define putchar _putchar_nolock
#endif
#ifdef getchar_unlocked
#define getchar getchar_unlocked
#endif
#ifdef putchar_unlocked
#define putchar putchar_unlocked
#endif
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
template <typename t> void scan (t& x) {do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0);}
void scan(pii &x) {scan(x.first); scan(x.second);}
template <typename t, typename ...r> void scan (t& x, r&... xs) {scan(x); scan(xs...);}
const int MN = 1e5+2, MM = 1e6+2, MOD = 1e8, BASE = 131;
int fpow (int base, int ex) {int res = 1;while (ex) {if (ex&1) res = res*1LL*base%MOD;base = base*1LL*base%MOD;ex>>=1;}return res;}
ll lcm (ll a, ll b) {return a*b/__gcd(a,b);}
int moddiv (int a, int b) {return a*1LL*fpow(b,MOD-2)%MOD;}

int main () {
    int n;
    scanf("%d",&n);
    printf ("%d\n",n*n*n);
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

_ = input()
As = list(map(int, input().split()))
bins = [0] * 9
table = [400, 800, 1200, 1600, 2000, 2400, 2800, 3200, 10000]
for a in As:
    for i, t in enumerate(table):
        if a < t:
            bins[i] += 1
            break
mn = sum(1 for x in bins[:-1] if x > 0)
if mn == 0:
    mn = 1
    mx = bins[-1]
else:
    mx = mn + bins[-1]
print(mn, mx)


Measured memory_bytes: 5664
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

//掛け算
ll mul(ll a,ll b){
    return ((a%MD)*(b%MD)) % MD;
}

int main(){
    int n,i=1,flag=1;
    string s1,s2;
    cin>>n>>s1>>s2;
    ll ans;
    if(s1[0]==s2[0]) ans=3;
    else{
        ans=6;
        i=2;
        flag=0;
    }
    for(;i<n;i++){
        if(flag){//一つ前が縦
            ans=mul(ans,2);
            if(s1[i]!=s2[i]) {
                flag=0;
                i++;
            }
        }else{//一つ前が横
            if(s1[i]==s2[i]) {
                flag=1;
            }else {
                ans=mul(ans,3);
                i++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e18;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, K;
int A[202020];
int B[202020];

int cnt(int x) {
    int ret = 0;
    //cerr << x << endl;
    FOR(i, 0, N) {
        if (A[i] == 0) {
            if (x >= 0) {
                ret += (N - 1);
                continue;
            } else if (x < 0) {
                continue;
            }
        }


        if (A[i] > 0) {
            int y = x / A[i];
            if (y * A[i] > x)
                y--;
            // cerr << "y:" << y << endl;
            auto it = upper_bound(A, A + N, y);
            ret += (int)(it - A);
        } else {
            int y = x / (A[i] * -1);
            if (y * (A[i] * -1) > x)
                y--;

            //cerr << "y:" << y << endl;
            auto it = upper_bound(B, B + N, y);
            ret += (int)(it - B);
        }
        if (A[i] * A[i] <= x)
            ret--;
        //cerr << ret << endl;
    }
    //cerr << endl;
    ret /= 2;
    return ret;
}

bool check(int x) {
    if (cnt(x) >= K)
        return true;
    else
        return false;
}

void solve() {
    sort(A, A + N);
    FOR(i, 0, N) {
        B[i] = A[N - i - 1] * -1;
    }

    int ok = INF + 100000;
    int ng = INF * -1ll - 100000;

    while (ok - ng > 1) {
        int mid = (ok + ng) / 2;
        if (check(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    cout << ok << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    FOR(i, 0, N)
    cin >> A[i];
    solve();
    return 0;
}


Measured memory_bytes: 3456
N, M, X = map(int, input().split())
ca = [list(map(int, input().split())) for i in range(N)]

ans = float("inf")

for i in range(2**N):
    l = [0 for _ in range(M)]
    c = 0
    for j in range(N):
        if i >> j & 1:
            l = [x + y for (x, y) in zip(ca[j][1:], l)]
            c += ca[j][0]

    l_bool = [a >= X for a in l]
    if all(l_bool):
        ans = min(ans, c)

if ans == float("inf"):
    print(-1)

else:
    print(ans)

Measured memory_bytes: 9168
#include <stdio.h>
#include <stdlib.h>

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    char str;
    int ans = 0;
    //最初のノードの指す先
    node *first1 = NULL, *first2 = NULL;
    //入力を受け取りスタックに追加
    while(1){
        scanf("%c", &str);
        if(str == '0' || str == '1'){
            push(&first1, str);
        }else{
            break;
        }
    }

    //ループ開始
    while(first1 != NULL){
        //次のキューブがなければ終了
        if(first1->next == NULL){
            break;
        }
        //もし現在のキューブと次のキューブが違う色なら
        if(first1->elem != first1->next->elem){
            //現在のキューブと次のキューブを取り除き数を+2する
            pop(&first1);
            pop(&first1);
            ans += 2;
            //ひとつ前のキューブを戻す
            if(first2 != NULL){
                push(&first1, pop(&first2));
            }
        }else{
            //現在のキューブを保存する
            push(&first2, pop(&first1));
        }
    }

    //答えを出力
    printf("%d\n", ans);
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	string s;
	cin >> s;

	int n = s.size();
	int a = 0, b = 0, c = 0;
	rep(i, n){
		if(s[i] == 'a')
		{ 
			a++;
		}else if(s[i] == 'b'){
			b++;
		}else{
			c++;
		}
	}

	if(abs(a-b) >= 2 || abs(b-c) >= 2 || abs(c-a) >= 2){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b){
  return a < b ? a : b;
}

int main(int argc, char const *argv[]) {
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for(i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head = 1;
  tail = n + 1;
  while (head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if (u.t > 0) {
      enqueue(u);
    }else{
      printf("%s %d\n", u.name, elaps);
    }
  }

  return 0;
}

Measured memory_bytes: 12744
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)

template <class T = int>
T in() { T x; std::cin >> x; return x; }
#define output(e) std::cout << e << '\n'

#ifdef LOCAL
#define db std::cout << "L" << __LINE__ <<
#define de << "\n"
#define dv(x) << " " << #x << "->" << x
#else
#define db
#define de
#define dv(x)
#endif

//
// Implementation
//

int main() {
  ll A = in<ll>();
  ll B = in<ll>();
  ll x = A + B;
  ll y = A - B;
  ll z = A * B;
  output(max(max(x, y), z));
}


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

int main() {
  int64_t A,B,K;
  int64_t a,b;
  cin >> A >> B >> K;
  
    if (A >= K) {
      a = A - K;
      b = B;
    } 
    else if (A + B >= K) {
      a = 0;
      b = B - (K - A);
    }
    else {
      a = 0;
      b = 0;
    }
  
  cout << a << " " << b << endl;
  
}     

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

int main(void){
  int n,d[105][5],count=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d %d",&d[i][0],&d[i][1]);
  }
  for(int i=0;i<n;i++){
    if(d[i][0]==d[i][1]) count++;
    if(d[i][0]!=d[i][1]) count=0;
    if(count>=3){
      printf("Yes");
      return 0;
    }
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#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 fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define VL vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define what(A) cout<<#A<<" is "<<A<<endl;
int main()
{
    fastio
        ll l = 0;
        ll test = 1;
    //cin >> test;
    while (test--)
    {
        ll n,ans=1000,stock=0;
        cin>>n;
        ll a[n];
        FOR(i,0,n)
        {
            cin>>a[i];
        }
        FOR(i,0,n-1)
        {
            if(a[i]<a[i+1] && ans>=a[i])
            {
                ll k=ans/a[i];
                ans-=a[i]*k;
                stock+=k;
            }
            if(a[i]>a[i+1])
            {
                ans+=a[i]*stock;
                stock=0;
            }
        }
        if(stock!=0)
        {
            ans+=a[n-1]*stock;
        }
        cout<<ans;
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define maxn 110
int main(){
    int n;
    scanf("%d",&n);
    int m = (n*n-n)/2;
    m-=n/2;
    printf("%d\n",m);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(n%2==0)
                if(i+j == n+1)
                    continue;
            if(n%2!=0)
                if(i+j == n)
                    continue;
            printf("%d %d\n",i,j);
        }
    }
}


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

int main() {
    vector <int> I(3);
    for (int i=0; i<3; i++) {
        cin >> I.at(i);
    }
    sort(I.begin(), I.end());
    cout << 10*I.at(2)+I.at(1)+I.at(0) << "\n";
}

Measured memory_bytes: 256
def main():
    N,K = map(int,input().split())
    XY = [list(map(int,input().split())) for _ in [0]*N]
    
    iX = sorted(x for x,y in XY)
    iY = sorted(y for x,y in XY)
    X = {x:i for i,x in enumerate(iX)}
    Y = {y:i for i,y in enumerate(iY)}

    c = [[0]*(N+1) for i in [0]*(N+1)]
    for x,y in XY:
        c[Y[y]+1][X[x]+1] = 1

    for i in range(N):
        ci1 = c[i+1]
        for j in range(N):
            ci1[j+1] += ci1[j]
    for i in range(N):
        ci1 = c[i+1]
        ci = c[i]
        for j in range(N):
            ci1[j+1] += ci[j+1]

    ans = 10**20
    for u in range(N):
        for d in range(u+K-1,N):
            l = 0
            r = 1
            dY = iY[d]-iY[u]
            cd = c[d+1]
            cu = c[u]
            while r<N:
                if cd[r+1]+cu[l]-cu[r+1]-cd[l] >=K:
                    ans = min(ans, (iX[r] - iX[l])*dY)
                    l+=1
                else:r+=1

    print(ans)
main()

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Numerics;

namespace AtCoder.Beginner._092 {
  public class Abc_of_ABC {
    public static void Main() {
      WriteYesNo(string.Join("", Console.ReadLine().ToArray().OrderBy(x => x)) == "abc");
    }

    #region Template
    private static int ReadInt() { return int.Parse(Console.ReadLine()); }
    private static double ReadDouble() { return double.Parse(Console.ReadLine()); }
    private static long ReadLong() { return long.Parse(Console.ReadLine()); }
    private static char ReadChar() { return Console.ReadLine()[0]; }
    private static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
    private static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    private static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    private static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    private static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
    private static void WriteArraySingleLine(Object[] array) { Console.WriteLine(string.Join(" ", array)); }
    private static void WriteArrayMultiLine(Object[] array) { Console.WriteLine(string.Join(Environment.NewLine, array)); }
    private static void WriteYesNo(bool b) { Console.WriteLine((b) ? "Yes" : "No"); }
  }

  public class Point {
    public int X;
    public int Y;
    public Point(int X, int Y) { this.X = X; this.Y = Y; }
    public Point(int[] XY) { this.X = XY[0]; this.Y = XY[1]; }
    public double EuclideanDistance(Point point) { return EuclideanDistance(this, point); }
    public double ManhattanDistance(Point point) { return ManhattanDistance(this, point); }
    public double ChebyshevDistance(Point point) { return ChebyshevDistance(this, point); }
    public static double EuclideanDistance(Point point1, Point point2) { return Math.Sqrt(Math.Pow(point1.X - point2.X, 2) + Math.Pow(point1.Y - point2.Y, 2)); }
    public static double ManhattanDistance(Point point1, Point point2) { return Math.Abs(point1.X - point2.X) + Math.Abs(point1.Y - point2.Y); }
    public static double ChebyshevDistance(Point point1, Point point2) { return Math.Max(Math.Abs(point1.X - point2.X), Math.Abs(point1.Y - point2.Y)); }
  }
}
#endregion

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

dis = [0] * (n - 1)
for i in range(n - 1):
    for j in range(i + 1, n):
        d = min(abs(x - i - 1) + abs(y - j - 1) + 1, j - i)
        dis[d - 1] += 1
print(*dis, sep = '\n')

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

#define pb         push_back

const int INF = 100000000;
const int N = 1000007;

int Eratos[N];
void era(){
	for(int i=0; i<N; i++){
		Eratos[i] = 1;
	}

	Eratos[0] = Eratos[1] = 0;
	for(int i=2; i*i <= N; i++){
		if(Eratos[i] != 1) continue;
		for(int j=2; i*j < N; j++){
			Eratos[i*j] = 0;
		}
	}
}

int main(void) {
	era();
	while(1){
		int a, d, n;
		cin >> a >> d >> n;
		if(a == 0 && d == 0 && n == 0) break;

		int cnt = 0;
		for(int i=0; ; i++){
			int s = a + d*i;
			if(Eratos[s] == 1) cnt++;
			if(cnt == n){
				cout << s << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 5064
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[100];
    for (int i = 0; i < n; i++)
        {
        cin >> a[i];
    }
         cout<<a[n-1];
    for (int i = n-2; i >= 0; i--)
        {
        cout  << " " << a[i];
    }
    cout <<endl;
    return 0;
}

Measured memory_bytes: 2984
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;
const int maxn=1e6;

typedef long long ll;

int a[maxn],b[maxn];

int main(){
	int n;cin>>n;
	for(int i=0;i<n;i++){
		int x,y;cin>>x>>y;
		a[i]=x+y;b[i]=x-y;
	}
	sort(a,a+n);
    sort(b,b+n);
    int ans=max(a[n-1]-a[0],b[n-1]-b[0]);
    cout<<ans;
	return 0;
}

Measured memory_bytes: 5176
#include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,l,n) for(i=l;i<n;i++)

int main(void){
	int n,i;
	double x1,x2,x3,y1,y2,y3,px,py,r,a,b,c,d,e,f;
	
	scanf("%d",&n);

	rep(i,0,n){
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		a=x1-x2;
		b=y1-y2;
		c=x2-x3;
		d=y2-y3;
		e=0.5*(x1*x1-x2*x2+y1*y1-y2*y2);
		f=0.5*(x2*x2-x3*x3+y2*y2-y3*y3);
		px=(d*e-b*f)/(a*d-b*c);
		py=(a*f-c*e)/(a*d-b*c);
		r=pow((x1-px)*(x1-px)+(y1-py)*(y1-py),0.5);
		printf("%.3lf %.3lf %.3lf\n",px,py,r);
	}

	return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

vector<pair<int, int>> adj[100000];
int pos[100000];

void dfs(int c, int p)
{
	pos[c] = p;
	for (auto n : adj[c]) {
		if (pos[n.first] == 0x7f7f7f7f) {
			dfs(n.first, p + n.second);
		}
		else if (pos[n.first] != pos[c] + n.second) {
			cout << "No\n";
			exit(0);
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, M;
	for (cin >> N >> M; M; M--) {
		int l, r, d;
		cin >> l >> r >> d;
		adj[--l].push_back({ --r,d });
		adj[r].push_back({ l,-d });
	}
	memset(pos, 0x7f, sizeof(pos));
	for (int i = 0; i < N; i++) if (pos[i] == 0x7f7f7f7f) {
		dfs(i, 0);
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 12032
#include<iostream>
using namespace std;
int main() {
  int H,N;
  cin >> H >> N;
  int a,i;
  for(i=0;i<N;i++) {
    cin >> a;
    H -= a;
  }
  if(H>0)cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    string s[n];
    rep(i, n) cin >> s[i];
    sort(s, s + n);
    int mx = 1;
    int num = 1;
    rep(i, n - 1){
        if (s[i] == s[i+1]){
            num++;
        }else{
            num = 1;
        }
        mx = max(mx, num);
    }
    num = 1;
    if (mx == 1){
        cout << s[0] << endl; 
    }
    
    rep(i, n - 1){
        if (s[i] == s[i+1]){
            num++;
        }else{
            num = 1;
        }
        // cout << num << endl;
        if (num == mx){
            cout << s[i+1] << endl;
        }
    }
}


Measured memory_bytes: 14208
import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
	Scanner s=new Scanner(System.in);
	  String st1=s.next();
	  String st2=s.next();
	  int ans=0;
	  for(int i=0;i<st1.length();i++)
	  {	
		if(st1.charAt(i)!=st2.charAt(i))
		ans++;
	  }
	System.out.println(ans);
	}
}

Measured memory_bytes: 41304
// input macro
// ref: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

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

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

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


#[allow(unused_mut)]
fn main() {
    input!(
        n: usize,
        k: usize,
        h: [usize; n],
    );

    h.sort();

    let mut ans: usize = 10usize.pow(18);
    for i in 0..(n-k+1) {
        ans = std::cmp::min(ans, h[i+k-1] - h[i]);
    }

    println!("{}", ans);
}


Measured memory_bytes: 6396
program teleporter
      implicit none
      integer(16) :: n,k
      integer(16),allocatable :: a(:),visitNum(:)
      logical,allocatable :: isVisited(:)
      integer(16) :: numTele,now,loopSize,loopPoint
      
      read*,n,k
      allocate( a(n) )
      read*,a(1:n)
      
      allocate( isVisited(n),source=.false. )
      allocate( visitNum(n) )
      
      numTele = 0
      now = 1
      visitNum(now) = numTele
      isVisited(now) = .true.
      do while(.true.)
        numTele = numTele + 1
        now = a(now)
        if( isVisited(now) )then
          loopSize = numTele - visitNum(now)
          loopPoint = now
          exit
        else
          isVisited(now) = .true.
          visitNum(now) = numTele
        end if
      end do
      
      
      now = 1
      if( loopPoint==now )then
        k = k - k/loopsize*loopsize
        if( k==0 )then
          print*,'1';stop
        end if
      end if
      do while( .true. )
        k = k - 1
        now = a(now)
        if( loopPoint==now )then
          k = k - k/loopsize*loopsize
        end if
        
        if( k==0 )then
          print*,now;stop
        end if
      end do
      
      
      
      
      
      
      !debugg
      print*,n,k
      print*,a(1:n)
      print*,visitNum
      print*,isVisited
      print*,'loopsize: ',loopSize
      print*,'loopPoint: ',loopPoint
      
      end program

Measured memory_bytes: 9984
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

vector<long long> d(55, 0);

long long clamp(long long a, long long b, long long c){
    return min(max(a, b), c);
}

long long  patty(int n, long long b, long long e){
    if (b == e)    return 0;
    if (n == 0)    return 1;
    long long l=1;
    l = (l << (n+2)) - 3;

    if (b == 0 && e == l){
        if (d[n] != 0)    return d[n];
    }

    long long ans = 0;
    ans += patty(n-1, clamp(b-1, 0, (l-3)/2-1), clamp(e-1, 0, (l-3)/2));
    ans += (b <= (l-1)/2 && (l-1)/2 < e) ? 1 : 0;
    ans += patty(n-1, clamp(b-(l-1)/2-1, 0, (l-3)/2-1), clamp(e-(l-1)/2-1, 0, (l-3)/2));

    if (b == 0 && e == l){
        d[n] = ans;
    }
    
    return ans;
}

int main(){
    long long n, x;
    cin >> n >> x;
    cout << patty(n, 0, x) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

char s[100005];
int main(void){
	scanf("%s",s);
	int l=0,r=strlen(s)-1;
	int ans=0;
	while(l<r){
		if(s[l]==s[r]){
			l++; r--;
			continue;
		}
		if(s[l]=='x'){
			l++; ans++;
			continue;
		}
		if(s[r]=='x'){
			r--; ans++;
			continue;
		}
		puts("-1");
		return 0;
	}
	printf("%d\n",ans);
	return 0;
}






Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int n, m;
VI l, r;

void solve() {
  cin >> n >> m;
  REP(i, m) {
    int L, R;
    cin >> L >> R;
    l.push_back(L);
    r.push_back(R);
  }
  sort(ALL(l));
  sort(ALL(r));
  int a = r.front() - l.back();
  if (a < 0) cout << 0 << endl;
  else cout << a+1 << endl;
}

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


Measured memory_bytes: 1276
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
      	int k = sc.nextInt();
      	int s = sc.nextInt();
        int i,j;
        int count = 0;

        for(i = 0;i <= k;i++){
	        for(j = 0;j <= k;j++){
		        if(s - (i + j) >= 0 && s - (i + j) <= k){
                  count += 1;
                }
        	}          
        }
      	System.out.print(count);
      
    }
}

Measured memory_bytes: 35668
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk)
{

var x= chunk.toString().split(' ')
 x[0] = Number(x[0])
 x[1] = Number(x[1])
 x[2] = Number(x[2])
x.sort();


console.log(x[0]+" "+x[1]+" "+x[2]);

});

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

int main() {
  
  int N;
  cin >> N;
  
  int mod, fx, Nd;
  Nd = N;
  while(Nd > 0) {
    mod = Nd % 10;
    fx += mod;
    Nd = Nd / 10;
  }
  
  if((N % fx) == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

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

int main(){
	double x1,x2,y1,y2;
	cin >> x1 >> x2 >> y1 >> y2;
	cout << fixed << setprecision(5) << sqrt((x1-y1)*(x1-y1) + (x2-y2)*(x2-y2)) << endl;
}

Measured memory_bytes: 1280
n = int(input())
a = list(map(int, input().split()))
def f(a, b):
    # b == 0: １番めが正

    sum_a = 0
    cost = 0
    for i, ai in enumerate(a):
        if i % 2 == b:
            sum_a += ai
            if sum_a <= 0:
                x = 1 - sum_a
                sum_a += x
                cost += abs(x)
        else:
            sum_a += ai
            if sum_a >= 0:
                x = -1 - sum_a
                sum_a += x
                cost += abs(x)
    return cost
print(min(f(a, 0), f(a, 1)))

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

using ll = long long;

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

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

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	std::string S;
	std::cin >> S;

	for (int i = 0; i < S.size(); ++i)
	{
		cout << 'x';
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    s = input()
    if s == "AC":
        ac += 1
    if s == "WA":
        wa += 1
    if s == "TLE":
        tle += 1
    if s == "RE":
        re += 1
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)


Measured memory_bytes: 9220
n,k  = map(int,input().split())
a = list(map(int,input().split()))
INF = 10**15
dp = [INF for _ in range(n)]
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i+j <= n-1 :
            dp[i+j] = min(dp[i]+ abs(a[i+j] - a[i]) , dp[i+j])
print(dp[-1])


Measured memory_bytes: 90136
s=input()

if s=='SUN':
    print(7)
if s=='MON':
    print(6)
if s=='TUE':
    print(5)
if s=='WED':
    print(4)
if s=='THU':
    print(3)
if s=='FRI':
    print(2)
if s=='SAT':
    print(1)


Measured memory_bytes: 2940