akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n;
lli c[100002];
int main() {
  cin >> n; 
  fill(begin(c), end(c), 0);
  for (lli i=0; i<n; ++i) {
    lli x; cin >> x;
    c[x-1]++; c[x]++; c[x+1]++;
  }
  lli ans = *max_element(begin(c), end(c));
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1024
#include <cstdio>
#define ll long long
ll gcb(ll a, ll b) {
    return a ? gcb(b % a, a) : b;
}
ll a, b;
int main() {
    while (~scanf("%lld %lld", &a, &b)) {
        if (a > b) {
            ll t = a;
            a = b;
            b = t;
        }
        ll g = gcb(a, b);
        printf("%lld %lld\n", g, a * b / g);
    }
    return 0;
}



Measured memory_bytes: 2552
n,k,q=map(int,input().split())
prev=0

if k>q:
    [print("Yes") for i in range(n)]
else:
    result=[0]*(n+1)
    while True:
        try:
            idx=int(input())
            result[idx]+=1
        except:
            break
    del result[0]
    
    for i in result:
        if i+k-q>0:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 50904
import std.stdio;

void main() {
	auto s = "abcdefghijklmnopqrstuvwxyz";
	long n;
	readf("%s", &n);
	--n;
	if (n == 0) {
		writeln("a");
		return;
	}

	auto result = new char[0];

	while (n >= 0) {
		result ~= s[n % s.length];
		n /= s.length;
		--n;
	}

	foreach_reverse (e;result) {
		write(e);
	}
	writeln;
}


Measured memory_bytes: 2828
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

struct edge
{
    int to, cost;
};
typedef pair<int, int> P; //firstは最短距離,secondは頂点の番号
#define V 100010
vector<edge> G[V];
int d[V];

void dijkstra(int s)
{
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;
        for (int i = 0; i < G[v].size(); i++)
        {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

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

    int n, m;
    cin >> n >> m;
    rep(i, m)
    {
        int l, r, c;
        cin >> l >> r >> c;
        l--, r--;
        G[l].push_back({r, c});
    }
    Rep(i, 1, n)
    {
        G[i].push_back({i - 1, 0});
    }
    dijkstra(0);
    int ans = d[n - 1];
    if (ans == INF)
        ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 9464
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int lli;

using namespace std;

int main() {
   
   int x,y;
   cin >> x >> y;
   
   //cout << 2*x-y/2 << " " <<  2*x-(double)y/2<< endl;

   if(y <= 4*x && x*2 <= y){
   if(2*x-y/2==2*x-(double)y/2){
      cout << "Yes" << endl;
      return 0;
   }else{
   cout << "No" << endl; 
   return 0;
   }
   }else{
   cout << "No" << endl; 
   return 0;

   }
}

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

using namespace std;

typedef long long ll;
#define em emplace_back

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (ll& x : a)
		cin >> x;
	ll l = 0, r = (ll)2e9+1;
	while (r-l>1) {
		ll mid = (l+r)/2;
		bool bl = 1;
		ll now = 0;
		for (const ll& x : a) {
			if (x <= mid)
				continue;
			ll z = (x/mid)+((x%mid)!=0);
			now+=(z-1);
			if (now > k) {
				bl = 0;
				break;
			}
		}
		if (bl)
			r = mid;
		else
			l = mid;
	}
	cout << r << '\n';
	return 0;
}


Measured memory_bytes: 4768
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
    int[] a = new int[n];
    for(int i=0;i<n;i++){
      a[i] = Integer.parseInt(sc.next());
    }
    for(int i=0;i<n;i++){
      if((a[i]%2==0) && ( a[i]%3!=0 && a[i]%5!=0)){
        System.out.print("DENIED");
        System.out.flush();
        return;
      }
    }
    System.out.print("APPROVED");
    System.out.flush();
  }
}

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

#define  ll   long long
#define  pb  push_back
#define  mp  make_pair
#define  MAX  500006
#define  MAX1  10000008
#define  mem(a,v)   memset(a,v,sizeof(a))

template <typename T>
T mymax (T a,T b){return (a>b)?a:b;}
template <typename T>
T mymin (T a,T b){return (a<b)?a:b;}
template <typename T>
T myabs (T a){return (a<0)?(-1*a):a;}
template <typename T>
T mysqrt (T x){if (x == 0 | x == 1)return x;int start = 1, End = x, ans;while (start <= End){int mid = (start + End) / 2;if (mid*mid == x)return mid;if (mid*mid < x){start = mid + 1;ans = mid;}else End = mid-1;}return ans;}

void fastIO (){ios_base::sync_with_stdio(false);cin.tie(0); cout.precision(20);}

ll A[MAX];
ll B[MAX];
ll C[MAX];
vector< ll >V;
vector< ll >Ans;
vector< pair<ll,ll> >VP;
map< ll,ll >M;
vector<ll>prime;
bool mark[MAX1];
ll N=1e7;
void seive (){int limit = sqrt(N*1.0)+2;mark[1]=1;for (int i=4;i<=N;i+=2)mark[i]=1;prime.push_back(2);for (int i=3;i<=N;i+=2){if(!mark[i]){prime.push_back(i);if(i<=limit){for (int j=i*i;j<=N;j+=i*2)mark[j]=1;}}}}

int main ()
{
    fastIO();
    ll a,b,c,n,m,k,p,q,r;
    ll cnt=0,cntr=0,sum=0,ans=1,check=0;
    float x,y,z;
    ll Max= 0,Max1=-1e18+1;
    ll Min = 1e18;
    string s,s1,s3,s4;

    cin>>n;
    sum=1;
    while(n!=1){
        n/=2;
        ans*=2;
        sum+=ans;
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
const int N=190;
using std::max;
using std::min;
int n,m,a[N][N],sum[N][N],dp[N][N][N][15];
char c[N][N];
int main(){
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) scanf("%s",c[i]+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            if (c[i][j]=='.') a[i][j]=1;
            else a[i][j]=0;
            sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j];
        }
    for (int i=1;i<=n;i++)  
        for (int j=1;j<=m;j++)
            for (int k=j;k<=m;k++){
                int l=i,r=n,ans=i-1;
                while (l<=r){
                    int mid=(l+r)>>1;
                    int s=sum[mid][k]-sum[mid][j-1]-sum[i-1][k]+sum[i-1][j-1];
                    if (s==0 || s==(mid-i+1)*(k-j+1))
                        ans=mid,l=mid+1;
                    else r=mid-1;
                }
                dp[i][j][k][0]=ans;
            }
    int k=1;
    for (k=1;dp[1][1][m][k-1]<n;k++)
    for (int h=1;h<=m;h++)
        for (int i=1;i<=n;i++)
            for (int j1=1,j2=j1+h-1;j2<=m;j1++,j2++){
                    if (dp[i][j1][j2][k-1]==n){
                        dp[i][j1][j2][k]=n;
                        continue;
                    }
                    dp[i][j1][j2][k]=dp[dp[i][j1][j2][k-1]+1][j1][j2][k-1];//横
                    if(dp[i][j1][j2][k]==n) continue; 
                    int l=j1,r=j2-1,ans=0;//竖 
                    while (l<=r){
                        int mid=(l+r)>>1;
                        int x=dp[i][j1][mid][k-1],y=dp[i][mid+1][j2][k-1];
                        ans=max(ans,min(x,y));
                        if (x<y) r=mid-1;
                        else l=mid+1;
                    }
    
                    dp[i][j1][j2][k]=max(dp[i][j1][j2][k],ans);
                }
    printf("%d\n",k-1);
    return 0;
}

Measured memory_bytes: 393856
#include <cstdio>
#include <cctype>
#include <string>
#include <iostream>
using namespace std;
template <typename T> inline void read(T& ret) {
  int c = getchar(); ret = 0;
  while(!isdigit(c)) { c = getchar(); }
  while(isdigit(c)) { ret = ret * 10 + c - 48, c = getchar(); }
}
template <typename T, typename... Args> inline void read(T& ret, Args&... args) { read(ret), read(args...); }
int main()
{
	int n, m; read(n, m);
	for(int i = 1; i <= n; i ++)
      for(int j = 1; j <= m; j ++) {
        string s; cin >> s;
        if(s == "snuke") {
          printf("%c%d\n", char('A' - 1 + j), i);
          return 0;
      }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n; cin >> n;
    vector<int> b(n);
    for(int i=0; i<n; i++){
        cin >> b[i];
    }
    vector<int> a;
    int cnt = n-1;
    int flag;
    while(cnt >= 0){
        flag = 0;
        for(int i=cnt; i>=0; i--)
        {
            flag = 0;
            if(b[i] == i+1)
            {
                a.push_back(b[i]);
                b.erase(b.begin() + i);
                cnt--;
                flag = 1;
                break;
            }
        }
        if(flag == 0)
        {
            cout << -1 << endl;
            break;
        }
    }
    if(flag == 1)
    {
        for(int i = 0; i < a.size(); i++)
        {
            cout << a.at(a.size()-1-i) << endl;
        }
    }
}

Measured memory_bytes: 764
#set
a,b,x = gets.chomp.split(" ").map(&:to_i)
count = 0

#main
max_count = b / x
if a >= 0 then
  min_count = (a - 1) / x
else
  min_count = 1
end

count = max_count - min_count
print ("#{count}\n")

Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	int counter = 0;
	counter += a;
	counter += b*5;
	counter += c*10;
	counter += d*50;
	counter += e*100;
	counter += f*500;
	if (counter >= 1000) {
		cout << 1 << endl;
	} else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;

int main() {
	int X;
	cin >> X;

	int gohyakuenn, gohyakuenn_Surplus;
	int goenn;

	gohyakuenn = X / 500;
	gohyakuenn_Surplus = X % 500;
	goenn = gohyakuenn_Surplus / 5;

	cout << gohyakuenn * 1000 + goenn * 5;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> a;
    rep(i,n)
    {
        int tmp;
        cin>>tmp;
        a.push_back(tmp);
    }
    int q;
    int count=0;
    cin>>q;
    rep(i,q)
    {
        int tmp;
        cin>>tmp;
        rep(j,a.size())
        {
            if(a[j]==tmp)
            {
                count++;
                break;
            }
        }
    }
    cout<<count<<endl;

    return 0;
}



Measured memory_bytes: 3196
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
const int MAXN = 1e6+10;
const int modul = 1e9+7;
int ken[300000][5];
int n,m,s,t;

vector<int> v[MAXN];

priority_queue<pair<pair<int,int>,int>> q;

void bfs(int x, int kenDiv, int kenMod){

	q.push({{-kenDiv,-kenMod},x});



	while(!q.empty()){
		pair<pair<int,int>,int> temp = q.top();
		q.pop();

		kenDiv = -temp.first.first;
		kenMod = -temp.first.second;
		x = temp.second;

		if (ken[x][kenMod] < kenDiv){
			continue;
		}
		int slDiv = kenDiv;
		int slMod = (kenMod + 1)%3;
		if (slMod == 0)slDiv++;

		for (auto y : v[x]){
			if (ken[y][slMod] == -1 ||
				ken[y][slMod] > slDiv){
				ken[y][slMod] = slDiv;
				q.push({{-slDiv, -slMod},y});
			}
		}

	}

}

int main()
{

	scanf("%d %d",&n,&m);

	for (int i = 1;i<=m;i++){
		int x,y;
		scanf("%d %d",&x,&y);

		v[x].push_back(y);
	}

	scanf("%d %d",&s,&t);

	for (int i = 1;i<=n;i++)
		for (int j = 0;j<3;j++)
			ken[i][j] = -1;

	ken[s][0] = 0;
	bfs(s,0,0);

	printf("%d\n",ken[t][0]);

	return 0;
}

Measured memory_bytes: 30016
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

lint tall[60];

lint solve(int n, lint x) {
    if (n == 0) {
        if (x == 0) return 0;
        else return 1;
    }

    if (x <= 1) {
        return 0;
    }
    else if (x <= tall[n-1] + 1) {
        return solve(n-1, x-1);
    }
    else if (x == tall[n-1] + 2) {
        return solve(n-1, x-2) + 1;
    }
    else if (x <= tall[n-1] * 2 + 2) {
        return solve(n-1, tall[n-1]) + solve(n-1, x - tall[n-1] - 2) + 1;
    }
    else {
        return 2 * solve(n-1, tall[n-1]) + 1;
    }
}

int main() {
    int n;
    cin >> n;
    lint x;
    cin >> x;

    tall[0] = 1;
    rep(i, n) tall[i+1] = 2 * tall[i] + 3;

    cout << solve(n, x) << endl;
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

main = do
  [n, k] <- readInt
  if n `mod` k == 0
    then put 0
    else put 1


Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

int main() {
    ll h, n; cin >> h >> n;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        ll tmp; cin >> tmp;
        sum += tmp;
    }
    if (sum >= h) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
p=[0]*m
s=[""]*m
flag=[0]*n
pen=[0]*n
penalty=0
for i in range(m):
  p[i],s[i]=input().split()
  if (flag[int(p[i])-1]==0):
    if (s[i]=="WA"):
      pen[int(p[i])-1]+=1
    elif (s[i]=="AC"):
      flag[int(p[i])-1]=1
      penalty+=pen[int(p[i])-1]
print(sum(flag),penalty)

Measured memory_bytes: 17268
#include <bits/stdc++.h>
#include <time.h>
#include <assert.h>


using namespace std;



#define For(i,x,n)  for(long long i=x;i<n;i++)
#define rFor(i,x,n) for(long long i=x;i>=n;i--)
#define itFor(it,st)   for(auto it=st.begin() ; it!=st.end() ; it++)
#define MOD 1000000007
#define PI 3.141592653589793
#define INF 999999999999999999
#define N 1000005
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sp " "
#define cont continue
#define brk break

#define deb1(x)                cout<<#x<<": "<<x<<endl
#define deb2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define deb3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define deb4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define deb5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define deb6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed;
    cout<<setprecision(3);
    srand(time(NULL));

    ll x;
    cin>>x;
    ll cnt = 0;
    ll cur = 0;
    while(1){
    	cur += x;
    	cnt++;
    	if(cur%360 == 0){
    		cout<<cnt;
    		return 0;
    	}
    }
    
    //cout<<"\nTime used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case
    return 0;
}

//s1.substr(1,3) - return 3 characters starting from position 1 as substring of string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan"
//num = atoi(s.c_str()); //convert string s to integer num
//n.erase(i,std::string::npos); //erase i th position in string n , decreasing string size
//s.find(b)!= std::string::npos - finds string b in string a - true if found
//cout<<"Time used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case                


Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define MOD 998244353
#define inv2 499122177

using namespace std;

typedef long long ll;

ll pow_mod(ll x,int k) {
  ll ans=1;
  while (k) {
  	if (k&1) ans=ans*x%MOD;
  	x=x*x%MOD;
  	k>>=1;
  }
  return ans;
}

int f[90005],g[90005];

int main() {
  int n;
  scanf("%d",&n);
  int s=0;
  f[0]=g[0]=1LL;
  for(int i=1;i<=n;i++) {
  	int x;
  	scanf("%d",&x);
  	s+=x;
  	for(int j=s;j>=0;j--) {
  		f[j]=f[j]*2LL%MOD;
  		if (j>=x) {
		  f[j]=(f[j]+f[j-x])%MOD;
		  g[j]=(g[j]+g[j-x])%MOD;
	    }
	  }
  }
  int sum=0;
  for(int i=1;i<=s;i++)
    if (i>=s-i) sum=(sum+f[i])%MOD;
  if (!(s&1)) sum=(sum-g[s>>1]+MOD)%MOD; 
  printf("%lld\n",(pow_mod(3LL,n)-3LL*sum%MOD+MOD)%MOD);
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	int a,b;
	cin>>a>>b;
	int c =0;
	rep1(i,10000000){
		int num = 0;
		int x = i;
		while(x%100==0){
			x/=100;
			num++;
		}
		if(num==a) c++;
		if(c==b){
			cout<<i<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin>>n>>m;
    vector<set<int>> neighbors(n);
    rep(i,m){
        int a,b;cin>>a>>b;
        a--;b--;
        neighbors[a].insert(b);
        neighbors[b].insert(a);
    }
    vector<int> color(n,-1);
    function<bool()> is_bipartite = [&](){
        queue<int> que;
        que.push(0);
        color[0]=0;
        while(!que.empty()){
            int cur = que.front();
            que.pop();
            for(auto x:neighbors[cur]){
                if(color[x]==-1){
                    color[x]=1-color[cur];
                    que.push(x);
                }
                else if(color[x]==color[cur]){return false;}
            }
        }
        return true;
    };
    if(is_bipartite()){
        ll cnt=0;
        rep(i,n){
            cnt += color[i];
        }
        cout << (cnt*(n-cnt)-m) << endl;
    }else{
        cout << n*(n-1)/2-m << endl;
    }

    return 0;
}


Measured memory_bytes: 14720
#include <stdio.h>
int main(void)
{
    int n,x,i,j,k;
    int sum;
    
    while(1)
    {
        scanf("%d %d",&n,&x);
        if(n==0 && x==0) break;
        else
        {
            sum=0;
            for(i=1;i<=(n-2);i++)
            {
                for(j=(i+1);j<=(n-1);j++)
                {
                    for(k=(j+1);k<=n;k++)
                    {
                        if(i+j+k==x) sum++;
                    }
                }
            }
            printf("%d\n",sum);
        }
    }
    
    return 0;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int cuts = 0;

int go(auto& g, int K, int loc) {
    int ht = 0;
    for (int ch : g[loc]) {
        int bl = go(g, K, ch);

        if (bl + 1 > K - !!loc)
            cuts++;
        else
            ht = max(ht, bl + 1);
    }
    return ht;
}

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

    int N, K;
    cin >> N >> K;

    vvi g(N);

    vi par(N);
    for (int i = 0; i < N; i++) {
        cin >> par[i];
        --par[i];
        if (i) {
            g[par[i]].push_back(i);
        }
    }

    go(g, K, 0);
    cout << !!par[0] + cuts << endl;

    return 0;
}



Measured memory_bytes: 12416
#include <iostream>
using namespace std;
typedef long long ll;
ll n, l, sum, lar;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++){
        cin >> l;
        sum += l;
        lar = max(lar, l);
    }
    if (lar < sum - lar) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
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 ll INF = 1e18;

//input
ll h,w,m;

int main(){
    cin >> h >> w >> m;
    vector<ll>yoko(h,0);
    vector<ll>tate(w,0);
    set<P>seen;
    rep(i,m){
        ll a,b;
        cin >> a >> b;
        a--;b--;
        yoko[a]++;
        tate[b]++;
        seen.insert({a,b});
    }
    vector<P>wp;
    vector<P>hp;
    rep(i,h){
        hp.push_back({yoko[i],i});
    }
    rep(i,w){
        wp.push_back({tate[i],i});
    }
    sort(hp.rbegin(),hp.rend());
    sort(wp.rbegin(),wp.rend());
    ll ans = hp[0].first+wp[0].first;
    vector<ll>max_h,max_w;
    rep(i,hp.size()){
        if(hp[i].first==hp[0].first){
            max_h.push_back(hp[i].second);
        }
        else{
            break;
        }
    }
    rep(i,wp.size()){
        if(wp[i].first==wp[0].first){
            max_w.push_back(wp[i].second);
        }
        else{
            break;
        }
    }
    ll x = max_h.size();
    ll y = max_w.size();
    if(x*y>m){
        cout << ans << endl;
        return 0;
    }
    rep(i,x){
        rep(j,y){
            if(seen.count({max_h[i],max_w[j]})==0){
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans-1 << endl;
    return 0;
}


Measured memory_bytes: 44996
#include <stdio.h>
#include <string.h>
#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b

void getstr(char str[]){
	char c;
	int i = 0;
	while((c = getchar()) != '\n')
		str[i++] = c;
	str[i] = '\0';
}

int dfs(int a[26][26],char c){
	static int flag[26] = {0};
	int j, ret = 0;
	flag[c - 'A'] = 1;
	for(j = 0;j < 26;j++){
		if(a[c - 'A'][j]){
			if(flag[j]){
				flag[c - 'A'] = 0;
				return 1;
			}
			ret += dfs(a,'A' + j);
		}
	}
	flag[c - 'A'] = 0;
	return ret;
}
int main(void){
	int h, w, flag, hmin, wmin, hmax, wmax, i, j, k, n, a[26][26];
	char c, str[50][51];
	scanf("%d",&n);
	for(k = 0;k < n;k++){
		scanf("%d%d%*c",&h,&w);
		for(i = 0;i < h;i++)
			getstr(str[i]);
		memset(a,0,sizeof(a));
		for(c = 'A';c <= 'Z';c++){
			flag = 0;
			for(i = 0;i < h;i++){
				for(j = 0;j < w;j++){
					if(str[i][j] == c) flag = 1;
				}
			}
			if(flag){
				hmax = wmax = 0;
				hmin = h - 1;
				wmin = w - 1;
				for(i = 0;i < h;i++){
					for(j = 0;j < w;j++){
						if(str[i][j] == c){
							hmax = max(hmax,i);
							wmax = max(wmax,j);
							hmin = min(hmin,i);
							wmin = min(wmin,j);
						}
					}
				}
				for(i = hmin;i <= hmax;i++){
					for(j = wmin;j <= wmax;j++){
						if(str[i][j] == '.') break;
						else if(str[i][j] != c) a[str[i][j] - 'A'][c - 'A'] = 1;
					}
					if(j != wmax + 1) break;
				}
				if(i != hmax + 1)
					break;
			}
		}
		flag = 0;
		for(i = 0;i < 26;i++)
			flag += dfs(a,c);
		if(c == 'Z' + 1 && !flag)
			printf("SAFE\n");
		else
			printf("SUSPICIOUS\n");
	}
	return 0;
}

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

int main() {
    int N, A, x, y;
    set<int> st;
    scanf("%d", &N);
    x = y = 0;
    for (int i = 0; i < N; i++) {
        scanf("%d", &A);
        bool flg = st.insert(A).second;
        if (flg == false) {
            y = max(y, min(x, A));
            x = max(x, A);
            st.erase(A);
        }
    }
    printf("%lld\n", (long long)x * y);
    return 0;
}

Measured memory_bytes: 4992
<?php
fscanf(STDIN, "%d %d", $N, $K);
$x = explode(" ", trim(fgets(STDIN)));

$answer = PHP_INT_MAX;

for ($i = 0; $i <= $N - $K; $i++) {
	$answer = min($answer, $x[$i + $K - 1] - $x[$i] + min(abs($x[$i + $K - 1]), abs($x[$i])));
}
echo $answer;


Measured memory_bytes: 12792
#include <iostream>
#include <cstdlib>
using namespace std;
long long int gcm(long long int a,long long int b)
{
	if(b == 0)
	{
		return a;
	}
	return gcm(b,a%b);
}
int main(){
	long long int n, x1, x;
	cin >> n >> x1;
	cin >> x;
	long long int g = abs(x - x1);
	for(int i = 1;i < n;i++){
		cin >> x;
		g = gcm(abs(x - x1), g);
	}
	cout << g << endl;
}

Measured memory_bytes: 256
N = int(input())


def n2a(n):
    if n == 0:
        return "z"
    n += 96
    return chr(n)


res = ""

while N > 0:
    t = N % 26
    res = n2a(t) + res
    N //= 26
    if t == 0:
        N -= 1

print(res)


Measured memory_bytes: 61780
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int A,B,K;
  cin >> A >> B >> K;
  if(A>=K){
    cout << A-K << " " << B << endl;
    return 0;
  }
  else if(A+B-K>=0){
    cout << 0 << " " << B-(K-A) << endl;
    return 0;
  }
  else {
    cout << 0 << " " << 0 << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int power(int x, int y) 
{ 
    int res = 1;
    x = x % MOD;
    while (y) {
    	if(y & 1) res = res * x % MOD;
    	y >>= 1;
        x = x * x % MOD;
    }
    return res; 
}

int dp[N];

signed main(){
    IOS;
 	int n, k, mod = MOD;
 	cin >> n >> k;
 	dp[1] = 1;
 	for(int i = 2; i <= k; i++){
 		dp[i] = power(i, n);
 		int l = i, r = k/2+1;
 		while(l > 1){
 			r = i/(i/l+1) +1;
 			dp[i] = (dp[i] - (l-r+1)*dp[i/l] + mod*mod) % mod;
 			l = r-1;
 		}
 	}
 	int ans = 0;
 	for(int i = 1; i <= k; i++){
 		ans = (ans + i*dp[k/i]) % mod;
 	}
	cout << ans;
    return 0;
}

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

n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
a, b, c = 0, 1, 2

dp = [[0, 0, 0] for _ in range(n)]
dp[0] = abc[0][:]
for i in range(1, n):
    dp[i][a] = max(dp[i-1][b], dp[i-1][c]) + abc[i][a]
    dp[i][b] = max(dp[i-1][a], dp[i-1][c]) + abc[i][b]
    dp[i][c] = max(dp[i-1][b], dp[i-1][a]) + abc[i][c]

print(max(dp[n-1]))


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

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i,n)cin>>a[i];
    map<int,int> mp;
    rep(i,n){
        if(a[i]%4==0){
            mp[4]++;
        }
        else if(a[i]%2==0){
            mp[2]++;
        }
    }
    int rem = n - mp[2] - mp[4];
    if(rem<=mp[4]||mp[2]==0&&rem<=mp[4]+1){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 640
import java.util.Scanner;
 
class Main{
 public static void main(String[] args){
   Scanner scanner = new Scanner(System.in);
   int n = scanner.nextInt();
   
   double d,f,g;
   
   Powmod all = new Powmod(10,n);
   Powmod b = new Powmod(9,n);
   Powmod c = new Powmod(8,n);
   
   d=all.powmod();
   f=b.powmod();
   g=c.powmod();
   
   d = d - ((2*f)-g);
   d = d % 1000000007;
   d=(d+1000000007)%1000000007;
   System.out.println((int)d);
 }
   
}

class Powmod{
  
  int x;
  int y;
  
  double powmod(){
    double res=1.0;
    double mod=1000000007;
    for(int i=0;i<y;i++) res = (res * x)%mod;
    return res;
  }
  
  Powmod(int x,int y){
   this.x = x;
   this.y = y;
  }
  
}

Measured memory_bytes: 35876
def dfs(n, str, maxord)
    if str.size == n
        puts str
        return
    end
    imax = maxord + 1;
    for i in 0..imax
        dfs(n, str + (i + "a".ord).chr, [i, maxord].max)
    end
end

n = gets.to_i
dfs(n, "a", 0)

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

#define ll long long int

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, R, X, Y, sum = 0;
  cin >> N >> R;
  for (int i = 0; i < N; i++){
    cin >> X >> Y;
    sum = (X * X + Y * Y <= R * R)? sum + 1 : sum;
  }
  cout << sum << '\n';
  return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
int main(){
	ll N,M,ans=0,sum=0;
	cin >> N >> M;
	vector<ll> A(N);
	FOR(i,0,N)cin >> A[i];
	map<ll,ll> ma;
	ma[0]++;
	FOR(i,0,N){
		(sum += A[i]) %= M;
		ans += ma[sum];
		ma[sum]++;
	}
	cout << ans << endl;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	vector<int> b(N);
	vector<int> c(N);
	rep(i,N) cin >> a[i] >> b[i] >> c[i];

	vector<int> select_a(N);
	vector<int> select_b(N);
	vector<int> select_c(N);
	select_a[0] = a[0];
	select_b[0] = b[0];
	select_c[0] = c[0];
	for(int i=1; i<N; i++){
		select_a[i] = max(select_b[i-1],select_c[i-1]) + a[i];
		select_b[i] = max(select_c[i-1],select_a[i-1]) + b[i];
		select_c[i] = max(select_a[i-1],select_b[i-1]) + c[i];
	}
	cout << max(select_a[N-1], max(select_b[N-1], select_c[N-1])) << endl;
	return 0;
}



Measured memory_bytes: 5544
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,x,y,z;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&e);
	scanf("%d",&f);
	x=100;
	if(x>a) {
		x=a;
	}
	if(x>b) {
		x=b;
	}
	if(x>c) {
		x=c;
	}
	if(x>d) {
		x=d;
	}
	if(e>f) {
		y=f;
	}
	else if(f>e) {
		y=e;
	}
	z=(a+b+c+d+e+f)-(x+y);
	printf("%d\n",z);
	return 0;
}

Measured memory_bytes: 1784
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
    double r;
    cin >> r;
    cout << fixed;
    cout << setprecision(6);
    cout << r*r*M_PI << " " << 2*r*M_PI << endl;
    return 0;
}


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

using namespace std;

vector<int> A;
int n, minn, count = 0;

void swap(int &a, int &b)
{
    int temp;
    temp = a;
    a = b;
    b = temp;
}

void SelectionSort()
{
    for (int i = 0; i < n; i++)
    {
        minn = i;
        for (int j = i; j < n; j++)
        {
            if (A[j] < A[minn])
            {
                minn = j;
            }
        }
        if (A[i] != A[minn])
        {
            swap(A[i], A[minn]);
            count++;
        }
    }
}

int main(int argc, const char **argv)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    A.resize(n + 1);

    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
    }

    SelectionSort();

    for (int i = 0; i < n; i++)
    {
        cout << A[i];
        if (i < n - 1)
            cout << " ";
    }
    cout << "\n" << count << "\n";
    return 0;
}


Measured memory_bytes: 3144
import java.io.*;
import java.util.*;

public class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String[] args) throws IOException {
        String s = br.readLine();

        int count = 0;
        if (s.charAt(1) == 'R')
            count = 1 + ((s.charAt(0) == 'R' ? 1 : 0)) + ((s.charAt(2) == 'R' ? 1 : 0));
        else
            count = ((s.charAt(0) == 'R' ? 1 : 0)) | ((s.charAt(2) == 'R' ? 1 : 0));

        pw.println(count);
        pw.close();
    }
}


Measured memory_bytes: 32756
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=200000+10;

int n,m,vis1[N],vis2[N];

int main() {
	n=read(),m=read();
	for (int i=1;i<=m;++i) {
		int u=read(),v=read();
		if (u>v) swap(u,v);
		if (u==1&&v==n) { puts("POSSIBLE"); return 0; }
		if (u==1) vis1[v]=1;
		if (v==n) vis2[u]=1;
	}
	for (int i=2;i<n;++i)
		if (vis1[i]&&vis2[i]) { puts("POSSIBLE"); return 0; }
	puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 5136
using System.Numerics;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var r = int.Parse(line[2]);
        var t = r - n * m;
        if (t < 0) { Console.WriteLine(0); goto exit; }
        var a = n + t - 1;
        BigInteger b1 = getNum(a, t);
        BigInteger b2 = getNum(t, t);
        BigInteger ans = b1 / b2;
        Console.WriteLine(ans);
        exit:;
    }
    static BigInteger getNum(int a, int b)
    {
        BigInteger res = 1;
        for (int i = 0; i < b; i++)
            res *= a - i;
        return res;
    }
}


Measured memory_bytes: 40864
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;
  ll k=0;
  for(ll i=0;i<n;i++){
    ll a;
    cin >> a;
    if(a==k+1){
      k++;
    }
  }
  if(k!=0)cout << n-k << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 3636
use std::io;
use std::io::prelude::*;

fn main() {
    let mut stdin = io::stdin();
    let mut buf = String::new();
    let _ = stdin.read_to_string(&mut buf);
    let mut iter = buf.split_whitespace();
    let a1: usize = iter.next().unwrap().parse().unwrap();
    let b1: usize = iter.next().unwrap().parse().unwrap();
    let a2: usize = iter.next().unwrap().parse().unwrap();
    let b2: usize = iter.next().unwrap().parse().unwrap();
    let a3: usize = iter.next().unwrap().parse().unwrap();
    let b3: usize = iter.next().unwrap().parse().unwrap();
    let mut d: [usize; 5] = [0; 5];

    d[a1] += 1;
    d[b1] += 1;
    d[a2] += 1;
    d[b2] += 1;
    d[a3] += 1;
    d[b3] += 1;
    println!(
        "{}",
        if d.iter().filter(|&&x| x == 1).count() == 2 && d.iter().filter(|&&x| x == 2).count() == 2 {
            "YES"
        } else {
            "NO"
        }
    );
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)


void aryan_p() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return;
}


int32_t main() {


	int n ;
	cin >> n ;

	mk(b, n - 1, int);
	for (int i  = 0 ; i < n - 1 ; i++) {
		cin >> b[i];
	}

	mk(a, n, int);
	for (int i = 0 ; i < n - 1 ; i++) {
		a[i] = b[i];
	}
	a[n - 1] = INT_MAX;
	for (int i = 0 ; i < n - 1 ; i++) {
		a[i + 1] = min(a[i + 1], b[i]);
	}

	int sum = 0 ;
	for (int i = 0; i < n ; i++) {
		sum += a[i];
	}
	cout  << sum;





	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  int N;
  ll x;
  while (scanf("%d%lld", &N, &x) != EOF) {
    vector<ll> a(N);
    for (int i : range(N)) scanf("%lld", &a[i]);

    ll res = 0;
    for (int i : range(1, N)) {
      if (a[i - 1] > x) {
        res += a[i];
        a[i] -= a[i];
        res += a[i - 1] - x;
        a[i - 1] -= a[i - 1] - x;
      } else if (a[i - 1] + a[i] > x) {
        ll diff = a[i - 1] + a[i] - x;
        a[i] -= diff;
        res += diff;
      } else {
        // none
      }
    }
    printf("%lld\n", res);
  }
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define in inline
#define re register
using namespace std;
in int read() {
	re int t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9') {
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}
int n,m,rt[200002],head[200002],a[200002],ls[20000002],rs[20000002],ans[200002],u,v,cnt,tot,s[20000002],la,r[200002],val[20000002];
struct edge{
	int to,next;
}e[400002];
inline void bu(re int x,re int y){
	e[++tot].to=y;
	e[tot].next=head[x];
	head[x]=tot;
}
inline int insert(re int v,re int l,re int r,re int x,re int vv) {
	int y=++cnt;
	s[y]=s[x]+1;val[y]=max(val[x],vv);
	if(l==r){
	val[y]=max(val[y],vv);
	return y;}
	ls[y]=ls[x];
	rs[y]=rs[x];
	int mid=(l+r)>>1;
	if(v<=mid)ls[y]=insert(v,l,mid,ls[x],vv);
	else rs[y]=insert(v,mid+1,r,rs[x],vv);
	return y;
}
inline int find(re int p,re int l,re int r,re int x){
	if(!p)return 0;
	if(r<=x)return val[p];
	re int mid=l+r>>1;
	if(x>mid)return max(find(ls[p],l,mid,x),find(rs[p],mid+1,r,x));
	else return find(ls[p],l,mid,x);
}
inline void dfs(re int x,re int y){
	ans[x]=find(rt[y],1,1e9+1,a[x]);
	rt[x]=insert(a[x]+1,1,1e9+1,rt[y],ans[x]+1);
	ans[x]=max(ans[x],ans[y]);
	for(re int i=head[x];i;i=e[i].next)
		if(e[i].to!=y)dfs(e[i].to,x);
}
int main(){
	n=read();
	for(re int i=1;i<=n;++i)a[i]=read();
	for(re int i=1;i<n;++i){
		u=read();
		v=read();
		bu(u,v);
		bu(v,u);
	}
	dfs(1,1);
	for(re int i=1;i<=n;++i)printf("%d\n",ans[i]+1);
}


Measured memory_bytes: 134972
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int m;
  cin >> m;
  cout << 48 - m << endl;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;
//max flow

vector<long long > A;
map<ll, ll> m;
void dec(int i){
    m[i]--;
    if(m[i] == 0)m.erase(i);
}

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int N;
    cin >> N;
    A = vector<ll>(N);
    rep(i, N)cin >> A[i];
    rep(i, N){
        m[-A[i]]++;
    } 
    
    ll ans = 0;
    for(int i = 0; i < N && m.size() > 0; i++){
        auto a = -(m.begin()->first);
        //debug(a)
        //debug(m[-a])
        dec(-a);
        int k = 1;
        while(k<=a)k<<=1;
        ll b = k-a;
        if(m.count(-b)){
            ++ans;
            dec(-b);
        }
        

    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 14336
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, K, ans{1000000000};
  cin >> N >> K;
  vector<int> x(N);
  for (int i = 0; i != N; ++i) {
    cin >> x[i];
  }

  for (int i = 0; i != N - K + 1; ++i) {
    auto a = x[i], b = x[i + K - 1];
    if ((long long){a} * b < 0) {
      a = abs(a);
      ans = min(ans, 2 * (a + b) - max(a, b));
    } else {
      ans = min(ans, max(abs(a), abs(b)));
    }
  }

  cout << ans << endl;
}


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

void solve() {
  string a, b, c;
  cin >> a >> b >> c;
  int az = (int) a.size();
  bool f = (a[az -1] == b[0]);
  int bz = (int) b.size();
  bool ff = (b[bz - 1] == c[0]);
  if(ff && f) {
    cout << "YES";
  }
  else {
    cout << "NO";
  }
}


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


Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main(){
  int n,ans=0;
  int a[101];
  int num[101] = {0};
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  for(int i=0; i<n; i++){
    num[a[i]]++;
  }
  for(int i=1; i<=100; i++){
    if(num[i]){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long unsigned int
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
ll cnt[200005];
int main() {
	
	ll n;
	cin>>n;
	ll ar[n];
	for(int i=1;i<=n;i++)
	cin>>ar[i],cnt[ar[i]]++;

	ll ans=0;
	for(int i=1;i<=200000;i++)
	{
		if(cnt[i]>=2)
		{
			ll n=cnt[i];
			ans+=(n*(n-1))/2;
		}
	}
	for(int i=1;i<=n;i++)
	{
		ll temp=ans;
		if(cnt[ar[i]]>=2)
		{
			ll n=cnt[ar[i]];
			temp-=(n*(n-1))/2;
			n--;
			temp+=(n*(n-1))/2;
		}
		cout<<temp<<endl;
	}






	return 0;
}

Measured memory_bytes: 4736
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
int main(){
    int n,x;
    cin >> n >> x;
    const ll mod = 1e9+7;
    vector<int>s(n);
    rep(i,n)cin >> s[i];
    sort(s.rbegin(),s.rend());
    vector<ll>dp(x+1);
    dp[x] = 1;
    rep(i,n){
        vector<ll>ndp(x+1);
        for(int j = 0; j <= x; j++){
            ndp[j] = dp[j] * (n-1-i+mod) % mod;
        }
        for(int j = 0; j <= x; j++){
            (ndp[j%s[i]] += dp[j]) %= mod;
        }
        swap(dp,ndp);
    }
    ll ans = 0;
    for(int i = 0; i <= x; i++){
        ans = (ans + dp[i]*i) % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <utility>

int gcd(int x, int y) {
  if (x < y) std::swap(x, y);
  if (y == 0) {
    return x;
  } else {
    return gcd(y, x % y);
  }
}

int main() {
  int x, y;
  std::cin >> x >> y;
  std::cout << gcd(x, y) << std::endl;
}


Measured memory_bytes: 3104
#include<stdio.h>
int main()
{
	int num[4][4];
	for (int i = 1; i<=3; i++)
	{
		for (int j = 1; j<=3; j++)
		{
			scanf("%d", &num[i][j]);
		}
	}
	for (int k = -1000; k <= 1000; k++)
	{
		int a[4], b[4];
		a[1] = k;
		b[1] = num[1][1] - a[1];
		b[2] = num[1][2] - a[1];
		b[3] = num[1][3] - a[1];
		a[2] = num[2][1] - b[1];
		a[3] = num[3][1] - b[1];
		int flag = 0;
		if (num[2][2] != a[2] + b[2])flag = 1;
		if (num[2][3] != a[2] + b[3])flag = 1;
		if (num[3][3] != a[3] + b[3])flag = 1;
		if (num[3][2] != a[3] + b[2])flag = 1;
		if (!flag)
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128