akhauriyash/Code-Regression huggingface dataset:
#C-HandV
import copy
ans = 0
S = []
S_red = []
S_kuro = []
H_parameter = [[0]]
W_parameter = [[0]]
Hsize = 0
Wsize = 0
n1 = 0
n2 = 0
n3 = 0
n4 = 0
n5 = 0
n6 = 0

#入力
H,W,K   = map(int, input().split())
for i in range(H):
    S.append(list(map(str, input())))

#red操作
#H
for n1 in range(1,H+1,1):
    H_parameter.append([n1])
    for n2 in range(1,H+1,1):
        if n2 > n1:
            H_parameter.append([n1,n2])
            for n3 in range(1,H+1,1):
                if n3 > n2:
                    H_parameter.append([n1,n2,n3])
                    for n4 in range(1,H+1,1):
                        if n4 > n3:
                            H_parameter.append([n1,n2,n3,n4])
                            for n5 in range(1,H+1,1):
                                if n5 > n4:
                                    H_parameter.append([n1,n2,n3,n4,n5])
                                    for n6 in range(1,H+1,1):
                                        if n6 > n5:
                                            H_parameter.append([n1,n2,n3,n4,n5,n6])
Hsize = len(H_parameter)
#print(H_parameter)
#print(Hsize)

#W
n1 = 0
n2 = 0
n3 = 0
n4 = 0
n5 = 0
n6 = 0

for n1 in range(1,W+1,1):
    W_parameter.append([n1])
    for n2 in range(1,W+1,1):
        if n2 > n1:
            W_parameter.append([n1,n2])
            for n3 in range(1,W+1,1):
                if n3 > n2:
                    W_parameter.append([n1,n2,n3])
                    for n4 in range(1,W+1,1):
                        if n4 > n3:
                            W_parameter.append([n1,n2,n3,n4])
                            for n5 in range(1,W+1,1):
                                if n5 > n4:
                                    W_parameter.append([n1,n2,n3,n4,n5])
                                    for n6 in range(1,W+1,1):
                                        if n6 > n5:
                                            W_parameter.append([n1,n2,n3,n4,n5,n6])
Wsize = len(W_parameter)
#print(W_parameter)
#rint(Wsize)
Qcount = 0

for l in range(Hsize):
    ll = len(H_parameter[l])
    for m in range(Wsize):
        S_red.clear()
        S_red = copy.deepcopy(S)
        mm = len(W_parameter[m])
        for q in range(ll):
            for r in range(mm):
                if H_parameter[l] != [0]:
                    for p in range(W):
                        S_red[H_parameter[l][q]-1][p]= 'R'
                if W_parameter[m] != [0]:            
                    for s in range(H):
                        S_red[s][W_parameter[m][r]-1]= 'R'
                
        # 黒の数
        Q = 0
        Qcount += 1
        S_kuro.clear()
        for j in range(H):
            for k in range(W):
                S_kuro.append(S_red[j][k])
        Q =S_kuro.count('#')
        #print(l,m,Q)
        #print(S_kuro)          
        if Q == K : ans += 1

# 出力
print(ans)

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;

int main() {
    int N, M;
    cin >> N >> M;
    map<int, int> cnt;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
    }

    for (auto mp : cnt) {
        if (mp.second % 2 != 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 4352
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		string S = Console.ReadLine();
		List<int> dif = new List<int>();
        for(var i = 0; i < S.Length - 2; i++)
		{
			string si = S.Substring(i, 3);
			int n = int.Parse(si);
			dif.Add(Math.Abs(n - 753));

		}
		dif.Sort();
		Console.WriteLine(dif[0]);

		
	}
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
struct EDGE { int from, to, cost; };
bool operator < (const EDGE& a, const EDGE& b) {
	return a.cost < b.cost;
}

vector<EDGE> g;
int par[10000];

int find(int x)
{
	if (par[x] == x) return x;
	return par[x] = find(par[x]);
}

bool _union(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y) return false;
	par[x] = y;
	return true;
}

int main()
{
	int V, E;
	scanf("%d %d", &V, &E);
	
	for (int i = 0; i < V; i++) par[i] = i;
	
	for (int i = 0; i < E; i++){
		int s, t, w;
		scanf("%d %d %d", &s, &t, &w);
		g.push_back((EDGE){s, t, w});
	}
	
	sort(g.begin(), g.end());
	
	int res = 0;
	for (int i = 0; i < g.size(); i++){
		EDGE &e = g[i];
		if (_union(e.from, e.to)) res += e.cost;
	}
	
	printf("%d\n", res);
	
	return 0;
}

Measured memory_bytes: 2756
if __name__ == '__main__':
    N = int(input())
    C = list(input())
    cnt = 0
    red_cnt = 0
    for c in C:
        if c == 'R':
            red_cnt += 1

    for i in range(red_cnt):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
                    red_cnt = j+1
    print(cnt)

Measured memory_bytes: 82496
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N, 0);
    for (int i = 0; i < N; i++)
        cin >> h[i];

    int ans = 0;
    for (int i = 0; i < N; i++)
        if (h[i] >= K) ans++;

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<ll> a(n), s(n), t(n);
    rep(i, 0, n) {
        cin >> a[i];
        s[i] = t[i] = a[i];
        if (i) s[i] += s[i - 1];
        if (i > 1) t[i] += t[i - 2];
    }
    while (q--) {
        int x;
        cin >> x;
        int l = 1, r = (n + 1) / 2 + 1;
        while (r - l > 1) {
            int mid = (r + l) / 2;
            if (n - 2 * mid < 0) {
                int k = a[n - mid];
                if (abs(x - a[0]) <= abs(k - x))
                    l = mid;
                else
                    r = mid;
                continue;
            }
            int lb = a[n - 2 * mid], rb = a[n - 1 - mid];
            int lout = a[n - 2 * mid - 1], rout = a[n - mid];
            if (x - lout > rb - x && x - lb <= rout - x) {
                l = mid, r = mid + 1;
                break;
            }
            if (x - lb <= rout - x || x - a[n - 2 * mid + 1] <= rout - x)
                l = mid;
            else
                r = mid;
        }
        ll ans = s[n - 1] - s[n - 1 - l];
        if (n - 1 - 2 * l >= 0) ans += t[n - 1 - 2 * l];
        debug(l);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include<iostream>
#include <algorithm>
#include<stdio.h>
#include<string.h>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include<vector>
using namespace std;
#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define Fs first
#define Sc second
#define endl "\n"
#define MOD 1000000007
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long lli;

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

int main()
{
    lli t,n;
    cin>>n;
    cin>>t;
    lli g=gcd(n, t);
    //cout<<g<<endl;
    //cout<<n*t<<endl;
    lli lcm=(n*t)/g;
    cout<<lcm<<endl;
    return 0;
}


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

using namespace std;
int main()
{
		ios_base::sync_with_stdio(false);
	cin.tie(NULL);
int n;
cin>>n;

string s;
cin>>s;
int l=s.length();
if(l<=n)
cout<<s<<endl;
else
{
for(int i=0;i<n;i++)
cout<<s[i];	
cout<<"..."<<endl;
}

}



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

int main() {

	long long int a,b,sum=0; cin>>a>>b;
	if((b-a)>= 672) {
		cout<<"0"<<endl;
		return 0;
	} sum=((a%2019)*((a+1)%2019))%2019;
	for(int i=a;i<b;i++) {
		for(int j=i+1;j<=b;j++) {
			int temp=((i%2019)*(j%2019))%2019;
			if(temp <sum) sum=temp;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, t;
    cin >> n >> t;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    vi b(n, -1);
    ll mi = INF, ma = -INF;
    ll ans = 0;
    rep(i, n){
        chmax(ma, a[i]-mi);
        chmin(mi, a[i]);
    }
    mi = INF;
    rep(i, n){
        if(a[i]-mi == ma){
            ans++;
        }
        chmin(mi, a[i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int count = 0;
    while(1){
        if(count%2 == 0){
            c-=b;
            if(c <= 0){
                cout << "Yes" << endl;
                return 0;
            }
        }else {
            a-=d;
            if(a <= 0){
                cout << "No" << endl;
                return 0;
            }
        }
        count++;
    }
    return 0;
}

Measured memory_bytes: 3652
/*
                                Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
 
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
 
#include <bits/stdc++.h>
 
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
 
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x) % M;
        x=(x*x)% M;
        n=n/2;
    }
    return result % M;
}
signed main()
{   jaldi
	int n;
	cin>>n;
	cout<<power(n,2);
	
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
        
        if (a == b + c) {
            System.out.print("Yes");
        } else if (b == c + a) {
            System.out.print("Yes");
        } else if (c == a + b) {
            System.out.print("Yes");
        } else {
            System.out.print("No");
        }

        sc.close();
    }
}

Measured memory_bytes: 21712
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
 
int main() {

    string s;
    cin >> s;

    vector<int> a(1000);
    rep(i,1000)  a[i]=0;
    rep(i,4) {
        a[s[i]-'0']++;
    }
    int count=0;
    rep(i,1000) {
        if(a[i]==2) count++;
    }

    if(count==2) cout<<"Yes"<<endl;
    else    cout<<"No"<<endl;

 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	string s;
	cin >> s;
	bool flg=true;
	int n=s.size();
	for(int i=0;i<(n-1)/2;i++)
	{
		cerr << s[i] << s[n-i-1] << endl;
		if(s[i]!=s[n-i-1])flg=false;
	}
	cerr << " " << endl;
	for(int i=0;i<n/4;i++)
	{
		cerr << s[i] << s[n/2-i-1] << endl;
		if(s[i]!=s[n/2-i-1])flg=false;
	}
	cerr << " " << endl;
	for(int i=0;i<n/4;i++)
	{
		cerr << s[i+n/2+1] << s[n-i-1] << endl;
		if(s[i+n/2+1]!=s[n-i-1])flg=false;
	}
	cout << (flg ? "Yes":"No") << endl;







}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    cout << n * n * n << endl;
}

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



Measured memory_bytes: 3616
import itertools
status = [(0, 1) for _ in range(3)]
state = list(itertools.product(*status))
num = [int(i) for i in input()]
for ptn in state:
  ans = num[0]
  ans_str = str(num[0])
  for i,ope in enumerate(ptn):
    if ope == 0:
      ans += num[i+1]
      ans_str += ("+" + str(num[i+1]))
    else:
      ans -= num[i+1]
      ans_str += ("-" + str(num[i+1]))
  if ans == 7:
    break
print(ans_str+"=7")


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#define Min(a,b) a=min(a,b);
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define H 4010
#define N (1<<12)
class RSQ{
private:
    ll dat[N*2];
    ll dfs(int l,int r,int a,int b,int k){
	if(l<=a&&b<=r)return dat[k];
	if(b<=l||r<=a)return 0;
	int vl=dfs(l,r,a,(a+b)/2,k*2+1);
	int vr=dfs(l,r,(a+b)/2,b,k*2+2);
	return vl+vr;
    }
public:
    void Init(){
	lol(i,2*N)dat[i]=0;
    }
    void Update(int i,int x){
	i+=N-1;
	dat[i]=x;
	while(i>0){
	    i=(i-1)/2;
	    dat[i]=dat[i*2+1]+dat[i*2+2];
	}
    }
    ll Sum(int l,int r){
	if(r>N-2)r=N-2;
	if(l>r)return 0;
	return dfs(l,r+1,0,N,0);
    }
};
ll h,w,p,q;
//bool t[H][H];
unordered_set<int> st[H];
ll f[H][H],g[H][H];
int main(){
    cin>>h>>w>>q>>p;
    lol(i,h)lol(j,w)f[i][j]=g[i][j]=mod;
    lol(i,p){int y,x;cin>>y>>x;st[y-1].insert(x-1);}
    lol(i,h){
	ll cnt=-1;
	lol(j,w){
	    if(st[i].find(j)!=st[i].end())cnt=-1;
	    else cnt++;
	    Min(g[i][j],cnt);
	}
	cnt=-1;
	for(int j=w-1;j>=0;j--){
	    if(st[i].find(j)!=st[i].end())cnt=-1;
	    else cnt++;
	    Min(f[i][j],cnt);
	}
    }
    lol(j,w){
	ll cnt=-1;
	lol(i,h){
	    if(st[i].find(j)!=st[i].end())cnt=-1;
	    else cnt++;
	    Min(f[i][j],cnt);
	}
	cnt=-1;
	for(int i=h-1;i>=0;i--){
	    if(st[i].find(j)!=st[i].end())cnt=-1;
	    else cnt++;
	    Min(g[i][j],cnt);
	}
    }
    ll ans=0;
    lol(r,h+w-1){
	int sy,sx;
	if(r<h)sy=r,sx=0;
	else sy=h-1,sx=r-h+1;
	ll n=min(min(r+1,h+w-1-r),min(h,w));
	vector<pair<ll,ll> >v;
	lol(i,n){
	    int y=sy-i,x=sx+i;
	    if(g[y][x]==-1)continue;
	    v.push_back(make_pair(i-g[y][x],i));
	}
	sort(v.begin(),v.end());
	int last=0;
	RSQ seg;seg.Init();
	lol(i,n){
	    int y=sy-i,x=sx+i;
	    if(f[y][x]==-1)continue;
	    while(last<v.size()){
		if(v[last].first<=i){
		    seg.Update(v[last].second,1);
		    last++;
		}
		else break;
	    }
	    ans+=seg.Sum(i+q-1,i+f[y][x]);
	}
    }
    cout<<ans<<endl;
    return 0;
}



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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int a[3];
  rep(i, 3) cin >> a[i];

  sort(a, a+3);
  cout << a[0] + a[1] << endl;
  
  return (0);
}

Measured memory_bytes: 3616
#include<stdio.h>
int x[10000],y[10000];
int main(void)
{
	int i,j,h,w,n,z[10000],e[10000],tol,su,sm;
	scanf("%d %d %d",&h,&w,&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&x[i],&y[i]);
	}
	su=0;
	sm=0;
	tol=0;
	for(i=0;i<n;i++){
		e[i]=x[i]-x[i+1];
		z[i]=y[i]-y[i+1];
		z[n-1]=0;
		e[n-1]=0;
		if((e[i]>0&&z[i]>0)||(e[i]<0&&z[i]<0)){
		if(e[i]<0&&z[i]<0){
				e[i]=e[i]*-1;
				z[i]=z[i]*-1;
			}
			if(e[i]<z[i]){
				su=su+z[i];
			}
			else{
				su=su+e[i];
			}
		}
		else{
			if(e[i]<0){
				e[i]=e[i]*-1;
			}
			if(z[i]<0){
				z[i]=z[i]*-1;
			}
			sm=sm+(e[i]+z[i]);
		}
	}
	tol=su+sm;
	printf("%d\n",tol);
	return 0;
}


Measured memory_bytes: 2736
// template for atcoder beginners
// when you create a *.cpp file, this template is loaded

#include <bits/stdc++.h>
using namespace std;

double average(double x, double y) {
  return (x + y) / 2; 
}

int main() {
  int N;
  cin >> N;
  double tmp;
  vector<double> V(N);
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    V.at(i) = tmp;
  }
  sort(V.begin(), V.end());
  for (int i = 0; i < N-1; i++) {
    V.at(i+1) = average(V.at(i), V.at(i+1));
  }
  cout << V.at(N-1) << endl;
}



Measured memory_bytes: 256
#include<cstdio>

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

using namespace std;

int day[128];
int dp[128][3][2];

int main(void){
	
	int n,k;
	int a,b;
	const int X = 10000;
	
	scanf("%d %d", &n, &k);
	
	rep(i,k){
		scanf("%d %d", &a, &b);
		day[a] = b;
	}
	
	rep(i,3){
		dp[1][i][0] = 1;
	}
	
	for(int i = 1; i <= n; i++){
		rep(j,3){
			if(day[i] != 0 && day[i] != j+1){
				dp[i][j][0] = 0;
				dp[i][j][1] = 0;
			}
			else{
				rep(l,3){
					if(l!=j)dp[i][j][0] += dp[i-1][l][0] + dp[i-1][l][1];
				}
				dp[i][j][1] += dp[i-1][j][0];
				dp[i][j][0]%=X;
				dp[i][j][1]%=X;
			}
		}
	}
	int ans = 0;
	rep(i,3){
		rep(j,2){
			ans += dp[n][i][j];
		}
	}
	printf("%d\n", ans%X);
	return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, m;
int memo[1010][1010];
pair<int, int> cat[1010];
int catsum[20100];
int foodx[1010];

int calc(int depth, int prev, int target) {
  if (memo[depth][prev] != -1) { return memo[depth][prev]; }
  if (depth == m + 1) { return depth; }
  int ret = m + 1;
  int x = foodx[depth];
  int px = max((foodx[prev] + x) / 2, 0);
  ret = calc(depth + 1, prev, target);
  int next = calc(depth + 1, depth, target);
  if (next != 10000) {
    int nx = min((foodx[next] + x) / 2, 20001);
    int sum = catsum[nx] - catsum[px];
    if (sum <= target) { ret = depth; }
  }
  //cout << depth << " " << prev << " " << ret << endl;
  return memo[depth][prev] = ret;
}

int main() {
  while (scanf("%d %d", &n, &m), n|m) {
  REP(i, n) {
    int x, y, cnt;
    scanf("%d %d %d", &x, &y, &cnt);
    x += 10001;
    cat[i] = make_pair(x, cnt);
  }
  sort(cat, cat + n);
  cat[n] = make_pair(100000000, 0);
  int sum = 0;
  int index = 0;
  FOREQ(x, 0, 20001) {
    while (cat[index].first == x) { sum += cat[index++].second; }
    catsum[x] = sum;
  }
  REP(i, m) {
    scanf("%d", &foodx[i + 1]);
    foodx[i + 1] += 10001;
  }
  foodx[0] = -100000000;
  foodx[m + 1] = 100000000;
  sort(foodx, foodx + m + 2);
  MEMSET(memo, -1);
  int maxcnt = 0;
  FOREQ(i, 1, m) {
    int x = foodx[i];
    int px = max((foodx[i - 1] + x) / 2, 0);
    int nx = min((foodx[i + 1] + x) / 2, 20001);
    int sum = catsum[nx] - catsum[px];
    maxcnt = max(maxcnt, sum);
  }
  int left = 0;
  int right = maxcnt;
  while (left != right) {
    MEMSET(memo, -1);
    int mid = (left + right) / 2;
    //cout << mid << endl;
    if (calc(1, 0, mid) != m + 1) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  printf("%d\n", left);
}
}

Measured memory_bytes: 4996
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
#define moder 1000000007
#define inf 1000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
map<int, int> factor(int m) {
	map<int, int>res;
	for (int i = 2; i*i <= m; i++) {
		while (m%i == 0) {
			res[i]++;
			m /= i;
		}
	}
	if (m != 1)res[m]++;
	return res;
}

/*--------Library Zone!--------*/


signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << " " << max(a + b - n, (int)0) << endl;
	endre;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        if (k % 2 == 1){
            System.out.println(k/2 * (k+1)/2);
        }else {
            System.out.println(k/2 * k/2);
        }
    }
}


Measured memory_bytes: 21716
import math
N = int(input())
list = list()
sum = 0
for i in range(N):
    x, y = map(int, input().split())
    list.append((x, y))
for i in range(N):
    for j in range(i+1, N):
        sum += math.sqrt((list[i][0]-list[j][0])**2 + (list[i][1]-list[j][1])**2)
print(sum*2/N)


Measured memory_bytes: 3060
/*
 *  Created on: 29 / 4 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n)
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(int i=m;i<n;i++)

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

//const ll mod = 1e9 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
vector<ll>v;
ll generatdivisors(ll n)
{
	for (ll i = 3; i <= n; i+=3)
	{
		v.pb(i);
	}
	for (ll i = 5; i <= n; i+=5)
	{
		v.pb(i);
	}
	sort(all(v));
	iq(v);
	ll c=0;
	for (auto it : v)
	{
	    c+=it;
	}
	return c;
}
int main()
{
    //stp(20);
    Eslam__Waheed
    ll n; cin >>n;
    ll a = (n*(n+1))/2;
    ll ans = a - generatdivisors(n);
    cout <<ans;
}

Measured memory_bytes: 11528
/**
 * @author torith
 * @date 2018-10-24
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string S,T;
    cin >> S;
    cin >> T;

    vector<string> cand;
    for (int i = 0; i < (int) (S.size() - T.size()) + 1; i++) {
        int frg = true;
        for (int j = i; j < (int) i + T.size(); ++j) {
            if (T[j - i] != S[j] && '?' != S[j]) frg = false;
        }
        if(frg){
            string a = S;
            a.replace(i,T.size(),T);
            replace(a.begin(),a.end(),'?','a');
            cand.push_back(a);
        }
    }

    if (cand.size() > 0) {
        sort(cand.begin(),cand.end());
        cout << cand[0] << "\n";
    }else{
        cout << "UNRESTORABLE" << "\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int arr[k],j,i,l;
	for(i=0 ; i<k ; i++) cin>>arr[i];
	for(i=n ; i<=n*10 ; i++){
		string x=to_string(i);
		int size=x.size();
		for(j=0 ; j<size ; j++){
			for(l=0 ; l<k ; l++){
				int y=x[j]-'0';
				if(y==arr[l]) break;
			}
			if(l!=k) break;
		}
		if(j==size){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;


int main()
{
    int a=0;
    char c;
    cin>>c;
    cout<<c;
    while(cin>>c)a++;
    cout<<a-1<<c<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		for(int i = 0;i < n;i++){
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		sc.close();
		double sum = 0.0;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				sum += Math.sqrt(Math.pow(x[i]-x[j], 2)+Math.pow(y[i]-y[j], 2));
			}
		}
		System.out.println(sum/n);
	}
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int INF = 1e9+5;

int main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    	cout.precision(10);
    	cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif
        
	int n;
	cin>>n;
	vvi dp(3,vi(n,0));
	
	int a,b,c;
	forn(i,n){
		cin>>a>>b>>c;
		if(i){
		 	dp[0][i] = max(dp[1][i-1],dp[2][i-1])+a;
		 	dp[1][i] = max(dp[0][i-1],dp[2][i-1])+b;
		 	dp[2][i] = max(dp[1][i-1],dp[0][i-1])+c;
		}else{
		 	dp[0][i]=a;dp[1][i]=b;dp[2][i]=c;
		}
		 	
	}
	cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<endl;
        #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif

	return 0;
}	



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  if(a>b){swap(a,b);}
  if(a==0){return b;}
  else{gcd(a,b%a);}
}
long atob(long a,long b,long d){
  return b/d-(a-1)/d;
}
int main(){
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long ans=b-a+1;
  long divisor=0;
  divisor+=atob(a,b,c)+atob(a,b,d)-atob(a,b,(c*d)/gcd(c,d));
  cout<<ans-divisor;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repe(i, n) for(int (i) = 0; i <= (n); (i)++)
#define repr(i, n) for(int (i) = (n); (i) > 0; --(i))
#define repre(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define elm1(pair) (pair).first
#define elm2(pair) (pair)).second
typedef long long ll;
typedef unsigned long long ull;
const ull MOD = 1000000007;
ull mpow(ull a, ull n);
ull inv_mod(ull a){return mpow(a, MOD-2);}

ull mpow(ull a, ull n)
{
    ull ans = 1;
    while(n>>=1){
        if(n & 1)(ans *= a)%= MOD;
        (a*=a)%=MOD;
    }
    return ans;
}

ull nCr(ull n, ull r)
{
    vector<ull> factorial(n+1);
    factorial[0]=1;
    rep(i, n)factorial[i+1] = factorial[i]*(i+1)%MOD;
    return factorial[n]*(inv_mod(factorial[n-r])%MOD*inv_mod(factorial[r])%MOD) % MOD;
}

ll dp[3000][3000] = {0};

//max manpuku
ll naps(vector<pair<ll, ll>> F, ll T, ll n, ll M)
{
    if(n >= F.size())return M;
    if(T <= 0.5)return M;
    return max(naps(F, T-F[n].first, n+1, M+F[n].second), naps(F, T, n+1, M));
}

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, N)cin >> h[i];
    vector<int> dp(N);
    dp[0] = 0;dp[1] = abs(h[0] - h[1]);
    for(int i = 2; i < N; i++){
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        for(int j = 2; j <= K && 0 <= (i - j); j++)
            dp[i] = min(dp[i], dp[i-j]+abs(h[i] - h[i-j]));
    }
    cout << dp[N-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;
long long int dp[51][51][3000] = {};

int main(void) {
	int n, a;
	int x[51];
	long long int total = 0;

	cin >> n >> a;
	FOR(i, 1, n) {
		cin >> x[i];
	}

	FOR(j, 0, n) {
		FOR(k, 0, n) {
			FOR(s, 0, n * 50) {
				if (j == 0 && k == 0 && s == 0) {
					dp[j][k][s] = 1;
				}
				else if (j >= 1 && s < x[j]) {
					dp[j][k][s] = dp[j - 1][k][s];
				}
				else if (j >= 1 && k >= 1 && s >= x[j]) {
					dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
				}
				else {
					dp[j][k][s] = 0;
				}
			}
		}
	}

	FOR(k, 1, n) {
		total += dp[n][k][k * a];
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 61184
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str  = sc.nextLine();
        String[] astr = str.split(" "); //状況に合わせて
        Boolean flag  = true;
        int[] in_data = Stream.of(astr).mapToInt(x->{
            try{
                return Integer.parseInt(x);
            }
            catch(Exception e){
                e.printStackTrace();
            }
            return 0;
        }).toArray();
        sc.close();

        int a= in_data[0];
        int b = in_data[1];
        int ans = a - b*2;
        if(ans > 0 ){
            System.out.println(ans);
        }else{
            System.out.println(0);
        }
    }

}

Measured memory_bytes: 29140
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 N;
  cin >> N;
  vector<i64> X(N);
  for (i64 i = 0; i < N; i++)
    cin >> X[i];
  i64 ans = 1e9;
  for (i64 i = 0; i <= 100; i++)
  {
    i64 tmp = 0;
    for (i64 j = 0; j < N; j++)
      tmp += (i - X[j]) * (i - X[j]);
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define int long long
using namespace std;

signed main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    
    B -= A;
    A = 0;
    bool judge = false;
    for (int i = 0; i < N; ++i) {
        int up = D * i - C * (N - 1 - i);
        int down = C * i - D * (N - 1 - i);
        if (down <= B && B <= up) judge = true;
        up *= -1;
        down *= -1;
        if (up <= B && B <= down) judge = true;
    }
    
    if (judge) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

int main() {
    string s;
    cin >> s;

    int len = s.length();
    for(int i = 0; i < len; i++){
        s[i] = s[i] == ',' ? ' ' : s[i];
    }
    cout << s << endl;
    return 0;
}


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

#define mx 200005
#define ll long long

int tc = 1, n;
ll a[mx], pre[mx], ans[mx], sum;
const ll mod  = 1e9+7;

void solve(int kk)
{
    cin >> n;
    for(int i=1; i<=n; i++)
        cin >> a[i];

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

    for(int i=1; i<n; i++){
        sum = (sum%mod + ans[i]%mod)%mod;
        if(sum<0)
            sum+=mod;
    }
    cout << sum << "\n";
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("D:\\Codings\\CPP\\input.in", "r", stdin);
    freopen("D:\\Codings\\CPP\\output.in", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int kk = 0;
    //cin >> tc;
    //scanf("%d", &tc);
    while (++kk <= tc)
        solve(kk);

    return 0;
}

Measured memory_bytes: 8276
#include <iostream>

int main() {
  int D;
  std::cin >> D;

  if (D == 25) {
    std::cout << "Christmas" << std::endl;
  } else if (D == 24) {
    std::cout << "Christmas Eve" << std::endl;
  } else if (D == 23) {
    std::cout << "Christmas Eve Eve" << std::endl;
  } else if (D == 22) {
    std::cout << "Christmas Eve Eve Eve" << std::endl;
  }
  return 0;
}

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

using namespace std;

int N, M;
int A[100][100];
string color[100];
//
// void dfs(int s) {
//   color[s] = "GRAY";
//   cout << "s:" << s+1 << endl;
//   // cout << "s:" << s << endl;
//   for (int t = 0; t < N; t++) {
//     if (A[s][t] == 1 && color[t] == "WHITE") {
//       dfs(t);
//     }
//   }
//   color[s] = "BLACK";
// }

int main() {
  cin >> N >> M;
  int a, b;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      A[i][j] = 0;
    }
  }
  // for (int i = 0; i < N; i++) {
  //   color[i] = "WHITE";
  // }
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    A[a-1][b-1] = 1;
    A[b-1][a-1] = 1;
    // A[a][b] = 1;
    // A[b][a] = 1;
  }
  int p[N];
  for (int i = 0; i < N; i++) {
    p[i] = i;
  }
  int count = 0;
  do {
    int prev = p[0];
    if (prev != 0) {
      continue;
    }
    bool can_go = true;

    for (int i = 1; i < N; i++) {
      if (A[prev][p[i]] != 1) {
        // cout << "prev:" << prev << ", " << "next:" << p[i] << ", ng"<< endl;
        can_go = false;
        break;
      } else {
        // cout << "prev:" << prev << ", " << "next:" << p[i] << ", ok"<< endl;
      }
      prev = p[i];
    }
    // cout << can_go << endl;
    if (can_go) {
      // cout << "count up" << endl;
      count++;
    }
  } while(next_permutation(p, p+N));
  cout << count << endl;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void print(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void print(H head, T ...tail) { cout << head << " "; print(tail...); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	vector<int> v(n);
	rep(i, 0, n) cin >> v[i];
	int ans = 0;
	rep(i, 0, n - 1) if (v[i] == i + 1) swap(v[i], v[i + 1]), ans++;
	if (v[n - 1] == n) swap(v[n - 2], v[n - 1]), ans++;
	cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;



int main(){
    int n;cin >> n;
    int ans = 0;
    int now = 0;
    int c = 0;
    for (int i = 0; i < n; i++) {
        int h;cin >> h;
        if(now>=h){
            now = h;
            c++;
        }
        else{
            ans = max(ans,c);
            c = 0;
            now = h;
        }
    }
    ans = max(ans,c);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}
int main()
{
        //input->compute->output//
        int X, Y, Z, K;
        cin >> X >> Y >> Z >> K;
        vector<ll> A(X), B(Y), C(Z);
        for (int i = 0; i < X; i++)
        {
                cin >> A[i];
        }
        for (int i = 0; i < Y; i++)
        {
                cin >> B[i];
        }
        for (int i = 0; i < Z; i++)
        {
                cin >> C[i];
        }
        sort(A.begin(), A.end(), greater<ll>());
        sort(B.begin(), B.end(), greater<ll>());
        sort(C.begin(), C.end(), greater<ll>());

        vector<ll> ABC;

        for (int a = 0; a < X; a++)
        {
                for (int b = 0; b < Y; b++)
                {
                        if ((a + 1) * (b + 1) > K)
                        {
                                break;
                        }

                        for (int c = 0; c < Z; c++)
                        {
                                if ((a + 1) * (b + 1) * (c + 1) > K)
                                {
                                        break;
                                }
                                ABC.push_back(A[a] + B[b] + C[c]);
                        }
                }
        }
        sort(ABC.begin(), ABC.end(), greater<ll>());

        for (int i = 0; i < K; i++)
        {
                cout << ABC[i] << endl;
        }

        return 0;
}


Measured memory_bytes: 1404
#!/usr/bin/python
# coding: utf-8

# AtCoder Beginner Contest 076
# D - AtCoder Express

from sys import stdin

# 移動距離を返す
def solve(ts, vs):
  if len(ts) == 0: return 0.0

  time  = sum(ts)  # 総時間
  limit = min(vs)  # 制限速度の下限
  if time / 2.0 <= limit:     # limitまで加速する時間がない
    return (time / 2.0) ** 2  # 半分の時間で加速，残りで減速

  # 制限速度まで達した区間がある
  if limit == 0:
    # その区間を除いて計算
    vzero = [i for i in range(len(vs)) if vs[i] == 0][0]
    return solve(ts[:vzero],     vs[:vzero]) + \
           solve(ts[vzero + 1:], vs[vzero + 1:])

  # 最初に1加速, 最後に1減速
  ts[0]  -= 1
  ts[-1] -= 1
  # 長さ0の区間を削除
  if ts[-1] == 0:
    ts = ts[:-1]
    vs = vs[:-1]
  if ts[0] == 0:
    ts = ts[1:]
    vs = vs[1:]
  # 制限時間を1減らす (= 現在速度を1増やす)
  vs = [v - 1 for v in vs]
  # 1加速, 速度1でtime-2秒移動, 1減速, の移動距離
  dist = time - 2 + 1
  return dist + solve(ts, vs)

# 文字列をintのリストに分解する
def splitToInt(line):
  words = line.strip().split()
  return [int(w) for w in words]

N = int(stdin.readline())
ts = splitToInt(stdin.readline())
vs = splitToInt(stdin.readline())
if len(ts) != N or len(vs) != N: raise
print(solve(ts, vs))

Measured memory_bytes: 2948
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

struct edge{int to,cost;};
int V;
vector<edge> G[100010];
ll d[100010];

void dijkstra(int s){
  priority_queue<pint,vector<pint>,greater<pint>> que;
  fill(d,d+V,longinf);
  d[s]=0;
  que.push(pint(0,s));
  
  while(!que.empty()){
    pint p=que.top(); que.pop();
    int v=p.second;
    if(d[v]<p.first)continue;
    rep(i,G[v].size()){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(pint(d[e.to],e.to));
      }
    }
  }
}

int main(){
  cin >> V;
  int a[V-1],b[V-1],c[V-1];
  rep(i,V-1){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--,b[i]--;
    G[a[i]].push_back({b[i],c[i]});
    G[b[i]].push_back({a[i],c[i]});
  }
  int q,k;
  cin >> q >> k;
  k--;
  dijkstra(k);
  rep(i,q){
    int x,y;
    cin >> x >> y;
    x--,y--;
    cout << d[x]+d[y] << endl;
  }
return 0;}

Measured memory_bytes: 11392
a = input()
b = input()
c = input()

la = len(a)
lb = len(b)
lc = len(c)

MAX = 2000
MAX2 = 2 * MAX


def match(c1, c2):
    return c1 == "?" or c2 == "?" or c1 == c2


def ok(li1, li2):
    ret = [None] * (2 * MAX2 + 1)
    for i in range(-MAX2, MAX2 + 1):
        if i < 0:
            zp = zip(li1, li2[-i:])
        else:
            zp = zip(li1[i:], li2)
        bl = True
        for e1, e2 in zp:
            if not match(e1, e2):
                bl = False

        ret[i] = bl

    return ret


ab = ok(a, b)
bc = ok(b, c)
ac = ok(a, c)

ans = 3 * MAX
for bi in range(-MAX2, MAX2 + 1):
    if ab[bi]:
        for ci in range(-MAX2, MAX2 + 1):
            if ac[ci] and bc[ci-bi]:
                l = min(0, bi, ci)
                r = max(la, bi + lb, ci + lc)
                ans = min(ans, r - l)


print(ans)


Measured memory_bytes: 58212
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll a,b,c;
  cin >> a >> b >> c;
  set<ll> st;
  st.insert(a);
  st.insert(b);
  st.insert(c);
  cout << st.size()<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

// g++ -std=c++11 prac.cpp
ll Max=-1e9,Min=1e9+1;
 
int main(){
    ll x,c,y=0,n,m,l,w,sum=0,sum2=0,ans=1;
    string s,t;
    bool f=true;
    cin >> n >> m;
    VI a(n);
    VI b(m);
    x = n;
    y = m;
    rep(i,n){
        ans = ans * x%mod;
        x--;
    }

    rep(i,m){
        ans = ans * y%mod;
        y--;
    }

    if(n==m)
        cout << ans*2 % mod << endl;
    else if (abs(n-m) >= 2)
        cout <<  0 << endl;
    else
        cout << ans % mod << endl;

    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    ll k;
    cin >> s >> k;
    rep(i,s.size()){
        if(s[i] != '1' || i+1 == k){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << "1" << endl;
    return 0;
}


Measured memory_bytes: 256