akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
const string YES = "YES";
const string NO = "NO";
ll R, C;    
struct event {
    char type;
    int x, y, i;
    pair<int, int> ordering() const {
        if(x == R) {
            return {0, y};
        } else if(y == C) {
            return {1, -x};
        } else if(x == 0) {
            return {2, -y};
        } else { // y == 0
            return {3, x};
        }
    }  
    bool operator<(const event& e) const {
        return ordering() < e.ordering();
    }
};
void solve(long long N, std::vector<std::vector<long long>> x, std::vector<std::vector<long long>> y) {
    auto on_boundary = [&](int xx, int yy) {
        return xx == 0 or xx == R or yy == 0 or yy == C;
    };
    vector<event> events;
    for(int i = 0; i < N; i++) {
        if(on_boundary(x[i][0], y[i][0]) and on_boundary(x[i][1], y[i][1])) {
            event e1 = {'?', x[i][0], y[i][0], i};
            event e2 = {'?', x[i][1], y[i][1], i};
            e1.type = e1 < e2 ? '(' : ')';
            e2.type = e2 < e1 ? '(' : ')';
            events.push_back(e1);
            events.push_back(e2);
        }
    }
    sort(events.begin(), events.end());
    stack<int> s;
    bool valid = true;
    for(auto& e : events) {
        if(e.type == '(') {
            s.push(e.i);
        } else if(not s.empty() and s.top() == e.i) {
            s.pop();
        } else {
            valid = false;
            break;
        }
    }
    cout << (valid ? YES : NO) << endl;
}
int main() {
    scanf("%lld",&R);
    scanf("%lld",&C);
    long long N;
    scanf("%lld",&N);
    std::vector<std::vector<long long>> x(N, std::vector<long long>(2));
    std::vector<std::vector<long long>> y(N, std::vector<long long>(2));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < 2 ; j++){
            scanf("%lld",&x[i][j]);
            scanf("%lld",&y[i][j]);
        }
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  string A = "Sunny",B = "Cloudy",C = "Rainy";
  if (S == A)
    cout << B << endl;
  if (S == B)
    cout << C << endl;
  if (S == C)
    cout << A << endl;
  
}


Measured memory_bytes: 3600
def main():
    n = int(input())
    i = 1
    ans = 10**18
    while i*i <= n:
        j = n//i
        if i*j == n:
            ans = min(ans, i-1 + j-1)
        i+=1
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import heapq

N = int(raw_input())
mins = [10**9] * (N+1)
mins[0] = 0
maps = [0] * (N+1)
maps[0] = 0
for i in xrange(N):
  maps[i+1] = int(raw_input())
h = []
for i in xrange(1, 7):
  heapq.heappush(h, [1, i+1])
while h:
  check = heapq.heappop(h)
  if N < check[1] or mins[check[1]] <= check[0]: continue
  mins[check[1]] = check[0]
  if maps[check[1]] == 0:
    for i in xrange(1, 7):
      heapq.heappush(h, [check[0]+1, check[1]+i])
  else:
    heapq.heappush(h, [check[0], check[1]+maps[check[1]]])
print mins[N]

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
const int maxx=0x3f3f3f3f;
int n,cnt;
int L[250005],R[250005];
void merge(int A[],int n,int left,int mid,int right)
{
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++) L[i]=A[left+i];
    for(int i=0;i<n2;i++) R[i]=A[mid+i];
    int i=0;
    int j=0;
    R[n2]=L[n1]=maxx;
    for(int k=left;k<right;k++)
    {
        if(L[i]<R[j])
        {
            cnt++;
            A[k]=L[i];
            i++;
        }
        else
        {
            cnt++;
            A[k]=R[j];
            j++;
        }
    }
}
void mergesort(int A[],int n,int left,int right)
{
    if(left+1>=right) return ;
    int mid=(left+right)/2;
    mergesort(A,n,left,mid);
    mergesort(A,n,mid,right);
    merge(A,n,left,mid,right);
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    int A[500005];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    mergesort(A,n,0,n);
    
    for(int i=0;i<n;i++)
    {
        if(i) cout<<" ";
        cout<<A[i];
    }
    cout<<endl<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 7016
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if(A > 12) {
    cout << B << endl;
  }
  else if (A >= 6) {
    cout << B / 2 << endl;
  }
  else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<char> t(q), d(q);
  rep(i, q) cin >> t[i] >> d[i];

  int ans = n;
  int l = -1, r = n;
  while (r - l > 1) {
    int m = (l + r) / 2, res = m;
    bool f = false;
    rep(i, q) {
      if (s[res] == t[i]) {
        if (d[i] == 'L') res--;
        else res++;
      }
      if (res < 0 || res >= n) {
        if (res < 0) f = true;
        break;
      }
    }
    if (f) l = m;
    else r = m;
  }
  ans -= l + 1;
  l = -1, r = n;
  while (r - l > 1) {
    int m = (l + r) / 2, res = m;
    bool f = false;
    rep(i, q) {
      if (s[res] == t[i]) {
        if (d[i] == 'L') res--;
        else res++;
      }
      if (res < 0 || res >= n) {
        if (res >= n) f = true;
        break;
      }
    }
    if (f) r = m;
    else l = m;
  }
  ans -= n - r;
  cout << ans << endl;



  
  return 0;
}

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

int main(){
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  if(s[0]=='s'){
    reverse(s.begin(),s.end());
    cout<<s<<"es"<<endl;
  }else{
    reverse(s.begin(),s.end());
    cout<<s<<"s"<<endl;
  }
  return 0;
}


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

using namespace std;
const long long mod=1e9+7;
int n,m;
string a[1001];
int d[1001][1001];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]='.'+a[i];
    }
    d[1][1]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(i==1&&j==1)
                continue;
            if(a[i][j]=='#')
                d[i][j]=0;
            else
                d[i][j]=(d[i-1][j]+d[i][j-1])%mod;
        }
    }
    cout<<d[n][m];
    return 0;
}


Measured memory_bytes: 5120
def main():

    N = int(input())
    A = list(map(int, input().split()))
    for v in A:
        if v % 2 == 0 and (v % 5 != 0 and v % 3 != 0): return "DENIED"
    return "APPROVED"

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;

const ll LINF = 1e18;
const int INF = 1e9;
const int MOD = 1e9+7;

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

map<int, int> m;

int main(){
	fastio;
	string s;
	cin >> s;
	int n = len(s);
	m[0] = 1;
	int num = 0, power = 1, ans = 0;
	for(int i = n-1; i >= 0; i--){
		num += (s[i]-'0')*power;
		num %= 2019;
		ans += m[num];
		m[num]++;
		power *= 10;
		power %= 2019;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int ans[100] ={};
    for (int a = 0; a <= 9; ++a) {
        for (int b = 0; b <= 9; ++b) {
            for (int c = 0; c <= 9; ++c) {
                for (int d = 0; d <= 9; ++d) {
                    ++ans[a + b + c + d];
                } 
            }
        }
    }

    int n;
    while (cin >> n) {
        cout << ans[n] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3084
x,n=map(int,input().split())
p=[]
if n:
	p=list(map(int,input().split()))
ans=None
mi=float("inf")
for i in range(-300,300):
	if i not in p:
		if mi>abs(x-i):
			mi=abs(x-i)
			ans=i
print(ans)

Measured memory_bytes: 9184
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

#[cfg(debug_assertions)]
macro_rules! debug {
      ($($a:expr),*) => {
          println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}

use std::collections::VecDeque;
fn main() {
  input!{
    h: usize, w:usize,
    a: [chars; h]
  }
  let inf = 100000000000i64;
  let mut b = vec![vec![inf; w]; h];
  let mut queue = VecDeque::new();
  for y in 0..h {
    for x in 0..w {
      if a[y][x] == '#' {
        b[y][x] = 0;
        queue.push_front((y, x));
      } 
    }
  }
      use std::cmp;
  let dx = [0, 1, 0, -1];
  let dy = [1, 0, -1, 0];
  //debug!(queue);
  while !queue.is_empty() {
    let (y, x) = queue.pop_back().unwrap();
    let mut ok = false;
    //debug!(y,x);
    for d in 0..4 {
      let ny = y as i64 + dy[d];
      let nx = x as i64 + dx[d];
      if !(0 <= nx && nx < w as i64 && 0 <= ny && ny < h as i64) {
        continue;
      }
      //debug!("FROM<-", ny, nx);
      let ny = ny as usize;
      let nx = nx as usize;
      if b[ny][nx] == inf {
        queue.push_front((ny, nx));
      }
      b[ny][nx] = cmp::min(b[y][x] + 1, b[ny][nx]);
    }
  }

  //debug!(b);
  let mut res = -1;
  for y in 0..h {
    for x in 0..w {
      res = cmp::max(b[y][x], res);
    }
  }
  println!("{}", res);
}

Measured memory_bytes: 31992
#include <bits/stdc++.h>
using namespace std;
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define fill(x, y)     memset(x, y, sizeof(y))
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
const   int            inf = 0;
const   double         eps = 0;
const   int            ms  = 0;
const   int            md  = 0;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long long int n,k;
	cin>>n>>k;
	vector<long long int>vec(n+1);
	for(long long int i =0 ; i<n; i++){
        cin>>vec[i+1];
	}
	long long int cnt =0;
	vector<long long int>check(n+1);
	vector<long long int>con;
    long long int ptr =1;
//    cout<<ptr<<endl;
//    con.push_back(ptr);
//    for(int i =0 ; i<con.size();i++){
//        cout<<con[i]<<endl;
//	}
	while(check[ptr] == 0){
        cnt++;
        check[ptr] = 1;
        con.push_back(ptr);
        ptr = vec[ptr];

	}
	int cntt = 0;
	vector<long long int>chec(n+1);
	vector<long long int>cont;
    while(chec[ptr] == 0){
        cntt++;
        chec[ptr] = 1;
        cont.push_back(ptr);
        ptr = vec[ptr];

	}
//	cout<<cnt<<endl;
//	cout<<cntt<<endl;
//	for(int i =0 ; i<con.size();i++){
//        cout<<con[i]<<endl;
//	}
//	cout<<"afdghfj"<<endl;
//	for(int i =0 ;i<cont.size();i++){
//        cout<<cont[i]<<endl;
//	}
//	cout<<cntt<<endl;
    int l  =cnt -cntt;
    if(k<= l){
        cout<<con[k];
    }else{
        k -= (l);
        int d= k%cntt ;

        cout<<cont[d]<<endl;
    }





	return 0;
}


Measured memory_bytes: 12348
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long  ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;

vector<int> G[2000];
string s;

P dfs(int id, int fr) {
	P ret = { 0,0 };
	if (s[id] == '1')ret.first++;
	rep(j, G[id].size()) {
		int to = G[id][j];
		if (to == fr)continue;
		P z = dfs(to, id);
		ret.first += z.first;
		ret.second += z.second;
	}
	ret.second += ret.first;
	return ret;
}
//dist,num
P dfs2(int id, int fr) {
	P ret = { 0,0 };
	if (s[id] == '1')ret.second++;
	vector<P> u;
	rep(j, G[id].size()) {
		int to = G[id][j];
		if (to == fr)continue;
		P z = dfs2(to, id);
		u.push_back(z);
		ret.second += z.second;
	}
	if (!u.empty()) {
		sort(u.begin(), u.end());
		int sum = u.back().first;
		rep(i, (int)u.size() - 1) {
			sum -= u[i].first;
		}
		if (sum < 0)sum = 0;
		ret.first += sum;
	}
	ret.first += ret.second;
	return ret;
}
void solve() {
	int n; cin >> n;
	cin >> s;
	rep(i, n - 1) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = mod;
	rep(i, n) {
		vector<P> v;
		rep(j, G[i].size()) {
			int to = G[i][j];
			P z = dfs(to, i);
			v.push_back({ z.second,to });
		}
		if (v.empty()) {
			cout << 0 << endl; return;
		}
		sort(v.begin(), v.end());
		int sum = 0; int chk = 0;
		rep(i, v.size()) {
			sum += v[i].first;
			chk ^= (v[i].first % 2);
		}
		if (chk)continue;
		if (sum - v.back().first < v.back().first) {
			P z = dfs2(v.back().second,i);
			if (z.first > sum - v.back().first)continue;
		}
		//cout << sum << endl;
		ans = min(ans, sum / 2);
	}
	if (ans == mod)ans = -1;
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> n)solve();
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 640
def main():
    n, m, *abc = map(int, open(0).read().split())
    d = [[float("Inf")] * (n + 1) for _ in range(n + 1)]

    for i in range(1, n + 1):
        d[i][i] = 0

    for a, b, c in zip(*[iter(abc)] * 3):
        d[a][b] = c
        d[b][a] = c

    for k in range(1, n + 1):
        for i in range(1, n + 1):
            for j in range(1, n + 1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

    ans = 0
    for a, b, c in zip(*[iter(abc)] * 3):
        if d[a][b] < c:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



int main() {
	int n,m; cin >> n >> m;
	vector<int> a(n), b(n), c(m), d(m),pos(n);

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

	int min,distance;

	for (int i = 0; i < n; i++) {
		min = 1000000000+7;
		int num = 0;
		for (int j = 0; j < m; j++) {
			distance = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			
			if (distance < min) {
				min = distance;
				num = j + 1;
			}
			
		}
		cout << num << endl;
	}

	
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
#include <cmath>

using namespace std;

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

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};


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

    int N,M;
    cin >> N >> M;
    int p[N];
    for(int i = 0; i < N; i++) {
        cin >> p[i];
    }

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

    UnionFind uf(N);

    for(int i = 0; i < M; i++) {
        uf.unionSet(x[i]-1,y[i]-1);
    }

    int ans = 0;

    for(int i = 0; i < N; i++) {
        if(uf.findSet(i,p[i]-1)) ans++;
    }
    cout << ans << endl;

}





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

using namespace std;

int main()
{
	long long n,a,b;
	cin >> n >> a >> b;
	if(a<b) swap(a,b);
	if((a-b)&1)
	{
		cout << (a-b)/2+min(b,n+1-a) << endl;
	}
	else 
	{
		cout << (a-b)/2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def main
  n = gets.chomp.to_i
  nums = Array.new(n)
  n.times do |i|
    nums[i] = gets.chomp.to_i
  end

  nums.sort!.reverse!

  ans = 0
  if n.even?
    # 偶数個(6個)の場合: +2, +2, +1, -1, -2, -2
    #       (4個)      :     +2, +1, -1, -2
    #       (2個)      :         +1, -1
    #                                ↑center_idx
    center_idx = n / 2
    nums.each_with_index do |num, idx|
      if idx < center_idx - 1
        ans += num * 2
      elsif center_idx < idx
        ans -= num * 2
      elsif idx == center_idx
        ans -= num
      else
        ans += num
      end
    end
  else
    # 奇数個(5個)の場合: +2, +2, -1, -1, -2
    #                    +2, +1, +1, -2, -2
    #       (3個)      :     +2, -1, -1
    #                        +1, +1, -2
    #                            ↑center_idx
    center_idx = n / 2

    # +2, -1, -1 パターン
    ans0 = 0
    nums.each_with_index do |num, idx|
      if idx < center_idx
        ans0 += num * 2
      elsif center_idx + 1 < idx
        ans0 -= num * 2
      else
        ans0 -= num
      end
    end

    # +1, +1, -2 パターン
    ans1 = 0
    nums.each_with_index do |num, idx|
      if idx < center_idx - 1
        ans1 += num * 2
      elsif center_idx < idx
        ans1 -= num * 2
      else
        ans1 += num
      end
    end

    ans = [ans0, ans1].max
  end

  puts ans
end

if __FILE__ == $0
  main
end


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

using namespace std;

int main() {
	int x, y; cin >> x >> y;

	vector<int> g1 = { 1,3,5,7,8,10,12 };
	vector<int> g2 = { 4,6,9,11 };

	if (x == 2 || y == 2) cout << "No" << endl;
	else {
		if (find(g1.begin(), g1.end(), x) != g1.end() && find(g2.begin(), g2.end(), y) != g2.end()) {
			cout << "No" << endl;
		}
		else if (find(g1.begin(), g1.end(), y) != g1.end() && find(g2.begin(), g2.end(), x) != g2.end()) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
}

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

using namespace std;
typedef long long ll;

string s;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> s;
    int ans = 0, cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'R')
            cnt++;
        else
            ans = max(ans, cnt), cnt = 0;
    }
    ans = max(ans, cnt);
    cout << ans;
    return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//using ll=long long;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//dp注意点
//問題の種類	 初期化する値	 備考
//最小化問題 	INF	
//最大化問題	    -INF	 テーブル全体で 00 以上の値しかとらないことがわかっていれば −1−1 でもいいですし、00 でもいい場合もあります
//数え上げ問題	00	
//確率問題	      00	
//Yes/No 判定問題	False
/*-------------ここまで---------------------------------------------*/

/*signed*/int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(c - (a - b), 0) << endl;
    return 0;
}

Measured memory_bytes: 3588
n,l=map(int,input().split())
dic={}
for i in range(n):
    text=input()
    if text[0] not in dic:
        dic[text[0]]=[text]
    else:
        dic[text[0]].append(text)
for i in dic:
    dic[i]=sorted(dic[i])
dic=sorted(dic.values())
for i in dic:
    try:
        for j in i:
            print(j,end='')
    except:
        print(i,end='')

Measured memory_bytes: 3060
// Aizu Vol-1 0138: Track and Field Competition
// 2017.8.2

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);
char buf[50], *p;

#define INF 1000000
typedef struct { int n, t; } R;
R s[4][8], a[4][2];

int getDouble(void)
{
	int len = 0, n = 0;

	while (isspace(*p)) p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	if (*p == '.') p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0'), len++;
#define MAGIC 2
	if (len > MAGIC) while (1);
	while (len < MAGIC) n = 10 * n, len++;
	return n;
}

int getInt(void)
{
	int n = 0;
	while (isspace(*p)) p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

int main()
{
	int i, j;
	int t1, t2, n1, n2;

	for (i = 0; i < 3; i++) for (j = 0; j < 8; j++) {
		gets(p = buf);
		s[i][j].n = getInt(), s[i][j].t = getDouble();
	}
	for (i = 0; i < 3; i++) {
		if (s[i][0].t <= s[i][1].t) t1 = 0, t2 = 1;
		else t1 = 1, t2 = 0;
		for (j = 2; j < 8; j++) {
			if (s[i][j].t < s[i][t1].t) t2 = t1, t1 = j;
			else if (s[i][j].t < s[i][t2].t) t2 = j;
		}
		a[i][0].n = s[i][t1].n, a[i][0].t = s[i][t1].t, s[i][t1].t = INF;
		a[i][1].n = s[i][t2].n, a[i][1].t = s[i][t2].t, s[i][t2].t = INF;
	}
	t1 = t2 = n1 = n2 = INF;
	for (i = 0; i < 3; i++) {
		for (j = 0; j < 8; j++) {
			if (s[i][j].t < t1) t2 = t1, n2 = n1, t1 = s[i][j].t, n1 = s[i][j].n;
			else if (s[i][j].t < t2) t2 = s[i][j].t, n2 = s[i][j].n;
		}
	}
	a[3][0].n = n1, a[3][0].t = t1;
	a[3][1].n = n2, a[3][1].t = t2;
	for (i = 0; i <= 3; i++) {
		for (j = 0; j < 2; j++) printf("%d %d.%02d\n", a[i][j].n, a[i][j].t/100, a[i][j].t%100);
	}

	return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
int main() {
  int n;cin>>n;
  set<string> shiri;
  vector<string> shi(n);
  REP(i,n){
    string s;cin>>s;
    shiri.insert(s);
    shi[i]=s;
  }
  bool ans=true;
  if(shiri.size()!=n){
    ans=false;
  }else{
    string s=shi[0];
    char last=s[s.size()-1];
    FOR(i,1,shiri.size()){
      string cur=shi[i];
      if(last==cur[0]){
        last=cur[cur.size()-1];
        continue;
      }else{
        ans=false;
      }
    }
  }
  cout <<((ans==false)?"No":"Yes") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,k;
    long long int a,b,c;
   cin>>a>>b>>c;
    {
        if(a==5 && b==5 && c==7)
        {
            cout<<"YES"<<endl;
        }
        else if(a==5 && b==7 && c==5)
        {
            cout<<"YES"<<endl;
        }
        else if(a==7 && b==5 && c==5)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,a[300000],a1[300000],a2[300000],d;
int main()
{
  cin>>n;
  for(int i=0;i<n;i++){int x;cin>>x;a[x]++;a1[x]++;if(a[x]==1)d++;a2[i]=x;}
  sort(a,a+n);
  long long ans=0;
  for(int i=0;i<=n;i++)
  {
  ans+=((a[i]*(a[i]-1))/2);
  }
  for(int i=0;i<n;i++)
  {
  cout<<ans-(a1[a2[i]]-1)<<endl;
  }
}

Measured memory_bytes: 8320
#include<iostream>
#include<vector>
#define LEN 100005

using namespace std;

typedef struct pp{
  string name;
  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 main()
{
  int elaps = 0;
  int c, q;
  P u;

  cin >> n >> q;

  for(int i = 1; i <= n ; i++){
    cin >> Q[i].name >> Q[i].t;
  }

  head = 1;
  tail = n + 1;

  while(head != tail){
    u = dequeue();
    c = q < u.t ? q : u.t;
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);

    else cout << u.name << " " << elaps << endl;
      
  }

  return 0;

}



Measured memory_bytes: 7100
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
  int n,m,q;
  while(cin>>n>>m,n||m){
    pair<int,int> p[100];
    for(int i=0;i<n;++i){
      for(int j=0;j<m;++j){
	if(i==0) p[j].second=j;
	if(cin>>q,q) --p[j].first;
      }
    }
    sort(p,p+m);
    cout<<p[0].second+1;
    for(int i=1;i<m;++i){
      cout<<' '<<p[i].second+1;
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
loop do
 tests = gets.split.map &:to_i
 if tests[0] + tests[1] + tests[2] == -3
  exit
 elsif tests[0] == -1 || tests[1] == -1
  puts :F
 else
  score = tests[0] + tests[1]
  if score >= 80
   puts :A
  elsif score >= 65
   puts :B
  elsif score >= 50
   puts :C
  elsif score >= 30
   puts tests[2] >= 50 ? :C: :D
  else
   puts :F
  end
 end
end


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

int main(){
    int d; cin>>d;
    
    if( d == 25 ) cout<<"Christmas"<<endl;

    else if(d == 24) cout<<"Christmas Eve"<<endl;

    else if( d == 23) cout<<"Christmas Eve Eve"<<endl;

    else if( d== 22) cout<<"Christmas Eve Eve Eve"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a < b){
		printf("a < b\n");
	}
	else if(a > b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
N = int(input())
 
S = [None] * N
 
m = dict()
 
for i in range(N):
  s = input()
  if not s in m.keys():
    m[s] = 1
  else:
    m[s] += 1
 
max_cnt = max(m.values())
 
ret = []
 
for k, v in sorted(m.items(), key=lambda x: x[1], reverse=True):
  if v < max_cnt:
    break
  ret.append(k)
 
ret.sort()
for s in ret:
  print(s)

Measured memory_bytes: 44764
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);

#ifdef BUGGY
	bool DEBUG = 1;
#endif
#ifndef BUGGY
	bool DEBUG = 0;
#endif

int A[3];

int main()
{
	scanf("%d %d %d", &A[0], &A[1], &A[2]);
	sort(A, A+3);
	reverse(A, A+3);
	printf("%d\n", (A[0] * 10) + A[1] + A[2]);

	return 0;
}
/*
	Powered by Buggy Plugin
*/

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 1000000000000;
const long long MOD = 1000000007;

//書くくらいの輪を返す
long long f(long long N){
  string s = to_string(N);
  long long slen = s.length();
  long long ret=0;
  for (int i = 0; i < slen; i++)
    ret += (s[i] - '0');
  return ret;
}

int main()
{
  string s;
  cin >> s;
  bool ans = true;
  long long c_count = 0;
  for (int i = 0; i < s.length(); i++)
  {
    if(i==0){
      if(s[i]=='A')
        continue;
      ans = false;
      break;
    }
    if(s[i]=='C' && 2<=i && i<=s.length()-2){
      c_count++;
      continue;
    }

    if(!('a'<=s[i] && s[i]<='z'))
      ans = false;
  }
  if(c_count!=1)
    ans = false;
  if(ans)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>

using namespace std;
typedef long long ll;

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



Measured memory_bytes: 1408
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <unordered_set>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

int n, a;

int main(void)
{
    cin >> n >> a;

    if (n % 500 <= a)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

struct UnionFind
{
    vector<int> par;
    vector<int> tsize;
    UnionFind(int n) : par(n), tsize(n) {
        REP(i,n) {
            par[i] = i;
            tsize[i] = 1;
        }
    }

    // 親を返す
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    // 木の統合
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        tsize[ry] += tsize[rx];
        par[rx] = ry;
    }

    // 同じ木に属しているか
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {return tsize[root(x)];};
};

int main(void)
{
    IOS
    ll n, m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<pii> ab(m);
    ll mf = n*(n-1)/2;
    vector<ll> ans;
    ans.push_back(mf);
    REP(i,m) {
        cin >> ab[i].first >> ab[i].second;
        ab[i].first--; ab[i].second--;
    }
    for(int i = m-1;i >= 0; i--) {
        if (!uf.same(ab[i].first,ab[i].second)) {
            cerr << uf.size(ab[i].first) << " " << uf.size(ab[i].second) << endl;
            ans.push_back(ans.back() - uf.size(ab[i].first) * uf.size(ab[i].second));
            uf.unite(ab[i].first,ab[i].second);
        } else {
            ans.push_back(ans.back());
        }
    }

    reverse(ALL(ans));
    REP(i,m) cout << ans[i+1] << '\n';



    return 0;
}

Measured memory_bytes: 3828
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ls = max(a, c);
	int ef = min(b, d);
	int res = ef - ls;
	if (res < 0) cout << 0 << endl;
	else cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
(defun collector (lst)
  (if lst
      (let* ((ans '())
             (mem (cons (car lst) 1)))
        (mapcar (lambda (k)
                  (if (= k (car mem))
                      (incf (cdr mem))
                      (progn (push mem ans)
                             (setf mem (cons k 1))))) (cdr lst))
        (push mem ans)
        ans)
      '()))
(let* ((n (read))
       (m (read))
       (lst (sort (loop :repeat n :collect (read)) #'<))
       (ans 0))
  (mapcar (lambda (k)
            (if (= m 0)
                (incf ans (cdr k))
                (decf m))) (sort (collector lst) #'> :key #'cdr) )
  (princ ans))

Measured memory_bytes: 61800
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  for(int i=0;i<s.length()-1;++i){
    if(s[i]==s[i+1]){
      cout<<"no";
      return 0;
    }
  }
  cout<<"yes";
  return 0;
}

Measured memory_bytes: 256
max_s = 2500

n,m,s = map(int, input().split())
s = min(s, max_s)
conv = lambda i,j : i*10000+j

G = [[] for i in range(conv(n-1, max_s)+1)]
for i in range(m):
    u,v,a,b = map(int, input().split())
    u,v = u-1, v-1
    for j in range(max_s+1):
        if j-a >= 0:
            G[conv(u,j)].append((conv(v,j-a), b))
            G[conv(v,j)].append((conv(u,j-a), b))

for i in range(n):
    c,d = map(int, input().split())
    for j in range(max_s+1):
        if j+c > max_s:
            break
        G[conv(i,j)].append((conv(i,j+c), d))

from heapq import heappush, heappop
def dijkstra(G, start):
    n = len(G)
    dist = [float("inf")]*n
    visited = set()
    heap = [(0, start)]

    while heap and len(visited) != n:
        d, cur = heappop(heap)
        if cur in visited:
            continue
        visited.add(cur)
        dist[cur] = d
        for to, cost in G[cur]:
            if to not in visited:
                heappush(heap, (d+cost, to))
    return dist

dist = dijkstra(G, conv(0, s))
for i in range(1,n):
    cost = min(dist[conv(i,0):conv(i,max_s)+1])
    print(cost)


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

int main()
{
	int i,N,n;
	cin >> N;
	vector<int> v;
	for (i=0;i<N;i++) {
		cin >> n;
		v.push_back(n);
	}
	
	sort(v.begin(),v.end(),greater<int>());
	
	int nOld = 0,nNow,nCountValue = 0,nCount = 0;
	for (i=0;i<N;i++) {
		nNow = v[i];
		if (nOld == nNow) {
			nCountValue++;
			continue;
		}
		
		nCount += (nCountValue % 2);
		nCountValue = 1;
		nOld = nNow;
	}
	nCount += (nCountValue % 2);
	
	cout << nCount <<endl;
	return 0;
}

Measured memory_bytes: 892
#include<stdio.h>
#include<stdlib.h>
char *P[2] = {"No", "Yes"};

int compare_char1(const void *a, const void *b){return *(char*)a - *(char*)b;}
int compare_char2(const void *a, const void *b){return *(char*)b - *(char*)a;}
char S[101], T[101], s, t, c, f;
int main(){
  while((c=getchar())!=10){S[s++]=c;}
  while((c=getchar())!=10){T[t++]=c;}
  qsort(S, s, sizeof(char), compare_char1);
  qsort(T, t, sizeof(char), compare_char2);
  f=0;
  for(c=0; c<=s; c++){
    if(S[c]>T[c]){
      break;
    }else if(S[c]<T[c]){
      f=1;
      break;
    }
  }
  puts(P[f]);
}


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

using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007LL;

int main()
{
    int N, T;
    cin >> N >> T;
    vector<int> D(N);
    for (int i = 0; i < N; i++) {
        cin >> D[i];
    }
    sort(D.begin(), D.end());

    ll prod = 1;
    for (ll i = 1; i < N; i++) {
        const ll lower = D.begin() + i - lower_bound(D.begin(), D.begin() + i, D[i] - T) + 1;
        prod = (prod * lower) % MOD;
    }
    cout << prod << endl;

    return 0;
}

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

int main() {
    int N, D;
    cin >> N >> D;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        if(sqrt(pow(x, 2) + pow(y, 2)) <= D) {
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3672
import heapq
heap = []
while True:
    op = input().split()
    if op[0] == 'end':
        break
    elif op[0] == 'insert':
        heapq.heappush(heap, -int(op[1]))
    elif op[0] == 'extract':
        print(-heapq.heappop(heap))



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

using namespace std;

int main(void){
    int n; cin >> n;
    int S[n];
    for(int i = 0; i < n; i++){ cin >> S[i];}
    int q; cin >> q;
    int T[q];
    for(int i = 0; i < q; i++){ cin >> T[i];}
    int sum = 0;
    for(int i = 0; i < q; i++){
        for(int j = 0; j < n; j++){
            if(T[i] == S[j]){
                sum ++;
                break;
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3088
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
k a b

10^9
 */
ll k,a,b;

int main(){
  cin>>k>>a>>b;

  if(a>=b || k<=a-1)
    cout<< k+1 <<endl;
  else
    cout << max(a+ (k-(a-1))/2*(b-a) + (k-(a-1))%2, k+1) <<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
 
#define REP(i,b,n) for(int i=b;i<n;++i)
#define REPR(i,b,n) for(int i=n-1;i>=b;--i)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PI acos(-1.0)

using namespace std;

static const double EPS = 1e-9;
typedef pair<int, int> pii;
typedef long long ll;

int ball[10];

bool issorted(vector<int> v){

	if(v.size() < 2)
		return true;
	
	for(int i = 0 ; i < v.size()-1; ++i){
	
		if(v[i] > v[i+1])
			return false;
	}
	
	return true;
}

string solve(){
	
	for(int i=0; i < (1<<10); ++i){
		
		vector<int> lft, rgt;
		
		for(int j=0; j<10; ++j){
			
			if(BIT(i,j))
				lft.push_back(ball[j]);
			else
				rgt.push_back(ball[j]);
		}
		
		if(issorted(lft)&& issorted(rgt)){
			return "YES";
		}
	}
	
	return "NO";
}		

int main(){
		
	int n;
	cin >> n;
	
	for(int k=0; k<n; ++k){
	
		for(int i=0; i<10; ++i){
			cin >> ball[i];
		}
		
		cout << solve() << endl;
	}
	
	return 0;
}

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

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

    int n, K;
    cin >> n >> K;
    int ok = 1e18, ng = 0;
    auto check = [&](int m) {
        int cur = m;
        REP(i, n) {
            if (cur == 0) return false;
            cur -= (cur + K - 1) / K;
        }
        return true;
    };
    while (abs(ok - ng) > 1) {
        int m = (ok + ng) / 2;
        (check(m) ? ok : ng) = m;
    }

    cout << ok - 1 << endl;
}



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

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

using namespace std;

int main () {
  int N = 0, K = 0, mv = 0;
  cin >> N >> K;
  
  rep(i, N) {
    int x = 0;
    cin >> x;
    mv += min(abs(x * 2), abs((x - K) * 2));
  }
  cout << mv << endl;
}

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

int main(void) {
	string s;
	cin >> s;
	if (s == "SUN") {
		cout << "7" << endl;
	}
	else if (s == "MON") {
		cout << "6" << endl;
	}
	else if (s == "TUE") {
		cout << "5" << endl;
	}
	else if (s == "WED") {
		cout << "4" << endl;
	}
	else if (s == "THU") {
		cout << "3" << endl;
	}
	else if (s == "FRI") {
		cout << "2" << endl;
	}
	else if (s == "SAT") {
		cout << "1" << endl;
	}
}

Measured memory_bytes: 256
def ext_euler(a, b):
    if b == 0:
        return 1, 0, a
    else:
        y, x, v = ext_euler(b, a%b)
        y -= (a//b) * x
        return x, y, v


def mod_inv(x, mod):
    if x > mod:
        ans, _, _ = ext_euler(x, mod)
    else:
        _, ans, _ = ext_euler(mod, x)
    return ans % mod


def comb_list(n, mod):
    ret = [1 for _ in range(n + 1)]
    for k in range(n):
        c = ret[k]
        c *= (n - k)
        c %= mod
        c *= mod_inv(k + 1, mod)
        c %= mod
        ret[k + 1] = c
    return ret


def main():
    MOD = 998244353
    N, M, K = list(map(int, input().split(' ')))
    # x pair of same color
    # -> M * (M - 1)**(N - 1 - x) * (N - 1)_C_x
    # -> sum up from x = min(K, N - 1) to x = 0
    patterns = [0 for _ in range(N)]
    comb = comb_list(N - 1, MOD)
    pw = M
    for x in range(N - 1, -1, -1):
        patterns[x] = pw * comb[x]
        patterns[x] %= MOD
        pw *= (M - 1)
        pw %= MOD
    ans = 0
    for x in range(min(K, N - 1) + 1):
        ans += patterns[x]
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

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

using namespace std;

typedef long long ll;
ll a[300];
int main(){
	long long x;
	cin>>x;
	for(long long  i =1;i <=200;i++)
	a[i] = pow(i,5);
	a[0] = 0;
    
	for(int i =0;i <= 200;i++)
	 {int p = 0;
	 for(int j = 0;j<= i;j++)
	   {
	   if(a[i]-a[j]==x) {
	   	 cout<<i<<" "<<j<<endl;
	     p =1;
		 break;
	   }
	   if(a[i]+a[j]==x)
	   {    p= 1;
			cout<<i<<" "<<-j<<endl;
	    	break;
	   }
       }
       if(p==1) break;
  }
	return 0;
}

Measured memory_bytes: 4124
n = input()

for _ in range(n):
    s = raw_input()

    bag = set()
    for i in range(len(s)):
        head = s[:i]
        tail = s[i:]

        bag.add(head + tail)
        bag.add(head + tail[:: -1])
        bag.add(head[:: -1] + tail)
        bag.add(head[:: -1] + tail[:: -1])
        bag.add(tail + head)
        bag.add(tail + head[:: -1])
        bag.add(tail[:: -1] + head)
        bag.add(tail[:: -1] + head[:: -1])

    print len(bag)

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

typedef long long int lli;
typedef long double lld;
typedef long long ll;
//Datatype
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vvlli vector<vector<long long int>>
#define ppi pair<int, int>
#define rppi pair<int, pair<int, int>>
#define lppi pair<pair<int, int>, int>
#define vppi vector<pair<int, int>>
#define sppi stack<pair<int int>>
#define qppi queue<pair<int, int>>
//function
#define f first
#define s second
#define pb(x) push_back(x)
#define mkp(i, j) make_pair(i, j)
#define lmkp(i,j,k) make_pair(make_pair(i,j),k)
#define rmkp(i,j,k) make_pair(i,make_pair(j,k))
//loop
#define loop(i,n) for (i = 0; i < n; ++i)
#define loops(i,k,n) for (i = k; i <= n; ++i)
#define looprev(i,k,n) for (i = k; i >= n; --i)
//Const
#define inf (int)1e9
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
//Print
#define prd(n) printf("%d", n)
#define prl(n) printf("%lld", n)
#define prdn(n) printf("%d\n", n)
#define prln(n) printf("%lld\n", n)
#define prf(n) printf("%f", n)
//Scan
#define scd(n) scanf("%d", &n)
#define scd2(a, b) scanf("%d %d", &a, &b)
#define scd3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scl(n) scanf("%lld", &n)
#define scl2(a, b) scanf("%lld %lld", &a, &b)
#define scl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define scf(n) scanf("%f", &n)

using namespace std;
lli dp[3005][3005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i, j, k, N;
    cin>>N;
    vector<lli> A(N, 0);
    loop(i, N){
        cin>>A[i];
    }
    looprev(i, N-1, 0){
        loops(j, i, N-1){
            if(i == j){
                dp[i][j] = A[i];
            }
            else{
                dp[i][j] = max(A[i] - dp[i+1][j], A[j] - dp[i][j-1]);
            }
        }
    }
    cout<<dp[0][N-1]<<endl;
  return 0;
}

Measured memory_bytes: 49696