akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<algorithm>
int main()
{
	char x[4];
	scanf("%s", x);
	int ans = 0;
	for (int i = 0; i < 4; i++)
	{
		if (x[i] == '+')
			ans++;
		else
			ans--;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int n, y; cin >> n >> y;
    int rel10000 = -1, rel5000 = -1, rel1000 = -1;
    rep(i, n + 1){ //10000
        rep(j, n - i + 1){ //5000
            int k = n - i - j;
            int total = 10000*i + 5000*j + 1000*k;
            if(total == y){
                rel10000 = i;
                rel5000 = j;
                rel1000 = k;
            }

        }
    }
    cout << rel10000 << " " << rel5000 << " " << rel1000;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const int MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1] = {1}, inv[1] = {1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return (c>r||c<0) ? 0:fac[r] * inv[c] % MOD * inv[r - c] % MOD;}


// 맥스세그.
int tree[1<<20];
int szz=1<<19;
int find(int i, int l, int r, int le, int ri) {
    if (l > ri || r < le) return 0;
    if (l <= le && ri <= r) return tree[i];
    return max(find(i*2,l,r,le,(le+ri)/2), find(i*2+1,l,r,(le+ri)/2+1,ri));
}
void upd(int i, int val) {
    i += szz;
    tree[i] = max(tree[i], val);
    while (i/=2) tree[i] = max(tree[i*2], tree[i*2+1]);
}

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

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int t;
        scanf("%d", &t);
        int le = t - k;
        int ri = t + k;
        int tt = find(1, max(0, le), min(ri, 300000), 0, szz - 1) + 1;
        ans = max(ans, tt);
        upd(t, tt);
    }
    printf("%d", ans);
}


// author: rdd6584


Measured memory_bytes: 6200
#include<bits/stdc++.h>
using namespace std;
char inc(int i){
    if(i==0)return '+';
    else return '-';
}
int main(){
    string s;
    cin >> s;
    int a=s[0]-'0';
    int b=s[1]-'0';
    int c=s[2]-'0';
    int d=s[3]-'0';
    int tmp;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){
                tmp=a+b+c+d;
                if(i==1)tmp-=2*b;
                if(j==1)tmp-=2*c;
                if(k==1)tmp-=2*d;
                if(tmp==7){
                    cout << a;
                    cout << inc(i);
                    cout << b;
                    cout << inc(j);
                    cout << c;
                    cout << inc(k);
                    cout << d;
                    cout << "=7";
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 3628
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int a,b;
   cin>>a>>b;
   int d=a/b;
   int r=a%b;
   double f=1.0*a/b;
   printf("%d %d %.5lf\n",d,r,f);
   //while(1);
   return 0;
 }
 

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    ll n, cnt = 1;
    string s;
    cin >> n >> s;
    for (int i = 1; i < n; ++i) {
        if (s[i] == s[i - 1])
            continue;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
	int n;
	cin >> n;
	
	vector< pair<int,int> > res;
	rep(i,n)
	{
		int a,v;
		cin >> a >> v;
		res.push_back(pair<int,int>(v,a));
	}

	sort(res.begin(),res.end(),greater<pair<int,int> >());
	int min_num = 21;
	rep(i,n)
	{
		if(res[0].first == res[i].first)
		{
			min_num = min(min_num,res[i].second);
		}
	}

	cout << min_num << " " << res[0].first << endl;
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, k;
  long long ans = 0;
  cin >> n >> k;
  vector<long long> v(n);
  for (int i = 0; i < n; ++i)  {
    cin >> v[i];
  }
  vector<int> cnt(40, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 40; j++) {
      if ((v[i] >> j) & 1) { //シフトのほうが優先度高いけど、括弧あるほうがきれいな気がする
        cnt[j]++;
      }
    }
  }

  bool underk = false;
  for (long long i = 39; i >= 0; i--) {
    int cnt0 = n - cnt[i];
    int cnt1 = cnt[i];
    //cout << (bool)underk << " " << cnt1 << " " << cnt0 << " " << (1ull << i) << " ";
    if (underk) {
      //既にkを下回っているならば、大きくできる方を取ればいい
      ans += (1ull << i) * max(cnt0, cnt1);
    } else {
      //kのi桁目のbitで分岐する。0なら0にするしかない
      //1なら、0か1を入れることができる。0をいれたら必ず下回るようになる。
      int kbit = k >> i & 1;
      if (kbit == 1) {
        if (cnt1 > cnt0) {
          ans += (1ull << i) * cnt1;
          underk = true;  //ここで0を入れられるのでkを下回ることが確定
        } else {
          ans += (1ull << i) * cnt0; //おとなしくビットを立てる
        }
      } else {
        ans += (1ull << i) * cnt1;//0を入れるしかない
      }
    }
  }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vi w(n);
    vector<ll> v(n);
    REP(i, n)
    {
        cin >> w[i] >> v[i];
    }

    vector<vector<ll>> dp(n + 1, vector<ll>(m + 1));

    FOR(i, 0, n)
    {
        REP(j, m + 1)
        {
            if (j >= w[i])
            {
                dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
            }
            else
            {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }

    cout << dp[n][m] << endl;
}

Measured memory_bytes: 80256
evaluation = []
while True:
    mid, last, re = map(int, input().split(' '))
    if mid == last == re == -1:
        break
    if mid * last < 0 or mid + last < 30:
        evaluation.append('F')
    elif mid + last >= 80:
        evaluation.append('A')
    elif mid + last >= 65:
        evaluation.append('B')
    elif mid + last >= 50 or re >= 50:
        evaluation.append('C')
    else:
        evaluation.append('D')

for grade in evaluation:
    print(grade)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef queue<ll> ql;
typedef set<ll> sl;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll &b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll &b) {if(b > a) {a = b; return 1;} return 0;}
const ll inf = 1LL << 60;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const ll max = 500010;
ll num, M, N, ans=0, count=0;
int main() {
  ll H, W;
  cin >> H >> W;
  if(H==1 || W==1) cout<< 1 << endl;
  else cout << (H*W+1)/2 << endl;
  return 0;
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 10000005;

int n;

int main() {

	FAST;

	cin >> n;
	intt ans = 0;
	for (int i = 1; i <= n; i ++) {
		for (int j = i; j <= n; j += i) {
			ans += j;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>
#define dr 1000000007

int main(){
  int n,i,j,c[60];
  long a[300005],b,m=0;
  for(i=0;i<60;i++){
    c[i]=0;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
    for(j=0;j<60;j++){
      c[j]+=(a[i]>>j)&1;
    }
  }
  for(i=0;i<60;i++){
    m+=(((long)n-c[i])*c[i]%dr)*(((long)1<<i)%dr);
  }
  printf("%ld",m%dr);
  return(0);
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

int countBlack(const vector< vector<char>> &field, const int &yBits, const int &xBits)
{
  int count = 0;
  int x = 0;
  int y = 0;
  for(auto row:field){
    x = 0;
    for(auto val:row){
      if( (yBits&(1<<y))==0 && (xBits&(1<<x))==0 ){
        if(val=='#'){
          count++;
        }
      }
      x++;
    }
    y++;
  }
  return count;
}

signed main() {
  int64_t h,w,k;
  cin >> h >> w >> k;
  
  vector< vector<char>> field(h, vector<char>(w,0));
  char c;
  for(int y=0;y<h;y++){
  	for(int x=0;x<w;x++){
      cin >> c;
      field[y][x] = c;
    }
  }
  
  int count = 0;
  for(int yBits=0;yBits < (1<<h);yBits++){
    for(int xBits=0;xBits < (1<<w);xBits++){
      if(k == countBlack(field,yBits,xBits)){
        count++;
      }
    }
  }
  cout << count << endl;

  return 0;
}




Measured memory_bytes: 3632
#include <iostream>
using namespace std;
 
int main(){
    int n, m, l;
    int i, j, k;
    int A[100][100], B[100][100];
    long  C[100][100]={0};
     
    cin >> n >> m >> l;
     
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            cin >> A[i][j];
        }
    }
     
    for(i = 0; i < m; i++){
        for(j = 0; j < l; j++){
            cin >> B[i][j];
        }
    }
     
    for(i = 0; i < n; i++){
        for(j = 0; j < l; j++){
            for(k = 0; k < m; k++){
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }
     
    for(i = 0; i < n; i++){
        for(j = 0; j < l; j++){
            cout << C[i][j];
            if(j != l - 1){
            cout << " ";
            }
        }
        cout <<endl;
    }
    return 0;
}

Measured memory_bytes: 3248
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a, b, c;
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        int count = 0;
        for(int i = a; i <= b; i++) {
            if(c % i == 0){
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26356
import heapq


def resolve():
    x, y, a, b, c = map(int, input().split())
    p = sorted(list(map(int, input().split())))[-x:]
    q = sorted(list(map(int, input().split())))[-y:]
    r = [-int(x) for x in input().split()]
    heapq.heapify(p)
    heapq.heapify(r)
    for i in q:
        heapq.heappush(p, i)
    ans = 0
    while p and r:
        ans += max(heapq.heappop(p), -heapq.heappop(r))
    ans += sum(p)
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 21608
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
#include "tuple"

#define rep(n) for (int i = 0; i < n; ++i)
#define REP(n,i) for (int i = 0; i < n; ++i)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define P pair<ll, ll>
typedef long long ll;
using namespace std;

int n;
ll cnt;
string s,m,m2;
bool b[18];
map<pair<string,string>,ll>mp;

int main() {
	cin>>n>>s;
	rep(1<<n){
		m="";
		m2="";
		int k=i;
		REP(n,j){
			if(k%2)m+=s[j];
			else m2+=s[j];
			k/=2;
		}
		mp[mkp(m,m2)]++;
	}
	cnt=0;
	rep(1<<n){
		m="";
		m2="";
		int k=i;
		REP(n,j){
			if(k%2)m+=s[2*n-1-j];
			else m2+=s[2*n-1-j];
			k/=2;
		}
		cnt+=mp[mkp(m,m2)];
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 91904
fun main(args: Array<String>) {
    // Your code here!
    var k = readLine()!!.toInt()
    var (a,b) = readLine()!!.split(" ").map{it.toInt()}
    var msg = "NG"
    
    for(i in a..b){
        
        if(i % k == 0){
            msg = "OK"
            break
        }
    }
    
    println(msg)
}


Measured memory_bytes: 36392
# Aizu Problem 0046: Differential
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


heights = [float(line) for line in sys.stdin]
diff = max(heights) - min(heights)
print(diff)

Measured memory_bytes: 7568
fn main() {
    let x: i32 = read();
    if x >= 30 {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 2092
n = int(input())
num = input()
num = num.split(" ")
divs = []

for i in range(n):
    num[i] = int(num[i])
num.sort()

for i in range(1,int(num[0]**(1/2))):
    if num[0]%i == 0:
        divs.append(i)
        divs.append(num[0]//i)
if num[0]%int(num[0]**(1/2)) == 0:
    divs.append(int(num[0]**(1/2)))
divs.sort()

for i in range(len(divs)):
    flag = 1
    for j in range(1,n):
        if num[j]%divs[i] != 0:
            flag = 0
            break
    if flag == 1:
        print(divs[i])


Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    string N;
    cin >> N;
    bool c = N[0] == N[2];
    cout << (c?"Yes" : "No") << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    if(n%10==3)cout << "bon";
    else if(n%10==0||n%10==1||n%10==6||n%10==8) cout << "pon";
    else cout << "hon";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
int main(){
	int n;
	cin>>n;
	ll num=0;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for(int i=n-1;i>=0;i--){
		ll re = (a[i]+num) % b[i];
		if( re != 0 ) num += b[i] - re;
	}
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,b) for(int i=1;i<=b;i++)
#define drep(i,b) for(int i=b;i>=1;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define endl '\n'
#define int long long
#define ls i<<1
#define rs i<<1|1
#define mid (l+r)/2

using namespace std;

const int N=1e5+7;
const int mod=998244353;
int n,m,k,t,x,y,z;
int dis[N],vis[N],cnt[N];

#define pr pair<int,int>
#define ff first
#define ss second

void solve(int sum=0){
    cin>>n>>m>>x>>y;
    int t=x/m,t2=n/y;
    if(x%m) t++;
    if(n%y) t2++;
    if(t<=t2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

#undef int
int main(){
    ios::sync_with_stdio(false);
    //int T;cin>>T;
    //while(T--)
    solve();
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>

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

using P = pair<int,int>;
int n,m;

vector<int> a,b;
int calc(vector<int>& s,vector<int>& t) {
  vector<P> ps;
  rep(i,m){
    ps.push_back(P(b[i]-1,a[i]));
  }

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

  int ret = 0;
  int nowt = 0;
  for (auto p : ps) {
    if (nowt < p.second) {
      ret++;
      nowt = p.first;
    }
  }
  return ret;
}

void solve() {
  int x = calc(a,b);
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  int y = 100000;//calc(a,b);
  cout << min(x,y) << endl;
}

signed main(void) {
  cin >> n >> m;
  a.resize(m);b.resize(m);
  rep(i,m) {
    cin >> a[i] >> b[i];
  }
  solve();
  return 0;
}


Measured memory_bytes: 2168
from collections import Counter
size = int(input())
ary = list(map(int, input().split()))
even, odd = Counter(ary[::2]), Counter(ary[1::2])
even[0], odd[0] = 0, 0
(e, em), (_, es) = even.most_common(2)
(o, om), (_, os) = odd.most_common(2)
print(size - max(em + os, es + om)) if e == o else print(size - em - om)

Measured memory_bytes: 18656
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
int WA[105000];
bool AC[105000];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M; 
    int pn = 0,ac = 0;
    for (int i = 0; i < N; ++i) {
        WA[i] = 0;
        AC[i] = false;
    }
    while (M--) {
        int p; string s;
        cin >> p >> s;
        if (AC[p])continue;
        if (s == "AC") {
            AC[p] = true;
            ac++;
            pn += WA[p];
        }
        else {
            WA[p]++;
        }
    }
    cout << ac << " " << pn << endl;
    return 0;
}


Measured memory_bytes: 768
def GCD(x, y):
    if y == 0:
        return x
    return GCD(y, x % y)

A, B, C = map(int, input().split())
if B > A:
    A, B = B, A
gcd = GCD(A, B)

if C % gcd == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

struct Node{
    int sign;
    long long min,max;
}tree[1000005];

int n;
pair<long long,int> ax[200005];
pair<long long,int> bx[200005];
int cx[200005];

bool mmp(const pair<long long,int>& a,const pair<long long,int>& b){
    return a.first<b.first;
}

int left (int x){
    return x<<1;
}

int right (int x){
    return (x<<1)+1;
}

void build (int L,int R,int i){
    if(L==R){
    tree[i].min = bx[L-1].first;
    tree[i].max = bx[L-1].first;
    tree[i].sign = 1;
    return;
    }
    int mid = (L+R)/2;
    build(L,mid,left(i));
    build(mid+1,R,right(i));
    tree[i].min = tree[left(i)].min;
    tree[i].max = tree[right(i)].max;
    tree[i].sign = tree[right(i)].sign+tree[left(i)].sign;
}

int findf (int L,int R,long long res,int i){
    if(tree[i].max<res) return 0;
    if(tree[i].min>=res) return tree[i].sign;
    if(L==R) return 0;
    int mid = (L+R)/2;
    return findf(L,mid,res,left(i))+findf(mid+1,R,res,right(i));
}

void shan (int L,int R,int res,int i){
   if(L>res||R<res)return;
   tree[i].sign -= 1;
   if(L==R) return;
   int mid = (L+R)/2;
   shan(L,mid,res,left(i));
   shan(mid+1,R,res,right(i));
}

int main()
{
    int k,i,a;
    long long res=0,mid=0,b=0;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        a -= k;
        cx[i] = a;
    }
    for(i=0;i<n;i++){
        b += (long long)cx[i];
        ax[i].first = b;
        bx[i].first = b;
        bx[i].second = i;
    }
    sort(bx,bx+n,mmp);
    for(i=0;i<n;i++){
        ax[bx[i].second].second = i+1;
    }
    build(1,n,1);
    b = 0;
    for(i=0;i<n;i++){
        res += (long long)findf(1,n,b,1);
        shan(1,n,ax[i].second,1);
        b += (long long)cx[i];
    }
    printf("%lld",res);
    return 0;
}


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

using namespace std;


int main(){
    
    string str="";
    int sum=0;

    while(true){
        cin >> str;
        if(str!="0"){
            for(int i=0; i<str.length(); i++){
                sum += str[i] - '0';
            }
            cout << sum << endl;
            sum=0;
        }else{
            break;
        }
    }

    return 0;
}




Measured memory_bytes: 3216
import sys
input = sys.stdin.readline

N = int(input())

v = [[] for _ in range(N)]
for _ in range(N-1) :
    a, b = map(int, input().split())
    v[a-1].append(b-1)
    v[b-1].append(a-1)

qa, qb = [0], [N-1]
sa, sb = 0, 0
visited = [False] * N
visited[0] = visited[N-1] = True

while qa or qb :
    qa_ = []
    while qa :
        cur = qa.pop()
        for nex in v[cur] :
            if not visited[nex] :
                visited[nex] = True
                qa_.append(nex)
                sa += 1
    qa = qa_
    
    qb_ = []
    while qb :
        cur = qb.pop()
        for nex in v[cur] :
            if not visited[nex] :
                visited[nex] = True
                qb_.append(nex)
                sb += 1
    qb = qb_
    
if sa > sb :
    print('Fennec')
else :
    print('Snuke')

Measured memory_bytes: 55216
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 105
int N,M,X;
int a[MAXN];
int main()
{
	scanf("%d %d %d",&N,&M,&X);
	for(int i=1;i<=M;i++)
	{
		int t;
		scanf("%d",&t);
		a[t]=1;
	}
	int ans=0,b=0;
	for(int i=X;i<=N;i++)
		ans+=a[i];
	for(int i=0;i<=X;i++)
		b+=a[i];
	ans=min(ans,b);
	printf("%d\n",ans);
}

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

int main() {
  int abc[3];
  for (int i = 0; i < 3; i++)
    cin >> abc[i];
  sort(abc, abc + 3);

  if (abc[0] == 5 && abc[1] == 5 && abc[2] == 7)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int n,q,L,R;
string s;
char t[222222],d[222222];
signed main(){
	cin>>n>>q>>s;
	rep(i,q)cin>>t[i]>>d[i];
	int ok=-1,ng=n;
	while(ng-ok>1){
		int mid=(ok+ng)/2;
		int now=mid;
		rep(i,q){
			if(s[now]==t[i]){
				if(d[i]=='L')now--;
				else now++;
			}
			if(now==-1)break;
		}
		if(now==-1)ok=mid;
		else ng=mid;
	}
	L=ok;
	ng=-1,ok=n;
	while(ok-ng>1){
		int mid=(ok+ng)/2;
		int now=mid;
		rep(i,q){
			if(s[now]==t[i]){
				if(d[i]=='L')now--;
				else now++;
			}
			if(now==n)break;
		}
		if(now==n)ok=mid;
		else ng=mid;
	}
	R=ok;
	cout<<max(0ll,R-L-1)<<endl;
	return 0;
}


Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl

/*--------------------template--------------------*/

#define SIZE 2000005
ll inv[SIZE], fac[SIZE], finv[SIZE];

void make(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    FOR(i,2,SIZE) {
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fac[i] = fac[i - 1] * (ll)i % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll C(ll a, ll b){
    if(a<b) return 0;
    return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}


int main() {
    cin >> n;
    if(n==2){
        cout << 1 << endl;
        return 0;
    }else if(n==3){
        cout << 4 << endl;
        return 0;
    }else if(n==4){
        cout << 16 << endl;
        return 0;
    }
    make();
    ans = fac[n];
    FOR(i,1,n) {
        m = C(i - 1, n - 1 - i) * fac[i] % MOD * fac[n - 1 - i] % MOD;
        //cout << "k = " << i << "  " << m << endl;
        ans -= m;
        if(ans<0){
            ans += MOD;
        }
    }
    cout << ans%MOD << endl;
}

Measured memory_bytes: 47104
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,string> P;
#define INF (1<<20)

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    int tmp = a*c + b*d;
    if(c >= 5 && d >= 2){
      ans = a*c + b*d;
      ans = (int)((double)ans*0.8);
    } else if(c >= 5) {
      d = 2;
      ans = a*c + b*d;
      ans = (int)((double)ans*0.8);
    } else if(d >= 2){
      c = 5;
      ans = a*c + b*d;
      ans = (int)((double)ans*0.8);
    } else {
      c = 5; d = 2;
      ans = a*c + b*d;
      ans = (int)((double)ans*0.8);
    }
    cout << min(ans,tmp) << endl;
  }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int x,k,d,z,l,ans;
  	cin>>x>>k>>d;
  	l=abs(x)/d;
  	z=abs(x)%d;
  	if(l<k)
    {
        //cout<<z;
      	k=k-l;
      	    if(k%2)
           {
               ans=abs(z-d);
           }
           else
           {
                ans=z;
           }
    }
  	else
    {
        ans=abs(x)-k*d;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3612
//============================================================================
// Name        : 0019.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	long long n,x=1;
	cin >>n;
	for(int i=1; i<=n; i++){
		x *= i;
	}
	cout <<x<<endl;
	return 0;
}

Measured memory_bytes: 1156
n,m = map(int,input().split())
a = list(map(int,input().split()))
ans = 0

newlist = sorted(a,reverse=True)

for i in range(m):
    if newlist[i] >= sum(a)*(1/(4*m)):
        ans += 1

if ans==m:
    print("Yes")

else:
    print("No")

Measured memory_bytes: 9200
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int H,W;
	cin >> H >> W;
	vector< vector<bool> > fld(H+2,vector<bool>(W+2,false));
	for(int h=1;h<=H;++h){
		string str;
		cin >> str;
		for(int w=0;w<W;++w){
			if( str[w] == '#' ){
				fld[h][w+1] = true;
			}
		}
	}
	vector< vector<int> > ans(H+2,vector<int>(W+2,0));
	int dh[] = {-1,-1,-1,0,0,1,1,1};
	int dw[] = {-1,0,1,-1,1,-1,0,1};
	for(int h=1;h<=H;++h){
		for(int w=1;w<=W;++w){
			int res = 0;
			for(int k=0;k<8;++k){
				int hh = h + dh[k];
				int ww = w + dw[k];
				if( fld[hh][ww] ){
					++res;
				}
			}
			ans[h][w] = res;
		}
	}
	for(int h=1;h<=H;++h){
		for(int w=1;w<=W;++w){
			if( fld[h][w] ){
				cout << '#';
			}else{
				cout << ans[h][w];
			}
		}
		cout << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

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


def solve(S: str):
    if S=="SUN":
        print(7)
    elif S=="MON":
        print(6)
    elif S=="TUE":
        print(5)
    elif S=="WED":
        print(4)
    elif S=="THU":
        print(3)
    elif S=="FRI":
        print(2)
    elif S=="SAT":
        print(1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import itertools

h,w,k = map(int,input().split())
c = []
for i in range(h):
    wks = input()
    kk = [ 0 if e == '.' else 1 for e in wks ]
    c.append(kk)

ans = 0

for elc in itertools.product([0,1],repeat=h):
    for elr  in itertools.product([0,1],repeat=w):
        kk = 0
        for i in range(h):
            for j in range(w):
                kk += c[i][j] * elc[i] * elr[j]
        if kk == k :
            ans += 1

print(ans)


Measured memory_bytes: 73740
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	string s;
	cin >> s;
	ll saisyo=LLONG_MAX;
	ll saigo = 0;
	for (ll i = 0; i < s.size(); i++) {
		if (s[i] == 'A') {
			saisyo =min( i,saisyo);
		}
		else if (s[i] == 'Z') {
			saigo = max(saigo,i);
		}
	}
	cout << saigo - saisyo + 1 << endl; 

}



Measured memory_bytes: 640
n = gets.to_i
a = gets.split.map(&:to_i)
ar = []

a.each do |v|
  if v.even?
    ar << v
  end
end

if ar.count == (ar.select{ |v| (v % 3 == 0) || (v % 5 == 0) }).count
  puts "APPROVED"
else
  puts "DENIED"
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

struct BIT{
private:
    vector<ll> a;
    int n;
public:
    BIT(int sz){
        n=sz;
        a.resize(sz+1);
    }
    ll sum(int i){
        ll res=0;
        while(i>0){
            res+=a[i];
            i-=i&-i;
        }
        return res;
    }
    ll sum(int i,int j){
        return sum(j)-sum(i-1);
    }
    void add(int i,ll x){
        while(i<=n){
            a[i]+=x;
            i+=i&-i;
        }
    }
};

int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    ll ans=LINF;
    int p[n]={};
    for(int i=0;i<(n+1)/2;i++){
        p[n-1-i]=1;
    }
    do{
        bool flag=true;
        vector<pair<int,int>> ev;
        vector<pair<int,int>> od;
        ev.reserve((n+1)/2);
        od.reserve(n/2);
        for(int i=0;i<n;i++){
            if(p[i]){
                if(i%2==0)ev.push_back({a[i],i});
                else ev.push_back({b[i],i});
            }
            else{
                if(i%2==0)od.push_back({b[i],i});
                else od.push_back({a[i],i});
            }
        }
        sort(ev.begin(),ev.end());
        sort(od.begin(),od.end());
        int t=-1;
        ll sum=0;
        BIT bit(n);
        for(int i=0;i<(n/2)*2;i++){
            if(i%2==0){
                if(t>ev[i/2].first){
                    flag=false;
                    break;
                }
                t=ev[i/2].first;
                sum+=abs(ev[i/2].second+bit.sum(ev[i/2].second+1,n)-i);
                bit.add(ev[i/2].second+1,1);
            }
            else{
                if(t>od[i/2].first){
                    flag=false;
                    break;
                }
                t=od[i/2].first;
                sum+=abs(od[i/2].second+bit.sum(od[i/2].second+1,n)-i);
                bit.add(od[i/2].second+1,1);
            }
        }
        if(n&1&&t>ev.back().first){
            continue;
        }
        if(flag){
            ans=min(ans,sum);
        }
    }while(next_permutation(p,p+n));
    if(ans==LINF)cout<<-1<<endl;
    else cout<<ans<<endl;
}

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

typedef long long ll;
typedef pair<int,int> P;
ll const INF = 1LL<<60;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    vector<vector<ll>> c(51,vector<ll>(51,INF));
    vector<vector<bool>> d(n,vector<bool>(51,false));
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) cin >> b[i];
    for (int i = 0;i < 51;++i) c[i][i] = 0;
    for (int i = 0;i < 51;++i) for (int j = 0;j <= i;++j) {
        for (int k = max(i,j)+1;k < 51;++k) for (int l = 1;i+l*k < 51;++l) {
            c[i+k*l][j] = min(c[i+k*l][j],c[i][j]+(1LL<<k));
        }
    }
    for (int i = 0;i < n;++i) d[i][a[i]] = true;
    bool ng = false;
    for (int i = 0;i < n;++i) if (c[a[i]][b[i]] == INF) ng = true;
    if (ng) {
        cout << "-1" << endl;
        return 0;
    }
    ll ans = 0;
    for (int i = 50;i > 0;--i) {
        bool f = false;
        for (int j = 0;j < n;++j) {
            bool g = true;
            for (int k = 0;k < 51;++k) {
                if (d[j][k] && c[k][b[j]] < (1LL<<i)) g = false; 
            }
            if (g) f = true;
        }
        if (f) {
            ans += (1LL<<i);
            for (int j = 0;j < n;++j) {
                for (int k = 0;k < 51;++k) {
                    if (d[j][k]) {
                        if (c[k%i][b[j]] < (1LL<<i)) d[j][k%i] = true;
                        if (c[k][b[j]] >= (1LL<<i)) d[j][k] = false;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    // for (int i = 0;i < 10;++i) p_ary(c[i],0,10,j);

    return 0;
}

Measured memory_bytes: 256
arr = gets.strip.split(' ').map(&:to_i)
result = (arr[0] == arr[1] && arr[0] != arr[2]) ||
    (arr[1] == arr[2] && arr[1] != arr[0]) ||
    (arr[2] == arr[0] && arr[2] != arr[1]) 
msg = 'No'
msg = 'Yes' if result
puts msg


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

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  int a1, b1, c1;
  a1 = y;
  b1 = x;
  c1 = z;
  int a, b, c;
  a = c1;
  b = b1;
  c = a1;
  cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;

int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  int X;
  cin >> X;
  int Y;
  cin >> Y;

  int ans = min(N, K) * X;
  ans += max(0, N - K) * Y;
  cout << ans << endl;
  return 0;
}

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

int main(){
    cin >> n;
    ll ans = 0;
    for(ll i=1; i<=n; i++){
        ans+=i*(n/i)*(n/i+1)/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;

const string NO = "No";
const string YES = "Yes";

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

    int n, m;
    cin >> n >> m;
    int q;
    cin >> q;

    vector<int> a(q);
    for (int i = 0; i < q; ++i) {
        cin >> a[i];
    }

    reverse(a.begin(), a.end());

    vector<int> b(n - 1);
    for (int i = 0; i + 1 < n; ++i) {
        b[i] = 0;
    }

    set<int> values;
    for (int x = 1; x <= m; ++x) {
        values.insert(x);
    }

    vector<int> minValues(m);
    for (int i = 0; i < m; ++i) {
        minValues[i] = 1;
    }

    map<int, int> mp;
    int last = 1;

    vector<int> revValues(m + 1);

    for (int x : a) {
        if (mp.find(x) == mp.end()) {
            values.erase(values.find(x));
            if (last < m) {
                minValues[last] = (*values.begin());
            }
            revValues[last] = x;
            mp[x] = last++;
            continue;
        }

        int xx = mp[x] - 1;

        int bl = 0;
        int br = n - 2;
        int ba = -1;
        while (bl <= br) {
            int bm = (bl + br) >> 1;

            if (b[bm] == xx) {
                ba = bm;
                br = bm - 1;
            } else if (b[bm] > xx) {
                bl = bm + 1;
            } else {
                br = bm - 1;
            }
        }

        if (ba == -1) {
            continue;
        } else {
            ++b[ba];
        }
    }

    vector<bool> good(last);

    good[last - 1] = true;
    for (int i = last - 2; i >= 0; --i) {
        good[i] = good[i + 1];
        if (revValues[i + 1] != minValues[i]) {
            good[i] = false;
        }
    }

    for (int i = 0; i + 1 < n; ++i) {
        if (!good[b[i]]) {
            cout << NO << endl;
            return 0;
        }
    }

    cout << YES << endl;

    return 0;
}

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

int main(){
	
	int n;
	cin>>n;
	vector<int> v(n);
	for (int i = 1; i <=n; ++i)
	{
		cin>>v[i];
	}
	//cout<<v[1]<<" "<<v[2];
	int dp[n+1]={0};
	dp[1]=0;
	dp[2]=abs(v[2]-v[1]);
	for (int i = 3; i <=n; ++i)
	{
		dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
	}
	cout<<dp[n];
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long ans = 0;
		int p = sc.nextInt();
		for (int i = 1; i < N; i++) {
			int c = sc.nextInt();
			if (p > c) {
				ans += p - c;
				c = p;
			}
			p = c;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 58620
import java.util.Scanner;

public class Main {

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



	public void run() {
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();
		char t[][] = new char[2][n];
		t[0] = sc.next().toCharArray();
		t[1] = sc.next().toCharArray();
		long MOD = 1000000007;
		long cnt = 0;
		int i=0;
		if(t[0][0]==t[1][0]) {
			cnt = 3;
			i=1;
		}else {
			cnt = 6;
			i=2;
		}
		while(i<n) {
			if(t[0][i]==t[1][i]) {
				if(t[0][i-1]==t[1][i-1]) {
					cnt = (cnt * 2) % MOD;
				}else {
					cnt = (cnt * 1) % MOD;
				}
				i++;
			}else {
				if(t[0][i-1]==t[1][i-1]) {
					cnt = (cnt * 2) % MOD;
				}else {
					cnt = (cnt * 3) % MOD;
				}
				i += 2;
			}
		}
		System.out.println(cnt);
		sc.close();
	}

}


Measured memory_bytes: 23636
#include <stdio.h>

    int main(void)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        if(a<b){
        printf("a < b\n");
        }else{
        if(a>b){
        printf("a > b\n");
        }else{
        printf("a == b\n");
        }
      }
	return 0;
    }

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int p=1;
    map<char,long long>m;
    set<char>so;
    set<char>::iterator it;
    for(int i=0;i<s.size();i++)
    {
        m[s[i]]+=1;
        so.insert(s[i]);
    }
    for(it=so.begin();it!=so.end();it++)
    {
        if(m[*it]%2!=0)
        {
            p=0;
            break;
        }
    }
    if(p==0)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
}


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

int main() {
int A; cin>> A;//age
int B; cin>> B;//cost
if(A>=13 && A<=100){
	cout<<B;
}
else if(A>=6 && A<=12){
	int C=B/2;
	cout<< C;
}
else if (A>=0 && A<=5){
printf("0\n");
}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999

int a, b;

int main() {
	cin >> a >> b;
	cout << abs(a - b) << endl;

	return 0;
}



Measured memory_bytes: 3120
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  char S;
  cin>>S;
  if(S<='Z') co("A");
  else co("a");
  return 0;
}

Measured memory_bytes: 3628
#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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long u, long long v, std::vector<long long> A, std::vector<long long> B){
  vector<vector<ll>> tree(N);
  REP(N-1){
    tree[A[i]].push_back(B[i]);
    tree[B[i]].push_back(A[i]);
  }
  vector<ll> depth(N,-1);
  vector<ll> parent(N,-1);
  deque<ll> q;
  q.push_back(v);
  depth[v]=0;
  parent[v]=-1;
  while(!q.empty()){
    ll tmp=q.back();q.pop_back();
    for (auto &&j : tree[tmp])
    {
      if(depth[j]==-1){
        depth[j]=depth[tmp]+1;
        parent[j]=tmp;
        q.push_front(j);
      }
    }
  }
  bool f=(depth[u])%2==0;
  ll p=(depth[u]+1)/2-1;
  REP(p){
    u=parent[u];
  }
  ll depmax=depth[u];
  q.clear();
  q.push_back(u);
  while(!q.empty()){
    ll tmp=q.back();q.pop_back();
    for (auto &&i : tree[tmp])
    {
      if(i==parent[tmp]){
        continue;
      }
      depmax=max(depmax,depth[i]);
      q.push_front(i);
    }
  }
  cout<<depmax-1<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long u;
    scanf("%lld",&u);
    long long v;
    scanf("%lld",&v);
    --u;--v;
    std::vector<long long> A(N-1);
    std::vector<long long> B(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        --A[i];
        --B[i];
    }
    solve(N, u, v, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	int a, b, c;
	cin >> a >> b >> c;
	if(c >= a && c <= b)cout << "Yes";
	else cout << "No";
	cout << endl;
	return 0;
}


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

int main()
{
  int n;
  cin>>n;
  int c[6];
  memset(c,0,sizeof(c));
  for(;n--;)
    {
      double t;
      cin>>t;
      int i=0;
      for(double l=185.0;l>164.9;l-=5.0,i++)
	{
	  if(l<=t)
	    {
	      c[i]++;
	      i=-1;
	      break;
	    }
	}
      if(i!=-1)
	c[5]++;
    }
  for(int i=5;i>=0;i--)
    {
      cout<<6-i<<":";
      for(;c[i]--;)
	cout<<"*";
      cout<<endl;
    }
    
}

Measured memory_bytes: 1232