akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n,vector<int>(m,l));
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>;
#define pint pair<int,int>;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")


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

	int n, t;
	cin >> n >> t;

	vector<pair<int, int>> a(n);
	rep(i, n)
	{
		cin >> a[i].second >> a[i].first;
	}

	sort(all(a));
	int ans = INF;
	rep(i, n)
	{
		if (a[i].first > t)
			break;
		ans = min(ans, a[i].second);
	}
	if (ans == INF)
		cout << "TLE" << endl;
	else
		cout << ans << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j,k;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */

  scanf("%d",&A[1]);
  k=A[1];
  for(i=2;i<=n;i++)
    {
      scanf("%d",&A[i]);
      if(A[i]>k) k=A[i];
    }
  for(i=0;i<=k;i++) C[i]=0;
  
  for(j=1;j<=n;j++) C[A[j]]++;

  for(i=1;i<=k;i++) C[i]=C[i]+C[i-1];

  for(j=n;j>=1;j--)
    {
      B[C[A[j]]]=A[j];
      C[A[j]]--;
    }
  for(i=1;i<n;i++) printf("%d ",B[i]);
  printf("%d\n",B[n]);

  return 0;
}




Measured memory_bytes: 9560
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;
const long long MOD = 1000000007;

long long dat[2 * MAX_N - 1];

ll fact(ll n) {
	if (n == 1) return 1;
	if (n == 0) return 0;
	return n * fact(n - 1);
}

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

//D 
int main(void) {
	ll n, m;
	cin >> n >> m;
	ll lcm = 1;
	ll ans = -1;
	ll count = -1;
	rep(i, 0, n) {
		ll a;
		cin >> a;
		ll b = gcd(a, lcm);
		ll c = a;
		ll cCount = 0;
		while (c % 2 == 0) {
			cCount++;
			c /= 2;
		}
		if (count < 0) count = cCount;
		if ((min(lcm, a) / b > 1 && max(lcm, a) > m) || count != cCount) {
			ans = 0;
			break;
		}
		else {
			lcm = lcm * a / b;
		}
	}

	if (ans == 0) cout << 0 << endl;
	else {
		ans = (m / (lcm / 2)) / 2 + m / (lcm / 2) % 2;
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
/*
 * 17-05-20_ARC074_C.cpp
 *
 *  Created on: 2017/05/20
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>
using namespace std;


long long H, W;
long long ans = 1e10;
signed main() {
	cin >> H >> W;
	long long s1, s2, s3;
	long long h1 = (2 * H + 3) / 6, h2;
	s1 = W * h1;
	h2 = H - h1;
	if (h2 % 2 == 0 || W % 2 == 0) {
		s3 = s2 = W * h2 / 2;
	} else if (h2 < W) {
		s2 = h2 * (W / 2);
		s3 = h2 * (W - W / 2);
	} else {
		s2 = (h2 / 2) * W;
		s3 = (h2 - h2 / 2) * W;
	}
	ans = min(max(s1, s3) - min(s1, s2), ans);
	h1 = H / 3, h2;
	s1 = W * h1;
	h2 = H - h1;
	if (h2 % 2 == 0 || W % 2 == 0) {
		s3 = s2 = W * h2 / 2;
	} else if (h2 < W) {
		s2 = h2 * (W / 2);
		s3 = h2 * (W - W / 2);
	} else {
		s2 = (h2 / 2) * W;
		s3 = (h2 - h2 / 2) * W;
	}
	ans = min(max(s1, s3) - min(s1, s2), ans);

	long long w1 = (2 * W + 3) / 6, w2;
	s1 = w1 * H;
	w2 = W - w1;
	if (w2 % 2 == 0 || H % 2 == 0) {
		s3 = s2 = w2 * H / 2;
	} else if (H < w2) {
		s2 = (w2 / 2) * H;
		s3 = (w2 - w2 / 2) * H;
	} else {
		s2 = w2 * (H / 2);
		s3 = w2 * (H - H / 2);
	}
	ans = min(max(s1, s3) - min(s1, s2), ans);

	w1 = W / 3, w2;
	s1 = w1 * H;
	w2 = W - w1;
	if (w2 % 2 == 0 || H % 2 == 0) {
		s3 = s2 = w2 * H / 2;
	} else if (H < w2) {
		s2 = (w2 / 2) * H;
		s3 = (w2 - w2 / 2) * H;
	} else {
		s2 = w2 * (H / 2);
		s3 = w2 * (H - H / 2);
	}
	ans = min(max(s1, s3) - min(s1, s2), ans);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;cin>>n>>a>>b;
	cout<<min(a*n,b);
}

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

using namespace std;

long long solve(long long a, long long b){
	if(a%b==0)
		return b*(2*(a/b)-1);
	return (a/b)*(2*b)+solve(b, a%b);
}

int main(){

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

	long long n, x;
	cin >> n >> x;

	cout << n + solve(max(n-x, x), min(n-x, x)) << '\n';

	return 0;
} // br1


Measured memory_bytes: 384
# For taking space seperated integer variable inputs.
import math


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


A, B = invr()
res = -1
for i in range(1001):
    if int(i * 0.08) == A and int(i*0.1) == B:
        res = i
        break
print(res)


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

int main(){
  int n;
  int len;
  int count;
  int i,j;
  int num;
  int flg;
  char moji[10][6]={
    {' ',' ',' ',' ',' '},
    {'.',',','!','?',' '},
    {'a','b','c'},
    {'d','e','f'},
    {'g','h','i'},
    {'j','k','l'},
    {'m','n','o'},
    {'p','q','r','s'},
    {'t','u','v'},
    {'w','x','y','z'}
  };

  cin >> n;

  for(i = 0 ; i < n ; i++){
    num = 0;
    count = -1;
    string str;

    cin >> str;

    for(j = 0 ; j < str.size() ; j++){
      flg = 1;
      if(str[j]=='1'){
	num = 1; 
      }else if(str[j]=='2'){
	num = 2; 
      }else if(str[j]=='3'){
	num = 3; 
      }else if(str[j]=='4'){
	num = 4;
      } else if(str[j]=='5'){
	num = 5; 
      }else if(str[j]=='6'){
	num = 6; 
      } else if(str[j]=='7'){
	num = 7;
      }else if(str[j]=='8'){
	num = 8; 
      }else if(str[j]=='9'){
	num = 9; 
      }else{
	if(num == 0){
	  continue;
	}

	if(num == 1){
	  count = count % 5;
	}else if(num == 7 || num == 9){
	  count = count % 4;
	}else{
	  count = count % 3;
	}

	cout << moji[num][count];

	flg = 0;
	count = -1;
	num = 0;
      }
      if(flg == 1) count++;
    }
    cout << endl;
  }
  return 0;
}
      

Measured memory_bytes: 1204
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;

/*int pre[200006];

int fin(int x)
{
    int r=x;
    while(pre[r]!=r)
        r=pre[r];
    int i=x,j;
    while(i!=r)
    {
        j=pre[i];
        pre[i]=r;
        i=j;
    }
    return r;
}

void unite(int x,int y)
{
    int fx=fin(x);
    int fy=fin(y);
    if(fx!=fy)
        pre[fx]=fy;
}

bool same(int x,int y)
{
    int fx=fin(x);
    int fy=fin(y);
    if(fx!=fy)
        return false;
    return true;
}*/

struct S
{
    char a[105];
};

bool cmp(S a,S b)
{
    return strcmp(a.a,b.a)<0;
}

int main()
{
    int i,k,x,y,j,n,m;
    S p[105];
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++)
        scanf(" %s",p[i].a);
    sort(p,p+n,cmp);
    for(i=0;i<n;i++)
        printf("%s",p[i].a);
    printf("\n");
    return 0;
}

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

int main() {
	int n;
	cin>>n;
	int arr[4]={0};
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s=="AC"){
			arr[0]++;
		}
		else if(s=="WA"){
			arr[1]++;
		}
		else if(s=="TLE"){
			arr[2]++;
		}
		else{
			arr[3]++;}
		}
	cout<<"AC x "<<arr[0]<<endl;
	cout<<"WA x "<<arr[1]<<endl;
	cout<<"TLE x "<<arr[2]<<endl;
	cout<<"RE x "<<arr[3]<<endl;
	
}

Measured memory_bytes: 3648
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int n;
int fie[110][110]={};
int d[]={-1,0,1,0,-1};


bool turn(int dir,int y,int x){
    int tmpy=y+d[dir];
    int tmpx=x+d[dir+1];
//    cout<<endl;
//    dump(dir);dump(y);dump(x);dump(tmpy);dump(tmpx);
    
    if(fie[y][x]==1 || tmpy<0 || tmpy>=n || tmpx<0 || tmpx>=n || fie[ tmpy+d[dir] ][ tmpx+d[dir+1] ]==1 || fie[ tmpy+d[dir+1] ][ tmpx+d[(dir+1)%4+1] ]==1 )return true;
    else return false;
}


int main() {
    
    int aa;
    cin>>aa;
    rep(i,aa){
        if(i!=0)cout<<endl;
        rep(a,110) rep(b,110) fie[a][b]=0;
        cin>>n;
        
        int dir=0;
        int y=n-1,x=0;
        
        int c=0;
        while(1){
            if( turn(dir,y,x) ){
                c++;
                dir++;
                dir%=4;
            }
            else{
                c=0;
                fie[y][x]=1;
                y+=d[dir];
                x+=d[dir+1];
            }
            if(c==4){
                fie[y][x]=1;
                break;

            }
        }
        
        rep(i,n){
            rep(j,n){
                if(fie[i][j]==1)cout<<"#";
                else cout<<" ";
            }
            cout<<endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ASSERT(C, ...) assert( (C) || (PRINT(__VA_ARGS__), false) )
template <class Head> void PRINT(Head head) {
    std::cout << head << "\n";
}
template <class Head, class... Tail> void PRINT(Head head, Tail... tail) {
    std::cout << head << " ";
    PRINT(tail...);
}

ll solve(ll X, ll Y) {
    ll ans = abs(abs(Y) - abs(X));
    if ( Y < X ) ans++;
    if ( 0 < Y && Y < X ) ans++;
    if ( Y < X && X < 0 ) ans++;
    if ( X < 0 && 0 < Y ) ans++;
    return ans;
}

void test() {
    struct Data {ll x; ll y; ll a;};
    vector<Data> v;
    v.push_back(Data{2,4,2});
    v.push_back(Data{-4,-2,2});
    v.push_back(Data{4,-2,3});
    v.push_back(Data{-2,4,3});
    v.push_back(Data{-2,2,1});
    v.push_back(Data{-4,2,3});
    v.push_back(Data{4,2,4});
    v.push_back(Data{2,-2,1});
    v.push_back(Data{2,-4,3});
    v.push_back(Data{-2,-4,4});
    for ( Data d : v ) {
        ASSERT(solve(d.x,d.y) == d.a, d.x, d.y, solve(d.x,d.y));
    }
}

int main() {
    ll X, Y;
    cin >> X >> Y;
    auto ans = solve(X, Y);
    cout << ans << "\n";
    return 0;
}

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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int N;
    cin >> N;
    ll A[N], B[N];
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    priority_queue<int> q;
    int ans = 0;
    ll need_more = 0;
    ll sumA = 0, sumB = 0;
    rep(i, N){
        sumA += A[i];
        sumB += B[i];
        if(A[i] < B[i]){
            need_more += B[i] - A[i];
            ans++;
        }
        else q.push(A[i] - B[i]);
    }
    if(sumA < sumB) cout << -1 << endl;
    else{
        while(need_more > 0){
            need_more -= q.top();
            q.pop();
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

void solve(){}

Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
using lnglng = long long;
using lngdbl = long double;

void fnInput(lnglng& rnNumA, lngdbl& rnNumB)
{
  cin >> rnNumA >> rnNumB;
}

lnglng fnMultiple(lnglng nNumA, lngdbl nNumB)
{
  int nIntB = nNumB * 100 + 0.5;
  return (lnglng)(nNumA * nIntB / 100);
}
  
int main()
{
  lnglng nNumA;
  lngdbl nNumB;

  fnInput(nNumA, nNumB);
  cout << fnMultiple(nNumA, nNumB) << endl;

  return 0;
}

Measured memory_bytes: 3716
n,k=gets.split.map &:to_i
r,s,p=gets.split.map &:to_i
t=gets.chomp


dp=Array.new(n){{"r"=>0,"s"=>0,"p"=>0}}

n.times{|i|
	if i<k
		dp[i]["r"] = t[i]=="s" ? r : 0
		dp[i]["s"] = t[i]=="p" ? s : 0
		dp[i]["p"] = t[i]=="r" ? p : 0
	else
		dp[i]["r"] = [dp[i-k]["s"], dp[i-k]["p"]].max + (t[i]=="s" ? r : 0)
		dp[i]["s"] = [dp[i-k]["r"], dp[i-k]["p"]].max + (t[i]=="p" ? s : 0)
		dp[i]["p"] = [dp[i-k]["r"], dp[i-k]["s"]].max + (t[i]=="r" ? p : 0)
	end
}

x=0
k.times{|i|
	x+=dp[~i].values.max
}

p x

Measured memory_bytes: 31892
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint()
{
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//
map<ll,ll>M;
ll sum,res;
int n;
//
int main()
{
	n=getint();
	M[0]++;
	rep(i,n)
	{
		int x=getint();
		sum+=1ll*x;
		M[sum]++;
	}
	for(auto &e:M)
	{
		res+=1ll*e.second*(e.second-1);
	}
	printf("%lld\n",res/2ll);
	return 0;
}


Measured memory_bytes: 12800
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int n, k;
bool a[10];
int main() {
	while(~scanf("%d %d", &n, &k)){
		for(int i = 0; i < 10; i++) a[i] = false;
		for (int j = 0; j < k; j++) {
			int x;
			scanf("%d", &x);
			a[x] = true;
		}
		while (1){
			int y = n;
			bool flag = true;
			while (y  > 0) {
				if (a[y % 10]) {
					flag = false;
					break;
				}
				y /= 10;
			}
			if (flag) break;
			n++;
		}
		printf("%d\n", n);
		}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		for (int i = 0; i < 200; i++) {
			if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) {
				System.out.println(i);
				return;
			}
			int aa = (b + c) / 2;
			int bb = (c + a) / 2;
			int cc = (a + b) / 2;
			a = aa;
			b = bb;
			c = cc;
		}
		System.out.println(-1);
	}
}


Measured memory_bytes: 23380
n=int(input())
nil=-1
t=[[-1,-1,-1]for _ in range(n)]
for i in range(n):
	a,b,c=map(int,input().split())
	if b!=-1:
		t[b][0]=a
		t[a][1]=b
	if c!=-1:
		t[c][0]=a
		t[a][2]=c
cnt=0
for i in range(n):
	if t[i][0]==-1:
		root=i
		break
def pre(u):
	if u==nil:
		return
	print(" "+str(u),end="")
	pre(t[u][1])
	pre(t[u][2])
def pre2(u):
	if u==nil:
		return
	pre2(t[u][1])
	print(" "+str(u),end="")
	pre2(t[u][2])
def pre3(u):
	if u==nil:
		return
	pre3(t[u][1])
	pre3(t[u][2])
	global cnt
	if cnt==n-1:
		print(" "+str(u))
	else:
		print(" "+str(u),end="")
	cnt+=1
print("Preorder")
pre(root)
print("\n"+"Inorder")
pre2(root)
print("\n"+"Postorder")
pre3(root)



Measured memory_bytes: 5620
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, c;
	cin >> N ;

	if ((N / 1000 == (N % 1000) / 100 && (N%1000)/100 == (N % 100) / 10 )||( (N % 1000) / 100 == (N % 100) / 10 && (N%100)/10 == (N % 10))) cout << "Yes" << endl;
	else cout << "No " << endl;
	
	}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

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

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    priority_queue<long long int> pq;
    int N, M; cin >> N >> M;

    rep(i,N){
        lli a; cin >> a;
        pq.push(a);
    }

    rep(i,M){
        lli rate = pq.top();
        pq.pop();
        rate/=2;
        pq.push(rate);
    }

    lli ans=0LL;
    while(!pq.empty()){
        ans+=pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n); int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
        sum += a.at(i);
    }
    sort(a.begin(), a.end(), greater<int>());
    int cnt = 0;
    for (int x : a) {
        if (x * 4 * m >= sum) {
            cnt++;
            if (cnt == m) {
                break;
            }
        }
    }
    if (cnt == m) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
A = sorted([int(input()) for _ in range(N)])
B = sorted(A[::1],reverse = 1)
qA = collections.deque(A)
qB = collections.deque(B)
Al = []
Bl = []
i = 1
while qA:
    if i:
        Al.append(qA.pop())
        Bl.append(qB.pop())
    else:
        Al.append(qA.popleft())
        Bl.append(qB.popleft())
    i = (i+1)%2
Al = [Al[-1]]+Al[:-1:]
Bl = [Bl[-1]]+Bl[:-1:]
cntA=0
cntB=0
for i in range(N-1):
    cntA += abs(Al[i+1]-Al[i])
    cntB += abs(Bl[i+1]-Bl[i])
print(max(cntA,cntB))


Measured memory_bytes: 18948
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, k, i, j, max, sum;
    int[] a;
    for(;;out.println(max)){
      n = sc.nextInt(); k = sc.nextInt();
      if(n == 0 && k == 0)break;
      max = -k * 10001;
      a = new int[n];
      for(i = 0;i < n;i++)a[i] = sc.nextInt();
      sum = 0;
      for(i = 0;i < k;i++)sum += a[i];
      max = sum;
      for(i = 0;i < n - k;i++){
        sum += (a[i + k] - a[i]);
        if(max < sum)max = sum;
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 67992
#include <iostream>
#include <string>

using namespace std;

bool kaibun(string s, int l, int n){
  string s1, s2;
  if(n==0){
    for(int i=0; i<(l-1)/2; i++) s1+=s[i];
    //cout << s1 << " ";
    for(int i=l-1; i>(l+3)/2-2; i--) s2+=s[i];
    //cout << s2 << endl;
    if(s1==s2){
      //cout << "true0" << endl;
      return (kaibun(s1, s1.length(), 1) && kaibun(s2, s2.length(), 1));
    }
  }
  else if(n==1){
    if(l%2!=0){
      for(int i=0; i<(l-1)/2; i++) s1+=s[i];
      //cout << s1 << " ";
      for(int i=l-1; i>l/2; i--) s2+=s[i];
      //cout << s2 << endl;
    } else{
      for(int i=0; i<(l-1)/2+1; i++) s1+=s[i];
      //cout << s1 << " ";
      for(int i=l-1; i>l/2-1; i--) s2+=s[i];
      //cout << s2 << endl;
    }
    if(l==1 || s1==s2){
      //cout << "true1" << endl;
      return true;
    }
  }
  return false;
}

int main(void){

  string S;
  int N;

  cin >> S;
  N = S.length();

  //cout << N << endl;

  if(kaibun(S, N, 0)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int main() {
    int n, m, a, b, g[8][8] = {}, p[8];
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        p[i] = i;
    for (int i = 0; i < m; ++i) {
        cin >> a >> b;
        a--; b--;
        g[a][b] = g[b][a] = 1;
    }

    int ans = 0;
    do {
        bool f = true;
        for (int i = 0; i < n - 1; ++i) {
            if (g[p[i]][p[i + 1]] == 0)
                f = false;
        }
        if (f)
            ans++;
    } while(next_permutation(p + 1, p + n));

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;

ll N;
map<ll, ll> S;
ll Q;
ll R;

int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    ++S[a];
    R += a;
  }
  cin >> Q;
  for (ll q = 0; q < Q; ++q) {
    ll b, c;
    cin >> b >> c;
    R += (c - b) * S[b];
    S[c] += S[b];
    S[b] = 0;
    cout << R << endl;
  }
}


Measured memory_bytes: 9468
#include<stdio.h>

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if((a==1 || a==2)  && (b==2 || b==1)) printf("3\n");
    if((a==2 || a==3) && (b==3 || b==2)) printf("1\n");
    if((a==3 || a==1) && (b==1 || b==3)) printf("2\n");
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int w, h, i, j;
	while (1)
	{
		scanf("%d%d", &w, &h);
		if (w + h ==0)
		{
			return 0; 
		}

		for (i = 1; i <= w; i++)
		{
			for (j = 1; j <= h; j++)
			{
				if (i > 1 && i < w && j < h && j > 1)
				{
					printf(".");
				}
				else
				{
					printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");

	}
	return 0;
}


Measured memory_bytes: 2044
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
     
        List<Integer> a = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            int d = sc.nextInt();
			a.add(d);
            }
        Collections.sort(a);
			
		int price = 0;
		for (int j = 0; j < K; j++) {
			price += a.get(j);
		}
		System.out.println(price);
        }
		
}

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

void pri(double a, double b, double c, double d, double e, double f){
	printf("(%4f)x + (%4f)y = (%4f)\n(%4f)x + (%4f)y = (%4f)\n\n", a, b, c, d, e, f);
}

int main(){
	double a, b, c, d, e, f, x, y;
	
	while(cin >>a >>b >>c >>d >>e >>f){
		
		b /= a; c /= a; a /= a;
		
		e -= d * b; f -= d * c;
		
		y = f / e;
		
		x = c - (b * y);
		
		if(x < 0) x = ceil(x * 1000 - 0.5) / 1000;
		else x = floor(x * 1000 + 0.5) / 1000;
		if(y < 0) y = ceil(y * 1000 - 0.5) / 1000;
		else y = floor(y * 1000 + 0.5) / 1000;
		
		printf("%.3f %.3f\n", x, y);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

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

   int n,k;
   cin >> n >> k;

    vector<int> d(k);
    vector<int> a(n,0);

    rep(i,k){
        cin >> d[i];
        rep(j, d[i]){
            int x;
            cin >> x;
            a[x-1]++;
        }
    }
    int ans=0;
    rep(i,n){
        if(a[i]==0) ans++;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc119d
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = ReadIntList();

            if (AB[0] >= 13)
            {
                Console.WriteLine(AB[1]);
            } else if (AB[0]>=6)
            {
                Console.WriteLine(AB[1]/2);
            } else
            {
                Console.WriteLine(0);
            }

#if DEBUG
            Console.ReadKey();
#endif
        }

        private static bool IsRange(int a, int from, int to) => (from <= a && a <= to);
        private static int ReadInt() => int.Parse(Console.ReadLine());
        private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList();
        private static double ReadDouble() => double.Parse(Console.ReadLine());
        private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList();
        private static long ReadLong() => long.Parse(Console.ReadLine());
        private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList();
        private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList();
        private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す
            where Type : IComparable
        {
            var lower = 0;
            var upper = s.Count - 1;
            while (upper - lower > 1)
            {
                var mid = lower + (upper - lower) / 2;
                if (s[mid].CompareTo(target) <= 0)
                {
                    lower = mid;
                }
                else
                {
                    upper = mid;
                }

            }
            return lower;
        }
    }
}


Measured memory_bytes: 13268
using System;
using System.Collections.Generic;
using System.Linq;

//ABC046-C-AtCoDeerくんと選挙速報
//http://abc046.contest.atcoder.jp/tasks/arc062_a
class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3");
            WillReturn.Add("2 3");
            WillReturn.Add("1 1");
            WillReturn.Add("3 2");
            //10
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4");
            WillReturn.Add("1 1");
            WillReturn.Add("1 1");
            WillReturn.Add("1 5");
            WillReturn.Add("1 100");
            //101
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("5");
            WillReturn.Add("3 10");
            WillReturn.Add("48 17");
            WillReturn.Add("31 199");
            WillReturn.Add("231 23");
            WillReturn.Add("3 2");
            //6930
        }
        //else if (InputPattern == "Input4") {
        //    WillReturn.Add("5");
        //    WillReturn.Add("3 11");
        //    WillReturn.Add("11 3");
        //    WillReturn.Add("3 11");
        //    WillReturn.Add("11 3");
        //    WillReturn.Add("1 1");
        //}
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        //Console.WriteLine(DeriveMinBaisuu(11, 3));
        //return;

        List<string> InputList = GetInputList();

        long[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => long.Parse(X)).ToArray();

        long TotalT = 1;
        long TotalA = 1;

        foreach (string EachStr in InputList.Skip(1)) {
            SplitAct(EachStr);
            long CurrT = wkArr[0];
            long CurrA = wkArr[1];

            //TotalT以上で最小のCurrTの倍数を求める
            long MinBaisuuT = DeriveMinBaisuu(TotalT, CurrT);

            //TotalA以上で最小のCurrAの倍数を求める
            long MinBaisuuA = DeriveMinBaisuu(TotalA, CurrA);

            //倍率を求める
            long BairituT = MinBaisuuT / CurrT;
            long BairituA = MinBaisuuA / CurrA;

            //大きいほうの倍率となる
            long Bairitu = Math.Max(BairituT, BairituA);

            TotalT = CurrT * Bairitu;
            TotalA = CurrA * Bairitu;

            //Console.WriteLine("CurrT={0},CurrA={1},TotalT={2},TotalA={3}",
            //    CurrT, CurrA, TotalT, TotalA);
        }
        Console.WriteLine(TotalT + TotalA);
    }

    //A,Bを引数として、A以上で最小のBの倍数を求める
    static long DeriveMinBaisuu(long pA, long pB)
    {
        long Syou = pA / pB;
        long Amari = pA % pB;

        return pB * (Syou + Math.Sign(Amari));
    }
}


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

int main() {
  int n;cin>>n;
  map<string,int> mp;
  int cnt=0;
  rep(i,n){
    string s;cin>>s;
    mp[s]++;
    cnt=max(cnt,mp[s]);
  }
  for(auto p:mp){
    if(cnt==p.second)cout<<p.first<<endl;
  }
}

Measured memory_bytes: 19232
#include<iostream>
#include <stdio.h>
#include <math.h>
#include <map>
#include <queue>
#include <string.h>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef unsigned long long ll;
const ll maxn = 1e18;
ll a,n;
ll b;
ll i;
ll sumn = 1;
char s[5];

int main()
{
    scanf("%llu%s",&a,s);
    b = (s[0]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0');
    printf("%llu",a*b/100);

}

Measured memory_bytes: 3204
#include<iostream>
#include<string>
using namespace std;
string S; int sum;
int main() {
	cin >> S;
	for (int i = 0; i < S.size() / 2; i++) {
		if ((S[i] != S[S.size() - i - 1]) || (S[i] == '(' || S[i] == ')')) {
			if (S[i] == ')' && S[S.size() - i - 1] == '(') { goto E; }
			if (S[i] == '(' && S[S.size() - i - 1] == ')') { goto E; }
			sum++;
		E:;
		}
	}
	if (S.size() % 2 == 1) { if (S[S.size() / 2] == '(' || S[S.size() / 2] == ')') { sum++; } }
	cout << sum << endl;
	return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ins insert
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int k,x;
    cin>>k>>x;

    for(int i=x-k+1;i<=x;i++)
        cout<<i<< " ";

    for(int i=x+1;i<x+k;i++)
        cout<<i<< " ";

    return 0;
}


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

const ll mod = 1e9 + 7;

ll power(ll a, ll b) {
	if (b == 0) {
		return 1;
	}
	ll s = power(a, b / 2);
	s *= s;
	if (b & 1) return (s*a);
	return s;
}

int main() {

	ll a, b, c;
	cin >> a >> b >> c;
	map<ll, ll> m;
	m[a]++;
	m[b]++;
	m[c]++;
	if (m[5] == 2 && m[7] == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

        int n = scanner.nextInt();
        int x = scanner.nextInt();

        int sum = 0;
        int count = 1;
        int tmp = 0;

        for(int i=0;i<n;i++) {
        	tmp = scanner.nextInt();
        	if((sum+tmp)>x) {
        		break;
        	}else {
        		sum += tmp;
        		count++;
        	}
        }

        System.out.println(count);

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 21204
fun main(args: Array<String>){
    val coins = readLine()!!.split(" ")
    val intCoins :IntArray = IntArray(3)
    for(i in coins.indices){
        intCoins[i] = coins[i].toInt()
    }
    val ans :String = if(intCoins[2] <= intCoins[0] + intCoins[1]) "Yes" else "No"
    println(ans)
}

Measured memory_bytes: 37640
#include<stdio.h>
#include<stdlib.h>

int main(){
  int X,A,B,n;

  scanf("%d%d%d",&X,&A,&B);

  X=X-A;
  n=X/B;
  X=X-(B*n);

  printf("%d\n",X);

  //printf("%d%d%d\n",X,A,B);

  return 0;
}


Measured memory_bytes: 128
import copy
n = int(input())
x = list(map(int, input().split()))
sortx = copy.copy(x)
sortx.sort()
high_x = sortx[len(sortx)//2]
low_x = sortx[len(sortx)//2-1]
for i in range(len(x)):
    if x[i] <= low_x:
        print(high_x)
    else:
        print(low_x)


Measured memory_bytes: 26724
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    VL v(n);
    ll cur = 0;
    rep(i, n)
    {
        cin >> v[i];
        cur += v[i];
        cur %= MOD;
    }
    ll ans = 0;
    rep(i, n)
    {
        cur -= v[i];
        if (cur < 0)
            cur += MOD;
        ans += v[i] * cur;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4840
#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>

#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;
    }
}

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

    ll N;
    cin >> N;
    vec A(N+1);
    Rep (i, N+1) {
        cin >> A[i];
    }

    ll tmp = 1;
    vec l(N+1);
    l[0] = tmp - A[0];
    Rep (i, N) {
        l[i+1] = (l[i] * 2 - A[i+1]);
        if (l[i]*2 < A[i+1]) {
            cout << "-1\n";
            return 0;
        }
        chmin<ll>(l[i+1], 1e18);
    }

    if (N == 0) {
        if (A[0] == 1) {
            cout << "1\n";
            return 0;
        } else {
            cout << "-1\n";
            return 0;
        }
    }

    vec s(N+1);
    Rep (i, N+1) {
        s[i] = l[i];
    }
    s[N] = 0;
    for (ll i = N-1; i >= 0; i--) {
        chmin(s[i], s[i+1]+A[i+1]);
    }

    ll ans = 0;
    Rep (i, N+1) {
        ans += s[i] + A[i];
    }

    // Rep (i, N+1) {
    //     cout << l[i] << " \n"[i==N];
    // }
    // Rep (i, N+1) {
    //     cout << s[i] << " \n"[i==N];
    // }

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

Measured memory_bytes: 5572
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  int sum=0;
  for(int i=0;i<k;i++){
    sum += a[i];
  }
  
  cout << sum << endl;
  
}

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

using namespace std;

int num[4];
const char op[3] = {'+', '-', '*'};
const string cat[5] = {"(a x (b x (c x d)))",
                       "(a x ((b x c) x d))",
                       "((a x b) x (c x d))",
                       "((a x (b x c)) x d)",
                       "(((a x b) x c) x d)"};

int cal(int a, int b, int op) 
{
    if (op == 0)
        return a + b;
    else if (op == 1)
        return a - b;
    else if (op == 2)
        return a * b;
}


int solve(int i, int j, int k, int l)
{
    if (l == 0) 
        return cal(num[0], cal(num[1], cal(num[2], num[3], k), j), i);
    else if (l == 1) 
        return cal(num[0], cal(cal(num[1], num[2], j), num[3], k), i);
    else if (l == 2) 
        return cal(cal(num[0], num[1], i), cal(num[2], num[3], k), j);
    else if (l == 3) 
        return cal(cal(num[0], cal(num[1], num[2], j), i), num[3], k);
    else if (l == 4) 
        return cal(cal(cal(num[0], num[1], i), num[2], j), num[3], k);
}

void print_ans(int i, int j, int k, int l)
{
    int op_cnt = 0;
    int num_cnt = 0;

    for (int n = 0; n < cat[l].size(); n++) {
        if (cat[l][n] == 'x') {
            switch (op_cnt) {
            case 0:
                cout << op[i];
                op_cnt++;
                break;
            case 1:
                cout << op[j];
                op_cnt++;
                break;
            case 2:
                cout << op[k];
                break;
            }
        }
        else if (cat[l][n] >= 'a' && cat[l][n] <= 'd')
            cout << num[num_cnt++];
        else
            cout << cat[l][n];
    }
    cout << endl;
}


int main()
{
    while (cin >> num[0] >> num[1] >> num[2] >> num[3]) {
        if (!num[0] && !num[1] && !num[2] && !num[3])
            break;
        bool flag = false;

        sort(num, num + 4);
        do {
            for (int i = 0; i < 3; i++) 
                for (int j = 0; j < 3; j++) 
                    for (int k = 0; k < 3; k++) 
                        for (int l = 0; l < 5; l++) 
                            if (solve(i, j, k, l) == 10) {
                                print_ans(i, j, k, l);
                                flag = true;
                                goto result;
                            }
        } while (next_permutation(num, num + 4));
    result:
        if (!flag)
            cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 1224
//Author:- S_Aditya

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const ll mod=1e9+7;         
const int N=1e5+4;

ll dp[104][N];

int main()                  
{
    int n,w;
    
    scn(n); scn(w);
    
    int wt[n+1],cost[n+1];
    
    rep(i,1,n+1)
    {
        scn(wt[i]); scn(cost[i]);
    }
    
    rep(i,1,n+1)
    {
        rep(j,1,w+1)
        {
            dp[i][j]=dp[i-1][j];
            
            if(j-wt[i]>=0)
            dp[i][j]=max(dp[i][j],dp[i-1][j-wt[i]]+1LL*cost[i]);
        }
    }
    
    ll ans=dp[n][w];
    
    lpri(ans);
    
} 

Measured memory_bytes: 79360
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0;; i++){
    h = (h1(key)+i*h2(key))%M;
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0; ; i++ ){
    h = (h1(key)+i*h2(key))%M;
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);

    if ( com[0] == 'i' ){
      if (insert(str)){

      }
    } else {
      if (find(str) ){
	printf("yes\n");
      } else {
	printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16040
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define pb push_back
#define pob pop_back
#define __bp __builtin_popcount
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pdd = pair<ld,ld>;
using vint = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
#define F first
#define S second
const int N = 1e5+5;//(1 << 18) + 5;
//const ll inf = 1e18+7;
const int Inf = 1e9+7;
const ll INF = 1e18+7;
const int Mod = 1e9+7;
const ld eps = 1e-9;
#ifndef M_PI
#define M_PI 3.1415926535
#endif

void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//	freopen("sweets.in", "r", stdin);
//	freopen("sweets.out", "w", stdout);
//	cout << setprecision(7) << fixed;
}

int n, a[2*N];

void solve()
{
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	int mx = a[0];
	ll ans = 0;
	for (int i = 1; i < n; ++i)
	{
		if (a[i] >= mx)
		{
			mx = a[i];
		}
		else
			ans += mx - a[i];
	}
	cout << ans << '\n';
}

signed main()
{
	io();
	int tt = 1;
//	cin >> tt;
	while (tt--)
		solve();
}
//overflows!!!

Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

//Do not get frustrated over WA. Check for edge cases and runtime errors :)
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    string s;
    map<string, ll> mp;
    bool ok = true;
    for (ll i = 0; i < n; ++i) {
        cin >> s;
        mp[s]++;
    }
    ll mx = 0;
    for (auto p : mp) {
        mx = max(mx, p.second);
    }
    set<string> res;
    for (auto p : mp) {
        if (p.second == mx) res.insert(p.first);
    }
    for (auto r : res) cout << r << "\n";
    return 0;
}


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

using namespace std;
using ll = long long;

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

   vector<ll> a(n);
   vector<ll> sums(n + 1);
   sums.at(0) = 0;
   ll S = 0;
   for (int i = 0; i < n; i++){
      cin >> a.at(i);
      sums.at(i+1) = sums.at(i)+a.at(i);
      S += a.at(i);
   }
   ll ans = 20202020202345;

   for (int i = 0; i <= n-1;i++){
      ll sum_r = sums.at(n) - sums.at(i);
      ans = min(ans, abs(sum_r - sums.at(i)));
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 3328
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    For(i,n) for(int i=0;i<n;i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    all(v) v.begin(),v.end()
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    test   int t;cin>>t;for(int l=0;l<t;l++)
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long 
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

int main()
{
MP;
    //test
    {
        int a[2];
        cin>>a[0]>>a[1];
        sort(a,a+2);
        if(a[0]!=1)cout<<1;
        else if(a[1]!=2)cout<<2;
        else cout<<3;
    }

End;
}


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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	string s, t; cin >> s >> t;
	int a, b; cin >> a >> b;
	string u; cin >> u;
	if(s == u) cout << a-1 << " " << b << endl;
	else cout << a << " " << b -1 << endl;
	
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>
#include <bitset>

using namespace std;

int n,a,b;

int main()
{
	cin >> n >> a >> b;
	if ((b - a) & 1)
		cout << "Borys" << endl;
	else
		cout << "Alice" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn = 50 + 2;

int n, a[maxn], b[maxn], used[maxn];
ll Ans;

bool dp[maxn][maxn];
inline bool Check(int id) {
  memset(dp,0,sizeof(dp));
	dp[50][a[id]] = 1;
	for(int i = 50;i >= 1;i --) {
		for(int j = 0;j <= a[id];j ++) {
			if(!dp[i][j]) continue;
			dp[i - 1][j] = 1;
			if(used[i]) dp[i - 1][j % i] = 1;
		}
	}
	return dp[0][b[id]];
}

inline bool check(int x) {
	int flag = 1;
	used[x] = 0;
	if(x == 1) {
		int xxx = 1;
		xxx ++;
	}
	for(int i = 1;i <= n;i ++) {
		flag &= Check(i);
	}
	used[x] = 1;
	return flag;
}

int main() {
	scanf("%d", &n);
	for(int i = 1;i <= n;i ++) scanf("%d", &a[i]);
	for(int i = 1;i <= n;i ++) scanf("%d", &b[i]);
	for(int i = 1;i <= n;i ++) {
		if(a[i] != b[i] && b[i] * 2 >= a[i]) {
			puts("-1");
			return 0;
		}
	}
	Ans = 0;
	for(int i = 0;i <= 50;i ++) used[i] = 1;
	for(int i = 50;i >= 0;i --) {
    if(!check(i)) Ans += 1LL << i;
		else used[i] = 0;
	}
	printf("%lld\n", Ans);
	return 0;
}


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

int main(){
	// sengen
	int n,k;
	// nyuryoku
	cin >> n >> k;
	vector<int> l(n);
	for(int i=0;i<n;i++){
		cin >> l.at(i);
	}
	// keisan
	sort(l.begin(),l.end(),greater<int>());
	int lenth=0;
	for(int i=0;i<k;i++){
		lenth += l.at(i);
	}
	cout << lenth << endl;
}

Measured memory_bytes: 256