akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <deque>
#include <stack>
#include <iomanip>
#include <cmath>


using namespace std;


typedef long long ll;
typedef long double ld;


const int MAXN = 401;
const ll MOD = 1000000007ll;;


int N, C;
ll A[MAXN], B[MAXN], memoBase[MAXN][MAXN], memoPow[MAXN][MAXN], memoSol[MAXN][MAXN];


ll modSum(ll a, ll b) {
  return ((a % MOD) + (b % MOD)) % MOD;
}


ll modProd(ll a, ll b) {
  return ((a % MOD) * (b % MOD)) % MOD;
}


ll getPow(ll x, ll e) {
  if (memoPow[x][e] != 0) return memoPow[x][e];
  if (e == 0) return memoPow[x][e] = 1;
  return memoPow[x][e] = modProd(getPow(x, e-1), x);
}


void input() {
  cin >> N >> C;
  for (int i = 1 ; i <= N ; i++) {
    cin >> A[i];
  }
  for (int i = 1 ; i <= N ; i++) {
    cin >> B[i];
  }
}


void preprocess() {
}


void solve() {
  for (int i = 1 ; i <= N ; i++) {
    for (int v = 0 ; v <= C ; v++) {
      for (int b = A[i] ; b <= B[i] ; b++) {
        memoBase[v][i] = modSum(memoBase[v][i], getPow(b, v));
      }
    }
  }
 // for (int i = 1 ; i <= N ; i++) {
 //   memoSol[0][i] = memoBase[0][i];
 // }
  memoSol[0][0] = 1;
  for (int sum = 0 ; sum <= C; sum++) {
    for (int i = 1 ; i <= N ; i++) {
      for (int v = 0 ; v <= sum ; v++) {
        memoSol[sum][i] = modSum(memoSol[sum][i], modProd(memoBase[v][i], memoSol[sum-v][i-1]));
      }
    }
  }
  cout << memoSol[C][N];
  /*for (int i = 0 ; i <= N ; i++) {
    for (int v = 0 ; v <= C ; v++) {
      cerr << "memoSol[" << v << "][" << i << "] = " << memoSol[v][i] << " ";
    }
    cerr << "\n";
  }*/
}






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

  int T;
//  cin >> T;
  T = 1;

  for (int i = 0 ; i < T ; i++) {
    input();
    preprocess();
    solve();
  }

  return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int ii=1,f=0;
	long long temp1=1;
	long long a,temp2;
	cin>>n;
	for(ii=1;ii<=n;ii++)
	{
		cin>>a;
		if(f==0)
		{
			if(a==0)
			{
				cout<<0;
				return 0;
			}
			
			temp2=temp1*a;

			if(temp2<temp1 && a!=0)
			{	
				temp1=-1;
				f=1;
			}
			else
				temp1=temp2;			
		}
		else
		{
			if(a==0)
			{
				cout<<0;
				return 0;
			}
			else
				temp1=-1;
		}	
	}
	
	if(temp1>1000000000000000000)
		cout<<-1;
	else
		cout<<temp1;			
	return 0;
}

Measured memory_bytes: 3632
using System;
class Program{
    static void Main(string[]args){
        int N=int.Parse(Console.ReadLine());
        string[]a=Console.ReadLine().Split(' ');
        int[]A=new int[a.Length];
        for(int i=0;i<a.Length;i++){
            A[i]=int.Parse(a[i]);
            
        }
        for(int i=0;i<N-1;i++){
            for(int j=i+1;j<N;j++){
                if(A[i]<A[j]){
                    int n=A[i];
                    A[i]=A[j];
                    A[j]=n;
                }
            }
        }
        
        Console.WriteLine(Math.Abs(A[A.Length-1]-A[0]));
        
    }
}

Measured memory_bytes: 11092
N,A,B=map(int,input().split())
S=input()
sum_pass=0
sum_out=0
for i in range(N):
    if S[i]=='a' and sum_pass<(A+B):
        print('Yes')
        sum_pass+=1
    elif S[i]=='b' and sum_pass<(A+B) and sum_out<B:
        sum_out+=1
        sum_pass+=1
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 4016
#include<stdio.h>

int main(){
  int G[100][100];
  int n,i,j,u,k,v;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      G[u][v]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j>0)printf(" ");
      printf("%d",G[i][j]);
    }
    printf("\n");
  }
  return 0;
}



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

int main(){
  string w;
  cin>>w;
  
  map<char,int> m;
  
  for(int i=0;i<w.size();i++){
    char x=w.at(i);
    if(!m.count(x)){
      m[x]=1;
    }else{
      m.at(x)++;
    }
  }
  
  bool flag=true;
  for(auto p:m){
    if(p.second%2==1){
      flag=false;
      break;
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;



int main(){
    int H, W;
    string S;
    cin >> H >> W;
    rep(i,H){
        cin >> S;
        cout << S << endl
             << S << endl;
    }
}


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

double func( double t,double a,double h ){
  double tmp = t - h*0.006;
  return abs( tmp - a );
}

int main() {
  int n;
  double t,a;
  cin >> n >> t >> a;
  vector<double> h(n);
  for(int i=0;i<n;i++){
    cin >> h.at(i);
  }
  
  int ans;
  double min_diff;
  for(int i=0;i<n;i++){
    double diff = func(t,a,h.at(i));
    //cout << diff << endl;
    if( i == 0 ){
      min_diff = diff;
      ans = i+1;
    }else if( diff < min_diff ){
      min_diff = diff;
      ans = i+1;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

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

	bool ans = false;
	for (int i = 0; i < N; i++)
	{
		for (int j = i+1; j < N; j++)
		{
			swap(p[i], p[j]);

			bool flag = true;
			for (int k = 1; k < N; k++)
			{
				if(p[k-1] > p[k])flag = false;
			}

			if(flag)ans = true;

			swap(p[i], p[j]);
		}
	}

	bool flag = true;
	for (int k = 1; k < N; k++)
	{
		if (p[k - 1] > p[k])flag = false;
	}

	if (flag)ans = true;

	cout<<(ans?"YES":"NO")<<endl;

	return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
count = [0]*N  # count[i] は i 番目まで S[:i+1] の解
for i in range(1, N):
    count[i] = count[i-1]
    if S[i-1: i+1] == "AC":
        count[i] += 1
for _ in range(Q):
    l,r = map(int, input().split())
    print(count[r-1] - count[l-1])


Measured memory_bytes: 6140
#include <iostream>

#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

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

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

    if(N == 25) PRINT("Christmas");
    if(N == 24) PRINT("Christmas Eve");
    if(N == 23) PRINT("Christmas Eve Eve");
    if(N == 22) PRINT("Christmas Eve Eve Eve");

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;
int n;
int a[300000];
int MAXN = 2147483647;

map<ll,int> mp;

ll len=0;

void init()
{
    scanf("%d",&n);
    for (int i=0; i<n; ++i)
        scanf("%d",&a[i]);
}

void clearLen(int i)
{
    for (auto it=mp.begin(); it!=mp.end();)
    {
        if (it->first>len) it = mp.erase(it);
        else it++;
    }
}

bool addState(int k)
{
    int nowLen=len;
    while (nowLen>=1)
    {
        auto it = mp.find(nowLen);
        if (it!=mp.end())
        {
            if (mp[nowLen]<k-1)
            {
                mp[nowLen]+=1;
                return 1;
            }else
            {
                mp.erase(it);
                nowLen-=1;
            }
        }else
        {
            mp[nowLen]=1;
            if (mp[nowLen]>k-1) return 0;
            return 1;
        }
    }
    return 0;
}

bool check(int ind)
{
    mp.clear();
    len=a[0];
    
    if (ind<1) return 0;
    for (int i=1; i<n; ++i)
    {
        len=a[i];
        if (a[i]>a[i-1])
        {
        }
        else
        {
            clearLen(i);
            bool flag=addState(ind);
            if (flag==0)
                return 0;
        }
    }
    return 1;
}

int binarySearch(int l,int r)
{
    int mid=0;
    while (l<=r)
    {
        mid=l+(r-l)/2;
        bool checkMid=check(mid);
        bool checkPre=check(mid-1);
        if (checkMid==1 && checkPre==0)
            return mid;
        if (checkMid)
            r=mid-1;
        else l=mid+1;
    }
    return -1;
}

int main()
{
    init();
    cout<<binarySearch(1,MAXN)<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int[] student = new int[30];
		for (int i=0; i<28; i++) {
			student[sc.nextInt()-1]++;
		}
		for (int i=0; i<30; i++) {
			if (student[i]==0) out.println(i+1);
		}
	}
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define Ba 10007
#define mod 1000000033

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

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

  int N;
  cin>>N;
  vector<int> A(N),B(N);
  vector<int> dA(N),dB(N);
  rep(i,N){
    cin>>A[i];
  }
  rep(i,N){
    dA[i]=A[i]^A[(i+1)%N];
  }
  rep(i,N){
    cin>>B[i];
  }
  rep(i,N){
    dB[i]=B[i]^B[(i+1)%N];
  }
  vector<ll> Ah(N+1,0),Bh(N+1,0);
  rep(i,N)Ah[i+1]=(Ah[i]+dA[i]*mod_pow(Ba,i)%mod)%mod;
  rep(i,N)Bh[i+1]=(Bh[i]+dB[i]*mod_pow(Ba,i)%mod)%mod;

  auto extract = [&](ll l,ll r,bool f) {
    if(!f) return (Ah[r]-Ah[l]+mod)*mod_pow(mod_pow(Ba,mod-2),l)%mod;
    else return (Bh[r]-Bh[l]+mod)*mod_pow(mod_pow(Ba,mod-2),l)%mod;
  };

  vector<int> ks;
  rep(k,N){
    int l=N-k;
    if(extract(k,N,false)==extract(0,l,true)&&extract(0,N-l,false)==extract(l,N,true)){
      ks.push_back(k);
    }
  }

  rep(i,ks.size()){
    cout<<ks[i]<<" "<<(A[ks[i]]^B[0])<<endl;
  }

  return 0;
}


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

using namespace std;

#define int long long
//region template
#define double long double
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
template<typename T1> void read(T1& arg) { cin >> arg; }
template<typename T1, typename... T2> void read(T1& arg, T2&... args) { cin >> arg; read(args...); }
#define make(t, ...) t __VA_ARGS__; read(__VA_ARGS__);
//endregion




void solve() {
    make(int, n, W);
    vector<int> w(n), v(n);
    forn (i, n) {
        cin >> w[i] >> v[i];
    }
    const int V = 100100;
    vector<vector<int>> dp(n, vector<int>(V, 2e9));
    dp[0][0] = 0;
    dp[0][v[0]] = w[0];
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < V; ++j) {
            dp[i][j] = dp[i - 1][j];
            if (j - v[i] >= 0) {
                dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
            }
        }
    }
    int ans = INT_MIN;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < V; ++j) {
            if (dp[i][j] <= W) {
                ans = max(ans, j);
            }
        }
    }
    cout << ans << endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    while (cin.peek() != EOF) {
        solve();
        cout << endl << endl;
        string s;
        do getline(cin, s);
        while (!cin.eof() && !s.empty());
        while (isspace(cin.peek())) cin.get();
    }
#else
    solve();
#endif
    return 0;
}


Measured memory_bytes: 79488
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

using P1 = array<int, 26>;
using P2 = array<int, 365>;

struct state{
    array<int, 26> prv;
    array<int, 365> ans;
    int val;
    bool operator<(const state &a) const { return val > a.val; }
    state(P1 a, P2 b, int x) : prv(a), ans(b), val(x) {};
};


int main() {
    int d;
    cin >> d;
    array<int, 26> A{};
    for (auto &&k : A) cin >> k;
    vector<array<int, 26>> v(d);
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < 26; ++j) {
            scanf("%d", &v[i][j]);
        }
    }
    vector<int> ans(d);
    int W = 10;
    vector<state> a;
    a.emplace_back(P1{}, P2{}, 0);
    fill(a[0].prv.begin(),a[0].prv.end(), -1);
    for (int i = 0; i < d; ++i) {
        priority_queue<state> Q;
        for (auto &&s : a){
            for (int k = 0; k < 26; ++k) {
                state ss(s);
                ss.ans[i] = k;
                ss.val += v[i][k];
                ss.prv[k] = i;
                for (int l = 0; l < 26; ++l) {
                    ss.val -= (i-ss.prv[l])*A[l];
                }
                Q.emplace(ss);
                if(Q.size() > W) Q.pop();
            }
        }
        a.clear();
        while(!Q.empty()) a.emplace_back(Q.top()), Q.pop();
    }
    for (auto &&m : a.back().ans) {
        printf("%d\n", m+1);
    }
    return 0;
}

Measured memory_bytes: 3888
import heapq
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())),reverse=True)[:x]
q=sorted(list(map(int,input().split())),reverse=True)[:y]
r=list(map(int,input().split()))
l=p+q
ans=sum(l)
hq=[]
for i in l:
    heapq.heappush(hq,i)
rq=[]
for i in r:
    heapq.heappush(rq,-i)
a=heapq.heappop(hq)
b=-heapq.heappop(rq)
while a<b:
    ans+=b-a
    if hq:
        a=heapq.heappop(hq)
    else:
        break
    if rq:
        b=-heapq.heappop(rq)
    else:
        break
print(ans)

Measured memory_bytes: 23344
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.Delayed;
import java.util.logging.Logger;


public class Main {
	static final long MOD=998244353;
	public static void main(String[] args){
		PrintWriter out = new PrintWriter(System.out);
		InputReader sc=new InputReader(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		System.out.println(A*B);
	}

	static class InputReader { 
		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;
		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}
 
		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}
 
		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}
 
		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}
 
		public boolean hasNext() {
			skip();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public double nextDouble() {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
 
		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 32456
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int inf = 0x3f3f3f3f;
const int maxn = 100000 + 100;
string s;
int main()
{
  cin >> s;
  if (s.find("AC") != string::npos)
  {
    cout << "Yes\n";
  }
  else
  {
    cout << "No\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <utility>
#include <queue>
#include <ios>
#include <iomanip>
#include <ctime>
#include <tuple>

#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; i++)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFF
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")

#define PInt pair<int, int>
#define PLL pair<long long, long long>
#define VInt vector<int>
#define VLL vector<long long>
#define MatrixInt vector<vector<int>>
#define MatrixLL vector<vector<long long>>

typedef long long ll;
using namespace std;

class UnionFind {
public:
    vector<int> par;
    vector<int> num;
    int root(int i) {
        if (par[i] == i)
            return i;
        else
            return par[i] = root(par[i]);
    }
    UnionFind(int n) : par(n, 0), num(n, 1) {
        iota(ALL_OF(par), 0);
    }
    void unite(int i, int j) {
        int ri = root(i);
        int rj = root(j);
        if (ri != rj) {
            par[ri] = rj;
            num[rj] += num[ri];
        }
    }
    bool same(int i, int j) {
        int ri = root(i);
        int rj = root(j);
        return ri == rj;
    }
};

int main() {

    int n, m;
    cin >> n >> m;
    vector<int> a(m, 0), b(m, 0);
    UnionFind uf(n);
    REP(i, m) {
        cin >> a[i] >> b[i];
        // make them 0-indexed
        a[i]--;
        b[i]--;
    }

    vector<ll> ans(m, 0);
    ans[m-1] = (ll)n * ((ll)n - 1ll) / 2ll;
    for (int i = m-1; i--;) {

        if (!uf.same(a[i+1], b[i+1])) {
            int na = uf.num[uf.root(a[i+1])];
            int nb = uf.num[uf.root(b[i+1])];
            ans[i] = ans[i+1] - (ll)na * (ll)nb;
            uf.unite(a[i+1], b[i+1]);
        } else {
            ans[i] = ans[i+1];
        }

    }

    REP(i, m) cout << ans[i] << endl;

    
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define inf 1000000000
#define N 100009
#define M 300009
#define E 4000009
using namespace std;

int n,tot,dfsclk,e[N][2],fst[M],pnt[E],nxt[E];
int fa[N],sz[N],d[N],anc[N],pos[N],son[N],id[N],tg[M];
bool vis[N];
struct node{ int x,y; }mn[M];
bool operator <(node u,node v){ return u.x<v.x; }
void add(int x,int y){
	pnt[++tot]=y; nxt[tot]=fst[x]; fst[x]=tot;
}
void dfs(int x){
	int i,y; sz[x]=1;
	for (i=fst[x]; i; i=nxt[i]){
		y=pnt[i];
		if (y!=fa[x]){
			fa[y]=x; d[y]=d[x]+1;
			dfs(y); sz[x]+=sz[y];
			if (sz[y]>sz[son[x]]) son[x]=y;
		}
	}
}
void dvd(int x,int tp){
	int i,y; anc[x]=tp; pos[x]=++dfsclk;
	if (son[x]) dvd(son[x],tp);
	for (i=fst[x]; i; i=nxt[i]){
		y=pnt[i];
		if (y!=fa[x] && y!=son[x]) dvd(y,y); 
	}
}
int lca(int x,int y){
	for (; anc[x]!=anc[y]; x=fa[anc[x]])
		if (d[anc[x]]<d[anc[y]]) swap(x,y);
	return d[x]<d[y]?x:y;
}
void maintain(int k){	
	mn[k]=min(mn[k<<1],mn[k<<1|1]); mn[k].x+=tg[k];
}
void ins(int k,int l,int r,int x,int y,int z,int v){
	if (x<=l && r<=y){
		tg[k]+=v; mn[k].x+=v; if (v>0) add(k,z);
		return;
	}
	int mid=l+r>>1;
	if (x<=mid) ins(k<<1,l,mid,x,y,z,v);
	if (y>mid) ins(k<<1|1,mid+1,r,x,y,z,v);
	maintain(k);
}
void build(int k,int l,int r){
	mn[k].x=0; mn[k].y=l; 
	if (l==r){ id[l]=k; return; }
	int mid=l+r>>1;
	build(k<<1,l,mid); build(k<<1|1,mid+1,r);
}
void ins(int i,int x,int y,int v){
	for (; anc[x]!=anc[y]; x=fa[anc[x]])
		ins(1,1,n,pos[anc[x]],pos[x],i,v);
	if (d[y]<d[x]) ins(1,1,n,pos[y]+1,pos[x],i,v);
}
void ins(int i,int v){
	int x=e[i][0],y=e[i][1],z=lca(x,y);
	ins(i,x,z,v); ins(i,y,z,v);
}
void mdy(int x,int y){
	int i=id[x]; mn[i].x=y;
	for (i>>=1; i; i>>=1) maintain(i);
}
int main(){
	scanf("%d",&n);
	int i,j,k,x,y;
	for (i=1; i<n; i++){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	d[1]=1; dfs(1); dvd(1,1);
	tot=0; memset(fst,0,sizeof(fst));
	build(1,1,n);
	for (i=1; i<n; i++){
		scanf("%d%d",&e[i][0],&e[i][1]);
		ins(i,1);
	}
	int res=n;
	while (res>1 && mn[1].x<2){
		if (!mn[1].x)
			mdy(mn[1].y,inf);
		else{
			for (i=id[mn[1].y]; i; i>>=1){
				for (j=fst[i]; j; j=nxt[j]){
					k=pnt[j];
					if (vis[k]) fst[i]=nxt[j]; else break;
				}
				if (fst[i]){
					vis[k]=1; ins(k,-1); res--; break;
				}
			}
			mdy(mn[1].y,inf);
		}
	}
	puts(res>1?"NO":"YES");
	return 0;
}


Measured memory_bytes: 32896
#include <iostream>
#include <cstdint>

const int MOD = 1000000007;

using namespace std;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (a < c && b <= c) {
    cout << 0 << endl; //abcd
    return 0;
  }
  if (c < a && d <= a) {
    cout << 0 << endl; //cdab
    return 0;
  }

  if (a < c) {
    if (b < d) {
      cout << b - c << endl; //acbd
      return 0;
    } else {
      cout << d - c << endl; //acdb
      return 0;
    }
  }
  if (c < a) {
    if (d < b) {
      cout << d - a << endl; //cadb
      return 0;
    } else {
      cout << b - a << endl;
      return 0;
    }
  }
  if (a == c) {
    if (b <= d) {
      cout << b - a << endl;
      return 0;
    } else {
      cout << d - a << endl;
    }
  }
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
X = [0] * (N + 1)
S = [0] * (N + 1)
for i in range(N):
  X[i + 1] = X[i] ^ A[i]
  S[i + 1] = S[i] + A[i]
cnt = 0
s = 0
t = 1
while True:
  while t <= N:
    if X[t] ^ X[s] == S[t] - S[s]:
      t += 1
    else:
      t -= 1
      break
  if t > N:
    t -= 1
  cnt += t - s
  if s == N - 1:
    break
  while True:
    s += 1
    if X[t] ^ X[s] == S[t] - S[s]:
      break
  if s == t:
    t += 1
print(cnt)

Measured memory_bytes: 28232
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int main() {
	long n, m; cin >> n >> m;
	vector<pair<long, long>> p(n);
	for (int i = 0; i < n; ++i) {
		long a, b; cin >> a >> b;
		p[i] = make_pair(a,b);
	}
	sort(p.begin(), p.end());
	long price = 0;
	for (auto itr = p.begin(); itr != p.end(); ++itr) {
		if (m < itr->second) {
			price += m * itr->first;
			break;
		} else {
			price += itr->second * itr->first;
			m -= itr->second;
		}
	}
	cout << price << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>

using namespace std;

void func_A() {

    int n;
    cin >> n;

    switch (n % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9: 
        cout << "hon";
        break;
    case 0:
    case 1:
    case 6:
    case 8: 
        cout << "pon";
        break;
    case 3:
        cout << "bon";
        break;
    }


}

void func_B() {

    int k;
    string s;
    cin >> k >> s;

    if (k < s.size()) s = s.substr(0, k) + "...";

    cout << s;
}

void func_C() {

    double a, b, h, m;
    cin >> a >> b >> h >> m;

    //長針と短針の間の角度
    double h_angle = h * 30 + 30 * m / 60;
    double m_angle = m * 6;
    double angel = (h_angle > m_angle) ? h_angle - m_angle : m_angle - h_angle;
    //cout << angel << "\n";
    if (angel > 180) angel = 360 - angel;

    //cout << angel << "\n";
    double ans = 0;
    //0時みたいな0°と6時みたいな180°のパターンは別に対処
    if (angel == 0) ans = (a > b) ? a - b : b - a;
    else if (angel == 180) ans = a + b;
    else {
        //他の角度では、余弦定理を使えば求められる
        double pi = 3.14159265358979323846;
        double radian = angel * (pi / 180);

        ans = a * a + b * b - 2 * a * b * cos(radian);
        ans = sqrt(ans);
    }

    cout << fixed << setprecision(10) << ans;

}

int main() {

    //func_A();
    //func_B();
    func_C();

    return 0;
}

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

using namespace std;

typedef pair<int, int> pair_t;

bool comp(const pair_t &l, const pair_t &r){
  return l.second < r.second;
}

int main(){
  int n,m;
  int count = 0;
  pair_t tmp;
  vector<pair_t> v;
  
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    cin >> tmp.first >> tmp.second;
    v.push_back(tmp);
  }
  
  sort(v.begin(), v.end(), comp);
  
  int second_data;
  count++;
  second_data = v[0].second;
  
  for(int i = 1; i < m; i++){
    if(v[i].second > second_data && v[i].first >= second_data){
      count++;
      second_data = v[i].second;
    }
  }
  cout << count << endl;
  return 0;
}

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

int main(void) {
	int n,count;
	count = 0;
	cin >> n;
	int p;
	for (int i = 0; i < n; i++) {
		cin >> p;
		if (p != i + 1) {
			count++;
		}
	}
	if (count <= 2) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)

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

void solve(long long N, long long X, std::vector<long long> x){
    rep(i, N){
        x[i] -= X;
        x[i] = abs(x[i]);
    }
    ll ans=x[0];
    rep(i, N-1){
        ans = gcd(ans, x[i+1]);
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    std::vector<long long> x(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
    }
    solve(N, X, std::move(x));
    return 0;
}


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

using namespace std;

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

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);

    vector<bool> fromOne(n + 1);
    vector<bool> toN(n + 1);

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

        if (x == 1)
            fromOne[y] = true;

        if (y == n)
            toN[x] = true;
    }

    for (int i = 1; i <= n; i++)
    {
        if (fromOne[i] && toN[i])
        {
            printf("POSSIBLE\n");
            return 0;
        }
    }

    printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 256
#ABC130 B
N,X = list(map(int, input().split()))
L = list(map(int, input().split()))
D = 0
ans = 1
for i in range(0, N):
    D += L[i]
    if D > X:
        print(ans)
        break
    else:
        ans += 1
if sum(L) <= X:
    print(N+1)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef pair<int, int> pint;
ll inf = 1000000000 + 7;


vint v1, v2;
int main() {
	int N, M, X, Y;
	int x;
	int Z;
	bool senso = true;
	cin >> N >> M >> X >> Y;

	rep(i, N) {
		cin >> x;
		v1.push_back(x);
	}

	rep(i, M) {
		cin >> x;
		v2.push_back(x);
	}


	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());

	rep(i, Y - X) {
		Z = X + i + 1;
		
		if (Z > v1[N - 1] && v2[0] >= Z) {
			senso = false;
			break;
		}

	}



	if (senso == false) {
		cout << "No War" << endl;
	}
	else
		cout << "War" << endl;
	


	return 0;
}

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

using namespace std;

long long n;
long long int cnt[1005];
long long int answer = 1;

bool isPrime(int m){
  bool judge = 1;
  for(int i = 2; i < m; ++i){
    if(m % i == 0){
      judge = 0;
      break;
    }
  }
  return judge;
}

long long int solver(){
  for(int i = 1; i <= n; ++i){
    cnt[i] = 1;
  }
  for(int i = 2; i <= n; ++i){
    for(int j = 2; j <= i; ++j){
      if(i % j == 0 && isPrime(j) == 1){
        cnt[j]++;
        long long int tmp = j * j;
        while(i % tmp == 0){
          cnt[j]++;
          tmp *= j;
        }
      }
    }
  }
  for(int i = 1; i <= n; ++i){
    answer *= cnt[i];
    answer = answer % (1000000000 + 7);
    //cout << cnt[i] << endl;
    //cout << answer << endl;
  }
  return answer % (1000000000 + 7);
}

int main(){
  cin >> n;
  cout << solver() << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var a = int.Parse(ReadLine());
        var s = ReadLine();
        
        var ans = (3200 <= a) ? s : "red";
        
        WriteLine(ans);
    }
}


Measured memory_bytes: 27404
#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 w(x)            int x; cin>>x; while(x--)
#define fr(i,a,b)       for(int i = a; i < b; i++)
#define mod				1000000007
void c_p_c()
{
	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
}

int candies(vi &arr, int n, int k)
{
	int dp[n + 1][k + 1];
	//base case
	for (int j = 0; j <= k; j++)
		dp[1][j] = (j > arr[1]) ? 0 : 1;

	for (int i = 2; i <= n; i++)
	{
		for (int j = 0; j <= k; j++)
		{
			if (j == 0)
				dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = (mod + dp[i][j - 1] + dp[i - 1][j] - ((j - arr[i] - 1 >= 0) ? dp[i - 1][j - arr[i] - 1] : 0)) % mod;
		}
	}
	return dp[n][k];
}

void solve()
{
	int n, k;
	cin >> n >> k;
	vi arr(n + 1);
	fr(i, 1, n + 1)
	cin >> arr[i];
	cout << candies(arr, n, k) << endl;
}

int32_t main()
{
	c_p_c();
	solve();
	return 0;
}

Measured memory_bytes: 81616
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;


public  class Main 
{

	   
	   static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 

  

	  // Complete the hurdleRace function below.
//    public static void solve() {
//    	FastReader s=new FastReader();

   
    public static void main(String[] args) throws IOException {
    	FastReader s=new FastReader();
    	long n = s.nextLong();
    	
    	long sum=0,c=1;
    	while(n>0) {
    		sum+=c;
    		c*=2;
    		n=n/2;
    		
    		
    	}
    	System.out.println(sum);
    	
    }	
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int n; scanf("%d",&n);
    string s; cin>>s;
    int l=0,r=n,mid;
    while(r-l>1){
        mid=(l+r)/2;
        map<string,vector<int>> mp;
        rep(i,0,n-mid+1){
            mp[s.substr(i,mid)].push_back(i);
        }
        bool f=0;
        for(pair<string,vector<int>> p:mp){
            int pre=-inf,cnt=0;
            rep(i,0,p.second.size()){
                if(p.second[i]-pre>=p.first.size()){
                    pre=p.second[i]; cnt++;
                }
            }
          if(cnt>=2){f=1;break;}
        }
        if(f)l=mid; else r=mid;
    }
    printf("%d\n",l);
    return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
long long i[3000000];
lol u[111111];
lol ii[121111];
bool o;
bool ans[5];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h=0,j=0;
  string s;
  cin >>a>>b;
  for(int n=0;n<=a;n++){
    for(int m=0;m<=a-n;m++){
      if(n*10000+m*5000+(a-n-m)*1000==b){
	cout <<n<<' '<<m<<' '<<a-n-m<<'\n';
	return 0;
      }
    }
  }
  cout <<"-1 -1 -1\n";
  return (0);
}


Measured memory_bytes: 256
n, x = map(int, input().split())


def f(a, b):
    if a == b:
        return a
    if a > b:
        a, b = b, a
    if b % a == 0:
        return 2 * b - a
    else:
        div, mod = divmod(b, a)
        return 2 * a * div + f(a, mod)

print(n + f(n-x, x))

Measured memory_bytes: 9076
#coding: utf-8

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

ans = 0
lenS = len(S)
for i in T:
    S.append(i)
    idx = 0
    while True:
        if S[idx] == i:
            break
        else:
            idx += 1
    if idx < lenS:
        ans += 1
    S.pop()
print(ans)


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

const int MOD = 1e9 + 7;
const int A = 0;
const int C = 1;
const int G = 2;
// const int T = 3;

int main(){
    
    int n;
    cin >> n;
	
	ll dp[n+1][4][4][4]; // 末尾ijkかつ条件を満たすもの
	memset(dp,0,sizeof(dp));
	rep(i,4) rep(j,4) rep(k,4) dp[3][i][j][k] = 1;
	dp[3][A][G][C] = 0;
	dp[3][A][C][G] = 0;
	dp[3][G][A][C] = 0;
	
	for(int i = 4; i < n+1; i++){
		rep(c1,4) rep(c2,4) rep(c3,4) rep(c4,4){
			if((c1==A && c2 == G && c4 == C) ||
			   (c1==A && c3 == G && c4 == C)) continue;
			dp[i][c2][c3][c4] += dp[i-1][c1][c2][c3];
			dp[i][c2][c3][c4] %= MOD;
		}
		dp[i][A][G][C] = 0;
		dp[i][A][C][G] = 0;
		dp[i][G][A][C] = 0;
	}
	
	ll res = 0;
	rep(i,4) rep(j,4) rep(k,4) res += dp[n][i][j][k]; res %= MOD;
	cout << res << endl;
    return 0;
    
}


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

vector<int>run(0);

void solve(string S){
	int N=S.size();
	run.push_back(stoll(S));
	if(N<=9){
		char c=S[N-1];
		if(c!='0'){c--; solve(S+c); c++;}
		solve(S+c);
		if(c!='9'){c++; solve(S+c); c--;}
	}
}


signed main(){
	int K; cin>>K;
	for(char c='1';c<='9';c++){
		string tmp; tmp+=c;
		solve(tmp);
	}
	sort(run.begin(),run.end());
	cout<<run[K-1]<<endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int a[SIZE];
int main(){
    DRII(N,x);
    REP(i,N){
        RI(a[i+1]);
    }
    LL an=0;
    REPP(i,2,N+1){
        if(a[i]+a[i-1]>x){
            int v=min(a[i]+a[i-1]-x,a[i]);
            an+=v;
            a[i]-=v;
            if(a[i]+a[i-1]>x){
                v=min(a[i-1],a[i-1]-x);
                a[i-1]-=v;
                an+=v;
            }
        }
    }
    cout<<an<<endl;
    return 0;
}


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

using namespace std;

long long int N;
string str;
int main(){
    cin >> str;
    if(str=="SUN"){
        cout << 7 << endl;
    }else if(str=="MON"){
        cout << 6 << endl;
    }else if(str=="TUE"){
        cout << 5 << endl;
    }else if(str=="WED"){
        cout << 4 << endl;
    }else if(str=="THU"){
        cout << 3 << endl;
    }else if(str=="FRI"){
        cout << 2 << endl;
    }else{
        cout << 1 << endl;
    }
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define int long long



signed main(){
    int n,ans=0;
    cin >>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<n;i++){
       
        if(a[i]<b[i]){
            ans+=(b[i]-a[i])/2;
        }else{
            ans-=a[i]-b[i];
        }
      //  cerr<<ans<<endl;
    }
    if(ans>=0)cout<<"Yes";
    else cout<<"No";



    return 0;
}

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

# define ll long long 
# define VI vector<int>
# define VLL vector<ll>
# define PII pair<int,int> 
# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ld long double
const int MxN = 200001 ; 
# define FOR(i,a,b) for(int i = a ; i < b ; ++i)
# define RFOR(i,a,b) for(int i = a ; i >= b ; --i)
const int MOD = 1e9 + 7 ; 

/* VARIABLES */
int n  ;
/* END OF VARIABLES */



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;  

	cin >> n ; 
	ll ans = 0 ; 
	vector<string> res ; 
	map<string,int> cnt ; 
	string s ; 
	FOR(i,0,n) {
		cin >> s ; 
		sort(s.begin(), s.end()) ; 
		cnt[s]++;
	}
	for(auto str : cnt) {
		int tmp = str.second ; 
		if(tmp > 1) {
			ans += ((ll)(tmp)*(tmp-1) )/2 ; 
		}
	}
	cout << ans ; 
	

		
	return 0 ; 
}



Measured memory_bytes: 11332
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for(int i = 0; i < N; i++) cin >> l[i];
  sort(l.begin(), l.end()), reverse(l.begin(), l.end());
  int sum = 0;
  for(int i = 0; i < K; i++) sum += l[i];
  cout << sum << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	int N; cin >> N;
	vector<pair<int, int>> w(N);
	REP(i,N){
		int A, B; cin >> A >> B;
		w[i] = make_pair(B, A);
	}

	SORT(w);

	bool ans = true;
	ll cnt = 0;
	REP(i,N){
		if(cnt+w[i].second <= w[i].first) cnt += w[i].second;
		else ans = false;
	}
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;

}


Measured memory_bytes: 1792
# 真ん中[中部]を固定化して考える
import bisect

n = int(input())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
c = [int(_) for _ in input().split()]

# まずは昇順ソート
a.sort()
b.sort()
c.sort()

# 答え格納する変数
ans = 0

# 全てのb[i]に対して a < b[i] < c となるaとcを探す
for i in range(n):
    center_size = b[i]
    left_idx = bisect.bisect_right(a, center_size-1)
    right_idx = bisect.bisect_left(c, center_size+1)
    ans += left_idx * (n-right_idx)
print(ans)

Measured memory_bytes: 23232
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=100005;

int N;
vector<int> adj[MAXN];
int val[MAXN],ans;

void dfs(int u,int fa=0)
{
	int mk=0;
	for(int i=0;i<(int)adj[u].size();i++)
	{
		int v=adj[u][i];
		if(v==fa)
			continue;
		dfs(v,u);
		mk|=(val[u]&val[v]);
		val[u]|=val[v];
	}
	if(val[u]==0)
		val[u]=1;
	else
	{
		int id=0;
		while((1<<id)<mk||(val[u]&(1<<id)))
			id++;
		val[u]=((val[u]>>id)<<id)|(1<<id);
		ans=max(ans,id);
	}
	//printf("val[%d]=%d\n",u,val[u]);
}

int main()
{
	scanf("%d",&N);
	for(int i=1;i<N;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(1);
	printf("%d\n",ans);
	
	return 0;
}

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

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

bool ok(const int n, const vector<int>& A, int K) {
  map<int, int> D;
  for (int i = 1; i < n; ++i) {
    if (A[i - 1] < A[i]) {
      continue;
    }
    while (!D.empty() && D.rbegin()->first >= A[i]) {
      D.erase(D.rbegin()->first);
    }
    int idx = A[i] - 1;
    while (true) {
      if (idx < 0) {
        return false;
      }
      D[idx] += 1;
      if (D[idx] == K) {
        D[idx] = 0;
        --idx;
      } else {
        break;
      }
    }
  }
  return true;
}

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

  bool sorted = true;
  for (int i = 0; i + 1 < n; ++i) {
    sorted &= A[i] < A[i + 1];
  }
  if (sorted) {
    puts("1");
    return 0;
  }

  int lo = 1, hi = n;
  while (hi - lo > 1) {
    int mid = (hi + lo) / 2;
    if (ok(n, A, mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  printf("%d\n", hi);

  return 0;
}


Measured memory_bytes: 1024
n=int(input())
count=[[0,0,0,0,0,0,0,0,0,0] for _ in range(10)]
for i in range(1,n+1):
    count[int(list(str(i))[0])-1][int(list(str(i))[-1])-1]+=1
ans=0
for j in range(10):
    for k in range(10):
        ans+=(count[j][k]*count[k][j])
print(ans)

Measured memory_bytes: 9220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;

public class Main {

	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
	 int n=fs.nextInt();
	 int k=fs.nextInt();
	 int a[]=fs.readArray(n);
	 long mult=1;
//	 for(int i=0;i<k;i++) {
//		 mult=mult*a[i];
//	 }
//	 long prev=mult;
	 
	 for(int i=k;i<n;i++) {
//		 System.out.println("i-k"+" "+a[i-k]);
//		 System.out.println("i"+" "+a[i]);
		 if(a[i-k]>=a[i]) {
			 System.out.println("No");
		 }
		 else {
			 System.out.println("Yes");
		 }
//	 mult=mult/a[i-k];
//	 mult=mult*a[i];
//	 if(mult>prev) {
//		 System.out.println("Yes");
//	 }
//	 else {
//		 System.out.println("No");
//	 }
//	 prev=mult;
	 }
	 
	   
	}
	static void sort(int[] a ) {
		ArrayList<Integer> l = new ArrayList<>();
		for(int i:a) l.add(i);
		Collections.sort(l);
		for(int i=0;i<l.size();i++) a[i]=l.get(i);
	}
	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while(!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				}catch(IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a = new int[n];
			for(int i=0;i<n;i++)a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 57436