akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include <vector>
#define ll long long int
#define ve vector<int>
#define vell vector<ll>
#define pb push_back
#define mod 998244353
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a,b,c,d;cin>>a>>b>>c>>d;
while(a>0&&c>0)
{
	c-=b;
	if(c<=0)
	{
		break;
	}
	a-=d;
	if(a<=0)
	{
		break;
	}
}
if(a<=0)
{
	cout<<"No";
}
else
cout<<"Yes";



}
 

Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  final int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


Measured memory_bytes: 125756
<?php
$n = intval(trim(fgets(STDIN)));

for($i = 1; $i <= $n/2; $i++) {
  $a = $i;
  $b = $n - $a;
  $sum[$i] = array_sum(array_map('intval', str_split($a))) + array_sum(array_map('intval', str_split($b)));
}
echo min($sum)."\n";

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

int main() {
    ll Q;
    cin >> Q;
    ll type, a, b, n, mn = 0;
    multiset<ll> l, r;
    auto resize = [&]() {
        if (ll(l.size()) - ll(r.size()) > 1) {
            auto mv = --l.end();
            r.insert(*mv);
            l.erase(mv);
        } else if (ll(r.size()) - ll(l.size()) > 0) {
            auto mv = r.begin();
            l.insert(*mv);
            r.erase(mv);
        }
    };
    auto insert = [&](ll a) {
        if (l.size() == 0 || a <= *l.rbegin()) {
            l.insert(a);
        } else {
            r.insert(a);
        }
        resize();
    };
    rep(q, Q) {
        cin >> type;
        if (type == 1) {
            cin >> a >> b;
            n++;
            insert(a);
            if (n % 2 == 0) {
                if (a <= *l.rbegin())
                    mn += *r.begin() - a + b;
                else
                    mn += a - *l.rbegin() + b;
            } else {
                mn += abs(*l.rbegin() - a) + b;
            }
        } else if (type == 2) {
            cout << *l.rbegin() << ' ' << mn << '\n';
        }
    }
    cout << flush;
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
int main() {
	long long int a=0,b=0,c=0,d=0,n=0,ans=0,count=0,h,w ,up,down,end=0,idx,m,kuso;
	string s;
	vector<long long int> x;
	vector<long long int>::iterator position;
	bool q=false;
	cin >> h>>n;
	for (int i = 0; i < n; i++){
		cin >> a;
		ans += a;
	}
	if (h <= ans)cout << "Yes";
	else cout << "No" << endl;
	
	
	
	
}

Measured memory_bytes: 256
n=int(input())
a=list(input())
b=list(input())
c=list(input())
ans=0
for i in range(n):
  if a[i] == b[i] and a[i] == c[i] and b[i] == c[i]:
    ans+=0
  elif a[i] != b[i] and a[i] == c[i] and b[i] == c[i]:
    ans+=1
  elif a[i] == b[i] and a[i] != c[i] and b[i] == c[i]:
    ans+=1
  elif a[i] == b[i] and a[i] == c[i] and b[i] != c[i]:
    ans+=1
  elif a[i] != b[i] and a[i] == c[i] and b[i] != c[i]:
    ans+=1
  elif a[i] == b[i] and a[i] != c[i] and b[i] != c[i]:
    ans+=1
  elif a[i] != b[i] and a[i] != c[i] and b[i] == c[i]:
    ans+=1
  elif a[i] != b[i] and a[i] != c[i] and b[i] != c[i]:
    ans+=2
print(str(ans))

Measured memory_bytes: 3064
//=======================================
// abc143d
//
//  2019/10/19
//=======================================

#include <bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[])
{
	cin.tie(0);
  ios::sync_with_stdio(false);

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

  sort(v.begin(), v.end());


  int cnt=0;
  for(int i=0; i<n-2; ++i)  
  {
    for(int j=i+1; j<n-1; ++j)
    {
      for(int k=j+1; k<n; ++k)
      {
        if(v[i]<(v[j]+v[k]))
        {
          if(v[j]<(v[i]+v[k]))
          {
            if(v[k]<(v[i]+v[j]))
            {
              cnt++;
            }
            else break;
          }
          else break;
        }
        else break;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}

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

int N;
int A[100];
int max_=0;

void solve()
{
    for(int j=0;j<N;j++)
    {
        for(int k=j+1;k<N;k++)
        {
            if(abs(A[j]-A[k])>max_)
            {
                max_ = abs(A[j]-A[k]);
            }
        }
    }
}
int main()
{
    cin >> N;
    for(int i=0;i<N;i++)
    {
        cin >> A[i];
    }
    solve();
    cout << max_ << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
   int x,n,sum,i,j,k; 
    while(1){
        int count=0;     
        scanf("%d %d",&n,&x);
        if(n==0&&x==0){
            break;
        }
    
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                sum=i+j+k;
                
               if(i<j&&j<k&&x==sum){
               count++;  
                
               }  
                }
        }
    }
    printf("%d\n",count);
    }
    
    return 0;
    
}



Measured memory_bytes: 2024
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0: break
    cnt = 0

    for i in range(1,a+1):
        for j in range(i+1,a+1):
            for k in range(j+1,a+1):
                if i + j + k == b:
                    cnt += 1
    print(cnt)



Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool chaek[50][50];
int A[50],B[50];
int N,M;
bool visited[50];
void roop(int i){
    visited[i] = true;
    for(int a = 0;a < N;a++){
        if(chaek[i][a] == false)continue;
        if(visited[a] == true)continue;
        roop(a);
    }
}
int main(){
    cin >> N >> M;
    int ans = 0;
    for(int a = 0;a < M;a++){
        int c,d;
        cin >> c >> d;
        chaek[c-1][d-1] = true;
        chaek[d-1][c-1] = true;
        A[a] = c-1;
        B[a] = d-1;
    }
    for(int i = 0;i < M;i++){
        chaek[A[i]][B[i]] = chaek[B[i]][A[i]] = false;
        for(int s = 0;s < N;s++)visited[s] = false;
        roop(0);
        bool bridge = false;
        for(int s = 0;s < N;s++)if(visited[s]==false)bridge = true;
        if(bridge)ans++;
        chaek[A[i]][B[i]] = chaek[B[i]][A[i]] = true;
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

rl = [0, N-1]
rl_condition = ["",""]
flag = True

for i, RL in enumerate(rl):
   print(RL)
   print("\n")
   s = input()
   rl_condition[i] = s
   if s == "Vacant":
      flag = False
      break

while flag:
   center = (rl[0] + rl[1])//2
   print(center)
   print("\n")
   s = input()
   if s == "Vacant":
      break
   elif ((center - rl[0])%2 == 1) and (s == rl_condition[0]):
      rl_condition[1] = s
      rl[1] = center
      continue
   elif ((rl[1] - center)%2 == 1) and (s == rl_condition[1]):
      rl_condition[0] = s
      rl[0] = center
      continue
   elif ((center - rl[0])%2 == 0) and (s != rl_condition[0]):
      rl_condition[1] = s
      rl[1] = center
      continue
   elif ((rl[1] - center)%2 == 0) and (s != rl_condition[1]):
      rl_condition[0] = s
      rl[0] = center
      continue
      
      


Measured memory_bytes: 3660
#include <stdio.h>

int main(void)
{
	int a, b, c;

	while (~scanf("%d%d%d", &a, &b, &c)){
		int card[11] = {0};
		card[a] = card[b] = card[c] = 1;
		for (c = 1; c <= 20 - (a + b); *card += !card[c++]);
		puts(*card < 4 ? "NO" : "YES");
	}
	return (0);
}

Measured memory_bytes: 580
n, m = gets.split.map(&:to_i)
products_vote = (gets.split.map(&:to_i)).sort.reverse
products_vote_sum = products_vote.sum
count = 0

border =  products_vote_sum * (1.0 / (4.0 * m))
(0..n-1).each { |product|
  if border <= products_vote[product]
    count += 1
  end
#  print border, " ",products_vote[product],"\n"
}

if count >= m
  puts "Yes"
else
  puts "No"
end  


Measured memory_bytes: 14320
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int a = sc.nextInt();
	    String s = sc.next();
	    
	    if (a >= 3200) {
	    	System.out.println(s);
	    } else {
	    	System.out.println("red");
	    }
	}	
}	

Measured memory_bytes: 20948
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b;
    cin >> a >> b;
    if(a*b == 2) cout << 3 << endl;
    if(a*b == 3) cout << 2 << endl;
    if(a*b == 6) cout << 1 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll a,b;
    
    cin >> a >> b;
    cout << a - 1 + min(ll(1), b / a) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] h = new int[n];
		Arrays.setAll(h, i -> sc.nextInt());
		
		long[] dp = new long[n];
		dp[0] = 0;
		dp[1] = Math.abs(h[0] - h[1]);
		for (int i = 2; i < n; i++) {
			long min = Long.MAX_VALUE;
			for (int j = 1; j <= k; j++) {
				if (i - j < 0) break;
				min = Math.min(min, dp[i - j] + Math.abs(h[i - j] - h[i]));
			}
			dp[i] = min;
		}
		
//		System.out.println(Arrays.toString(dp));
		
		System.out.println(dp[n - 1]);
 		
		sc.close();
	}
}



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

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			var inputs = Console.ReadLine().Split(' ').Select(input => int.Parse(input)).ToArray();
			var n = inputs[0];
			var x = inputs[1];
			var xs = Console.ReadLine().Split(' ').Select(input => int.Parse(input)).ToArray();

			var intervals = xs
				.Select(item => x - item)
				.Select(item => Math.Abs(item))
				.ToArray();

			var gcd = intervals[0];
			foreach (var interval in intervals)
			{
				gcd = euclidean(gcd, interval);
			}
			Console.WriteLine(gcd);

			return;
		}

		private static int euclidean(int a, int b)
		{
			var m = a > b ? a : b;
			var n = a < b ? a : b;
			return euclideanCore(m, n);
		}

		private static int euclideanCore(int m, int n)
		{
			if (n == 0)
			{
				return m;
			}
			return euclideanCore(n, m % n);
		}
	}

}


Measured memory_bytes: 21088
def bubble!(arr)
  has_unordered = true
  count = 0

  while has_unordered
    has_unordered = false

    for i in (1..(arr.length-1)).to_a.reverse
      if (x=arr[i]) < arr[i-1]
        arr[i] = arr[i-1]
        arr[i-1] = x
        has_unordered = true
        count += 1
      end
    end
  end

  [arr, count]
end

gets
xs=gets.split.map(&:to_i)

result, count = bubble!(xs)

puts result.join(" ")
p count



Measured memory_bytes: 6984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9 + 7;
const int INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    int n;cin>>n;
    string str;cin>>str;
    rep(i,str.size()){
        if(str[i]+n<='Z'){
            str[i]+=n;
            cout<<str[i];
        }else{
            str[i]=str[i]+n-'Z'+'A'-1;
            cout<<str[i];
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n,i;
    long a[3]={2,1};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        a[2]=a[0]+a[1];
        a[0]=a[1];
        a[1]=a[2];
    }
    printf("%ld",a[0]);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    bool flag = 0;
    if (v <= w) flag = 0;
    else {
        if (abs(b-a) <= t * (v - w)) flag = 1;
    }
    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


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


int main() {
	int n, m;
	cin >> n >> m;
	vector<string> a(n);
	vector<string> b(m);

	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < m; i++) cin >> b[i];

	for (int i = 0; i < n - m + 1; i++) {
		for (int j = 0; j < n - m + 1; j++) {
			bool flag = true;
			for (int k = 0; k < m; k++) {
				if (a[i+k].substr(j, m) != b[k]) flag = false;
			}

			if (flag) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int k, x;
    cin >> k >> x;
    if(k*500 >= x) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int d,p,w,l;
    cin>>d>>p;
    string s[d];
    w=d+2;
    l=p+2;
    for(int i=0;i<d;i++)
        cin>>s[i];
    for(int i=0;i<l;i++)
        cout<<'#';
    cout<<endl;
    for(int i=0;i<d;i++)
        cout<<'#'<<s[i]<<'#'<<endl;

    for(int i=0;i<l;i++)
        cout<<'#';
        cout<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    int N;
    cin >> N;

    int X = N * 100 / 108;
    while (int(X * 1.08) <= N) {
        if (int(X * 1.08) == N) {
            cout << X << endl;
            exit(0);
        } else {
            X++;
        }
    }
    cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	c1, c2, c3 := readBytes(), readBytes(), readBytes()

	fmt.Println(string(c1[0]) + string(c2[1]) + string(c3[2]))
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s;
    cin >> s;
    auto x1 = 0;
    auto x2 = 0;
    for(unsigned int i = 0; i < s.size(); ++i){
        int j = s[i] - '0';
        if(j != (static_cast<int>(i) % 2)){
            x1++;
        }
        if(j != ((static_cast<int>(i) + 1)% 2)){
            x2++;
        }
    }
    cout << min(x1, x2);
    return 0;
}

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

const int maxN = 202, maxM = 4e4+5, oo = 0x3f3f3f3f;
  
struct edge{
  int next, v, rsd;
  edge (int a=0,int b=0,int c=0)
    :next(a), v(b), rsd(c) {}
};

int n;
int head[maxN], totE;
edge E[maxM];

void addedge(int u,int v,int flow) {
  E[++totE] = edge(head[u], v, flow); head[u] = totE;
  E[++totE] = edge(head[v], u,    0); head[v] = totE;
}

int s, t;
int cur[maxN], d[maxN];

bool bfs() {
  static int inq[maxN], now;
  static int q[maxN], front, rear;
  inq[q[rear = 1] = s] = ++now; front = 0;
  while(front != rear) {
    if(++front == maxN) front = 0;
    int u = q[front];
    for(int e = head[u], v; e; e = E[e].next) {
      if(inq[v = E[e].v] == now || E[e].rsd <= 0) continue;
      d[v] = d[u] + 1; inq[v] = now;
      if(++rear == maxN) rear = 0;
      q[rear] = v;
    }
  }
  return inq[t] == now;
}

int dfs(int u,int a) {
  if(u == t || a == 0) return a;
  int flow = 0, f;
  for(int &e = cur[u], v; e; e = E[e].next) 
    if(d[v = E[e].v] == d[u]+1 && (f = dfs(v, std::min(E[e].rsd, a)))) {
      flow += f; E[e].rsd -= f;
      E[e^1].rsd += f; a -= f;
      if(!a) break;
    }
  return flow;
}
  
int maxflow() {
  int flow = 0;
  for(; bfs(); flow += dfs(s, oo)) {
    for(int i = 0;i <= n; ++i)
      cur[i] = head[i];
  }
  return flow;
}

int H, W;
char buf[105];

int main() {
  if(fopen("input.txt","r")) {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  }

  scanf("%d%d", &H, &W);
  n = H + W; totE = 1;
  for(int i = 1;i <= H; ++i) {
    scanf("%s", buf + 1);
    for(int j = 1;j <= W; ++j) {
      if(buf[j] == 'o') addedge(i, j + H, 1), addedge(j + H, i, 1);
      else if(buf[j] == 'S') s = i, addedge(i, j + H, oo), addedge(j + H, i, oo);
      else if(buf[j] == 'T') t = j + H, addedge(i, j + H, oo), addedge(j + H, i, oo);
    }
  }

  int flow = maxflow();
  printf("%d", flow >= oo ? -1: flow);
  
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define lb(x) ((x)&(-(x)))
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define dalao 998244353
#define inf 0x3f3f3f3f
#define N 100010
using namespace std;
typedef long long ll;
int n,m,K,x,y,fac[N<<2]={1},inv[N<<2],l[N],r[N],ans;
char a[N],b[N],c[N],d[N],s[N];
inline int poww(int a,int b){int r=1;for(;b;b>>=1,a=1ll*a*a%dalao)if(b&1)r=1ll*r*a%dalao;return r;}
inline int C(int a,int b){return a<b||b<0?0:1ll*fac[a]*inv[b]%dalao*inv[a-b]%dalao;}
inline void upd(int& a,int b){a=a+b>=dalao?a+b-dalao:a+b;}
int main(){
	scanf("%d%d%s%s%s%s",&n,&m,a+1,b+1,c+1,d+1),K=max(n,m);
	for(int i=1;i<=(K<<2);i++)fac[i]=1ll*fac[i-1]*i%dalao;
	inv[K<<2]=poww(fac[K<<2],dalao-2);
	for(int i=(K<<2)-1;~i;i--)inv[i]=1ll*inv[i+1]*(i+1)%dalao;
	for(int i=1;i<=n;i++)ans+=a[i]+b[i]-96;
	for(int i=1;i<=m;i++)ans+=c[i]+d[i]-96;
	if(!ans)return puts("1"),0;
	ans=0;
//	---------------------------------------------
	K=0;
	for(int i=1;i<=m;i++)if(d[i]-48+c[i]-48>0)s[++K]=d[i]-48+c[i]-48;
	for(int i=1;i<=n;i++)x+=a[i]-48;
	for(int i=1;i<=K;i++){
		if(x==0&&y==0)l[i]=1;
		else if(x)l[i]=C(x+y-1,x-1);
//		cout<<i<<" "<<l[i]<<" "<<x<<" "<<y<<endl;
		y+=s[i];
	}
	x=y=0;
	for(int i=1;i<=n;i++)x+=b[i]-48;
	for(int i=K;i;i--){
		if(x==0&&y==0)r[i]=1;
		else if(x)r[i]=C(x+y-1,x-1);
		y+=s[i];
	}
	x=0;
	for(int i=1;i<=K;i++){
		upd(x,l[i]);
		if(s[i]==2)upd(x,x);
		upd(ans,1ll*r[i]*x%dalao);
	}
//	---------------------------------------------
	K=x=y=0;
	for(int i=1;i<=n;i++)if(a[i]-48+b[i]-48>0)s[++K]=a[i]-48+b[i]-48;
	for(int i=1;i<=m;i++)x+=c[i]-48;
	for(int i=1;i<=K;i++){
		if(x==0&&y==0)l[i]=1;
		else if(x)l[i]=C(x+y-1,x-1);
		else l[i]=0;
//		cout<<i<<" "<<l[i]<<" "<<x<<" "<<y<<endl;
		y+=s[i];
	}
	x=y=0;
	for(int i=1;i<=m;i++)x+=d[i]-48;
	for(int i=K;i;i--){
		if(x==0&&y==0)r[i]=1;
		else if(x)r[i]=C(x+y-1,x-1);
		else r[i]=0;
		y+=s[i];
	}
	x=0;
	for(int i=1;i<=K;i++){
		upd(x,l[i]);
		if(s[i]==2)upd(x,x);
		upd(ans,1ll*r[i]*x%dalao);
	}
//	---------------------------------------------
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4608
import Data.Bits
import Data.List
import Data.Foldable(foldlM)
import Data.Maybe(fromJust)
import Control.Monad
import Data.Array as A ((!),accumArray)
import Data.Graph
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Char8 as BS
import Debug.Trace

toTuple :: [a] -> (a,a)
toTuple (x:y:_) = (x,y)
toTuple _ = undefined

getInt :: IO Int
getInt = fst . fromJust. BS.readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile (== ' ')) <$> BS.getLine

getLineB :: (Read a) => IO [a] --直接入力
getLineB = map (read.BS.unpack) . BS.words <$> BS.getLine

--solve :: Int -> V.Vector Int -> IO ()
--solve q vec = do

main :: IO ()
main = do
  [m,d] <- getIntList
  ans <- fmap sum $ forM [4..m] $ \m -> do
    fmap sum $ forM [22..d] $ \i -> do
      let d1 = i `mod` 10
          d10 = i `div` 10
      if d1 < 2 || d10 < 2 then return 0
        else if d1*d10 == m then return 1
          else return 0
  print (ans :: Int)


Measured memory_bytes: 636
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int n,k;
		cin>>n>>k;
		vi v(n);
		for(ll int i=0;i<n;i++) cin>>v[i];
		sort(all(v));
		ll int ans=0;
		for(ll int i=0;i+k<n;i++) ans+=v[i];
		cout<<ans;	
	}
	return 0;
}

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

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define FOR(i,l,r) for(long long i=l; i<r; i++)
#define FOR_REV(i,r,l) for(long long i=r; i>=l; i--)
#define pb push_back
#define mp make_pair

int main()
{
    string s,t,u;
    int a,b;

    cin>>s>>t;
    cin>>a>>b;
    cin>>u;

    if (u.compare(s) == 0)
    {
        cout<<a-1<<" "<<b<<endl;
    }
    else
    {
        cout<<a<<" "<<b-1<<endl;   
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int binarySearch(int *A,int key);

int cnt;
int n,q;

int main(){
  int s[100000],t[50000];
  int i,j;
  //in
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&s[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++)
    scanf("%d",&t[i]);

  //roop
  for(j=0;j<q;j++){
    if(binarySearch(s,t[j])!=0)cnt++;
  }
  //out
  printf("%d\n",cnt);
  return 0;
}
//func
int binarySearch(int *A,int key){
  int left,right,mid;
  int hit;
  
  left = 0;
  right = n;
  while (left < right){
    hit=0;
    mid = (left + right)/2;
    if (key == A[mid]){
      hit=1;
      return 1;
    }
    if (key > A[mid])
      left = mid + 1;
    else if (key < A[mid])
      right = mid;
  }
  return 0;
}



Measured memory_bytes: 2344
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main()
{
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  int N;
  if(S=="RRR") N = 3;
  else if(S=="SSS") N = 0;
  else if(S=="RRS"||S=="SRR") N = 2;
  else N = 1;
  cout << N << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <inttypes.h>

int main(void)
{
    uint_fast8_t a, b;
    scanf("%" SCNuFAST8 " %" SCNuFAST8, &a, &b);
    if (a == 1) {
        a = 14;
    }
    if (b == 1) {
        b = 14;
    }
    if (a > b) {
        puts("Alice");
    } else if (a < b) {
        puts("Bob");
    } else {
        puts("Draw");
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

#define WIDTH 10
#define HEIGHT 10

int field[ WIDTH + 4 ][ HEIGHT + 4 ] = {};
const int dx[ 3 ][ 4 ] = { { -1, 0, 1, 0 }, { -1, 1, -1, 1 }, { -2, 0, 2, 0 } };
const int dy[ 3 ][ 4 ] = { { 0, -1, 0, 1 }, { -1, -1, 1, 1 }, { 0, -2, 0, 2 } };

int main( void ) {
	int i, x, y, size, white, max;

	while ( scanf( "%d,%d,%d", &x, &y, &size ) == 3 ) {
		x += 2;
		y += 2;

		field[ x ][ y ]++;

		while ( size-- )
			for ( i = 4; i--; field[ x + dx[ size ][ i ] ][ y + dy[ size ][ i ] ]++ ) ;
	}

	white = max = 0;
	for ( y = HEIGHT + 2; y-- > 2;  )
		for ( x = WIDTH + 2; x-- > 2; white += !field[ x ][ y ] )
			if ( max < field[ x ][ y ] )
				max = field[ x ][ y ];

	printf( "%d\n%d\n", white, max );

	return 0;
}

Measured memory_bytes: 600
from itertools import accumulate
from bisect import bisect_right
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
accumA = [0]+list(accumulate(A))
accumB = [0]+list(accumulate(B))
#Aをi冊読むとき、Bは何冊よめるか、を調べる
ans = 0
for i in range(N+1):
    cnt = i
    a = accumA[i]
    rest = K-a
    if rest > 0:
        j = bisect_right(accumB,rest)-1
        cnt += j
    if rest < 0:
        continue
    else:
        ans = max(ans,cnt)

print(ans)


Measured memory_bytes: 135156
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    string s; cin >> s;
    string ans = s=="ABC" ? "ARC":"ABC";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cmath>

int N;

int dheight(int cx, int cy, int x, int y) {
  return std::abs(x - cx) + std::abs(y - cy);
}

int height(int cx, int cy, int ch, int x, int y) {
  int ret = ch - dheight(cx, cy, x, y);
  return (ret > 0) ? ret : 0;
}

int check(int cx, int cy, int xs[], int ys[], int hs[]) {
  int ch;
  for (int i = 0; i < N; ++i) {
    if (hs[i] > 0) {
      ch = hs[i] + dheight(cx, cy, xs[i], ys[i]);
      break;
    }
  }
  if (ch < 1) {
    return -1;
  }

  bool flag = true;
  for (int i = 0; i < N; ++i) {
    if (hs[i] != height(cx, cy, ch, xs[i], ys[i])) {
      flag = false;
      break;
    }
  }
  return flag ? ch : -1;
}

int main() {
  std::cin >> N;

  int xs[N], ys[N], hs[N];
  for (int i = 0; i < N; ++i) {
    std::cin >> xs[i] >> ys[i] >> hs[i];
  }

  for (int cx = 0; cx <= 100; ++cx) {
    for (int cy = 0; cy <= 100; ++cy) {
      int ch = check(cx, cy, xs, ys, hs);
      if (ch >= 0) {
        std::cout << cx << " " << cy << " " << ch << std::endl;
        break;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>

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

using namespace std;

typedef long long ll;

int A, B;

int main() {
    cin >> A >> B;
    int result = 0;
    REP(i, 2) {
        if (A < B) {
            result += B;
            B--;
        } else {
            result += A;
            A--;
        }
    }
    cout << result << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

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

Measured memory_bytes: 1152
# -*- coding:utf-8 -*-
import sys

def solve():
    S = input()
    for i in range(len(S)):
        if (i+1)%2 == 0:
            # 偶数
            if S[i] in ("L", "U", "D"):
                continue
            else:
                print("No")
                return
        else:
            # 奇数
            if S[i] in ("R", "U", "D"):
                continue
            else:
                print("No")
                return
    print("Yes")


if __name__ == "__main__":
    solve()


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

using namespace std;
int main(int argc, char const *argv[])
{
	//freopen("in.txt", "r", stdin);
	int m, n;
	cin >> m >> n;
	if(m <= n) cout << m << endl;
	else cout << m-1 << endl;
	return 0;
}

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

int main() {
  int n;
  int ans = 0;
  cin >> n;
  vector<int> a(n);
  rep(i ,n){
    cin >> a[i];
  }
  rep(i ,n -2){
    if((a[i] < a[i + 1] && a[i + 1] < a[i + 2]) || (a[i] > a[i + 1] && a[i + 1] > a[i + 2])){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define lli long long int
#define llu unsigned long long int
#define fr(va, beg, end) for (lli va = beg; va < end; va++)
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

void solve() {
    lli n, a, b, c, k;
    cin >> a >> b >> c >> k;
    lli sum = 0;
    if (a >= k) {
        sum += k;
        a -= k;
        cout << sum << endl;
        return;
    } else {
        sum += a;
        k -= a;
    }
    k -= b;
    if (k <= 0) {
        cout << sum << endl;
        return;
    }

    sum -= k;
    cout << sum << endl;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

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

long long int nikou(long long int x){
    return x*(x-1)/2;
};

int main(){
    int n;
    cin >> n;
    map<int,int> mp;
    long long int sum=0;
    int a[n];

    for(int i=0; i<n; i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    for(int i=0; i<n+1; i++){
        sum+=nikou(mp[i]);
    }

    for(int k=0; k<n; k++){
        cout << sum-nikou(mp[a[k]])+nikou(mp[a[k]]-1) << endl;
    }

    return 0;
}

Measured memory_bytes: 12800
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

bool dfs(int N, int M, vector< vector<bool> >& adj, vector<int>& a, vector<int>& b, int i, vector<bool>& vis) {
	vis[i] = true;
	for (int j = 0; j < M; j++) {
		if (!adj[i][j] || a[i] == j) continue;
		if (b[j] == -1) {
			b[j] = i;
			a[i] = j;
			return true;
		}
		for (int _i = 0; _i < N; _i++) {
			if (!adj[_i][j] || b[j] != _i || vis[_i]) continue;
			if (dfs(N, M, adj, a, b, _i, vis)) {
				b[j] = i;
				a[i] = j;
				return true;
			}
		}
	}
	return false;
}

int match(int N, int M, vector< vector<bool> >& adj) {
	vector<int> a(N, -1), b(M, -1);
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (a[i] != -1) continue;
		vector<bool> vis(N);
		if (dfs(N, M, adj, a, b, i, vis))
			cnt++;
	}
	return cnt;
}

int main() {
	for (;;) {
		int N, M; cin >> N >> M;
		if (N == 0) break;
		vector<int> x(N), y(N), v(N);
		for (int i = 0; i < N; i++)
			cin >> x[i] >> y[i] >> v[i];
		vector<int> X(M), Y(M);
		for (int j = 0; j < M; j++)
			cin >> X[j] >> Y[j];
		double lb = 0, ub = 20000;
		for (int t = 0; t < 100; t++) {
			double mid = (lb + ub) / 2;
			vector< vector<bool> > adj(N, vector<bool>(M));
			for (int i = 0; i < N; i++)
				for (int j = 0; j < M; j++) {
					double dx = X[j] - x[i], dy = Y[j] - y[i];
					adj[i][j] = (sqrt(dx * dx + dy * dy) <= mid * v[i]);
				}
			if (match(N, M, adj) == M) ub = mid;
			else lb = mid;
		}
		printf("%.10f\n", lb);
	}
}

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

void dfs(vector<vector<int>> &result, int &ans){
    bool flag = false;
    int n = result.size();
    bool loope = false;
    for (int i = 0; i < n; i++){
        int win = 0; int lose = 0;
        for (int j = 0; j < n; j++){
            if (i == j) continue;
            if (result[i][j] == 0){
                if (win < n / 2){
                    result[i][j] = 1;
                    result[j][i] = 2;
                    dfs(result, ans);
                    result[i][j] = 0;
                    result[j][i] = 0;
                }
                if (lose < n / 2){
                    result[i][j] = 2;
                    result[j][i] = 1;
                    dfs(result, ans);
                    result[i][j] = 0;
                    result[j][i] = 0;
                }
                flag = true;
                loope = true;
                break;
            }
            else if (result[i][j] == 1) win++;
            else if (result[i][j] == 2) lose++;
        }
        if (loope) break;
    }

    if (!flag){
        bool ok = true;
        int win = n / 2; int lose = n / 2;
        for (int i = 0; i < n; i++){
            if (win != n / 2 || lose != n / 2){
                ok = false;
                break;
            }
            win = 0; lose = 0;
            for (int j = 0; j < n; j++){
                if (result[i][j] == 1) win++;
                if (result[i][j] == 2) lose++;
            }
        }
        if (win != n / 2 || lose != n / 2) ok = false;
        if (ok) ans++;
    }
}

int main(){
    while (1){
        int n;
        cin >> n;
        if (!n) break;
        vector<vector<int>> result(n, vector<int>(n, 0));
        for (int i = 0; i < n; i++) result[i][i] = -1;
        int m;
        cin >> m;
        for (int i = 0; i < m; i++){
            int x, y;
            cin >> x >> y;
            x--; y--;
            result[x][y] = 1;
            result[y][x] = 2;
        }
        int ans = 0;
        dfs(result, ans);
        cout << ans << endl;
    }
}


Measured memory_bytes: 3148
# for #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion
class union_find:
    def __init__(self, n):
        self.n = n
        self.rank = [0]*n
        self.parent = [int(j) for j in range(n)]
    
    def union(self,i,j):
        i = self.find(i)
        j = self.find(j)
        if self.rank[i] == self.rank[j]:
            self.parent[i] = j
            self.rank[j] += 1

        elif self.rank[i] > self.rank[j]:
            self.parent[j] = i
        else:
            self.parent[i] = j

    def find(self, i):
        temp = i
        if self.parent[temp] != temp:
            self.parent[temp] = self.find(self.parent[temp])
        return self.parent[temp]
from math import log2, ceil
from collections import deque, Counter as CC
def main():
# Enter your code here. Read input from STDIN. Print output to STDOUT
    # for t in range(int(input())):
        
        n = int(input())
        # n,x,t = [int(j) for j in input().split()]
# )
        l = [int(j) for j in input().split()]
        tmp = l[0]
        ans = 0
        for i in range(1,n):
            if(l[i]<tmp):
                ans+=tmp-l[i]
            else:
                tmp = l[i]
        print(ans)



        # b = [int(j) for j in input().split()]

            # s = n-1

        # s = input()




        # a = list(a)
        # print(a)
        # for i in a:



        



if __name__ == "__main__":
    main()

Measured memory_bytes: 104764
s = input()
n = int(s)
m = len(s)
ans = 0
i = 1
while(True):
    if i == m:
        ans += n - 10 ** (i - 1) + 1
        break
    elif i > m:
        break
    ans += 9 * 10 ** (i - 1)
    i += 2
print(ans)


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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vi primes;
	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}



set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}


// int power(int x, unsigned int y, int p)
// {
// 	int res = 1;     // Initialize result

// 	x = x % p; // Update x if it is more than or
// 	// equal to p

// 	if (x == 0) return 0; // In case x is divisible by p;

// 	while (y > 0)
// 	{
// 		// If y is odd, multiply x with result
// 		if (y & 1)
// 			res = (res * x) % p;

// 		// y must be even now
// 		y = y >> 1; // y = y/2
// 		x = (x * x) % p;
// 	}
// 	return res;
// }
// Graph------------------------------------------------------------------------


int32_t main()
{
	FIO;
	// c_p_c();
// --------------------------------------------------

	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (a >= k)
	{
		cout << k << endl;
	}
	else if ((a + b) >= k)
	{
		cout << a << endl;
	}
	else
	{
		int left = k - (a + b);
		cout << a - left << endl;
	}

}





Measured memory_bytes: 3672
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc127/tasks/abc127_d
# わからん... データ構造で殴ります...
# いや、書き換えるっていうのは追加するっていうのと同じ意味じゃない？
# カードの枚数が多いから追加するのも大変→カードの枚数で管理しよう
N, M = read_ints()
A = read_ints()
A_cnt = Counter(A)
for _ in ra(M):
    b, c = read_ints()
    A_cnt[c] += b

tmp = list(A_cnt.items())
tmp.sort(key=lambda x: x[0], reverse=True)

ans = 0
cnt = 0
for k, v in tmp:
    while v > 0 and cnt < N:
        ans += k
        v -= 1
        cnt += 1
    if cnt == N:
        break


print(ans)


Measured memory_bytes: 44292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

int n, m, k;

bool solve(){
    for(int i=0; i<=n; i++) for(int j=0; j<=m; j++) if(j*n+i*m-2*i*j==k) return true;
    return false;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m>>k;
    cout<<(solve() ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256