akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb; 
typedef long long ll;  
typedef double db;                         
 
 
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 3e5 + 48, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, x, cnt[N], cnt1[N], pr[N], suff[N];
pii f[N];

main () {
	cin >> n;
	forn (i, 1, n) {
		cin >> x;
		++cnt[x];
	}

	forn (i, 1, n)
		++cnt1[cnt[i]];

	forn (i, 1, n) 
		pr[i] = pr[i - 1] + cnt1[i] * i;

	forev (i, n, 1)
		suff[i] = suff[i + 1] + cnt1[i];

	forn (i, 1, n) {
		f[i].f = pr[i - 1] / i + suff[i];					 
		f[i].s = i;
	}
	
	sort(f + 1, f + 1 + n);
	reverse(f + 1, f + 1 + n);
	int j = 1, mx = 0;
	vi ans;
	forev (k, n, 1) {
		while (j <= n && f[j].f >= k) 
			mx = max(mx, f[j++].s);
		ans.pb(mx);
	}
	reverse(all(ans));					
	for (auto x : ans)
		cout << x << endl;
}


Measured memory_bytes: 20336
import math
n = int(input())
x = [int(num) for num in input().split()]
y = [int(num) for num in input().split()]
D1 = 0
D2 = 0
D3 = 0
D4 = []
for i, j in zip(x, y):
    D1 += abs(i - j)
print(D1)
for i, j in zip(x, y):
    D2 += (abs(i - j))**2
print(math.sqrt(D2))
for i, j in zip(x, y):
    D3 += (abs(i - j))**3
print(math.pow(D3, 1.0/3.0))
for i, j in zip(x, y):
    D4.append(abs(i - j))
print(max(D4))

Measured memory_bytes: 7896
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
typedef long long ll;

int main(){
    string S;
    cin>>S;
    int size=S.size();
    rep(i,size){
        S.erase(S.size()-1);
        if(S.size()%2==0){
            if(S.substr(0,S.size()/2)==S.substr(S.size()/2,S.size()/2)){
                cout<<S.size()<<endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e6+9;
int main()
{
    FASTINOUT;
    string s,t;
    cin>>s>>t;
    int a[26]= {0};
    int b[26]= {0};
    int ls=s.length(),lt=t.length();
    for (int i=0; i<ls; i++)
    {
        a[s[i]-'a']++;
    }
    for (int i=0; i<lt; i++)
    {
        b[t[i]-'a']++;
    }
    bool ans=true;
    for (int i=0; i<26; i++)
    {
        if (b[i]&&!a[i])
        {
            ans=false;
            break;
        }
    }
    if (!ans)
    {
        cout<<-1<<endl;
    }
    else
    {
        vector<int>arr[26];
        for (int i=0; i<ls; i++)
        {
            arr[s[i]-'a'].push_back(i);
        }
        int beg=-1;
        ll ans=0;
        vector<int>::iterator it;
        for (int i=0; i<lt; i++)
        {
            it=lower_bound(arr[t[i]-'a'].begin(),arr[t[i]-'a'].end(),beg);
            if (it==arr[t[i]-'a'].end())
            {
                ans+=ls;
                beg=-1;
                i--;
            }
            else
            {
                beg=(*it)+1;
            }
        }
        cout<<ans+beg<<endl;
    }
    return 0;
}


Measured memory_bytes: 1228
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        _n: usize,
        s: Chars
    };
    let mut max = 0;
    let mut x = 0;
    for c in s {
        x += match c {
            'I' => 1,
            'D' => -1,
            _ => unreachable!(),
        };
        max = std::cmp::max(max, x);
    }
    println!("{}", max);
}


Measured memory_bytes: 2100
#include<stdio.h>
char str[2];
int main(){
	int a=1000000001;
	while(1){
		if(a==1000000001){
			scanf("%d",&a);
		}else{
			int b;
			scanf("%d",&b);
			if(str[0]=='+')a+=b;
			if(str[0]=='-')a-=b;
			if(str[0]=='*')a*=b;
			if(str[0]=='/')a/=b;
		}
		scanf("%s",str);
		if(str[0]=='='){
			printf("%d\n",a);
			return 0;
		}
	}
}

Measured memory_bytes: 1028
//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <vector>

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

using namespace std;

typedef long long ll;

int group(int n){
    if(n==2)
        return 2;
    else if(n==4 || n==6 || n==9 || n==11)
        return 1;
    else
        return 0;

}

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int x,y;
    cin >> x >> y;
    if(x+y>=10)
        cout << "error" << endl;
    else
    cout << x+y << endl;
    return 0;
}


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

typedef long long ll;
const int maxn=360;
const ll mod=1e9+7;
ll n; ll K;
ll a[maxn];
struct node{ ll b,c; }b[maxn];

void chkmin(ll& x,ll y){ if(x>y) x=y; }
void chkmax(ll& x,ll y){ if(x<y) x=y; }

bool cmp1(node A,node B){ return A.c<B.c; }
bool cmp2(node A,node B){ return A.b<B.b || (A.b==B.b && A.c<B.c); }

map<vector<ll>, vector<node> > mp; typedef map<vector<ll>, vector<node> >::iterator it;

ll popmin(ll l,ll r){
	if(l>r) return maxn;
	ll ret=0;
	for(ll i=60;i>=0;i--){
		if((l & (1ll<<i)) ^ (r & (1ll<<i))){
			if(l & ((1ll<<i)-1)) ret++;
			break;
		}
		if(l & (1ll<<i)) ret++;
	}
	return ret;
}

void add(ll x,ll k){
	if(k<0) return;
	vector<ll> vec;
	vec.resize(n);
	ll Min=b[1].b-(1<=x);
	for(ll i=1;i<=n;i++){
		vec[i-1]=b[i].b-(i<=x);
		chkmin(Min, vec[i-1]);
	}
	if(Min<0) return;
	for(ll i=0;i<n;i++) vec[i]-=Min;
	sort(vec.begin(), vec.end());
	mp[vec].push_back( (node){max(Min-k,0ll), Min} );
	// for(int i=0;i<n;i++) printf("%d ", vec[i]); puts("");
	// printf("Min = %d Max = %d\n", max(Min-k, 0ll) ,Min);
}

int main(){

	int T=1;
	while(T--){
		mp.clear();
		scanf("%d%lld", &n, &K);
		for(int i=1;i<=n;i++) scanf("%lld", &a[i]);
		for(ll i=0;i<=60;i++){
			for(ll j=1;j<=n;j++){
				b[j].b=a[j]>>i;
				b[j].c=a[j] & ((1ll<<i)-1);
			}
			sort(b+1,b+1+n,cmp1);
			ll Next, l=0, r=0;
			for(ll j=1;j<=n;j=Next+1,l=r+1){
				Next=j;
				while(Next<n && b[Next+1].c==b[j].c) Next++;
				r=b[j].c;
				add(j-1,K-popmin(l,r)-i);
			}
		}

		ll ans=0;
		for(it it=mp.begin();it!=mp.end();it++){
			vector<node> vec=it->second;
			sort(vec.begin(), vec.end(), cmp2);
			ll l=0, r=-1;
			// puts("");
			for(ll i=0;i<vec.size();i++){
				// printf("l = %d r = %d\n", vec[i].b, vec[i].c);
				if(vec[i].b>r){
					l=vec[i].b; r=vec[i].c;
					ans=(ans+r-l+1)%mod;
				}else{
					ans=(ans+vec[i].c-r)%mod;
					r=vec[i].c;
				}
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int N;
  cin >> N;
  vector <int> A(N), B(N), C(N - 1);
  rep(i,N) cin >> A.at(i);
  rep(i,N) cin >> B.at(i);
  rep(i,N-1) cin >> C.at(i);

  int ans = 0;
  rep(i,N){
    ans += B.at(A.at(i) - 1);
    if (i > 0 && A.at(i) == A.at(i - 1) + 1){
      ans += C.at(A.at(i - 1) - 1);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        var S = cin.next;
        int A = S[0] - '0';
        int B = S[1] - '0';
        int C = S[2] - '0';
        int D = S[3] - '0';
        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                for (int k = 0; k < 2; k++)
                {
                    int sum = A;
                    sum += (i == 0) ? B : -B;
                    sum += (j == 0) ? C : -C;
                    sum += (k == 0) ? D : -D;
                    if (sum == 7)
                    {
                        Write(S[0]);
                        Write(i == 0 ? "+" : "-");
                        Write(S[1]);
                        Write(j == 0 ? "+" : "-");
                        Write(S[2]);
                        Write(k == 0 ? "+" : "-");
                        Write(S[3]);
                        WriteLine("=7");
                        return;
                    }
                }
            }
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

int main(void) {
    unsigned long long n,m;
    cin >> n >> m;
    if(n==1&&m==1){
        cout << 1 << endl;
    }else if(n==1||m==1){
        cout << max(n,m)-2 << endl;
    }else{
        cout << (n-2)*(m-2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s)
	fmt.Scan(&t)

	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			fmt.Println("No")
			return
		}
	}
	fmt.Print("Yes")
}


Measured memory_bytes: 1816
n = int(input())
s = [input() for u in range(n)]
a = sum([u.count("AB") for u in s])
b = len([1 for u in s if u.endswith("A")])
c = len([1 for u in s if u.startswith("B")])
d = len([1 for u in s if u.endswith("A") and u.startswith("B")])
if (b>0 and b==c and c==d):
  print(a+b-1)
else:
  print(a+min(b,c))

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

using namespace std;

int main(){
int N;
vector<int> A;
int tmp;

cin>>N;
for(int i=0;i<N;i++){
    cin>>tmp;
    A.push_back(tmp);
}

sort(A.begin(),A.end());

cout<<A[A.size()-1]-A[0]<<endl;

//system("pause");
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long T,i,j,n=0,x,t;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        n+=(s[i]-'0');
    }
    if(n%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


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

int main() {
    
    int N,M,C=0,k=0;
    cin >> N >> M;
    
    int data[N];
    
    for(int i=0;i<N;i++){
        cin >> data[i];
        C += data[i];
    }
  
    double max = C / (4.0 * M);
    
    for(int i=0;i<N;i++){
        if(max <= data[i]){
            k++;
        }
        
        if(k == M){
            cout << "Yes" <<endl;
            return 0;
        }
    }
    
    cout <<"No" <<endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -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 io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) 
{
    ll n;
    cin >>n;
    vll h(n);
    ll ma = 0;
    rep(i, n) {
        cin >>h[i];
        ma = max(ma, h[i]);
        if (h[i] <= ma-2) {
            mes("No");
            re0;
        }
        
    }
    mes("Yes");

}


Measured memory_bytes: 3964
n,m=map(int,input().split())
rm=10**5+1
lm=0
for i in range(m):
    l,r=map(int,input().split())
    if r<rm:
        rm=r
    if l>lm:
        lm=l
if rm-lm+1<0:
    print(0)
else:
    print(rm-lm+1)

Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(answer063bAlt(s))
}

fun answer063bAlt(s: String): String {
    var res = "yes"
    val alphabets: ArrayList<String> = arrayListOf(
        "a",
        "b",
        "c",
        "d",
        "e",
        "f",
        "g",
        "h",
        "i",
        "j",
        "k",
        "l",
        "m",
        "n",
        "o",
        "p",
        "q",
        "r",
        "s",
        "t",
        "u",
        "v",
        "w",
        "x",
        "y",
        "z"
    )
    s.forEach {
        if (alphabets.contains(it.toString())) {
            alphabets.remove(it.toString())
        }else {
            res = "no"
        }
    }
    return res
}

Measured memory_bytes: 31392
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> w(n);
    for (int i = 0; i < n; i++)
    {
        cin >> w.at(i).second >> w.at(i).first;
    }
    sort(w.begin(), w.end());
    long long time = 0;
    int x = 0;
    for (int i = 0; i < n; i++)
    {
        time += w.at(i).second;
        if (time > w.at(i).first)
        {
            x++;
            break;
        }
    }
    if (x == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

int main()
{
	int h, w;
	scanf("%d %d", &h, &w);

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			string s;
			cin >> s;

			if (s == "snuke")
			{
				printf("%c%s\n", j + 'A', to_string(i+1).c_str());
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
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,b,c;
cin >> a >> b >> c;
if(a+b+c >= 22) cout << "bust" << endl;
else cout << "win"  << endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    vector<ll> a(N), b(N);
    for(int i=0; i<N; i++) cin >> a[i] >> b[i];

    ll ans = 0;
    for(int i=N-1; i>=0; i--){
        if((ans+a[i])%b[i]) ans += b[i] - (ans+a[i])%b[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rgi register int
#define ll long long
class fastin{
	private: int _ch,_f;
	public: inline fastin& operator>>(char&c) {c=getchar(); return *this;}
		template<typename _Tp> inline fastin& operator>>(_Tp&_x){
		_x=0; while(!isdigit(_ch)) _f|=(_ch==45),_ch=getchar();
		while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
		_f&&(_x=-_x,_f=0); return *this;}
	fastin() {_ch=_f=0;}
}fin;
class fastout{
#define endl '\n'
	private: int _num[32],_head;
	public: inline fastout& operator<<(char c) {putchar(c); return *this;}
		template<typename _Tp> inline fastout& operator<<(_Tp _x){
		_Tp _k; if(_x==0) {putchar('0'); return *this;} if(_x<0) putchar('-'),_x=-_x;
		while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
		while(_head>0) putchar(_num[_head]),--_head; return *this;}
	fastout() {_head=0;}
}fout;
// ----------------------------
// #define int ll
// using namespace std;
const int maxn=200004;
const int mod=998244353,inf=1000000007;

int n,k;
int a[200010];
int cf[200010];
int fir;
signed main()
{
	fin>>n>>k;
	for(int i=1;i<=n;i++){
		fin>>a[i];
		if(a[i]>=i-1){
			fir++;
		}
		if(i-a[i]>=2){
			cf[i-a[i]]++;
		}
		if(i+a[i]+1<=n){
			cf[i+a[i]+1]--;
		}
	}
	while(k--){
		a[0]=fir;
		int cnt=0;
		for(int i=1;i<=n;i++){
			a[i]=a[i-1]+cf[i];
			cf[i]=0;
			cnt+=(a[i]>=n);
		}
		fir=0;
		if(cnt>=n){
			break;
		}
		for(int i=1;i<=n;i++){
			if(a[i]>=i-1){
				fir++;
			}
			if(i-a[i]>=2){
				cf[i-a[i]]++;
			}
			if(i+a[i]+1<=n){
				cf[i+a[i]+1]--;
			}
		}
		// for(int i=1;i<=n;++i) cout<<a[i]<<' ';
		// cout<<endl;
	}
	for(int i=1;i<=n;i++){
		fout<<a[i]<<' ';
	}
	return 0; 
}


Measured memory_bytes: 5184
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int p[] = new int[N];

        for (int i=0;i<N;i++) {
            p[i] = sc.nextInt();
        }

        if (isAsc(p)) {
            System.out.println("YES");
            return;
        }

        for (int i=0;i<N-1;i++) {
            for (int j = i + 1; j < N; j++) {
                int tmp = p[i];
                p[i] = p[j];
                p[j] = tmp;
                if (isAsc(p)) {
                    System.out.println("YES");
                    return;
                }
                p[j] = p[i];
                p[i] = tmp;
            }
        }
        System.out.println("NO");
    }

    public static boolean isAsc(int a[]) {
        for (int i =0;i<a.length-1;i++) {
            if (a[i] > a[i+1]) return false;
        }
        return true;
    }
}


Measured memory_bytes: 23252
//#pragma comment(linker,"/STACK:102400000,102400000")
//#include <initializer_list>
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define slla(n) scanf("%lld", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define DE(val) cout<<#val<<": "<<val<<endl;
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); repp(i,1,___T)

const int dx44[5] = { 0,-1,-1,1,1 };
const int dy44[5] = { 0,-1,1,-1,1 };

const int dx4[5] = { 0,-1,0,1,0 };
const int dy4[5] = { 0,0,1,0,-1 };
const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int dx82[9] = { 0,-1,-1,1,1, 2,2,-2,-2 };
const int dy82[9] = { 0,2,-2,2,-2, 1,-1,1,-1 };
const int maxn = 5e6 + 50;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;

ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void extgcd(ll a,ll b,ll& d,ll& x,ll& y){ if(!b){ d=a; x=1; y=0;} else{ extgcd(b,a%b,d,y,x); y-=x*(a/b); }}
ll inverse(ll a,ll n){ ll d,x,y;extgcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}

void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes");}// exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No");}// exit(0); }
void one() { puts("-1"); exit(0); }


int a[maxn];
 
struct node
{
	int a,b;
}Max[maxn];
 
void f(int x,node &b)
{
	if(b.a==x||b.b==x) return;
	if(a[b.a]<a[x]) swap(b.a,b.b),b.a=x;
	else if(a[b.b]<a[x]) b.b=x;
}


void solve() {
	int n;
	scanf("%d",&n);
	int N=1<<n;
	for(int i=0;i<N;i++){
		scanf("%d",&a[i]);
		Max[i].a=a[0]>a[i]?0:i;
		Max[i].b=a[0]>a[i]?i:0;
	}
	for(int i=1;i<N;i++){
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				int k=i^(1<<j);
				f(Max[k].a,Max[i]);
				f(Max[k].b,Max[i]);
			}
		}
	}
	int ans=0;
	for(int i=1;i<N;i++){
		ans=max(ans,a[Max[i].a]+a[Max[i].b]);
		printf("%d\n",ans);
	}

}

int main()
{

	solve();
    // system("pause");
    return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
 
int main() {
  int n;
  cin >> n;
  
  int ans=0;
  
  for(int i=1;i<=50000;i++){
  	if(int(i*1.08)==n)ans = i;
  }
  
  if(ans==0)cout << ":(" << endl;
  else cout << ans << endl;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

const int N=110000;
typedef long long LL;
const LL mod=1e9+7;

int l[N],r[N];
int a[N],b[N],c[N];
int n,m;
vector<int> g;
vector<pair<int,LL> > f[N*8];
priority_queue<pair<LL,int>,vector<pair<LL,int> >,greater<pair<LL,int> > > q;
const LL INF=1e15;
LL dis[N*8];
int pp[N*8];
int idx[N];
int maxx;
void dijkstra(int x,int n)
{	int i,u;
	for (i=1;i<=n;++i)
		dis[i]=INF,pp[i]=0;
	dis[x]=0;
	for (i=1;i<=n;++i)
		q.push(make_pair(dis[i],i));
	while (!q.empty())
	{	
		u=q.top().second;
		q.pop();
		if (pp[u])
			continue ;
		pp[u]=1;
		for (i=0;i<f[u].size();i++)
			if (dis[f[u][i].fi]>dis[u]+f[u][i].se)
			{	dis[f[u][i].fi]=dis[u]+f[u][i].se;
				q.push(make_pair(dis[f[u][i].fi],f[u][i].fi));
			}
	}
}
void build(int k,int l,int r)
{
	maxx=max(maxx,k);
	if (l==r) {idx[l]=k;return;}
	int mid=(l+r)/2;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
}
void build2(int k,int l,int r)
{
	f[k+maxx].pb(mp(k,0));
	if (l==r) {return;}
	int mid=(l+r)/2;
	build2(k<<1,l,mid),f[k<<1].pb(mp(k,0)),f[k+maxx].pb(mp((k<<1)+maxx,0));
	build2(k<<1|1,mid+1,r),f[k<<1|1].pb(mp(k,0)),f[k+maxx].pb(mp((k<<1|1)+maxx,0));
}
void add(int k,int l,int r,int a,int b,int c)
{
	if (l==a&&r==b)
	{
		g.pb(k);
		return;
	}
	int mid=(l+r)/2;
	if (b<=mid) add(k<<1,l,mid,a,b,c);
	else if (a>mid) add(k<<1|1,mid+1,r,a,b,c);
	else add(k<<1,l,mid,a,mid,c),add(k<<1|1,mid+1,r,mid+1,b,c);
}
int main()
{
	scanf("%d %d",&n,&m);
	for (int i=1;i<=n;i++)
		l[i]=i-1,r[i]=i+1;
	r[0]=1,l[n+1]=n;
	build(1,1,n);
	build2(1,1,n);
	for (int i=1;i<=m;i++)
	{
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
		g.clear();
		add(1,1,n,a[i],b[i],i);
		for (int j=0;j<g.size();j++)
			for (int k=0;k<g.size();k++)
				f[g[j]].pb(mp(g[k]+maxx,c[i]));
	}
	dijkstra(idx[1],maxx+maxx);
	if (dis[idx[n]]==INF) cout<<-1<<endl;
	else cout<<dis[idx[n]]<<endl;
	return 0;
}

Measured memory_bytes: 506660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n;
	cin >> n;
	ll q = sqrt(n + 0.5);
	for (ll i = q; i >= 1; --i) {
		if (n % i == 0) {
			cout << i + n / i - 2 << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3676
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

def fact(a,M=mod):
    ans = 1
    for i in range(2,a+1):
        ans = ans*i
        ans = ans%M
    return ans

N = I()
S = str(input())

if S[0]=='W':
    print(0)
    exit()

if S[2*N-1]=='W':
    print(0)
    exit()

d = ['L']*(2*N)

for i in range(1,2*N):
    if S[i]!=S[i-1]:
        d[i]=d[i-1]
    else:
        if d[i-1]=='L':
            d[i] = 'R'
        else:
            d[i] = 'L'

nr = 0
nl = 0
for i in range(2*N):
    if d[i]=='L':
        nl += 1
    else:
        nr += 1
if nl != nr:
    print(0)
    exit()



temp = 0
x = [0]*(2*N)
for i in range(2*N):
    if d[i]=='L':
        temp += 1
    else:
        x[i] = temp

ans = 1
rnum = 0
for i in range(2*N):
    if d[i]=='R':
        ans *= x[i]-rnum
        ans %= mod
        rnum += 1

ans *= fact(N)
ans %= mod

print(ans)

Measured memory_bytes: 44000
import sys
readline = sys.stdin.buffer.readline

lst1 = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

n = int(readline())

print(lst1[n-1])

Measured memory_bytes: 38256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(p);
            Console.WriteLine(p[0] + p[1] == p[2] ? "Yes" : "No");

            Console.Out.Flush();
        }
    }
    


    public class Calculation
    {
        
    }

    public class Graph
    {

    }
}
    

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> ans(N);
  vector<vector<int>> G(N);
  rep(i, N) rep(j, N) {
    if(i != j) G[i].push_back(j);
  }
  vector<int> done(N*N, -1);
  int col = 0;
  vector<int> depth(N);
  vector<bool> vis(N);
  int cnt = 0;
  auto dfs = [&](auto dfs, int cur, int par) -> bool {
    if(vis[cur]) return false;
    vis[cur] = true;
    bool updated = false;
    for(int ne: G[cur]) {
      int e = min(cur, ne)*N+max(cur, ne);
      if(ne != par && done[e]==-1) {
        updated = true;
        if(vis[ne]) {
          if(abs(depth[cur]-depth[ne])%2) {
            done[e] = col;
            cnt++;
          }
        } else {
          done[e] = col;
          cnt++;
          depth[ne] = depth[cur]+1;
          dfs(dfs, ne, cur);
        }
      }
    }
    return updated;
  };
  while(cnt < N*(N-1)/2) {
    depth = vector<int>(N);
    vis = vector<bool>(N);
    rep(i, N) if(!vis[i]) dfs(dfs, i, -1);
    col++;
  }
  rep(i, N) {
    for(int j=i+1; j<N; j++) cout << done[i*N+j]+1 << ' ';
    cout << "\n";
  }
  return 0;
}


Measured memory_bytes: 5176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int d[11][11];
    int h,w;
    cin>>h>>w;
    
    rep(i,10)rep(j,10)cin>>d[i][j];
    
    rep(k,10){
        rep(i,10){
            rep(j,10){
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    
    int ans = 0;
    rep(i,h){
        rep(j,w){
            int a;
            cin>>a;
            if(a==-1)continue;
            ans += d[a][1];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>

typedef long long ll;

using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<pair<ll, ll>> AB(N);
  for(ll i=0;i<N;i++)
  {
    ll a, b;
    cin >> a >> b;
    AB[i] = make_pair(b, a);
  }
  ll time = 0;
  sort(AB.begin(), AB.end());
  for (ll i=0;i<N;i++)
  {
    time+=AB[i].second;
    if (time > AB[i].first)
    {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<bitset>
std::bitset<2000010>v;
int main(){
	int N,A,S=0;
	scanf("%d",&N);
	v[0]=1;
	for(int i=N;i--;){
		scanf("%d",&A);
		S+=A;
		v|=v<<A;
	}
	for(int i=S/2;;i--)if(v[i])return printf("%d\n",S-i),0;
}

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

int main(){
	long long s;
	scanf("%lld", &s);
	
	if(s % 1000000000 == 0)printf("0 0 1000000000 0 0 %lld\n", s / 1000000000);
	else printf("0 0 1000000000 1 %lld %lld\n", 1000000000 - s % 1000000000, (s + 1000000000 - 1) / 1000000000);
	
	return 0;
}


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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int n;
using P = pair<int, int>;

struct edge {
    int to;
    int cost;
};

vector<int> dist;
vector<int> prever;
vector<vector<edge> > g;

void dijkstra(int s) {
    dist = vector<int>(n, Inf);
    prever = vector<int>(n, -1);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P> > pq;
    pq.push(P(0, s));

    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;

        rep (i, g[v].size()) {
            edge e = g[v][i];
            if (dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                prever[e.to] = v;
                pq.push(P(dist[e.to], e.to));
            }
        }
    }
}

vector<int> get_path(int t) {
    vector<int> path;
    for (; t != -1; t = prever[t]) path.push_back(t);
    reverse(path.begin(), path.end());

    return path;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int m;
    cin >> n >> m;
    g = vector<vector<edge> >(n);
    vector<vector<bool> > used(n, vector<bool>(n, true));
    rep (i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        edge e;
        e.to = b, e.cost = c;
        g[a].push_back(e);
        e.to = a;
        g[b].push_back(e);
        used[a][b] = used[b][a] = false;
    }
    rep (i, n) {
        dijkstra(i);
        rep (j, n) {
            if (i == j) continue;
            auto v = get_path(j);
            rep (k, v.size() - 1) used[v[k]][v[k + 1]] = used[v[k + 1]][v[k]] = true;
            
        }
    }
    int res = 0;
    rep (i, n) {
        rep (j, n) if (!used[i][j]) res++;
    }
    cout << res / 2 << endl;
    
    return 0;
}



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

int main() {
  int H, W;
  cin >> H >> W;
  char pic[H][W];
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> pic[i][j];
    }
  }
  for(int i = 0; i < H+2; i++){
    for(int j = 0; j < W+2; j++){
      	if ( !((i > 0 && i <= H) && (j > 0 && j <= W)) ){
    	  cout << "#";
        } else {
          cout << pic[i-1][j-1];
        }
    }
    cout << endl;
  } 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll mincost_y[100005],mincost_s[100005],ans[100005];
vector<P> node[100005],snode[100005];
const ll inf=1744174417441744;
#define int ll
ll dijkstra_y(ll s){
  for(int i=0;i<100005;i++) mincost_y[i]=inf;
  vector<bool> used(100005,false);
  mincost_y[s]=0;
  priority_queue<P,vector<P>,greater<P>> pque;
  pque.push(P(0,s));
  while(!pque.empty()){
    P p=pque.top();
    pque.pop();
    ll cos=p.first,pos=p.second;
    if(used[pos]) continue;
    used[pos]=true;
    for(int i=0;i<node[pos].size();i++){
      ll ncos=node[pos][i].first+cos,to=node[pos][i].second;
      if(mincost_y[to]>ncos&&!used[to]){
        mincost_y[to]=ncos;
        pque.push(P(ncos,to));
      }
    }
  }
}
ll dijkstra_s(ll t){
  for(int i=0;i<100005;i++) mincost_s[i]=inf;
  vector<bool> used(100005,false);
  mincost_s[t]=0;
  priority_queue<P,vector<P>,greater<P>> pque;
  pque.push(P(0,t));
  while(!pque.empty()){
    P p=pque.top();
    pque.pop();
    ll cos=p.first,pos=p.second;
    if(used[pos]) continue;
    used[pos]=true;
    for(int i=0;i<snode[pos].size();i++){
      ll ncos=snode[pos][i].first+cos,to=snode[pos][i].second;
      if(mincost_s[to]>ncos&&!used[to]){
        mincost_s[to]=ncos;
        pque.push(P(ncos,to));
      }
    }
  }
}
signed main(){
  ll n,m,s,t;
  cin>>n>>m>>s>>t;
  for(ll i=1;i<=m;i++){
    ll u,v,a,b;
    cin>>u>>v>>a>>b;
    node[u].push_back(P(a,v));
    node[v].push_back(P(a,u));
    snode[u].push_back(P(b,v));
    snode[v].push_back(P(b,u));
  }
  dijkstra_y(s);
  dijkstra_s(t);
  ll fcost=1e15;
  ans[n-1]=fcost-(mincost_y[n]+mincost_s[n]);
  for(ll i=n-1;i>0;i--){
    ans[i-1]=max(ans[i],fcost-(mincost_y[i]+mincost_s[i]));
  }
  for(int i=0;i<n;i++) cout<<ans[i]<<endl;
}


Measured memory_bytes: 19196
#include <iostream>
#include <string>
using namespace std;
int main()
{
 
	int n;
	int cnt=0;
	string str;

	cin >> str;
	cin >> n;

	for(int i=0 ;i<n ;i++){

		string ring;
		cin >> ring;

		ring = ring + ring;

		string::size_type index = ring.find( str ); 
	    if( index == string::npos ){
	    }
	    else{
		     cnt ++;
	    }
	}	

	cout << cnt <<endl;
	return 0;
	}

Measured memory_bytes: 0
N, K = map(int,input().split())

A = [1 for i in range(N)]
d = [0 for i in range(K)]

for i in range(K):
    d[i] = int(input())
    temp = list(map(int, input().split()))
    for t in temp:
        A[t-1] = 0

print(sum(A))

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n;
string s;
i64 a[101010], b[101010], c[101010], d[101010];

i64 mod_pow(i64 x, i64 y, i64 mod){
	i64 res = 1;
	while(y > 0){
		if(y & 1) res = res * x % mod;
		x = x*x %mod;
		y >>= 1;
	}
	return res;
}

int main(){
	cin >> s;
	n = s.size();
	
	i64 ans = 0;
	for(int i = 0; i < n; i++){
		d[i+1] = d[i];
		a[i+1] = a[i];
		b[i+1] = b[i];
		c[i+1] = c[i];
		if(s[i] == '?') d[i+1]++;
		if(s[i] == 'A') a[i+1]++;
		if(s[i] == 'B') b[i+1]++;
		if(s[i] == 'C') c[i+1]++;
	}
	//Bの位置から計算
	for(int i = 1; i < n; i++){
		if(s[i] == 'B'){
			ans += a[i] * (c[n] - c[i]) % INF * mod_pow(3,d[n],INF);
			ans %= INF;
			ans += a[i] * (d[n] - d[i]) % INF * mod_pow(3,d[n]-1,INF);
			ans %= INF;
			ans += d[i] * (c[n] - c[i]) % INF * mod_pow(3,d[n]-1,INF);
			ans %= INF;
			ans += d[i] * (d[n] - d[i]) % INF * mod_pow(3,d[n]-2,INF);
			ans %= INF;
		}
		if(s[i] == '?'){
			ans += a[i] * (c[n] - c[i]) % INF * mod_pow(3,d[n]-1,INF);
			ans %= INF;
			ans += a[i] * (d[n] - d[i]-1) % INF * mod_pow(3,d[n]-2,INF);
			ans %= INF;
			ans += d[i] * (c[n] - c[i]) % INF * mod_pow(3,d[n]-2,INF);
			ans %= INF;
			ans += d[i] * (d[n] - d[i]-1) % INF * mod_pow(3,d[n]-3,INF);
			ans %= INF;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main(void){
	char str[1001];
	int i=0;
	scanf("%s",str);
	while(str[i]!='\0'){
		str[i]-=3;
		if(str[i]<'A'){
			str[i]+=26;
		}
		i++;
	}
	printf("%s\n",str);
	return 0;
}

Measured memory_bytes: 524
/**
 *    author:  [itmo] enot.1.10
 *    created: 23.10.2016 15:01:32       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

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

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 1e5 + 10;

int a[N];


int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    int k, n;
    scanf("%d%d", &k, &n);
    forn(i, n) scanf("%d", a + i);
    set<pi> S;
    forn(i, n) S.insert(mp(-a[i], i));
    int res = 0;
    int w = -1;
    forn(_, k)
    {      
        auto it = S.begin();
        if (it->S == w && sz(S) >= 2)
        {
            it++;
            int i = it->S;
            S.erase({-a[i], i});
            a[i]--;
            if (a[i]) S.insert({-a[i], i});
            w = i;
            continue;
        }
        int i = it->S;
        if (i == w) res++;
        S.erase({-a[i], i});
        a[i]--;
        if (a[i]) S.insert({-a[i], i});
            w = i;
        }
    printf("%d\n", res);
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


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

using namespace std;

#define DIM 59
#define INF ((long long)1e18+9ll)
#define pairll pair<int,int>
#define fi first
#define se second
#define ld long double
#define amen exit(0)
#define endl '\n'
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)

long long i,j,k,l,n,m,res,timer,mask;

long long edges[DIM],tin[DIM],tout[DIM],par[DIM];

vector<pairll>e;

vector<long long>a[DIM];

void dfs(long long v,long long p){
    tin[v]=++timer;

    par[v]=p;

    for(auto to:a[v]){
        if(to==p)continue;
        dfs(to,v);
    }

    tout[v]=++timer;
}

bool upper(long long v,long long u){
    return tin[v]<=tin[u] && tout[u]<=tout[v];
}

long long lca(long long v,long long u){
    if(upper(v,u))return v;
    if(upper(u,v))return u;

    while(1){
        if(upper(v,u))return v;
        v=par[v];
    }
}

bool check(long long v,long long v1,long long v2,long long lca){
    if(upper(lca,v) && (upper(v,v1) || upper(v,v2)))return true;
    return false;
}

int main()
{
    fast;

    cin>>n;

    for(i=1;i<n;i++){
        cin>>k>>l;
        a[k].push_back(l);
        a[l].push_back(k);
        e.push_back({k,l});
    }

    dfs(1,1);

    cin>>m;

    for(i=1;i<=m;i++){
        cin>>k>>l;

        long long lc=lca(k,l);

        mask=0;

        long long j=0;

        for(auto to:e){
            if(check(to.fi,k,l,lc) && check(to.se,k,l,lc))mask+=(1ll<<j);
            j++;
        }

        edges[i]=mask;
    }

    res=(1ll<<(n-1));

    for(mask=1;mask<(1ll<<m);mask++){
        long long mm=0;
        for(j=1;j<=m;j++){
            if(mask&(1<<(j-1)))mm|=edges[j];
        }

        long long cnt=n-1-__builtin_popcountll(mm);

        if(__builtin_popcountll(mask)%2==1)res-=(1ll<<cnt);
        else res+=(1ll<<cnt);

    //    cout<<(bitset<3>)mask<<' '<<cnt<<endl;
    }

    cout<<res<<endl;

    amen;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main()
{
    int a,b;
    char x[100],y[100],m[100];
    scanf("%s %s",x,y);
    scanf("%d %d",&a,&b);
    scanf("%s",m);
    if(strcmp(x,m)==0)
    {
        printf("%d %d",a-1,b);
    }
    else
    {
        printf("%d %d",a,b-1);
    }

    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

int main(){
  int N,C;
  cin >> N >> C;
  int c[N][N];
  vector<vector<int>> t(3,vector<int>(C,0));
  int D[C][C];
  vector<int> MOD(C,0);

  for(int i = 0; i < C; i++) for(int j = 0; j < C; j++) cin >> D[i][j];
  for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) {
    cin >> c[i][j];
    t[(i+j)%3][c[i][j]-1] ++;
  }

  long ans = 1e15;
  for(int i = 0; i < C; i++){
    for(int j = 0; j < C; j++){
      if(i==j) continue;
      for(int k = 0; k < C; k++){
        if(i==k || j==k) continue;
        int cnt = 0;
        for(int l = 0;l < C; l++) cnt += D[l][i] * t[0][l];
        for(int l = 0;l < C; l++) cnt += D[l][j] * t[1][l];
        for(int l = 0;l < C; l++) cnt += D[l][k] * t[2][l];
        ans = min(ans,(long)cnt);
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}


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

template<typename T>
void print_ary(std::vector<T> ary, char delim = '\n') {
    for(int i = 0; i < ary.size()-1; i++) {
        std::cout << ary[i] << delim;
    }
    std::cout << ary[ary.size()-1];
}


template<typename T>
void insertion_sort(std::vector<T>&& ary) {
    for (int i = 1; i < ary.size(); i++) {
        int target = ary[i];
        int j = i - 1;
        while(j >= 0 &&  ary[j] > target) {
            ary[j+1] = ary[j];
            j--;
        }
        ary[j+1] = target;
        print_ary(ary, ' ');
        std::cout << std::endl;
    }
}

template<typename T>
void bubble_sort(std::vector<T> && ary) {
    int n = ary.size();
    bool flag = true;
    int counter = 0;
    while (flag) {
        flag = false;
        for (int j = n - 1; j > 0; j--) {
            if (ary[j] < ary[j - 1]) {
                std::swap(ary[j], ary[j - 1]);
                flag = true;
                counter++;
            }
        }
    }
    print_ary(ary, ' ');
    std::cout << std::endl << counter << std::endl;;
}

int main(int argc, char const* argv[])
{
    int n;
    std::cin >> n;
    std::vector<int> ary(n);
    for (auto &i: ary) {
        std::cin >> i;
    }
    bubble_sort(std::move(ary));
    return 0;
}

Measured memory_bytes: 3120
// abc177_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
//struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int H, W;
    cin >> H >> W;
    vector<int> A(H), B(H);
    REP(i, H) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    set<P> st;
    REP(i, W) st.emplace(i, i);

    multiset<int> diff;
    REP(i, W) diff.insert(0);

    REP(i, H){

        auto it = st.lower_bound(P(A[i], 0));
        int mx = -1;
        while (it != st.end() && it->first <= B[i]+1){
            diff.erase(diff.lower_bound(it->first - it->second));
            mx = max(mx, it->second);
            st.erase(it++);
        }

        if (mx != -1 && B[i] != W-1){
            st.emplace(B[i]+1, mx);
            diff.emplace(B[i]+1-mx);
        }

        if (st.empty()){
            print(-1);
            continue;
        }

        int ans = *diff.begin() + i+1;

        print(ans);
    }

    return 0;
}


Measured memory_bytes: 23592