akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
  public static void main(String... args) {
    Scanner input = new Scanner(System.in);
    char[] s = input.next().toCharArray();
    Deque<Character> deque = new LinkedList<>();
    for (char c : s) {
      deque.addLast(c);
    }
    
    int q = input.nextInt();
    int rev = 0;
    for (int i = 0; i < q; i++) {
      int op = input.nextInt();
      if (op == 1) {
        rev++;
      } else {
        int f = input.nextInt();
        char c = input.next().charAt(0);
        if (rev % 2 == 0) {
     		if (f == 1) {
              deque.addFirst(c);
            } else {
              deque.addLast(c);
            }
        } else {
          if (f == 1) {
            deque.addLast(c);
          } else {
            deque.addFirst(c);
          }
        }
      }
    }
    
    StringBuilder sb = new StringBuilder();
    while (!deque.isEmpty()) {
      sb.append(deque.pollFirst());
    }
    
    System.out.println(rev % 2 == 0 ? sb.toString() : sb.reverse().toString());
  }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> a(n), num(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    num.at(a.at(i) - 1)++;
  }
  
  vector<int> discard(n + 1); // discard[i]: How many cards you can NOT eat when you operate i times
  for (int i = 0; i < n; i++) {
    if (num.at(i) == 0) continue;
    discard.at(num.at(i) - 1)++;
  }
  // imos
  for (int loop = 0; loop < 2; loop++) {
    for (int i = n - 1; i >= 0; i--) {
      discard.at(i) += discard.at(i + 1);
    }
  }
  
  for (int k = 1; k <= n; k++) {
    int l = 0, r = n / k + 1;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (k * mid <= n - discard.at(mid)) l = mid;
      else r = mid;
    }
    cout << l << '\n';
  }
}

Measured memory_bytes: 6644
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ff first
#define ss second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define forn(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;



int32_t main()
{
    fast

   int test=1;
    //cin>>test;
  
   

  while(test--)
  {
    string s,t;
    cin>>s>>t;
int ans=t.size();
    for(int i=0;i+t.size()<=s.size();i++)
    {
        int c=0;
        for(int j=0;j<t.size();j++)
        {
            if(s[i+j]!=t[j])c++;
        }
        ans=min(ans,c);
    }
   cout<<ans;

// while ending
   }
  

return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  map<char, int> mp;
  REP(i,s.size()) mp[s[i]]++;
  if(mp['N']>0&&mp['S']==0) puts("No");
  else if(mp['S']>0&&mp['N']==0) puts("No");
  else if(mp['E']>0&&mp['W']==0) puts("No");
  else if(mp['W']>0&&mp['E']==0) puts("No");
  else puts("Yes");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    long N,C,x[100005],y[100005],ansr[100005],ansl[100005];
    cin>>N>>C;
    for(int i=0;i<N;i++){
        cin>>x[i+1]>>y[i+1];
    }
    x[N+1]=C; x[0]=0; ansr[N+1]=0,ansl[0]=0;
    long a,b,s=0,t=0;
    for(int i=1;i<=N;i++){
        a=y[i]-x[i]+x[i-1];
        s=s+a;
        ansl[i]=max(ansl[i-1],s);
    }
    for(int i=N;i>=1;i--){
        b=y[i]-x[i+1]+x[i];
        t=t+b;
        ansr[i]=max(ansr[i+1],t);
    }
    long ansR=0,ansL=0;
    long c,d,u=0,v=0,test;
    for(int i=1;i<=N;i++){
        c=y[i]-x[i]+x[i-1];
        u=u+c;
        test=u+ansr[i+1]-x[i];
        test=max(u,test);
        ansR=max(ansR,test);
    }
    for(int i=N;i>=1;i--){
        d=y[i]-x[i+1]+x[i];
        v=v+d;
        test=v+ansl[i-1]-C+x[i];
        test=max(v,test);
        ansL=max(ansL,test);
    }
    cout<<max(ansR,ansL)<<endl;
}


Measured memory_bytes: 3456
import sys
input = sys.stdin.readline
x = int(input())
from collections import defaultdict
A=[int(i) for i in input().split()]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
for i in dd:
    if dd[i] > 1:
        print('NO')
        exit()
print('YES')

        

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

#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 330;
const long long MX = sqrt(N);
const long long H = 17;
const long long MAGIC = 1000;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int m;
int d[N][N][N];
vector < pair < int, int > > v[N];

void solve()
{
        cin >> n >> m;
        for(int i = 1; i <= m; i++){
                int l, r, x;
                cin >> l >> r >> x;
                v[r].pb({l, x});
        }
        d[0][0][0] = 1;
        for(int i = 0; i <= n; i++){
                for(int j = 0; j <= n; j++){
                        for(int h = 0; h <= n; h++){
                                int r = max(i, max(j, h));
                                for(int k = 0; k < v[r].size(); k++){
                                        int l = v[r][k].fi;
                                        int co = (i >= l) + (j >= l) + (h >= l);
                                        if(co != v[r][k].se){
                                                d[i][j][h] = 0;
                                                break;
                                        }
                                }
                                d[r + 1][j][h] = (d[r + 1][j][h] + d[i][j][h]) % mod;
                                d[i][r + 1][h] = (d[i][r + 1][h] + d[i][j][h]) % mod;
                                d[i][j][r + 1] = (d[i][j][r + 1] + d[i][j][h]) % mod;
                        }
                }
        }
        int ans = 0;
        for(int i = 0; i <= n; i++){
                for(int j = 0; j <= n; j++){
                        for(int h = 0; h <= n; h++){
                                if(max(i, max(j, h)) == n){
                                        ans = (ans + d[i][j][h]) % mod;
                                }
                        }
                }
        }
        cout << ans << endl;
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("landscape.in");
        //fout("landscape.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}


Measured memory_bytes: 129152
a = gets
taro = 0
hanako = 0

while line = gets
    words = line.split
    if words[0] > words[1]
        taro += 3
    elsif words[0] < words[1] 
        hanako += 3
    else
        taro += 1
        hanako += 1
    end
end

puts "#{taro} #{hanako}"


Measured memory_bytes: 6844
#include <bits/stdc++.h>
using namespace std;
/*
given a array of ints, return minimum cost from 0 to n-1
each can go from i+1 or i+2

dp[i] = min(dp[i-1] + abs(A[i]-A[i-1], dp[i-2] + abs(A[i]-A[i-2]))
*/

int main() {
    const int INF = 1e9+7;
    int n;
	scanf("%d", &n);
	vector<int> A;
	for (int i = 0; i < n; i++) {
	    int num;
	    scanf("%d", &num);
	    A.push_back(num);
	}
	vector<int> dp(n);
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
	    int prev = i-1 >= 0 ? dp[i-1] + abs(A[i] - A[i-1]) : INF;
	    int prev_prev = i-2 >= 0 ? dp[i-2] + abs(A[i] - A[i-2]) : INF;
	    dp[i] = min(prev, prev_prev);
	}
	printf("%d", dp[n-1]);
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i;
    cin>>i;
    if(i>=1&&i<=999){
    	cout<<"ABC";
	}
	else{
		cout<<"ABD";
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import math

def main():
    n = int(input())

    div = n/1.08
    fl = math.floor(div)
    if math.floor(fl*1.08) == n:
        print(fl)
    elif math.floor((fl+1)*1.08) == n:
        print(fl+1)
    else:
        print(":(")


if __name__ == '__main__':
    main()

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

int main() {
  string s;
  cin >> s;
   
  bool first_CanMonth = false;
  bool second_CanMonth = false;
  if(stoi(s.substr(0,2)) <= 12 && stoi(s.substr(0,2)) > 0) first_CanMonth = true;
  if(stoi(s.substr(2,2)) <= 12 && stoi(s.substr(2,2)) > 0) second_CanMonth = true;
  
  if(first_CanMonth && second_CanMonth) cout << "AMBIGUOUS" << endl;
  else if(first_CanMonth && !second_CanMonth) cout << "MMYY" << endl;
  else if(!first_CanMonth && second_CanMonth) cout << "YYMM" << endl;
  else cout << "NA" << endl;

  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int N = 100 + 5;
int vis[N];

int main()
{
	int x,n;
	cin >> x >> n;
	for(int i = 0; i < n; i++){
		int z;
		cin >> z;
		vis[z] = 1;
	}
	for(int i = 0; i <= 100; i++){
		if(vis[x-i] == 0){
			cout << x-i << endl;
			break;
		}
		else if(vis[x+i] == 0){
			cout << x + i << endl;
			break;
		}
	}
    return 0; 
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
long long n,a[200005],x,sum=0;
void turn(long long  m,int k){
	sum+=m;
	if(a[k+1]>=m) a[k+1]-=m;
	else{a[k]-=(m-a[k+1]);a[k+1]=0;}
}
int main(){
	cin>>n>>x;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n-1;i++) if((a[i]+a[i+1])>x) turn(a[i]+a[i+1]-x,i);
	cout<<sum;
	return 0;
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int num[10];
    for(int i = 0; i < s.size() - 2; ++i){
        int X = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + (s[i+2] - '0');
        num[i] = abs(X - 753);
    }
    cout << *min_element(num, num + s.size() - 2) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define scan(a,n) for(long int index=0;index<n;index++) cin>>a[index];
#define print(a,n) for(long int index=0;index<n;index++) cout<<a[index]<<" ";cout<<endl;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define vli vector<long long int>
#define vlli vector<pair<long long int,long long int>>
#define vsi vector<string>
#define vci vector<char>
#define all(n) (n.begin(),n.end())


 
int main() {
   #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fast;
    ll t;
    t=1;
    while(t--){
      
      float a,b,c;
      cin>>a>>b>>c;
      if(a/c<=b) cout<<"Yes";
      else cout<<"No";

        

    }
return 0;    
 }  

Measured memory_bytes: 3724
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
int x[110];

int main()
{
    int n;
    while(scanf("%d", &n) !=EOF){
        for(int i=0; i<n ; i++){
            scanf("%d", &x[i]);
        }
        sort(x, x+n);
        int mid = n/2;
        long long res=inf;
        for(int i=x[mid];i<=x[n-1];i++){
            long long t=0;
            for(int j=0;j<n;j++){
                int padding = x[j] - i;
                t += padding * padding;
            }
            if(t>res)break;
            else res=t;
        }
        for(int i=x[mid];i>=x[0];i--){
            long long t=0;
            for(int j=0;j<n;j++){
                int padding = x[j] - i;
                t += padding * padding;
            }
            if(t>res)break;
            else res=t;
        }
        printf("%lld\n", res);
    }
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    vi a(3);
    rep(i,3) cin>>a[i];
    sort(all(a));
    cout<<a[0]+a[1]<<endl;
    return 0;
}


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

int main(){
int x,y;
int noflag;
  
cin>>x>>y;

if(x==1 || x==3 || x==5 || x==7 || x==8  || x==10 || x==12){
  if(y==1 || y==3 || y==5 || y==7 || y==8  || y==10 || y==12){
    cout<<"Yes";
    return 0;
  }
  else{
    noflag=1;
  }
}

if(x==4 || x==6 || x==9 || x==11){
  if(y==4 || y==6 || y==9 || y==11 ){
    cout<<"Yes";
   return 0;
  }
  else{
    noflag=2;
  }
}

if(x==2 && y==2){
  cout<<"Yes";
  return 0;
}
else{
  noflag=3;
}

  
if(noflag==3){
	cout<<"No";
}
}



Measured memory_bytes: 256
import sys
f = sys.stdin

board = [[0 for i in range(11)] for j in range(11)]
for i, line in enumerate(f):
    for j, c in enumerate(line.strip()):
        board[i + 1][1 + (i + 1) % 2 + j * 2] = int(c)

step = {(-1, 0 ):'L',(0, -1 ):'U',(1, 0 ):'R',(0, 1):'D'}
    
    
start = pre_loc = 1 + 1j
loc = 3 + 1j
print('R',end='')
while loc != start:
    for direct in [(pre_loc - loc) / 2 * 1j ** (i + 1) for i in range(4)]:
        if board[int(loc.imag + direct.imag)][int(loc.real + direct.real)]:
            pre_loc = loc
            loc += direct * 2
            print(step[(direct.real,direct.imag)],end='')
            break
print()

Measured memory_bytes: 6764
from collections import deque

X, N = [int(i) for i in input().split()]

nums = [int(i) for i in input().split()]

candidates = deque([X])
output = []

while True:
    c1 = candidates[0]
    c2 = candidates[-1]
    for c in [c1,c2]:
        if c not in nums:
            output.append(c)
    if len(output) > 0:
        break
    candidates.appendleft(candidates[0]-1)
    candidates.append(candidates[-1]+1)
    
print(min(output))

Measured memory_bytes: 9472
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	static int n;
	static int[] num;
	
	public static void main(String[] args) throws Exception {
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
			n = Integer.parseInt(br.readLine());
			num = new int[n+1];
			for(int i=2; i<=n; i++) {
				int c = i;
				for(int j=2; j<=i; j++) {
					while(c % j == 0) {
						num[j]++;
						c /= j;
					}
				}
			}
//			Arrays.stream(num).mapToObj(Integer::toString).map(e -> e + ", ").forEach(System.out::print);
//			System.out.println();
			
			int result = (count(75) + count(25) * (count(3) - 1) + count(15) * (count(5) - 1)
					+ count(5) * (count(5) - 1) * (count(3) - 2) / 2);
			System.out.println(result);
		}
	}
	
	public static int count(int nn) {
		return Arrays.stream(num).filter(e -> e >= nn - 1).toArray().length;
	}

}

Measured memory_bytes: 27988
#include<cstdio>
#include<algorithm>

using namespace std;

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

int dp[50][2][3001];

int main(){
	
	int n,m,s,nn,st,i,j,k;
	int t1=0,t2=1;
	while(1){
		scanf("%d%d%d",&n,&m,&s);
		if(n==0)break;
		
		t1=0;
		t2=1;
		n*=n;
		rep(i,50)rep(j,2)rep(k,s+1)dp[i][j][k]=0;
		dp[0][0][0]=1;
		reps(j,m){
			
			dp[0][t2][0]=1;
			
			reps(i,n){
				nn=i;
				st=(nn*(nn+1))/2;
				for(k=st-1;k<s+1;k++){
					dp[i][t2][k]=0;
					if(k-j>=0){
						dp[i][t2][k]+=dp[i-1][t1][k-j];
					}
					dp[i][t2][k]+=dp[i][t1][k];
					if(dp[i][t2][k]<0)puts("AAAAAAA");
					dp[i][t2][k]%=100000;
				}
				/*
				if(i<9&&j<9){
					printf("%d %d\n",i,j);
					for(int k=0;k<50;k++){
						printf("%d ",dp[i][t2][k]);
					}puts("");
				}*/
			}
			swap(t1,t2);
		}
		
		printf("%d\n",dp[n][t1][s]);
	}
}

Measured memory_bytes: 1932
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
  cin >> n;
 vector<tuple<string, int, int>> data(n);
  for (int i = 0; i < n; i++) {
    cin >> get<0>(data.at(i)) >> get<1>(data.at(i));
  get<2>(data.at(i)) = i;
  }
     for (int i = 0; i < n; i++) {
       get<1>(data.at(i)) = get<1>(data.at(i)) * (-1);
     }
  sort (data.begin(), data.end());
    for (int i = 0; i < n; i++) {
  cout << get<2>(data.at(i)) + 1 << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

max_move = 0
tmp_max_move = 0
for i in range(1, N):
    if H[i] <= H[i -1]:
        tmp_max_move += 1
    else:
        max_move = max(max_move, tmp_max_move)
        tmp_max_move = 0

max_move = max(max_move, tmp_max_move)
print(max_move)

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


int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P[i];
  int ans = 0, m = P[0];
  for (int i = 0; i < N; i++) {
    if (P[i] <= m) ans += 1;
    m = min(m, P[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int n,d,aa[1100][4000],ab[1100][10],cnt=0,a,b;
pair<int,int> p[220000];
string s,t,u;
char c;
signed main(){
    cin>>s;
    rep(i,s.size()){
        cout<<'x';
    }
}

Measured memory_bytes: 256
#ifndef ___Geometry_Library
#define ___Geometry_Library

// ------ Includes ------ //
#include <cmath>
#include <vector>
#include <complex>
#include <utility>
#include <algorithm>

// ------ Defines ------ //
typedef long double GType;
typedef std::complex<GType> Point;
typedef std::pair<Point, Point> Segment;

// ------ Constants ------ //
const GType EPS = 1.0e-10L;

// ------ Functions Level 1 ------ //
GType dot(const Point& p1, const Point& p2) {
	return (std::conj(p1) * p2).real();
}
GType cross(const Point& p1, const Point& p2) {
	return (std::conj(p1) * p2).imag();
}
int ccw(const Point& p1, const Point& p2, const Point& p3) {
	Point v1 = p2 - p1, v2 = p3 - p1;
	if (cross(v1, v2) > EPS) return +1;
	if (cross(v1, v2) < -EPS) return -1;
	if (dot(v1, v2) < -EPS) return +2;
	if (std::norm(v1) < std::norm(v2)) return -2;
	return 0;
}

// ------ Functions Level 3 ------ //
GType area(std::vector<Point> v) {
	GType ret = 0;
	for (int i = 0; i < v.size(); i++) {
		if (i + 1 != v.size()) ret += cross(v[i], v[i + 1]);
		else ret += cross(v[i], v[0]);
	}
	return ret / 2;
}

#endif

#include <iomanip>
#include <iostream>
using namespace std;
int n, x, y; vector<Point> v;
int main() {
	cin >> n; v.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		v[i] = Point(x, y);
	}
	cout << fixed << setprecision(1) << area(v) << endl;
	return 0;
}

Measured memory_bytes: 3284
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr = new int[m][2];
        for (int i=0; i<m; i++) {
            arr[i][0] = sc.nextInt() - 1;
            arr[i][1] = sc.nextInt() - 1;
        }

        UnionFind unionFind = new UnionFind(n);
        for (int i=0; i<m; i++) {
            unionFind.unite1(arr[i][0], arr[i][1]);
        }

        int size = unionFind.size.length;

        int res = 1;
        for (int i=0; i<size; i++) {
            res = Math.max(res, unionFind.size[i]);
//            System.out.print(unionFind.size[i]);
        }

        System.out.print(res);


    }
    class UnionFind {

        int[] parent, rank, size;

        void init(int n) {
            for (int i=0; i<n; i++) {
                parent[i] = i;
                rank[i] = 0;
            }
        }

        UnionFind(int n) {
            parent = new int[n];
            size = new int[n];
            for (int i=0; i<n; i++) {
                parent[i] = i;
                size[i] = 1;
            }
        }

        public int find(int x) {
            if (x==parent[x]) return x;
            return parent[x] = find(parent[x]);
        }

        //    結合して木のサイズを更新
        public void unite1(int x, int y) {
            x = find(x);
            y = find(y);
            if (x==y) return;
            if (size[x] < size[y]) {
                int tmp = x;
                x = y;
                y = tmp;
            }
            parent[y] = x;
            size[x] += size[y];
        }


        public boolean same(int x, int y) {
            return find(x) == find(y);
        }

        public int size(int x) {
            return size[find(x)];
        }


    }

}



Measured memory_bytes: 64844
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        

        out.println(n+n*n+n*n*n);
     	out.flush();
    }
        
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

class P {
	int x,y,c;
	P(int  x, int y, int c) {
	  this.x=x;
	  this.y=y;
	  this.c=c;
	}
}

//
//class P implements Comparable<P>{
//	int x,c;long s;
//	P(int  x, int c, long s) {
//	  this.x=x;
//	  this.c=c;
//	  this.s=s;
//	}
//
//    public int compareTo(P p){
//        return Long.signum(s-p.s);
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 32924
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;

using namespace std;
int main()
{
  string S;
  ull K;
  cin >> S >> K;
  string res = "";
  for (auto i = 0; i < S.size(); i++) {
    if (S[i] != '1') {
      res = S[i];
      break;
    } else if (i + 1 == K){
      res = "1";
      break;
    }
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>

using namespace std;

const int maxN = 1e5 + 10;

#define FORU(i, l, r) for (int i = l; i <= r; ++i)
#define FORD(i, r, l) for (int i = r; i >= l; --i)
#define REPU(i, r) for (int i = 0; i < r; ++i)
#define LL long long
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define PINT pair < ll, int >
#define BIT(x, i) ((x >> i) & 1)
#define NUM_SET_BIT __builtin_popcountll

int a[maxN], n;

int gcd(int a, int b) {
    return (b == 0) ? a : gcd(b, a % b);
}

int main() {
    cin >> n;
    FORU(i, 0, n) cin >> a[i];
    int g = 0, max_v = 0;
    FORU(i, 1, n) g = gcd(a[i], g), max_v = max(max_v, a[i]);
    if (a[0] > max_v || a[0] % g) cout << "IMPOSSIBLE";
    else cout << "POSSIBLE";
}


Measured memory_bytes: 640
main = do
  li <- getLine
  let [r,d,x2000] = map read $ words li
  let answer = compute r d x2000
  sequence_ $ map print answer

compute :: Int -> Int -> Int -> [Int]
compute r d x2000 = take 10 $ tail $ iterate f x2000
  where
    f xi = r * xi - d

Measured memory_bytes: 508
import bisect

s = input()
t = input()
lis = [[]for _ in range(26)]

for i,j in enumerate(s):
    j = ord(j) -ord("a")
    lis[j].append(i)

lenlis = [len(lis[i]) for i in range(26)]

now = 0
ans = 0
for i in t:
    i = ord(i) -ord("a")
    if lenlis[i] == 0:
        ans = -1
        break
    insert_index = bisect.bisect_left(lis[i],now)
    if insert_index == lenlis[i]:
        ans += 1
        now = lis[i][0] +1
    else:
        now = lis[i][insert_index] + 1

if ans == -1:
    print(-1)
else:
    ans = ans*len(s) + now
    print(ans)


Measured memory_bytes: 7756
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>

using namespace std;
typedef long long ll;
const int maxn = 2e5+10;

ll x[maxn],y[maxn],h[maxn];

int main(){
    int n;
    cin>>n;
    for(int i = 1;i<=n;i++){
        cin>>x[i]>>y[i]>>h[i];
    }
    ll cx,cy;
    for(int i = 0;i<=100;i++)
    for(int j = 0;j<=100;j++){
        bool flag = true;
        int H = -1;
        for(int k = 1;k<=n;k++){
            int ret = abs(x[k] - i) + abs(y[k] - j);
            if(h[k] > 0){
                H = ret + h[k];
            } 
            else if(H == -1) H = ret;
        }
        for(int k = 1;k<=n;k++){
            int ret = abs(x[k] - i) + abs(y[k] - j);
            if(h[k] > 0){
                int tmp = ret + h[k];
                if(tmp!=H){
                    flag = false;
                    break;
                }
            }
            else{
                int tmp = ret;
                if(H > tmp) {
                    flag = false;
                    break;
                }
            }
        }
        if(flag && H >= 1){
            cout<<i<<' '<<j<<' '<<H<<endl;
            exit(0);
        }
    }
    return 0;
}



Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define PI 3.1415926535897932384626
#define mod 1000000007
#define fo(i,n) for(i=0;i<n;i++)
#define endl "\n"
#define mset(m,v) memset(m,v,sizeof(m))
typedef vector<int>	vi;

void solve()
{
	int n,i=1,x=0;
	cin >> n ;
	if(n%2==0){
	    cout << -1;
	    return ;
	}
	while(i<100000000){
	    x+=7;
	    x%=n;
	    if(x==0){
	        cout << i;
	        return ;
	    }
	    x*=10;i++;
	}
	cout << -1 << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define szof(x) int32_t((x).size())
#define str(x) to_string(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const ll MOD998 = 998244353;
const int INF = 1e9;
const ll LLINF = 1e18;

mt19937_64 rng((uint) chrono::steady_clock::now().time_since_epoch().count());

template <class T>
T rnd(T l, T r) {
	return uniform_int_distribution<T>(l, r)(rng);
}

int add(int x, int y, int mod = MOD998) {
	return x + y >= mod ? x + y - mod : x + y;
}

int sub(int x, int y, int mod = MOD998) {
	return x - y < 0 ? x - y + mod : x - y;
}

int mul(int x, int y, int mod = MOD998) {
	return 1LL * x * y % mod;
}

int pw(int a, int n, int mod = MOD998) {
	int res = 1;
	while (n) {
		if (n & 1) {
			res = mul(res, a, mod);
		}
		a = mul(a, a, mod);
		n >>= 1;
	}
	return res;
}

int inv(int x, int mod = MOD998) {
	return pw(x, mod - 2, mod);
}

vector<int> get_invs(int upto, int mod = MOD998) {
	vector<int> res(upto + 1);
	res[1] = 1;
	for (int i = 2; i <= upto; i++) {
		res[i] = mod - mul(mod / i, res[mod % i], mod);
	}
	return res;
}


void run() {
	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(n));
	for (auto &v : a) {
		for (int &x : v) {
			cin >> x;
		}
	}
	vector<vector<int>> dp(n + 1, vector<int>(1 << n, -1));
	dp[0][0] = 1;
	function<int(int, int)> solve = [&](int boys, int girls) {
		if (dp[boys][girls] != -1) {
			return dp[boys][girls];
		}
		int res = 0;
		for (int girl = 0; girl < n; girl++) if (girls & (1 << girl)) if (a[boys - 1][girl]) {
			res = add(res, solve(boys - 1, girls ^ (1 << girl)), MOD);
		}
		return dp[boys][girls] = res;
	};
	cout << solve(n, (1 << n) - 1) << "\n";
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cout.precision(10); cout << fixed;
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		run();
	}
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


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

typedef long long ll;
const long long LINF = 1LL << 60;
const long long LMINF = 1LL << 63;
const int INF = 1 << 30;

#define REP(i,n) for(int i = 0;i < n;++i)
#define REPS(i,x) for(int i = 1;i <= (int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i >= 0;i--)
#define RREPS(i,x) for(int i=((int)(x));i > 0;i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"

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



int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n;
    cin >> n;
    long double z = 1.08;
    int x= ceil(n / z);
    if(floor(x * z) == n){cout << x << endl;}else{cout << ":(" << endl;}    

    return 0;
}

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

int main()
{
	long long K;
	cin >> K;

	long long gcd = __gcd( K, 10LL );
	if( gcd != 1 ) {
		cout << -1 << endl;
		return 0;
	}
	long long ans = 1;
	long long n = 7 % K;
	while( n ) {
		n = n * 10 + 7;
		n %= K;
		ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main(){
	init();
	ll n;cin>>n;
	vector<ll>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	vector<ll>ans;
	if(n%2==0){
		for(int i=n-1;i>=0;i-=2){
			ans.push_back(a[i]);
		}
		for(int i=0;i<n;i+=2){
			ans.push_back(a[i]);
		}
	}
	else{
		for(int i=n-1;i>=0;i-=2){
			ans.push_back(a[i]);
		}
		for(int i=1;i<n;i+=2){
			ans.push_back(a[i]);
		}
	}
	
	for(int i=0;i<n;i++)cout<<ans[i]<<endl;
}



Measured memory_bytes: 5488
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,S;
  cin>>N>>S;
  VL A(N);
  rep(i,N) cin>>A[i];
  VVL X(N+1,VL(S+1,0));
  X[0][0]=1;
  ll mod=998244353;
  rep(i,N) rep(j,S+1){
    if(X[i][j]){
      X[i+1][j]=(X[i+1][j]+2*X[i][j]%mod)%mod;
      if(j+A[i]<=S) X[i+1][j+A[i]]=(X[i+1][j+A[i]]+X[i][j])%mod;
    }
  }
  cout<<X[N][S]<<endl;
}

Measured memory_bytes: 73684
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A, B = map(int, input().split())
if A == B:
    print("Draw")
elif B == 1 or (A != 1 and A < B):
    print("Bob")
else:
    print("Alice")


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long K, X;
  cin >> K >> X;
  cout << (K * 500 >= X ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
 
  int N ;
  int ans = 0 ;
  cin >> N ;
  vector<int> A(N) ;
  rep(i,N) cin >> A.at(i) ;
  map<int,int> mp_k ;
  map<int,int> mp_g ;
  vector<pair<int,int>> G ;
  vector<pair<int,int>> K ;
  rep(i,N){
    if(i%2) mp_k[A.at(i)]++ ;
    else mp_g[A.at(i)]++ ;
  }
  for(auto p : mp_g ) G.push_back(make_pair(p.second,p.first)) ;
  for(auto p : mp_k ) K.push_back(make_pair(p.second,p.first)) ;
  
  sort(G.begin(),G.end()) ;
  sort(K.begin(),K.end()) ;
  reverse(G.begin(),G.end()) ;
  reverse(K.begin(),K.end()) ;
  if(G.at(0).second != K.at(0).second ){
    cout << N - G.at(0).first - K.at(0).first << endl;
    return 0 ;
  }
  if(G.at(0).first == N/2 && K.at(0).first == N/2 ){
    cout << N - G.at(0).first << endl ;
    return 0 ;
  }
  if(G.at(0).first == N/2 && K.at(0).first != N/2 ){
    cout << N - G.at(0).first - K.at(1).first << endl ;
    return 0 ;
  }
  if(G.at(0).first != N/2 && K.at(0).first== N/2 ){
    cout << N - G.at(1).first - K.at(0).first << endl ;
    return 0 ;
  }
    cout << min( N - G.at(0).first - K.at(1).first , N - G.at(1).first - K.at(0).first ) << endl;
}

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

ll nCr(ll n,ll r){
  ll res=1;
  for(int i=0;i<n-r;i++){
    res*=(n-i);
    res/=(i+1);
  }
  return res;
}

ll mpow(ll a,ll b){
  ll res=1;
  while(b){
    if(b%2==1)res*=a;

    b/=2;
    a=a*a;
  }
  return res;
}

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

  ll a=0,b=0;
  for(int i=0;i<N;i++){
    ll x;
    cin>>x;
    if(x%2==0)a++;
    else b++;
  }
  
  ll ans=0;
  if(P==0){
    for(int i=0;i<=b;i+=2){
      ans+= nCr(b,i) * mpow(2,a);
    }
  }else{
    for(int i=1;i<=b;i+=2){
      ans+= nCr(b,i) * mpow(2,a);
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = "";
		ArrayList<String> array = new ArrayList();
		String[] param = a.split("");
		for (int i = 0; i < param.length; i++) {
			array.add(param[i]);
		}
		Collections.reverse(array);
		for (int i = 0; i < param.length; i++) {
			b += array.get(i);
		}
		if (a.equals(b)) {
			System.out.println("Yes");
		} else if (a.equals(b) == false) {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}inline void read(i64 &x){
	x=0;i64 f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
const int maxn=100005;
i64 v[maxn],del[maxn];
int n,w[maxn],tmp[maxn],m,f[maxn];
i64 k;
int main(){
	read(n);
	rep(i,1,n)read(v[i]);
	rep(i,2,n)del[i]=v[i]-v[i-1];
	read(m);read(k);
	rep(i,1,n)w[i]=i;
	rep(i,1,m){
		int x;read(x);
		swap(w[x+1],w[x]);
	}rep(i,1,n)f[i]=i;
	for(;k;k>>=1){
		if(k&1){
			rep(i,1,n)tmp[i]=f[i];
			rep(i,1,n)f[i]=tmp[w[i]];
		}
		rep(i,1,n)tmp[i]=w[i];
		rep(i,1,n)w[i]=tmp[w[i]];
	}
	rep(i,2,n)v[i]=del[f[i]]+v[i-1];
	rep(i,1,n)printf("%lld.0\n",v[i]);
	return 0;
}

Measured memory_bytes: 4224
#n=int(input())
n,k=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

ans=0
while True:
    ans+=1
    shou=n//k
    amari=n%k
    if shou==0:
        break
    n=shou
print(ans)

Measured memory_bytes: 3060
#include <cstdio>

using namespace std;

int gcd(int a, int b) {
    if (a < b) return gcd(b, a);
    if (a % b) return gcd(b, a % b);
    return b;
}

int main() {
    int n, s, a;
    scanf("%d%d", &n, &s);
    for (int i = 1; i < n; ++i) {
        scanf("%d", &a);
        s = gcd(s, a);
    }
    printf("%d\n", s);
    return 0;
}


Measured memory_bytes: 128
main = getContents >>= putStr . unlines . map solve . init . map (rl . words) . lines

rl :: [String] -> [Int]
rl = map read

solve :: [Int] -> String
solve [] = []
solve (x:y:[]) = if x > y then (show y) ++ " " ++ (show x)
                          else (show x) ++ " " ++ (show y)


Measured memory_bytes: 4544
from collections import deque
import sys
sys.setrecursionlimit(10000000)
N, M = map(int, input().split())
class tree():
    def __init__(self):
        self.num = 0
        self.flag = 0
        self.step = -1
        self.leaf = []

li = [tree() for i in range(N)]
def saiki(que, step):
    pop = que.popleft()
    li[pop].flag = 2


    for i in range(len(li[pop].leaf)):
        if li[li[pop].leaf[i]].flag == 0:
            que.append(li[pop].leaf[i])
            li[li[pop].leaf[i]].flag = 1
            if li[li[pop].leaf[i]].step != -1:
                if li[li[pop].leaf[i]].step > li[pop].step + 1:
                    li[li[pop].leaf[i]].step = li[pop].step + 1
                    li[li[pop].leaf[i]].num = pop
            else:
                li[li[pop].leaf[i]].step = li[pop].step + 1
                li[li[pop].leaf[i]].num = pop


    #print(que)
    if len(que) != 0:
        saiki(que, li[pop].step)
for i in range(M):
    A, B = map(int, input().split())
    li[A-1].leaf.append(B-1)
    li[B-1].leaf.append(A-1)

que = deque()
que.append(0)
li[0].step = 0
saiki(que, 0)
flag = 1

for i in range(len(li)):
    if li[i].flag == 0:
        flag = 0
        break
if flag == 0:
    print("No")
else:
    print("Yes")
for i in range(1, len(li)):
    print(li[i].num+1)

Measured memory_bytes: 201696
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


bool check(string s) {
  int dig = 0;
  for(auto itr : s) {
	dig += (itr - '0');
	dig %= 9;
	//	cout << dig << endl;
  }
  return dig % 9 == 0;
}


int main() {
  ll N;
  ll cost = 0;
  ll pre;
  cin >> N;
  cin >> pre;
  rep(i,N-1) {
	ll h;
	cin >> h;
	cost += max(ll(0),pre - h);
	pre = max(h,pre);
  }
  cout << cost << endl;
  return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define prt_cs                  printf("Case %lld: ",cs)
#define sqr(x)                  (x)*(x)
#define ms(a,b)                 memset(a, b, sizeof(a))
#define db                      double
#define ll                      long long int
#define MOD                     100000007
#define PI                      acos(-1.0)
#define pii                     pair< int, int >
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
#define gcd(a, b)               __gcd(a, b)
#define lcm(a, b)               (((a)*(b))/gcd(a,b))
#define MAX                     100005

using namespace std;

int main()
{
//    READ;
//    WRITE;
    string s;
    cin>>s;
    ll n=0;
    for(int i=0;i<s.size();i++)
    {
        n+=(s[i]-'0');
    }
    if(n%9==0)
        printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 3700
let n = read_int ()
let ps = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let qs = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ns, fs, c, a, b = Array.(make n 0, make n false, ref 0, ref 0, ref 0)
let rec f i = if i >= n then (incr c; if !a = 0 && ps = ns then a := !c; if !b = 0 && qs = ns then b := !c; if !a * !b > 0 then (Printf.printf "%d\n" @@ abs (!a - !b); exit 0))
  else for j = 0 to n - 1 do if not fs.(j) then (fs.(j) <- true; ns.(i) <- j + 1; f (i + 1); fs.(j) <- false) done
let _ = f 0

Measured memory_bytes: 384
S = input()

def solve(S):
    check1 = 1 <= int(S[0:2]) <= 12
    check2 = 1 <= int(S[2:4]) <= 12
    return {
        (False, False): "NA",
        (False, True):  "YYMM",
        (True,  False): "MMYY",
        (True,  True):  "AMBIGUOUS",
    }[(check1, check2)]

print(solve(S))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009

void solve()
{
	ll n;
	rl(n);
	if(n%2==1)
	{
		cout<<0<<endl;
		return;
	}

	ll ans=0;
	for(ll i=10;i<1e18+5;i*=5)
	{
		ans+=n/i;
	}
	wl(ans);
	NL;
	return;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    long long N,M;
    cin>>N>>M;
    long long A[M];
    long long answer =N;
    
    for(long long i=0;i<M;i++)
    {
      cin>>A[i];
    }
    for(long long i=0;i<M;i++)
    {
      answer-=A[i];
    }
    if(answer>=0){
    	cout<<answer<<endl;
    }else{
        cout<<"-1"<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 3664
from collections import defaultdict
from math import gcd

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
mod = 10 ** 9 + 7
MAX = 2 * 10 ** 5

p = defaultdict(int)
m = defaultdict(int)
ab0 = 0
for a, b in ab:
    if a == 0 and b == 0:
        ab0 += 1

    elif a == 0:
        m[(0, 1)] += 1
        p[(1, 0)]

    elif b == 0:
        p[(1, 0)] += 1

    else:
        g = gcd(a, b)
        a //= g
        b //= g
        sign = a * b
        a = abs(a)
        b = abs(b)
        if sign < 0:
            m[(a, b)] += 1
            p[(b, a)]
        else:
            p[(a, b)] += 1

power = [1]
for _ in range(MAX):
    power.append(power[-1] * 2 % mod)

ans = 1
for (a, b), v in p.items():
    ans *= power[v] + power[m[(b, a)]] - 1
    ans %= mod

ans -= 1
ans += ab0
ans %= mod
print(ans)


Measured memory_bytes: 118156
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [a, b] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const cost = _ => {
  if (a >= 13) {
    return b
  } else if (a >= 6) {
    return b / 2
  } else {
    return 0
  }
}

console.log(cost())


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int k,a,b,i;
    cin>>k>>a>>b;
    for(i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK"<<endl;
            i=0;
            break;
        }
    }
    if(i!=0) cout<<"NG"<<endl;
}



Measured memory_bytes: 3564