akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	// 木の直径が1or2ずつ減る。mod3で2に合同なら先手の負け、それ以外で先手の勝ち。
	vector<vector<int>> g(N, vector<int>());
	int a, b;
	for (int i = 1; i < N; ++i) {
		cin >> a >> b;
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vector<int> d(N,N+1);
	priority_queue<int> q;
	// 頂点0からの距離を求める
	d[0] = 0;
	q.push(0);
	int v;
	while (q.size() > 0) {
		v = q.top(); q.pop();
		for (const auto& e : g[v]) {
			if (d[e] > d[v]) {
				d[e] = d[v] + 1;
				q.push(e);
			}
		}
	}
	int maxv = max_element(d.begin(), d.end())-d.begin();
	vector<int> dd(N, N + 1);
	dd[maxv] = 0;
	q.push(maxv);
	while (q.size() > 0) {
		v = q.top(); q.pop();
		for (const auto& e : g[v]) {
			if (dd[e] > dd[v]) {
				dd[e] = dd[v] + 1;
				q.push(e);
			}
		}
	}
	maxv = *max_element(dd.begin(), dd.end());
	
	// maxv は直径-1だから、余りは1かどうか

	cout << (maxv%3==1?"Second":"First") << endl;
	

}

Measured memory_bytes: 14452
H, W = map(int, input().split())
INF = H * W
A = [input() for x in range(H)]
used = [[False] * W for x in range(H)]

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            q.append([i, j])
            used[i][j] = True

max_dist = 0
counter = 0
depth = -1
while counter != INF:
    # print(q)
    # print(counter)
    for i in range(len(q) - counter):
        item = q[counter]

        if item[0] > 0 and not used[item[0]-1][item[1]]:
            q.append([item[0] - 1, item[1]])
            used[item[0] - 1][item[1]] = True
        if item[1] > 0 and not used[item[0]][item[1] - 1]:
            q.append([item[0], item[1] - 1])
            used[item[0]][item[1] - 1] = True
        if item[0] < H - 1 and not used[item[0] + 1][item[1]]:
            q.append([item[0] + 1, item[1]])
            used[item[0] + 1][item[1]] = True
        if item[1] < W - 1 and not used[item[0]][item[1] + 1]:
            q.append([item[0], item[1] + 1])
            used[item[0]][item[1] + 1] = True
        counter += 1
    depth += 1

print(depth)

Measured memory_bytes: 152664
#include<iostream>
#include<algorithm>
using namespace std;
long long a[100000], b[100000];

int main() {
	int n;
	long long h;
	cin >> n >> h;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	long long max_a;
	int strongest=0;
	for (int i = 0; i < n; i++) {
		if (a[i] > a[strongest]) {
			strongest = i;
		}
	}
	max_a = a[strongest];
	sort(b, b + n);
	int cnt = 0;
	int j = n - 1;
	while (b[j] > max_a && h > 0) {
		h = h - b[j];
		j--;
		cnt++;
	}
	if (h <= 0) {
		cout << cnt << endl;
	}
	else {
		if (h%max_a == 0) {
			cnt--;
		}
		cnt = cnt + ((h) / max_a) + 1;
		cout << cnt << endl;
	}
}

Measured memory_bytes: 1792
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=[I() for _ in range(n)]

  for x in l:
    if x%2==1:
      return 'first'
  return 'second'

# main()
print(main())


Measured memory_bytes: 9568
#define e(i,n)for(i=0;i<n;i++)
d,m=1e9+7,p[10001][200]={1};i,j,k,x,I;char s[11111];main(L){scanf("%s%d",s,&d);e(i,strlen(s))e(j,2)e(x,(L=j?9:s[i]-48)+1)e(k,d)p[i+1][I=(j|x<L)*d+(k+x)%d]+=p[i][j*d+k],p[i+1][I]%=m;printf("%d",(*p[i]+p[i][d]-1+m)%m);}

Measured memory_bytes: 7936
#include <cstdio>
#include <vector>

int n;
std::vector<std::pair<int, int> > E[100000];
int D[100000];
int C[100000];
int K;

void color(int x, int p, int c){
  for(auto y: E[x]){
    if(y.first == p) continue;
    C[y.second] = c = (c + 1) % K;
    color(y.first, x, c);
  }
}

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n-1; i++){
    int x, y;
    scanf("%d%d", &x, &y);
    E[x-1].emplace_back(std::pair<int, int>(y-1,i));
    E[y-1].emplace_back(std::pair<int, int>(x-1,i));
    D[x-1]++;
    D[y-1]++;
  }
  int maxd = 0;
  for(int i = 0; i < n; i++) maxd = std::max(maxd, D[i]);
  K = maxd;

  printf("%d\n", K);
  color(0, -1, -1);

  for(int i = 0; i < n-1; i++) printf("%d\n", C[i]+1);

  return 0;
}


Measured memory_bytes: 7680
import java.util.Scanner;

fun main(args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val N = input.nextInt()
    val S = input.next()
    var idx = 0
    var count = 0;
    
    while (idx >= 0) {
      idx = S.indexOf("ABC", idx)
      
      if (idx >= 0) {
        ++count
        idx += 3
      }
    }
    
    println(count)
  }
}

Measured memory_bytes: 37676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int a,b;
  a = N%1000;
  b = N-(N%10);
  if (a%111==0 || b%111==0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
MOD = 1000000007
n = int(input())
l = list(map(int,input().split()))
a = {}
for i in l:
    if i in a:
        a[i] += 1
    else:
        a[i] = 1

cur = 1 if n % 2 == 0 else 0

ok = True
while cur < n:
    x = 1 if cur == 0 else 2
    if cur in a and a[cur] != x:
        ok = False
        break
    cur += 2

ans = 0
if ok:
    ans = 1
    for _ in range(n // 2):
        ans = ans * 2 % MOD

print(ans)

Measured memory_bytes: 14436
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

int dfs(int n, int count){
	if (n < 6){
		return count + n;
	}
	int a=0,b=0,c=0,d=0;
	while(true){
		if (n < pow(9,a+1)) break;
		++a;
	}
	while(true){
		if (n < pow(6,b+1)) break;
		++b;
	}
	c=dfs(n-pow(9,a), count+1);
	d=dfs(n-pow(6,b), count+1);
	return min(c,d);
}

int main(){
	int n; cin >> n;
	int a = 0;
	a = dfs(n,0);
	cout << a << endl;
}


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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    ll ans = 0;
    bool even = false;
    for(int i = 0; i < N; i++) {
        int j = i;
        while(j < N && S[j] == S[i])
            j++;
        ans += j - i - 1;
        if(even && K-- > 0) {
            ans++;
            if(j < N)
                ans++;
        }
        i = j - 1;
        even = !even;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
void print(int A[], int length){
  int i;
  for(i=0; i<length; ++i){
	printf("%d", A[i]);
	if(i<(length-1))
	  printf(" ");
}
  printf("\n");
}
int main(){
  int length;
  scanf("%d", &length);
  int i, j;
  int A[1000];
  for(i=0; i<length; ++i){
	scanf("%d", &A[i]);
}
  print(A, length);
  int key;
  for(j=1; j<length; ++j){
	key=A[j];
	i=j-1;
	while((i>=0)&&(A[i]>key)){
	  A[i+1]=A[i];
	  --i;
}
	A[i+1]=key;
	print(A, length);
}

  return 0;
}



Measured memory_bytes: 2032
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    x = input_number_list()
    print(x.index(0)+1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, K;
bool b[2000000];

int main() {
	cin >> N >> K;
	if (N < 2 * K - 1) {
		cout << -1 << endl;
		return 0;
	}
	int t = K + 2 * N - 1;
	int p = K + (N + 1) / 2 - 1;
	int s = K + N * 3 - 1;
	while (s >= K + N * 2) {
		cout << t << sp << p << sp << s << endl;
		t--;
		p--;
		s -= 2;
	}
	p = K + N - 1;
	s = K + N * 3 - 2;
	while (s >= K + N * 2) {
		cout << t << sp << p << sp << s << endl;
		t--;
		p--;
		s -= 2;
	}
}


Measured memory_bytes: 2304
H,W,K = (int(x) for x in input().split())

mat = [[0]*W for _ in range(W)]

def dfs(bar_partial):
    if len(bar_partial) == W-1:
        perm = list(range(W))
        for i,w in enumerate(bar_partial):
            if w == 1:
                perm[i] = i+1
                perm[i+1] = i
        for i in range(W):
            mat[i][perm[i]] += 1
        return
    bar_partial.append(0)
    dfs(bar_partial)
    bar_partial.pop()
    if len(bar_partial) == 0 or bar_partial[-1] == 0:
        bar_partial.append(1)
        dfs(bar_partial)
        bar_partial.pop()

dfs([])
dp_hw = [[0]*W for _ in range(H+1)]
dp_hw[0][0] = 1
for i in range(1, H+1):
    dp_prev = dp_hw[i-1]
    dp_current = dp_hw[i]
    for j in range(W):
        for k in range(W):
            dp_current[j] += dp_prev[k]*mat[j][k]
        dp_current[j] = dp_current[j] % 1000000007

print(dp_hw[-1][K-1])


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  while(true){
    string s;
    cin>>s;
    if(s=="-")break;
    int n;
    cin>>n;
    int a=0;
    for(int i=0;i<n;i++){
      int b;
      cin>>b;
      a+=b;
    }
    a%=s.size();
    for(int i=0;i<s.size();i++){
      cout<<s[(a+i)%s.size()];
    }
    cout<<endl;
  }
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](long a, long b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<long>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  double r;
  cin >> r;
  cout << 2*r*3.141592 << endl;
  return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (int i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (int i = x.size()-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define fst first
#define scd second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int a, b;
    cin>>a>>b;
    string s = "", t = "";
    REP(i,a) s += to_string(b);
    REP(i,b) t += to_string(a);
    cout<<min(s, t)<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int n;
    int h[100010];
    int dp[100010];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    for(int i=1;i<n;i++){
        dp[i] = dp[i-1]+abs(h[i-1]-h[i]);
        if(i >= 2){
            dp[i] = min(dp[i],dp[i-2]+abs(h[i-2]-h[i]));
        }
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef long long ll;

signed main() 
{
	int n, l, x, sum = 0;
	cin >> n >> l;
	for (int i = 1; i <= n; i++)
		sum += l + i - 1;
	
	if (l >= 0) x = l;
	else if (1 - l <= n) x = 0;
	else x = l + n - 1;
	
	cout << sum - x;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    ll x;
    cin >> x;

    ll f, d;
    for (ll i = 0; i*i*i*i*i <= x*x; ++i) {
        for (ll j = 0; j*j*j*j*j <= x*x; ++j) {
            f = i*i*i*i*i;
            d = j*j*j*j*j;
            if(f + d == x){
                cout << i << " " << -j << "\n";
                return 0;
            }
            if(f - d == x){
                cout << i << " " << j << "\n";
                return 0;
            }
        }
    }


    return 0;
}


Measured memory_bytes: 3576
#include <cstdio>
int a[112345];
int main(){
	int n; scanf("%d", &n);
	for(int i(1); i <= n; ++i){
		scanf("%d", &a[i]);
	}
	for(int i(2); i <= n; ++i){
		if(a[i - 1] >= a[i] + 2){
			printf("No\n");
			return 0;
		}
	}
	int len = 1;
	for(int i(2); i <= n && len <= 2; ++i){
		if(a[i - 1] > a[i]) ++len;
		else if(a[i - 1] < a[i]) len = 1;
	}
	printf("%s\n", len >= 3 ? "No" : "Yes");
	return 0;
} 


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

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)

//repetition
//------------------------------------------
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)

//constant
//--------------------------------------------
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

// output vector
// ------------------------------------------
namespace std {
    template<typename T> ostream & operator<<(ostream& os, vector<T> const& v){
        for(auto it=v.begin(); it!=v.end(); ++it){
            os << *it << (it+1==v.end() ? "" : ",");
        }
        return os;
    }
}

//clear memory
#define clr(a) memset((a), 0 ,sizeof(a))

int main(){
	int n;
	ull a;
	
	cin >> n;
	
	rep(i,n){
		cin >> a;
		cout << "Case " << i+1 << ":"<<  endl;
		rep(j,10){
			a=pow(a,2);
			a/=100;
			a%=10000;
			cout << a << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
			while (sc.hasNext()) {
				String str = sc.nextLine();
				System.out.println(roman(str));
			}
		sc.close();

	}

	private static int roman(String str) {
		char[] c = str.toCharArray();
		int sum = 0;

			for (int i = 0; i < c.length; i++) {
				if ( i == c.length - 1 ) {
					sum += t(c[i]);
				} else if (t(c[i]) >= t(c[i + 1])) {
					sum += t(c[i]);
				} else {
					sum += t(c[i + 1]) - t(c[i]);
					i++;
				}
			}

		return sum;
	}

	private static int t(char c) {
		int t = 1;

			switch (c) {
			case 'I':
				t = 1;
				break;
			case 'V':
				t = 5;
				break;
			case 'X':
				t = 10;
				break;
			case 'L':
				t = 50;
				break;
			case 'C':
				t = 100;
				break;
			case 'D':
				t = 500;
				break;
			case 'M':
				t = 1000;
				break;
			}


		return t;
	}

}


Measured memory_bytes: 26332
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int a;
    cin>>a;
    cout<<3*a*a<<endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
M=998244353;N=gets.to_i;v=$<.map{|e|Complex(*e.split.map(&:to_i))};h={};r=2**N+~N;[*0...N].combination(2){|i,j|h[x=[i,j]]||((j+1...N).map{|k|((v[j]-v[k]).conj*(v[i]-v[k])).imag.abs<1e-9&&x<<k};r-=2**(l=x.size)+~l;x.combination(2){|a,b|h[[a,b]]=1})};p r%M

Measured memory_bytes: 5372
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T> T expo(T base, T e, T mod) { T res = 1;
  while(e > 0) { if(e&1) res = res * base % mod; base = base * base % mod; e >>= 1; }
  return res;
}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}

const int MAXN = 3e5 + 3;
LL arr[MAXN], n;

int main() {
  ios_base::sync_with_stdio(false);
	cin >> n;
	for(int i = 0; i < 3*n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + 3*n);
	int cnt = 0;
	LL res = 0;
	for(int i = 3*n - 2; i >= 0 && cnt < n; i -= 2) {
		res += arr[i];
		cnt++;
	}
	cout << res << '\n';
  return 0;
}


Measured memory_bytes: 2560
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int R = sc.nextInt();
		int d = sc.nextInt();
		sc.close();

		int cnt = 0;
		for (int i = L; i <= R; i++) {
			if (i % d == 0) {
				cnt++;
			}
		}

		System.out.println(cnt);
	}
}


Measured memory_bytes: 35728
// デバッグ実行：Ctrl+F5

using System;

class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        //String[] words = line.Split(' ');

        line = line.Replace('1', 'a');
        line = line.Replace('9', '1');
        line = line.Replace('a', '9');
        Console.WriteLine(line);
    }
}

Measured memory_bytes: 11092
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<sstream>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e2 + 5;
int x[MAXN],y[MAXN];
double mp[MAXN][MAXN];
int biaoji[MAXN];
int n,ans = 0;
double sum = 0;
double dis(int x1,int y1,int x2,int y2)
{
	int xx = abs(x1 - x2);
	int yy = abs(y1 - y2);
	return sqrt(xx * xx + yy * yy);
}

void dfs(int t,int x,double s)
{
	if(x == n){
		ans++;
		sum += s;
	}
	for(int i = 0;i < n;i++){
		if(!biaoji[i]){
			biaoji[i] = 1;
			dfs(i,x + 1,s + mp[t][i]);
			biaoji[i] = 0;
		}
	}
}
int main()
{
	cin >> n;
	for(int i = 0;i < n;i++){
		scanf("%d %d",&x[i],&y[i]);
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			mp[i][j] = dis(x[i],y[i],x[j],y[j]);
		}
	}
	for(int i = 0;i < n;i++){
		biaoji[i] = 1;
		dfs(i,1,0);
		biaoji[i] = 0;
	}
	double aans = sum * 1.0  / ans;
	printf("%.10lf\n",aans);
	return 0;
}


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

int main(void) {
    int a, b, c, x, ret = 0;
    cin >>a >>b >>c >>x;
    for (int ai = 0; ai <= a; ai++) {
        for (int bi = 0; bi <= b; bi++) {
            for (int ci = 0; ci <= c; ci++) {
                if (500 * ai + 100 * bi + 50 * ci == x) ++ret;
            }
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    UNIQUE(s);

    cout << n - max(1LL, SZ(s) - k * 2) << endl;

    return 0;
}


Measured memory_bytes: 888
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    D = list(map(int, input().split()))
    count = Counter(D)
    result = 1
    if D[0] != 0 or count[0] != 1:
        print(0)
        return
    for i in range(max(D)):
        result *= count[i] ** count[i + 1]
    print(result % 998244353)


if __name__ == "__main__":
    main()


Measured memory_bytes: 19872
#include <algorithm>
#include <iostream>
#include <vector>
#include <tuple>

using namespace std;

template <typename T>
size_t indexOf(vector<T> v, T elem)
{
  auto iter = find(v.begin(), v.end(), elem);
  size_t idx = distance(v.begin(), iter);
  if (idx == v.size()) return -1;
  return idx;
}

int x,a, b;
string result;

void input()
{
  cin>> x >> a >> b;
}

void calc()
{
  result="delicious";
  if((b-a)>0)result="safe";
  if((b-a)>x)result="dangerous";
}

void output()
{
  cout << result << endl;
}

int main(int argc, char const* argv[])
{
  input();
  calc();
  output();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main(void){
  int N, M, X;
  cin >> N >> M >> X;
  int A[M];
  rep(i, M)
    cin >> A[i];
  //入力終了

  //Xから見て左に向かうときのコストと，右のときとを計算する
  int left_cost = 0;
  int right_cost = 0;
  rep(i, M){
    //左
    if(A[i] < X)
      left_cost++;
    //右
    else
      right_cost++;
  }

  //コストの小さい方を選ぶ
  cout << min(left_cost, right_cost) << endl;

  return 0;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = 3.14159265;
const ll MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 100005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;

int arr[MAXN];
int mm[MAXN];
int aa[MAXN];
int tot;
char text[MAXN];

void extgcd(ll a, ll b, ll& d, ll& x, ll& y) {
    if (!b) {
        d = a;
        x = 1;
        y = 0;
    } else {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}

inline ll getInv(ll x, ll mod) {
    ll g, a, b;
    extgcd(x, mod, g, a, b);
    return (a % mod + mod) % mod;
}

int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
        arr[i] /= 2;
    }
    ull lcm = 1;
    for (int i = 0; i < n; i++) {
        ull gcd = __gcd((ull)arr[i], lcm);
        lcm /= gcd;
        lcm *= arr[i];
        if (lcm > (ull)m) {
            printf("0\n");
            return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        ull stp = lcm / (ull)arr[i];
        if (!(stp % 2)) {
            printf("0");
            return 0;
        }
    }
    printf("%llu", (m / lcm - 1) / 2 + 1);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = s; i < n; i++)
typedef pair<int, int> P;

int main()
{
   int n,q;
   map<int,int> a;

   cin >> n;

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

   for(int i=1; i<=n; i++){
      cout << a[i];
      if(i!=n){cout << " ";}
      else {cout << endl;} 
   }


	return 0;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){
    int a, b, a_v, b_w, t;
    cin >> a >> a_v >> b >> b_w >> t;
    double dist = abs(a - b);
    double diff = a_v - b_w;
    bool ans = false;
    int sec = 0;
    if (dist == 0) {
        ans = true;
    } else if (diff <= 0) {
        ans = false;
    } else {
        ans = (dist/diff <= t);
    }
    cout << ((ans) ? "YES" : "NO") << endl;;
  return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    ull N, X;
    cin >> N >> X;

    ull l = N;
    ull a=N-X, b=X;

    while(a!=0) {
        l += 2 * (b/a) * a;
        b = b % a;
        swap(a, b);
    }

    l  -= b;

    cout << l << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
 
numbers = list(map(int, input().split(" ")))
 
cnt = 0
 
for i in range(n):
    for j in range(n - 1, i, -1):
        if numbers[j] < numbers[j - 1]:
            numbers[j],numbers[j - 1] = numbers[j - 1], numbers[j]
            cnt += 1
 
numbers = map(str, numbers)
print(" ".join(numbers))
 
print(cnt)

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

int main() {
  string w;
  cin >> w;
  
  int l = w.size();
  map<char, int> count;
  for(int i = 0; i < l; ++i){
    count[w[i]]++;
  }
  bool flag = true;
  for(auto c : count){
    if(c.second % 2) flag = false;
  }
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main(){
    string S;
    string T;
    cin >> S >> T;
    int ans = 0;
    for(int i = 0;i < S.size();i++){
        if(S[i] != T[i])
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3904
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int main() {
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<int> l(n), r(n);
	int gl = 0;
	for (int i = 0; i < n; i++) {
		if (gl > 0) gl--;
		if (a[i] == 0) gl = 999999999;
		if (a[i] < 0) gl = min(gl, -a[i]);
		if (a[i] > 0) l[i] = gl;
	}
	int gr = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (gr > 0) gr--;
		if (a[i] == 0) gr = 999999999;
		if (a[i] < 0) gr = min(gr, -a[i]);
		if (a[i] > 0) r[i] = gr;
	}
	int ret = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] > 0) ret += min(a[i], max(l[i], r[i]));
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3896
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  int n;
  cin >> n;
  ll tmp;
  set<ll>ans;
  rep(i,n){
    cin >> tmp;
    ans.insert(tmp);
  }
  if(ans.size() == n)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  if (x == 0) {
    if (k % 2 == 1) {
      cout << d << endl;
    } else {
      cout << 0 << endl;
    }
    return 0;
  }

  vector<ll> cand;
  cand.push_back(0LL);
  cand.push_back(k);
  ll y = (-x) / d;
  vector<ll> sub;
  FOR(i, -100, 100) {
    ll z = k + y + i;
    FOR(j, -100, 100) { sub.push_back(z / 2 + j); }
  }

  FOR(i, -10, 10) REP(j, 2) for (ll t : sub) {
    ll u = j == 0 ? (t + i) : (-t + i);
    if (0LL <= u && u <= k) {
      cand.push_back(u);
    }
  }

  ll ans = 1e18;
  for (ll c : cand) {
    // DUMP(c);
    ll cons = 2 * c - k;
    if (abs(cons) > (d - 1 + 1e18) / d) {
      continue;
    }
    ll e = abs(x + cons * d);
    // DUMP(d);
    ans = min(ans, e);
  }
  cout << ans << endl;
}


Measured memory_bytes: 11972
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,count1,count10,count20,count30,count40,count50,count60;
    count1=0;
    count10=0;
    count20=0;
    count30=0;
    count40=0;
    count50=0;
    count60=0;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            for (int i=0;i<n;i++) {
                cin>>a;
                if (a<10) {
                    count1++;
                } else if (a>=10&&a<20) {
                    count10++;
                } else if (a>=20&&a<30) {
                    count20++;
                } else if (a>=30&&a<40) {
                    count30++;
                } else if (a>=40&&a<50) {
                    count40++;
                } else if (a>=50&&a<60) {
                    count50++;
                } else if (a>=60) {
                    count60++;
                }
            }
        }
        cout<<count1<<endl;
        cout<<count10<<endl;
        cout<<count20<<endl;
        cout<<count30<<endl;
        cout<<count40<<endl;
        cout<<count50<<endl;
        cout<<count60<<endl;
        count1=0;
        count10=0;
        count20=0;
        count30=0;
        count40=0;
        count50=0;
        count60=0;
    }
}



Measured memory_bytes: 3088
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
double x[8], y[8];

signed main(){
    cin >> N;
    rep(i, N) cin >> x[i] >> y[i];

    double sum = 0;
    rep(i, N){
        rep(j, N){
            if(i >= j) continue;
            sum += sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
        }
    }
    cout << setprecision(16) << sum / N * 2 << endl;
}

Measured memory_bytes: 256
import math
N,M = map(int,input().split())
f = 1
if abs(N-M) > 1:
    print(0)
    exit()
if (N+M) % 2 == 0:
    f = 2

print(math.factorial(N) % (10**9+7) * math.factorial(M) % (10**9+7) * f % (10**9+7))






Measured memory_bytes: 79488
N = int(input())
A = [[] for i in range(2)]
for i in range(2):
    a = list(map(int, input().split()))
    A[i] = a

num = 0
for i in range(N):
    num = max(num, sum(A[0][:i + 1]) + sum(A[1][i:]))

print(num)

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#define MN 200005
using namespace std;
vector<int>a[MN];
int l[MN],r[MN],n,m;
priority_queue<int,vector<int>,greater<int> >q;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&l[i],&r[i]),a[l[i]].push_back(r[i]);
		if(l[i]==0)q.push(r[i]);
	}
	for(int i=1;i<=m;i++)sort(a[i].begin(),a[i].end());int pos=0;
	for(int i=1;i<=m;i++){
		if(a[i].size())for(int j=0;j<a[i].size()-1;j++)q.push(a[i][j]);
		else {
			if(!q.empty()&&q.top()<=i)q.pop();
			else {
				pos=max(pos,i);
				while(!a[pos].size()&&pos<=m)pos++;
				a[pos].pop_back();
			}
		}
	}printf("%d\n",q.size());
}

Measured memory_bytes: 10496
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<n;(i)++ )
#define FOR(i,m,n) for(int (i)=m;(i)<n;(i)++)
 
int main(){
    int n;
    cin>>n;
    double x[n];
    string u;
    double ans;
    rep(i,n){
        cin>>x[i]>>u;
        if(u=="JPY"){
            ans+=x[i];
        }else {
            ans+=(x[i]*380000.0);
        }
    }
    cout<<ans<<endl;
    return 0;

}


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

int main() {
    int n, cnt[2][26]{}, ans = 0;
    string s;
    cin >> n >> s;
    REP(i,n) cnt[1][s[i]-'a']++;
    REP(i,n-1){
        cnt[0][s[i]-'a']++;
        cnt[1][s[i]-'a']--;
        int tmp=0;
        REP(j,26) if(cnt[0][j]*cnt[1][j])tmp++;
        ans = max(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli a, b;
    cin >> a >> b;
    lli i = 1;
    if(a>b){
        swap(a, b);
    }
    while(true){
        if((a*i)%b==0){
            out(a * i);
            return 0;
        }
        i++;
    }
}

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

long long findMaxProfit(vector<int>&w,vector<long long>&profit,long long we,int n)
{
    long long dp[n+1][we+1];
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=we; j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(w[i-1]<=j)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+profit[i-1]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    return dp[n][we];
}
int main()
{
    int n,w;
    cin>>n>>w;
    vector<int>weight;
    vector<long long>profit;
    int x;
    long long y;
    for(int i=0; i<n; i++)
    {
        cin>>x>>y;
        weight.push_back(x);
        profit.push_back(y);
    }
    long long val=findMaxProfit(weight,profit,w,n);
    cout<<val<<endl;
    return 0;
}


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

typedef long long ll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	// freopen("input.in", "r", stdin);
	// freopen("input.out", "w", stdout);
	ll n; cin >> n;
	vector<ll> a(n);
	F0R(i, n) cin >> a[i];
	ll ans = 0;
	FOR(i, 1, n) {
		if (a[i] < a[i - 1]) {
			ans += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}
	cout << ans << nl;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const ll INF=12345678901234LL;
// i??????, j????????????, k??????????£???°????????£???????????¨
ll dp[150][10][150];

int k[150];
int x[150][10], d[150][10];

int main()
{
    int n,m;
    while(scanf(" %d %d", &n, &m),n)
    {
        rep(i,n)
        {
            scanf(" %d", &k[i]);
            rep(j,k[i]) scanf(" %d %d", &x[i][j], &d[i][j]);
        }

        fill(dp[0][0],dp[150][0],INF);

        // 0??????
        rep(i,k[0]) dp[0][i][0]=0;
        // 1??????
        if(m>0) rep(i,k[1]) dp[1][i][1]=0;

        ll ans=INF;
        rep(r,n)rep(s,k[r])rep(j,min(76,m+1))
        {
            if(r==n-1 || (r==n-2 && j<m))
            {
                ans = min(ans, dp[r][s][j]);
                continue;
            }

            // ??????????????£??????
            rep(i,k[r+1])
            {
                ll add=(d[r][s]+d[r+1][i])*abs(x[r][s]-x[r+1][i]);
                dp[r+1][i][j] = min(dp[r+1][i][j], dp[r][s][j]+add);
            }

            // ???????£???°???????????£??????
            if(j<m)
            {
                rep(i,k[r+2])
                {
                    ll add=(d[r][s]+d[r+2][i])*abs(x[r][s]-x[r+2][i]);
                    dp[r+2][i][j+1] = min(dp[r+2][i][j+1], dp[r][s][j]+add);
                }
            }
        }

        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 4932
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	if (a == b + c) {
		cout << "Yes" << endl;
	}
	else if (b == a + c) {
		cout << "Yes" << endl;
	}
	else if (c == a + b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}






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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;
pair<int, int> p[100000];

int main() {
	cin >> n;
	inc(i, n) {
		int a, b;
		cin >> a >> b;
		p[i] = MP(a, b);
	}
	
	sort(p, p + n);
	
	cout << p[n - 1].FI + p[n - 1].SE << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
namespace mxr{
	#define inc(i,a,b) for(register int i=a;i<=b;i++)
	#define dec(i,a,b) for(register int i=a;i>=b;i--)
 	using namespace std;
	template<class nT>
	void read(nT& x){
		char c;while(c=getchar(),!isdigit(c));
		x=c^48;while(c=getchar(),isdigit(c)) x=x*10+c-48;
	}
	const int p=1e9+7;
}
using namespace mxr;
int n,a[200010],b[200010];
long long f[4010][4010];
long long KSM(long long a,long long b){
	long long res=1;
	while(b){
		if(b&1) res=res*a%p;
		a=a*a%p;
		b/=2;
	}
	return res;
}
long long fac[40010];
long long C(long long a,long long b){
	if(b>a) return 0;
	return fac[a]*KSM(fac[b],p-2)%p*KSM(fac[a-b],p-2)%p;
}
int main(){
	read(n); fac[0]=1;
	inc(i,1,8000) fac[i]=fac[i-1]*i%p;
	inc(i,1,n) read(a[i]),read(b[i]),f[2002-a[i]][2002-b[i]]++;
	inc(i,1,4002) inc(j,1,4002){
		f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%p;
	}
	long long ans=0;
	inc(i,1,n){
		ans=(ans+f[a[i]+2002][b[i]+2002])%p;
		ans=((ans-C(2*a[i]+2*b[i],2*a[i]))%p+p)%p;
	}
	ans=ans*KSM(2,p-2)%p;
	cout<<ans;
}

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

int main(){
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b, c, tmp;
    cin >> a >> b >> c;
    if (a > b) {
      tmp = a;
      a = b;
      b = tmp;
    }
    if (b > c) {
      tmp = b;
      b = c;
      c = tmp;
    }
    if (c * c == a * a + b * b)
    cout << "YES" << endl;
    else
    cout << "NO" << endl;
  }
}



Measured memory_bytes: 3076
n = int(input())
s = input()
tow = [0]*(n+1)
tob = [0]*(n+1)
for i in range(n):
    if s[i] == "#":
        tow[i+1] = tow[i]+1
    else:
        tow[i+1] = tow[i]
    if s[n-i-1] == ".":
        tob[i+1] = tob[i]+1
    else:
        tob[i+1] = tob[i]
ans = min(i+j for i, j in zip(tow, tob[::-1]))
print(ans)

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


int main() {
	int n, m;
	cin >> n >> m;
	if (n == m) cout << "Yes" << endl;
	else cout << "No" << endl;


}

Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    lefter = 0
    righter = 0
    last = -1
    ans = [0]*len(S)
    last_is_R = True
    for i,s in enumerate(S):
        
        #print(lefter,last,righter)
        if last_is_R and s == "L":
            #print("lefter",lefter)
            #RLゾーン
            last = i
            ans[last]+=lefter//2
            ans[last-1]+=ceil(lefter/2)
            lefter = 0
            righter = 0
        elif not last_is_R and s == "R":
            #print("righter",righter)
            ans[last] += ceil(righter/2)
            ans[last-1] += righter//2
            righter = 0

        lefter += 1
        righter += 1

        if s == "L":
            last_is_R = False
            lefter = 0
        else:
            last_is_R = True
            righter = 0

    ans[last] += ceil(righter/2)
    ans[last-1] += righter//2
    print(*ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 55616