akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n, m;
int D[20][20];
int V;
const int INF = 1 << 20;

void solve()
{
	for (int k = 0; k < V; k++)
	{
		for (int i = 0; i < V; i++)
		{
			for (int j = 0; j < V; j++)
			{
				D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
			}
		}
	}
}

int main()
{
	fill(D[0], D[0] + 400, INF);
	char comma;
	cin >> n;
	V = n;
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		int a, b, c, d;
		cin >> a >> comma >> b >> comma >> c >> comma >> d;
		a--; b--;
		D[a][b] = c;
		D[b][a] = d;
	}
	int x1, y1, x2, y2;
	cin >> x1 >> comma >> x2 >> comma >> y1 >> comma >> y2;
	solve();
	cout << y1 - D[--x1][--x2] - D[x2][x1] - y2 << endl;
	cin >> n;
	return 0;
}

Measured memory_bytes: 1160
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b, c = rm()
if a==b:
  print(c)
elif b == c:
  print(a)
else:
  print(b)









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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    int k;
    cin >> k;
    A.at(i) = abs(k - X);
  }
  int ans = A.at(0);
  for (int i = 1; i < N; i++) {
    ans = __gcd(ans, A.at(i));
  }
  cout << ans << endl;
}




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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;





int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	string s, t;
	cin >> s >> t;
	int A, B;
	cin >> A >> B;
	string u;
	cin >> u;

	if (u == s)
		--A;
	else
		--B;

	cout << A << ' ' << B << '\n';



	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int a,b,c,sumab,sumbc,sumca;
    scanf("%d%d%d",&a,&b,&c);
    while(((1>a)||(a>10000))||((1>b)||(b>10000))||((1>c)||(c>10000)))
    {
        scanf("%d%d%d",&a,&b,&c);
    }
    sumab=a+b;
    sumbc=b+c;
    sumca=c+a;
    if((sumab<=sumbc)&&(sumab<sumca))
    {
        printf("%d\n",sumab);
    }
    else if((sumbc<=sumca)&&(sumbc<sumab))
    {
        printf("%d\n",sumbc);
    }
    else if((sumca<=sumab)&&(sumca<sumbc))
    {
        printf("%d\n",sumca);
    }
    else
    {
        printf("%d\n",sumab);
    }
    return 0;
}

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

int get_digit(int N){
    int cnt=0;
    while(1){
        if(N==0){
            break;
        }
        N /=10;
        cnt++;
    }

    return cnt;
}

int main(){
    int N;
    cin >> N;
    int cnt=0;

    for(int i=1 ;i<=N;i++){
        if( get_digit(i)%2 == 1 ){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
  import sys
  input=sys.stdin.buffer.readline
  n=int(input())+1
  data=[0]*n*2
  def update(i,x):
    i+=n
    data[i]=x
    i//=2
    while i:
      data[i]=data[i*2]|data[i*2+1]
      i//=2
  def query(l,r):
    l+=n
    r+=n
    s=0
    while l<r:
      if l&1:
        s|=data[l]
        l+=1
      if r&1:
        r-=1
        s|=data[r]
      l//=2
      r//=2
    return bin(s).count('1')
  for i,c in enumerate(input()[:-1],n):data[i]=2**(c-97)
  for i in range(n-1,0,-1):data[i]=data[i*2]|data[i-~i]
  s=[]
  for _ in range(int(input())):
    q,a,b=input().split()
    if q[0]>49:s+=query(int(a)-1,int(b)),
    else:update(int(a)-1,2**(b[0]-97))
  print('\n'.join(map(str,s)))
main()

Measured memory_bytes: 57620
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m;
  cin>>n>>m;
  using T = tuple<int,int>;
  vector<vector<T>> dp(11, vector<T>(n, make_tuple(-1, 0)));
  vector<vecint> g(n);
  REP(i,m) {
    int a,b;
    cin>>a>>b;
    --a;--b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int q;
  cin>>q;
  REP(i,q) {
    int u,d,c;
    cin>>u>>d>>c;
    --u;
    dp[d][u] = make_pair(i, c);
  }
  for(int d=10; d>0; --d) {
    REP(i,n) {
      int qi, clr;
      tie(qi, clr) = dp[d][i];
      for(auto&& to:g[i]) {
        dp[d-1][to] = max(dp[d-1][to], make_tuple(qi, clr));
      }
      dp[d-1][i] = max(dp[d-1][i], make_tuple(qi, clr));
    }
  }
  REP(i,n) {
    cout<<get<1>(dp[0][i])<<"\n";
  }
  return 0;
}


Measured memory_bytes: 15088
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
#include<deque>
#include<iomanip>
#include<ctime>
#include<bitset>
using namespace std;

class Monster
{
public:
	int hp, attack;
};

int main()
{
	Monster takahashi, aoki;
	cin >> takahashi.hp >> takahashi.attack >> aoki.hp >> aoki.attack;

	int a = (int)(takahashi.hp / aoki.attack);
	
	if (takahashi.hp % aoki.attack > 0.0F)
	{
		a += 1;
	}

	int b = (int)(aoki.hp / takahashi.attack);
	
	if (aoki.hp % takahashi.attack > 0.0F)
	{
		b += 1;
	}

	if (a >= b)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<string> &s, string a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


int main() {
    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (k == i * j + (n - i) * (m - j)) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)

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

	s[0] = '2';
	s[1] = '0';
	s[2] = '1';
	s[3] = '8';
	printf("%s\n",s.c_str());
	return 0;

	//	std::cout << "Hello World!\n"; 
}


Measured memory_bytes: 256
h,w=map(int,input().split())
s=[input() for i in range(h)]

ans=[]
for i in range(h):
  if s[i]!='.'*w:
    ans.append(s[i])

n=len(ans)
a=['' for i in range(n)]

for i in range(w):
  sm=''
  cnt=0
  for j in range(n):
    sm+=ans[j][i]
    if ans[j][i]!='.':
      cnt+=1
  if cnt!=0:
    for k in range(n):
      a[k]+=ans[k][i]
m=len(a)
for i in range(m):
  print(a[i])

Measured memory_bytes: 38896
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static long fact[] = new long[1000002];
	static long factInv[] = new long[1000002];

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		final int MOD = 1_000_000_000 + 7;

		fact[0] = 1;
		factInv[0] = 1;
		for(int i = 0; i < fact.length - 1; i++){
			fact[i+1] = fact[i]*(i+1) % MOD; // n!(mod M)
	        factInv[i+1] = (int)(factInv[i]*repeatablePow(i+1, MOD-2, MOD) % MOD);
		}

		int n = sc.nextInt();
		int k = sc.nextInt();

		int a[] = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}

		Arrays.sort(a);

		if(k == 1){
			System.out.println(0);
			return;
		}

		long sumArray[] = new long[n];
		sumArray[0] = a[0];
		for(int i = 1; i < n; i++){
			sumArray[i] = sumArray[i - 1] + a[i];
		}

		long result = 0;
		for(int i = k - 2; i <= n - 2; i++){
			result += (sumArray[n - 1] - sumArray[i] - sumArray[n - i - 2])%MOD*combination(i, k - 2, MOD);
			result %= MOD;
//			System.out.println("i = "+i+" result = "+result);
		}

		System.out.println(result);

	}

	static long repeatablePow(int x, int n, int mod){
		if(n == 0){
			return 1;
		}
		long result = repeatablePow((int)((long)x*x%mod), n/2, mod);
		if(n % 2 == 1){
			result = result*x%mod;
		}
		return result;
	}

	static long combination(int a, int b, int mod){ //aCbをmod計算
	    if(a == 0 && b == 0)return 1;
	    if(a < b || a < 0)return 0;

	    long tmp = factInv[a - b]* factInv[b] % mod;
	    return tmp * fact[a] % mod;
	}
}


Measured memory_bytes: 64980
#include "bits/stdc++.h"
using namespace std;
int main()
{
	long long k, m, n = 50;
	scanf("%lld", &k);
	m = k / n;
	vector<long long> a(n, n - 1 + m);
	for(int i = k - n * m, j = 0; i > 0; --i, ++j)
	{
		a[j] += n;
		for(int k = 0; k < n; ++k)
		{
			if(k != j)
			{
				--a[k];
			}
		}
	}
	printf("%d\n", n);
	for(int i = 0; i < n; printf("%lld ", a[i++])){}
	printf("\n");
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define pb push_back

int main()
{
    string S;
    cin >> S;
    ll N = SZ(S);

    vec T(N+1, 0);
    ll p = 1;
    for(ll i=N-1; i>=0; --i) {
        T[i] = (T[i+1] + (S[i] - '0') * p) % 2019; 
        p = (p * 10) % 2019;
    }
    
    ll cnt = 0;
    map<ll,ll> C;
    REP(i,0,N+1) ++C[T[i]];
    FORR(c,C) cnt += c.second * (c.second - 1) / 2;
    PR(cnt);

    return 0;
}

/*



*/

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

using namespace std;
#define BUF (1000)
#define ll long long 
#define MAX (1000001)
#define MOD (1000000007)
int x,y;

long long fac[MAX], finv[MAX], inv[MAX];

void combination_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long combination(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
	combination_init();

	cin >> x >> y;

	int A = 2*x -y;
	int B = 2*y -x;
	if( A<0 || B<0 || A%3!=0 || B%3!=0){
		cout << 0 << endl;
		return 0;
	} 

	A/=3;
	B/=3;

	int total = A+B;
	int mn = min(A,B);
	cout << combination(total,mn) << endl;
	return 0;
}


Measured memory_bytes: 23680
#include<iostream>
using namespace std;
int main(void){
    while(true){
        int ans=0,n;
        cin >> n;
        if(n==0)                        break;
        for(int i=0;i<n;i++){
            int x,y,h,w;
            cin >> x >> y >> h >> w;
            int s=x+y+h;
            if(s<=60 && w<=2)           ans+=600;
            else if(s<=80 && w<=5)      ans+=800;
            else if(s<=100 && w<=10)    ans+=1000;
            else if(s<=120 && w<=15)    ans+=1200;
            else if(s<=140 && w<=20)    ans+=1400;
            else if(s<=160 && w<=25)    ans+=1600;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 1e18;
  rep(i, n + 1) {
    ll j = n - i;
    ll now = pow(2, i) + j * k;
    ans = min(ans, now);
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define in auto&it
#define out auto it
#define fi first
#define se second
#define allr(x) (x).rbegin(),(x).rend()
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
const double pi = acos(-1);
#define print(x) 
#define err(x) cerr<<#x<<" = "<<x<<'\n';
int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		freopen("error.txt", "w", stderr);
	#endif
	fastio
	string s;
	cin>>s;
	if(s[s.size()-1]!='s') cout<<s<<"s";
	else cout<<s<<"es";
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int k;
unsigned long long ans=0;
int gcd(int x,int y,int z)
{
    int j;
    do
    {
        j=x%y;
        x=y;
        y=j;
    }
    while(j);
    do
    {
        j=x%z;
        x=z;
        z=j;
    }
    while(j);
    return x;
}
int main()
{
    cin>>k;
    for(int x=1;x<=k;x++)
    {
        for(int y=1;y<=k;y++)
        {
            for(int z=1;z<=k;z++)
            {
                ans+=gcd(x,y,z);
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>

int main(){

	int count[26];
	for(int i = 0;i < 26;i++) {
		count[i] = 0;
	}
	char s[1300];
	while(fgets(s,1300,stdin) != NULL) {

		for(int i = 0;s[i] != '\0';i++) {
			if(s[i] >= 'A' && s[i] <= 'Z') {
				count[s[i] - 'A']++;
			}
			if(s[i] >= 'a' && s[i] <= 'z') {
				count[s[i] - 'a']++;
			}
		}
	}

	for(int i = 0;i < 26;i++) {
		printf("%c : %d\n",'a' + i,count[i]);
	}
	return 0;
}



Measured memory_bytes: 2704
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int n, w[105], s1[105], ans = 100005;

int main(){
    scanf("%d", &n);
    rep(i,n){
        scanf("%d", w+i);
        s1[i] = (i ? s1[i-1] : 0) + w[i];
    }
    rep(i,n){
        ans = min(ans, abs(s1[n-1]-s1[i]*2));
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define translow transform(s.begin(),s.end(),s.begin(),::tolower);
#define transup transform(s.begin(),s.end(),s.begin(),::toupper);
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;
 
 
int main() {
				fast
                // #ifndef ONLINE_JUDGE
                // freopen("input.txt","r",stdin);
                // freopen("output.txt","w",stdout);
                // #endif

                ll x,y,a,b,c;
                cin>>x>>y>>a>>b>>c;
                
                vector<ll>ans,a1,b1,c1;
                for(ll i=0;i<a;i++){
                    //cin>>a1[i];
                    ll z; cin>>z;
                    a1.pb(z);
                    
                }
                 for(ll i=0;i<b;i++){
                   // cin>>b1[i];
                    ll z; cin>>z;
                    b1.pb(z);
                   
                }
                 for(ll i=0;i<c;i++){
                    // cin>>c1[i];
                    ll z; cin>>z;
                    c1.pb(z);
                    ans.pb(c1[i]);
                }
                sort(a1.rbegin(),a1.rend());

                for(ll i=0;i<x;i++)
                    ans.pb(a1[i]);

                sort(b1.rbegin(),b1.rend());

                 for(ll i=0;i<y;i++)
                    ans.pb(b1[i]);
               
                 sort(ans.rbegin(),ans.rend());
                 ll sum=0;
                 for(ll i=0;i<x+y;i++)
                    sum+=ans[i];
                cout<<sum;
             

                return 0;
            }

Measured memory_bytes: 8856
import math
def distance(l1, l2):
  l = [0] * len(l1)
  for i in range(len(l)):
    l[i] = (l1[i] - l2[i]) ** 2
  s = sum(l)
  return math.sqrt(s), int(math.sqrt(s))
n,d=map(int, input().split())
l = []

for i in range(n):
  l.append(list(map(int, input().split())))

c = 0  
for i in range(n):
  for j in range(i+1, n):
    sq, insq = distance(l[i], l[j])
    if sq-insq == 0:
      c +=1
      
print(c)

Measured memory_bytes: 3064
N = int(input())
plist = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
    if plist[i] == i + 1:
        plist[i], plist[i + 1] = plist[i + 1], plist[i]
        ans += 1
if plist[-1] == N:
    ans += 1
print(ans)


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in(),K=in();
	string S=in<string>();
	vector<ll> one(1,0),zero(1,0);

	bool find_one=true;
	int cont=0;
	REP(i,N){
		if(find_one){
			if(S[i]=='1') cont++;
			else{
				auto v=one.back();
				one.push_back(v+cont);
				find_one = false;
				cont=1;
			}
		}
		else{
			if(S[i]=='0') cont++;
			else{
				auto v=zero.back();
				zero.push_back(v+cont);
				find_one = true;
				cont=1;
			}
		}
	}
	if(find_one){
		auto v=one.back();
		one.push_back(v+cont);
	}
	else{
		auto v=one.back();
		one.push_back(v);
		v=zero.back();
		zero.push_back(v+cont);
	}

	int M=zero.size();
	if(M-1<=K){
		out(N);
		return 0;
	}

	ll ans=0;
	for(int i=1;i<=M-K;i++){
		ans = max(ans,(zero[i+K-1]-zero[i-1])+(one[i+K]-one[i-1]));
	}

	out(ans);
	return 0;
}


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

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

 int max = A+B;
 if(max < (A-B)){
   max = A-B;
 }

 if(max < A*B){
   max = A*B;
 }

 cout << max << endl;


}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

S = sum(A)

for i in range(N):
    x = min(B[i], A[i])
    B[i] -= x
    A[i] -= x
    x = min(B[i], A[i+1])
    B[i] -= x
    A[i+1] -= x

print(S-sum(A))


Measured memory_bytes: 18476
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    map<int,int> mp;
    rep(i,n) mp[a[i]]++;
    int m = mp.size();
    if(m >= 4){
        cout << "No" << endl;
        return 0;
    }
    if(m == 1){
        if(mp[0] == n) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else if(m == 2){
        if(n%3 == 0 && mp[0] == n/3) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
        int t = 0;
        bool ok = true;
        for(auto u : mp){
            t ^= u.first;
            if(u.second != n/3) ok = false;
        }
        if(t == 0 && ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}



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

using namespace std;

int main() {

	int n,d;
	cin >> n >> d;

	vector<vector<double>> x(n, vector<double>(d, 0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}

	int counter = 0;
	for (int i = 0; i < n-1; i++) {
		for (int j = i + 1; j < n; j++) {
			double distance = 0;
			for (int k = 0; k < d; k++) {
				distance += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
			}
			distance = sqrt(distance);
			if (distance == int(distance)) {
				counter++;
			}
		}
	}

	cout << counter << endl;
}

Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.
	LL n,ans=0;
	cin >> n;
	FOR(i, 0, n) {
		LL a, b;
		cin >> a >> b;
		ans += b - a + 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

# -*- coding: utf-8 -*-


class FactMod():
    '''
    modの値が素数の時のfactと組み合わせを求める
    フェルマーの小定理を用いているため、modが素数以外の時は使えない
    '''

    def __init__(self, n, mod):
        '''
        コンストラクタ
        f:nまでの i!の値を　配列に入れる
        inv: (i!)^-1　の値を配列に入れる
        '''
        self.mod = mod
        self.f = [1]*(n+1)
        for i in range(1, n+1):
            self.f[i] = self.f[i-1]*i % mod

        self.inv = [pow(self.f[-1], mod-2, mod)]
        for i in range(1, n+1)[::-1]:
            self.inv.append(self.inv[-1]*i % mod)
        self.inv.reverse()

    def perm(self, a, b):
        if a < b or a < 0 or b < 0:
            return 0
        ret = self.f[a]*self.inv[a-b]
        ret %= self.mod
        return ret


MOD = 10**9+7
N, K = map(int, input().split())
edges = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N-1)]
adj = [[] for _ in range(N)]

F = FactMod(K+1, MOD)

for a, b in edges:
    adj[a].append(b)
    adj[b].append(a)

# current parent
Q = []
for a in adj[0]:
    Q.append((a, 0))
ans = F.perm(K, len(adj[0])+1)
ans %= MOD

while Q:
    current, prev = Q.pop()
    child = len(adj[current])-1
    ret = F.perm(K-2, child)
    ans *= ret
    ans %= MOD
    for a in adj[current]:
        if a == prev:
            continue
        else:
            Q.append((a, current))
print(ans)


Measured memory_bytes: 50516
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(int a[][22],int x,int y,int vx,int vy,int p){
  int i;
  int mn=11;
  if(p<11){
    for(i=1;;i++){
      if(0){
      }else if(a[x+vx*i][y+vy*i]==-1){
	break;
      }else if(a[x+vx*i][y+vy*i]==1){
	if(i==1)
	  break;
	a[x+vx*i][y+vy*i]=0;
	int t;
	t=f(a,x+vx*(i-1),y+vy*(i-1),-1,0,p+1);
	if(mn>t)
	  mn=t;
	t=f(a,x+vx*(i-1),y+vy*(i-1),0,-1,p+1);
	if(mn>t)
	  mn=t;
	t=f(a,x+vx*(i-1),y+vy*(i-1),1,0,p+1);
	if(mn>t)
	  mn=t;
	t=f(a,x+vx*(i-1),y+vy*(i-1),0,1,p+1);
	if(mn>t)
	  mn=t;
	a[x+vx*i][y+vy*i]=1;
	break;
      }else if(a[x+vx*i][y+vy*i]==3){
	mn=p;
	break;
      }
    }
  }
  return mn;
}
int main(){
  int i,j;
  int a[22][22],w,h,sx,sy;
  int mn;
  while(cin>>w>>h&&w+h){
    memset(a,-1,sizeof(a));
    for(i=1;i<h+1;i++){
      for(j=1;j<w+1;j++){
	cin>>a[j][i];
	if(a[j][i]==2){
	  a[j][i]=0;
	  sx=j;
	  sy=i;
	}
      }
    }
    mn=11;
    int t;
    t=f(a,sx,sy,-1,0,1);
    if(mn>t)
      mn=t;
    t=f(a,sx,sy,0,-1,1);
    if(mn>t)
      mn=t;
    t=f(a,sx,sy,1,0,1);
    if(mn>t)
      mn=t;
    t=f(a,sx,sy,0,1,1);
    if(mn>t)
      mn=t;
    if(mn==11)
      cout<<-1<<endl;
    else
      cout<<mn<<endl;
  }
  return 0;
}

Measured memory_bytes: 868
K=int(input())
List = list(str(K))
i = len(List)
tryNum = 7*10**i
res = -1
if K % 2 == 0 or K % 5 == 0:
  print(res)
else:
  flag = True
  mid=0
  K=9*K
  N=0
  while flag:
    N = tryNum % K
    if  N == 7 :
      res = i
      flag = False
    else:
      i += 1
      tryNum= N*10
  print(res)

Measured memory_bytes: 9152
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    int house[4][3][10] = {};
    for(int i = 0;i < n;i++)
    {
        int b,f,r,v;
        cin >> b >> f >> r >> v;
        house[b - 1][f - 1][r - 1] += v;
    }
    for(int i = 0;i < 4;i++)
    {
        for(int j = 0;j < 3;j++)
        {
            for(int k = 0;k < 10;k++)
            {
                cout << " " << house[i][j][k];
            }
            cout << "\n";
        }
        if(i != 3)
        {
            cout << "####################\n";
        }
    }

    return 0;
}


Measured memory_bytes: 3088
//O(N^2)
#include <stdio.h>
#include <x86intrin.h>
typedef unsigned int uint;
uint a[200000] __attribute__ ((aligned (16)));
uint b[200000] __attribute__ ((aligned (16)));
int main(void){
    uint n;
    uint s=0;
    uint ss[4];
    scanf("%u", &n);
    for(uint i=0; i<n; i++){
        scanf("%u", a+i);
    }
    for(uint i=0; i<n; i++){
        scanf("%u", b+i);
    }
    __m128i s0 = _mm_setzero_si128();
    __m128i s1 = _mm_setzero_si128();
    __m128i s2 = _mm_setzero_si128();
    __m128i s3 = _mm_setzero_si128();
    uint j;
    for(j=0; j<(n/4*4); j+=4){
        __m128i d = _mm_load_si128((__m128i*)(b+j));
        __m128i d0 = _mm_shuffle_epi32(d, 0x00);
        __m128i d1 = _mm_shuffle_epi32(d, 0x55);
        __m128i d2 = _mm_shuffle_epi32(d, 0xAA);
        __m128i d3 = _mm_shuffle_epi32(d, 0xFF);
        uint i;
        for(i=0; i<(n/16*16); i+=16){
            __m128i c0 = _mm_load_si128((__m128i*)(a+i+0));
            __m128i c1 = _mm_load_si128((__m128i*)(a+i+4));
            __m128i c2 = _mm_load_si128((__m128i*)(a+i+8));
            __m128i c3 = _mm_load_si128((__m128i*)(a+i+12));
            __m128i t0 = _mm_add_epi32(c0, d0);
            __m128i t1 = _mm_add_epi32(c1, d0);
            __m128i t2 = _mm_add_epi32(c2, d0);
            __m128i t3 = _mm_add_epi32(c3, d0);
            s0 = _mm_xor_si128(s0, t0);
            s1 = _mm_xor_si128(s1, t1);
            s2 = _mm_xor_si128(s2, t2);
            s3 = _mm_xor_si128(s3, t3);
            t0 = _mm_add_epi32(c0, d1);
            t1 = _mm_add_epi32(c1, d1);
            t2 = _mm_add_epi32(c2, d1);
            t3 = _mm_add_epi32(c3, d1);
            s0 = _mm_xor_si128(s0, t0);
            s1 = _mm_xor_si128(s1, t1);
            s2 = _mm_xor_si128(s2, t2);
            s3 = _mm_xor_si128(s3, t3);
            t0 = _mm_add_epi32(c0, d2);
            t1 = _mm_add_epi32(c1, d2);
            t2 = _mm_add_epi32(c2, d2);
            t3 = _mm_add_epi32(c3, d2);
            s0 = _mm_xor_si128(s0, t0);
            s1 = _mm_xor_si128(s1, t1);
            s2 = _mm_xor_si128(s2, t2);
            s3 = _mm_xor_si128(s3, t3);
            t0 = _mm_add_epi32(c0, d3);
            t1 = _mm_add_epi32(c1, d3);
            t2 = _mm_add_epi32(c2, d3);
            t3 = _mm_add_epi32(c3, d3);
            s0 = _mm_xor_si128(s0, t0);
            s1 = _mm_xor_si128(s1, t1);
            s2 = _mm_xor_si128(s2, t2);
            s3 = _mm_xor_si128(s3, t3);
        }
        for(; i<n; i++){
            s ^= a[i]+b[j+0];
            s ^= a[i]+b[j+1];
            s ^= a[i]+b[j+2];
            s ^= a[i]+b[j+3];
        }
    }
    for(; j<n; j++){
        for(uint i=0; i<n; i++){
            s ^= a[i]+b[j];
        }
    }
    s0 = _mm_xor_si128(s0, s2);
    s1 = _mm_xor_si128(s1, s3);
    s0 = _mm_xor_si128(s0, s1);
    _mm_storeu_si128((__m128i*)ss, s0);
    ss[0] ^= ss[2];
    ss[1] ^= ss[3];
    ss[0] ^= ss[1];
    printf("%u\n", ss[0]^s);
    return 0;
}


Measured memory_bytes: 1664
def calculate(n, bindexes):
    arr = []
    for i in range(n):
        if bindexes.get(i):
            arr.append(0)
            continue

        if i == 0:
            arr.append(1)
        elif i == 1:
            arr.append(arr[i-1] + 1)
        else:
            arr.append(arr[i-1] + arr[i-2])
    return arr

S = input().split(" ")

n = int(S[0])
m = int(S[1])
brokenStairIndexes = {}

for i in range(m):
    brokenStairIndexes.setdefault(int(input())-1, True)


arr = calculate(n,brokenStairIndexes)

print(arr[n-1] % 1000000007)

Measured memory_bytes: 460020
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>


using namespace std;

bool ans[1005];
int x;


void pd()
{
    for(int i = 1; i < 50; i++)
    {
        for(int j = 2; j < 50; j++)
        {
            int f = pow(i,j);
            if(f <= 1000)
            {
                ans[f]=1;
            }
            else 
                break;
        }
    }
}


int main()
{
    cin >> x;
    pd();
    for(int i = x; i >= 1; i--)
    {
        if(ans[i] == 1)
        {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i;
	long int sum_time = 0;
	int n;
	scanf("%d", &n);
	
	long int t[n];
	for (i = 0; i < n; i++)
		scanf("%ld", &t[i]);
	
	int m;
	scanf("%d", &m);
	
	int p[m], x[m];
	for (i = 0; i < m; i++)
		scanf("%d %d", &p[i], &x[i]);
	
	for (i = 0; i < n; i++)
		sum_time += t[i];
	
	for (i = 0; i < m; i++)
	{
		int sa;
		sa = t[p[i] - 1] - x[i];
		printf("%d\n", sum_time - sa);
	}

	return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int A =sc.nextInt();
        int B =sc.nextInt();
        int M =sc.nextInt();
        
        int result=0;
       
       
        
        int costA[] = new int[A];
        int costB[] = new int[B];
        int numberA[] =new int[M];
        int numberB[] =new int[M];
        int numberM[] =new int[M];
        
        
        
        
        int MinA =1000000;
        int MinB =1000000;
        int Coupon=1000000;
        
        for(int i=0;i<A;i++){
            costA[i]=sc.nextInt();
        }
        
        for(int j=0;j<B;j++){
            costB[j]=sc.nextInt();
        }
        
        for(int k=0;k<M;k++){
            numberA[k]=sc.nextInt();
            numberB[k]=sc.nextInt();
            numberM[k]=sc.nextInt();

        }
        
        
        
        for(int i=0;i<A;i++){
            if(costA[i]<MinA){
                MinA=costA[i];
            }
        }
        
        for(int i=0;i<B;i++){
            if(costB[i]<MinB){
                MinB=costB[i];
            }
        }
        
        
        for(int i=0;i<M;i++){
             result=(costA[numberA[i]-1]+costB[numberB[i]-1]-numberM[i]);
            if(Coupon>result){
                Coupon=result;
            }
        }
        
        if(MinA+MinB<Coupon){
            
            System.out.println(MinA+MinB);
        }else{
             System.out.println(Coupon);
        }
        
    }
}


Measured memory_bytes: 62464
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        r: i64,
        g: i64,
        b: i64,
        n: i64
    }
    let rn = n/r;
    let gn = n/g;
    // let bn = n/b;
    let mut cnt = 0;
    for i in 0..(rn+1) {
        for j in 0..(gn+1) {
            if n-i*r-j*g >= 0 && (n-i*r-j*g)%b==0 {
                cnt+=1;
            }
        }
    }
    println!("{}", cnt);
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)




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

 ll n;
  cin >> n;
  if(n%2==1) {
    cout << 0 << endl;
  }
    else {
     ll res=0; 
     ll pow=5;
      while(pow<n) {
        res+=n/(2*pow);
        pow*=5;
      }
      cout << res << endl;
    }
  
  
  
} // main


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 100020
#define INF 100000000000000000ll
using namespace std;
int read(){
	int nm=0,fh=1; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
LL n,x,F[3];
int main(){
	n=read(),F[1]=F[2]=-INF;
	while(n--){
		x=read(),F[0]+=x,F[1]-=x,F[2]+=x;
		if(x<0) F[2]=max(F[1],F[2]),F[1]=max(F[1],F[0]);
		F[0]=max(F[0],F[1]),F[1]=max(F[1],F[2]);
	}
	printf("%lld\n",F[0]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<pi>
#define size(a)  (int)(a.size())
#define fill(s,x,n) vector
 x(n); rep(i,0,n) cin>>x[i];
#define mod 1000000007
#define inf 1000000005
void solve(){
	int a,b,c;
	int k;
	cin>>a>>b>>c>>k;
	int ans=min(k,a)*1;
	k-=a;
	k-=b;
	if(k>0){
       ans-=k;
	}
	cout<<ans;

}
 

signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);  
    #endif
    */
	int test;
	//cin>>test;
	test=1;
	while(test--){
         solve();
         cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

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

template<typename Monoid>
struct SegmentTree {
   using F = function<Monoid(Monoid,Monoid)>;
   int sz;
   vector< Monoid > seg;
   const F f;
   const Monoid M1;
   SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
      sz = 1;
      while(sz < n) sz <<= 1;
      seg.assign(2 * sz, M1);
   }
   void set(int k, const Monoid &x) {
      seg[k + sz] = x;
   }
   void build() {
      for(int k = sz - 1; k > 0; k--) {
         seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
      }
   }
   void update(int k, const Monoid &x) {
      k += sz;
      seg[k] = x;
      while(k >>= 1) {
         seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
      }
   }
   Monoid query(int a, int b) {
      Monoid L = M1, R = M1;
      for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
         if(a & 1) L = f(L, seg[a++]);
         if(b & 1) R = f(seg[--b], R);
      }
      return f(L, R);
   }
   Monoid operator[](const int &k) const {
      return seg[k + sz];
   }
};
template<typename T> struct RMQ {
   SegmentTree<T> segt;
   RMQ(int n, const T& inf=INF, const T& init=0) : segt(n, [](T a,T b){return max(a,b);}, -inf) {
      for (int i = 0; i < n; i++) segt.set(i,init);
      segt.build();
   }
   void update(int i, const T& x) { segt.update(i, x); }
   T query(int a, int b) { return segt.query(a, b); }
};
// template<typename T> struct RMQ {
//    SegmentTree<T> segt;
//    RMQ(int n, const T& inf=INF, const T& init=0) : segt(n, [](T a,T b){return min(a,b);}, inf) {
//       for (int i = 0; i < n; i++) segt.set(i,init);
//       segt.build();
//    }
//    void update(int i, const T& x) { segt.update(i, x); }
//    T query(int a, int b) { return segt.query(a, b); }
// };

signed main()
{
   int n; cin >> n;
   V<int> h(n), a(n);
   for (int i = 0; i < n; i++) {
      cin >> h[i];
      h[i]--;
   }
   for (int i = 0; i < n; i++) {
      cin >> a[i];
   }

   RMQ<int> rmq(n);
   for (int i = 0; i < n; i++) {
      rmq.update(h[i], rmq.query(0, h[i]+1) + a[i]);
   }
   cout << rmq.query(0,n) << endl;

   return 0;
}


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

using ll = long long;
using p = pair<ll, ll>;
constexpr ll INF = 1LL << 62;

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> wacount(N + 1, 0), account(N + 1, 0);
  for (ll i = 0; i < M; i++) {
    ll p;
    string S;
    cin >> p >> S;
    if (account[p] != 0) { 
      continue;
    }
    if (S == "WA") {
      wacount[p]++;
    } else if (S == "AC") {
      account[p]++;
    }
  }
  ll answa = 0;
  for (ll p = 1; p <= N; p++) {
    if (account[p]) {
      answa += wacount[p];
    }
  }

  cout << accumulate(account.begin(), account.end(), 0) << " " << answa << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,n,s) for(int i=s;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

  int n,x;
  cin >> n >> x;
  int ans = 1;
  int stack = 0;
  REP(i, n) {
    int l;
    cin >> l;
    stack += l;
    if(stack <= x) {
      ans ++;
    } else {
      break;
    }
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int N, K;

int smW[2002][2002], smB[2002][2002];

int sub(int sm[2002][2002], int x1, int y1, int x0, int y0){
    x0--; y0--;
    return sm[x1][y1] + sm[x0][y0] - sm[x0][y1] - sm[x1][y0];
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    vector<int> x(N), y(N), c(N);
    for(int i=0; i<N; i++){
        char cc;
        cin >> x[i] >> y[i] >> cc;
        if(cc == 'W') c[i] = 0;
        else c[i] = 1;
    }
    for(int i=0; i<N; i++){
        x[i] %= 2*K;
        y[i] %= 2*K;
    }

    vector<pair<int, int>> W, B;
    for(int i=0; i<N; i++){
        if(c[i] == 0){
            W.push_back(make_pair(x[i], y[i]));
        }
        else{
            B.push_back(make_pair(x[i], y[i]));
        }
    }
    for(int i=0; i<=2*K; i++)
        for(int j=0; j<=2*K; j++){
            smW[i][j] = 0;
            smB[i][j] = 0;
        }

    for(auto xy : W)
        smW[xy.first+1][xy.second+1]++;
    for(auto xy : B)
        smB[xy.first+1][xy.second+1]++;

    for(int i=1; i<=2*K; i++)
        for(int j=1; j<=2*K; j++){
            smW[i][j] += smW[i][j-1];
            smB[i][j] += smB[i][j-1];
        }
    for(int j=1; j<=2*K; j++)
        for(int i=1; i<=2*K; i++){
            smW[i][j] += smW[i-1][j];
            smB[i][j] += smB[i-1][j];
        }

    int ans = 0;

    for(int i=0; i<K; i++){
        for(int j=0; j<K; j++){
            int tmpW1 = sub(smW, i, j, 1, 1);
            int tmpW2 = sub(smW, i+K, j+K, i+1, j+1);
            int tmpW3 = sub(smW, 2*K, j, i+K+1, 1);
            int tmpW4 = sub(smW, i, 2*K, 1, j+K+1);
            int tmpW5 = sub(smW, 2*K, 2*K, i+K+1, j+K+1);

            int tmpB1 = sub(smB, i+K, j, i+1, 1);
            int tmpB2 = sub(smB, i, j+K, 1, j+1);
            int tmpB3 = sub(smB, i+K, 2*K, i+1, j+K+1);
            int tmpB4 = sub(smB, 2*K, j+K, i+K+1, j+1);
            
            int sm1 = tmpW1+tmpW2+tmpW3+tmpW4+tmpW5;
            int sm2 = tmpB1+tmpB2+tmpB3+tmpB4;
            ans = max(ans, sm1+sm2);
        }
    }

    for(int i=0; i<K; i++){
        for(int j=0; j<K; j++){
            int tmpW1 = sub(smB, i, j, 1, 1);
            int tmpW2 = sub(smB, i+K, j+K, i+1, j+1);
            int tmpW3 = sub(smB, 2*K, j, i+K+1, 1);
            int tmpW4 = sub(smB, i, 2*K, 1, j+K+1);
            int tmpW5 = sub(smB, 2*K, 2*K, i+K+1, j+K+1);

            int tmpB1 = sub(smW, i+K, j, i+1, 1);
            int tmpB2 = sub(smW, i, j+K, 1, j+1);
            int tmpB3 = sub(smW, i+K, 2*K, i+1, j+K+1);
            int tmpB4 = sub(smW, 2*K, j+K, i+K+1, j+1);
            
            int sm1 = tmpW1+tmpW2+tmpW3+tmpW4+tmpW5;
            int sm2 = tmpB1+tmpB2+tmpB3+tmpB4;
            ans = max(ans, sm1+sm2);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 33780