akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

void trace(int A[], int N){
	int i;
	for(i = 0; i < N; i++){
		if(i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

void insertionSort(int A[], int N){
	int j, i, v;
	for(i = 1; i < N; i++){
		v = A[i];
		j = i - 1;
		while(j >= 0 && A[j] > v){
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		trace(A, N);
	}
}

int main(){
	int N, i;
	int A[100];
	
	scanf("%d", &N);
	for(i = 0; i < N; i++) scanf("%d", &A[i]);
	
	trace(A, N);
	insertionSort(A, N);
	
	return 0;
}


Measured memory_bytes: 1952
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M, K = map(int, input().split())
    for n in range(N + 1):
        for m in range(M + 1):
            num = N * m + M * n - 2 * m * n
            if K == num:
                print("Yes")
                return

    print("No")
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll N,X,l;
	cin >> N >> X;
	ll ans = 0;
	for(ll i = 0;i < N ;i++){
		cin >> l;
		if (ans == 0){
			ans = abs(l - X);
		}
		else{
			ans = __gcd(ans,abs(l-X));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
     int a,b,x;
     scanf("%d",&a);
     scanf("%d",&b);
     if((a+b)%2==0) x =  (a+b)/2;
     if((a+b)%2!=0) x = (a+b)/2+1;
     printf("%d",x);
     return 0;
    }

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

int main(){
  int x1,y1,x2,y2,x3,y3,x4,y4;
  cin>>x1>>y1>>x2>>y2;
  int vx1,vy1;
  vx1=x2-x1;
  vy1=y2-y1;
  int vx2,vy2;
  vx2 = -vy1;
  vy2 = vx1;
  x3=x2+vx2;
  y3=y2+vy2;
  x4=x3-vx1;
  y4=y3-vy1;

  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<" "<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   int n;
   int now=0,ans=0;
   string s;
   cin >> n >> s;
   for (int i=0;i < n;i++){
     if(s[i]=='I'){
       now++;
       ans=max(ans,now);
     }
     else {
       now--;
       ans=max(ans,now);
     }
   }
   cout << ans << endl;


   return 0;
}



Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <set>
typedef long long int ll;
typedef double ld;
using namespace std;

class DCaracalVsMonster {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll n,i,step=0;
	    in>>n;

	   for(i=0;;i++)
       {
           ll po =1LL<<i;
	       if(po>n)
           {
	           break;
           }
	       if(po<=n)
           {
	           step+=po;
           }
       }
	    out<<step<<endl;
	}
};


int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    DCaracalVsMonster solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    int n=0;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        if(s.at(i)!=t.at(i)){
          n++;
   
        }
       
        }
        if(s.size()>t.size()){
            n++;
        }
        if(n==0){
            cout<<"Yes"<<endl;
            
        }else{
            cout<<"No"<<endl;
        }
    
}

Measured memory_bytes: 3628
N = int(input())
l={}
for _ in range(N):
    s = input()
    if s not in l:
        l[s] = 1
    else:
        l[s] += 1
M = int(input())
for _ in range(M):
    s = input()
    if s in l:
        l[s] -= 1
        
print(max(l.values()) if max(l.values()) >= 0 else 0)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <utility>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define DEBUG(x) cerr<<#x<<":"<<x<<endl;
#define ALL(c) (c).begin(),(c).end()
#define mp make_pair
typedef pair<int, int> P;
  
template<class T> void pv(T a, T b) {
    for(T it = a; it != b; ++it)
        cerr << *it << " ";
    cerr << endl;
}
  
bool defense[100];
  
int main() {
    int N, M;
    cin >> N >> M;
  
    vector<P> v(M);
    REP(i,M) {
        int a, b;
        cin >> a >> b;
        if(a > b) swap(a,b);
        v[i] = mp(a - 1, b - 1);
    }
    // impossible test
    memset(defense, 0, sizeof defense);
    REP(i,M) {
        int s = v[i].first;
        int g = v[i].second;
        for(int i = s; i <= g; i++)
            defense[i] = true;
    }
    if(count(defense, defense + N, false) > 0) {
        cout << "Impossible" << endl;
        exit(0);
    }
  
    sort(ALL(v));
    int ans = 1;
    int cover = -1;
    {
        REP(i,M) {
            if(v[i].first == 0)
                cover = max(cover, v[i].second);
        }
    }
    // DEBUG(cover)
  
    for(;;) {
        if(cover == N - 1) {
            break;
        }
        int next = -1;
        REP(i,M) {
            if(v[i].first <= cover + 1) {
                next = max(next, v[i].second);
            }
            else break;
        }
        cover = next;
        // DEBUG(cover)
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  ll k;
  cin>>n>>k;
  ll a[n];
  rep(i,0,n) cin>>a[i];
  
  bool b[40];
  rep(i,0,40){
    if(k%2) b[i]=true;
    else b[i]=false;
    k/=2;
  }
  
  int c[40];
  rep(i,0,40) c[i]=0;
  rep(i,0,n){
    rep(j,0,40){
      if(a[i]%2) c[j]++;
      a[i]/=2;
    }
  }
  
  ll d[40];
  d[0]=1;
  rep(i,0,39) d[i+1]=d[i]*2;
  
  bool p=false;
  ll ans=0;
  rep(i,0,40){
    if(p){
      ans+=d[39-i]*max(c[39-i],n-c[39-i]);
    }
    else{
      if(b[39-i]){
        if(c[39-i]<=n/2){
          ans+=d[39-i]*(n-c[39-i]);
        }
        else{
          ans+=d[39-i]*c[39-i];
          p=true;
        }
      }
      else{
        ans+=d[39-i]*c[39-i];
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
	int n,tmp,flag;

	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		tmp = i;
		if (tmp % 3 == 0)printf(" %d", i);
		else {
			while (1) {
				if (tmp % 10 == 3) {
					printf(" %d", i);
					flag = 1;
				}
				tmp = tmp / 10;
				if (tmp == 0||flag==1)break;
			}
		}
		flag = 0;
	}
	printf("\n");
	return 0;
}



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

int main() {
    int x;
    int i = 1;
    while(true){
        cin >> x;
        if (x == 0) {
            break;
        }
        cout << "Case " << i << ": " << x << endl;
        i++;
    }
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<string> S(0);
  vector<int> I(0);
  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    int j=0;
    for(;j<S.size();j++)
      if(S.at(j)==s){
        I.at(j)++;
        break;
      }
    if(j==S.size()){
      S.push_back(s);
      I.push_back(1);
    }
  }
  int M;
  cin >> M;
  for(int i=0;i<M;i++){
    string s;
    cin >> s;
    int j=0;
    for(;j<S.size();j++)
      if(S.at(j)==s){
        I.at(j)--;
        break;
      }
    if(j==S.size()){
      S.push_back(s);
      I.push_back(-1);
    }
  }
  int j=0;
  for(int i=0;i<I.size();i++)
    if(I.at(i)>j)
      j=I.at(i);
  cout << j << endl;
}

Measured memory_bytes: 256
S=input()
T=input()
Rs=[-1]*26
Rt=[-1]*26
for i in range(len(S)):
  a=ord(S[i])-ord("a")
  b=ord(T[i])-ord("a")
  if Rs[a]==-1:
    Rs[a]=b
  elif Rs[a]!=b:
    print("No")
    exit()
  if Rt[b]==-1:
    Rt[b]=a
  elif Rt[b]!=a:
    print("No")
    exit()
print("Yes")

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

using namespace std;

const int N = 3e5 + 5;

struct SegmentTree {
    int node[N << 2];
    void init (int i, int l, int r) {
        if (l == r) {
            node[i] = 0;
            return;
        }

        int mid = l + r >> 1;
        init(i << 1, l, mid);
        init(i << 1 | 1, mid + 1, r);
        node[i] = 0;
    }

    void update (int i, int l, int r, int pos, int val) {
        if (l == r) {
            node[i] = max(node[i], val);
            return;
        }

        int mid = l + r >> 1;
        if (pos <= mid) update(i << 1, l, mid, pos, val);
        else update(i << 1 | 1, mid + 1, r, pos, val);
        node[i] = max(node[i << 1], node[i << 1 | 1]);
    }

    int query (int i, int l, int r, int a, int b) {
        if (l > r || a > r || b < l) return 0;
        if (a <= l && r <= b) return node[i];

        int mid = l + r >> 1;
        return max(query(i << 1, l, mid, a, b), query(i << 1 | 1, mid + 1, r, a, b));
    }
} it;

int n, k, a[N], dp[N];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    it.init(1, 0, N - 5);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
        dp[i] = 1 + it.query(1, 0, N - 5, max(0, a[i] - k), min(N - 5, a[i] + k));
        it.update(1, 0, N - 5, a[i], dp[i]);
    }

    cout << *max_element(dp + 1, dp + n + 1) << "\n";
    return 0;
}


Measured memory_bytes: 10104
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	while(n)
	{
		int m=n%10;
		n=n/10;
		if(m==7)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
 } 

Measured memory_bytes: 3636
#include <stdio.h>
#include <math.h>

typedef struct{
	int num;
	double money;
}bank;

int main(void){
	while(1){
		int n, y, r, t, i;
		bank b[50];
		
		scanf(" %d", &n);
		if(n==0) break;
		
		scanf(" %d", &y);
		for(i=0; i<n; i++){
			scanf(" %d %d %d", &b[i].num, &r, &t);
			
			if(t==1){
				b[i].money = 1 + y*r/100.0;
			}
			else if(t==2){
				b[i].money = pow( (1+r/100.0), y);
			}
			
		}
		
		double max = b[0].money;
		int index = 0;
		
		for(i=0; i<n; i++){
			if(max < b[i].money){
				max=b[i].money;
				index = i;
			}
		}
			
		printf("%d\n", b[index].num);
	
	}

	return 0;
}

Measured memory_bytes: 696
import java.util.Scanner;


class Main {
	public static void main(String args[]) {
		
	    Scanner sc = new Scanner(System.in);
	    String  t = sc.next();
	    int S = Integer.parseInt(t);
	    if( 0 <= S && S < 86400){
	        int h = S / 60 / 60;
            int m = ( S - (h * 60 * 60) ) / 60;
            int s = ( S - (h * 60 * 60 + m * 60));
	        System.out.println( h + ":" + m + ":" + s );
    	}
	}

}

Measured memory_bytes: 17128
#include <iostream>
using namespace std;
string s;
int main() {
  cin >> s;
  if (s == "RRR")
    cout << '3' << endl;
  else if (s == "RRS" || s == "SRR")
    cout << '2' << endl;
  else if (s == "RSR" || s == "RSS" || s == "SRS" || s == "SSR")
    cout << '1' << endl;
  else if (s == "SSS")
    cout << '0' << endl;
  system("pause");
  return 0;
}

Measured memory_bytes: 3708
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;

    cout << max(0, a - 2 * b) << endl;
    return 0;
}


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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cout << fixed << setprecision(12);
  int n, k;
  cin >> n >> k;
  vector<double> ev(n);
  double ans = 0.0;
  auto sum = [&](int l, int r) {
    if(l == 0) return ev[r];
    else return ev[r] - ev[l - 1];
  };
  for(int i = 0; i < n; ++i) {
    int p;
    cin >> p;
    ev[i] = (p + 1) / 2.0;
    if(i) ev[i] += ev[i - 1];
    if(i >= k - 1) {
      ans = max(ans, sum(i - k + 1, i)); 
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 1792
S = input()

N = len(S)
L = []
temp = S[0]
c = 1
for i in range(1, N-1):
    if S[i] == temp:
        c += 1
    else:
        L.append(c)
        c = 1
        temp = S[i]
if S[N-1] == temp:
    c += 1
else:
    L.append(c)
    c = 1
L.append(c)

ans = N
while len(L) >= 3:
    if L[0] > L[-1]:
        ans = min(ans, N-L[-1])
        L[-2] += L[-1]
        L.pop(-1)
    else:
        ans = min(ans, N-L[0])
        L[1] += L[0]
        L.pop(0)
        
if len(L) == 2:
    ans = min(ans, max(L))
    
print(ans)

Measured memory_bytes: 3708
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
#define Maxm(A, B) (A > B ? A : B)
#define Minm(A, B) (A < B ? A : B)

ll N,D,D2,x[101010],y[101010];

ll block[1010][1010], mksq[2020][2020];
bool mk[2020][2020],mkyl[2020],mkxl[2020];
ll maxx,cy,cx,minsq,addsq;

ll ans;
double aave;
ll i,j,k,l;

double abss(double a){
    return a < 0 ? -a : a;
}

int main(){
    scanf("%lld%lld", &N,&D);
    fornum(i,0,N){
        scanf("%lld%lld", &x[i],&y[i]);
        block[y[i] % D][x[i] % D]++;
    }
    fornum(i,0,D){
        fornum(j,0,D){
            if(maxx<block[i][j]){
                maxx=block[i][j];
            }
        }
    }
    for (minsq = 0; minsq * minsq < maxx;minsq++)
        ;    
    minsq--;
    //printf("%lld\n", minsq);

    D2 = D * 2;
    fornum(i,0,D2){
        fornum(j,0,D2){
            //printf("%lld ", block[i%D][j%D]);
            if(minsq*minsq<block[i%D][j%D]){
                mk[i][j] = true;
            }
            if(minsq*minsq+minsq<block[i%D][j%D]){
                mkyl[i] = true;
                mkxl[j] = true;
            }
        }
        //printf("\n");
    }
    fornum(i,0,D2){
        if(mkyl[i]){
           continue;
        }
        fornum(j,0,D2){
            if(mkxl[j]||mk[i][j]){
                //printf("a");
                continue;
            }
            
            mksq[i+1][j+1] = Minm(Minm(mksq[i][j+1],mksq[i+1][j]),mksq[i][j])+1;
        }
    }
    addsq = D;
    fornum(i,0,D2){
        fornum(j,0,D2){
            //printf("%lld ",mksq[i+1][j+1]);
            ll asq = D-mksq[i+1][j+1];
            if(asq<addsq){
                addsq = asq;
            }
        }
        //printf("\n");
    }
    

    printf("%lld", (minsq)*D+addsq-1);

    return 0;
}

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

int main(){
  int n,k=20000000,j=0;
  cin>>n;
  int arr[n];
  for(int x=0;x<n; x++){
    cin>>arr[x];
    if(arr[x]<k){
      j++;
    }
    k=min(k,arr[x]);
  }
  cout<<j;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(){
int N;
  cin>>N;
char S[N],T[N];
int M=N*2;
char A[M];
cin>>S>>T;
int j=0;
for(int i=0;i<=N;i++){
A[j]=S[i];
j++;
A[j]=T[i];
j++;
}
cout<<A;
}

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

using namespace std;

int main() {
  long N, K;
  cin >> N >> K;
  vector<long> steps(N);
  for (long n = 0; n < N; ++n) cin >> steps[n];
  
  vector<vector<long>> dp{vector<long>(N, numeric_limits<long>::max()), vector<long>(N, 0)};
  dp[0][0] = 0;
  for (size_t i = 1; i <= K && i < N; ++i) {
    for (size_t idx = 0; idx < i; ++idx) dp[1][idx] = dp[0][idx];    
    for (size_t j = i; j < N; ++j) {
      long tmp = numeric_limits<long>::max();
      for (size_t k = 1; k <= i; ++k) {
	      tmp = min(tmp, min(dp[0][j], dp[1][j-k] + abs(steps[j] - steps[j-k])));
      }
      dp[1][j] = tmp;
    }
    dp[0].swap(dp[1]);
  }
  cout << dp[0][N-1] << endl;
  
  return 0;
}
                     

Measured memory_bytes: 4224
while True:
    H, W = map(int, input().split())
    if H == W == 0:
        break
    for i in range(1, H + 1):
        if i == 1 or i == H:
            print("#" * W)
        else:
            print("#" + "." * (W - 2) + "#")
    print()

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    vector<int> a(3);

    rep(i,3)    cin >> a[i];
    sort(a.begin(),a.end());

    cout << a[2]-a[0] << endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> p(100000), y(100000), yd[100001];

  rep(i, m) cin >> p[i] >> y[i], yd[p[i]].push_back(y[i]);
  rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
  rep(i, m) printf("%06lld", p[i]),
      printf("%06lld\n", lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) -
                             yd[p[i]].begin() + (ll)1);
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int 
int main()
{  ll a,b; 
  cin>>a>>b; 
  if(a>=10)
  cout<<b; 
  else 
  { 
      cout<<b + 100*(10-a);
  }


    return(0);
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    char a, b, c;
    string s;
    cout << 0 << '\n';
    cout.flush();
    cin >> s;
    a = s[0];
    if (a == 'V') {
        return 0;
    }
    int l = 1, r = n;
    while (true) {
        int m = l + r >> 1;
        cout << m << '\n';
        cout.flush();
        cin >> s;
        b = s[0];
        if (b == 'V') {
            return 0;
        }
        if (m & 1) {
            if (b == a) {
                r = m;
            }
            else {
                l = m;
            }
        }
        else {
            if (b == a) {
                l = m;
            }
            else {
                r = m;
            }
        }
    }
    return 0;




}


Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
int a[100005][4];
int dp[100005][4];
int n;

int func(int ind, int flag) {

	if (ind == n) return 0;

	if (dp[ind][flag] != -1) return dp[ind][flag];

	int maxi = 0;
	if (flag == 0) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 1) {
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 2) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
	}

	return dp[ind][flag] = maxi;
}

int main() {

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> a[i][j];
		}
	}

	memset(dp, -1, sizeof dp);

	cout << func(0, 0);

	return 0;
}


Measured memory_bytes: 9600
#include<stdio.h>
int main(){
    char s[3];
    int ans = 0;
    // 整数の入力
    scanf("%s%s%s",&s[0],&s[1],&s[2]);
    
  	if(s[0] == s[1] && s[1] == s[2]){
    	puts("No");
    }else{
  		puts("Yes");
    }
    return 0;
}

Measured memory_bytes: 128
// Created by new_sm
//
#include<bits/stdc++.h>
#define int long long
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
int n;
cin>>n;
int a[n];
for(auto &x:a)
cin>>x;
int sum=0;
for(int i=0;i<n-1;i++)
{
    if(a[i]<=a[i+1])
    continue;
    else
    {
        sum+=(a[i]-a[i+1]);
        a[i+1]=a[i];
    }
}
cout<<sum;
}
signed main()
{
//code
fastio
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t=1;
while(t--)
{
solve();
cout<<endl;
}
}

Measured memory_bytes: 5200
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;

public class Main {
	public static void main(final String[] args){
    
        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        String t = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();

        if(u.equals(s)){
            a -= 1;
        }else{
            b -= 1;
        }
        System.out.print(a + " " + b);
        
        






    }
}

Measured memory_bytes: 23764
use strict;
use warnings;
package SuffixArray;
#sub sa_is(\@$);
sub sa_is{
	my$upper=shift;
	my@s=@{$_[0]};
	my$n=@s;
	if($n==0){
		return();
	}
	elsif($n==1){
		return(0);
	}
	elsif($n==2){
		if($s[0]<$s[1]){
			return(0,1);
		}
		else{
			return(1,0);
		}
	}
	my@sa;
	my@ls;
	for(my$i=$n-2;$i>=0;$i--){
		$ls[$i]=$s[$i]==$s[$i+1]?$ls[$i+1]:$s[$i]<$s[$i+1];
	}
	my@sum_l=(0)x($upper+1);
	my@sum_s=(0)x($upper+1);
	for(0..$n-1){
		if($ls[$_]){
			$sum_l[$s[$_]+1]++;
		}
		else{
			$sum_s[$s[$_]]++;
		}
	}
	for(0..$upper){
		$sum_s[$_]+=$sum_l[$_];
		$sum_l[$_+1]+=$sum_s[$_]if$_<$upper;
	}
	my$induce;
	$induce=sub{
		my@sa=(-1)x$n;
		my@buf=@sum_s;
		for(@_){
			next if$_==$n;
			$sa[$buf[$s[$_]]++]=$_;
		}
		@buf=@sum_l;
		$sa[$buf[$s[$n-1]]++]=$n-1;
		for(0..$n-1){
			my$v=$sa[$_];
			$sa[$buf[$s[$v-1]]++]=$v-1if$v>=1&&!$ls[$v-1];
		}
		@buf=@sum_l;
		for(my$i=$n-1;$i>=0;$i--){
			my$v=$sa[$i];
			$sa[--$buf[$s[$v-1]+1]]=$v-1if$v>=1&&$ls[$v-1];
		}
		return@sa;
	};
	my@lms_map=(-1)x($n+1);
	my$m=0;
	my@lms=();
	for(1..$n-1){
		if(!$ls[$_-1]&&$ls[$_]){
			$lms_map[$_]=$m++;
			push@lms,$_;
		}
	}
	@sa=$induce->(@lms);
	if($m>0){
		my@sorted_lms;
		for(@sa){
			push@sorted_lms,$_ if$lms_map[$_]!=-1;
		}
		my@rec_s=();
		my$rec_upper=0;
		$rec_s[$lms_map[$sorted_lms[0]]]=0;
		for(1..$m-1){
			my$l=$sorted_lms[$_-1];
			my$r=$sorted_lms[$_];
			my$end_l=$lms_map[$l]+1<$m?$lms[$lms_map[$l]+1]:$n;
			my$end_r=$lms_map[$r]+1<$m?$lms[$lms_map[$r]+1]:$n;
			my$same=1;
			if($end_l-$l!=$end_r-$r){
				$same=0;
			}
			else{
				$l++,$r++while$l<$end_l&&$s[$l]==$s[$r];
				$same=0if$l==$n||$r==$n||$s[$l]!=$s[$r];
			}
			$rec_upper++if!$same;
			$rec_s[$lms_map[$sorted_lms[$_]]]=$rec_upper;
		}
		my@rec_sa=sa_is($rec_upper,\@rec_s);
		$sorted_lms[$_]=$lms[$rec_sa[$_]]for 0..$m-1;
		@sa=$induce->(@sorted_lms);
	}
	return@sa;
}
sub suffix_array(\$){
	my@s=map ord,split"",${$_[0]};
	return sa_is(255,\@s);
}
package LcpArray;
sub lcp(\@\@){
	my@s=@{$_[0]};
	my$n=@s;
	my@sa=@{$_[1]};
	my@rnk;
	$rnk[$sa[$_]]=$_ for 0..$n-1;
	my@lcp;
	my$h=0;
	for(0..$n-1){
		$h--if$h>0;
		next if$rnk[$_]==0;
		my$j=$sa[$rnk[$_]-1];
		$h++while$j+$h<$n&&$_+$h<$n&&$s[$j+$h]==$s[$_+$h];
		$lcp[$rnk[$_]-1]=$h;
	}
	return@lcp;
}
sub lcp_array(\$\@){
	my@s=map ord,split"",${$_[0]};
	return lcp(@s,@{$_[1]});
}
package main;
my$s=<>;
chomp$s;
my@sa=SuffixArray::suffix_array($s);
my@lcp=LcpArray::lcp_array($s,@sa);
my$ans=@sa*(@sa+1)/2;
$ans-=$_ for@lcp;
print$ans,$/;


Measured memory_bytes: 252672
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int w_diffs[] = new int[2];
    int h_diffs[] = new int[2];
    int m[][] = new int[3][3];
    boolean con = true;
    
    
    for(int i = 0; i < 3; i++) {
      for(int j = 0; j < 3; j++) {
        m[i][j] = sc.nextInt();
      }
    }
    
    w_diffs[0] = m[0][1] - m[0][0];
    w_diffs[1] = m[0][2] - m[0][1];
    
    h_diffs[0] = m[1][0] - m[0][0];
    h_diffs[1] = m[2][0] - m[1][0];
    
    for(int i = 1; i < 3 && con; i++){
      for(int j = 0; j < 2; j++){
      	if(m[i][j+1] - m[i][j] != w_diffs[j]) con = false;
        if(m[j+1][i] - m[j][i] != h_diffs[j]) con = false;
      }
    }
        
    if(con) System.out.println("Yes");
    else System.out.println("No");
  }
}


Measured memory_bytes: 35748
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        long K = sc.nextLong();

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

        // position, order
        HashMap<Integer, Integer> positionOrderMap = new HashMap<Integer, Integer>();
        List<Integer> orderList = new ArrayList<Integer>();

        int order = 0;
        int currentPos = 1;
        positionOrderMap.put(currentPos, order);
        orderList.add(currentPos);
        
        int offset = 0;
        int loopCount = N;
        while (order < N) {
            order += 1;
            currentPos = A[currentPos-1];
            if (positionOrderMap.containsKey(currentPos)) {
                offset = positionOrderMap.get(currentPos);
                loopCount = order - positionOrderMap.get(currentPos);
                break;
            } else {
                positionOrderMap.put(currentPos, order);
                orderList.add(currentPos);
            }
        }

        List<Integer> offsetOrder = orderList.subList(0, offset);
        List<Integer> loopOrder = orderList.subList(offset, offset+loopCount);
        
        if (K < offset) {
            System.out.println(offsetOrder.get((int) K));
        } else {
            K = (K - offset) % loopCount;
            System.out.println((loopOrder.get((int) K)));
        }
    }
}

Measured memory_bytes: 72288
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 3010
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

LL T,n,m,i,j,k,x,y,z,Ans;
LL a[N][N],f[N][N][4];

IL int Abs(LL x){return (x<0)?-x:x;}
IL void Swap(LL &a,LL &b){a^=b^=a^=b;}
IL LL Min(LL a,LL b){return (a<b)?a:b;}
IL LL Max(LL a,LL b){return (a>b)?a:b;}

IL LL Mi(LL x,LL y){
	LL p=x,t=1,Res=1;
	for (;t<=y;(t&y)?Res=(Res*p)%MOD:0,p=(p*p)%MOD,t<<=1);
	return Res;
}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();	m=read();	k=read();
	for (i=1;i<=k;i++){
		x=read();	y=read();	z=read();
		a[x][y]+=z;
	}
	memset(f,-1,sizeof(f));
	f[1][1][0]=0;
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++){
			for (k=3;k>=0;k--){
				if (f[i][j][k]==-1)	continue;
				if (a[i][j] && k<3)
					f[i][j][k+1]=Max(f[i][j][k+1],f[i][j][k]+a[i][j]);
				}
			for (k=0;k<=3;k++){
				if (f[i][j][k]==-1)	continue;
				if (j<m)
					f[i][j+1][k]=Max(f[i][j][k],f[i][j+1][k]);
				if (i<n)
					f[i+1][j][0]=Max(f[i][j][k],f[i+1][j][0]);
			}
		}
	Ans=Max(f[n][m][0],f[n][m][1]);
	Ans=Max(Ans,Max(f[n][m][2],f[n][m][3]));
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 357340
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

n = input()
flag = False
for i in range(100):
    if i * 4 > n:
        break
    if (n - i * 4) % 7 == 0:
        flag = True
print "Yes" if flag else "No"

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

int main()
{
    unsigned long long l;
    cin >> l;

    double a = (l * (1000000)) / 3;
    double ans = a * a * a;
    cout << std::fixed << std::setprecision(12) << ans / 1000000000000000000 << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, l: "List[int]", r: "List[int]"):
    counter = 0
    for i in range(N):
        counter += r[i]-l[i]+1
    print(counter)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    l = [int()] * (N)  # type: "List[int]"
    r = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, l, r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define mid (low+high)/2
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

ll n,m;
vector < pi > info[N];
ll a,b,c;
ll dist[N];
bool vis[N];
bool can = true;

void dfs(ll cur,ll d)
{
    if(vis[cur])
    {
        if(dist[cur] != d)
            can = false;

        return;
    }

    vis[cur] = true;
    dist[cur] = d;

    rep(i,0,info[cur].size())
    {
        dfs(info[cur][i].first,d+info[cur][i].second);
    }

    return;
}

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

    cin >> n >> m;

    rep(i,0,m)
    {
        cin >> a >> b >> c;

        info[a].push_back(mp(b,c));
        info[b].push_back(mp(a,-c));
    }

    rep(i,1,n+1)
    {
        if(!vis[i])
        {
            dfs(i,0);
        }
    }

    if(can)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}



Measured memory_bytes: 21888
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<memory.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  ll a[n];
  ll ans=0;
  ll b[n];
  ll left=-1;
  ll right=n;
  rep(i,n){
    cin >> a[i];
    a[i]--;
    b[a[i]]=i;
  }
  set<ll> se;
  se.insert(-1);
  se.insert(n);
  rep(i,n){
    if(i>0){
      auto x=se.upper_bound(b[i]);
      right=*x;
      x--;
      left=*x;
    }
    se.insert(b[i]);
    ans+=(i+1)*((b[i]-left-1)*(right-b[i]-1)+right-left-1);
  }
  cout << ans << endl;
return 0;}


Measured memory_bytes: 12800
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.AGC_043
{
    class B
    {

        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            string s = Read();
            int[] array = new int[n];
            bool hasOne = false;
            for(int i = 0; i < n; i++)
            {
                array[i] = s[i] - '1';
                if (array[i] == 1)
                {
                    hasOne = true;
                }
            }
            if (!hasOne)
            {
                for(int i = 0; i < n; i++)
                {
                    array[i] /= 2;
                }
            }

            bool isOdd = IsOdd(array);

            if (isOdd)
            {
                if (hasOne)
                {
                    WriteLine(1);
                }
                else
                {
                    WriteLine(2);
                }
            }
            else
            {
                WriteLine(0);
            }
        }

        static bool IsOdd(int[] array)
        {
            bool[] oddArray = CalcOddArray(array.Length);
            int cnt = 0;
            for(int i = 0; i < array.Length; i++)
            {
                if (array[i] == 1&&oddArray[i])
                {
                    cnt++;                    
                }
            }

            return cnt % 2 == 1;
        }

        static bool[] CalcOddArray(int n)
        {
            bool[] array = new bool[n];
            array[0] = true;
            int numeratorCnt = 0;
            int denominatorCnt = 0;
            for (int i = 1; i < n; i++) {
                int numerator = n - i;
                int denominator = i;

                while (numerator % 2 == 0)
                {
                    numeratorCnt++;
                    numerator /= 2;
                }

                while (denominator % 2 == 0)
                {
                    denominatorCnt++;
                    denominator /= 2;
                }

                array[i] = numeratorCnt == denominatorCnt;
            }

            return array;
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

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

	vector<int> m(n, 0);
	for (int i = 0; i < n - 1; ++i) {
		int a;
		cin >> a;

		++m[a - 1];
	}

	for (int s : m) {
		cout << s << endl;
	}
	
	return 0;
}
	

Measured memory_bytes: 4056
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b>>1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////


int main() {
	ll N;
	cin >> N;

	vector<ll> A(N+1);
	rep(i, N + 1) cin >> A[i];

	vector<ll> zan(N + 1);
	zan[N] = 0;
	for (ll i = N - 1; i >= 0; i--) { zan[i] = zan[i + 1] + A[i + 1]; }

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

	if (A[0] != 0) { cout << -1 << endl; return 0; }
	ll ans = 1;
	ll t = 1;

	repn(i, N) {
		t = t * 2 - A[i];
		if (t < 0) { cout << -1 << endl; return 0; }
		t = min(t, zan[i]);
		//cout << zan[i] << endl;
		ans += t + A[i];
	}

	cout << ans << endl;
}


Measured memory_bytes: 4848
n,k  = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * n
for i in range(1, n):
  start = max(0, i - k)
  dp[i] = dp[start] + abs(h[start] - h[i])
  for j in range(start+1, i + 1):
    dp[i] = min(dp[i], dp[j] + abs(h[j]-h[i]))
  
print(dp[n-1])

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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

void solve() {
	int n;
	int c[20],v[20];
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> c[i];
	}

	ll ans = 0;
	for (int mask = 0; mask < (1<<n); ++mask) {
		ll s = 0;
		for (int j = 0; j < n; ++j) {
			if (mask&(1<<j)) {
				s += v[j]-c[j];
			}
		}
		if (ans < s) {
			ans = s;
		}
	}

	cout << ans << '\n';
}


/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

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

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

a,b = map(int, input().split())

print(max(a+b,a-b,a*b))




Measured memory_bytes: 9164
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
l = []
for _ in range(n):
    l.append(iil())

ans = 0
for item in l[::-1]:
    a = item[0]+ans
    if a%item[1] != 0:
        ans += item[1]-a%item[1]

print(ans)

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

//LIFE IS NOT A PROBLEM TO BE SOLVED

#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a, b) cout << #a << " = " << a << " ---- " << #b << " = " << b << endl;
#define F first
#define S second
#define pb push_back

using namespace std;


typedef long long int ll;
typedef pair<int, int> ii;


int main(){
	
	ll N, M, L, I;
	string S, T;
	cin >> N >> M >> S >> T;
	
	I = (N*M)/__gcd(N, M);
	L = I;
	
	for(; L<=2LL*I; L+=I){
		map<int, char> X;
		for(ll i=0; i<N; i++){
			X[(i*L)/N] = S[i];
		}
		int yep = true;
		for(ll i=0; i<M; i++){
			if(!X.count((i*L)/M) || X[(i*L)/M]==T[i]) continue;
			yep = false;
			break;
		}
		if(yep){
			cout << L << '\n';
			return 0;
		}
	}
	
	puts("-1");
	
	return 0;
} 

Measured memory_bytes: 4736
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(0) ;
using ll = long long ;
const ll INF = 1e10 + 10 ;

int main(){
    fastio
    int a , b ;
    cin >> a >> b ;
    if ( a - 2 * b <= 0 ) {
        cout << 0 << endl;
    }
    else cout << a - 2 * b << endl;
    return 0 ;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
graph = [[False for i in range(N)] for i in range(N)]
ab = []
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ab.append([a, b])
    graph[a][b] = graph[b][a] = True

all_use = (1 << N) - 1


def rec(v, use):
    use |= 1 << v
    for u in range(N):
        if (not graph[u][v]) or (use >> u) & 1:
            continue
        use |= rec(u, use)
    return use

ans = 0
for a, b in ab:
    graph[a][b] = graph[b][a] = False
    if rec(0, 0) != all_use:
        ans += 1
    graph[a][b] = graph[b][a] = True
print(ans)
    

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;

class Program
{
    static void Main()
    {
        new Program().Solve();
    }

    void Solve()
    {
        var nm = ReadLongArray();
        var n = nm[0];
        var m = nm[1];

        var link = new List<long>[n + 1];
        var r = new long[n + 1];
        var k = new List<long>();
        var kk = new List<long>();

        for (var i = 0; i <= n; i++)
        {
            link[i] = new List<long>();
        }

        for (var i = 0; i < m; i++)
        {
            var ab = ReadLongArray();
            link[ab[0]].Add(ab[1]);
            link[ab[1]].Add(ab[0]);
        }

        k.Add(1);

        while (k.Count != 0)
        {
            foreach (var parent in k)
            {
                foreach (var next in link[parent])
                {
                    if (r[next] == 0)
                    {
                        r[next] = parent;
                        kk.Add(next);
                    }
                }
            }

            k.Clear();
            k.AddRange(kk);
            kk.Clear();
        }

        for (var i = 2; i <= n; i++)
        {
            if (r[i] == 0)
            {
                Console.WriteLine("No");
                return;
            }
        }

        Console.WriteLine("Yes");

        for(var i = 2; i <= n; i++)
        {
            Console.WriteLine(r[i]);
        }
    }

    #region Console.Read 関係
    long[] ReadLongArray() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    long ReadLong() => long.Parse(Console.ReadLine());
    #endregion
}


Measured memory_bytes: 54532
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val n = sc.nextInt()
    val k = sc.nextInt()
    val r = sc.nextInt()
    val s = sc.nextInt()
    val p = sc.nextInt()
    sc.nextLine()
    val str = sc.nextLine().toCharArray
    val qd = new QD(n, k, r, s, p)
    println(qd.ans(str))
  }
}

class QD(n: Int, k: Int, r: Long, s: Long, p: Long) {
  def judge(c: Char):Long = {
    if(c.equals('r')) {
      this.p
    } else if(c.equals('s')) {
      this.r
    } else if(c.equals('p')) {
      this.s
    } else {
      0
    }
  }

  def ans(str: Array[Char]): Long = {
    var result = 0L
    for(i <- Range(0, this.n)) {
      if(i >= k && str(i).equals(str(i-k))) {
        str(i) = '_'
      } else {
        result += judge(str(i))
      }
    }
    result
  }
}


Measured memory_bytes: 30828
import scala.collection.mutable.Map
import scala.collection.mutable.PriorityQueue


object Main {
    def main(args : Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n, k = sc.nextInt
        val sushis = List.fill(n)(sc.nextInt, sc.nextInt).sortWith(_._2 > _._2)
        var kind, ans : Long = 0
        val used = new Array[Boolean](n+1)
        var selected = PriorityQueue[Long]()(Ordering.Long.reverse)
        for ((t, d) <- sushis take k) {
            ans += d
            if (used(t)) selected += d
            else {
                used(t) = true
                kind += 1
            }
        }
        val toeat_ : Map[Int, List[Long]] = Map()
        for ((t, d) <- sushis) 
            if (toeat_ contains t) toeat_(t) = d :: toeat_(t)
            else toeat_(t) = List(d)
        var toeat : List[List[Long]] = toeat_.filter{case (k, _) => !used(k)}.values.toList
        toeat = toeat.map(_.sortWith(_ > _)).sortWith(_.head > _.head)
        var candidate : Long = kind * kind + ans
        for (xs <- toeat if selected.size > 0) {
            kind += 1
            ans += (xs.head - selected.dequeue)
            candidate = candidate max (kind * kind + ans)
        }
        println(candidate)
    }
}


Measured memory_bytes: 92716
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define substr(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
vvi E(100010);
int par[100010];
int dist[100010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;cin>>n>>m;
  vi hoge(100010);
  for(int i=0;i<n+m-1;i++){
    int a,b;cin>>a>>b;
    E[a].pb(b);
    hoge[b]++;
  }
  vi cnt(100010);
  for(int i=1;i<=n;i++){
    if(hoge[i]!=0)continue;
    queue<pair<ll,ll>>que;
    que.push(mp(i,0));
    while(!que.empty()){
      pair<int,int>now=que.front();
      que.pop();
      for(int j=0;j<E[now.F].size();j++){
	if(dist[E[now.F][j]]<now.S+1){
	  cnt[E[now.F][j]]++;
	 
	    par[E[now.F][j]]=now.F;
	    dist[E[now.F][j]]=now.S+1;
 if(cnt[E[now.F][j]]==hoge[E[now.F][j]])
	    que.push(mp(E[now.F][j],now.S+1));
	}
      }
    }
  }
  for(int i=1;i<=n;i++){
    printf("%d\n",par[i]);
  }
  return 0;
}



Measured memory_bytes: 7936