akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>
#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF 1e9
#define INFL 1e18
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

class CDistinctOrNot {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;
        ll A[N];
        REP(i, N) in >> A[i];
        string ans = "YES";
        sort(A,A+N);
        REP(i, N-1) {
            if (A[i] == A[i+1]) {
                ans = "NO";
                break;
            }
        }
        out << ans << '\n';
	}
};


int main() {
	CDistinctOrNot solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1792
s = list(input())
t = list(input())
t += t

ff = False
for i in range(len(s)):
    f = True
    for j in range(len(s)):
        if s[j] != t[i+j]:
            f = False
            break
    if not f:
        continue
    print('Yes')
    ff = True
    break
if not ff:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int k;
    cin>>k;
    string s1;
    cin>>s1;
    int n = s1.size();
    if(n<=k)
        cout<<s1<<endl;
    else
    {
        for(int i=0;i<k;i++)
            cout<<s1[i];
        cout<<"...\n";
    }
    return 0;
}



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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1e6 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}

void work()
{
    int k, n;
    cin >>k >>n;
    for(int i = 0; i < n; i++)
    {
        int x; cin >>x;
        k -= x;
    }
    puts(k <= 0 ? "Yes" : "No");
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,m,i,j,sum=0;
  scanf("%d %d",&n,&m);
  int a[n][m],b[m],c[n];
  for(i=0;i<n;i++)
    for(j=0;j<m;j++)
      scanf("%d",&a[i][j]);
  for(j=0;j<m;j++)
    scanf("%d",&b[j]);
  for(i=0;i<n;i++)
  {
    for(j=0;j<m;j++)
    {
      sum=sum+a[i][j]*b[j];
    }
    c[i]=sum;
    sum=0;
  }
  for(i=0;i<n;i++)
  {
    printf("%d\n",c[i]);
  }
  return 0;
}



Measured memory_bytes: 2112
#include<iostream>

using namespace std;

int main()
{
	int n;
	int a;
	int b;
cin >> n;
cin >> a;
cin >> b;
if (n * a >= b) {
	cout << b;
}
else if (n * a <= b) {
	cout << n * a;
}
return 0;
}

Measured memory_bytes: 256
/** "Ever tried.
         Ever failed.
               No matter.
                   Try Again.
                        Fail again.
                             Fail better.**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp  __builtin_popcount
#define pb push_back
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define Unique(n)        (n).erase(unique(s(n)), (n).end())
#define NumofDigits(n)   ((long long)log10(n)+1)
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
const  double EPS = 1e-9;
const int MOD = 1e9+7;
/*
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll fastpow(ll b, ll p)
{if(!p)return 1;ll ret = fastpow(b, p >> 1);ret *= ret;if(p&1)ret*= b;return ret;}
int dx[] = {- 1, 0, 0, 1, 0 };
int dy[] = { 0,- 1, 1, 0, 0 };*/

string s[105];
int main()
{
    ios_base::sync_with_stdio(0);
    int n,l;
    cin>>n>>l;
    for(int i=0;i<n;i++)
        cin>>s[i];
    sort(s,s+n);
    for(int i=0;i<n;i++)
        cout<<s[i];
}


Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main()
{
  unsigned long long n, ans = 0;
  cin >> n;
  if(n % 2 == 1){
    cout << 0;
    return 0;
  }
  n /= 2;
  for(unsigned long long i = 5;i <= n;i*=5){
    ans += (n/i);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
/// Thank you tanakh!!!
///  https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::f64::consts;

fn main() {
    input!(n: usize);
    let mut is_prime = vec![true; n + 10];
    is_prime[0] = false;
    is_prime[1] = false;
    for p in 2..is_prime.len() {
        if is_prime[p] {
            let mut i = p * 2;
            while i < is_prime.len() {
                is_prime[i] = false;
                i += p;
            }
        }
    }

    let mut ans = 0;
    for q in 0..(n + 1) {
        if !is_prime[q] {
            continue;
        }
        let p = 2;
        if p + q >= is_prime.len() {
            continue;
        }
        if is_prime[p + q] {
            ans += 1;
        }
    }
    println!("{}", ans * 2);
}



Measured memory_bytes: 15160
n = int(input())
a = list(map(int, input().split()))

cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]

cum.sort()
num = cum[0]
count = 1
ans = 0
for i in range(n):
    if cum[i+1] == num:
        count += 1
    else:
        ans += count * (count - 1) // 2
        num = cum[i+1]
        count = 1

if count > 1:
    ans += count * (count - 1) // 2

print(ans)




Measured memory_bytes: 26136
#include<iostream>
using namespace std;
int main(){
  long long int N;
  long long int a[5];
  long long int m;
  long long int ans;
  int i;
  cin >> N;
  for(i=0;i<5;i++){
    cin >> a[i];
    if(i==0){
      m = a[i];
    }else{
      if(m > a[i]){
	m = a[i];
      }else{
	//do nothing;
      }
    }
  }
  //cout << m << endl;
  ans = N/m + 5;
  if(N%m == 0){
    cout << ans-1 << endl;
  }else {
    cout << ans << endl;
  }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
nodes=[]
for i in range(n):
    nodes.append(input().split())

nodes.sort(key=lambda x:int(x[0]))
ans={}
#parent
for i in range(n):
    if int(nodes[i][1]) >=1:
        for j in nodes[i][2:]:
            ans[j]=[nodes[i][0]]

for i in range(n):
    if str(i) not in ans:
        ans[str(i)]=[str(-1)]
        
#depth
for key,value in ans.items():
    depth=0
    x=value[0]
    while int(x) != -1:
        x=ans[x][0]
        depth+=1
    ans[key].append(str(depth))


#type,c
for key in ans.keys():
    ans[key].append(nodes[int(key)][2:])
    if ans[key][0] == '-1':ans[key].append('root')
    elif ans[key][2] == []:ans[key].append('leaf')
    else:ans[key].append('internal node')


for i in range(n):
    I=str(i)
    print('node '+I+': parent = '+ans[I][0]+', depth = '+str(ans[I][1])+', '+ans[I][3]+', ['+', '.join(ans[I][2])+']') 
                                                             
                                                       


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

typedef long long ll;
typedef pair<int, pair<int, int>> piii;
//loop
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//STL
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

const int INF = 1e9;

int bubbleSort(vector<int> &A, int N)
{
    int swap_cnt = 0;
    bool flag = true;
    while (flag)
    {
        flag = false;
        FORD(j, N - 1, 1)
        {
            if (A.at(j) < A.at(j - 1))
            {
                swap(A.at(j), A.at(j - 1));
                swap_cnt++;
                flag = true;
            }
        }
    }
    return swap_cnt;
}

void Main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N)
    cin >> A.at(i);

    int swap_cnt = bubbleSort(A, N);

    REP(i, N)
    {
        if (i != 0)
        {
            cout << " ";
        }
        cout << A.at(i);
    }
    cout << endl;
    cout << swap_cnt << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    return 0;
}



Measured memory_bytes: 3208
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>

#ifdef PRINTERS
#include "printers.hpp"
using namespace printers;
#define tr(a)        cout<<a<<endl;
#else
#define tr(a)    
#endif

#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)    for(int i=a;i<b;i++)
using namespace std;

void solve(){
    int N,M;
    cin>>N>>M;
    string s[N];
    rep(i,0,N)cin>>s[i];
    string t[M];
    rep(i,0,M)cin>>t[i];
    rep(i,0,N-M+1){
        rep(j,0,N-M+1){
            bool good=1;
            rep(k,i,i+M){
                rep(l,j,j+M){
                    if(s[k][l]!=t[k-i][l-j])good=0;
                }
            }
            if(good){
                cout<<"Yes\n";
                return;
            }
        }
    }
    cout<<"No\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int w[10], k[10];

int main(void) {
  REP(i, 0, 10) cin >> w[i];
  REP(i, 0, 10) cin >> k[i];

  sort(w, w + 10);
  sort(k, k + 10);

  cout
    << accumulate(w + 7, w + 10, 0) << " "
    << accumulate(k + 7, k + 10, 0) << endl;

  return 0;
}

Measured memory_bytes: 3084
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){

  int n,d = 0;

  while(cin >> n, n){
    if(d) cout << endl;

    int a,b,c,z[100],tmp;
    string s[100],tmp2;

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

      z[i] = a * 3 + c;
    }

    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(z[j] > z[j - 1]){

	  tmp = z[j];
	  z[j] = z[j - 1];
	  z[j - 1] = tmp;

	  tmp2 = s[j];
	  s[j] = s[j - 1];
	  s[j - 1] = tmp2;
	}
      }
    }

    for(int i=0;i<n;i++) cout << s[i] << "," << z[i] << endl;
  
    d = 1;
  }
}

Measured memory_bytes: 1212
S=input()
lst=['A','C','G','T']
ans=0
a=0
i=0
while i<len(S):
    if not (S[i] in lst):
        i+=1
    else:
        a=1
        i+=1
        while i<len(S) and S[i] in lst:
            a+=1
            i+=1
    if ans<a:
        ans=a
    a=0
print(ans)

Measured memory_bytes: 8924
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  in n;
  in k;
  cin>>n>>k;
  vector<int> a(n);
  rep(i,n){
    int b;
    cin>>b;
    a.at(i)=b-1;
  }
  if(a.at(0)==0){
    cout<<1<<endl;
    return 0;
  }
  
  in ans=0;
  in time;//mod
  in x=0;//now
  
  vector<in> count(n,-1);
  count.at(0)=0;
  while(1){
    x=a.at(x);
    ans++;
    if(count.at(x)!=-1){
      //cout<<"x:"<<x<<" ans"<<ans<<endl;
      time=ans-count.at(x);
      break;
    }    
    
    count.at(x)=ans;
  }
  //cout<<"x:"<<x<<" count_x:"<<count.at(x)<<endl;
  //cout<<time<<endl;
  
  //k-=count.at(x);
  //in num=k%time;
  in num;
  in finalans;
  if(k<count.at(x)){
    num=k;
    rep(i,n){
      
    if(count.at(i)==num){
      finalans=i;
      finalans++;
      break;
    }
  }
  cout<<finalans<<endl;
    return 0;
  }
  else{
    num=(k%time)-(count.at(x)%time);
    if(num<0)
      num+=time;
  }
  rep(i,n){
    if(count.at(i)==num+count.at(x)){
      finalans=i;
      finalans++;
      break;
    }
  }
  cout<<finalans<<endl;
}


Measured memory_bytes: 5632
#include<iostream>
#include<set>

using namespace std;

int main(void){
    int N;
    cin >> N;
    set<int> v;
    for(int i=0; i<N; i++){
        int A;
        cin >> A;
        if(v.count(A)) v.erase(A);
        else v.insert(A);
    }

    int ans = v.size();

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        for (int i = n - 1; i >= 0; i--) {
            if(i != 0){
                System.out.print(a[i]+" ");
            }else{
                System.out.println(a[i]);
            }
        }

        sc.close();
    }
}


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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main() {
  int n;
  cin >> n;
  bool ans=false;
  for (int i=9; i > 0; i--){
    if (n%i==0 && n/i < 10){
      ans = true;
    }
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl; 
    
  return 0;
}


Measured memory_bytes: 256
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;


    


int main()
{
    int x,y;
    cin>>x>>y;
    if  ( x >= 0 && x <= 9 &&  y >= 0 && y<=9)
    {
        cout << x * y; 
    }
    else{
        cout << -1;
    }

   
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  int ans = 0;
  for(int i=1;i<=N;i++) ans += i;

  cout << ans << endl;
  return 0;
}


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

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll)(n) ; i++ )
#define DREP(i,m,n) for(ll i=(ll)(m) ; i > (ll)(n) ; i-- )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define p_b push_back
#define SZ(x) ((ll)(x).size()) //size()がunsignedなのでエラー避けに
#define endk '\n'


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //




// --------- library end - //


int main(){

  ll N = il();
  vector<ll> as;
  rep(i, N){
    as.push_back(il());
  }

  ll nowmax = 0;
  ll ans = 0;
  rep(i, N){
    ll a = as[i];
    if (a < nowmax){
      ans += nowmax - a;
      a = nowmax;
    }
    chmax(nowmax, a);
  }

  cout << ans << endk;



  
}

Measured memory_bytes: 5364
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

int dp[3050][8000];

int main() {
    int n, t;
    cin >> n >> t;
    vec a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    vector<P> p(n);
    rep(i, n) p[i] = make_pair(a[i], b[i]);

    sort(all(p));

    rep(i, 3010) rep(j, 8000) dp[i][j] = 0;

    int res = 0;

    rep(i, n) {
        int ni = i+1;
        rep(j, t) {
            chmax(dp[ni][j], dp[i][j]);
            chmax(dp[ni][j+p[i].first], dp[i][j] + p[i].second);
            chmax(res, dp[i][j] + p[i].second);
        }
    }

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

Measured memory_bytes: 94464
#include <iostream>
using namespace std;
int main(void){
    int a;
    cin>>a;
    int s=0;
    while(a>=500){
        s+=1000;
        a-=500;
    }
    while(a>=5){
        s+=5;
        a-=5;
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;



int main()
{

ll n ;
cin>>n;

ll ans =0;
for(ll i = 0 ; i <=n;i++)
  if(i%3&&i%5)
  {
     // cout<<i<<endl;
      ans+=i;
  }




cout<<ans<<endl;


 return 0;
}


Measured memory_bytes: 3640
import sys
input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import heapq
import bisect
import copy
import math
from collections import defaultdict

def warshall_floyd(d, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i * N +j] = min(d[i * N +j], d[i * N + k] + d[k * N + j])
    return d
MOD = 10**9 + 7
INF = 10**10

def dijkstra(n, graph, start):
    visited = [0 for i in range(n)]
    cost = [INF for i in range(n)]
    parents = [[] for i in range(n)]
    visited[start] = 1
    cost[start] = 0
    # cur = start
    pq = []
    for g in graph[start]:
        heapq.heappush(pq, g)
    while(pq):
        nxt = heapq.heappop(pq)
        # print(nxt)
        # print(cost)
        tcos, cur, tdist = nxt
        if cost[tdist] == cost[cur] + tcos:
            parents[tdist].append(cur)
        elif cost[tdist] > cost[cur] + tcos:
            cost[tdist] = cost[cur] + tcos
            parents[tdist] = [cur]
            for g in graph[tdist]:
                heapq.heappush(pq, g)

    res = []
    # print(parents)
    for i, par in enumerate(parents):
        for ppar in par:
            res.append((i, ppar))

    return res


def main():
    n, m = getlist()
    graph = [[] for i in range(n)]

    for i in range(m):
        a,b,c = getlist()
        graph[a-1].append((c, a-1, b-1))
        graph[b - 1].append((c, b-1, a-1))

    cands = []

    for start in range(n):
        res = dijkstra(n, graph, start)
        # print(res)
        for re in res:
            if re[0] < re[1]:
                cands.append(re)
            else:
                cands.append((re[1], re[0]))

    print(m - len(list(set(cands))))

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

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

bool solve2(int a, int b, int c) {
    bool ok = (a == (b ^ c));
    bool ok2 = (b == (a ^ c));
    bool ok3 = (c == (a ^ b));
    return ok && ok2 && ok3;
}

bool solve() {
    int N; cin >> N;
    vector<int> a(N);
    rep(i, 0, N) cin >> a[i];
    sort(a.begin(), a.end());
    map<int, int> ma;
    rep(i, 0, N) ma[a[i]]++;
    vector<int> b;
    for(auto p : ma) b.push_back(p.first);
    if(ma.size() == 1 && a[0] == 0) return true;
    if(ma.size() == 2 && a[0] == 0) return ma[0] * 2 == ma[b[1]];
    if(ma.size() != 3) return false;
    for(auto p : ma) if(ma[a[0]] != p.second) return false;

    return solve2(b[0],b[1],b[2]) || solve2(b[0], b[1], b[2]) || solve2(b[1], b[0], b[2]) || solve2(b[1],b[2],b[3]) || solve2(b[2], b[0], b[1]) || solve2(b[2], b[1], b[0]);
}

int main() {
    cout << (solve() ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin>>N;
    bool flg=false;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j == N){
                flg = true;
            }
        }
    }
    
    if(flg){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3560
N = gets.to_i
$board = 2.times.map { gets.split.map(&:to_i) }

def dfs(i, j, score)
  score += $board[i][j]
  if i == 1 && j == N - 1
    return score
  end
  if i == 0 && j < N - 1
    [
      dfs(i, j + 1, score),
      dfs(i + 1, j, score)
    ].max
  elsif j == N - 1
    dfs(i + 1, j, score)
  else
    dfs(i, j + 1, score)
  end
end
ans = dfs(0, 0, 0)
puts ans


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

int main() {
  	string S;
  	cin >>S;
  	if(S[2] == S[3] && S[4] == S[5]) {
      cout << "Yes" << endl;
    }else {
	  cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
fun main() {
    val n = readLine()!!.toInt()
    val m = n - 1
    val t = Array(n) { IntArray(m) }
    for (i in 0 until n) {
        val a = readLine()!!.split(' ').map { it.toInt() - 1 }
        for (j in 0 until m) {
            t[i][j] = a[j]
        }
    }

    val cur = IntArray(n)
    var q = mutableSetOf<Pair<Int, Int>>()

    fun check(i: Int) {
        if (cur[i] == m) return
        val j = t[i][cur[i]]
        if (cur[j] == m) return
        if (t[j][cur[j]] != i) return
        q.add(if (i < j) i to j else j to i)
    }

    for (i in 0 until n) {
        check(i)
    }

    var day = 0

    while (q.isNotEmpty()) {
        day++
        val prev = q
        q = mutableSetOf()

        for ((i, j) in prev) {
            cur[i]++
            cur[j]++
        }

        for ((i, j) in prev) {
            check(i)
            check(j)
        }
    }

    val ans = if (cur.all { it == m }) {
        day
    } else {
        -1
    }

    println(ans)
}


Measured memory_bytes: 65736
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var nk = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var xy = new int[nk[0]][];
        for (var i = 0; i < nk[0]; i++)
            xy[i] = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var xar = xy.Select(p => p[0]).OrderBy(v => v).ToArray();
        var yar = xy.Select(p => p[1]).OrderBy(v => v).ToArray();
        var res = long.MaxValue;
        for (var xf = 0; xf < nk[0] - 1; xf++)
            for(var xl=xf+1;xl<nk[0];xl++)
                for(var yf=0;yf<nk[0]-1;yf++)
                    for(var yl = yf + 1; yl < nk[0]; yl++)
                    {
                        var cou = 0;
                        var xfir = xar[xf];
                        var xlas = xar[xl];
                        var yfir = yar[yf];
                        var ylas = yar[yl];
                        for (var i = 0; i < nk[0]; i++)
                            if (xfir <= xy[i][0] && xy[i][0] <= xlas && yfir <= xy[i][1] && xy[i][1] <= ylas)
                                cou++;
                        if (cou >= nk[1])
                            res = Min(res, (long)(xlas - xfir) * (ylas - yfir));
                    }
        WriteLine(res);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 13524
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> v(n);
    int max_v = -INF;
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
        max_v = max(v[i], max_v);
        sum += v[i];
    }
    sum -= max_v;
    cout << (sum <= max_v ? "No" : "Yes") << endl;
    return 0;
}



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

int main()
{
	int long long id,curr;
	cin >> id;
	id--;
	vector<char> name;
	while (id >=0) {
		name.push_back('a'+(id%26));
		id = id/ 26-1;
	}

	for (int i=size(name)-1;i>=0;i--)
	{
		cout << name[i];
	}
	return 0;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define mx 100005

int t, u;
int main(){
  scanf("%d", &u);
  for(t = 0; t < 18;){
    printf("%d\n", (t%9+1)*(t/9?10:1)+(t/9?9:0));
    if(++t == u) return 0;
  }
  for(int i = 0; i < 15; i++){
    for(int j = 1; j < 10; j++){
      for(int k = 0; k < 10; k++){
        for(int l = 0; l < 10; l++){
          if((j*100+k*10+l+1) <= (i*9+j+k+l)*(l-9?1:k-9?10:l-9?100:1000)){
            printf("%d%d%d", j, k, l);
            for(int m = 0; m < i; m++) printf("9");
            puts("");
            if(++t == u) return 0;
          }
        }
      }
    }
  }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var w, h int
	fmt.Scan(&w, &h)

	if w > h {
		h, w = w, h
	}

	if w == 1 && h == 1 {
		fmt.Println(1)
		return
	}

	if w == 1 {
		fmt.Println(h - 2)
		return
	}

	fmt.Println((w - 2) * (h - 2))
}


Measured memory_bytes: 512
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;

struct edge{
	int to;
	int cost;
};

vector<edge> graph[100010];
int come[100010];
struct edge e;

int search(int x){
	int i;

	come[x]=1;

	for(i=0;i<graph[x].size();i++){
		e=graph[x][i];
		if(come[e.to]==-1){
			search(e.to);
		}
	}

	return 0;
}

int main(void)
{
	//変数の宣言
	int r,d,x;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;



	//データの読み込み


	scanf("%d %d %d",&r,&d,&x);
//	scanf_s("%d %d %d",&r,&d,&x);

//	scanf("%s",&s);
//	scanf_s("%s",&s,5);


/*	for(i=0;i<m;i++){
//		scanf("%d %d %d",&x,&y,&z);
		scanf_s("%d %d %d",&x,&y,&z);
	}

	for(i=1;i<=n;i++){
		come[i]=-1;
	}*/

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理


	//	printf("計算部分終了\n");

	//出力
	for(i=0;i<10;i++){
		x=r*x-d;
		printf("%d\n",x);
	}


	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 2560
from fractions import gcd

a,b,c,d = map(int,input().split())
count = (b-(b//c+b//d-b//int(c*d/gcd(c,d)))) - ((a-1)-((a-1)//c+(a-1)//d-(a-1)//int(c*d/gcd(c,d))))
print(count)

Measured memory_bytes: 5048
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
#include<numeric>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    string s;
    cin >> s;
    int cnt = 0;
    if ( s.length() < 3 ) {
        cout << 0 << endl;
        return 0;
    }
    vector<ll> cont_a_cnt(s.length()+2, 0);
    vector<ll> cont_bc_cnt(s.length()+2, 0);
    rep(i, s.length()) {
        if ( s[i] == 'A' ) {
            cont_a_cnt[i+1] = cont_a_cnt[i]+1;
        }
        if ( i < 2 ) continue;
        if ( s[i-1] == 'B' && s[i] == 'C' ) {
            cont_bc_cnt[i+1] = cont_bc_cnt[i] = cont_bc_cnt[i-1] + 1;
        }
    }
    ll a_num = 0;
    ll b_num = 0;
    bool a_flg = 0;
    bool b_flg = 0;
    ll ans = 0;
    for ( int i = 1; i <= s.length()+1; ++i ) {
//        cout << i << " " << a_num << " " << b_num << endl;
        if ( cont_a_cnt[i] != 0 ) {
            a_flg = 1;
        }
        else if ( a_flg ) {
            a_num += cont_a_cnt[i-1];
            a_flg = 0;
            b_flg = 1;
        }
        if ( !b_flg ) {
            continue;
        }
        if ( cont_bc_cnt[i] == 0 ) {
            b_num = cont_bc_cnt[i-1];
//            cout << b_num << endl;
            ans += a_num * b_num;
            b_flg = 0;
            if ( cont_a_cnt[i] == 0 ) {
                a_num = 0;
            }
            b_num = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3844
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 29;
const double EPS = 1e-10;

int p[100010];
int dist[100020];

int main(){
  int N;
  while(cin >> N){
    rep(i, N) cin >> p[i];

    fill(dist, dist + 100020, INF);
    dist[0] = 0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0, 0));
    while(!que.empty()){
      P p2  = que.top(); que.pop();
      int v = p2.second;
      int cost = p2.first;
      if(v >= N - 1) {
	cout << cost << endl;
	break;
      } 
      if(dist[v] < cost) continue;
      if(p[v] == 0){
	rep2(i,1,7){
	  int nxt = v + i;
	  if(dist[nxt] > cost + 1){
	    dist[nxt] = cost + 1;
	    que.push(P(cost + 1, nxt));
	  }
	} 
      }else{
	int nxt = v + p[v];
	if(dist[nxt] > cost){
	  dist[nxt] = cost;
	  que.push(P(cost, nxt));
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1672
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-7
//#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main() 
{
    fastio
    int n;
    cin>>n;
    set<string> st;
    for(int i = 0; i<n; ++i) {
        string s;
        cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<endl;
}   

Measured memory_bytes: 19244
#include <bits/stdc++.h>
using namespace std;
long long x[10000010], y[10000010];
#define int long long
signed main()
{

   cin.tie(0);
   ios::sync_with_stdio(false);

   int a, b, n, cnt = 0, ans = 0;
   string s;

   cin>>a>>b;
   if(a-b*2<=0) cout<<0<<'\n';
   else cout<<a-b*2<<'\n';
}

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

int main() {
  ll h, w, d; cin >> h >> w >> d;
  vector <pair <ll, ll>> v(h*w, pair <ll, ll> ());
  rep(i, h) {
    rep(j, w) {
      ll a; cin >> a;
      v.at(a-1) = make_pair(i, j);
    }
  }
  vector <ll> imos(h*w, 0);
  rep(i, d) {
    ll tmp = i;
    while (tmp+d < h*w) {
      imos.at(tmp+d) = imos.at(tmp)+abs(v.at(tmp+d).first-v.at(tmp).first)+abs(v.at(tmp+d).second-v.at(tmp).second);
      tmp += d;
    }
  }
  ll q; cin >> q;
  rep(i, q) {
    ll l, r; cin >> l >> r;
    l--; r--;
    cout << imos.at(r) - imos.at(l) << endl;
  }
}

Measured memory_bytes: 5340
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define MOD 1000000007
#define deb(n) cout<<"[ "#n<<" = "<<n<<" ]"<<endl;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const long long  MAX = 1 << 18;
int case_no = 1;
#define w(x) int x; cin>>x; while(x--)

int main() {
	FIO
	int n; cin >> n;
	int a = 0, b = 0, c = 0, d = 0;
	for(int i = 0; i < n; i++) {
		string str;
		cin >> str;
		if(str == "AC") a++;
		else if(str == "WA") b++;
		else if(str == "TLE") c++;
		else d++;
	}
	cout << "AC x " << a << endl;
	cout << "WA x " << b << endl;
	cout << "TLE x " << c << endl;
	cout << "RE x " << d << endl;

	return 0;
}

Measured memory_bytes: 3656
#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>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n;
  string s;
  cin >> n;
  cin >> s;
  if(n % 2 == 1) return cout << "No", 0;
  string x = s.substr(0, n / 2);
  string y = s.substr(n / 2, n / 2);
  cout << (x == y ? "Yes" : "No");
}

Measured memory_bytes: 256
import math
from functools import lru_cache

x,y = map(int, input().split(' '))
# x, y = 999999, 999999
MOD = 10 ** 9 + 7


# 08        01
# 07          04
# 06      01    06
# 05        03    04
# 04    01    03    01
# 03      02    01
# 02  01    01
# 01    01
# 00ST
#   000102030405060708

# 到達可能地点の座標はx+y%3==0
# 到達可能手数は座標位置についてパスカルの三角形になる


# 到達可能か調べる
if x <= 2 * y and y <= x * 2 and (x + y) % 3 == 0:
    # 段数と位置を調べる
    total = (x + y) // 3
    # kx = 2 * total - x + 1
    # ky = 2 * total - y + 1
    n=x-total
    # print(total, k)

    # nCk 三角数n段目k番目の数は total! / k!(total-k)! であり
    # 回答は nCk / MOD なので
    # total! % MOD * 1/k! % MOD * (total-k)! % MOD と書ける

    fac = [1, 1]
    ifac = [1, 1]
    inv = [0, 1]

    for i in range(2, total + 1):
        fac.append(fac[-1] * i % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        ifac.append((ifac[-1] * inv[-1]) % MOD)

    def c(n, k):
        k = min(k, n-k)
        # if total < k: return 0
        # if total < 0 or k < 0: return 0
        return fac[n] * ifac[k] * ifac[n-k] % MOD

    # print(nck(total - 1, k - 1))

    print(c(total, n))
else:
    print(0)
    exit()


Measured memory_bytes: 83048
n=int(input())
a=[0]*(n+1)
b=[0]*n
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans=0
for i in range(n):
  if (a[i]>b[i]):
    ans+=b[i]
    b[i]=0
    a[i]-=b[i]
  else:
    ans+=min(b[i],a[i]+a[i+1])
    a[i+1]-=b[i]-a[i]
    a[i]=0
    a[i+1]=max(a[i+1],0)
  #print(a)
  #print(b)
print(ans)

Measured memory_bytes: 19504
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	int n;
	cin >> n;
	map<string, int>m;
	m.insert(make_pair("AC", 0));
	m.insert(make_pair("WA", 0));
	m.insert(make_pair("TLE", 0));
	m.insert(make_pair("RE", 0));
	while (n--) {
		string str;
		cin >> str;

		m[str]++;
	}
	cout <<"AC x "<< m.at("AC") << "\n"
		<<"WA x " <<m.at("WA") << "\n" 
		<<"TLE x "<< m.at("TLE") << "\n"
		<<"RE x "<< m.at("RE");
}


Measured memory_bytes: 3196
n=int(input())
f=[0]*n
a=list(map(int,input().split()))
f[0]=0
f[1]=abs(a[0]-a[1])
for i in range(2,n):
    a1=abs(a[i]-a[i-2])
    b=abs(a[i]-a[i-1])
    f[i]=min((f[i-2]+a1),(f[i-1]+b))
print(f[n-1])

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

using namespace std;

const int maxn = 2e5 + 50 ;

int v[maxn] ,vv[maxn];

int main() {
	int n ; scanf("%d",&n) ;
	for (int i = 1 ; i <= n ; i ++ ) {
		scanf("%d",&v[i]) ;
		vv[i] = v[i] ;
	}
	sort(v + 1 ,v + n + 1 ) ;
	for (int i = 1 ; i <= n ; i ++ ) {
		if ( vv[i] == v[n] ) {
			printf("%d\n" ,v[n-1]) ;
		} else {
			printf("%d\n",v[n]) ;
		}
	}
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
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/gcd(a,b)*b;}

int main() {
  ll n; cin >> n;
  map<ll,ll> m;
  ll a[n];
  FOR(i,0,n-1){
    cin >> a[i];
    ++m[a[i]];
  }
  ll suma = 0;
  for(auto x: m){
    suma += x.second * (x.second-1) / 2;
  }
  FOR(i,0,n-1){
    ll ans = 0;
    ans = suma - (m[a[i]] * (m[a[i]]-1) / 2) + max((m[a[i]]-1) * (m[a[i]]-2) /2,0LL);
    cout << ans << "\n";
  }


}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(LL)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

#define INF 1LL << 50


int cost[403][403];
LL bs[403][403];

int main(){
    REP(i,403)REP(j,403){
        cost[i][j]=20000;
        bs[i][j]=0;
    }
    int N,Ma,Mb;
    cin>>N>>Ma>>Mb;
    int a[41],b[41],c[41];
    cost[0][0]=0;
    
    REP(i,N){
        cin>>a[i]>>b[i]>>c[i];
    }
    
    REP(i,401)REP(j,401){
        int pos=-1;
        REP(p,N)if(i-a[p]>=0&&j-b[p]>=0&&!(bs[i-a[p]][j-b[p]]&(1<<p))){
            if(cost[i][j]>cost[i-a[p]][j-b[p]]+c[p]){
                cost[i][j]=cost[i-a[p]][j-b[p]]+c[p];
                //cout<<i<<" "<<j<<" "<<cost[i][j]<<endl;
                pos=p;
            }
        }
        if(pos!=-1)bs[i][j]=bs[i-a[pos]][j-b[pos]]|(1<<pos);
    }
    int res=20000;
    for(int i=1;Ma*i<=400&Mb*i<=400;i++){
        int ares=Ma*i,bres=Mb*i;
        res=min(res,cost[ares][bres]);
    }
    if(res<10000)cout<<res<<endl;
    else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 2176
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#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(c++17)
#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;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

signed main()
{
  int x, y, z;
  cin >> x >> y >> z;

  swap(x, z);
  swap(z, y);
  cout << x << " " << y << " " << z << endl;
}


Measured memory_bytes: 256