akhauriyash/Code-Regression huggingface dataset:
#include <unistd.h>
#include <cstdlib>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))

int input() {
    char buf[6];
    int size = read(0, buf, 6);
    int n = 0;
    REP (i, 5) {
        n = n * 10 + buf[i] - '0';
    }
    return n;
}
void output(int n) {
    char buf[20];
    char *s = buf + sizeof buf;
    *(-- s) = '\n';
    if (not n) *(-- s) = '0';
    for (; n; n /= 10) {
        *(-- s) = (n % 10) + '0';
    }
    write(1, s, buf + sizeof buf - s);
}


__attribute__((constructor))
static void _main() {
    int a = input();
    int b = input();
    int cnt = 0;
    REP (x, 10) REP (y, 10) REP (z, 10) {
        int n = x * 10000 + y * 1000 + z * 100 + y * 10 + x;
        cnt += (a <= n and n <= b);
    }
    output(cnt);
    _exit(EXIT_SUCCESS);
}

int main() {
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {
    string s;
    cin>>s;
    string t = "CODEFESTIVAL2016";

    int ans=0;
    rep(i,s.size())
    if(s[i]!=t[i]) ans++;
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

const int mod = 1e9 + 7;


int dp[100001][2];

ll dfs(int v, int p, int c, vector<vector<int>> &G) {
    if (dp[v][c]) return dp[v][c];

    ll ret = 1;
    for (int i = 0; i < G[v].size(); i++) {
        if (G[v][i] == p) continue;
        if (c == 0) {
            ret *= dfs(G[v][i], v, 0, G) + dfs(G[v][i], v, 1, G);
            ret %= mod;
        } else{
            ret *= dfs(G[v][i], v, 0, G);
            ret %= mod;
        }
    }
    return dp[v][c] = ret;
}

void solve() {
    int N;
    cin >> N;
    vector<vector<int>> G(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cout << (dfs(0, -1, 0, G) + dfs(0, -1, 1, G)) % mod << endl; 
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 14848
$N=<>;
<>=~/ (.*) /,$
$`{$1}=$
$1{$`}=$' for 2..$N;
@s=<>=~$"*$';
map{$d[$_]or$d[$_]=$d[$u]+$$u{$_},push@s,$_}keys%$u while$u=pop@s;
/ /,print$d[$`]+$d[$'],$/for<>

Measured memory_bytes: 125696
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli n,k;
	cin>>n>>k;

	lli flag=0;
	vector<lli> a(n);
	REP(i,0,n){
		cin>>a[i];
		if(a[i]>=0)flag++;
	}

	/*data[i], a0からaiまでのプラスのみ足し合わせた数*/
	vector<lli> data(n+1,0);
	data[0] = max(0LL,a[0]);

	REP(i,1,n)data[i] = data[i-1] + max(0LL,a[i]);

	lli sum = 0;
	/*先頭k個を黒にしたときの尺取りを行う*/
	REP(i,0,k)sum += a[i];
	if(DEBUG)cout<<"first sum ="<<sum<<endl;

	data[n] = data[n-1];
	lli ans = -INF;
	if(flag==n)ans = data[n];
	/*黒で塗った時*/
	ans = max(ans,sum + data[n-1]-data[k-1]);
	if(DEBUG)cout<<"BALL ans="<<ans<<endl;
	/*白で塗った時*/
	ans = max(ans,data[n-1]-data[k-1]);
	if(DEBUG)cout<<"WALL ans="<<ans<<endl;

	if(DEBUG){
		for(lli i=0;i<n;i++){
			cout<<data[i]<<endl;
		}
	}

	if(DEBUG)cout<<"ans="<<ans<<endl;
	for(lli i=k;i<n;i++){
		if(DEBUG)cout<<"i="<<i<<endl;
		sum += a[i];
		sum -= a[i-k];
		if(DEBUG)cout<<"sum="<<sum<<endl;
		lli next = sum + data[n-1] - data[i];
		if(i-k-1>=0)next += data[i-k];
		ans = max(ans,next);
		if(DEBUG)cout<<"BALL ans="<<ans<<endl;
		ans = max(ans,data[n-1] - data[i] + data[i-k]);
		if(DEBUG)cout<<"WALL ans="<<ans<<endl;
	}

	cout<<ans<<endl;

	return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<int> v(n);
    map<int,int> mp;
    for(auto& i : v){
        cin >> i;
        mp[i]++;
    }

    bool flag = true;
    
    REP(i, 30){
        int even = 0;
        for(auto j : v){
            if(!((j >> i) & 1)) even++;
        }
        if(!(even == n || even*3 == n)) flag = false;
    }

    if(mp.size() > 3) flag = false;

    cout << (flag ? "Yes" : "No") << endl;
    
    





    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <math.h>
using namespace std;


int negative(int* number, int m, int N, int minIdx, pair<int, int>* operation) {
	for (int i = N - 1; i >= 0; --i) {
		while (number[i] > number[i + 1]) {
		    if (number[minIdx] > number[i]) {
		    	minIdx = i;
		    }
			number[i] += number[minIdx];
			operation[m] = make_pair(minIdx + 1, i + 1);
			++m;
			if (number[minIdx] > number[i]) {
		    	minIdx = i;
		    }
		}
	}
	return m;
}

int positive(int* number, int m, int N, int maxIdx, pair<int, int>* operation) {
	for (int i = 1; i < N; ++i) {
		while (number[i] < number[i - 1]) {
		    if (number[maxIdx] < number[i]) {
		    	maxIdx = i;
		    }
			number[i] += number[maxIdx];
			operation[m] = make_pair(maxIdx + 1, i + 1);
			++m;
			if (number[maxIdx] < number[i]) {
		    	maxIdx = i;
		    }
		}
	}
	return m;
}

int main() {
	int N;
	cin >> N;
	int* number = new int [N];
	int maxIdx = 0;
	int minIdx = 0;
	for (int i = 0; i < N; ++i) {
		cin >> number[i];
		if (number[maxIdx] < number[i]) {
			maxIdx = i;
		}
		if (number[minIdx] > number[i]) {
			minIdx = i;
		}
	}
	int m = 0;
	pair<int, int>* operation = new pair<int, int>[2 * N];
	
	if (number[minIdx] < 0 && number[maxIdx] > 0) {
		if (-number[minIdx] > number[maxIdx]) {
			for (int i = 0; i < N; ++i) {
				if (number[i] > 0) {
					number[i] += number[minIdx];
					operation[m] = make_pair(minIdx + 1, i + 1);
					++m;
				}
			}
			// all is negative
			m = negative(number, m, N, minIdx, operation);
		} else {
			for (int i = 0; i < N; ++i) {
				if (number[i] < 0) {
					number[i] += number[maxIdx];
					operation[m] = make_pair(maxIdx + 1, i + 1);
					++m;
				}
			}
			//all is positive
			m = positive(number, m, N, maxIdx, operation);
		}
	} else if (number[maxIdx] <= 0) {
		//all is negative
		m = negative(number, m, N, minIdx, operation);
	} else if (number[minIdx] >= 0) {
		// all is positive
		m = positive(number, m, N, maxIdx, operation);
	}
	cout << m << endl;	
	for (int i = 0; i < m; ++i) {
		cout << operation[i].first << " " << operation[i].second << endl; 
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define X 100
int main(){
    int A[X],N,i,j,k,flag=1,count=0;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    while(flag){
        flag=0;
        for(j=N-1;j>0;j--){
            k=A[j];
            if(A[j]<A[j-1]){
                A[j]=A[j-1];
                A[j-1]=k;
                flag=1;
                count++;
            }
        }
    }
    for(i=0;i<N-1;i++){
        printf("%d ",A[i]);
    }
    printf("%d\n",A[i]);
    
    printf("%d\n",count);
    
    return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <list>
using namespace std;

int main()
{
    int L, R;
    cin >> L >> R;
    if ((R - L) >= 2019)
    {
        cout << 0 << endl;
    }
    else
    {
        int ans = 2018;
        for (int i = L; i < R; i++)
        {
            int lmod = i % 2019;
            for (int j = i + 1; j <= R; j++)
            {
                int rmod = j % 2019;
                int tmp = (lmod * rmod) % 2019;
                if (tmp < ans)
                {
                    ans = tmp;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static long [][]memo;
	
	static int [] w,v;
	static int n;
	public static long dp(int ne,int we) {
		if(ne==n)
			return 0;
		if(memo[ne][we]!=-1)
			return memo[ne][we];
		long t=0,l=-1;
		if(we>=w[ne])
		t=v[ne]+dp(ne+1,we-w[ne]);
		l=dp(ne+1,we);
		return memo[ne][we]=Math.max(t, l);
		 
	}
	public static void main (String[]args) {
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int wmax=sc.nextInt();
		w=new int[n];
		v=new int[n];
		memo=new long[n][wmax+1];
		for(long[]x:memo) {
			Arrays.fill(x,-1);
		}
		for(int i=0;i<n;i++) {
			w[i]=sc.nextInt();
			v[i]=sc.nextInt();
		}
		for(int i=n-1;i>0;i-=10)
			dp(i,wmax);
		System.out.print(dp(0,wmax));
				
		
		
		sc.close();
	}

		
	}




Measured memory_bytes: 131584
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
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():
    N=I()
    ans = inf
    for i in range(1,int(sqrt(N)+1)):
        if N%i==0:
            ans = min(ans, i+N//i)
    print(ans-2)
if __name__ == '__main__':
    main()

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int n;
int a[100010];
map<int,int> cnt;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  rep(i,n)cin>>a[i];
  ll res=n;
  for(int i=0;i<n;i+=2)cnt[a[i]]++;
  ll mxa=0,mxacnt=0;
  for(auto it : cnt){
    if(mxacnt<it.se){
      mxa=it.fi; mxacnt=it.se;
    }
  }
  cnt.clear();
  for(int i=1;i<n;i+=2)cnt[a[i]]++;
  ll mxb=0,mxbcnt=0;
  for(auto it : cnt){
    if(mxbcnt<it.se){
      mxb=it.fi; mxbcnt=it.se;
    }
  } 
  if(mxa==mxb){
    int resa=n,resb=n;
    {
      cnt.clear();
      for(int i=1;i<n;i+=2)cnt[a[i]]++;
      ll mxccnt=0;
      for(auto it : cnt){
        if(it.fi==mxa)continue;
        maxch(mxccnt,it.se);
      }
      resa-=mxacnt+mxccnt;
    }
    {
      cnt.clear();
      for(int i=0;i<n;i+=2)cnt[a[i]]++;
      ll mxccnt=0;
      for(auto it : cnt){
        if(it.fi==mxa)continue;
        maxch(mxccnt,it.se);
      }
      resb-=mxbcnt+mxccnt;
    }
    res=min(resa,resb);
  }else{
    res-=mxacnt+mxbcnt;
  }
  cout<<res<<endl;
  return 0;
}


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

using namespace std;

const int INF = 10000000;

int main(int argc, char *argv[])
{
  int v;
  cin >> v;

  cout << 180*(v-2) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};


class union_find {
private:
  int component;
  std::vector<int> parent;

public:
  union_find() = default;
  union_find(int size_) { init(size_); }

  void init(int size_) {
    component = size_;
    parent.assign(size_, -1);
  }

  int count_components() const { 
    return component; 
  }
  int component_size(int i) { 
    return -parent[find_parent(i)]; 
  }
  bool same_component(int i, int j) { 
    return find_parent(i) == find_parent(j); 
  }

  int find_parent(int i) {
    if (parent[i] < 0) {
      return i;
    }
    else {
      return parent[i] = find_parent(parent[i]);
    }
  }

  bool unite(int i, int j) {
    i = find_parent(i);
    j = find_parent(j);
    if (i == j) {
      return false;
    }
    if (parent[i] > parent[j]) {
      std::swap(i, j);
    }
    parent[i] += parent[j];
    parent[j] = i;
    --component;
    return true;
  }

};

int main() {
  int N, Q;
  int64_t M;
  std::cin >> N >> M >> Q;
  std::vector<int> A(Q), B(Q), C(Q);
  union_find dsu(N);
  for (int i: range(0, Q)) {
    std::cin >> A[i] >> B[i] >> C[i];
  }
  std::vector<int> order(Q);
  std::iota(order.begin(), order.end(), 0);
  std::sort(order.begin(), order.end(), [&](int i, int j) {
    return C[i] < C[j];
  });
  for (int i: order) {
    if (C[i] == 0) {
      dsu.unite(A[i], B[i]);
    }
    else {
      if (dsu.same_component(A[i], B[i])) {
        std::cout << "No\n";
        return 0;
      }
    }
  }
  if (M == N - 1) {
    std::cout << (C[order.back()] == 0 ? "Yes" : "No") << '\n';
    return 0;
  }
  int64_t cmp = dsu.count_components();
  if (cmp <= 2) {
    std::cout << "No\n";
    return 0;
  }
  std::cout << (N - cmp + cmp * (cmp - 1) / 2 >= M ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 2176
package main

import "fmt"

func main() {
	var n, p int
	fmt.Scan(&n)
	fmt.Scan(&p)

	vals := map[int]int{}
	var re int
	for index := 0; index < n; index++ {
		var nn int
		fmt.Scan(&nn)
		for j := 0; j < nn; j++ {
			var v int
			fmt.Scan(&v)
			vals[v]++
		}
	}

	for _, item := range vals {
		if item == n {
			re++
		}
	}
	fmt.Println(re)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define INF 1<<30
#define MAX 100005
#define ll long long
#define speed ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;
int main()
{
    speed;
    ll N,W;
    cin>>N>>W;
    ll wt[N],val[N];
    for(ll i=0;i<N;i++) cin>>wt[i]>>val[i];
    ll K[N+1][W+1];
    for(ll i=0;i<=N;i++)
    for(ll j=0;j<=W;j++){
        if(i==0||j==0)
            K[i][j]=0;
        else if(wt[i-1]<=j)
            K[i][j]=max(K[i-1][j-wt[i-1]]+val[i-1],K[i-1][j]);
        else
            K[i][j]=K[i-1][j];
    }
    cout<<K[N][W];
}


Measured memory_bytes: 79232
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;


const ll N   =  500005;
const ll mod = 1e9 + 7;



void solve(){

  ll x=0,y=0,c=0,ans=0;
  ll n,m,k;
  cin>>k >> n;

  ll a[n];
  for (ll i = 0; i < n; ++i){
  cin>>a[i];
  c+=a[i];
  }
  c(max(-1LL,k-c));

}

signed main(){
     
  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  //int T;cin >> T;while (T--)
  solve();
  return 0;
}


Measured memory_bytes: 3696
#include <iostream>
int main(){
  int x1,y1,x2,y2,dx,dy;
  std::cin>>x1>>y1>>x2>>y2;
  dx=x2-x1;dy=y2-y1;
  std::cout<<x2-dy<<' '<<y2+dx<<' '<<x2-dy-dx<<' '<<y2+dx-dy<<"\n";
}

Measured memory_bytes: 256
<?php
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext()
    {
        return $this->pointer < $this->count;
    }
    public function nextInt()
    {
        return (int)$this->next();
    }
    public function nextDouble()
    {
        return (float)$this->next();
    }
}
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b


list($N, $K) = sscanf(trim(fgets(STDIN)), "%d %d");
$item = [];
$sc = new Scanner();
for ($i = 1; $i <= $N; $i++) {
    $item[$i] = $sc->nextInt();
}

sort($item);
$sum = 0;
for ($i = 0; $i < $K; $i++) {
    $sum += $item[$i];
}
print($sum);


Measured memory_bytes: 16224
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String[] tapMove = scanner.nextLine().split("");

		String ans = "Yes";
		for (int i = 0; i < tapMove.length; i++) {
			if((i + 1) % 2 == 0) {
				if(tapMove[i].equals("R")) {
					ans = "No";
					break;
				}
			}
			else {
				if(tapMove[i].equals("L")) {
					ans = "No";
					break;
				}
			}
		}
		
		System.out.println(ans);

	}
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int maxn = 1000000 + 10;
 
template<typename T> T read() {
	T n(0), f(1);
	char ch = getchar();
	for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
	for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int n;
int sg[maxn];
vector<int> G[maxn];

void dfs(int u, int f = 0) {
    sg[u] = 0;
    for(int i = 0; i < int(G[u].size()); i++) {
        int v = G[u][i];
        if(v == f) continue;

        dfs(v, u);
        sg[u] ^= sg[v] + 1;
    }
}

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif

    cin >> n;
    for(int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        G[x].pb(y);
        G[y].pb(x);
    }

    dfs(1);
    puts(sg[1] ? "Alice" : "Bob");

    return 0;
}


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

int main() {
  string S;
  cin >> S;
  if (S == "hi" || S == "hihi" || S == "hihihi" || S == "hihihihi" || S == "hihihihihi")
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
S = input()
n = len(S)-1
result = 0
for i in range(2 ** n):
    sum = 0
    temp = ''
    for j in range(n):
        temp += S[j]
        if (i >> j) & 1:
            sum += int(temp)
            temp = ''
    sum += int(temp+S[-1])
    result += sum
print(result)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long  ll;
 
int main(){
  int N; cin >> N;
  string S; cin >> S;
 
  ll ans = 0;
  int phase = 1;
  for(int a=0; a<10; a++) {
      for(int b=0; b<10; b++) {
          for(int c=0; c<10; c++) {

              for(int i=0; i<N; i++) {
                  if(phase==1 && a==((int)S[i]-'0')) {
                      phase++;
                  } else if(phase==2 && b==((int)S[i]-'0')) {
                      phase++;
                  } else if(phase==3 && c==((int)S[i]-'0')) {
                      ans++;
                      phase=1;
                      break;
                  }
              }
              phase=1;

          }
      }
  }
  cout << ans <<endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

ans = 0

b = [0]
for i in range(n):
	b.append(b[i] + a[i])

c = Counter(b)

for value in c.values():
	ans += value * (value - 1) // 2
    
print(ans)

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

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int sum = 0;
    rep(i, N) sum += A[i];
    if (sum >= H)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main () {
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=min(a,b);i>=1;i--)
    {
        if(a%i==0&&b%i==0)
        {
            k--;
            if(k==0)cout<<i<<endl;
        }
    }
}


Measured memory_bytes: 256
n, q = map(int,input().split())
s = list(input())
x = [0]
ans = 0
for i in range(n-1):
	if s[i] == "A" and s[i+1] == "C":
		ans += 1
		x.append(ans)
	else:
		x.append(ans)

for j in range(q):
	l, r = map(int,input().split())
	print(x[r-1]-x[l-1])

Measured memory_bytes: 6872
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n, m = map(int, input().split())

if n % m == 0:
  print(int(n/m))
  exit()
else:
  lst = make_divisors(m)[::-1]
  for i in lst:
    if i == 1:
      print(i)
      exit()
    if m - i*(n-1) > 0:
      if (m - i*(n-1)) % i == 0:
        print(i)
        exit()
    else:
      continue


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

int main(){
  ll N, M;
  cin >> N >> M;

  ll sum = 0;
  for(ll i=0; i<M; i++){
    ll tmp;
    cin >> tmp;
    sum += tmp;
  }
  if(sum <= N){
    cout << N - sum << endl;
  }else{
    cout << -1 << endl;
  }
}

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

const int MOD = 1000000007;
const int MAXN = 10005;

void add(int &a, int b) { a += b; if(MOD <= a) a -= MOD; }

int dp[MAXN][100], S[MAXN];

int B[MAXN];
char A[MAXN];

int N, D, Ans;

int main() {
	scanf(" %s%d", A+1, &D);
	N = int(strlen(A+1));
	for(int i = 1; i <= N; i++) {
		B[i] = A[i] & 15;
		S[i] = S[i-1] + B[i];
	}

	for(int i = 1; i <= N; i++) {
		for(int j = D; j--;)
			for(int k = 10; k--;)
				add(dp[i][(j+k)%D], dp[i-1][j]);
		for(int j = B[i]; j--;)
			add(dp[i][(S[i-1]+j)%D], 1);
	}

	Ans = dp[N][0];
	add(Ans, MOD-1);
	if(!(S[N] % D)) add(Ans, 1);

	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 4224
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
#define watch(x) cout << (#x)<<" = "<<x<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
	file();
	fast();
	int n, k; cin >> n >> k;
	vi v1(n);
	for (auto& it : v1) cin >> it;
	for (int i = k; i < n; i++) {
		cout << (v1[i] > v1[i - k] ? "Yes\n" : "No\n");
	}
	return 0;
}

Measured memory_bytes: 3968
import sys
s = input()

p = { 'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0, 'h': 0, 'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0,}

for e in s:
    p[e] += 1
    if p[e] == 2:
        print('no')
        sys.exit()

print('yes')


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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    //int N; cin >> N;
    int N,Q;
    cin >> N >> Q;
    
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    //int Q; cin >> Q;
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21728
#include<bits/stdc++.h>
using namespace std;
map<double,int>mp;
int main()


{
    int a,b,c=0,t,i,j,k;
    string s1,s2;
    cin>>t;
    int ara[t];
    for(i=0;i<t;i++)
    {
        cin>>ara[i];
    }
    sort(ara,ara+t);
    for(i=0;i<t;i++)
    {
       for(j=0;j<i;j++)
       {
           for(k=0;k<j;k++)
           {
               if(ara[i]!=ara[j]&&ara[k]!=ara[i]&&ara[k]!=ara[j])
                {
                 if(ara[i]+ara[j]>ara[k]&&ara[i]+ara[k]>ara[j]&&ara[j]+ara[k]>ara[i])
                    c++;
                }
           }
       }
    }
    cout<<c<<"\n";




return 0;
}


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

int main(){
        int h,w;
        cin >> h >> w;
        string s[h];
        for(int i = 0; i < h; i++){
                cin >> s[i];
        }

        int ans[h][w];

        for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                        int b = 0;
                        // upper
                        if (i - 1 >= 0)
                                if( j - 1 >= 0)
                                        if(s[i - 1][j - 1] == '#')  b++;
                        if(s[i - 1][j] == '#')  b++;
                        if(j + 1 < w)
                                if(s[i - 1][j + 1] == '#')  b++;
                        // middle
                        if( j - 1 >= 0)
                                if(s[i][j - 1] == '#')  b++;
                        if(j + 1 < w)
                                if(s[i][j + 1] == '#')  b++;
                        // bottom
                        if (i + 1 < h)
                                if( j - 1 >= 0)
                                        if(s[i + 1][j - 1] == '#')  b++;
                        if(s[i + 1][j] == '#')  b++;
                        if(j + 1 < w)
                                if(s[i + 1][j + 1] == '#')  b++;
                        ans[i][j] = b;
                }
        }
        for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                        if(s[i][j] == '#'){
                                cout << '#';
                        } else {
                                cout << ans[i][j];
                        }
                }
                cout << endl;
        }
}

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

int main()
{
	int n;
	int a[1000] = {};
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int x = n-1; x >= 0; x--)
	{
		if (x == n - 1)
		{
			cout << a[x];
		}
		else
		{
			cout << " ";
			cout << a[x];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3068
n = input()

if len(list(n)) == 1:
    print(int(n))
    exit()

if set(list(n)) == {'9'}:
    print(len(list(n))*9)
    exit()

tmp = ''
for i in range(1,len(n)):
    if n[i] == '9':
        tmp += n[i-1]
    else:
        tmp += str(int(n[i-1])-1) + '9'*(len(n)-i)
        break
else:
    tmp += '9'

ans=0
for i in range(len(tmp)):
    ans += int(tmp[i]) 

print(ans)


Measured memory_bytes: 9144
X,N = map(int,input().split())
p = list(map(int,input().split()))


# p = list(p.sort())
list2 = sorted(p)

for i in range(1000):
    if X-i not in list2:
        print(X-i)
        break
    elif not X + i in list2:
        print(X+i)
        break


Measured memory_bytes: 9168
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    ll a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
    return 0;
}


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

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

long long lcm(long long x, long long y)
{
    if (x == 0 || y == 0)
        return 0;
    return x / gcd(x, y) * y;
}

int main()
{
    string s, t;
    cin >> s >> t;
    reverse(s.begin(), s.end());
    cout << (s == t ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>

using namespace std;


int main(){
    int n, ans;
    cin >> n;
    if (n%2 == 0){
        ans = n/2 -1;
    }
    else{ans = (n+1)/2-1;}

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
N = input()
a = input().split()
import numpy as np 
a = np.array(a).astype(int)
a.sort()
pai = -1
v = []
i = 0
for ai in a[::-1]:
    if pai == ai:
      v.append(ai)
      pai = -1
      i = i + 1
      if i >= 2:
          break
      continue
    pai = ai
if len(v) >= 2:
    print(v[0]*v[1])
else:
    print(0)

Measured memory_bytes: 27508
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
int T[2*1000+10][2*1000+10];
int main() {

    cout.precision(10);
    cout<<fixed;
    ll N,X,Y;
    cin>>N>>X>>Y;
    --X;--Y;
    vector<ll> ans;
    ans.resize(N,0);
    REP(i,N)
        REP(j,N)
            T[i][j]=0;
    // use Y-X
    REP(i,N)
        REP(j,N)
            T[i][j]=1+abs(X-i)+abs(Y-j);
    REP(i,N)
        REP(j,N)
            T[i][j]=min(abs(j-i),T[i][j]);
    for(int i=0;i<N;++i)
        for(int j=i+1;j<N;++j) {
            ans[T[i][j]]+=1;
        }
    REP(i,N-1) {
            cout<<ans[i+1]<<endl;
        }




}

struct Vec{
    double v[2];
    string to_s(){
        return "("+to_string(v[0])+","+to_string(v[1])+")";
    }
    double& operator[](int t){
        return v[t];
    }
    Vec operator+(Vec t) {
        return {v[0]+t[0],v[1]+t[1]};
    }
    Vec& operator+=(Vec t) {
        v[0]+=t[0];v[1]+=t[1];
        return *this;
    }
    Vec operator-(Vec t) {
        return {v[0]-t[0],v[1]-t[1]};
    }
    Vec& operator-=(Vec t) {
        v[0]-=t[0];v[1]-=t[1];
        return *this;
    }
    Vec operator*(double t) {
        return {v[0]*t,v[1]*t};
    }
    Vec& operator*=(double t) {
        v[0]*=t;v[1]*=t;
        return *this;
    }
    double operator*(Vec t) {
        return v[0]*t[0]+v[1]*t[1];
    }
    Vec operator-(){
        return {-v[0],-v[1]};
    }
    static Vec Z;
};
Vec Vec::Z={0,0};


Measured memory_bytes: 16000
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

// typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

// conversion
inline LL toLong(string s) {
  LL 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;
}

// 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 SZ(a) LL((a).size())
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#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)
#define UNTIL(p) while (!(p))

// constant
const double EPS = 1e-5;
const double PI = acos(-1.0);

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

LL mod_pow_fast(LL a, LL n, LL MOD) {
  LL p = a;
  LL ret = 1;
  while (n) {
    if (n & 1) ret = (ret * p) % MOD;
    n = n >> 1;
    p = (p * p) % MOD;
  }
  return ret;
}

LL mod_val[200005][10] = {{0}};
LL dp[10000] = {0};

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL n, p = 2019;
  string s;
  cin >> s;
  n = s.size();

  if (p == 2 || p == 5) {
    LL ans = 0;
    REP(i, n) {
      LL x = s[i] - '0';
      if (x % p == 0) {
        ans += i + 1;
      }
    }
    PUTS(ans);
    return 0;
  }
  // (100x + 10y + z) mod p
  // (100x % p + 10y % p + z % p) mod p
  // x * 10^100000 % p
  // mod_val[i][j] == j * 10^i mod p
  REP(i, n) {
    REP(j, 10) { mod_val[i][j] = (mod_pow_fast(10, i, p) * j) % p; }
  }

  reverse(ALL(s));
  LL ans = 0;
  LL m = 0;
  dp[0] = 1;
  REP(i, n) {
    LL x = s[i] - '0';
    m += mod_val[i][x];
    m %= p;
    ans += dp[m];
    dp[m]++;
  }

  PUTS(ans);
}


Measured memory_bytes: 19388
require 'set'; require 'prime'
INF=Float::INFINITY
n,k = gets.chomp.split.map(&:to_i)

kmax = (n-1) * (n-2) / 2
if kmax < k
  puts -1
  exit
end

if n==2
  puts 1
  puts "1 2"
  exit
end

ans = []
2.upto(n).each do |i|
  ans.push [1, i]
end

nokori = kmax - k
2.upto(n-1).each do |i|
  (i+1).upto(n).each do |j|
    break if nokori <= 0
    ans.push [i,j]
    nokori -= 1
  end
end

puts ans.size
ans.each do |line|
  puts line.join(' ')
end


Measured memory_bytes: 2556
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  map<string, int> mp1;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    mp1[s]++;
  }

  int M;
  cin >> M;
  map<string, int> mp2;
  for (int i = 0; i < M; i++) {
    string s;
    cin >> s;
    mp2[s]++;
  }

  int ans = 0;
  for (auto itr = mp1.begin(); itr != mp1.end(); itr++) {
    int tmp = itr->second - mp2[itr->first];
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int N;
    cin>>N;
    string s;
     int ac=0,wa=0,tle=0,re=0;
    rep(i,N){
        cin>>s;
        if(s=="AC")ac++;
        else if(s=="WA")wa++;
        else if (s=="TLE")tle++;
        else re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl; 
}

Measured memory_bytes: 3560
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

LL dir,pos[200005];
LL n,l,t,rnk = 0;

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> l >> t;
	for(LL i = 1;i <= n;i ++){
		cin >> pos[i] >> dir;
		if(dir == 1){
			pos[i] += t;
			rnk += pos[i] / l;
		}
		else{
			pos[i] -= t;
			rnk += (pos[i] >= 0 ? 0 : (pos[i] + 1 - l) / l);
		}
		pos[i] = (pos[i] % l + l) % l;
		rnk = (rnk % n + n) % n;
	}
	sort(pos + 1,pos + 1 + n);
	for(LL i = rnk + 1;i <= n;i ++) cout << pos[i] << endl;
	for(LL i = 1;i <= rnk;i ++) cout << pos[i] << endl;
    return 0;
}

Measured memory_bytes: 2048
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
ans = 0
(1...n).each do |i|
    if a[i-1] > a[i] then
        ans += a[i-1] - a[i]
        a[i] = a[i-1]
    end
end
puts ans

Measured memory_bytes: 30292
import sys

S = input()

while S:
    if S[-1] == 'r':
        if S[-7:] == 'dreamer':
            S = S[:-7]
        elif S[-6:] == 'eraser':
            S = S[:-6]
        else:
            print('NO')
            sys.exit()
    elif S[-5:] == 'dream' or S[-5:] == 'erase':
        S = S[:-5]
    else:
        print('NO')
        sys.exit()

print('YES')

Measured memory_bytes: 133880