akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200009];
main(){
    ll n;
    cin >> n;
    for(ll i =  1; i <= n; i++){
        cin >> a[i];
    }
    if(a[1] != 0){
        cout << -1<< endl;
        return 0;
    }
    ll ans = 0;
    for(ll i = 2; i <= n; i++){
        if(a[i] > a[i-1] + 1){
            cout << -1 << endl;
            return 0;
        }
        if(a[i] == a[i-1] + 1) ans ++;
        else ans += a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include <iterator>
#include <tuple>
using namespace std;
using ll = long long;

int main()
{
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (auto &e : a)
    cin >> e;
  sort(a.begin(), a.end());
  int cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    if (x == 0)
      break;
    if (i == n - 1 && a[i] < x)
      break;
    if (a[i] <= x)
    {
      x -= a[i];
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll d[500000];
ll A[500001];
ll B[500001];
int main() {
	int N, D;
	cin >> N >> D;
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	A[0] = D;
	for (int i = 0; i < N; i++) {
		A[i + 1] = min(abs(A[i] - d[i]), A[i]);
	}
	B[N] = 1;
	for (int i = N - 1; i >= 0; i--) {
		if (B[i + 1] <= d[i] / 2) B[i] = B[i + 1];
		else B[i] = B[i + 1] + d[i];
	}
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int q;
		cin >> q;
		q--;
		if (A[q] >= B[q + 1]) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

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

  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  vector<int> freq(N+1);
  for(auto elem:data){
    freq.at(elem)++;
  }
  sort(freq.begin(), freq.end(), greater<int>());

  int Npat= 0;
  for(int k=0; k<K; k++){
    Npat+= freq.at(k);
  }

  int ans= N- Npat;

  cout << ans << endl;
}

Measured memory_bytes: 4808
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
int main()
{
	int n;
	cin >> n;
	vector<pii> vp(n);
	rep(i, n)
	{
		int x, l;
		cin >> x >> l;
		vp[i] = make_pair(x + l, x-l);
	}
	sort(all(vp));
	int now = vp[0].first;
	int ans = 1;
	rep(i, n)
	{
		if(now <= vp[i].second){
			now = vp[i].first;
			ans++;
		}
	}
	cout << ans << endl;
}


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

int main(){
    long int a,b,c,sum,num;
    cin >> a >> b >>c;
    sum=a+b;

    if(sum>=c&&a>c){
        cout<<0<<endl;
    }
    else if(sum>=c){
        num=c-a;
        cout<<num<<endl;
    }
    else{
        cout<<"NA"<<endl;
    }
    
   return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  VI A(N);
  rep(i,N) cin>>A[i];
  sort(all(A));
  int cnt=1;
  rep(i,N-1) if(A[i+1]!=A[i]) cnt++;
  if((N-cnt)%2) cout<<cnt-1<<endl;
  else cout<<cnt<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, lint> pi;

struct disj{
	int pa[100005];
	void init(int n){
		for(int i=0; i<=n; i++) pa[i] = i;
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		pa[q] = p; return 1;
	}
}disj;

struct pnt{
	int x, y, idx;
}a[100005];

int n, p, q;

lint solve(vector<pi> v, lint p){
	lint ret = 0;
	sort(v.begin(), v.end());
	for(auto &i : v){
		ret += lower_bound(v.begin(), v.end(), pi(i.first - p, i.second + p + 1))
			- lower_bound(v.begin(), v.end(), pi(i.first - p, i.second - p));
		ret += lower_bound(v.begin(), v.end(), pi(i.first + p, i.second + p + 1)) 
			- lower_bound(v.begin(), v.end(), pi(i.first + p, i.second - p));
	}
	for(auto &i : v) swap(i.first, i.second);
	sort(v.begin(), v.end());
	for(auto &i : v){
		ret += lower_bound(v.begin(), v.end(), pi(i.first - p, i.second + p))
			- lower_bound(v.begin(), v.end(), pi(i.first - p, i.second - p + 1));
		ret += lower_bound(v.begin(), v.end(), pi(i.first + p, i.second + p)) 
			- lower_bound(v.begin(), v.end(), pi(i.first + p, i.second - p + 1));
	}
	ret /= 2;
	return ret;
}

int dx[100005];

int main(){
	scanf("%d %d %d",&n,&p,&q);
	p--, q--;
	for(int i=0; i<n; i++){
		scanf("%d %d",&a[i].x, &a[i].y);
		a[i].idx = i;
	}
	int dis = abs(a[p].x - a[q].x) + abs(a[p].y - a[q].y);
	auto cmp1 = [&](const pnt &a, const pnt &b){
		return pi(a.x + a.y, a.x - a.y) < pi(b.x + b.y, b.x - b.y);
	};
	auto cmp2 = [&](const pnt &a, const pnt &b){
		return pi(a.x - a.y, a.x + a.y) < pi(b.x - b.y, b.x + b.y);
	};
	disj.init(n);
	sort(a, a+n, cmp1);
	for(int i=0; i<n; i++){
		auto l1 = lower_bound(a, a+n, (pnt){a[i].x - dis, a[i].y, -1}, cmp1);
		auto l2 = upper_bound(a, a+n, (pnt){a[i].x, a[i].y - dis, -1}, cmp1);
		if(l1 != l2){
			disj.uni(a[i].idx, l1->idx);
			dx[l1 - a + 1]++; dx[l2 - a]--;
		}
		l1 = lower_bound(a, a+n, (pnt){a[i].x, a[i].y + dis, -1}, cmp1);
		l2 = upper_bound(a, a+n, (pnt){a[i].x + dis, a[i].y, -1}, cmp1);
		if(l1 != l2){
			disj.uni(a[i].idx, l1->idx);
			dx[l1 - a + 1]++; dx[l2 - a]--;
		}
	}
	for(int i=1; i<n; i++){
		dx[i] += dx[i-1];
		if(dx[i]) disj.uni(a[i-1].idx, a[i].idx);
	}
	memset(dx, 0, sizeof(dx));
	sort(a, a+n, cmp2);
	for(int i=0; i<n; i++){
		auto l1 = lower_bound(a, a+n, (pnt){a[i].x - dis, a[i].y, -1}, cmp2);
		auto l2 = upper_bound(a, a+n, (pnt){a[i].x, a[i].y + dis, -1}, cmp2);
		if(l1 != l2){
			disj.uni(a[i].idx, l1->idx);
			dx[l1 - a + 1]++; dx[l2 - a]--;
		}
		l1 = lower_bound(a, a+n, (pnt){a[i].x, a[i].y - dis, -1}, cmp2);
		l2 = upper_bound(a, a+n, (pnt){a[i].x + dis, a[i].y, -1}, cmp2);
		if(l1 != l2){
			disj.uni(a[i].idx, l1->idx);
			dx[l1 - a + 1]++; dx[l2 - a]--;
		}
	}
	for(int i=1; i<n; i++){
		dx[i] += dx[i-1];
		if(dx[i]) disj.uni(a[i-1].idx, a[i].idx);
	}
	vector<pi> v;
	for(int i=0; i<n; i++){
		if(disj.find(p) == disj.find(a[i].idx)){
			v.push_back(pi(a[i].x + a[i].y, a[i].x - a[i].y));
		}
	}
	cout << solve(v, dis);
}


Measured memory_bytes: 5872
N, M = map(int, input().split())
KA = [ list(map(int, input().split())) for _ in range(N)]

like = [ 0 for x in range(M+1)]
for ka in KA:
    a = ka[1:]
    for aa in a:
        like[aa] += 1

#print(like)
cnt = 0
for l in like:
    if l == N:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
import java.io.IOException;
import java.util.BitSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			boolean[][] map = new boolean[n][31];
			for (int i = 0; i < n; i++) {
				int f = scanner.nextInt();
				while (f-- > 0)
					map[i][scanner.nextInt()] = true;
			}
			int ans = -1;
			BitSet[] bit = new BitSet[n];
			for (int i = 0; i < n; i++) {
				bit[i] = new BitSet();
				bit[i].set(i);
			}
			for (int t = 1; t <= 30; t++) {
				BitSet tmp = new BitSet();
				for (int i = 0; i < n; i++)
					if (map[i][t])
						tmp.or(bit[i]);
				for (int i = 0; i < n; i++)
					if (map[i][t])
						bit[i].or(tmp);

				if (tmp.cardinality() == n) {
					ans = t;
					break;
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 70076
#include <bits/stdc++.h>
using namespace std;
namespace mint {
  int md = 1e9 + 7;
  inline void add (int &a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    a += b; if (a >= md) a -= md;
  }
  inline void sub (int &a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    a -= b; if (a < 0) a += md;
  }
  inline int sum (int a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    add(a, b); return a;
  }
  inline int dif (int a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    sub(a, b); return a;
  }
  template<class... A>
  inline int prod (A... args) {
    long long ret = 1;
    for (int a :	initializer_list<int>{args...}) {
      assert(0 <= a && a < md);
      ret *= a;
      ret %= md;
    }
    return (int)(ret % md);
  }
  inline void mul (int &a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    a = prod(a, b);
  }
  inline int inv (int a) {
    assert(0 <= a && a < md);
    a %= md;
    if(a < 0) a += md;
    int b = md, u = 0, v = 1;
    while (a) {
      int t = b / a;
      b -= a * t; swap(a, b);
      u -= v * t; swap(u, v);
    }
    assert(b == 1);
    if(u < 0) u += md;
    return u;
  }
  inline int quot (int a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    return prod(a, inv(b));
  }
  inline void div (int& a, int b) {
    assert(0 <= a && a < md && 0 <= b && b < md);
    a = quot(a, b);
  }
  inline int pow (int a, long long b) {
    assert(0 <= a && a < md);
    int res = 1;
    for (; b; b >>= 1) {
      if (b & 1) mul(res, a);
      mul(a, a);
    }
    return res;
  }
  namespace factorials {
    int sz;
    vector<int> fact, finv;
    void init (int n) {
      sz = n;
      fact.resize(n); finv.resize(n);
      fact[0] = 1;
      for (int i = 1; i < n; i++) fact[i] = prod(fact[i - 1], i);
      finv[n - 1] = inv(fact[n - 1]);
      for (int i = n - 2; i >= 0; i--) finv[i] = prod(finv[i + 1], i + 1);
    }
  }
  inline int fct (int i) {
    using namespace factorials;
    assert(0 <= i && i < sz);
    return fact[i];
  }
  inline int fnv (int i) {
    using namespace factorials;
    assert(0 <= i && i < sz);
    return finv[i];
  }
  inline int binom (int n, int k) {
    using namespace factorials;
    assert(0 <= n && n < sz);
    if (0 < k || n < k) return 0;
    return prod(fact[n], finv[k], finv[n - k]);
  }
}
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int n, h, d;
  cin >> n >> h >> d;
  mint::factorials::init(n + 1);
  int B = 0;
  for (int i = 1; i <= n; i++) {
    mint::add(B, mint::fct(i));
  }
  vector<int> dp(h, 0);
  dp[0] = 1;
  for (int i = 1; i < h; i++) {
    dp[i] = mint::prod(mint::sum(B, 1), dp[i - 1]);
    if (i > d) mint::sub(dp[i], mint::prod(B, dp[i - d - 1]));
  }
  int ret = mint::prod(
    mint::dif(dp[h - 1], dp[h - d - 1]),
    mint::fct(n)
  );
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 12032
import java.util.Scanner;

public class Main {
	//implement the inversion pair with a modified version of merge algorithm
	
	public static long inter_count(int[] arr, int lo, int mid, int hi) {
		int n_l = mid - lo +1;
		int n_r = hi - mid;
		int [] L = new int[n_l+1];
		int [] R = new int[n_r+1];
		
		for(int i = 0; i< n_l; i++) {
			L[i] = arr[lo+i];
		}
		
		for(int j = 0; j < n_r; j++) {
			R[j] = arr[mid + j +1];
		}
		
		L[n_l] = Integer.MAX_VALUE;
		R[n_r] = Integer.MAX_VALUE;
		
		int l_i = 0;
		int r_i = 0;
		long c = 0;
		
		int i = lo;
		while(i <= hi) {
			if(L[l_i] > R[r_i]) {
				arr[i] = R[r_i];
				c += n_l - l_i;
				r_i++;
			}else {
				arr[i] = L[l_i];
				l_i++;
			}
			i++;
		}
		
		
		
		return c;
	}
	
	public static long count_inv(int [] arr, int lo, int hi) {
		if(lo == hi) return 0;
		
		int mid = (lo + hi) >> 1;
		long ans = 0;
		
		ans += count_inv(arr, lo, mid);
		ans += count_inv(arr, mid+1, hi);
		
		
		return ans + inter_count(arr, lo, mid, hi);
	}
	
	public static void main(String [] args) {
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		int [] arr = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = cin.nextInt();
		}
		
		System.out.println(count_inv(arr, 0, arr.length-1));
		
		cin.close();
	
	}
}

Measured memory_bytes: 101052
package main

import (
	"fmt"
	"os"
)

func main() {
	var s string
	fmt.Scanln(&s)

	var a, b, c, d int
	a = int(s[0] - '0')
	b = int(s[1] - '0')
	c = int(s[2] - '0')
	d = int(s[3] - '0')

	// fmt.Println(a, b, c, d)

	for i := 0; i < 2; i++ {
		for j := 0; j < 2; j++ {
			for k := 0; k < 2; k++ {
				b2 := b
				bs := '+'
				if i == 1 {
					b2 *= -1
					bs = '-'
				}
				c2 := c
				cs := '+'
				if j == 1 {
					c2 *= -1
					cs = '-'
				}
				d2 := d
				ds := '+'
				if k == 1 {
					d2 *= -1
					ds = '-'
				}
				if a+b2+c2+d2 == 7 {
					fmt.Printf("%d%c%d%c%d%c%d=7\n", a, bs, b, cs, c, ds, d)
					os.Exit(0)
				}
			}
		}
	}
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int n, k;
string a[11];
bool used[11];
set<string> se;

void dfs(int j, string s="")
{
    if (j == 0) {
        se.insert(s);
        return;
    }

    rep(i, n) {
        if (used[i]) continue;
        used[i] = true;

        dfs(j - 1, s + a[i]);

        used[i] = false;
    }
}

int main()
{
    while (cin >> n >> k, n) {
        se.clear();

        rep(i, n) cin >> a[i];

        dfs(k);

        cout << se.size() << endl;
    }
}

Measured memory_bytes: 3380
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K,x,y;
	while(cin>>N>>M) {
		VI C(N, 1), R(N);
		R[0]=1;
		REP(i, M) {
			cin>>x>>y;
			x--;y--;
			if(R[x]) R[y]=1;
			C[y]++;
			C[x]--;
			if(C[x]==0) R[x]=0;
		}
		ll ans=0;
		REP(i, N) ans+=R[i];
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1792
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 300;

int aa[N][N], kk_[N][N], rr_[N][N];
bool used[N];

int main() {
	int n, m, l; cin >> n >> m >> l;
	while (m--) {
		int i, j, c; cin >> i >> j >> c, i--, j--;
		if (l >= c)
			aa[i][j] = aa[j][i] = c;
	}
	for (int s = 0; s < n; s++) {
		int *kk = kk_[s], *rr = rr_[s];
		for (int j = 0; j < n; j++)
			kk[j] = n;
		kk[s] = 0, rr[s] = l;
		fill(used, used + n, false);
		while (true) {
			int i = -1;
			for (int j = 0; j < n; j++)
				if (!used[j] && (i == -1 || kk[i] > kk[j] || kk[i] == kk[j] && rr[i] < rr[j]))
					i = j;
			if (i == -1)
				break;
			used[i] = true;
			for (int j = 0, c; j < n; j++) {
				if (!used[j] && (c = aa[i][j])) {
					int k = kk[i];
					int r = rr[i];
					if (r < c) {
						k++;
						r = l;
					}
					r -= c;
					if (kk[j] > k || kk[j] == k && rr[j] < r) {
						kk[j] = k;
						rr[j] = r;
					}
				}
			}
		}
	}
	int q; cin >> q;
	while (q--) {
		int i, j; cin >> i >> j, i--, j--;
		int k = kk_[i][j];
		if (k == n)
			k = -1;
		cout << k << '\n';
	}
	return 0;
}


Measured memory_bytes: 4688
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N ;
    cin >> N;
    vector<int>a(N);
    vector<int>b(N);
    for(int i= 0; i<N;i++){
        cin >> a[i];
        b[i] = a[i];
    }
    int c = 0;
    sort(b.begin(),b.end());
    for(int i = 0; i<N;i++){
        //cout <<b[i];
        if(a[i] != b[i]){
            c++;
        } 
    }
    if(c > 2){
        cout << "NO" <<endl;

    }
    else{
        cout << "YES" <<endl;
    }
}

Measured memory_bytes: 256
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
}


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

using namespace std;

int A[101010];
int main(void){
	int N, K;
	scanf("%d %d", &N, &K);

	int p=-1, min = 101010;
	for(int i = 0; i < N;++i){
		scanf("%d", A + i);
		if(A[i] < min){
			min = A[i];
			p = i;
		}
	}

	int left = 1 + ceil((double) max(p - K + 1, 0)/(K-1));
	int right = 1 + ceil((double) max(N - (p+K), 0)/(K-1));

	if(p < K){
		int r = N-K;
		right = ceil((double)r/(K-1));
	}else if(p >= N-K){
		int l = N-K;
		left = ceil((double)l/(K-1));
	}

	int a = left + right;

	int x = ceil((double) (p - (K/2))/(K-1));

	int hoge;
	if(K%2 == 0){
		hoge = (K/2) - 1;
	}else{
		hoge = K/2;
	}
	int y = ceil((double) (N - (p + hoge) - 1)/(K-1));

	printf("%d\n", a < x+y+1 ? a:x+y+1);

	return 0;
}

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

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

  cout << (int)(ceil(n / x) * t) << endl;

  return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>

int main(){
	int n,i,ans=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		if(a!=i+1)ans++;
	}
	if(ans<=2)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 128
n = int(input())
buy = 2000000001
sell = 0
max_profit = -1000000001
for _ in range(n):
    r = int(input())
    if r < buy:
        max_profit = max(max_profit, r - buy)
        buy = r
    else:
        sell = r
        max_profit = max(max_profit, sell - buy)

print(max_profit)
    


Measured memory_bytes: 5612
import Control.Monad
import Data.List

main = do
    n <- readLn  -- :: IO Int
    -- xus <- words <$> getLine
    xus <- replicateM n (words <$> getLine)  -- :: IO [[String]]
    -- let [x,u] = transpose xus
    print . sum $ map solve xus

solve :: [String] -> Double
solve (x:u:[]) = if u == "JPY" then read x else (read x) * 380000

Measured memory_bytes: 636
#include<iostream>
#include<stack>
#include<utility>
#define INF 10000000
using namespace std;
int fw[30][30],fh[30][30];
bool used[30][30];
int w,h;
int d[30][30];
int cnt;
void dfs(){
  stack<pair<pair<int,int>,int> > sta;
  sta.push(make_pair(make_pair(0,0),1));
  while(!sta.empty()){
    pair<pair<int,int> ,int> q=sta.top(); sta.pop();
    int x=q.first.first,y=q.first.second;
    int cnt=q.second;
    if(d[x][y]<=cnt) continue;
    d[x][y]=cnt;
    cnt++;
    if(x!=0&&fh[x-1][y]==0) sta.push(make_pair(make_pair(x-1,y),cnt));
    if(y!=0&&fw[x][y-1]==0) sta.push(make_pair(make_pair(x,y-1),cnt));
    if(x!=h-1&&fh[x][y]==0) sta.push(make_pair(make_pair(x+1,y),cnt));
    if(y!=w-1&&fw[x][y]==0) sta.push(make_pair(make_pair(x,y+1),cnt));
  }
}
int main(){
  cin >> w >> h;
  while(w!=0){
    cnt=0;
    for(int i=0;i<2*h-1;i++){
      if(i%2==0){
        for(int j=0;j<w-1;j++){
          cin >> fw[i/2][j];
        }
      }else{
        for(int j=0;j<w;j++){
          cin >> fh[i/2][j];
        }
      }
    }
    for(int i=0;i<30;i++){
      for(int j=0;j<30;j++){
        used[i][j]=false;
        d[i][j]=INF;
      }
    }
    dfs();
    if(d[h-1][w-1]==INF) d[h-1][w-1]=0;
    cout << d[h-1][w-1]<<endl;
    cin >> w >> h;
  }
}



Measured memory_bytes: 3072
#include<iostream>
int main (void){
    int n;
    double so=1,ans=0,z;
    scanf("%d",&n);
    int a[n+1];
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        so=so*a[i];
    }
    for(int i=1;i<=n;i++){
        ans=ans+so/a[i];
    }
    z=so/ans;
    printf("%f",z);
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class C
{
	public static void Main()	
	{
		long mod = 1000000007;

		int N = GetInt();
		int[] num = new int[N];
		for(int i = 0; i < N; i++)
			num[GetInt()]++;

		if(!verify(N, num))
		{
			Console.WriteLine(0);
			return;
		}
		
		long ans = 1;
		for(int i = 0; i < N/2; i++)
			ans = (ans << 1) % mod;		
		Console.WriteLine(ans);
	}

	private static bool verify(int N, int[] num)
	{
		if(N % 2 == 1)
		{
			if(num[0] != 1)
				return false;
			for(int i = 2; i < N; i += 2)
				if(num[i] != 2)
					return false;
			return true;
		}
		else
		{
			for(int i = 1; i < N; i += 2)
				if(num[i] != 2)
					return false;
			return true;
		}
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 21856
/*
 *  Created by Andrei Arhire 02/08/2020
 *  Copyright © 2020 Andrei Arhire. All rights reserved.
 */
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lll long long
#define llf __float128
#define lld long double
using namespace std;
const lll NR = 1e5 + 10  ,oo = 2e9 + 10, MOD = 1e9 + 7 ;
const long double pi = 2*acos(0.0);

lll cnt , d , n , x , y ;
signed main () {
    int i ;

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0) ;
   cin >> n >> d ;
   for ( i = 1 ; i <= n ; ++ i )    {
       cin >> x >> y ;
       if ( x * x + y * y <= d * d )
           ++ cnt ;
   }
    cout << cnt << '\n';
    return 0 ;
}


Measured memory_bytes: 3648
import sys
from collections import Counter

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

mod = 10 ** 9 + 7

h, w = na()
c = []
for i in range(h):
    c.append(input())

for i in range(2 * h):
    ans = ""
    for j in range(w):
        ans += c[i//2][j]
    print(ans)




Measured memory_bytes: 3316
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let mut a: isize = read().unwrap();
    let b: isize = read().unwrap();
    let mut c: isize = read().unwrap();
    let d: isize = read().unwrap();

    let mut turn = 0;
    while (a > 0) & (c > 0) {
        if turn % 2 == 0 {
            c -= b;
        } else {
            a -= d;
        }
        turn += 1;
    }
    if c <= 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2156
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
a = inpl()
res = 0
for ope in range(k+1):
    for pick in range(ope+1):
        if pick > n: continue
        back = ope - pick
        for lp in range(pick+1):
            rp = pick - lp
            # print(ope,back,lp,rp)
            q = []
            for i in range(lp):
                q.append(a[i])
            for i in range(rp):
                q.append(a[-i-1])
            q.sort()
            ans = sum(q)
            res = max(res,ans)
            for i in range(back):
                if i >= pick: break
                ans -= q[i]
                res = max(res,ans)
print(res)

Measured memory_bytes: 79528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, x, y, z, ans;
  cin >> N;
  x=1;
  y=1;
  z=1;
  for(long long i=1; i<=N; i++){
    ans=0;
    for(long long j=x; j<101; j++){
      for(long long k=y; k<101; k++){
         for(long long l=z; l<101; l++){
           if(j*j+k*k+l*l+j*k+k*l+l*j>i){
             break;
           }else if(j*j+k*k+l*l+j*k+k*l+l*j<i){
             continue;
           }else if(j*j+k*k+l*l+j*k+k*l+l*j==i){
             ans++;
           }
         }
      }
    }
    if(ans==0){
      cout << 0 << endl;
    }else{
      cout << ans << endl;
    }
  }
 
  return 0;
}

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

const int INF = 1e9;
const int inf = 1e18;
const int MOD = 1e9 + 7;

int f(int b, int n){
	if (n < b){
		return n;
	}
	return f(b, n / b) + (n % b);
}

signed main(){
	int n, s, b;
	cin >> n >> s;
	if (n == s){
		cout << n + 1;
		return 0;
	}
	int ans = inf;
	for (int i = 2; i * i <= n; i++){
		if (f(i, n) == s){
			cout << i;
			return 0;
		}
	}
	for (int i = 1; i * i <= n - s; i++){
		b = (n - s) / i + 1;
		if (f(b, n) == s){
			ans = min(ans, b);
		}
	}
	if (ans == inf){
		cout << -1;
		return 0;
	}
	cout << ans;
}

Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, K;
	cin >> n >> K;
	int c = 0;
	for(int i=0;i<n;i++) {
		int x;
		cin >> x;
		if(x >= K) c++;
	}
	cout << c;
	return 0;
}


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

int main(void)
{
	int n;
	scanf("%d", &n);

	char s[n + 1][11], temp;
	int len;

	scanf("%s", s[0]);
	len = strlen(s[0]);
	temp = s[0][len - 1];

	for (int i = 1; i < n; i++)
	{
		scanf("%s", s[i]);
		if (s[i][0] != temp)
		{
			printf("No");
			return 0;
		}
		len = strlen(s[i]);
		temp = s[i][len - 1];
	}

	for (int i = 0; i < n - 1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if ((strcmp(s[i], s[j])) == 0)
			{
				printf("No");
				return 0;
			}
		}
	}

	printf("Yes");

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c)
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define mod          10000007
#define PI           acos(-1.0)
#define MAX3(a,b,c)  max(a,max(b,c))

/*------------------------Bitmask-------------------------------*/
#define bitOn(N,pos)      (N | (1LL<<(pos)))
#define bitOff(N,pos)     (N & (~(1LL<<(pos))))
#define bitCheck(N,pos)   ((bool)(N & (1LL<<(pos))))
#define bitFlip(a,k)      (a^(1LL<<(k)))

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

/*----------------------- Graph Moves---------------------------*/
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};  // 4 Direction
// int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1-1,-1};  // 8 Direction // Kings Move
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};  // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};  // Hexagonal Direction

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
//string S, T, U;

ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;

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

    cin>>n;
    cout<<n+(n*n)+(n*n*n)<<endl;
    return 0;
}


Measured memory_bytes: 3580
/* created   : 2019-10-07 21:54:49
 * accepted  : 2019-10-07 22:04:46
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

struct key {
  int cost;
  int unlock;
};

void solve() {
  int n, m; cin >> n >> m;
  vector<key> v(m);
  for (int i = 0; i < m; i++) {
    cin >> v[i].cost;
    int b; cin >> b;
    int unlock = 0;
    for (int j = 0; j < b; j++) {
      int x; cin >> x;
      x--;
      unlock |= (1 << x);
    }
    v[i].unlock = unlock;
  }
  const int INF = (1 << 30);
  vector<int> dp(1 << n, INF);
  dp[0] = 0;
  for (auto key : v) {
    for (int state = 0; state < (1 << n); state++) {
      int nstate = state | key.unlock;
      // trace(nstate, state, key.unlock);
      dp[nstate] = min(dp[nstate], dp[state] + key.cost);
    }
  }
  trace(dp);
  int ans = dp[(1 << n) - 1];
  cout << (ans == INF ? -1 : ans) << '\n';
}

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


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

typedef long long LL;

int main()
{
	LL N;
	cin>>N;
	
	LL h,n,w;
	
	if(N%2==0)
	{
		h=n=N;
		w=N/2;
	}
	else
	{
		bool flag=false;
		for(LL i=1;i<=3500;i++)
		{
			for(LL j=1;j<=3500;j++)
			{
				LL t1=N*i*j;
				LL t2=4*i*j-N*i-N*j;
				if(t2>0&&t1>0&&t1%t2==0)
				{
					h=i;
					n=j;
					w=t1/t2;
					flag=true;
				}
				if(flag)break;
			}
			if(flag)break;
		}
	}
	
	cout<<h<<" "<<n<<" "<<w;
	
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,x;
int m,a=1e9,ans;
int main(){
    cin>>n>>x;
    ans=n;
    for(int i=0;i<n;i++){
        cin>>m;
        x-=m;
        a=min(a,m);
    }
    ans+=(x/a);
    cout<<ans;
}

Measured memory_bytes: 256
//by shubham_bitsg

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector <string> vs;

//#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define forl(i,a,b) for (int i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define srt(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)
#define PI 3.141592653589793238
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n; cin>>n;
    string s = "";
    while(n>0) {
        n--;
        char ch = 'a' + n%26;
        s = ch + s;
        n/=26;
    }
    cout<<s<<"\n";
}

Measured memory_bytes: 3588
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io
	
	string x;
	cin>>x;
	ll s1=0,s2=0;
	rep(i,0,3)
	{
		if(x[i]=='A')
			s1++;
		else
			s2++;
	}
	if(s1 && s2)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>//万能头文件
using namespace std;
int main()
{
	long long x,a,b,c,ans=0;//long long保险
	cin>>a>>b>>c>>x;//输入这四个数
	for(int i=0;i<=a;i++)//枚举500硬币的个数
	    for(int j=0;j<=b;j++)//枚举100硬币的个数
	        for(int z=0;z<=c;z++){//枚举50硬币的个数
	        	int k=i*500+j*100+z*50;//定义k为此时硬币总值
	        	if(k==x)//如果就是x
	        	   ans++;//计数器加一
	        	if(k>x)//这是一个优化，如果k值已经超过了x，后面的z到c时k的值一定大于x，肯定不等于x，所以可以直接退出当前循环
	        	   break;//退出当前循环
	        }
	cout<<ans<<endl;//输出ans的值(AT题都要打换行)
	return 0;
}

Measured memory_bytes: 256
/**
                  ▄█▀ ▀█▀ ▄▀▄ █▀ █▄█▄█ ▄▀▄ █▀ ▄█▀
                  <⇋⇋⇋⋛∰≓⊂(⌒,_ゝ⌒)⊃≓∰⋛⇋⇋⇋>

            ♔♕♖♗♘♙ ☜❷☞✪ ィℋ६ ≈ ᗫẵℜℵĬŊĞ ✪☜❷☞ ♚♛♜♝♞♟
            ♔♕♖♗♘♙                             ♚♛♜♝♞♟
                      ˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙

**/

#include <bits/stdc++.h>

#define sz(s) s.size()
#define pb emplace_back
#define fr first
#define sc second
#define mk make_pair
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 2e5 + 5;
const int inf = 1e9 + 7;

int n, sum, a[N];
vector < int > b;
vector < pair < int, int > > s;

main()
{
   cin >> n;
   for( int i = 1; i <= n; i++ )
      cin >> a[i], b.pb( a[i] );

   sort( all( b ) );

   for( int i = 1; i <= n; i++ )
   {
      int pos = lower_bound( all( b ), a[i] / 2 ) - b.begin() - 3;
      pos = max( 0, pos );
      int p = inf, l = 0;
      for( int j = pos; j <= min( pos + 3, n - 1 ); j++ )
         if( abs( a[i] - b[ j ] - b[ j ] ) < p )
            l = b[ j ], p = abs( a[i] - b[ j ] - b[ j ] );
      s.pb( mk( a[i], l ) );
   }
   pair < int, int > v, q;
   sort( all( s ) );
   v = s[ sz(s) - 1 ];
   cout << v.fr << ' ' << v.sc << endl;
}


Measured memory_bytes: 2168
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <climits>
#include <queue>
#include <assert.h>
#include <set>
#include <numeric>
#include <memory.h>

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

//#define int long long
typedef long long ll;

using namespace std;

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int a, b, c;
    
    cin >> a >> b >> c;
    if (b - a == c - b) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>
#include<unordered_map>
using namespace std ;

#define MOD 1000000007
#define MAXN 1007

int n ;
int mng , mxg ;
int lo , hi ;

long long dp[ MAXN ][ MAXN ] ;

long long fac[ MAXN ] ;
long long inv[ MAXN ] ;


long long fastpow ( long long x , long long pw ) {
    long long ret = 1 ;
    while ( pw > 0 ) {
        if ( ( pw & 1 ) == 0 ) {
            x = ( x * x ) % MOD ;
            pw /= 2 ;
        }
        else {
            ret = ( ret * x ) % MOD ;
            -- pw ;
        }
    }
    return ret ;
}

void input ( ) {
    cin >> n >> mng >> mxg >> lo >> hi ;
}

void solve ( ) {
    fac[ 0 ] = 1 ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        fac[ i ] = ( fac[ i - 1 ] * i ) % MOD ;
    }
    inv[ n ] = fastpow ( fac[ n ] , MOD - 2 ) ;
    for ( int i = n - 1 ; i >= 0 ; -- i ) {
        inv[ i ] = ( inv[ i + 1 ] * ( i + 1 ) ) % MOD ;
    }

    dp[ mng - 1 ][ n ] = 1 ;
    for ( int i = mng ; i <= mxg ; ++ i ) {
        long long hh = fastpow ( inv[ i ] , lo ) ;
        for ( int j = 0 ; j <= n ; ++ j ) {
            dp[ i ][ j ] = dp[ i - 1 ][ j ] ;
            long long coef = hh ;
            for ( int t = lo ; t <= hi ; ++ t ) {
                if ( t * i + j > n ) { break ; }
                long long ways = ( fac[ t * i + j ] * inv[ j ] ) % MOD ;
                ways = ( ways * coef ) % MOD ;
                ways = ( ways * inv[ t ] ) % MOD ;
                dp[ i ][ j ] += ( ways * dp[ i - 1 ][ t * i + j ] ) % MOD ;
                dp[ i ][ j ] %= MOD ;
                coef = ( coef * inv[ i ] ) % MOD ;
            }
        }
    }
    printf ( "%lld\n" , dp[ mxg ][ 0 ] ) ;
}


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


Measured memory_bytes: 8192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;

        static void SolveA()
        {
            string n = Console.ReadLine();
            string ans = "ABC" + n;
            Console.WriteLine(ans);
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    for(auto& i : d) cin >> i;
    
    sort(d.begin(), d.end());
    cout << d[n / 2] - d[n / 2 - 1] << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<int> sort(vector<int> vec) {
    vector<int> sorted(vec.size(),0);
    sort(vec.begin(), vec.end());
    rep(i, vec.size()) {
        sorted[i] = vec[i];
    }
    return sorted;
}
vector<int> resort(vector<int> vec) {
    sort(vec);
    reverse(vec.begin(), vec.end());
    return vec;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
  int n;
  cin >> n;
  vector<int> v=input(n);
  sort(v.begin(),v.end());
  cout << v.back()-v[0] << endl;
}

Measured memory_bytes: 256
W,a,b = list(map(int,input().split()))
if (a<=b<=a+W) or (a<=b+W<=a+W) or (b<=a<=b+W) or (b<=a+W<=b+W):
    c=0
else:
    c = min(abs(b-a-W),abs(a-b-W))
print(c)


Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
    
typedef long long in;
typedef unsigned long long ull;
    
#define MOD 1000000007
#define mi 18446744073709551615

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<a*b;
    
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define ll long long

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a.at(i);
		if(a.at(i) == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	
	ll max = 1000000000000000000;
	
	ll ans = a.at(0);
	for(int i = 1; i < n; i++){
		if(a.at(i) > max/ans){
			ans = -1;
			break;
		}
		ans *= a.at(i);
	}
	
	cout << ans << endl;
	
}

Measured memory_bytes: 3984
n, m = map(int, input().split())
ans = [-1]*n

if n == 1 and m == 0:
    print(0)
    exit()

for i in range(m):
    s, c = map(int, input().split())

    if s == 1 and c == 0 and n != 1:
        print(-1)
        exit()

    if ans[s-1] == -1 or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()

if ans[0] == -1:
    ans[0] = 1

for i in range(n):
    if ans[i] == -1:
        ans[i] = 0

print(*ans, sep="")


Measured memory_bytes: 38384
n = int(input())
s = list(input())

result = 0
for i in range(len(s)):
    if (i > n - 3):
        break
    if (s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C'):
        result = result + 1

print(result)


Measured memory_bytes: 2940
'use strict';
(function(stdin) {
    var inputs = stdin.toString().split('\n');
    var EOF = '0';
    var data = inputs.slice(0, inputs.indexOf(EOF));
    for(var i=0;i<data.length;i++){
    var j = 1
    console.log('Case',i+1+':',data[i]);
}
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 20752