akhauriyash/Code-Regression huggingface dataset:
#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;

void nrm(pair<int, int> &a) {
	if (a.first > a.second) {
		swap(a.first, a.second);
	}
}

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

	int n;
	cin >> n;
	vector<vector<int>> a(n);
	for (int i = 0; i < n; i++) {
		a[i].resize(n - 1);
		for (auto &t : a[i]) {
			cin >> t;
			t--;
		}
		reverse(a[i].begin(), a[i].end());
	}
	map<pair<int, int>, int> cnt;
	set<pair<int, int>> bc[3];
	auto mk = [&](int i) {
		pair<int, int> v = {i, a[i].back()};
		nrm(v);
		int vw = cnt[v];
		if (vw == 1) bc[vw].erase(v);
		cnt[v]++;
		bc[cnt[v]].insert(v);
	};
	for (int i = 0; i < n; i++) {
		mk(i);
	}
	int ans = 0;
	while (true) {
		vector<pair<int, int>> tk;
		for (auto v : bc[2]) tk.push_back(v);
		if (tk.empty()) {
			break;
		}
		bc[2].clear();
		for (auto v : tk) {
			int i = v.first;
			int j = v.second;
			a[i].pop_back();
			a[j].pop_back();
			if (!a[i].empty()){
				mk(i);
			}
			if (!a[j].empty()) {
				mk(j);
			}
		}
		ans++;
	}
	for (int i = 0; i < n; i++) {
		if (!a[i].empty()) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 35456
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          int cnt = Integer.parseInt(br.readLine());
          String[] sarray = br.readLine().split(" ",cnt);
          
          String str;
          StringBuilder sb = new StringBuilder();
          
          //????????????
          for ( int i = 0 ; i < cnt ; i++){
            int j = i;
            while (j > 0){
                if( Integer.parseInt(sarray[j]) < Integer.parseInt(sarray[j - 1]) ){
                    str = sarray[j];
                    sarray[j] = sarray[j - 1];
                    sarray[j - 1] = str;
                }
                j--;
            }
            
            for ( int n = 0 ; n < cnt ; n++){
                if ( n > 0 ){
                    sb = sb.append(" ");
                }
                sb = sb.append(sarray[n]);
            }
            System.out.println(sb);
            sb.setLength(0);
          }
    }
};


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

int main() {
int B = 0;
  string A; 
cin >> A;

  for (int i = 0; i < 4; i++) {
    if ( A.at (i) == '+' ){
B++;
  }
else {
B--;
}
}
cout << B << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    string s;
    getline(cin, s);
    transform(ALL(s), s.begin(), ::toupper);
    OP(s)
    return 0;
}


Measured memory_bytes: 3176
#include "bits/stdc++.h"
using namespace std;

int main(){
	string s;
	cin>>s;
	int t,r;
	cin>>t>>r;
	vector<int> x;
	vector<int> y;
	vector<vector<bool> > xdp(8000,vector<bool>(20000,false));
	vector<vector<bool> > ydp(8000,vector<bool>(20000,false));
	vector<int> a;
	
	int p=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='F'){
			p++;
		}else{
			a.push_back(p);
			p=0;
		}
	}
	a.push_back(p);
	xdp[1][10000+a[0]]=true;
	ydp[0][10000]=true;
	
	for(int i=0;i<a.size();i++){
		if(i%2==0){
			x.push_back(a[i]);
		}else{
			y.push_back(a[i]);
		}
	}
	
	for(int i=1;i<x.size();i++){
		for(int j=0;j<20000;j++){
			if(xdp[i][j]==true){
				xdp[i+1][j+x[i]]=true;
				xdp[i+1][j-x[i]]=true;
			}
		}
	}
	
	for(int i=0;i<y.size();i++){
		for(int j=0;j<20000;j++){
			if(ydp[i][j]==true){
				ydp[i+1][j+y[i]]=true;
				ydp[i+1][j-y[i]]=true;
			}
		}
	}
	
	//for(int i=7990;i<8010;i++)cout<<i<<" "<<xdp[i]<<endl;;
	//cout<<endl;
	//for(int i=7990;i<8010;i++)cout<<i<<" "<<ydp[i]<<endl;;
	//cout<<endl;
	
	
	if(xdp[x.size()][t+10000]==true&&ydp[y.size()][r+10000]==true){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 42240
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    int n;
    cin >> n;
    int tmp = 1e7;
    int cnt = 0;
    rep(i,n){
        int p;
        cin >> p;
        if(p < tmp){
            cnt++;
            tmp = p;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
from math import factorial
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
P_0 = list(range(1, N + 1))
Q_0 = list(range(1, N + 1))
num_P = 0
num_Q = 0
for i in range(N):
  for j in range(N):
    if P[i] == P_0[j]:
      num_P += j * factorial(N - 1 - i)
      P_0.remove(P_0[j])
      break
for i in range(N):
  for j in range(N):
    if Q[i] == Q_0[j]:
      num_Q += j * factorial(N - 1 - i)
      Q_0.remove(Q_0[j])
      break
print(abs(num_Q - num_P))


Measured memory_bytes: 3064
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int N, K;
Vec< Vec< int > > adj;
lint c[100005];
const lint MOD = (lint)1e9 + 7;

void dfs(int v, int p) {
	lint r = 0;
	for (int u : adj[v]) {
		if (u == p) continue;
		c[u] = (K - 2) - r;
		dfs(u, v);
		++r;
	}
}

int main() {
	cin >> N >> K;
	adj.assign(N, Vec< int >());
	for_(i,0,N-1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	c[0] = K;
	lint r = 1;
	for (int v : adj[0]) {
		c[v] = K - r;
		dfs(v, 0);
		++r;
	}
	
	lint ans = 1;
	for_(i,0,N) ans = (ans * c[i]) % MOD;
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

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

#define fo(i, x, y) for (int i = x; i <= y; ++i)
#define fd(i, x, y) for (int i = x; i >= y; --i)

const int maxn = 2e5 + 5;

int n, m;
int fa[maxn], siz[maxn];

int getint()
{
	char ch;
	int res = 0, p;
	while (!isdigit(ch = getchar()) && (ch ^ '-'));
	p = ch == '-'? ch = getchar(), -1 : 1;
	while (isdigit(ch))
		res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
	return res * p;
}

int getfa(int x)
{
	return x == fa[x]? x : fa[x] = getfa(fa[x]);
}

void merge(int u, int v)
{
	int fu = getfa(u), fv = getfa(v);
	if (fu == fv) return;
	if (siz[fu] < siz[fv]) fa[fu] = fv, siz[fv] += siz[fu];
		else fa[fv] = fu, siz[fu] += siz[fv];
}

int main()
{
	n = getint(); m = getint();
	fo(i, 1, n) fa[i] = i, siz[i] = 1;
	fo(i, 1, m)
	{
		int u, v;
		u = getint(); v = getint();
		merge(u, v);
	}
	int ans = 0;
	fo(i, 1, n)
		if (i == fa[i]) ans = max(ans, siz[i]);
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

int h[100100];
int n, k;
int dp[100100];
const int INF = (int)1e18;

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> h[i];
	for (int i = 1; i <= n; i++)
		dp[i] = INF;
	dp[1] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i - j >= 1)
			dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i]);
			else break;
		}
	}
	cout << dp[n];
}

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

// DP (simple rec + memo) version
int dp[21][11][156];
void init(){
  // not yet computed
  for(int i = 0; i < 21; i++) {
    for(int j = 0; j < 11; j++) {
      for(int k = 0; k < 156; k++) {
        dp[i][j][k] = -1;
      }
    }
  }
}
int rec(int n, int k, int s)
{
  if(s < 0) return 0;  // no answer
  if(k > n) return 0;  // less elements remain
  if(k == 0) return s == 0 ? 1 : 0; // 0 by 0?
  if(dp[n][k][s] < 0) {
    // using n, or not using n
    dp[n][k][s] = rec(n-1, k-1, s-n) + rec(n-1, k, s);
  }
  return dp[n][k][s];
}
int main(int argc, char *argv[])
{
  init();
  for(;;) {
    int n, k, s;
    cin >> n >> k >> s;
    if(n == 0 && k == 0 && s == 0) break;
    int cnt = 0;
    if(k <= n) {
      cnt = rec(n, k, s);
    }
    cout << cnt << endl;
  }
  return 0;
}



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

struct Node{
  int key;
  struct Node *back, *next;
};

struct Node *nil;
 
void initialize(void);
void insert(int);
struct Node* listsearch(int);
void delete_n(struct Node *t);
void delete_f(void);
void delete_l(void);
void delete_k(int);
  
int main(){

  struct Node *now;
  int n, i, key;
  char command[12];
  
  scanf("%d",&n);
  initialize();
  for(i=0;i<n;i++){
    scanf("%s %d",command,&key);
    if(command[0]=='i') insert(key);
    else if(command[0]=='d'){
      if(strlen(command)==6) delete_k(key);
      if(strlen(command)>6){
        if(command[6]=='F') delete_f();
        else if(command[6]=='L') delete_l();
      }
    }
  }
  
  now=nil->next;
  i=0;

  while(1){
    if(now==nil) break;
    if(i>0) printf(" ");
    i++;
    printf("%d",now->key);
    now=now->next;
  }
  printf("\n");

  return 0;
}

void initialize(){
  nil=(struct Node *)malloc(sizeof(struct Node));
  nil->next=nil;
  nil->back=nil;
}

void insert(int key){
  
  struct Node *a;
  
  a=(struct Node *)malloc(sizeof(struct Node));
  a->key=key;
  a->next=nil->next;
  nil->next->back=a;
  nil->next=a;
  a->back=nil;
}

struct Node* listsearch(int key){
  
  struct Node *now;
  now=nil->next;
  while (now!=nil && now->key!=key){
    now=now->next;
  }
  return now;
}

void delete_n(struct Node *d){
  
  if(d==nil) return;
  d->back->next=d->next;
  d->next->back=d->back;
  free(d);
}

void delete_f(){
 
  delete_n(nil->next);
}

void delete_l(){

  delete_n(nil->back);
}

void delete_k(int key){

  delete_n(listsearch(key));
}






Measured memory_bytes: 32952
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

A, B, C, D = map(int, input().split())
CD = lcm(C, D)
print((B-A+1) - (B // C - (A-1) // C) - (B // D - (A-1) // D) + (B // CD - (A-1) // CD))

Measured memory_bytes: 3060
#include <cstdio>
#include <stack>
#include <vector>


int main(){
    char ch;
    std::stack<int> pos;
    std::stack<std::pair<int, int>> result;
    int sum = 0;
    for(int i = 0; std::scanf("%c", &ch) != EOF; ++i){
        if(ch == '\\'){
            pos.push(i);
        } else if(ch == '/'){
            if(!pos.empty()){
                int j = pos.top();
                pos.pop();
                int res = (i - j);
                sum += res;
                while(result.size() > 0 && result.top().first > j){
                    res += result.top().second;
                    result.pop();
                }
                result.push(std::make_pair(j, res));
            }
        }
    }

    std::vector<int> ans;
    while(!result.empty()){
        ans.push_back(result.top().second);
        result.pop();
    }
    std::printf("%d\n", sum);
    std::printf("%lu", ans.size());
    for(auto iter = ans.rbegin(); iter != ans.rend(); ++iter){
        std::printf(" %d", *iter);
    }
    std::printf("\n");

    return 0;
}



Measured memory_bytes: 2800
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <vector>

using namespace std;

#define ll long long
// #define rep(i, n) for (ll i = 1; i < (n+1); i++)
// #define rep(j, n) for (ll j = 1; j < (n+1); j++)
// #define rep(k, n) for (ll k = 1; k < (n+1); k++)


// int main()
// {
//     ll K;
//     int a = 100;
//     cin >> K;
//     int year = 0;
//     while (a < K) {
//         a = a * 1.01;
//         // a = float(a);
//         // cout << a << endl;
//         year++;
//     }
//     cout << year << endl;
// }


int main()
{
    int K;
    cin >> K;
    int A, B;
    int C;
    int ans;
    cin >> A >> B;
    C = B / K;
    int d = 0;
    for (ll i = 1; i <= C; i++) {
        ans = K * i;
        if (A <= ans && ans <= B) {
            cout << "OK" << endl;
            d++;
            break;
        }
    }
    if (d == 0) {
        cout << "NG" << endl;
    }
}

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

//関数
//main関数
int main() {
    
    
    //入力
    long N;
    cin>>N;
    
    vector<long> a(N),b(N),c(N);
    for(int i=0;i<N;i++){
        cin>>a.at(i)>>b.at(i)>>c.at(i);
    }
    
    //計算
    vector<long> A(N),B(N),C(N);
    A.at(0)=a.at(0);
    B.at(0)=b.at(0);
    C.at(0)=c.at(0);
    for(int i=1;i<N;i++){
        A.at(i)=max(B.at(i-1),C.at(i-1))+a.at(i);
        B.at(i)=max(C.at(i-1),A.at(i-1))+b.at(i);
        C.at(i)=max(A.at(i-1),B.at(i-1))+c.at(i);
    }
    
    //出力
    cout<<max(max(A.at(N-1),B.at(N-1)),C.at(N-1))<<endl;
}




Measured memory_bytes: 4992
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;

template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int n;
int rt[200005],sizee[200005];
int arr[200005];
void initialize()
{
    for(int i=0;i<n+2;i++)
    {
        rt[i]=i;
        sizee[i]=1;
    }
}
int root(int i)
{
    while(rt[i]!= i)
    {
        rt[i]=rt[rt[i]]; 
        i=rt[i];
    }
    return i;
}
void merge(int A,int B)
{
    int root_A = root(A);
    int root_B = root(B);
    if(rt[root_A]==rt[root_B])
        return;
    if(sizee[root_A] < sizee[root_B])
    {
        rt[root_A] = rt[root_B];
        sizee[root_B] += sizee[root_A];
    }
    else
    {
        rt[root_B] = rt[root_A];
        sizee[root_A] += sizee[root_B];
    }
}

int32_t main()
{
    IOS;
    int m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    initialize();
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        merge(a,b);
    }
    set<int>roots;
    vector<int> values[n+2]={};
    for(int i=0;i<n;i++)
    {
        int a=root(i);
        roots.insert(a);
        values[a].push_back(arr[i]);
    }
    int components=roots.size();
    if(2*(components-1)>n)
        return cout<<"Impossible",0;
    else if(components==1)
        return cout<<0,0;

    for(int i=0;i<n+1;i++)
        sort(values[i].begin(),values[i].end());
    int ans=0;
    multiset<int>ms;
    for(int i:roots)
    {
        ans+=values[i][0];
        for(int j=1;j<values[i].size();j++)
            ms.insert(values[i][j]);
    }
    int left=2*(components-1)-components;
    while(left--)
    {
        int get=*ms.begin();
        ans+=get;
        ms.erase(ms.find(get));
    }
    cout<<ans;
}

Measured memory_bytes: 16140
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	std::string S;
	in >> N >> S;

	LL ans = 114514810;
	std::vector<LL>imos(N + 1);
	rep(i, N) imos[i + 1] = imos[i] + (S[i] == '#' ? 1 : 0);
	for (LL i = 0; i <= N; ++i)
	{
		LL black = imos[i];
		LL white = (N - i) - (imos[N] - imos[i]);
		LL res = black + white;
		ans = std::min(ans, res);
	}

	out << ans << std::endl;
}


Measured memory_bytes: 2180
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c = map(int, input().split())

if a + b + c > 21:
    print('bust')
else:
    print('win')




Measured memory_bytes: 9072
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1000+5,dx[]={0,0,1},dy[]={0,1,0},dz[]={1,0,0};
bool cmp(ll x,ll y)
{
    return x>y;
}
struct P{
    int x,y,z;
    ll w;
    P(){};
    P(int a,int b,int c,ll ww)
    {
        x=a;y=b;z=c;w=ww;
    }
    friend bool operator<(const P &p1,const P&p2)
    {
        return p1.w<p2.w;
    }
};
priority_queue<P>q;
ll a[N],b[N],c[N];
int k;
map<ll,int>mmp;
ll zh(int x,int y,int z)
{
    return x*100000000+y*10000+z;
}
int x,y,z;

void bfs()
{
    mmp[0]=1;
    q.push(P(0,0,0,a[0]+b[0]+c[0]));
    while(!q.empty()&&k)
    {
        P p=q.top();
        q.pop();
        k--;
        printf("%lld\n",p.w);
        for(int i=0;i<3;i++)
        {
            int nx=p.x+dx[i],ny=p.y+dy[i],nz=p.z+dz[i];
            if(nx<x&&ny<y&&nz<z&&!mmp[zh(nx,ny,nz)])
            {
                mmp[zh(nx,ny,nz)]=1;
                q.push(P(nx,ny,nz,a[nx]+b[ny]+c[nz]));
            }
        }
    }
    while(!q.empty()){
        q.pop();
    }

}
int main()
{

    scanf("%d%d%d%d",&x,&y,&z,&k);
    for(int i=0;i<x;i++)
    {
        scanf("%lld",&a[i]);
    }
    for(int i=0;i<y;i++)
    {
        scanf("%lld",&b[i]);
    }
    for(int i=0;i<z;i++)
    {
        scanf("%lld",&c[i]);
    }
    sort(a,a+x,cmp);
    sort(b,b+y,cmp);
    sort(c,c+z,cmp);
    bfs();
    return 0;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> S(H, vector<char>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> S.at(i).at(j);
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S.at(i).at(j) == '#') {
                if (S.at(max(i - 1, 0)).at(j) == '.'
                && S.at(min(i + 1, H - 1)).at(j) == '.'
                && S.at(i).at(max(j - 1, 0)) == '.'
                && S.at(i).at(min(j + 1, W - 1)) == '.') {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}


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

int main( int argc, char *argv[] )
{
  char bus[10];
  int yes=0;

  scanf( "%s", bus );

  if( bus[0] != bus[1] ) yes = 1;
  if( bus[1] != bus[2] ) yes = 1;
  if( yes ) printf( "Yes\n" );
  else printf( "No\n" );

/*
  long long n;
  long long a,b;
  long long aa;
  long long l;

  scanf( "%ld %ld %ld", &n, &a, &b );
  l = abs(a-b);
  if( l%2 ){
    if( a > b ){
      aa = b; b = a; a = aa;
    }
    if( n-a > b-1 ) printf( "%ld\n", b-1 );
    else printf( "%ld\n", n-a );
  }
  else{
    printf( "%ld\n", l/2 );
  }
*/
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long

signed main() {
    int n,c,k;
    cin >> n>> c>>k;
    vector<int> t(n);
    rep(i,n) cin >> t[i];
    sort(t.begin(),t.end());
    int en = t[0]+k;
    int id = 1;
    int cnt = 1;
    int ans = 1;
    while(id<n) {
        if(en>=t[id]) {
            cnt++;
            if(cnt>=c) {
                cnt=0;
                ans++;
                if(id+1<n) en = t[id+1]+k;
            }
        }else {
            cnt=1;
            ans++;
            en = t[id]+k;
        }
        id++;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4048
/*input
5
1 2 1
1 3 1
2 4 1
3 5 1
3 1
2 4
2 3
4 5
*/

#include <bits/stdc++.h>
#include <cstdio>
#define rep(i,a,b) for(int i=a;i < b;i++)
#define rrep(i,b,a) for(int i=b ; i > a ; i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define check1(a) cerr << a << endl
#define check2(a,b) cerr << a << "|" << b << endl
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
/*----------------------------------------------*/
using edge = struct {int to; ll cost;};
vector <edge>  tree[100010];
int q,k;
ll depth[100010];
void dfs(int v,int p, ll dis){
    depth[v] = dis;
    for(auto e:tree[v]){
        if(e.to == p)continue;
        dfs(e.to,v,dis+e.cost);
    }
}
int main(){
    int n;
    cin >> n;
    rep(i,0,n-1){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        tree[a].pb({b,c});
        tree[b].pb({a,c});
    }
    cin >> q >> k;
    --k;
    dfs(k,-1,0);
    rep(i,0,q){
        int a,b;
        cin >> a >> b;
        cout << depth[--a] + depth[--b] << endl;
    }
}





Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1LL << 60;


int main() {
    // cout << cos(3.141592653589793) << endl;
    // return 0;
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long H;
    scanf("%lld",&H);
    long long M;
    scanf("%lld",&M);

    long double m = 6 * M;
    long double h = 30 * H + 0.5 * M;

    // if (abs(m - h) == 180) {
    //     // cout << A + B
    //     printf("%.10Lf\n", (long double)(A + B));
    //     return 0;
    // }

    if (h == m) {
        // cout << abs(A - B) << endl;
        printf("%.10Lf\n", (long double)abs(A - B));
    } else if (h > m) {
        long double dig = h - m;

        // cout << h << " " << m << endl;
        if (dig > 180) {
            dig = (long double)360 - dig;
        }

        // cout << dig << endl;

        long double radian = dig * (M_PI / 180);
        long double ans = sqrt(A * A + B * B - 2 * A * B * cos(radian));
        // cout << ans << endl;
        printf("%.10Lf\n", ans);
    } else {
        long double dig2 = m - h;
        if (dig2 > 180) {
            dig2 = (long double)360 - dig2;
        }
        long double radian = dig2 * (M_PI / 180);
        long double ans = sqrt(A * A + B * B - 2 * A * B * cos(radian));
        // cout << ans << endl;
        printf("%.10Lf\n", ans);
    }
}


Measured memory_bytes: 4164
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

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

const long long int mod=1e9+7;



int main(){
	int A,B;
	cin >> A >> B;

	int x = A+B;
	int y = A-B;
	int z = A*B;


	int ans;

	if(x>=y && x>=z) ans = x;
	else if(y>=x && y>=z) ans = y;
	else ans = z;


	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N-1):
    next = i + 1
    if A[i] > A[next]:
        a =A[i] - A[next]
        ans += a
        A[next] += a
    else:
        pass
print(ans)


Measured memory_bytes: 32368
#include<stdio.h>
int main(){
  int a, b, k;
  scanf("%d %d %d", &a, &b, &k);
  for(int i = 0; i < k; ++i){
    if(i % 2){
    if(b % 2) b--;
    a += b / 2;
    b /= 2;
    }else{
      if(a % 2)a--;
      b += a / 2;
      a /= 2;
    
    }
  }
  printf("%d %d\n", a, b);
  return 0;
}

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

int main(){
  int k,str=0;
  char s[101];
  scanf("%d %s",&k,s);
  for(int i=0;s[i]!='\0';i++){
    str++;
  }
  if(str<=k){
    printf("%s",s);
  }else{
    for(int i=k;i<=k+3;i++){
      if(i<k+3){
        s[i]='.';
      }else{
        s[i]='\0';
      }
    }
    printf("%s",s);
  }

return 0;
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
#define ll long long
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;

int N,M;

int main(){
  cin>>N>>M;
  int best = 1;
  for (int i=1;i <= sqrt(M); i++ ) {
    if (M % i == 0 && i <= M/N) best = max(best, i);
    int j = M/i;
    if (M % j == 0 && j <= M/N) best = max(best, j);

  }
  cout<<best<<endl;
}


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

typedef long long ll;
ll mod = 1e9+7;

int main(){
    int n;
    cin>>n;
    
    vector<ll> a(n);
    ll sum = 0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        sum += a[i];
        sum %= mod;
    }

    ll ans = 0;
    for(int i=1; i<=n; i++){
        sum -= a[i-1];
        if(sum < 0){
            sum += mod;
        }
        ans += a[i-1]*sum%mod;
      
    }
    cout<<ans%mod<<endl;
    return 0;
}


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

int main() {
	set<string> s;
	int n;
	char str[11];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> str;
		s.insert(str);
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 19008
#include <bits/stdc++.h>
#define M 1000000007
#define endl '\n'
#define ll long long
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	ll a{0};
	ll b{0};
	ll c{0};
	ll d{0};
	cin>>a>>b>>c>>d;

	ll product1=a*c;
	ll product2=a*d;
	ll product3=b*c;
	ll product4=b*d;

	ll maxi=max(product1,max(product2,max(product3,product4)));
	cout<<maxi<<endl;
	
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define lowbit(k) k&-k
#define pi	3.1415926535
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5+7;
int ans[MAXN];
int gcd(int n, int m)
{
	if (n%m == 0)	return m;
	else return gcd(m, n%m);
}
int main()
{
	int n, x;
	cin >> n >> x;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &ans[i]);
		ans[i] = fabs(ans[i] - x);
	}
	sort(ans, ans + n);
	int m = gcd(ans[0], ans[n - 1]);
	for (int i = 0; i < n; i++)
	{
		if (ans[i] % m != 0)
		{
			m = gcd(m, ans[i]);
		}
	}
	cout << m << endl;
	return 0;
}


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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int a[100] = {0};
	string str;
	cin >> str;
	REP(i,str.size()){
		a[(int)str[i]-'a']++;
	}
	bool flag = true;
	for(int i = 0; i < 26; i++){
		if(a[i]%2!=0) flag = false;
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
typedef long long int llint;

int main(void){
  int k;
  std::cin >> k;

  llint sum = 0;
  for(int i=1; i<=k; i++){
    for(int j=1; j<=k; j++){
      for(int l=1; l<=k; l++){
	sum+=std::gcd(i, std::gcd(j, l));
      }
    }
  }

  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define x first
#define y second
#define pii pair<int , int>
#define sz(a) (int)(a.size())
const int INF = 1000 * 1000 * 1000;
const int mod = 998244353;
const int MAX = 1000 * 1000 + 47;
using namespace std;
int a[2][20];
int dp[1 << 18][18];
int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < n; j++)
			cin >> a[i][j];
	for(int i = 0; i < (1 << n); i++)
		for(int j = 0; j < n; j++)
			dp[i][j] = INF;
	for(int i = 0; i < n; i++)
		dp[(1 << i)][i] = 0;
	for(int i = 1; i < (1 << n); i++)
		for(int j = 0; j < n; j++)
			for(int k = 0; k < n; k++)
			{
				if((i >> k) & 1)
					continue;
				int cnt = __builtin_popcount(i);
				int val = a[(j + cnt - 1) & 1][j];
				int val2 = a[(k + cnt) & 1][k];
				if(val <= val2)
					dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k] , dp[i][j] + __builtin_popcount(i >> k));
			}
	int ans = INF;
	for(int i = 0; i < n; i++)
	{
		ans = min(ans , dp[(1 << n) - 1][i]);
	}
	cout << (ans == INF ? -1 : ans);
	
}


Measured memory_bytes: 18688
#include <stdio.h>

int main() {
	char x;
	int sum = 0;

	while (1) {
		while ((x = getchar()) != '\n') {
			sum += x - '0';
		}
		if (sum == 0)
			break;
		else {
			printf("%d\n", sum);
			sum = 0;
		}
	}
}


Measured memory_bytes: 2116
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	x := nextInt(sc)
	y := nextInt(sc)

	for {
		if y > x {
			t := x
			x = y
			y = t
		}
		x = x % y
		if x == 0 {
			fmt.Println(y)
			return
		}
	}
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}



Measured memory_bytes: 1108
def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    stock = 0
    MONEY = 1000
    for i in range(N - 1):
        if A[i] < A[i + 1]:
            # 売却
            MONEY += stock * A[i]
            stock = 0
            # 購入
            stock = MONEY // A[i]
            MONEY -= A[i] * stock
        else:
            # 売却
            MONEY += stock * A[i]
            stock = 0
    if stock > 0:
        # 売却
        MONEY += stock * A[-1]
        stock = 0
    print(MONEY)

resolve()



Measured memory_bytes: 9200
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int lim = N/4;
		int judge = 0;

		for(int i=0; i<=lim; i++) {
			if((N-4*i)%7 == 0) {
				judge += 1;
			}
		}if(judge != 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	ll n, x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0;
  for(int i = 0; i < n-1; ++i){
    if(a[i] + a[i+1] > x){
      ll tmp = a[i] + a[i+1] - x;
      ans += tmp;
      if(a[i+1] >= tmp){
        a[i+1] -= tmp;
      }
      else{
        a[i] -= tmp - a[i+1];
        a[i+1] = 0;
      }
    }
  }

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



Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(void){    //sは面積、lは周の長さ、hは高さ
    double a,b,C; //aはaの長さ、bはbの長さ、cは大きさ
    double S,L,h,c; //cは余弦定理を使うため
    
    cin >> a >> b >> C;
    
    double PI = acos(-1);  //PIをつくる
    C = (C * PI) / 180;
    
    S = (a*b*sin(C)) / 2;
    c = sqrt(a*a + b*b - 2*a*b*cos(C));
    L = a + b + c;
    h = S * 2 / a;
    
    printf("%lf\n %lf\n %lf\n", S,L,h);
    
    
    
}


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

int main() {
    int N;
    char s1[110], s2[110];
    cin >> N;
    cin >> s1;
    cin >> s2;
    for (int i = 0; i < N; i++)
    {
        cout << s1[i];
        cout << s2[i]; 
    }
    cout << endl;
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

  int X;
  cin >> X;

  if (X == 3 or X == 5 or X == 7)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 764
# ENV[Z = 'RUBY_THREAD_VM_STACK_SIZE'] || exec( { Z => '50000000' },'ruby',$0)
# readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }
# gets.split.map(&:to_i)

a,b = gets.split.map(&:to_i)

puts (a*b).odd? ? "Odd" : "Even"


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

char classify(int m, int e, int j){
    if(m == 100 || e == 100 || j == 100)    return 'A';
    if((m+e)/2 >= 90)   return 'A';
    if((m+e+j)/3 >= 80) return 'A';
    if((m+e+j)/3 >= 70)    return 'B';
    if((m+e+j)/3 >= 50 && max(m,e) >= 80)   return 'B';
    return 'C';
}

int main(){
    int n;
    while(cin >> n, n){
        int m, e, j;
        for(int i = 0; i < n; i++){
            cin >> m >> e >> j;
            cout << classify(m,e,j) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string A;
  cin >> A;
  ll N = A.size();
  if(N==1){
    cout << 1 << endl;
    return 0;
  }
  vll counter(26, 0);
  for(int i = 0; i < N; i++){
    counter.at(A.at(i) - 'a')++;
  }
  ll ans = N * (N-1) / 2;
  for(int i = 0; i < 26; i++){
    ll num = counter.at(i);
    if(num <= 1) continue;
    ans -= num * (num-1LL) / 2LL;
  }
  cout << ans+1 << endl;

  /*実験
  map<string, int> mp;
  mp[A] = 1;
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      string pre = A.substr(0, i);
      string mid = A.substr(i, j-i+1);
      string post = A.substr(j+1, N-j);
      reverse(ALL(mid));
      mp[pre+mid+post]++;
      if(pre+mid+post == "abadacarbra") cout << i << ' ' << j << ' ' << pre + mid + post << endl;
    }
  }
  int counter = 0;
  for(auto i = mp.begin(); i != mp.end(); i++){
    cout << i->first << ' ' << i->second << endl;
    counter += i->second;
  }
  cout << counter << endl;
  cout<< mp.size() << endl;*/
}

Measured memory_bytes: 720
/*{{{*/
#include "bits/stdc++.h"
using namespace std;

#define MT make_tuple
#define all(x) begin(x), end(x)
#define putchar(x) cout << (x)
static int fastio = [](){ ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(17); return 0; }();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename ...T> string format(const string& fmt, T&&... args) {
    size_t sz = snprintf(nullptr, 0, fmt.c_str(), args...) + 1;
    unique_ptr<char[]> buf(new char[sz]);
    snprintf(buf.get(), sz, fmt.c_str(), args...);
    return string(buf.get(), buf.get() + sz - 1);
}

template<class T> struct rge { T b, e; auto begin() const { return b; } auto end() const { return e; } };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
template<class T> auto dud(T* x) -> decltype(cerr << *x, 0);
template<class T> char dud(...);

struct debug {
#ifdef LOCAL
    debug(int line) {
        if(line) cerr << "LINE(" << line << ") -> ";
    }
    template<class T> typename enable_if<sizeof dud<T>(0) != 1, debug&>::type operator<<(T i) {
        cerr << boolalpha << i; return * this;
    }
    template<class T> typename enable_if<sizeof dud<T>(0) == 1, debug&>::type operator<<(T i) {
        return *this << range(begin(i), end(i));
    }
    template<class T, class U> debug& operator<<(pair<T, U> d) {
        return *this << "(" << d.first << ", " << d.second << ")";
    }
    debug& operator<<(tuple<>&) { return *this << "()"; };
    template<class ...T> debug& operator<<(tuple<T...> d) {
        *this << "("; debug_tuple<sizeof...(T), 0>(d);
        return *this << ")";
    }
    template<size_t L, size_t I, class T> void debug_tuple(const T& t) {
        *this << (I == 0 ? "" : ", ") << get<I>(t);
        if(I + 1 < L) debug_tuple<L, (I + 1) % L>(t);
    }
    template<class T> debug & operator <<(rge<T> d) {
        *this << "[";
        for(auto it = d.b; it != d.e; ++it)
            *this << (it != d.b ?  ", " : "") << *it;
        return *this << "]";
    }
    debug& operator<<(ostream&(*pf)(std::ostream&)) {
        cerr << pf; return *this;
    }
#else
    debug(int) {}
    template<class T> debug& operator<<(T&&) { return *this; }
    debug& operator<<(ostream&(*)(std::ostream&)) { return *this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ << ": " << (__VA_ARGS__) << "] "

#define debug0()  debug(__LINE__)
#define debug1(x) debug(0)
#define GET_MACRO(_0, _1, NAME, ...) NAME
#define debug(...) GET_MACRO(_0, ##__VA_ARGS__, debug1, debug0)(__VA_ARGS__)
/*}}}*/
using LL = long long;

const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const int MAX_N = 200005;

void solve(int) {
    LL N;
    cin >> N;
    string ans;
    while(N > 0) {
        N -= 1;
        ans.push_back('a' + N % 26);
        N /= 26;
    }
    reverse(all(ans));
    cout << ans << endl;
}

int main() {
    int T = 1;
    //cin >> T;
    for(int i = 1; i <= T; ++i) {
        solve(i);
    }
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
pair<long long,long long> dt[1000100];
long long sumx[1000100],sumy[1000100];
priority_queue<long long,vector<long long>,greater<long long> >que;
bool cmp(pair<long long,long long> a,pair<long long,long long> b){return a.first-a.second<b.first-b.second;}
int main()
{
	long long x,y,z,all=0,ans=-1e18;scanf("%lld%lld%lld",&x,&y,&z);
	for (long long i=1;i<=x+y+z;i++)
	{
		long long a,b,c;scanf("%lld%lld%lld",&a,&b,&c);a-=c;b-=c;all+=c;
		dt[i]=make_pair(a,b);
	}
	sort(dt+1,dt+x+y+z+1,cmp);
	for (long long i=1;i<=x+y+z;i++)
	{
		que.push(dt[i].second);sumy[i]=sumy[i-1]+dt[i].second;
		if (que.size()>y) {sumy[i]-=que.top();que.pop();}
	}
	while (!que.empty()) que.pop();
	for (long long i=x+y+z;i>=1;i--)
	{
		que.push(dt[i].first);sumx[i]=sumx[i+1]+dt[i].first;
		if (que.size()>x) {sumx[i]-=que.top();que.pop();}
	}
	for (long long i=y;i<=y+z;i++) ans=max(ans,sumy[i]+sumx[i+1]);
	printf("%lld\n",all+ans);//cerr<<all<<endl;
}

Measured memory_bytes: 10360
N = int(input())
P = list(map(int, input().split()))

sortP = sorted(P)
sumChk = sum([a != b for a, b in zip(P, sortP)])

# 2箇所を入れ替えたら昇順になる ＝ 昇順に並べ替えた配列と要素ごとに比較して、違いは2箇所だけ。または同一についてもYES判定
if sumChk == 2 or sumChk == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 2940
// Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
int main()
{
    int  a , b ;
    cin >> a >> b ;
    a -= b*2 ;
    if(a <= 0 )a = 0;
    cout << a <<"\n";

}


Measured memory_bytes: 256
def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p,r):
        if A[j] <= x:
            i = i+1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return A, i+1

n = int(input())
*A, = map(int,input().split())

A_out, pos = partition(A, 0, n-1)
*A_out, = map(str,A_out)


print(" ".join(A_out[:pos]) + " [" + str(A_out[pos]) + "] " + " ".join(A_out[pos+1:]))



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


int a,b,c,d;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>a>>b>>c>>d;
    int x=(b+c-1)/b;
    int y=(d+a-1)/d;
    if (x<=y) out("Yes");
    out("No");
  

    return 0;
}


Measured memory_bytes: 3588
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    ll n,m;
    cin>>n>>m;
    vll v[11];

    rep(i,m){
        ll k;
        cin>>k;
        rep(j,k){
            ll a;
            cin>>a;a--;
            v[a].pb(i);
        }
    }
    ll p[12]={};
    rep(i,m) cin>>p[i];

    ll ans=0;
    rep(bit,(1<<n)){
        ll c[20]={};
        rep(i,n){
            if(bit&(1<<i)){
                for(auto j:v[i]){
                    c[j]++;
                }
            }
        }
        bool ok=true;
        rep(i,m){
            if(c[i]%2!=p[i]) {
                ok=false;
                break;
            }
        }
        if(ok) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    string s;
    cin>>s;
    
    int t=s.size()-1;
    bool judge=true;

    string s_rev = s;
    reverse(s_rev.begin(), s_rev.end());

    if(s!=s_rev || s.substr(0,t/2)!=s.substr(t/2+1)){
        judge=false;
    }

    if(judge==true){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

int main()
{
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    if (a == 0) {
        cout << "1" << endl;
    } else if (b == 0) {
        cout << "2" << endl;
    } else if (c == 0) {
        cout << "3" << endl;
    } else if (d == 0) {
        cout << "4" << endl;
    } else {
        cout << "5" << endl;
    }

    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[5];
    for(int i=0;i<5;i++){
        cin >> a[i];
    }
    for(int i=0;i<5;i++){
        if(a[i]==0){
            cout << i+1;
        }
    }
    return 0;
}


Measured memory_bytes: 3508
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, a[112345];
LL four_cou, two_cou;

int main()
{
	in >> N;
	rep(i, N) { in >> a[i]; }

	rep(i, N)
	{
		if (a[i] % 4LL == 0) { ++four_cou; }
		else if (a[i] % 2LL == 0) { ++two_cou; }
	}
	if (two_cou >= 2) { N -= (two_cou - 1LL); }

	if (four_cou >= N / 2LL) { out << "Yes" << std::endl; }
	else { out << "No" << std::endl; }
	return 0;
}

Measured memory_bytes: 1024
//????

#include <stdio.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
typedef long long ll;
const ll N = 1 << 19;
const ll sqrtN = 1 << 9;



ll n;
ll a[100005];
ll ans = 0;

ll gcd_bucket[100005];

void update(int k, ll dat);
ll get_gcd(int s, int t);//?????gcd
ll gcd(ll m, ll n); //m,n?gcd

int main()
{
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);

		update(i, a[i]);
	}

	ans = get_gcd(0, n + 1);
	for (int i = 0; i < n; i++) {
		ll tmp = a[i];

		if (i > 0)	update(i, a[i - 1]);
		else update(i, a[i + 1]);

		ans = max(ans, get_gcd(0, n + 1));

		update(i, tmp);
	}

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

	return 0;
}

void update(int k, ll dat)
{
	a[k] = dat;
	ll g = 0;

	k /= sqrtN;
	for (int i = k * sqrtN; i < (k + 1) * sqrtN; i++) {
		gcd(g, a[i]);
	}

	gcd_bucket[k] = g;

	return;
}

ll get_gcd(int s, int t)
{
	int g = 0;
	int K = (n + sqrtN - 1) / sqrtN;

	for (int k = 0; k < K; k++) {
		int l = k * sqrtN;
		int r = (k + 1) * sqrtN;

		if (t <= l || r <= s) {
			continue;
		}
		else if (s <= l && r <= t) {
			g = gcd(g, gcd_bucket[k]);
		}
		else {
			for (int i = max(s, l); i < min(t, r); i++) {
				g = gcd(g, a[i]);
			}
		}
	}

	return g;
}

ll gcd(ll m, ll n)
{
	if (m < n) {
		ll tmp = m;
		m = n;
		n = tmp;
	}

	while (n) {
		ll tmp = m % n;
		m = n;
		n = tmp;
	}

	return m;
}


Measured memory_bytes: 896
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const int MAX_M = 1e5;

int main(void){
    int W, H, x, y;
    double spa = 0;
    int does_exist = 0;
    
    cin >> W >> H >> x >> y;
    
    int min_x, min_y;
    min_x = min(x, W - x);
    min_y = min(y, H - y);

    if (W - x == x && H - y == y) does_exist = 1;

    cout << (double)(W) * double(H) / 2 << " " << does_exist << endl;

    return 0;
}

Measured memory_bytes: 256