akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
#define rev_rep(i, n) for(int i = n - 1; i >= 0; --i)
#define dump(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair);
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair){
  os << '(' << pair.first << ',' << pair.second << ')';
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::set<T>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  ll N;
  cin >> N;
  vector<ll> v(N);

  rep(i, N){
    cin >> v[i];
  }
  int res = 0;
  while(1){
    auto b = v.begin();
    auto e = v.begin();
    while(b != v.end() && *b == 0){ // find beg
      b++;
      e++;
    }
    // dump(*e);
    while(e != v.end() && (e + 1) != v.end() && * (e + 1) != 0){ // find end
      e++;
    }
    // dump(*e);
    if(b == e && e == v.end()){
      break;
    }

    while(b <= e){
      (*b)--;
      b++;
    }
    // dump(v);
    res++;

  }

  cout << res;
    
}
#endif


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 

 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll ans = 0;
    ll n, k; cin >> n >> k;

    ll d;
    vector<int> p;
    for (int i = 0; i < n; i++) {
        p.push_back (0);
    }

    for (int i = 0; i < k; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            ll ip; cin >> ip;
            p[--ip] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        if (p[i] == 0) ans++;
    }

    cout << ans << endl;


} 

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;

int main() {
    int a[100000], n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    a[n] = 100000 + 1;

    sort(a, a + n);
    int m = 0, l = -1;
    int j = 0, k = -1;
    for (int i = 0; i <= n; i++) {
        if (a[i] == j) {
            k++;
        } else {
            if (k % 2 == 0) m++;
            l++;
            j = a[i];
            k = 1;
        }
    }
    cout << l - (m % 2 == 1) << endl;
    return 0;
}


Measured memory_bytes: 640
def C_BuildStairs():
    N = int(input())
    H = list(map(int, input().split()))
    ans = "Yes"
    for x in range(N - 1):
        if H[x] < H[x+1]:
            H[x+1] -= 1
        if H[x] > H[x + 1]:
            ans = "No"
            break
    print(ans)
    
if __name__ == "__main__":
    C_BuildStairs()

Measured memory_bytes: 14396
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	int n;
	cin >> n;
	
	int d1, d2;
	int cnt=0;
	bool yes=0;
	for(int i=0 ; i<n ; ++i){
		cin >> d1 >> d2;
		if(d1 == d2)++cnt;
		else cnt=0;
		
		if(cnt == 3){
			yes=1;
		}
	}
	
	cout << (yes ? "Yes" : "No");
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cout << fixed << setprecision(10);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}


Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<sstream>
using namespace std;
int inf = 1000000000;

int main(){
  string s;
  int w;
  cin >> s >> w;
  string ans = "";
  for(int i=0; i<s.size(); i++){
    if( i % w == 0 ) ans += s[i];
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
sum=0
for i in range(n-1):
    if B[i]-A[i]>0:
        if A[i+1]-(B[i]-A[i])<0:
            
       #     print(A[i]+A[i+1])
            sum+=A[i]+A[i+1]
            A[i+1]=0
        else:
            A[i+1]+=-(B[i]-A[i])
      #      print(B[i])
            sum+=B[i]
    else:
     #   print(B[i])
        sum+=B[i]

if B[n-1]<A[n-1]+A[n]:
    #print(B[n-1])
    sum+=B[n-1]
else:
    #print(A[n-1]+A[n])
    sum+=A[n-1]+A[n]
print(sum)


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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {


			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			var hegihtArray = retreiveLongArray();

			var overSet = new Dictionary<long, long>();

			for (int i = 0; i < N; i++) {
				var code = i - hegihtArray[i];
				if (overSet.ContainsKey(code)) {
					overSet[code]++;
				}
				else {
					overSet.Add(code, 1);
				}
			}

			var underSet = new Dictionary<long, long>();
			for (int i = 0; i < N; i++) {
				var code = i + hegihtArray[i];
				if (underSet.ContainsKey(code)) {
					underSet[code]++;
				}
				else {
					underSet.Add(code, 1);
				}
			}

			long count = 0;
			for (int i = 0; i < N; i++) {

				var condition = i + hegihtArray[i];
				long num = 0;

				if (overSet.ContainsKey(condition)) {
					num = overSet[condition];
				}
				count += num;
			}


			for (int i = 0; i < N; i++) {

				var condition = i - hegihtArray[i];
				long num = 0;

				if (underSet.ContainsKey(condition)) {
					num = underSet[condition];
				}
				count += num;
			}


			//答えの出力
			var ans = count/2;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 61388
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;
 
typedef tuple<ll,ll,ll> T;

int main(){
	int T;
	cin >> T;
	int N,D;
	for(int i=0;i<T;i++){
		cin >> N >> D;
		N--;
		if(N%2==0)
			cout << N*127 + D << endl;
		else
			cout << N*127 +127 - D << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
using namespace std;
 
int main(){
   int n,i;
   long long tmp,sum=0;
   long mean;
   cin>>n;
   for(i=0;i<n;i++){
       cin>>tmp;
        sum+=tmp;
   }
   mean=sum/n;
   cout<<mean<<endl;
    return 0;
}


Measured memory_bytes: 3016
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)

void run() {
  int n;
  cin >> n;
  int n_ok{0};
  rep(i, 0, n) {
    int d1, d2;
    cin >> d1 >> d2;
    if (d1 == d2) {
      ++n_ok;
      if (n_ok >= 3) {
        cout << "Yes" << endl;
        return;
      }
    } else {
      n_ok = 0;
    }
  }
  cout << "No" << endl;
}

int main() {
  cin.tie(nullptr);
  run();
  return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    vector<ll> v={a,b};
    for(auto &x: v){
        if(x<k){
            k-=x;
            x=0;
        }
        else{
            x-=k;
            k=0;
        }
    }
    for(auto x: v) cout<<x<<" ";
}

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

using namespace std;


int main(){
  string s;
  cin >> s;
  if(s.at(2) == s.at(3) && s.at(4) == s.at(5)){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(400000)
n,m=map(int,input().split())
g=[[] for _ in range(n+1)] #グラフ
for i in range(m):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
for j in range(len(g)):
    g[j]=sorted(list(set(g[j])))
visited=[0]*(n+1)
def dfs(v):
    global ret
    visited[v]+=1
    flag=0
    for i in range(len(g[v])):
        if visited[g[v][i]]==0:
            ret+=1
            flag=1
            dfs(g[v][i])
ans=0
for i in range(1,n+1):
    if visited[i]==0:
        ret=1
        dfs(i)
        length=ret
        if ans<length:
            ans=length
print(ans)


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

int main(){
    int n;
    int a[10000];
    long long int min = 1000000;
    long long int max = -1000000;
    long long int sum = 0;
    
    cin >> n;
    
    for (int i =0; i <n ; i++){
        cin >> a[i];
        if (a[i] <min) min =a[i];
        if (a[i] >max) max = a[i];
        sum += a[i];
    }
    cout << min <<" "<< max << " "<<sum << endl;
    
    return 0;
}


Measured memory_bytes: 3148
#include <stdio.h>

int ALDS1_1_A();
void printA(int* a, int n);

int main()
{
	return ALDS1_1_A();
}

void printA(int* a, int n) {
	int i;
	for (i = 0; i < n; i++) {
		printf("%d", a[i]);
		i < n - 1 ? printf(" ") : printf("\n");
	}
}

int ALDS1_1_A() {
	int n, i, a[1000];

	scanf("%d", &n);

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

	int v, j;
	printA(a, n);
	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;
		printA(a, n);
	}
	
	return 0;

}



Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;

signed main(){
  ll n; cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    if(a[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = a[0];
  for(int i = 1; i < n; i++){
    if((INF < ans * a[i]) || (INF / ans < a[i])){
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
#define fmax akioi
multiset<long long> fmax,foth,bmin; 
multiset<long long>::iterator it;
int n;
long long a[300100];
long long b[200100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=3*n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n*2;i++){
		b[i]=a[i];
	}
	sort(b+1,b+n*2+1);
	reverse(b+1,b+n*2+1);
	long long sigmaf=0LL,sigmab=0LL;
	for(int i=1;i<=n;i++){
		fmax.insert(b[i]);
		sigmaf+=b[i];
	}
	for(int i=n+1;i<=n*2;i++)
		foth.insert(b[i]);
	for(int i=n*2+1;i<=n*3;i++){
		bmin.insert(a[i]);
		sigmab+=a[i];
	}
	long long tmp;
	long long res=sigmaf-sigmab;
	for(int i=n*2;i>=n+1;i--){//delete
		it=foth.find(a[i]);
		if(it!=foth.end()){
			foth.erase(it);
		}
		else{
			it=fmax.find(a[i]);
			sigmaf-=*it; 
			fmax.erase(it);
			it=foth.find(*foth.rbegin());
			sigmaf+=*it;
			fmax.insert(*it);
			foth.erase(it);
		}
		if(a[i]<*bmin.rbegin()){
			it=bmin.find(*bmin.rbegin());
			sigmab-=*it;
			bmin.erase(it);
			sigmab+=a[i];
			bmin.insert(a[i]);
		}
		res=max(res,sigmaf-sigmab);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 18176
import numpy as np
h, w = map(int, input().split())
table = np.array([list(input())for _ in range(h)]) == '.'
 
d = np.zeros((h, w), dtype = int)
u = np.zeros((h, w), dtype = int)
r = np.zeros((h, w), dtype = int)
l = np.zeros((h, w), dtype = int)

for i in range(h):
    d[i] = (d[i-1]+1) * table[i]
    u[-i-1] = (u[-i]+1) * table[-i-1]

for i in range(w):
    r[:, i] = (r[:, i-1]+1) * table[:, i]
    l[:, -i-1] = (l[:, -i]+1) * table[:, -i-1]
print(np.max(d+u+r+l)-3)

Measured memory_bytes: 219832
#include <iostream>
#include <math.h>
#include<iomanip>
using namespace std;

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

  if(X < 100){
    cout << 0;
    return 0;
  }
  if(X >= 100 && X< 106 ){
    cout << 1;
    return 0;
  }

  int num = X/100;
  int val = X - num * 100;
  if(num * 5 < val ){
    cout << 0;
  }
  else{
    cout << 1;
  }
  
  return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)

//変数
int a, b, c, d;

//解法
void solve() {

	cout << min(a, b) + min(c, d);

	return;
}

int main() {
	//入力
	cin >> a >> b >> c >> d;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;
#define what(x) cerr << #x << " is " << x << endl;

int main(){
    string s;
    cin >> s;
    string t;
    cin >> t;
    vector<string> ret;
    vector<int> start;
    for(int i = 0; i < s.size(); ++i) {
        bool ok = true;
        for(int j = 0; j < t.size(); ++j) {
            if(s[i+j] != '?' && s[i+j] != t[j]) {
                ok = false;
                break;
            }
        }
        if(ok)
            start.push_back(i);
    }
    if(start.size() == 0) {
        cout << "UNRESTORABLE" << endl;
    }
    else {
        for(auto idx : start) {
            string temp = s;
            for(int i = idx; i < idx+t.size(); ++i) {
                temp[i] = t[i-idx];
            }
            for(int i = 0; i < s.size(); ++i) {
                if(temp[i] == '?')
                    temp[i] = 'a';
            }
            ret.push_back(temp);
        }
        sort(ret.begin(), ret.end());
        cout << ret[0] << endl;
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int l[n];
    rep(i, n) cin >> l[i];

    int* maxv = max_element(l, l+n);
    int maxi = distance(l, maxv);
    int other = 0;

    rep(i, n) if (i != maxi) other += l[i];

    if (*maxv < other) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  int A[M];
  int sum = 0;
  rep(i,M) {
    cin >> A[i];
    sum += A[i];
  }
  int ans = N - sum;
  if(ans < 0) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String str = in.nextLine();
    in.close();
    int num = Integer.parseInt(str.substring(0, 3));
    int ans = Math.abs(753 - num);
    for (int i = 3; i < str.length(); i++) {
      num = (num % 100) * 10 + str.charAt(i) - (int)'0';
      int tmp = Math.abs(753 - num);
      if (ans > tmp) {
        ans = tmp;
      }
      if (ans == 0) {
        break;
      }
    }
    System.out.println(ans);
  }
}
    

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;




ll T1, T2, A1, A2, B1, B2;

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

    cin>>T1>>T2>>A1>>A2>>B1>>B2;

    ll P = (A1-B1)*T1;
    ll Q = (A2-B2)*T2;

    if (P > 0) {
	P = -P;
	Q = -Q;
    }

    if (P + Q < 0) {
	out(0);
    }

    if (P + Q == 0) {
	out("infinity");
    }

    assert(P + Q > 0);


    // 1,2,2,2,....2,[1],0,0,0....

    // k = # of 2's
    
    // |P| > k(P+Q)
    ll k = abs(P)/(P+Q); 
    if (abs(P)%(P+Q) == 0) k--;

    ll res = 1 + 2*k;

    // If divisible, [1] "exact bounce" occurs
    if (abs(P)%(P+Q) == 0) res++;

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


Measured memory_bytes: 3656
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String data1 = sc.nextLine();
        String data2 = sc.nextLine();
        
        String[] array1 = data1.split(" ");
        String[] array2 = data2.split(" ");
        
        int n = Integer.parseInt(array1[0]);
        int m = Integer.parseInt(array1[1]);
        
        int sum = 0;
        
        for(int i = 0; i < m; i++)
        {
            int buf = Integer.parseInt(array2[i]);
            sum += buf;
        }
        
        int nokori = n - sum;
        
        if(nokori < 0)
        {
            nokori = -1;
        }
        System.out.println(nokori);
    }
}


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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int decode(char c)
{
	if(isupper(c)) return c-'A';
	if(islower(c)) return c-'a'+26;
	if(isdigit(c)) return c-'0'+52;
	if(c=='+') return 62;
	if(c=='/') return 63;
	assert(0);
}

vvi parse(int w,int h)
{
	vvi res(h);
	rep(i,h){
		string s; cin>>s;
		for(char c:s){
			int x=decode(c);
			per(j,6) res[i].push_back(x>>j&1);
		}
		res[i].erase(begin(res[i])+w,end(res[i]));
	}
	return res;
}

vvi mirror(const vvi& a)
{
	return vvi(a.rbegin(),a.rend());
}

vvi rotate(const vvi& a)
{
	int n=a.size();
	vvi b(n,vi(n));
	rep(i,n) rep(j,n)
		b[n-1-j][i]=a[i][j];
	return b;
}

int main()
{
	const ull prime1=1e9+7;
	const ull prime2=1e9+9;
	
	for(int w,h,p;cin>>w>>h>>p && w|h|p;){
		vvi image=parse(w,h);
		vvi pattern=parse(p,p);
		if(p>w || p>h){
			cout<<0<<endl;
			continue;
		}
		
		ull pp1=1,pp2=1;
		rep(i,p) pp1*=prime1,pp2*=prime2;
		
		vvi match(h,vi(w));
		for(int _=0;_<2;_++,pattern=mirror(pattern))
		for(int _=0;_<4;_++,pattern=rotate(pattern)){
			ull ph=0;
			rep(j,p){
				ull x=0;
				rep(i,p) (x*=prime1)+=pattern[i][j];
				(ph*=prime2)+=x;
			}
			
			vector<ull> t(w);
			rep(i,p) rep(j,w) (t[j]*=prime1)+=image[i][j];
			
			rep(i,h-p+1){
				ull ih=0;
				rep(j,p) (ih*=prime2)+=t[j];
				rep(j,w-p+1){
					if(ih==ph) match[i][j]=1;
					if(j+p<w) ((ih*=prime2)-=t[j]*pp2)+=t[j+p];
				}
				if(i+p==h) continue;
				rep(j,w) ((t[j]*=prime1)-=image[i][j]*pp1)+=image[i+p][j];
			}
		}
		
		int res=0;
		rep(i,h) rep(j,w) res+=match[i][j];
		cout<<res<<endl;
	}
}

Measured memory_bytes: 9308
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int sum = a + b;
    if(sum == 3){
      System.out.println(3);
    }else if(sum == 4){
      System.out.println(2);
      }else{
      System.out.println(1);          
      }
  }
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var K = ReadInt();
            var list = new List<int>();
            for (int i = 1; i <= K; i++)
            {
                for (int j = 1; j <= K; j++)
                {
                    for (int l = 1; l <= K; l++)
                    {
                        list.Add(Gcd(Gcd(i, j), l));
                    }
                }
            }
            WriteLine(list.Sum());
        }
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        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: 92616
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename G >
struct StronglyConnectedComponents {
  const G &g;
  UnWeightedGraph gg, rg;
  vector< int > comp, order, used;

  StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
    for(int i = 0; i < g.size(); i++) {
      for(auto e : g[i]) {
        gg[i].emplace_back((int) e);
        rg[(int) e].emplace_back(i);
      }
    }
  }

  int operator[](int k) {
    return comp[k];
  }

  void dfs(int idx) {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt) {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(UnWeightedGraph &t) {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    for(int i = 0; i < g.size(); i++) {
      for(auto &to : g[i]) {
        int x = comp[i], y = comp[to];
        if(x == y) continue;
        t[x].push_back(y);
      }
    }
  }
};

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  int n, m; cin >> n >> m;
  UnWeightedGraph g(n);
  vector<int> z(m);
  for(int i=0;i<m;++i) {
    int a, b;
    cin >> a >> b >> z[i];
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  StronglyConnectedComponents<UnWeightedGraph> scc(g);
  UnWeightedGraph buff;
  scc.build(buff);
  map<int, bool> sel;
  int ans = 0;
  for(int i=0;i<n;++i) {
    if(!sel[scc[i]]) {
      ans++;
      sel[scc[i]] = true;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 20864
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
using namespace std;

int main(){
    int A,P;cin>>A>>P;
    int ans = 0;
    ans += 3*A;
    ans += P;
    ans = ans / 2;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 200000

using namespace std;
typedef pair<llong, llong> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

llong N, K;
llong A[MAX_N], F[MAX_N];

ipair AF[MAX_N];


llong g(llong x) {
    llong sum = 0;
    for(int i = 0; i < N; ++i)
        if(AF[i].first > x)
            sum += ceil((double)(AF[i].first - x) / AF[i].second);
    return sum;
}

llong ub() {
    llong l = 0, r = 1e12;
    while(l <= r) {
        llong mid = l + (r - l) / 2;
        if(g(mid) <= K) r = mid - 1;
        else l = mid + 1;
    }
    return l;
}

llong solve() {
    llong res = ub();
    return res;
}

int main(int argc, char **argv) {
    cin >> N >> K;
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = 0; i < N; ++i) cin >> F[i];
    
    sort(A, A + N);
    sort(F, F + N);
    reverse(A, A + N);

    for(int i = 0; i < N; ++i)
        AF[i] = make_pair(A[i] * F[i], F[i]);
    
    cout << solve() << endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> l(2*n);
	for(int i = 0; i < 2*n; i++)
		cin >> l[i];
	sort(l.begin(), l.end());
	int ans = 0;
	for(int i = 0; i < 2*n; i+=2){
		ans += min(l[i], l[i+1]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()

if s == 'RRR':
    print(3)
    exit()
elif s == 'SSS':
    print(0)
    exit()
elif s[:2] == 'RR' or s[1:] == 'RR':
    print(2)
    exit()
elif 'R' in s:
    print(1)
    exit()
else:
    print(0)
    exit()

Measured memory_bytes: 8980
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""
#decomment when needed
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
a,b,c = ips()
if a <b+c:
    print(b+c-a)
else:
    print(0)

Measured memory_bytes: 15684
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IFOR(v,it) for(VI::iterator it=(v).begin();it!=(v).end();++it)
#define IN(v) cin>>(v)
#define OUT(v) cout>>(v)>>endl

int D, G;

int solve(int P[10], int C[10], int k) {
  int score = 0;
  int count = 0;
  REP(i, D) {
    bool flag = ((k >> i) & 1) == 1;
    if (!flag)
      continue;
    score += (i+1)*100 * P[i] + C[i];
    count += P[i];
  }
  if (score < G) {
    for (int i = D - 1; i >= 0; --i) {
      bool flag = ((k >> i) & 1) == 1;
      if (flag)
        continue;
      if ((i+1) * 100 * (P[i] - 1) + score < G)
        return 1e6;
      int problem_score = ((i+1) * 100);
      count += (G - score + problem_score - 1) / problem_score;
      break;
    }
  }
  return count;
}

int main() {
  cin >> D >> G;


  int P[10], C[10];
  REP(i, D) {
    int p, c;
    cin >> p >> c;
    P[i] = p;
    C[i] = c;
  }

  int res = 1e6;
  REP(k, 1 << D) {
    // 完全に解くかbitを立てる
    res = min(res, solve(P, C, k));
  }
  cout << res << endl;


  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=20005;
int n,i,j,a[N],p[N],l,b[N],ans[N],g,cnt;
bool v[N];
int Abs(int a)
{
	return a>0?a:-a;
}
int gcd(int a,int b)
{
	if(!b)
		return a;
	return gcd(b,a%b);
}
int main()
{
	scanf("%d",&n);
	for(i=n;i>=0;--i)
		scanf("%d",a+i);
	for(i=2;i<=n;++i)
	{
		if(!v[i])
			p[++l]=i;
		for(j=1;j<=l&&p[j]*i<=n;++j)
		{
			v[p[j]*i]=true;
			if(i%p[j]==0)
				break;
		}
	}
	g=Abs(a[0]);
	for(i=1;i<=n;++i)
		g=gcd(g,Abs(a[i]));
	for(i=2;i*i<=g;++i)
		if(g%i==0)
		{
			ans[++cnt]=i;
			while(g%i==0)
				g/=i;
		}
	if(g>1)
		ans[++cnt]=g;
	for(i=1;i<=l;++i)
	{
		for(j=0;j<=n;++j)
			b[j]=(a[j]%p[i]+p[i])%p[i];
		for(j=n;j-p[i]+1>=1;--j)
		{
			b[j-p[i]+1]=(b[j-p[i]+1]+b[j])%p[i];
			b[j]=0;
		}
		for(;j>=0;--j)
			if(b[j]!=0)
				break;
		if(j<0&&g%p[i]!=0)
			ans[++cnt]=p[i];
	}
	sort(ans+1,ans+1+cnt);
	for(i=1;i<=cnt;++i)
		printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cmath>

void rekkyo(int i, int k, int n){
    int j;
    for(j=(i+1)*i/2;j>i*(i-1)/2;j--){
        printf(" %d",j);
    }
    j=i*(i-1)/2+i+1;
    if(j<=n)printf(" %d",j);
    int tmp = i+2;
    while(true){
        j+=tmp;
        if(j>n)break;
        printf(" %d",j);
        tmp++;
    }
    printf("\n");
    return;
}

int main(){
    int i,k,n;
    scanf("%d",&n);
    k = sqrt(n*2)+1;
    if(n!=k*(k-1)/2){
        printf("No\n");
        return 0;
    }
    printf("Yes\n%d\n",k);

    for(i=0;i<k;i++){
        printf("%d",k-1);
        rekkyo(i,k,n);
    }

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    string S;
    cin>>S;
    int N=S.length();
    int a=0;
    int b=0;
    rep(i,N){
        if(i%2==0){
            if(S[i]=='0') a++;
            else b++;
        }else {
            if(S[i]=='0') b++;
            else a++;
        }
    }
    cout<<min(a,b)<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef tuple<ll, ll, ll>T;
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

vector<int>pa[101010];
vector<int>e[101010];
vector<int>ans(101010,-1);

void dfs(int n) {
	fore(x,e[n]) {
		if (ans[x] != -1)continue;
		int ok = 1;
		fore(y, pa[x]) {
			if (ans[y] == -1) {
				ok = 0;
				break;
			}
		}
		if (ok) {
			ans[x] = n+1;
			dfs(x);
		}
	}
}


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

	rep(i, 0, n + m - 1) {
		int a, b;
		cin >> a >> b;

		a--, b--;
		pa[b].pb(a);
		e[a].pb(b);
	}

	rep(i, 0, n) {
		if (pa[i].size() == 0) {
			ans[i] = 0;
			dfs(i);
			break;
		}
	}

	rep(i, 0, n) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 15360
#include<bits/stdc++.h>
using namespace std;
int H,W,K,i,j,k,l,counti;
string s[10];
vector<int> u,v;

void check(vector<int> &u, vector<int> &v)
{
    int q,w,r,t,cur = 0;
    for(q=0;q<H;q++)
    {
        for(w=0;w<W;w++)
        {
            bool pass = true;
            for(auto it: u)
                if(it==q) pass = false;
            for(auto it: v)
                if(it==w) pass = false;
            if(s[q].at(w)=='#' && pass)
                cur++;
        }
    }
    if(cur==K)
        counti++;
}

void fi_trav(int z)
{
    v.push_back(z);
    if(z!=W-1)
        fi_trav(z+1);
    if(z==W-1)
        check(u,v);
    v.pop_back();
    if(z!=W-1)
        fi_trav(z+1);
    if(z==W-1)
        check(u,v);
}

void traverse(int z)
{
    u.push_back(z);
    if(z!=H-1)
        traverse(z+1);
    if(z==H-1)
        fi_trav(0);
    u.pop_back();
    if(z!=H-1)
        traverse(z+1);
    if(z==H-1)
        fi_trav(0);
}

int main()
{
    cin>>H>>W>>K;
    for(i=0;i<H;i++)
        cin>>s[i];
    traverse(0);
    cout<<counti;
}


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

int z[26] = {0};
char ch[4] = {'i', 'x', 'c', 'm'};
string s1, s2;
int n;

string enc(int x);
int dec(string s);

int main() {
  int a;
  cin >> n;
  z['m' - 'a'] = 1000;
  z['c' - 'a'] = 100;
  z['x' - 'a'] = 10;
  z['i' - 'a'] = 1;
  for(a = 0; a < n; ++a) {
    cin >> s1 >> s2;
    cout << enc(dec(s1) + dec(s2)) << endl;
  }
  return 0;
}

string enc(int x) {
  int now, xx = x;
  string ans;
  for(int i = 0; i < 4; ++i) {
    now = xx % 10;
    xx /= 10;
    if(now == 0) continue;
    ans += ch[i];
    if(now == 1) continue;
    ans += '0' + now;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
int dec(string s) {
  int ans = 0;
  for(int i = 0; i < s.size(); ++i) {
    if(s[i] >= 'a' && s[i] <= 'z')
      ans += z[s[i] - 'a'];
    else
      ans += (s[i] - '0') * z[s[++i] - 'a'];
  }
  return ans;
}


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

int main(){
    int a, b, c, temp;
    cin >> a >> b >>c;
    
    if(a > b){
        temp = b;
        b = a;
        a = temp;
    }
        if(b > c){
        temp = b;
        b = c;
        c = temp;
    }
        if(a > b){
        temp = b;
        b = a;
        a = temp;
    }
    cout<< a <<" "<< b <<" "<< c <<endl; 
}


Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#define pb push_back
#define s(a) (int)(a).size()
#define all(x) (x).begin(),(x).end()
#define endl ("\n")

using ll = long long;
using ld = long double;
const ll M = 1000000007;
const ld pi = 3.14159265358979323846;

long long mod(long long x)
{
    return ((x%M + M)%M);
}

long long add(long long a, long long b)
{
    return mod(mod(a)+mod(b));
}

long long mul(long long a, long long b)
{
    return mod(mod(a)*mod(b));
}

void solve()
{
	int n, k;
	cin >> n >> k;
	string sh;
	cin >> sh;
	sh[k - 1] += 'a' - 'A';
	cout << sh << endl;
}

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

	int tt = 1;
	//cin >> tt;
	for(int test_case = 1; test_case <= tt; test_case++)
	{
		//cout << "Case #" << test_case << ": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 3580
/**
 *    author: tanishq_code_c
**/
#include <bits/stdc++.h>
using namespace std;



void __print(int x) {cerr << x;}; void __print(long x) {cerr << x;}; void __print(long long x) {cerr << x;}; void __print(unsigned x) {cerr << x;}; void __print(unsigned long x) {cerr << x;}; void __print(unsigned long long x) {cerr << x;}; void __print(float x) {cerr << x;}; void __print(double x) {cerr << x;}; void __print(long double x) {cerr << x;}; void __print(char x) {cerr << '\'' << x << '\'';}; void __print(const char *x) {cerr << '\"' << x << '\"';}; void __print(const string &x) {cerr << '\"' << x << '\"';}; void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif


#define int                                         long long
#define setbits(x)                                     __builtin_popcountll(x)
#define zerobits(x)                                 __builtin_ctzll(x)
#define mod                                         1000000007
#define inf                                            1e18
#define endl                                        '\n'
#define pb                                          push_back
#define all(x)                                      x.begin(),x.end()
#define ff                                          first
#define ss                                          second
#define rep(i,n)                                      for(int i = 0; i < n; i++)
#define set(n)                                      fixed << setprecision(n)

int powmod(int a, int b) {int res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod; a = a * a % mod;} return res;}
int fast_pow(int a, int b) {if (b == 1) return a; if (b == 0) return 1; int x = fast_pow(a, b / 2); x *= x; if (b & 1) x *= a; return x;}

void t_c_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /*#ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif*/
    int n; cin >> n;
    int arr[n];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    for (int i = 1; i < n; i++) {
        if (arr[i] < arr[i - 1]) {
            ans += max(arr[i], arr[i - 1]) - arr[i];
            arr[i] = arr[i - 1];
        }
    }
    cout << ans << endl;
}

int32_t main()
{
    t_c_c();
    return 0;
}


Measured memory_bytes: 5128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;

//while(c){
//    total += c%10;
//    c/=10;
//}

int main() {
    int n; cin >> n;
    vector<string> a;
    for(int i = 0;i < n;i++){
        string b; cin >> b;
        a.push_back(b);
    }
    sort(a.begin(),a.end());
    a.erase(unique(a.begin(),a.end()),a.end());
    if(a.size() == 3){
        cout << "Three";
    }else{
        cout << "Four";
    }
}




Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(){
	
	int a[4],b[4];
	int hit,blow;
	
	while (scanf("%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3])!=EOF) {
		hit=0;
		blow=0;
		for (int i=0; i<4; i++) {
			if (a[i]==b[i]) {
				hit++;
			}
			else if(a[0]==b[i]||a[1]==b[i]||a[2]==b[i]||a[3]==b[i]){
				blow++;
			}
		}
		printf("%d %d\n",hit,blow);
	}
	return 0;
}
 

Measured memory_bytes: 0
//AtCoder - Flip, Flip and Flip - Regular 091
#include <bits/stdc++.h>
using namespace std;

int main() {
    int64_t n, m;

    cin >> n >> m;

    if (n == 1 && m == 1) {
        cout << 1 << endl;
        return 0;
    }

    if (n == 1 || m == 1) {
        cout << (n * m) - 2 << endl;
    } else {
        cout << (n * m) - (4 + (n - 2) * 2 + (m - 2) * 2);
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static String[] a;
	static String[] b;
	static String temp;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		a = scanner.nextLine().split(" ");
		b = scanner.nextLine().split(" ");
		char[] c = { 'E', 'E', 'E', 'N', 'W', 'W', 'W', 'S' };
		
		boolean flag = false;
		for(int i=0;i<3;i++){
			for(char d:c){
				roll(d);
				if(Arrays.equals(a, b)){
					flag=true;
					break;
				}
			}
		}
		if(flag)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

	public static void roll(char c) {
		switch (c) {
		case 'E':
			temp = a[0];
			a[0] = a[3];
			a[3] = a[5];
			a[5] = a[2];
			a[2] = temp;
			break;
		case 'N':
			temp = a[0];
			a[0] = a[1];
			a[1] = a[5];
			a[5] = a[4];
			a[4] = temp;
			break;
		case 'W':
			temp = a[0];
			a[0] = a[2];
			a[2] = a[5];
			a[5] = a[3];
			a[3] = temp;
			break;
		default:
			temp = a[0];
			a[0] = a[4];
			a[4] = a[5];
			a[5] = a[1];
			a[1] = temp;
			break;
		}
	}

}


Measured memory_bytes: 26292
#include<bits/stdc++.h>
using namespace std;
int const nax = 5e5 + 10;

const int mod = 1000000007;//
void plusle (int &a, int b) {
    if (( a += b) >= mod ) a -= mod ;
}
void minun (int &a, int b) {
    if ((a -= b) < 0) a += mod ;
}
int add (int a, int b) {
    return (( a += b ) >= mod ) ? a - mod  : a;
}
int sub (int a, int b) {
    return (( a -= b) < 0) ? a + mod : a;
}
int mul (int a, int b) {
    return 1LL * a * b % mod;
}
int power (int a, int b) {
    int res = 1;
    for (; b > 0 ; b >>= 1 , a = mul(a, a))
        if (b & 1) res = mul(res, a);
    return res ;
}




const int Mx = 5e5 + 10;
int fac[Mx], invf[Mx] ;
void prefact () {
    fac[0] = 1 ;
    for (int i = 1 ; i < Mx ; i ++) {
        fac[i] = mul(fac[i - 1], i);
    }
    invf[Mx - 1] = power (fac[Mx - 1] ,  mod - 2 );
    for (int i = Mx - 2 ; i >= 0 ; i --) {
        invf[i] = mul(invf[i + 1], i + 1);
    }
}

int ncr (int N, int R) {
    if (R > N) return 0;
    if (R == 0 || R == N) return 1;
    return mul (fac[N], mul(invf[N - R], invf[R]));
}

int n, m;

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

    int ans1 = 0, ans = 0;

    for (int bar = 0 ; bar <= n ; ++ bar) {
        int calc = mul(ncr(n, bar), ncr(m - bar, n - bar));
        calc = mul(calc, fac[n - bar]);

        if (bar % 2) {
            plusle(ans, calc);
            minun(ans1, calc);
        } else {
            plusle(ans1, calc);
            minun(ans, calc);
        }
    }

    ans1 = mul(ans1, mul(fac[n], ncr(m, n)));
    ans = mul(ans, mul(fac[n], ncr(m, n)));
    printf("%d", ans1);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 7720
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<functional>
using namespace std;
typedef pair<int,int> P;
int main(){
	int n,w,d,p,s;
	while(cin>>n>>w>>d,n||w||d){
		vector<P> tab;
		vector<P>::iterator ite;
		tab.push_back(P(w,d));
		for(int i=0;i<n;i++){
			cin>>p>>s;p--;ite=tab.begin();
			for(int i=0;i<p;i++)ite++;
			P q=*ite;tab.erase(ite);
			s%=(q.first+q.second);
			if(q.first>s){
				if(q.first-s<s){
					tab.push_back(P(q.first-s,q.second));
					tab.push_back(P(s,q.second));
				}else{
					tab.push_back(P(s,q.second));
					tab.push_back(P(q.first-s,q.second));
				}
			}else{
				s-=q.first;
				if(q.second-s<s){
					tab.push_back(P(q.first,q.second-s));
					tab.push_back(P(q.first,s));
				}else{
					tab.push_back(P(q.first,s));
					tab.push_back(P(q.first,q.second-s));
				}
			}
		}
		ite=tab.begin();
		priority_queue<int,vector<int>,greater<int> > que;
		while(ite!=tab.end()){
			que.push((ite->first)*(ite->second));
			ite++;
		}
		cout<<que.top();
		que.pop();
		while(!que.empty()){
			cout<<' '<<que.top();
			que.pop();
		}
		cout<<endl;
	}
	return 0;
}

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


}


Measured memory_bytes: 3612
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int N,K;
    cin >> N >> K;
    int A[N];
    rep(i,N) cin >> A[i];
    rep(i,N) A[i]--;
    pint Sum[N+1]={};
    Sum[0].first=0,Sum[0].second=0;
    rep(i,N){
        Sum[i+1].first=(Sum[i].first+A[i])%K;
        Sum[i+1].second=i+1;
    }
    lint ans=0;
    sort(Sum,Sum+N+1);
    int num=Sum[0].first,count=0;
    int las=0,top=1;
    int begsave=0;
    for(int i=0;i<=N;i++){
        if(Sum[i].first==num) count++,top=Sum[i].second;
        else{
            count=1,num=Sum[i].first;las=Sum[i].second;
            begsave=i;
            continue;
        }
        if(top-las>=K){
            while(top-las>=K){
                count--;
                begsave++;
                las=Sum[begsave].second;
            }
        }
        ans+=count-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5944