akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

bool eight(int n){
    int divisor=0;
    for(int i=1; i<=n; i++){
        if(n%i == 0) divisor++;
    }
    return (divisor == 8);
}

int main() {
    string S;
    long long int K;
    int a=0;
    char answer='0';

    cin >> S >> K;
    rep(i, S.length()){
        if(S[i] == '1'){
            a++;
        }else {
            answer = S[i];
            break;
        }
    }
    if(K>a){
        cout << answer << endl;
    }else{
        cout << '1' << endl;
    }
    return 0;
}



Measured memory_bytes: 256
a = input()
def p(s,n):
    for i in range(n//2):
        if s[i] != s[-(i+1)]:
            return 0
    return 1
r = len(a)
if p(a,r) == 1 and p(a[:((r-1)//2)],(r-1)//2) == 1 and p(a[(r+3)//2-1:],r-(r+3)//2+1)== 1:
    print("Yes")
else:
    print("No")
    


Measured memory_bytes: 3060
line = STDIN.gets

head = line[0,2]
tail = line[2,2]


def MM?(a)
  0 < a.to_i and a.to_i < 13
end

if (12 < head.to_i and tail == "00") or (head == "00" and 12 < tail.to_i) or (head == "00" and tail == "00") or (12 < head.to_i and 12 < tail.to_i)
  puts "NA"
end

if MM?(head) and !MM?(tail)
  puts "MMYY"
end

if MM?(head) and MM?(tail)
  puts "AMBIGUOUS"
end

if !MM?(head) and MM?(tail)
  puts "YYMM"
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  cout<<s[0]<<s[1]<<s[2]<<endl;
}

Measured memory_bytes: 3628
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


int MAX_INDEX = 40;

string create(long long val, vector<long long>& max_table, vector<long long>& min_table, vector<long long>& pow_table){
    if(val == 0){
        return "0";
    }

    int index = 0;

    for(; index < MAX_INDEX; ++index){
        if(min_table[index] <= val && val <= max_table[index]){
            break;
        }
    }

    if(index % 2 == 0){
        val -= pow_table[index];
    }
    else{
        val += pow_table[index];
    }

    if(val == 0){
        string ret = "1";
        for(int i = 1; i < index + 1; ++i){
            ret += "0";
        }
        return ret;
    }

    string sub = create(val, max_table, min_table, pow_table);
    string ret = "1";

    for(int i = 1; i < index - sub.size() + 1; ++i){
        ret += "0";
    }

    return ret + sub;
}


int main(){
    long long N;
    cin >> N;

    vector<long long> max_table(MAX_INDEX);
    vector<long long> min_table(MAX_INDEX);
    vector<long long> pow_table(MAX_INDEX);

    pow_table[0] = 1;
    pow_table[1] = 2;

    max_table[0] = 1;
    max_table[1] = -1;

    min_table[0] = 0;
    min_table[1] = -2;

    long long val = 2;

    for(int i = 2; i < MAX_INDEX; ++i){
        val *= 2;
        pow_table[i] = val;

        if(i % 2 == 0){
            max_table[i] = max_table[i - 2] + val;
            min_table[i] = min_table[i - 1] + val;
        }
        else{
            max_table[i] = max_table[i - 1] - val;
            min_table[i] = min_table[i - 2] - val;
        }
    }

    cout << create(N, max_table, min_table, pow_table);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
  return x / gcd(x, y) * y;   // (x * y) / gcd(x, y) だと x*y でオーバフローする可能性あり
}

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

  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll nc = b / c - (a-1) / c;
  ll nd = b / d - (a-1) / d;
  ll cd = lcm(c, d);
  ll ncd = b / cd - (a-1) / cd;

  cout << (b - (a - 1)) - (nc + nd - ncd) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	long long A, B, C, D,temp,temp2;
	cin >> A >> B >> C >> D;
	temp = D;
	temp2 = C;
	long long t = 0;
	while (temp%temp2!=0) {
		t = temp;
		temp = temp2;
		temp2 = t % temp;
	}
	t = D * C / temp2;

	cout << B - A + 1 - (B / D + B / C - B / t)+((A- 1) / D + (A - 1) / C - (A - 1) / t) << endl;

}


Measured memory_bytes: 256
//Δ_E
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 111111;
const int MO = 998244353;
int gcd(int x,int y){
	if(!y)
		return x;
	return gcd(y,x%y);
}
int n,a[N];
int main()
{
	int i,x;
	scanf("%d",&n);
	for(i=0;i<n;i=i+1)
		scanf("%d",a+i);
	sort(a,a+n);
	x=1;
	for(i=0;i<n;i=i+1)
		x=(LL)x*gcd(a[i],i)%MO;
	cout<<x;
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  for(int i=0;i<2;i++){
    if(S.at(i)==S.at(i+1) && S.at(i+1)==S.at(i+2)){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

bool prime(int n) {
    if (n == 2) return true;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

int MAX = 1000000;
vector<bool> p(MAX+1, true);

void eratos() {
    p[0] = p[1] = false;
    for (int i = 2; i * i <= MAX; i++) {
        if (p[i]) {
            for (int j = i + i; j <= MAX; j += i) {
                p[j] = false;
            }
        }
    }
}

int main() {
    int x;
    scanf("%d", &x);
    eratos();
    int i = x;
    while (not p[i]) {
        i++;
    }
    printf("%d\n", i);
}

Measured memory_bytes: 3916
#include<iostream>
#include<queue>
using namespace std;
int main() {
	int h, w;
	cin >> h >> w;
	int dx[4] = { -1,0,0,1 };
	int dy[4] = { 0,-1,1,0 };
	char buf[1005][1005];
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++) {
				cin >> buf[i][j];
			}
		}
		int inf = 1e9;
		int dist[1005][1005];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				dist[i][j] = inf;
			}
		}
		queue<int>v;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (buf[i][j] == '#') {
					dist[i][j] = 0;
					v.push(j); v.push(i);
				}
			}
		}

		while (v.size()) {
			int x = v.front(); v.pop();
			int y = v.front(); v.pop();
			for (int k = 0; k < 4; k++) {
				int a = x + dx[k];
				int b = y + dy[k];
				if (a>=0&&a<w&&b>=0&&b<h&&dist[b][a]==inf&&buf[b][a]=='.') {
					buf[b][a] = '#';
					dist[b][a] = dist[y][x] + 1;
					v.push(a); v.push(b);
				}
			}
		}
		int max = -1e6;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (dist[i][j] > max) {
					max = dist[i][j];
				}
			}
		}
		cout << max << endl;
		return 0;
}

Measured memory_bytes: 13328
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
double x[4], y[4], a, b, c, s, r, S;
int main(void){
    // Your code here!
    for (ll i = 0; i < 3; i++) cin >> x[i] >> y[i];
    a = sqrt(pow(x[0] - x[1], 2) + pow(y[0] - y[1], 2));
    b = sqrt(pow(x[1] - x[2], 2) + pow(y[2] - y[1], 2));
    c = sqrt(pow(x[0] - x[2], 2) + pow(y[0] - y[2], 2));
    s = (a + b + c) / 2;
    S = sqrt(s * (s - a) * (s - b) * (s - c));
    r = S / s;
    double lb = 0, ub = r;
    for (ll i = 0; i < 10000; i++){
        double mid = (lb + ub) / 2;
        if (max(a, max(b, c)) * (1 - mid / r) >= 2 * mid) lb = mid;
        else ub = mid;
    }
    printf("%.10lf\n",lb);
}


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

int main() {
  int n;
  std::cin >> n;
  std::vector<int> cards(n);
  for (int i = 0; i < n; ++i) std::cin >> cards.at(i);

  std::sort(cards.begin(), cards.end());
  int alice = 0;
  int bob = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0) {
      alice += cards.at(i);
      continue;
    } 
    bob += cards.at(i);
  }
  std::cout << std::abs(alice - bob) << std::endl;
}


Measured memory_bytes: 632
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;
#define MAX 30
#define NIL -1

struct Node { int p, l, r;};
struct Node T[MAX];
int n;


void preParse(int u)
{
	if(u == NIL) return;
	cout << " " << u ;
	
	 
	preParse(T[u].l);
	preParse(T[u].r);
	
}

void inParse(int u)
{
	if(u == NIL) return;
	
	inParse(T[u].l);
	cout << " " << u;
	inParse(T[u].r);
	
}

void postParse(int u)
{
	if(u == NIL) return;
	 
	postParse(T[u].l);
	postParse(T[u].r);
	cout <<  " " << u;
}

int main() {
	int i, l, r, root;
	cin >> n;
	for(i = 0; i < n; i++)
	{
		T[i].p = T[i].l = T[i].r = NIL;
	}
	
	for(i = 0; i < n; i++)
	{
		int v;
		cin >> v;
		cin >> l >> r;
		
		T[v].l = l;
		T[v].r = r;
		
		if(l != NIL) T[l].p = v;
		if(r != NIL) T[r].p = v;
	}
	
	for(i = 0; i < n; i++)
	{
		if(T[i].p == NIL) root = i;
	}
	
	cout << "Preorder" << endl;
	preParse(root);
	cout << endl;
	
	cout << "Inorder" << endl;
	inParse(root);
	cout << endl;
	
	cout << "Postorder" << endl;
	postParse(root);
	cout << endl;
	
	
//	system("pause");
	return 0;
}



Measured memory_bytes: 3084
#include<stdio.h>
#define N 100000

int partition(int *,int, int);

int main(){
  int i,j,n;
  int A[N];

  scanf("%d",&n);

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

  j = partition(A,0,n - 1);

  for(i = 0;i < n;i++){
    
    if(i) printf(" ");
    if(i == j)printf("[");
      printf("%d",A[i]);
    if(i == j)printf("]");
    
  }  

  printf("\n");

  return 0;
}

int partition(int A[],int p,int q){
  int x,i,j,t;
  x = A[q];
  i = p - 1;

  for(j = p;j < q ;j++){
    if(A[j] <= x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i + 1];
  A[i + 1] = A[q];
  A[q] = t;
  return i + 1;
}


Measured memory_bytes: 2112
#include "bits/stdc++.h"

using namespace std;

typedef long double db;
typedef long long ll;
typedef pair<db, db> pd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define printlist(l) for(auto x: l) cout << x << ' '; cout << endl;

#define mod 1000000007
#define maxn 300005
#define maxl 62

ll n, x, y, m, q, t, k, a[maxn];
ll cnt[maxl];
ll pow2[maxl];

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

	pow2[0] = 1;
	for (int i = 1; i < maxl; ++i) {
		pow2[i] = (pow2[i - 1] * 2) % mod;
	}

	ll ans = 0;
	cin >> n;
	for (ll i = 0; i < n; ++i) {
		cin >> a[i];
		for (ll j = 0; j < maxl; ++j) {
			cnt[j] += (a[i] / (ll(1) << j)) % 2;
		}
	}

	for (int i = 0; i < maxl; ++i) {
		x = cnt[i];
		y = n - x;
		ll tmp = (x * y) % mod;
		tmp = (tmp * pow2[i]) % mod;
		ans = (ans + tmp) % mod;
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 2560
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

#define MAX 101
struct node {
    int v, d, no;
    node(int v, int d, int no):v(v),d(d),no(no){}
    bool operator<(const node &n) const { return d > n.d; }
};
struct edge { int to, d, no ; edge(int ti, int di, int noi){to = ti; d = di; no = noi;} };
int V;
vector<edge> G[MAX];
int dist[MAX]; // shortest distance
int pre[MAX]; // previous edge

void dijkstra(int s) {
    REP(i,MAX) { dist[i] = -1; pre[i] = -1; }
    priority_queue<node> que;
    que.push(node(s, 0, -1));
    while(!que.empty()){
        int v = que.top().v, d = que.top().d, no = que.top().no;
        que.pop();
        if(dist[v] >= 0 and dist[v] <= d) continue;
        dist[v] = d;
        pre[v] = no;
        for(auto j : G[v]) que.push(node(j.to, d+j.d, j.no));
    }
}

int used[1001],n,m,a,b,c;

int main(){
    I(n); I(m);
    REP(i,m) used[i] = 1;
    REP(i,m){
        I(a); I(b); I(c);
        a--; b--;
        G[a].pb( edge (b,c,i) );
        G[b].pb( edge (a,c,i) );
    }
    REP(i,n){
        dijkstra(i);
        REP(j,n){
            if ( pre[j] >= 0) used[ pre[j] ] = 0;
        }
    }

    int ret = 0;
    REP(i,m) ret += used[i];
    cout << ret << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<pair<int, int>> v;
    ll sa = 0, sb = 0;
    for (auto &&item : a) {
        scanf("%d", &item);
        sa += item;
    }
    for (auto &&i : b) {
        scanf("%d", &i);
        sb += i;
    }
    if(sb > sa){
        puts("-1");
        return 0;
    }
    v.reserve(n);
    for (int i = 0; i < n; ++i) {
        v.emplace_back(a[i]-b[i], i);
    }
    ll k = sa-sb;
    int ans = 0;
    sort(v.begin(), v.end());
    for (int i = 0; i < n; ++i) {
        if(v[i].first < 0) continue;
        int p, q;
        tie(p, q) = v[i];
        if(k >= p) {
            ans++;
            k -= p;
        }
    }
    cout << n-ans << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	string a;
	cin >> a;
	if (a[0] == a[1] || a[1] == a[2] || a[2] == a[3]) cout << "Bad\n";
	else cout << "Good\n";
}


Measured memory_bytes: 256
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  while (true) {
    auto rd = readln.split;
    auto a = rd[0].to!int, op = rd[1], b = rd[2].to!int;

    if (op == "?") break;

    switch (op) {
    case "+": writeln(a + b); break;
    case "-": writeln(a - b); break;
    case "*": writeln(a * b); break;
    case "/": writeln(a / b); break;
    default: assert(0);
    }
  }
}

Measured memory_bytes: 2484
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define SIZE(x) ((int)(x).size())
#define UQ(v) v.erase(unique(v,begin(),v,end()),v.end());
ll INF = 1LL <<30;
#define pb push_back 
int dxy4[5] = { 0,1,0,-1,0 };
int dxy8[9] = { 0,1,1,0,-1,1,-1,-1,0 };
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
ll mod7 = 1000000007;
ll mod9 = 1000000009;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i,x,n) for(int i=x;i<n;++i)
//vector< vector<int> > v (max1, vector<in t>(max2) );

//bool f[51][51];
bool so[55];
int sosu(int num) {
	if (num <= 2)return 0;
	if (num % 2 == 0)return 0;
	int x = (int)sqrt(num);
	FOR(i,3, x+1) {
		if (num%i==0)return 0;
	}
	return 1;
}

int main() {
	vector<int>ans;
	int n,x;
	cin >> n;
	rep(i, 30000) {
		if(i%10 == 1){	
			x = sosu(i);
			if (x) {
				ans.pb(i);
			}
		}
	}
	rep(i, n)cout << ans[i] << " ";
	cout << endl;
	int nn;
	cin >> nn;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N,D;
  cin >> N >> D;
  if(N % (2 * D + 1) == 0){
  cout << N / (2 * D + 1) << endl;
  }else{
    cout << N / (2 * D + 1) + 1 << endl;
  }
 
}

Measured memory_bytes: 3604
// atcoder/abc148/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  while (cin >> a >> b) {
    cout << (1 + 2 + 3) - a - b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define range1(i,a,b,c) for(int i = int(a);i <= int(b);i+=int(c))
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define sz(v) ((int)((v).size()))
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int a[N];
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n;
    scanf("%d",&n);
    lp(i,n){
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    reverse(a,a+n);
    ll ans = (ll)a[0];
    int take = n-2;
    for(int i=1;i<n;i++){
        int mn = min(take,2);
        ans+=(ll)a[i]*mn;
        take-=mn;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 4600
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



int W, H, w, h, x, y;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> W >> H >> w >> h >> x >> y;

    int sx = max(-W / 2, x - w / 2);
    int tx = min(W / 2, x + w / 2);
    int sy = max(-H / 2, y - h / 2);
    int ty = min(H / 2, y + h / 2);

    double xx = 1.0 * (sx + tx) / 2;
    double yy = 1.0 * (sy + ty) / 2;

    double ans = 1.0 * yy / xx;
    printf("%.10f\n", ans);
}



Measured memory_bytes: 3248
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
map<int,int>mm;
int row[maxn],col[maxn];
int rowt[maxn],colt[maxn];
struct node{
    int num;
    int u;
    bool operator<(const node & t)const{
        return row[u]<row[t.u];
    }
};
struct node2{
    int num;
    int u;
    bool operator<(const node & t)const{
        return col[u]<col[t.u];
    }
};
int main()
{
    int maxrow=0;
    int numrow=0;
    int maxcol=0;
    int numcol=0;
    int h,w,m;
    cin >> h >> w >> m;
    int u,v;
    vector<pair<int,int>>vv;
    for(int i=0;i<m;i++){
        cin >> u >> v;
        vv.push_back({u-1,v-1});
        row[u-1]++;
        col[v-1]++;
    }
    for(int i=0;i<h;i++){
        rowt[i]=row[i];
    }
    for(int i=0;i<w;i++){
        colt[i]=col[i];
    }
    sort(row,row+h);
    sort(col,col+w);
    int maxnum=row[h-1]+col[w-1];
    int num1 = lower_bound(row,row+h,row[h-1])-row;
    int num2 = lower_bound(col,col+w,col[w-1])-col;
    long long cnt = (h-num1)*(w-num2);
    //cout << cnt << endl;
    for(auto i :vv){
        //cout << i.first << " " << i.second <<" " << rowt[i.first] << " " << colt[i.second] << endl;
        if(rowt[i.first]+colt[i.second]==maxnum){
            cnt--;
        }
    }
    if(cnt)
        cout<<maxnum <<endl;
    else
        cout << maxnum-1 <<endl;
    return 0;
}


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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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 (b<a) { a=b; return 1; } return 0; }
 

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
    int N;
    cin >> N;

    vector<ll> l(N);
    vector<ll> r(N);
    fill(l.begin(), l.end(), 0);
    fill(r.begin(), r.end(), 0);

    vector<ll> A(N);
    rep(i, N)
    {
        ll a;
        cin >> a;
        A[i]=a;
        if(i-A[i]>0)
        {
            l[i-A[i]]++;
        }
        if(i+A[i]<N)
        {
            r[i+A[i]]++;
        }
    }

    ll ans=0;
    rep(i, N)
    {
        ans+=l[i]*r[i];
    }

    cout << ans << endl;
 

    return 0;
}



Measured memory_bytes: 7972
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize,
        d: usize,
    }
    let left_v = a + b;
    let right_v = c + d;
    if left_v > right_v {
        println!("Left");
    } else if left_v == right_v {
        println!("Balanced");
    } else {
        println!("Right");
    }
}

Measured memory_bytes: 4352
import sys
input = sys.stdin.readline

# C - management
N = int(input())
A = list(map(int, input().split()))
bosses = dict()

for a in A:
  if a in bosses.keys():
	  bosses[a] += 1
  else:
    bosses[a] = 1

for i in range(1, N + 1):
    if i in bosses.keys():
	    print(bosses[i])
	   
    else:
      print(0)

Measured memory_bytes: 34896
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int x[100],y[100];
LL h[100];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N;
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> x[i] >> y[i] >> h[i];
	}
	if(h[0] == 0){
		for(int i=1; i<N; i++){
			if(h[i] > 0){
				swap(h[0],h[i]);
				swap(x[0],x[i]);
				swap(y[0],y[i]);
				break;
			}
		}
	}

	for(int X=0; X<=100; X++){
		for(int Y=0; Y<=100; Y++){
			LL H = h[0] + abs(X-x[0]) + abs(Y-y[0]);
			for(int i=1; i<N; i++){
				if(max(H - abs(X-x[i]) - abs(Y-y[i]), (LL)0) != h[i]) break;
				if(i == N-1){
					cout << X << " " << Y << " " << H << endl;
					return 0;
				}
			}
		}
	}

	return 1;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
typedef long long int ll;
bool dp[100001][2];
ll n,k,a[500];
int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i = 0 ; i < n ; i++)scanf("%lld",&a[i]);

    for(int i = 0; i <= k ; i++)
    {
        for(int j = 0; j < n; j ++)
        {
            if(i>=a[j])
            {
                dp[i][1] |=!(dp[i-a[j]][0]);
                dp[i][0] |=!(dp[i-a[j]][1]);
            }

        }
    }
    if(!dp[k][1])printf("Second\n");
    else printf("First\n");
}



Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#define FOR(variable,a,b) for(variable=(a);variable<(b);variable++)

void transformAlpha(char* targetText, int count) {
    // generate carsar from [targetText] shift with [shift]
    // [targetText] and [targetText] has [count] of char element
    int i;
    int index;

    // shift char
    FOR(i, 0, count) {
        if('A' <= targetText[i] && targetText[i] <= 'Z') {
            index = (targetText[i] - 'A') % 26;
            targetText[i] = 'a' + index;
        } else if('a' <= targetText[i] && targetText[i] <= 'z') {
            index = (targetText[i] - 'a') % 26;
            targetText[i] = 'A' + index;
        }
    }
    return;
}

int main(){
    // import phase
    char rawText[256];

    gets(rawText);
    
    // calclate phase
    transformAlpha(rawText, strlen(rawText));
    
    // output phase
    printf("%s\n", rawText);

    return 0;
}

Measured memory_bytes: 520
// finish date: 2018/01/14
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int i=a;i<b;i++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 1000000000

vector<vector<int>> b, c, field;


int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}

int factorial(int n) {
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans = ans * i;
    }
    return ans;
}


int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    string str = "";
    rep(i, tx - sx) str += "R";
    rep(i, ty - sy) str += "U";
    rep(i, tx - sx) str += "L";
    rep(i, ty - sy) str += "D";

    str += "D";
    rep(i, tx - sx + 1) str += "R";
    rep(i, ty - sy + 1) str += "U";
    str += "LU";
    rep(i, tx - sx + 1) str += "L";
    rep(i, ty - sy+1) str += "D";
    str += "R";

    cout << str << endl;
}


Measured memory_bytes: 256
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int X; cin>>X;
    vector<vector<bool>> dp(10,vector<bool>(X+1,false));
    FOR(i,1,7){
        int res=99+i;
        dp[i][0]=true;
        FOR(x,1,X+1){
            if(dp[i-1][x] || (x-res>=0 && dp[i][x-res])) dp[i][x]=true;
            else                                         dp[i][x]=false;
        }
    }
    if(dp[6][X]) cout<<1<<endl;
    else         cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static class Point {
		double x;
		double y;
		public Point(double x, double y) {
			this.x = x;
			this.y = y;
		}
		public String toString() {
			return String.format("%.8f %.8f", x, y);
		}
	}
	
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		reader.close();		
		getKochCurve(n, new Point(0, 0), new Point(100, 0));
	}

	private static void getKochCurve(int n, Point start, Point end) {
		System.out.println(start);
		getKochCurve(0, n, start, end);
		System.out.println(end);
	}

	private static void getKochCurve(int i, int n, Point start, Point end) {		
		if (i < n) {
			Point[] temp = divide(start, end);
			Point firstPoint = temp[0];
			Point thirdPoint = temp[1];
			Point secondPoint = getSecondPoint(start, end, firstPoint, thirdPoint);
			getKochCurve(i + 1, n, start, firstPoint);
			System.out.println(firstPoint);
			getKochCurve(i + 1, n, firstPoint, secondPoint);
			System.out.println(secondPoint);
			getKochCurve(i + 1, n, secondPoint, thirdPoint);
			System.out.println(thirdPoint);
			getKochCurve(i + 1, n, thirdPoint, end);
		}
	}

	private static Point[] divide(Point start, Point end) {
		
		double deltaX = end.x - start.x;
		double deltaY = end.y - start.y;

		deltaX = deltaX / 3;
		deltaY = deltaY / 3;		
		
		Point point1 = new Point(start.x + deltaX, start.y + deltaY);
		Point point2 = new Point(end.x - deltaX, end.y - deltaY);

		Point[] points = new Point[2];
		points[0] = point1;
		points[1] = point2;
		return points;
	}

	private static Point getSecondPoint(Point start, Point end, Point second, Point third) {
		double deltaX = third.x - second.x;
		double deltaY = third.y - second.y;
		double len = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));		
		double x;
		double y;		
		if (deltaY == 0) {
			x = start.x + (end.x - start.x) / 2;
			if (start.x < end.x) {
				y = second.y + Math.sqrt((Math.pow(len, 2) - Math.pow(len / 2.0, 2)));
			} else {
				y = second.y - Math.sqrt((Math.pow(len, 2) - Math.pow(len / 2.0, 2)));
			}
		} else if (start.x < end.x && start.y < end.y) {
			x = start.x;
			y = third.y;
		} else if (start.x < end.x && start.y > end.y) {
			x = end.x;
			y = second.y;
		} else if (start.x > end.x && start.y < end.y) {
			x = end.x;
			y = second.y;
		} else {
			x = start.x;
			y = third.y;
		}
		return new Point(x, y);
	}
}



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

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int n,t,a;
    cin>>n>>t>>a;
    double mint = 1000000.0;
    int ind = -1;
    for(int i = 0;i < n;i++) {
        double x;
        cin>>x;
        double temp = t - x * 0.006;
        if(mint > abs(temp - (double)a)) {
            mint = abs(temp - (double)a);
            ind = i;
        }
    }
    cout<<ind+1;
}

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

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>	    P;
#define fi                  first
#define se                  second

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	long double a, b, c;
	cin >> a >> b >> c;

	long double eps = 1.0E-14;
	if (sqrt(a) + sqrt(b) + eps < sqrt(c)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

class UnionFind {
public:
	vector <ll> par; // 各元の親を表す配列
	vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool isSame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}
};

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

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

	vector<ll> a(m), b(m);

	rep(i, m)
	{
		cin >> a[i] >> b[i];
	}

	UnionFind tree(n);
	vector<ll> ans(m);
	ans[m - 1] = n * (n - 1);
	ans[m - 1] /= 2;

	for (int i = m - 2; i >= 0; i--)
	{
		if (!tree.isSame(a[i+1]-1, b[i+1]-1))
		{
			ans[i] = ans[i + 1] - tree.size(a[i+1]-1) * tree.size(b[i+1]-1);
			tree.merge(a[i+1]-1, b[i+1]-1);
		}
		else
		{
			ans[i] = ans[i + 1];
		}

	}
	rep(i, m)
	{
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 5248
//Bismillahir rahmanir Rahim
//sajeedreefy
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long int n,x,t,i;
    cin >> n >> x >> t;
    if(n<=x)
    {
        cout << t << "\n";
        return 0;
    }
    i=1;
    while(1)
    {
       if(n<=x*i)
       {
           t=t*i;
           break;
       }
       else
       {
           i++;
       }
    }
    cout << t << "\n";
    return 0;
}


Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
 
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
 
#define PB(a) push_back(a)
#define PF(a) pop_front(a)
 
#define MP(a,b) make_pair(a,b)
 
#define FS first
#define SE second
 
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
 
//------show vector---------
template <typename T>
void showV(vector < T > a){
  EACH(i,a){
    cerr << *i << ',';
  }  
  cerr << endl;
}
 
//------show matrix---------
template <typename T>
void showVV(vector < vector < T > > a){
  EACH(i,a){
    showV(*i);
  }  
}
//grobal var
//------------------------------------------
LL dp[2000][2000];
vector< int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  return (ret);
}

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  int N;
  while(cin >> N){
    str ans = "YES";
    VI p(N);
    REP(i,N){
      cin >> p[i];
    }
    int cnt = 0;
    REP(i,N){
      if(p[i]!=i+1) cnt++;
    }
    if(cnt>2) ans = "NO";
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int main()
{
    int n,in;
    vector<int> x;
    cin >> n;

    REP(i,n){
        cin >> in;
        if(in == i+1) x.push_back(1);
        else x.push_back(0);
    }

    int cnt = 0;
    REP(i,n){
        if(x[i] == 1){
            x[i]--;x[i+1]--;
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

struct shop{
	ll a;int b;
};

bool operator<(const shop& x,const shop& y){
	return x.a<y.a;
}

int main() {
	int n,m;
	cin>>n>>m;
	shop s[alength];
	fori(n){cin>>s[i].a>>s[i].b;}
	sort(s,s+n);
	ll money=0;
	fori(n){
		if(m<=s[i].b){
			money+=s[i].a*m;
			cout<<money;
			return 0;
		}else{
			money+=s[i].a*s[i].b;
			m-=s[i].b;
		}
	}
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, MAX, L, SUM;

int main(){
	cin >> N;
	for (int i = 0; i != N; ++i) {
		cin >> L;
		MAX = max(MAX, L);
		SUM += L;
	}
	if (MAX < SUM - MAX)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int w[3];
int k[3];
int main()
{
  int i,j;
  for(i=0;i<10;i++){
    scanf("%d",&j);
    if(w[0] < j) {
      w[2] = w[1]; w[1] = w[0]; w[0] = j;
    }else if(w[1] < j){
      w[2] = w[1]; w[1] = j;
    }else if(w[2] < j){
      w[2] = j;
    }
  }
  for(i=0;i<10;i++){
    scanf("%d",&j);
    if(k[0] < j) {
      k[2] = k[1]; k[1] = k[0]; k[0] = j;
    }else if(k[1] < j){
      k[2] = k[1]; k[1] = j;
    }else if(k[2] < j){
      k[2] = j;
    }
  }
  printf("%d %d\n",w[0]+w[1]+w[2],k[0]+k[1]+k[2]);
  return 0;
}

Measured memory_bytes: 0
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion

int n, m, q;
vector<int> a(55), b(55), c(55), d(55);
int res = 0;

void dfs(int cnt, int now, vector<int> &v)
{
	if (cnt == n)
	{
		int tmp = 0;
		rep(i, q)
		{
			if (v[b[i]] - v[a[i]] == c[i])tmp += d[i];
		}
		chmax(res, tmp);
		return;
	}
	for (int i = now; i <= m; ++i)
	{
		v[cnt] = i;
		dfs(cnt + 1, i, v);
	}
}


int main()
{
	cin >> n >> m >> q;
	rep(i, q)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		--a[i];
		--b[i];
	}
	for (int i = 1; i <= m; ++i)
	{
		vector<int> v(n);
		dfs(0, i, v);
	}
	cout << res << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// DAME:
ll pmid(ll mid, ll tmp){
    // 標準だと-2/3 -> 0となってしまう
    if (mid<0 and mid%tmp!=0) return mid/tmp-1;
    return mid/tmp;
}

ll mmid(ll mid, ll tmp){
    if (mid<0 and mid%tmp!=0) return mid/tmp+1;
    return mid/tmp;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll inf = ll(1e18)+1;
    ll left = -inf, right = inf;
    // mid以下の数を求める
    while(left+1 < right){
        ll mid = (left+right)/2;
        ll cnt = 0;
        rep(i, n){
            ll tmp = a[i];
            if (tmp>0){
                auto iter = upper_bound(a.begin(), a.end(), pmid(mid, tmp)); 
                cnt += iter - a.begin();
            }else if (tmp==0){
                if (mid>=0) cnt+=n;
            }else{
                auto iter = lower_bound(a.begin(), a.end(), mmid(mid, tmp));
                cnt += a.end() - iter;
            }
            if (tmp*tmp <= mid) cnt--;
        }
        cnt /= 2;
        if (cnt < k){
            left = mid;
        }else{
            right = mid;
        }
    }

    cout << right << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
using  namespace  std;
int  n,m,ans;
int  main()
{
	scanf("%d%d",&n,&m);
	for(int  i=1;i<=n;i++)
	{
		int  x;scanf("%d",&x);
		if(x>=m)ans++;
	}
	printf("%d\n",ans);
	return  0;
}

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

int main(){
  int N, Y;
  cin >> N >> Y;
  int res10000 = -1, res5000 = -1, res1000 = -1;
  for (int a = 0; a <= N; a++) {
    for (int b = 0; b + a <= N; b++) {
      int c = N - a - b;
      int total = 10000*a + 5000*b + 1000*c;
      if (total == Y) {
        res10000 = a;
        res5000 = b;
        res1000 = c;
      }
    }
  }

  cout << res10000 << ' ' << res5000 << ' ' << res1000 << endl;

  return 0;
}


Measured memory_bytes: 256