akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	ll d;
	cin >> d;
	ll c = 0;
	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		if (x*x + y*y <= d*d) c++; 
	}
	cout << c << endl;
}



Measured memory_bytes: 3608
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n; cin>>n;
    vector<int> d(n,0),c(13,0);
    rep(i,n){
        cin>>d[i];
        c[d[i]]++;
    }
    if(c[0]>0){
        cout<<0<<endl;
        return 0;
    }
    rep(i,12){
        if(c[i+1]>2){
            cout<<0<<endl;
            return 0;
        }
    }
    vector<int> data,r;
    rep(i,12){
        if(c[i+1]==2){
            data.push_back(i+1);
            data.push_back(24-i-1);
        }
        else if(c[i+1]==1) r.push_back(i+1);
    }
    data.push_back(0);
    int ans=0,k=r.size(),l=data.size();
    if(k==0){
        ans=30;
        rep(i,l)rep(j,l){
            if(i==j) continue;
            int cur=abs(data[i]-data[j]);
            ans=min(ans,min(cur,24-cur));
        }
        cout<<ans<<endl;
    }
    else{
        rep(i,k) data.push_back(0);
        rep(i,(1<<k)){
            int cur=30;
            rep(j,k){
                if(i&(1<<j)) data[l+j]=r[j];
                else data[l+j]=24-r[j];
            }
            rep(I,l+k)rep(J,l+k){
                if(I==J) continue;
                int cu=abs(data[I]-data[J]);
                cur=min(cur,min(cu,24-cu));
            }
            ans=max(ans,cur);
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n;
int ga, sa, ba;
int gb, sb, bb;
ll dp[30000000];

int main() {
    cin >> n;
    cin >> ga >> sa >> ba;
    cin >> gb >> sb >> bb;
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        dp[i] = dp[i-1];
        if (i-ga >= 0) dp[i] = max(dp[i], dp[i-ga]+gb-ga);
        if (i-sa >= 0) dp[i] = max(dp[i], dp[i-sa]+sb-sa);
        if (i-ba >= 0) dp[i] = max(dp[i], dp[i-ba]+bb-ba);
    }
    n += dp[n];
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        dp[i] = dp[i-1];
        if (i-gb >= 0) dp[i] = max(dp[i], dp[i-gb]+ga-gb);
        if (i-sb >= 0) dp[i] = max(dp[i], dp[i-sb]+sa-sb);
        if (i-bb >= 0) dp[i] = max(dp[i], dp[i-bb]+ba-bb);
    }
    cout << n+dp[n] << endl;
}


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

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

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

string S;

void init(){
  cin >> S;
}

void preprocess(){

}

void solve(){
  for( int i = S.size() - 1; i >= 0; --i ){
    if( i - 6 >= 0 and S.substr( i - 6, 7 ) == "dreamer" )
      i = i - 6;
    else if( i - 5 >= 0 and S.substr( i - 5, 6 ) == "eraser" )
      i = i - 5;
    else if( i - 4 >= 0 and S.substr( i - 4, 5 ) == "dream" )
      i = i - 4;
    else if( i - 4 >= 0 and S.substr( i - 4, 5 ) == "erase" )
      i = i - 4;
    else
      cout << "NO" << endl, exit( 0 );
  }
  cout << "YES" << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int n,k; CI n>>k;
	vector<int> h(n);  CI h;

	int ans = 10000000000;
	sort(h.begin(), h.end());
	for (int i = 0; i < n - k + 1;i++) {
		ans = min(ans, h[i + k - 1] - h[i]);
	}
	CO ans EN;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
using namespace std;

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


int main() {
	int64_t n;
	int64_t A[5];
	cin >> n;
	rep(i, 5) cin >> A[i];

	int64_t mn = *min_element(A, A+5);
	int64_t ans = (n-1)/mn + 5;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N,count;
    cin>>N;
    count=1;
    vector<string>S(N);
    for(int i=0;i<N;i++){
        cin>>S[i];
        
    }
    sort(S.begin(),S.end());
    for(int i=0;i<N;i++){
        if(S[0]!=S[i]){
            if(S[i-1]!=S[i]){
                count++;
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 9472
// // -*- coding:utf-8-unix -*-

// #[macro_use]
// extern crate lazy_static;
// extern crate num_bigint; // 0.2.2
// extern crate num_traits; // 0.2.8
// use num_bigint::BigInt;
// use num_traits::Pow;
// use petgraph::algo::dijkstra;
// use petgraph::Directed;

// // use proconio::derive_readable;
// use proconio::fastout;
// use proconio::input;
// // use std::convert::TryInto;
// use ascii::{AsciiChar, AsciiString};
// use itertools::concat;
// use lazy_static::lazy_static;
// use libm::*;
// use petgraph::Graph;
// use std::cmp::*;
// use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
// use std::io::*;
// use std::ops::Range;
// use std::str::FromStr;
// use std::sync::Mutex;
// use superslice::*;

// pub fn read<T: FromStr>() -> T {
//     let stdin = stdin();
//     let stdin = stdin.lock();
//     let token: String = stdin
//         .bytes()
//         .map(|c| c.expect("failed to read char") as char)
//         .skip_while(|c| c.is_whitespace())
//         .take_while(|c| !c.is_whitespace())
//         .collect();
//     token.parse().ok().expect("failed to parse token")
// }

// // lazy_static! {
// //     static ref H: Mutex<Vec<i32>> = Mutex::default();
// //     static ref W: Mutex<Vec<i32>> = Mutex::default();
// // }

// // let mut values = VALUES.lock().unwrap();
// // values.extend_from_slice(&[1, 2, 3, 4]);
// // assert_eq!(&*values, &[1, 2, 3, 4]);

use proconio::{input, marker::Chars};
use std::collections::HashMap;

// static ASCII_LOWER: [char; 26] = [
//     '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',
// ];

// abc172-D
fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }

    let mut b = vec![false; n];
    for i in (1..n + 1).into_iter().rev() {
        let mut num = i;
        let mut sum_b: usize = 0;
        while num <= n {
            sum_b += if b[num - 1] { 1 } else { 0 };
            num += i;
        }

        // eprintln!("{}, {}", i, sum_b);
        b[i - 1] = (sum_b % 2) != a[i - 1];
        //
        // if i * 2 > n {
        //     b[i - 1] = a[i - 1] == 1;
        // } else {
        //     b[i - 1] = a[2 * i - 1] != a[i - 1];
        // }
    }

    println!(
        "{}",
        b.iter()
            .map(|is_b| if *is_b { 1 } else { 0 })
            .sum::<usize>()
    );
    for (idx, b) in b.iter().enumerate() {
        if *b {
            println!("{}", idx + 1);
        }
    }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 112345;
vector<int> g[MAX_N];
int H[MAX_N];

int main2() {
  REP(i, MAX_N) g[i].clear();
  int N = nextInt();
  int M = nextInt();
  REP(i, N) H[i] = nextInt();
  REP(i, M) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  int ans = 0;
  REP(i, N) {
    int ok = true;
    for (int j : g[i]) if (i != j) {
      if (H[i] <= H[j]) ok = false;
    }
    if (ok) ans++;
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 9512
#include<bits/stdc++.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
    string a,b,c;
    cin>>a>>b>>c;
    a[0]=toupper(a[0]);
    b[0]=toupper(b[0]);
    c[0]=toupper(c[0]);
    cout<<a[0]<<b[0]<<c[0];
}

Measured memory_bytes: 3624
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  s[k - 1] = std::tolower(s[k - 1]);
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <ctype.h>

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	printf("%d\n",(a*b)-(a+b)+1);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long mod = 1000000007;

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

	int n;
	cin >> n;
	char* s;
	s = new char[n];
	rep(i, n) cin >> s[i];

	int ans = 0;
	REP(i, 1, n) {
		int counter = 0;
		rep(j, n - i) {
			if (s[j] == s[j + i]) {
				if (++counter == i) {
					ans = max(ans, counter);
					break;
				}
			}
			else {
				ans = max(ans, counter);
				counter = 0;
			}
		}
		ans = max(ans, counter);
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 384
# 桁DP練習
# 「0以外の値をkより多く使ったか」でとくに枝切りしてない
# ループでどうしてもかけない...

from sys import setrecursionlimit

setrecursionlimit(10**7)

n = input()
k = int(input())
dp = {}


def rec(i, smaller, count):
    if (i, smaller, count) in dp:
        return dp[(i, smaller, count)]
    if i == len(n):
        if count == k:
            return 1
        else:
            return 0
    limit = 10
    if not smaller:
        limit = int(n[i]) + 1
    ret = 0
    for j in range(limit):
        if smaller or j < int(n[i]):
            if j == 0:
                ret += rec(i + 1, True, count)
            else:
                ret += rec(i + 1, True, count + 1)
        else:
            if j == 0:
                ret += rec(i + 1, False, count)
            else:
                ret += rec(i + 1, False, count + 1)
    dp[(i, smaller, count)] = ret
    return ret


print(rec(0, False, 0))


Measured memory_bytes: 9548
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  int n ;
  string s ;
  cin >> n >> s ;
  int ans = 0 ;
  int count = 0 ;
  
  REP(i,n-1){
    vector<int> vec1(26,0) ;
    vector<int> vec2(26,0) ;
    REP(j,i){
      vec1.at(s.at(j)-'a') = 1 ;
    }
    FOR(j,i,n){
      vec2.at(s.at(j)-'a') = 1 ;
    }
    REP(j,26){
      if(vec1.at(j)==1 &&vec2.at(j)==1){
        count++ ;
      }
    }
    ans = max(ans,count) ;
    count = 0 ;
  }
    
  cout << ans <<endl ;

  return 0 ;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};


fn solve(k: usize, xs: Vec<usize>) -> usize {
    xs.into_iter()
        .map(|x| 2 * if x <= k / 2 { x } else { k - x })
        .sum::<usize>()
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    let (n, k) = (sc.next(), sc.next());
    println!("{}", solve(k, sc.vec(n)));
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        self.buf.clear();
        for c in self.bytes
            .by_ref()
            .map(|c| c.unwrap())
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
        {
            self.buf.push(c);
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
        <C as FromStr>::Err: Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_yesno(x: bool, yes: &'static str, no: &'static str) {
    println!("{}", if x { yes } else { no });
}


#[allow(dead_code)]
fn print_foreach<T: Display, I: IntoIterator<Item = T>>(xs: I) {
    for x in xs.into_iter() {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_or<T: Display>(x: Option<T>, or: &'static str) {
    if let Some(x) = x {
        println!("{}", x);
    } else {
        println!("{}", or);
    }
}


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

int main() {

    int day, n;

    cin >> day >> n;

    for(int i = 0; i < n; ++i) {
        int task;
        cin >> task;
        day -= task;
    }

    if(day < 0)
        day = -1;

    cout << day << endl;

    return 0;


}

Measured memory_bytes: 3640
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var hwab = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int h = hwab[0];
        int w = hwab[1];
        int a = hwab[2];
        int b = hwab[3];
        ModInt res = 0;;
        for (int i = 0; i < h - a; i++) res += (Factorial(i + b - 1) / (Factorial(i) * Factorial(b - 1))) * (Factorial((w - b - 1) + (h - i - 1)) / (Factorial(w - b - 1) * Factorial(h - i - 1)));
        Console.WriteLine((long)res);
    }

    static List<ModInt> factorialMemo = new List<ModInt>() { 1 };
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static ModInt Factorial(int x)
    {
        for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i);
        return factorialMemo[x];
    }
}

struct ModInt
{
    const int MOD = 1000000007;
    long Data;
    public ModInt(long data) { Data = data; Eval(); }

    private long Eval() => (Data %= MOD) < 0 ? Data += MOD : Data;
    public static implicit operator long(ModInt modInt) => modInt.Eval();
    public static implicit operator ModInt(long val) => new ModInt(val);
    public static ModInt operator +(ModInt a, ModInt b) => new ModInt(a.Eval() + b.Eval());
    public static ModInt operator -(ModInt a, ModInt b) => new ModInt(a.Eval() - b.Eval());
    public static ModInt operator *(ModInt a, ModInt b) => new ModInt(a.Eval() * b.Eval());
    public static ModInt operator /(ModInt a, ModInt b) => a * Power(b.Eval(), MOD - 2);

    static ModInt Power(ModInt n, ModInt m)
    {
        ModInt res = 1;
        while (m > 0)
        {
            if ((m & 1) == 1) res *= n;
            n *= n;
            m >>= 1;
        }
        return res;
    }
}

Measured memory_bytes: 16352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

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

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

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

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

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

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

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}


int main(){
  int H,W;
  cin >> H >> W;
  int c;
  WeightedGraph< int> g(10);
  rep(i,10)rep(j,10){
    cin >> c;
    g[i].emplace_back(j,c);
  }
  int a;
  multiset<int> m;
  rep(i,H) rep(j,W){
    cin >> a;
    m.insert(a);
  }
  ll ans=0;
  rep(i,10){
    int count=m.count(i);
    if(count!=0 && i!=1){
      ans+=1LL*(dijkstra(g,i)[1]*count);
    }
  }
  cout << ans << endl;


  
  return 0;

}


Measured memory_bytes: 2176
import java.util.*;
import java.lang.*;
import java.io.*;
 class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner sc=new Scanner(System.in);
	   // BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	    int t=1;
	   // t=sc.nextInt();
	    //int t=Integer.parseInt(br.readLine());
	    while(--t>=0){
	        int n=sc.nextInt();
	        int a[][]=new int[n][2];
	        for(int i=0;i<n;i++){
	            a[i][0]=sc.nextInt();
	            a[i][1]=sc.nextInt();
	        }
	        int k=0;
	        for(int i=0;i<n-2;i++){
	            if(a[i][0]==a[i][1]&&a[i+1][0]==a[i+1][1]&&a[i+2][0]==a[i+2][1]){
	                k=1;
	            }
	            
	        }
	        if(k==1)
	        System.out.println("Yes");
	        else
	        System.out.println("No");
	     
	        
	    }
	    
	}
}

Measured memory_bytes: 36012
#include <cstdio>
#include <deque>
#include <tuple>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
using namespace std;

int main() {
    int n, l; scanf("%d%d", &n, &l);
    vector<int> t(n), v(n); repeat (i, n) scanf("%d%d", &t[i], &v[i]);
    deque<pair<int, double> > deq;
    deq.emplace_back(v[0], t[0]);
    double acc = t[0] *(double) v[0];
    printf("%.12lf\n", acc /(double) l);
    repeat_from (i, 1, n) {
        for (int nv = v[i]; nv > 0; ) {
            int dv = min(nv, deq.front().first);
            nv -= dv;
            deq.front().first -= dv;
            acc -= deq.front().second * dv;
            if (deq.front().first == 0) {
                deq.pop_front();
            }
        }
        int nv = v[i];
        double nt = t[i];
        while (not deq.empty() and deq.back().second > nt) {
            int pv; double pt; tie(pv, pt) = deq.back();
            deq.pop_back();
            nt = (nt * nv + pt * pv) / (nv + pv);
            nv += pv;
        }
        deq.emplace_back(nv, nt);
        acc += t[i] *(double) v[i];
        printf("%.12lf\n", acc /(double) l);
    }
    return 0;
}


Measured memory_bytes: 23296
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long

LL mod = 998244353;
int n, r[200005];
LL dp[200005];
vector<pair<int, int>> a;

int c[200005];
int lowbit(int x) {
  return x & (-x);
}
void update(int l, int w) {
  for(int i = l; i <= n; i += lowbit(i)) {
    c[i] = max(c[i], w);
  }
}
int query(int l) {
  int ans = 0;
  for(int i = l; i > 0; i -= lowbit(i)) {
    ans = max(ans, c[i]);
  }
  return ans;
}
bool cmp(const pair<int, int> a, const pair<int, int> b) {
  return a.first < b.first;
}

int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    pair<int, int> pii;
    scanf("%d%d", &pii.first, &pii.second);
    a.push_back(pii);
  }
  sort(a.begin(), a.end());
  for(int i = n - 1; i >= 0; i--) {
    pair<int, int> pii = {a[i].first + a[i].second, 0};
    r[i] = (lower_bound(a.begin(), a.end(), pii, cmp) - a.begin()) - 1;
    r[i] = max(i, query(r[i] + 1));
    update(i + 1, r[i]);
  }

  dp[n] = 1;
  for(int i = n - 1; i >= 0; i--) {
    dp[i] = dp[i + 1] + dp[r[i] + 1];
    dp[i] %= mod;
  }
  cout << dp[0] << endl;
  return 0;
}

Measured memory_bytes: 5104
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<ctype.h>
#define PI 3.141592653589
#define N_MAX 1000
#define NUM 26

int main()
{
  char buf[N_MAX], W[N_MAX];
  int count = 0,len, j;
  scanf("%s",W);
  len = strlen(W);
  for(j = 0; j < len; j++)
    {
      W[j] = tolower(W[j]);
    }
  char end[] = "END_OF_TEXT";
  while(1)
    {
      scanf("%s",buf);
      if(strcmp(buf,end) == 0) break;
      len = strlen(buf);
      for(j = 0; j < len; j++)
	{
	  buf[j] = tolower(buf[j]);
	}
      if(strcmp(buf,W) == 0) count++;
    }
  printf("%d\n",count);
  return 0; 
}

Measured memory_bytes: 552
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

int main()
{
	char a;
	cin >> a;
	if (a == 'A')
	{
		cout << "T" << endl;
	}
	else if (a == 'T')
	{
		cout << "A" << endl;
	}
	else if (a == 'G')
	{
		cout << "C" << endl;
	}
	else 
	{
		cout << "G" << endl;
	}

}


Measured memory_bytes: 256
n=int(input())
ans = 100000000
for i in range(1,n):
    ankari = 0
    for j in range (1,6):
        ankari += (i%pow(10,j))//pow(10,j-1)+((n-i)%pow(10,j))//pow(10,j-1)
    ans = min(ans,ankari)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n,p[123456],k,q,a;
int main(){
    cin>>n>>k>>q;
    for(int i=0;i<q;i++){
        cin>>a;
        p[a]++;
    }
    for(int i=1;i<=n;i++){
        if(p[i]>(q-k))cout<<"Yes"<<endl;
        else if(p[i]<=(q-k))cout<<"No"<<endl;
    }
}


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

bool ispalin(string s)
{
	string ss=s;
	reverse(s.begin(),s.end());
	
	if(ss==s)
	return true;
	
	else
	return false;
}

int main()
{
  string s,s1="",s2="";
  cin>>s;
  int n=s.length();
  int n1=(n-1)/2;
  int n2=(n+3)/2;
  for(int i=0;i<n1;i++)
    s1+=s[i];
  for(int i=n2-1;i<n;i++)
  s2+=s[i];
  
  if(ispalin(s) && ispalin(s1)  && ispalin(s2))
  cout<<"Yes"<<"\n";
  
  else
  cout<<"No"<<"\n";
  
  return 0;
}
  

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> graph(H);
    Rep(i, H) cin >> graph[i];
    vector<vector<int>> dp(H, vector<int>(W, 0));
    Rep(i, H) {
        if (graph[i][0] == '#') break;
        dp[i][0] = 1;
    }
    Rep(j, W) {
        if (graph[0][j] == '#') break;
        dp[0][j] = 1;
    }
    for (int i = 1; i < H; i++) {
        for (int j = 1; j < W; j++) {
            if (graph[i][j] == '#') continue;
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % Mod;
        }
    }
    cout << dp[H - 1][W - 1] << endl;
    return 0;
}

Measured memory_bytes: 9504
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
//rep(i, v.size()) v[i]=i;
//#define int long long
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>
 
using namespace std;
 
signed main(){
  int S;
  cin >> S;
  
  if(S == 1 || S == 2 || S == 3 || S == 5 || S == 7 || S == 13 || S == 15 || S == 17 || S == 19 || S == 23 || S == 29 || S == 31 || S == 11)cout << 1 << endl;
  if(S == 4 || S == 6 || S == 9 || S == 10 || S == 14 || S == 21 || S == 22 || S == 25 || S == 26)cout << 2 << endl;
  if(S == 8 || S == 12 || S == 18 || S == 20 || S == 27)cout << 5 << endl;
  if(S == 16)cout << 14 << endl;
  if(S == 24)cout << 15 << endl;
  if(S == 28 || S == 30)cout << 4 << endl;
  if(S == 32)cout << 51 << endl;
}


Measured memory_bytes: 256
@n = gets(chomp:true).to_i
@a = gets.split.map(&:to_i)
@q = gets(chomp:true).to_i
@m = gets.split.map(&:to_i)

  def check(check_value, sum_value, count)
    if check_value == sum_value
      return true

    elsif count > @n - 1
      return false

    elsif check_value < sum_value
      return false
      
    elsif check(check_value, sum_value, (count + 1)) || check(check_value, (sum_value += @a[count]), (count + 1))
      return true
    end
  end

@m.each do |value|
  puts check(value, 0, 0) ? "yes" : "no"
end



Measured memory_bytes: 6868
/* SANDEEP YADAv*/
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
lld gcd(lld a,lld b){ if(a<b) { a=a+b; b=a-b; a=a-b;}while(b!=0){lld r=a%b; a=b; b=r;} return a;}
long long power(long long a, long long b, long long m) {a %= m;long long res = 1;while (b > 0) {if (b & 1)res = res * a % m;a = a * a % m;b >>= 1;}return res;}
void judge()
{
      #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
    #endif
}

int main()
{
    fastio;
    // judge();
    long double n;
    cin>>n;

    printf("%0.9LF",(n/3)*(n/3)*(n/3));

    return 0;
}

Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<cstdio>

#define s(A,B) std::sort(A,B,std::greater<int>());

int main(){
	int W[21],K[21],p;
	for(int i=0;i<20;i++)
		scanf("%d",&p),(i<10)?W[i] = p:K[i-10] = p;
	s(W,W+10);
	s(K,K+10);
	int Wp = W[0] + W[1] + W[2],Kp = K[0] + K[1] + K[2];
	printf("%d %d\n",Wp,Kp);
	return 0;
}

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

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		Main app = new Main();
		
		boolean prime[] = app.primeSet();
		int n, res;
		while(true){
			if((n = Integer.valueOf(reader.readLine())) == 0) break;
			
			res = 0;
			for(int i = n + 1; i <= 2 * n; i++){
				if(!prime[i]) res++;
			}
			System.out.println(res);
		}
		
		reader.close();
	}
	public boolean[] primeSet(){
		boolean res[] = new boolean[123456 * 2 + 1];
		res[0] = res[1] = true;
		for(int i = 2; i * i < 123457 * 2; i++){
			for(int j = 2; i * j < 123457 * 2; j++){
				res[i * j] = true;
			}
		}
		return res;
	}
}

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

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 187;
char s[N][N];
int n, m;
int dp[2][N][N][N];
int closeDiff[N][N];

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

	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%s", s[i]);
	for (int y = 0; y < m; y++) {
		closeDiff[n - 1][y] = n;
		for (int x = n - 2; x >= 0; x--) {
			if (s[x][y] == s[x + 1][y])
				closeDiff[x][y] = closeDiff[x + 1][y];
			else
				closeDiff[x][y] = x + 1;
		}
	}
	for (int x = 0; x < n; x++) {
		for (int i = 0; i < m; i++)
			for (int j = i + 1; j <= m; j++)
				dp[0][x][i][j] = x;
		for (int y1 = 0; y1 < m; y1++) {
			int val = closeDiff[x][y1];
			dp[0][x][y1][y1 + 1] = val;
			for (int y2 = y1 + 1; y2 < m; y2++) {
				if (s[x][y1] != s[x][y2]) break;
				val = min(val, closeDiff[x][y2]);
				dp[0][x][y1][y2 + 1] = val;
			}
		}
	}
	int ans = 0;
	while(dp[0][0][0][m] != n) {
		ans++;
		for (int x = 0; x < n; x++)
			for (int i = 0; i < m; i++)
				for (int j = i + 1; j <= m; j++)
					dp[1][x][i][j] = dp[0][x][i][j];
		for (int x = 0; x < n; x++) {
			for (int y1 = 0; y1 < m; y1++)
				for (int y2 = y1 + 1; y2 <= m; y2++) {
					int x2 = dp[0][x][y1][y2];
					if (x2 < n)
						x2 = dp[0][x2][y1][y2];
					dp[1][x][y1][y2] = max(dp[1][x][y1][y2], x2);
				}
		}
		for (int x = 0; x < n; x++)
			for (int y1 = 0; y1 < m; y1++) {
				int p = y1 + 1;
				for (int y2 = y1 + 2; y2 <= m; y2++) {
					while(p + 1 < y2 && dp[0][x][y1][p + 1] >= dp[0][x][p + 1][y2]) p++;
					dp[1][x][y1][y2] = max(dp[1][x][y1][y2], min(dp[0][x][y1][p], dp[0][x][p][y2]));
					if (p + 1 < y2)
						dp[1][x][y1][y2] = max(dp[1][x][y1][y2], min(dp[0][x][y1][p + 1], dp[0][x][p + 1][y2]));
				}
			}
		for (int x = 0; x < n; x++)
			for (int i = 0; i < m; i++)
				for (int j = i + 1; j <= m; j++)
					dp[0][x][i][j] = dp[1][x][i][j];
	}
	printf("%d\n", ans);

	return 0;
}


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

using namespace std;

#define eps (1e-10)
struct point{
    double x,y;
    point(){}
    point(double x,double y):x(x),y(y){}
    point operator + (point &p){return point(x+p.x,y+p.y);}
    point operator - (point &p){return point(x-p.x,y-p.y);}
    point operator * (double k){return point(x*k,y*k);}
    point operator / (double k){return point(x/k,y/k);}

    double norm(){return x*x+y*y;}
    double abs(){return sqrt(norm());}

    bool operator < (const point &p){
        return x!=p.x?x<p.x:y<p.y;
    }
    bool operator == (const point &p){
        return fabs(x-p.x)<eps&&fabs(y-p.y)<eps;
    }
};
//内积
double dot(point a,point b)
{
    return a.x*b.x+a.y*b.y;
}
//外积
double cross(point a,point b){
    return a.x*b.y-a.y*b.x;
}

const int counter_clockwise=1;
const int clockwise=-1;
const int online_back=2;
const int online_front=-2;
const int on_segment=0;

string ccw(point a,point b,point c)
{
    point temp1=b-a;
    point temp2=c-a;
    if(cross(temp1,temp2)>eps){return "COUNTER_CLOCKWISE";}
    if(cross(temp1,temp2)<-eps){return "CLOCKWISE";}
    if(dot(temp1,temp2)<-eps){return "ONLINE_BACK";}
    if(temp1.norm()<temp2.norm()){return "ONLINE_FRONT";}
    return "ON_SEGMENT";
}

int main()
{
    point a,b;
    cin>>a.x>>a.y>>b.x>>b.y;
    int q;
    cin>>q;
    point temp;
    for(int i=0;i<q;i++){
        cin>>temp.x>>temp.y;
        string res=ccw(a,b,temp);
        cout<<res<<endl;
    }
    return 0;
}



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

using namespace std;

int n, f[100000];
vector<int> g[100000];

void dfs(int v, int p) {
	for(int to : g[v]) {
		if(to == p)
			continue;
		dfs(to, v);
		f[v] ^= (f[to] + 1);
	}
}

int main() {
	cin >> n;
	for(int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0, -1);
	cout << (f[0] == 0 ? "Bob" : "Alice");
}

Measured memory_bytes: 12288
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String str,arr[];
		List<String> list = new ArrayList<String>();
		while(null!=(str = in.readLine())){
			arr = str.split(",",0);
			list.add(arr[1]);
		}
		System.out.println(count("A",list));
		System.out.println(count("B",list));
		System.out.println(count("AB",list));
		System.out.println(count("O",list));
	}

	private static long count(String bl,List<String> list){
		List<String> lis = new ArrayList<String>(list);
		int i=0;
		while(lis.remove(new String(bl)))i++;
		return i;
	}
}

Measured memory_bytes: 16920
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	vector<Int> dl(N, 0), dr(N, 0);
	dl[0] = a[0];
	for (int i = 1; i < N; ++i) { dl[i] = dl[i - 1] + a[i]; }
	dr[N - 1] = a[N - 1];
	for (int i = N - 2; i >= 0; --i) { dr[i] = dr[i + 1] + a[i]; }

	Int ans = 1e18;
	for (int i = 0; i + 1 < N; ++i) {
		ans = min(ans, abs(dl[i] - dr[i + 1]));
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4992
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, 1); \
                 auto rnd = bind(__dis, __gen);

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int n;
    string s;
    map<string, int> gain;
    
    cin >> n;
    while (n--) cin >> s, ++gain[s];
    
    cin >> n;
    while (n--) cin >> s, --gain[s];
    
    int maxGain = 0;
    for (auto x : gain) maxGain = max(maxGain, x.second);
    
    cout << maxGain << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <cstdio>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;

int main(){

    while(true){
        int n;
        cin>>n;
        if(n==0)break;
        
        int dice[4]={5,3,2,4};
        int up=1;
        int ans=1;
        
        REP(i,n){
            string dire;
            cin>>dire;
            if(dire=="North"){
                dice[0]=up;
                up=dice[2];
                dice[2]=7-dice[0];
            }else if(dire=="East"){
                dice[1]=up;
                up=dice[3];
                dice[3]=7-dice[1];
            }else if(dire=="South"){
                dice[2]=up;
                up=dice[0];
                dice[0]=7-dice[2];
            }else if(dire=="West"){
                dice[3]=up;
                up=dice[1];
                dice[1]=7-dice[3];
            }else if(dire=="Right"){
                int t=dice[0];
                dice[0]=dice[3];
                dice[3]=dice[2];
                dice[2]=dice[1];
                dice[1]=t;
            }else{
                int t=dice[0];
                dice[0]=dice[1];
                dice[1]=dice[2];
                dice[2]=dice[3];
                dice[3]=t;
            }
            ans+=up;
            
        }
        
        cout<<ans<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 3224
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <algorithm>
typedef long long ll;
template <typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-')	flag = true; c = getchar(); }
	while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
	if (flag)	x = -x;
}
using namespace std;
int n;
int main() {
	read(n);
	int mx = -1;
	ll res = 0;
	for (int i = 1; i <= n; ++i) {
		int x; read(x);
		if (i == 1)	mx = x;
		else	mx = max(mx, x), res += mx - x;
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i > init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    ll W, H, N;
    cin >> W >> H >> N;
    vector<vector<ll>> table(W, vector<ll>(H, 0));
    repi(i, N, 0)
    {
        ll x, y, a;
        cin >> x >> y >> a;
        if (a == 1)
        {
            repi(i, x, 0)
            {
                repi(j, H, 0)
                {
                    table[i][j] = 1;
                }
            }
        }
        else if (a == 2)
        {
            repi(i, W, x)
            {
                repi(j, H, 0)
                {
                    table[i][j] = 1;
                }
            }
        }
        else if (a == 3)
        {
            repi(i, W, 0)
            {
                repi(j, y, 0)
                {
                    table[i][j] = 1;
                }
            }
        }
        else if (a == 4)
        {
            repi(i, W, 0)
            {
                repi(j, H, y)
                {
                    table[i][j] = 1;
                }
            }
        }
    }
    ll cnt = 0;
    repi(i, W, 0)
    {
        repi(j, H, 0)
        {
            if (table[i][j] == 0)
            {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 384
//コンパイラ最適化用
#pragma GCC optimize("Ofast")

//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//INT_MAXなど
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

// clang++ main.cc -std=c++11 -stdlib=libc++

/*
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
*/

signed main(){
  int S;
  cin >> S;

  int res = 0;
  while (1) {
    if (S == 4 || S == 2 || S == 1) {
      res += 4;
      break;
    }

    if (S % 2 == 0)
      S /= 2;
    else
      S = S * 3 + 1;
    res++;
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

template<class T> void inputVector(vector<T>& v, int n) {
	v.resize(n);
	for (int i = 0; i < v.size(); i++) cin >> v[i];
}

struct Edge {
	int next;
	int cost;

	Edge() {}
	Edge(int n, int c) {
		next = n;
		cost = c;
	}
};

vector<int> dists;
vector<vector<Edge>> edges;

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

	edges.resize(N);

	rep(i, N - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;

		edges[a].push_back(Edge(b, c));
		edges[b].push_back(Edge(a, c));
	}

	int Q, K;
	cin >> Q >> K;
	K--;

	const int INF = LLONG_MAX;

	dists = vector<int>(N, INF);
	dists[K] = 0;
	queue<int> q;
	q.push(K);
	while (!q.empty()) {
		int now = q.front(); q.pop();
		rep(i, edges[now].size()) {
			int next = edges[now][i].next;
			int cost = edges[now][i].cost;
			if (dists[next] != INF) continue;
			dists[next] = dists[now] + cost;
			q.push(next);
		}
	}

	rep(i, Q) {
		int x, y;
		cin >> x >> y;
		x--; y--;

		cout << dists[x] + dists[y] << endl;
	}

    return 0;
}


Measured memory_bytes: 11456
class KMP:
    def __init__(self, P):
        self.P = P
        self.N = len(P)
        self.T = [0] * (self.N + 1)
        self._compile()

    def _compile(self):
        j = 0
        self.T[0] = -1
        for i in range(1, self.N):
            self.T[i] = j
            j += 1 if self.P[i] == self.P[j] else -j
        self.T[self.N] = j

    def search(self, S):
        NS = len(S)
        i = m = 0
        A = []
        while m + i < NS:
            if self.P[i] == S[m + i]:
                i += 1
                if i != self.N:
                    continue
                A.append(m)
            m += i - self.T[i]
            i = max(0, self.T[i])
        return A

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    dA = [A[i] ^ A[(i + 1) % N] for i in range(N)]
    dB = [B[i] ^ B[(i + 1) % N] for i in range(N)]

    dA = dA + dA[:-1]
    # C string D pattern
    K = KMP(dB).search(dA)
    for k in K:
        print(k, A[k] ^ B[0])

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 152608
#include<stdio.h>
#include<string.h>
int main()
{

char S[7];
scanf("%s",&S);
int i,a=0;
for(i=0;i<6;i++)
{
   if(S[2]==S[3]&&S[4]==S[5]){
     a=1;
     break;
   }
   else
   {
       a=2;
       break;
   }
}
if(a==1)
    printf("Yes\n");
else
    printf("No\n");
return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 2 * 1000 * 100 + 47;
const int MIN = 404;
const int MOD = INF;



struct RSQ
{
    int T[MAX << 2];
    int A[MAX];
    int n;
    
    void upd(int v, int tl, int tr, int pos)
    {
        if (tl == tr)
        {
            T[v] = !!A[tl];
            return ;
        }
        int tm = (tl + tr) / 2;
        if (pos <= tm)upd(v + v, tl, tm, pos);
        else upd(v + v + 1, tm+1, tr, pos);
        T[v] = T[v+v] + T[v+v+1];
    }
    void dec(int pos)
    {
        A[pos]--;
        upd(1, 0, n-1, pos);
    }
    
    void inc(int pos)
    {
        A[pos]++;
        upd(1, 0, n-1, pos);
    }
    
    
    int get()
    {
        return T[1];
    }
    
};

RSQ T;
int A[MAX];
int CNT[MAX];

int main()
{
    // freopen("in.txt", "r", stdin);
    int n, m;
    scanf("%d%d", &n, &m);
    T.n = n;
    FOR(i, 0, n)
    {
        scanf("%d", &A[i]);
        --A[i];
        CNT[A[i]]++;
    }
    
    FOR(i, 0, n)
        FOR(j, max(0, j - CNT[i] + 1), i+1)
            T.inc(j);
    
    FOR(q, 0, m)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        --x, --y;
        int xx = A[x] - CNT[A[x]] + 1;
        if (xx >= 0)T.dec(xx);
        CNT[A[x]]--;
        A[x] = y;
        CNT[A[x]]++;
        xx = A[x] - CNT[A[x]] + 1;
        if (xx >= 0)T.inc(xx);
        
        printf("%d\n", n - T.get());
    }
    
    
    
    return 0;
}





Measured memory_bytes: 6400