akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int maxn = 2e6 + 5;
vector<int> blue[maxn], red[maxn];
int dep[maxn], fa[maxn], dp[maxn];
bool safe[maxn], vis[maxn];
void dfs(int v, int p) {
    fa[v] = p;
    for (int i=0; i<blue[v].size(); i++) if(blue[v][i] != p) {
        dep[blue[v][i]] = dep[v] + 1;
        dfs(blue[v][i], v);
    }
}
bool atMost2(int x, int y) {
    return (fa[x] == fa[y]) || (fa[x] == y) || (x == fa[y]) || (fa[fa[x]] == y) || (x == fa[fa[y]]);
}
int main() {
    int n, X, Y, x, y;
    scanf("%d %d %d", &n, &X, &Y);
    for (int i=1; i<n; i++) {
        scanf("%d %d", &x, &y);
        red[x].push_back(y), red[y].push_back(x);
    }
    for (int i=1; i<n; i++) {
        scanf("%d %d", &x, &y);
        blue[x].push_back(y), blue[y].push_back(x);
    }
    dfs(Y, -1);
    for (int i=1; i<=n; i++)
        for (int j=0; j<red[i].size(); j++)
            if (!atMost2(i, red[i][j]))
                safe[i] = safe[red[i][j]] = 1;
    if (safe[X]) {puts("-1"); return 0;}
    memset(dp, -1, sizeof(dp));
    queue<int> q;
    q.push(X); dp[X] = 0; vis[X] = 0;
    int ans = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        if (dp[u] >= dep[u]) continue;
        if (safe[u]) {puts("-1"); return 0;}
        ans = max(ans, dep[u] * 2);
        for (int i=0; i<red[u].size(); i++) {
            int v = red[u][i];
            if (!vis[v] && dp[u] + 1 < dep[v] && atMost2(u, v)) {
                dp[v] = dp[u] + 1;
                vis[v] = 1;
                q.push(v);
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 127612
#include <iostream>
#define ll long long
using namespace std;

int main()
{
    int n;
    cin >> n;
    int* arr = new int[n];
    for(int i=0;i<n;i++){
        cin >> arr[i];
    }
    int stocks=0;
    ll total = 1000;
    for(int i=1;i<n;i++){
        if(arr[i]>arr[i-1]){
            total += (arr[i]-arr[i-1])*(total/arr[i-1]);
        }
    }
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 3636
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var count = 0;
        for (int i = 0; i < n; i++)
            if (i % 2 == 0 && a[i] % 2 == 1) count++;
        Console.WriteLine(count);

    }
}


Measured memory_bytes: 27468
#include <iostream>
#include <vector>
#include <map>

#define ALP 26

using namespace std;

struct Day_data{
    int penalty;
    int satis[ALP];
    int lasts[ALP];
    int selected;
};

struct Solution_data{
    int days;

    int penalties[ALP];
    vector<Day_data> day_data;
    int satis_sum;
    int penal_sum;

    Solution_data(int d);
    int get_score();
    void solve_greedily();
};

Solution_data::Solution_data(int d): days(d), day_data(d)
{
    satis_sum = 0;
    penal_sum = 0;

    for(int i = 0; i < d; i++){
        for(int j = 0; j < ALP; j++){
            day_data[i].lasts[j] = -1;
        }
    }
}

int Solution_data::get_score()
{
    return satis_sum - penal_sum;
}

void Solution_data::solve_greedily()
{
    for(int i = 0; i < days; i++){
        int penal = (i - day_data[i].lasts[0]) * penalties[0];
        pair<int, int> max = make_pair(0, day_data[i].satis[0] + penal);
        for(int j = 1; j < ALP; j++){
            int penal = (i - day_data[i].lasts[j]) * penalties[j];
            int day_score = day_data[i].satis[j] + penal;
            if(max.second < day_score){
                max.first = j;
                max.second = day_score;
            }
        }

        day_data[i].selected = max.first;
        for(int j = i; j < days; j++){
            day_data[i].lasts[max.first] = i;
        }
        satis_sum += day_data[i].satis[max.first];

        for(int j = 0; j < ALP; j++){
            penal_sum += (i - day_data[i].lasts[j]) * penalties[j];
        }
    }
}

int main(void)
{
    int days;
    cin >> days;

    Solution_data sol(days);

    for(int i = 0; i < ALP; i++){
        int p;
        cin >> p;
        sol.penalties[i] = p;
    }

    for(int i = 0; i < days; i++){
        for(int j = 0; j < ALP; j++){
            int s;
            cin >> s;
            sol.day_data[i].satis[j] = s;
        }
    }

    for(int i = 0; i < days; i++){
        for(int j = 0; j < ALP; j++){
            sol.day_data[i].lasts[j] = -1;
        }
    }

    sol.solve_greedily();

    for(int i = 0; i < days; i++){
        cout << sol.day_data[i].selected + 1 << endl;
    }
}

Measured memory_bytes: 3680
N, M = map(int, input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())

from itertools import permutations

def make_aja_mtx(N, M, A, B):
    D = [[0 for _ in range(N)] for _ in range(N)]
    for i in range(M):
        D[A[i]-1][B[i]-1] = 1
        D[B[i]-1][A[i]-1] = 1
    return D

def check(p, N, D):
    len_path = 1
    for i in range(1, N):
        if D[p[i-1]-1][p[i]-1] == 1:
            len_path += 1
        else:
            break
    return len_path == N
        
def perm(perm_2):
    for p in perm_2:
        yield (1,) + p

def Main(N, M, A, B):
    ns = range(2, N+1)
    perm_2 = permutations(ns, N-1)
    ans = 0
    D = make_aja_mtx(N, M, A, B)
    for p in perm(perm_2):
        if check(p, N, D):
            ans += 1
    return ans
    
print(Main(N, M, A, B))


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n;
      if(n%2==0)ans=(n/2)*(n/2);
      else ans=((n+1)/2)*((n-1)/2);
      Cout(ans);
     

       
return 0;
}


Measured memory_bytes: 256
/*
ABHIJEET BISWAS
CSE (2017-2021)
MNNIT ALLAHBAD
*/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e15
#define ll long long
#define ld long double
#define int ll
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define MAX 1000009
#define pb push_back
#define mp map<int,int>
#define F first
#define S second
#define popi __builtin_popcount
#define popll __builtin_popcountll
#define grp vector<int> graph[MAX];
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define endl "\n"

//////////////////////TEMPLATE ENDS///////////////////////////////////////////////////////////////////////
ll power(ll,ll);
ll mpower(ll,ll);
int BIT[MAX];
int query(int );
void update(int ,int);
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int n;

vector<pii> arr;
int dp[5003],tmp[5003];
int32_t main() {
	fastIO
	
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int a,b;
		cin >> a>> b;
		arr.pb({a,b});
	}

	sort(arr.begin(),arr.end(),[](pii a,pii b){return a.first + a.second < b.first + b.second;});
	for(int i=1;i<=n;i++)
	{
		dp[i] = INF;
	}
		
	for(int i=0;i<n;i++)
	{
		for(int i=0;i<=n;i++)
			tmp[i] = dp[i];
		for(int j=0;j<n;j++)
		{
			if(arr[i].first>=dp[j])
				tmp[j+1] = min(tmp[j+1],dp[j]+arr[i].second); 
		}
		for(int i=0;i<=n;i++)
			dp[i] = tmp[i];
	}


	for(int i=n;i>=0;i--)
	{
		if(dp[i]!=INF)
		{
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}







/*_________________________________________________Utility Functions HERE_______________________________*/

void update(int x, int delta)
{
      for(; x < MAX; x += x&-x)
        BIT[x] += delta;
}
int query(int x)
{
     int sum = 0;
     for(; x > 0; x -= x&-x)
        sum += BIT[x];
     return sum;
}

ll power(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b%2==1)
		res=res*a;
		a=a*a;
		b=b/2;
	}
	return res;
}
ll mpower(ll a ,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%MOD;
		}
		a=(a*a)%MOD;
		b=b/2;
	}
	return res;
}

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

using namespace std;
using ll = long long;

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

    vector<ll> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    vector<ll> c(n);
    for (int i = 0; i < n; i++) cin >> c[i];

    ll ans = -1e+18;
    for (int i = 0; i < n; i++) {
        ll v = p[i] - 1;
        ll l = 1;
        ll c_sum = c[i];
        while (v != i) {
            l++;
            c_sum += c[v];
            v = p[v] - 1;
        }
        if (c_sum < 0) c_sum = 0;

        v = p[i] - 1;
        ll sum = 0;
        for (int i = 0; i < l; i++) {
            if (i >= k) break;
            sum += c[v];
            ans = max(ans, c_sum * ((k - i - 1) / l) + sum);
            v = p[v] - 1;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3580
n = gets.chomp.to_i
v = gets.chomp.split.map(&:to_i)
c = gets.chomp.split.map(&:to_i)

vc  = v.zip(c)
max = 0
vc.each { |e| d = e[0] - e[1]; max += d > 0 ? d : 0 }
puts max


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair<int, int>pi;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll INF = 9e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

ll n, a[200010], k, ans = INF;

int main() {
	cin >> n >> k;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	int it = lower_bound(a, a + n, 0) - a;
	if (it == 0)k--;
	if (it + k < n)ans = min(ans, a[it + k]);
	if (it - k >= 0)ans = min(ans, abs(a[it - k]));
	for (int i = 1;i < k;i++) {
		if (it - i < 0)continue;
		if (it + k - i > n)continue;
		ans = min(ans, min(abs(a[it - i]), a[it + (k - i) - 1])*2 + max(abs(a[it - i]), a[it + (k - i) - 1]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
int main()
{
ll a,b,n,c,d,e;
cin>>n>>a>>b>>c>>d>>e;
 printf("%lld\n",(n-1)/min({a,b,c,d,e})+5);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int N;
int ans = 0;

void check(int x) {
  if (x > N) return;
  int cnt3 = 0, cnt5 = 0, cnt7 = 0;
  while (x > 0) {
    int rem = x % 10;
    if (rem == 3) {
      cnt3++;
    } else if (rem == 5) {
      cnt5++;
    } else if (rem == 7) {
      cnt7++;
    } else {
      return;
    }
    x /= 10;
  }
  if (cnt3 !=0 && cnt5 != 0 && cnt7 != 0) ans++;
}

void dfs(ll x) {
  check(x);
  if (x <= 1000000000) {
    dfs(x * 10 + 3);
    dfs(x * 10 + 5);
    dfs(x * 10 + 7);
  }
}

int main() {
  cin >> N;
  dfs(0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
int main(){
	int n;
	while(std::cin>>n){
		int ans=0;
		std::vector<int> vec(n+1);
		for(int i=0;i<=n;i++)vec[i]=1;
		vec[0]=vec[1]=0;
		for(int i=2;i<=n;i++){
			if(vec[i] == 1){
				ans++;
				for(int j = 2 * i ; j <= n ; j += i){
					vec[j]=0;
				}
			}
		}
		std::cout<<ans<<std::endl;
	}

	return 0;
}

Measured memory_bytes: 5356
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] x =new int[n];
		ArrayList<Integer> data = new ArrayList<Integer>();
		for(int i = 0;i < n;i++){
			x[i] = sc.nextInt();
			data.add(x[i]);
		}
		Collections.sort(data);		

		for(int i = 0;i < n;i++){
			if(x[i] <= data.get((data.size()/2) -1)){
				System.out.println(data.get(data.size()/2));

				//			System.out.println();
				//			for(int j = 0;j < n;j++){
				//				System.out.print (data.get(j)+" ");
				//			}
				//			System.out.println();

			}else{
				System.out.println(data.get((data.size()/2) -1));
			}



		}
	}





}

class UnionFind{
	int[] parent;
	public UnionFind(int N){
		this.parent = new int[N];
		for(int i = 0; i < N;i++){
			parent[i] = i;
		}
	}
	public int root(int x){			//根要素を取得
		if(parent[x] == x){			//初期状態
			return x;
		}else{
			return parent[x] = root(parent[x]);    	//再帰によって根を取得
		}
	}
	public void unite(int x,int y){ 	//統合メソッド
		if(same(x,y)){					//同じ根なら終了
			return;
		}
		int xroot = root(x);
		int yroot = root(y);
		parent[xroot] = yroot;			//統合
		return;

	}

	public boolean same(int x,int y){			//根が同じか（同じグループに属しているか）を判定
		return(root(x) == root(y));
	}
}



class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 97152
#include<bits/stdc++.h>
using namespace std;
long long n,s,ans;
int main(){
    cin>>n; 
    for(int i=sqrt(n);i>0;--i){
        if(n%i==0){
            ans=n/i;
            break;
        }
	}
    while(ans>0){
        ++s;
        ans/=10;
    }
   	cout<<s;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
using namespace std;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,p=1,q=1;
    ll n,m,tmp;
    string s[200000];
    string str;
    ll sum=0;
    ll strr[200005];
    cin>>n;
    ll f=0;
  	if(n%10==7) f=1;
  	if(n/100==7) f=1;
  	n=n%100;
  	n=n/10;
  	if(n==7) f=1;
  	if(f==1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 9884
A,B,C,K = [int(a) for a in input().split()]

ans = 0
count = 0

if A >= K:
    print(K)
    exit()
else:
    ans += A
    count += A

if B >= (K-count):
    print(ans)
    exit()
else:
    count += B

if C >= (K-count):
    ans -= (K-count)
    print(ans)
    exit()

Measured memory_bytes: 9172
S = input()

for i in range(1,len(S)) :
    if (len(S)-i)%2 == 1 :
        continue
    else :
        halflen = (len(S)-i) // 2
        preS = S[:-i-halflen]
        postS = S[halflen:-i]
        if preS == postS :
            print(len(S)-i)
            exit()


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

double dist(int n,int x[],int y[],int p){
    double d=0;
    
    if(p!=-1){
        for(int i=0;i<n;i++){
            d += pow(abs(x[i]-y[i]),p);
        }
        d = pow(d, 1.0/p);
    }else{
        for(int i=0;i<n;i++){
            double temp = abs(x[i]-y[i]);
            if(temp > d){
                d = temp;
            }
        }
    }
    return d;
}

int main(void){
    int n;
    cin >> n;
    
    int x[n];
    int y[n];
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    for(int i=0;i<n;i++){
        cin >> y[i];
    }
    
    double d1 = dist(n,x,y,1);
    double d2 = dist(n,x,y,2);
    double d3 = dist(n,x,y,3);
    double di = dist(n,x,y,-1);
    
    cout << fixed << d1 << endl;
    cout << fixed << d2 << endl;
    cout << fixed << d3 << endl;
    cout << fixed << di << endl;

    return 0;
}

Measured memory_bytes: 1292
S = input()
T = input()
s = len(S)
t = len(T)
q = []
for i in range(s+1-t):
  f = True
  for j in range(t):
    if S[i+j] == '?' or S[i+j] == T[j]:
      continue
    f = False
  if f:
    #print(S[i+t:])
    tmp = S[:i] + T + S[i+t:]
    #print(tmp)
    q.append(tmp.replace('?','a'))
    q.sort()
if len(q) == 0:
  print('UNRESTORABLE')
else:
  print(q[0])


Measured memory_bytes: 3064
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int A,B,C;
   while(cin>>A>>B>>C)
   {
     if(A==0&&B==0&&C==0) break;
     int num;
     int a=A*A+B*B;
     int b=A*A+C*C;
     int c=B*B+C*C;
     double kk=min(a,min(b,c));
     kk=sqrt(1.0/4*kk); 
     cin>>num;
     while(num--)      
     {
       int n;
       cin>>n;
       if(n>kk) cout<<"OK"<<endl;
       else cout<<"NA"<<endl;                  
     }             
   }
   //while(1);
   return 0;
 }

Measured memory_bytes: 3072
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n,w;
    cin>>n>>w;
    pii a[n];
    for (int i = 0; i < n; ++i)
        cin>>a[i].ff>>a[i].ss;
    int dp[w+5];
    fill(dp,0);
    int ans = 0;
    for (int j = 0; j < n; ++j)
    {
        
        for (int i = w; i >=0 ; --i)
        {
            if(i-a[j].ff>=0)
            {
                dp[i] = max(dp[i-a[j].ff]+a[j].ss,dp[i]);
                ans = max(ans,dp[i]);
            }
        }
    }
    cout<<ans<<endl;


    printclock;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 1;
    char c = s[0];
    for(int i=0; i<s.size(); i++){
        if(c!=s[i]){
            ans++;
            c = s[i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
const int V=100003;
int n;
bool vis[V*2];
vector<int> r[2*V],cnt;
void dfs(int u)
{
    vis[u]=1;
    cnt[u/V]++;
    for (int v:r[u])
    {
        if (!vis[v]) dfs(v);
    }
}
long long ans=0;
int main()
{
    //freopen("F.in","r",stdin);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n;
    fill(vis+1,vis+2*V,1);
    for (int i=1;i<=n;i++)
    {
        int x,y;
        cin >> x >> y;
        y+=V;
        r[x].push_back(y);
        r[y].push_back(x);
        vis[x]=vis[y]=0;
    }

    for (int i=1;i<V*2;i++)
    {

        if (!vis[i])
        {
            cnt=vector<int> (2,0);
            dfs(i);
            ans+=(long long) cnt[0]*cnt[1];
        }
    }
    cout << ans-n;
}


Measured memory_bytes: 10240
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
	double a;
	double u=0,d=10000000;
	while(cin>>a){
        u=max(u,a);
        d=min(d,a);


	}
	u-=d;
	printf("%.1lf\n",u);


	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
using namespace std;
int main() {
	int x, y, gx, gy;
	int a[] = { 1,3,5,7,8,10,12 };
	int b[] = { 4,6,9,11 };
	int c = 2;

	cin >> x >> y;

	for (int i = 0; i < 7; i++)
	{
		if (a[i] == x) {
			gx = 1;
		}
		if (a[i] == y) {
			gy = 1;
		}
	}

	for (int i = 0; i < 4; i++)
	{
		if (b[i] == x) {
			gx = 2;
		}
		if (b[i] == y) {
			gy = 2;
		}
	}

	if (x == c) {
		gx = 3;
	}
	if (y == c) {
		gy = 3;
	}

	if (gx == gy) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
int f(int a[26]){
FOR(i,26) if(a[i]%2) return false;
return true;
}


int main(){
	string s;
	cin >>s;
	int a[26];
	FOR(i,26)a[i]=0;
	char c='a';
	//cout <<(int )c;
	FOR(i,s.length())a[(int)(s[i])-97]++;
	//FOR(i,26)cout <<a[i];
	if(f(a)) cout << "Yes";
	else cout <<"No";

	return 0;
}

Measured memory_bytes: 256
str = input()

if str == "SUN":
  print("7")
elif str == "MON":
  print("6")
elif str == "TUE":
  print("5")
elif str == "WED":
  print("4")
elif str == "THU":
  print("3")
elif str == "FRI":
  print("2")
elif str == "SAT":
  print("1")
else:
  print("入力ミスです")

Measured memory_bytes: 3060
k = int(input())

ans = 0

import math

for i in range(1, k + 1):
    for j in range(i + 1, k + 1):
        for l in range(j + 1, k + 1):
#            print('({}, {}, {})'.format(i, j, l))
            ans += (math.gcd(i, math.gcd(j, l))) * 6

for i in range(1, k + 1):
    for j in range(i + 1, k + 1):
#        print('({}, {})'.format(i, j))
        ans += math.gcd(i, j) * 6

for i in range(1, k + 1):
    ans += i

print(ans)


Measured memory_bytes: 9228
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto & i : (a))
#define SZ(x) ((int)(x).size())
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;
typedef long double ld;
int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	ld x;
	std::cin >> x;
	x /= 3;
	std::cout << std::fixed << std::setprecision(20) << x*x*x;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
// #define int long long int

using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

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

const ll mod =  1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 112345;
// const double pi = 3.14159265359;
const double eps = 0.00000001;

int n; 
ll k;
ll cnt_b[64]; 
ll arr[MAXN];

void job (ll x) {
    for (int i = 0; x; ++i) {
        cnt_b[i] += (x & 1LL);
        x >>= 1LL;
    }
}

ll dp[2][64];
bool seen[2][64];

ll sol (int idx, bool f) {
    if (idx < 0) {
        return 0;
    }
    ll& pd = dp[f][idx];
    bool& vis = seen[f][idx];
    if (vis) {
        return pd;
    }
    ll p2 = (1LL << idx);
    if (f) {
        pd += sol(idx - 1, f) + p2 * max(cnt_b[idx], n - cnt_b[idx]);
    } else {
        if (k & p2) {    
            pd = sol(idx - 1, 1) + p2 * cnt_b[idx];
            pd = max(pd, sol(idx - 1, 0) + p2 * (n - cnt_b[idx]));
        } else {
            pd = sol(idx - 1, 0) + p2 * cnt_b[idx];
        }
    }
    vis = 1;
    return pd;
}

int32_t main() {
    $
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        job(arr[i]);
    }
    int cnt = 0;
    for (ll i = k; i; i >>= 1LL) {
        ++cnt;
    }
    ll acc = 0;
    for (int i = 62; i >= cnt; --i) {
        if (cnt_b[i]) {
            acc += (1LL << i) * cnt_b[i];
        }
    }
    cout << sol (cnt - 1, 0) + acc << '\n';
}

Measured memory_bytes: 1024
h, w = map(int, input().split())
 
mat = [[] for _ in range(h)]
 
for i in range(h):
    mat[i] = input()
 
dp = [[float("inf")] * w for _ in range(h)]
 
if mat[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0
 
for i in range(h):
    for j in range(w):
 
        if mat[i][j - 1] != mat[i][j]:
            left = dp[i][j - 1] + 1
        else:
            left = dp[i][j - 1]
 
        if mat[i - 1][j] != mat[i][j]:
            top = dp[i - 1][j] + 1
        else:
            top = dp[i - 1][j]
 
        dp[i][j] = min(dp[i][j], left, top)
 
print((dp[h - 1][w - 1] + 1) // 2)

Measured memory_bytes: 3064
# a=gets
# nums=gets.strip.split.map(&:to_i)
# ans=0
# flag=true

# while flag do

#     nums.each {|n| 
#         if n%2!=0
#             flag=false

#         end
#         }
#     if flag
#        nums= nums.map {|n| n/2}
#         ans+=1
#     end
# end

# puts ans

_n=gets.to_i
as=gets.strip.split.map(&:to_i)
cnt=0

while as.all?(&:even?) do
    cnt+=1
    as=as.map {|n| n/2}
end

puts cnt

Measured memory_bytes: 14260
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		int K = int.Parse(str);
		if(K<=12){
			Console.WriteLine(K);
		} else {
			int a = 12;
			int[]S = new int[12];
			for(var i=0;i<=9;i++){
              S[i] = -1;
            }
			S[10] = 1;
			S[11] = 2;
			int d = 11;
			while(true){
				a++;
				int t = 11;
				S[t]++;
				bool flag = false;
				while(S[t]==10 || (S[t-1]!=-1 && S[t] - S[t-1] >= 2)){
					t--;
					d = Math.Min(d,t);
					if(S[t]==-1){
                      S[t] = 0;
                    }
					S[t]++;
					for(var t2 = t+1;t2<=11;t2++){
						S[t2] = Math.Max(0,S[t2-1]-1);
					}
					flag = true;
                }
					//Console.Error.Write(a+" ");
					for(var i=0;i<12;i++){
                    //  Console.Error.Write(S[i]+" ");
                    }
                  	//Console.Error.WriteLine();
				if(a==K){
					break;
				}
            }
         	bool flag2 = false;
			for(var i=0;i<=11;i++){
              	if(S[i]!=-1 &&(S[i]!=0 || flag2)){
				Console.Write(S[i]);
                  flag2 = true;
                }
            }
		}
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <complex.h>
#include <math.h>
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace std;
#define int ll
// fendwick tree
//#include <ext / pb_ds / assoc_container.hpp> //required
//#include <ext/pb_ds/tree_policy.hpp>         //required
using namespace __gnu_pbds; //required
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<int> s;
ordered_set<int>::iterator itr;
// fendwick tree
/*
ll ans[200005];
void fun(ll a, ll b, ll c)
{
    //ll val = 1;

    while (a <= b)
    {
        ans[a] += c;
        ll p = -a;
        a += (a & p);
    }
}
ll find1(ll a)
{
    ll sum = 0;
    while (a != 0)
    {
        sum += ans[a];
        ll p = -a;
        a -= (a & p);
    }
    return sum;
}*/
int fastexpo(int a, int b, int m)
{
    int ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (ans * a) % m;
        b = b / 2;
        a = (a * a) % m;
    }
    return ans;
}
int32_t main()
{
    int n;
    cin >> n;
    int a[4] = {0};
    for (int i = 0; i < n; i++)
    {
        string temp;
        cin >> temp;
        if (temp == "AC")
        {
            a[0]++;
        }
        if (temp == "TLE")
        {
            a[1]++;
        }
        if (temp == "WA")
        {
            a[2]++;
        }
        if (temp == "RE")
        {
            a[3]++;
        }
    }
    cout << "AC x " << a[0] << "\n";
    cout << "WA x " << a[2] << "\n";
    cout << "TLE x " << a[1] << "\n";
    cout << "RE x " << a[3] << "\n";
    return 0;
}
//ACx10

Measured memory_bytes: 3560
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007


int main()
{
	int a, b;
	cin >> a >> b;
	if(a > 9 || b > 9) cout << -1 << endl;
	else cout << a * b << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

using namespace std;


int32_t main()
{
    
    IOS;
    //fill(isprime, true);
    //pre();
    
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans1=a*c;
    ans1=max(ans1,a*d);
    ans1=max(ans1,b*c);
    ans1=max(ans1,b*d);
    cout<<ans1<<"\n";
    
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define sp " "
#define cs "Case "
#define fi first
#define sn second

/* STL */
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxi(v) distance(v.begin(),max_element(v.begin(),v.end()))
#define mxa(a) *max_element(a, a.size())
#define r(a)   reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n) i=1;i<=(n);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(something)  cerr<<#something<<" - "<<something<<"\n";

int main()
{

   Ezio
   ll t,m,n,x,a,b,c;
   string s;

   cin>>a>>b>>c;
   if((a==5 and b==5 and c==7) or (a==7 and b==5 and c==5) or (a==5 and b==7 and c==5)){
    cout<<"YES"<<endl;
   }
   else
    cout<<"NO"<<endl;
   return 0;
}


Measured memory_bytes: 3600
A,B = [int(x) for x in input().split()]

if (A + B) >= (A - B) and (A + B) >= (A * B):
    print(A + B)
elif (A - B) >= (A + B) and (A - B) >= (A * B):
    print(A - B)
elif (A * B) >= (A + B) and (A * B) >= (A - B):
    print(A * B)
    

Measured memory_bytes: 3060
import std.stdio;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;

void main(){

    while(true){
	int[][] mat;
	int n = readln().chomp().to!int;
	if(n==0) break;
	for(int i=0;i<n;i++){
	    auto s = readln().split().to!(int[]);
	    mat ~= s;
	}
	int[] temp;
	for(int i=0;i<n;i++){
	    int rsum,csum;
	    for(int j=0;j<n;j++){
		rsum += mat[i][j];
		csum += mat[j][i];
	    }
	    mat[i] ~= rsum;
	    temp ~= csum;
	}
	int sum;
	for(int i=0;i<n;i++){
	    sum += mat[i][n];
	}
	temp ~= sum;
	mat ~= temp;

	for(int i=0;i<n+1;i++){
	    for(int j=0;j<n+1;j++){
		writef("%5d",mat[i][j]);
	    }
	    writeln();
	}
    }
}

Measured memory_bytes: 2516
S = list(input())

tmp = S[0]
cnt = 0
for i in range(1, len(S)):
    if S[i] == tmp:
        cnt += 1
        if S[i] == '0':
            S[i] = '1'
        else:
            S[i] = '0'
    tmp = S[i]
print(cnt)

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

int main()
{
    int n;cin>>n;
    vector<int> dp(3);
    //dp[i] is the total cost done by activity i the previous day
    REP(days,n){
        vector<int> new_dp(3,0);
        vector<int> c(3);
        REP(i,3)scanf("%d",&c[i]);
        REP(i,3){
            REP(j,3){
                if(i!=j){
                    new_dp[j]=max(new_dp[j],dp[i]+c[j]);
                }
            }
        }
        dp = new_dp;
    }
    printf("%d\n",max({dp[0],dp[1],dp[2]}));
    return 0;
}


Measured memory_bytes: 3788
s = str(input())
n = len(s)
a = []
for i in range(n):
    if s[i] != 'B':
        a.append(s[i])
    else:
        if len(a) != 0:
            a.pop(-1)
t =''
m = len(a)
for j in range(m):
    t += a[j]
print(t)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    fast
    int n,k,sum=0;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<k;i++){
        sum+=a[i];
    }
    cout<<sum<<endl;
   return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>
#include <atcoder/all>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

using mint = atcoder::modint998244353;

vector<mint> repunit;

struct S{
    mint value;
    int size;
};
using F = long long;

const F ID = 8e18;

S op(S a, S b){ return {a.value + mint(10).pow(a.size) * b.value, a.size+b.size}; }
S e(){ return {0, 0}; }
S mapping(F f, S x){
    if(f != ID) {
        x.value = repunit[x.size] * f;
    }
    return x;
}
F composition(F f, F g){ return (f == ID ? g : f); }
F id(){ return ID; }

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

    repunit = vector<mint>(300000, 0);
    for (ll i = 1; i < 300000; i *= 2) {
        repunit[i] = (mint(10).pow(i)-1) / 9;
    }

    ll N, Q;
    cin >> N >> Q;
    vector<S> v(N, {mint(1), 1});
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(v);
    while (Q--) {
        ll L, R, D;
        cin >> L >> R >> D;
        ll l = N - R;
        ll r = N - L + 1;
        seg.apply(l, r, D);
        cout << seg.all_prod().value.val() << "\n";
    }
}

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

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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
ll n,T;


int main(){
  vector<ii> vec;
  string s;
  cin >> n >> T >> s;
  rep(i,s.size()) if( s[i] == '^' || s[i] == '+' ) s[i] = ' ';
  {
    stringstream ss;
    ss << s;
    ll temp1,temp2;
    while( !(ss>>s).fail() ) {
      temp1 = n;
      ss >> temp2;
      if( temp2 == 0LL ) temp1 = 1;
      vec.push_back(ii(temp1,temp2));
    }
  }


  ll sum = 0;

  rep(i,vec.size()){
    ll multi = 1;
    rep(j,vec[i].second)  {
      multi *= vec[i].first;
      if( multi > 1000000000LL ) { sum = -1; goto Skip; }
    }
    multi *= T;
    if( multi > 1000000000LL ) { sum = -1; goto Skip; }
    sum += multi;
    if( sum > 1000000000LL ) { sum = -1; goto Skip; }
  }
 Skip:;
  if( sum < 0LL ) puts("TLE");
  else cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1220
#include<iostream>
using namespace std;
int main(){
  int n,a,b,i,abc,bc;abc = bc = 0;char s;cin >> n >> a >> b;
  for(i=0;i<n;i++){
    cin >> s;
    if (s == 'a' && abc < a+b){
      cout << "Yes" << endl;abc++;
    } else if (s == 'b' && abc < a+b && bc < b){
      cout << "Yes" << endl;abc++;bc++;
    } else cout << "No" << endl;
  }
}
      
  

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;



int main(){

    
    string s;
    cin >> s;

    int cntz = 0;
    int cnto = 0;
    rep(i,s.size()){
        if (s[i] == '0') cntz++;
        else cnto++;
    }

    int ans = 2 * min(cntz, cnto);


    cout << ans << endl;

    

}





//              g++ -std=c++1z


Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>

 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;


int main()   {


    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

//    auto start = chrono::steady_clock::now()

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        readll(last_);
        ll ret = 0;
        forr(i,0,n-1) {
            readll(next_);
            ret += max(last_-next_, 0LL);
            last_ = max(last_, next_);
        }
        cout << ret << endl;
    }

//    auto end = chrono::steady_clock::now();
//    cerr << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    ll n, a, b; cin >> n >> a >> b;
    ll c = a+b;
    ll ans = (n / c) * a + min ((n % c), a);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<vector>
#define N 55
using namespace std;

int n,m;
int ans;
vector<int> sw[N];
int p[N],temp[N];
bool vis[N];

void dfs(int x)
{
    if(x==n+1)
    {
        memset(temp,0,sizeof(temp));
        for(int i=1;i<=n;i++)
        {
            if(!vis[i]) continue;
            for(int j=0;j<sw[i].size();j++)
            {
                int b=sw[i][j];
                temp[b]++;
            }
        }
        for(int i=1;i<=m;i++) if(temp[i]%2!=p[i]) return ;
        ans++;
        return ;
    }
    dfs(x+1);
    vis[x]=true;
    dfs(x+1);
    vis[x]=false;
}

int main(){
	scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int k;
        scanf("%d",&k);
        for(int j=0;j<k;j++)
        {
            int t;
            scanf("%d",&t);
            sw[t].push_back(i);
        }
    }
    for(int i=1;i<=m;i++) scanf("%d",&p[i]);
    dfs(1);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  int A[1100000];
  int sum=0;
  
  for(int i=1;i<=M;i++){
    int x;
    cin >> x;
    A[i] = x;
    sum += x;
  }
  if(N < sum) cout << -1 << endl;
  else cout << N - sum << endl;

}

Measured memory_bytes: 3592
import sys

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    A, B, C, X, Y = mi()

    if A+B > 2*C:
        if X > Y:
            ans = 2*Y*C+min((X-Y)*A, (X-Y)*2*C)
        else:
            ans = 2*X*C+min((Y-X)*B, (Y-X)*2*C)
    else:
        ans = A*X+B*Y
    print(ans)

if __name__ == '__main__':
    main()


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

using namespace std;

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

/*
  二部グラフの最大マッチングを計算する
  最初にグラフを作成して登録するが
  最初にグラフをクリアするためにclearGraphを呼び出す必要があることに注意する
  O(V*(V+E))
 */
class BiMatching{
private:
  static const int MAX_V = 10000;
  static const int INF = 100000000;
  // グラフのリスト表現
  vector<int> G[MAX_V];
  // マッチングのペア
  int match[MAX_V];
  // dfsですでに調べたかどうかのフラグ
  bool used[MAX_V];
public:
  void clearGraph(){
    for(int i=0;i<MAX_V;i++)
      G[i].clear();
  }
  // uとvを結ぶ辺をグラフに追加
  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }
  // 増加パスをdfsで探す
  bool dfs(int v){
    used[v] = true;
    for(int i = 0; i < (int)G[v].size(); i++){
      int u = G[v][i],w = match[u];
      if(w < 0 || !used[w] && dfs(w)){
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
    return false;
  }
  // 二部グラフの最大マッチングを求める
  int bipartite_matching(int V){
    int res = 0;
    memset(match,-1,sizeof(match));
    for(int v = 0; v < V; v++){
      if(match[v] < 0){
        memset(used,0,sizeof(used));
        if(dfs(v)){
          res++;
        }
      }
    }
    return res;
  }
};



int a[110];
int b[110];
int c[110];
int d[110];

BiMatching bm;
int main(){


    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i < N; i++){
        cin >> c[i] >> d[i];
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(a[i] < c[j] && b[i] < d[j]){
                bm.add_edge(i, j + N);
            }
        }
    }
    cout << bm.bipartite_matching(N * 2) << endl;


    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define for0(i,n) for(long long i=0;i<n;i++)
#define sp <<" "<<
#define ll long long int
#define pb(v,i) v.push_back(i)
#define er(v,i) v.erase(v.begin()+i)
#define MOD 1000000007
#define tin 1000000000
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main() 
{
    ios
    ll j,i,n,t,l,c,h,k,da,m,maxi,d,s,x,y;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
     }
     ll dp[n]={0};
     for(i=1;i<n;i++)
     {
     	x=99999999;
     	y=999999999;
     	if(i>=1)
     		x=dp[i-1]+abs(arr[i]-arr[i-1]);
     	if(i>=2)
     		y=dp[i-2]+abs(arr[i]-arr[i-2]);
     	dp[i]=min(x,y);

     }
     cout<<dp[n-1];
     

}

        

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
signed main() {
	ll x;
	cin >> x;
	if (x < 1200)puts("ABC");
	else puts("ARC");
	ggr
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
using namespace std;
vector<int>g[100001];
int q[100001];
int ans[100001];
int x, y, z;
int n, m, a, b;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	q[0] = 1;
	y++;
	for (int i = 1; i <= n; i++)ans[i] = -1;
	while (x < y) {
		z = q[x];
		x++;
		for (int i = 0; i < g[z].size(); i++) {
			if (ans[g[z][i]] == -1) {
				q[y] = g[z][i];
				ans[g[z][i]] = z;
				y++;
			}
		}
	}
	for (int i = 2; i <= n; i++) {
		if (ans[i] == -1) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	for (int i = 2; i <= n; i++) {
		printf("%d\n", ans[i]);
	}
}

Measured memory_bytes: 10284
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    char zero='0';
    string nstr=to_string(n);
    vector<vector<int>> cnt(10,vector<int>(10));
    for(int i=0;i<=n;i++){
        cnt[to_string(i)[0]-zero][to_string(i).back()-zero]++;
    }
    ll ans=0;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            ans+=cnt[i][j]*cnt[j][i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256