akhauriyash/Code-Regression huggingface dataset:
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int n;
int k;

vi cnt(1e4);

void input() {
  cnt = vi(cnt.size());

  cin >> n >> k;
}

void solve() {
  for (int i = 0; i < k; ++i) {
    int d;
    cin >> d;

    for (int j = 0; j < d; ++j) {
      int t;
      cin >> t;

      cnt[t]++;
    }
  }

  int ans = 0;

  for (int i = 1; i <= n; ++i)
    ans += cnt[i] == 0;

  cout << ans << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 2;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define DIM 10007
#define INF 10000000007
#define X 10000
#define epc 0.0000000000000000000001
#define pi 3.14159265358979323846
#define MAX 25
#define MODULO 1000000007

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I,I> pII;
typedef pair<ll,ll> pllll;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef set<I> sI;
typedef set<ll> sll;
typedef set<pllll> spllll;

typedef stack<I> stI;
typedef stack<ll> stll;

typedef char cr;
typedef string str;

typedef queue<I> qI;
typedef queue<ll> qll;
typedef queue<pllll> qpllll;
typedef priority_queue<ll> pqllmin;
typedef priority_queue<pllll,vector<pllll>,greater<pllll> > pqpllllmax;

typedef tree<
I,
null_type,
greater<I>,
rb_tree_tag,
tree_order_statistics_node_update> mset;

ll n;
str s;

struct num{
  I d[DIM],l;

  num(){
  };

  num(ll x){
   if(x==0){
    l=1;
    d[0]=0;
   }
   else{
    l=0;
    while(x>0){
     d[l++]=x%10;
     x/=10;
    }
   }
  }

  void read(){
   memset(d,0,sizeof(d));
   str s;
   cin>>s;
   l=s.size();
   for(int i=0;i<l;i++)d[l-i-1]=s[i]-'0';
  }

  void print(){
   for(int i=(l-1);i>=0;i--)cout<<d[i];
   cout<<endl;
  }
};

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

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

    cin>>s;
    n=s.length();
    for(int i=0;i<n;i++){
     if(s[i]=='1')s[i]='9';
     else if(s[i]=='9')s[i]='1';
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
def gcd x, y
  if x == 0
    puts y
  elsif y == 0
    puts x
  else
    case x <=> y
    when 1
      gcd y, x % y
    when -1
      gcd x, y % x
    else
      puts x
    end
  end
end

x, y = gets.split.map &:to_i
gcd x, y

Measured memory_bytes: 8684
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


const LL MOD = 1000000007;

LL solve(LL n, LL m, vector<pair<LL,LL>>& rest){
    LL row_r = n;
    LL col_r = m;
    LL ans = 1;
    LL cur = 0;
    for(pair<LL,LL> p: rest){
        LL v = p.first;
        LL type = p.second;
        if(type == 1){ // row
            LL w = v - cur;
            //cerr << "type1 " << w << endl;
            if(w < col_r) return 0;
            ans = ans * col_r % MOD;
            for(LL j = 0; j < col_r-1; ++j){
                ans = ans * (w-1-j) % MOD;
            }
            cur += col_r;
            row_r -= 1;
        }else if(type == 2){ // col
            LL w = v - cur;
            //cerr << "type2 " << w << endl;
            if(w < row_r) return 0;
            ans = ans * row_r % MOD;
            for(LL j = 0; j < row_r-1; ++j){
                ans = ans * (w-1-j) % MOD;
            }
            cur += row_r;
            col_r -= 1;
        }else{ // row + col
            assert(type == 3);
            LL w = v - cur;
            //cerr << "type3 " << w << endl;
            if(w < col_r + row_r - 1) return 0;
            for(LL j = 0; j < col_r+row_r-1-1; ++j){
                ans = ans * (w-1-j) % MOD;
            }
            cur += col_r+row_r-1;
            row_r -= 1;
            col_r -= 1;
        }
    }
    return ans;
}

int main(){
    LL n, m;
    cin >> n >> m;
    map<LL,LL> rest;
    for(LL i = 0; i < n; ++i){
        LL v;
        cin >> v;
        if(rest.count(v) > 0){
            cout << 0 << endl;
            return 0;
        }
        rest[v] = 1;
    }
    for(LL i = 0; i < m; ++i){
        LL v;
        cin >> v;
        if(rest[v] & 2){
            cout << 0 << endl;
            return 0;
        }
        rest[v] |= 2;
    }
    //cerr << "debug1" << endl;
    vector<pair<LL,LL>> rest2(rest.begin(), rest.end());
    cout << solve(n, m, rest2) << endl;
    return 0;
}



Measured memory_bytes: 384
def main():
    N = int(input())
    pl = list(map(float, input().split()))
    v = [1 - pl[0], pl[0]]
    mid = (N + 1) // 2
    for i, p in enumerate(pl[1:mid], 1):
        v = v + [0.0]
        t = v[0]
        v[0] = t * (1 - p)
        for j, uu in enumerate(v[1:], 1):
            v[j] = t * p + uu * (1 - p)
            t = uu
    for i, p in enumerate(pl[mid:], mid):
        t = v[i - mid + 1]
        for j, uu in enumerate(v[i - mid + 2:-1], i - mid + 2):
            v[j] = t * p + uu * (1 - p)
            t = uu
        v[mid] += t * p
    print(v[mid])

main()


Measured memory_bytes: 41436
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	ans := "No"
	for i := 1; i <= 9; i++ {
		for j := 1; j <= 9; j++ {
			if i*j == n {
				ans = "Yes"
			}
		}
	}
	fmt.Println(ans)
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<long long> H(N);
  for(int i=0; i<N; i++) cin >> H.at(i);
  sort(H.begin(), H.end());
  long long ans=0;
  if(N-K>0){
    for(int i=0; i<N-K; i++){
      ans+=H.at(i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int h,w,m;
    cin>>h>>w>>m;
    set<pi> s;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        s.insert({a,b});
    }
    map<int,int> mh,mw;
    for(auto t:s)mh[t.fi]++,mw[t.se]++;
    int ch=0,cw=0;
    for(auto t:s)ch=max(ch,mh[t.fi]),cw=max(cw,mw[t.se]);
    vi hh,ww;
    for(auto t:mh)if(t.se==ch)hh.eb(t.fi);
    for(auto t:mw)if(t.se==cw)ww.eb(t.fi);
    int ans=ch+cw-1;
    for(auto i:hh)for(auto j:ww){
        if(s.find({i,j})==s.end()){
            cout<<ans+1<<endl;
            return;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 67744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	if(n*a>b){
		cout <<b;
	}
	else{
		cout << n*a;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll k;
  cin >> k;
  vl a(50, 49);
  rep(i, 50) {
    ll x = k / 50;
    if(k % 50 > i) x++;
    a[i] += 51 * x - k;
  }
  cout << 50 << endl;
  rep(i, 50) cout << a[i] << ' ';
  cout << endl;
}

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

using namespace std;
using PII = pair<int, int>;

int main() {
	int h, w, d, tmp;
	cin >> h >> w >> d;

	vector<vector<int>> a(h, vector<int>(w, 0));
	vector<PII> val2point(h * w);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> tmp;
			tmp--;
			val2point[tmp] = make_pair(i, j);
			a[i][j] = tmp;
		}
	}

	vector<long long> cumul(h * w, -1);
	for (int st = 0; st < d; st++) {
		cumul[st] = 0;

		for (int i = st; i + d < cumul.size(); i += d) {
			auto from = val2point[i];
			auto to = val2point[i + d];

			cumul[i + d] = cumul[i] + abs(to.first - from.first) + abs(to.second - from.second);
		}
	}

	int q, l, r;
	cin >> q;
	vector<long long> ans(q);
	for (int i = 0; i < q; i++) {
		cin >> l >> r;
		l--;
		r--;
		ans[i] = cumul[r] - cumul[l];
	}

	for (auto x: ans) {
		cout << x << endl;
	}


	return 0;
}


Measured memory_bytes: 3712
#include <cstdio>
#include <utility>
#include <vector>
#include <functional>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n';)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;if((c=gcu())=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
	_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

using V = vector<int>;

int main() {
	for (int n; (n = in);) {
		V v(n);
		for (int &i: v)
			i = in;
		int s {in}, c {};
		function<int(int, int)> search {[&](int b, int e) {
			if (b > e)
				return c;
			int m = (b + e) / 2;
			c++;
			return v[m] == s ? c : s < v[m] ? search(b, m - 1) : search(m + 1, e);
		}};
		outl(search(0, v.size() - 1));
	}
}


Measured memory_bytes: 2480
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    int flag = 0;
    cin >> a;
    cin >> b;
    cin >> c;

    for(int i = 0;i < 500000000;i++){
        if((a + a * i) % b == c && c != 36){
            cout << "YES" << endl;
            flag = 1;
            break;
        }
    }
    if(flag != 1){
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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();
	int low = a[0];
	long sum = 0;
	for (int i=1; i<n; i++) {
	    if (low <= a[i]) low = a[i];
	    else {
		sum = sum + low - a[i];
	    }
	}
	System.out.print(sum);
    }
}


Measured memory_bytes: 61812
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	

	void solve(){
		


		ini(n);
		if(n>=30){
			out("Yes");
		}
		else{
			out("No");
		}

			
			
			


				
		


		
		
		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


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

int card[255][14] = {{0}};

int main(void){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        char c; /*0~255*/
        int num;
        cin >> c >> num;
        card[(int)c][num] = 1; // 発見
    }
    /* S を探す*/
    for(int i =1; i <= 13; i++) {
        if(card[(int)'S'][i] == 0) {
            cout << "S " << i << endl;
        }
    }
    /* H を探す*/
    for(int i =1; i <= 13; i++) {
        if(card[(int)'H'][i] == 0) {
            cout << "H " << i << endl;
        }
    }
    /* C を探す*/
    for(int i =1; i <= 13; i++) {
        if(card[(int)'C'][i] == 0) {
            cout << "C " << i << endl;
        }
    }
    /* D を探す*/
    for(int i =1; i <= 13; i++) {
        if(card[(int)'D'][i] == 0) {
            cout << "D " << i << endl;
        }
    }    
}


Measured memory_bytes: 3076
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}


#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__)
#else
#define debug(...)
#endif


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N;
    ll M;
    cin >> N >> M;

    ll A[N];
    REP(i, N) cin >> A[i];

    unordered_map<ll, ll> B;

    ll s = 0;
    ++B[0];
    REP(i, N) {
        s = (s + A[i]) % M;
        if (B.find(s) == B.end()) B[s] = 1;
        else ++B[s];
    }

    ll ans = 0;
    for(auto it = B.begin(); it != B.end(); ++it) {
        ll n = it->se;
        ans += n * (n - 1) / 2;
    }
    
    cout << fixed << setprecision(20);
    cout << ans << endl;

}


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

int main(){
  	string s;
  	cin >> s;
  
  	rep(i,0,s.size()){
      if(i % 2 == 0){
        cout << s[i];
      }
    }
  	cout << endl;
  	return 0;
}

Measured memory_bytes: 512
<?php
list($a, $b, $k) = explode(" ", trim(fgets(STDIN)));

if($k > $a){
  $k = $k-$a;
}else{
  echo ($a-$k)." ".$b;
  exit;
}

if($k > $b){
  echo "0 0";
}else{
  echo "0 ".($b-$k);
}

Measured memory_bytes: 4604
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<vector>
using namespace std;

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

//infinity
#define INTINF 2000000000
#define LONGINF 2000000000

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

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> s;
	vector<int> e;

	REP(i, m){
		int src, dest;
		cin >> src >> dest;
		if(src == 1) s.push_back(dest);
		else if(dest == n) e.push_back(src);
	}
	sort(s.begin(), s.end());
	sort(e.begin(), e.end());

	int ss = s.size();
	int es = e.size();

	int is = 0, ie = 0;
	while(true){
		if(is == ss || ie == es) break;

		if(s[is] == e[ie]){
			cout << "POSSIBLE" << endl;
			return 0;
		}

		if(s[is] > e[ie]) ie++;
		else is++;
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}


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

int main() {
	int n,i;
	vector<long long> d;
	long long j,k,a[505],sum=0,ds;
	cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> a[i];
		sum+=a[i];
	}
	for(j=1;j<=sqrt(sum);j++){
		if(sum%j==0){
			if(j*j!=sum){
				d.push_back(j);
				d.push_back(sum/j);
			} else {
				d.push_back(j);
			}
		}
	}
	sort(d.begin(),d.end());
	ds=d.size();
	for(j=ds-1;j>=0;j--){
		long long e=d[j],sume=0,min;
		int ms;
		vector<long long> m;
		for(i=0;i<n;i++){
			if(a[i]%e!=0) m.push_back(a[i]%e);
			sume+=a[i]%e;
		}
		ms=m.size();
		if(ms==0){
			cout << e << endl;
			return 0;
		}
		sort(m.begin(),m.end());
		min=e*ms-sume;
		long long summ=0,sumr,memo;
		for(i=1;i<=ms;i++){
			summ+=m[i-1];
			sumr=e*(ms-i)-sume+summ;
			if(summ>=sumr) memo=summ;
			else memo=sumr;
			if(min>memo) min=memo;
			if(min<=k){
				cout << e << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 384
MOD = 10 ** 9 + 7
INF = 10 ** 12
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  itertools import permutations
from heapq import heapify,heappop,heappush

def main():
    n,k = map(int,input().split())
    ans = 0
    for i in range(k,n + 2):
        ans += i * (n - i + 1) + 1
        ans %= MOD
    print(ans)

if __name__ =='__main__':
    main() 

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define con_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define con_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);

int main(){
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    cout<<(m1!=m2?1:0)<<endl;
}

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

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i;
	cin >> i;
	if (i>=30){
        cout << "Yes";
	}
	else{
        cout<< "No";
	}
	return 0;
}



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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

using ll    = long long;
using vll   = vector<ll>;
using pll   = pair<ll,ll>;
using ld    = long double;

const ll mod = (ll)1e9 + 7;
const ll mxN = (ll)1e6 + 3;



void solve() {
	ll a;cin>>a;
	cout<<a+a*a+a*a*a<<"\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
//	pre();
//	ll t;cin>>t;while (t--)
		solve();
}


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

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

using namespace std;
using lint=long long;

int main(){
	lint n,k; scanf("%lld%lld",&n,&k);
	n%=k;
	printf("%lld\n",min(n,k-n));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define repeat_from_reverse(i, m, n) for( int i = (n) - 1; (i) >= (m); --(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t t=0; t<v.size(); ++t){cout << " " << #v << "[" << t << "]=" << v[t];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    
    int n, k;
    cin >> n >> k;
    
    lint ans = k;
    if (n==1) cout << ans << endl;
    else {
        rep(n-1) {
            ans *= (k-1);
        }
        cout << ans << endl;
    }
    return 0;    
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// 1202
// --------------------------------------------------------------------------------
#define fastio	ios_base::sync_with_stio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b,k) for(int i=a;i<=b;i+=k)
#define frepj(a,b,k) for(int j=a;j<=b;j+=k)
// --------------------------------------------------------------------------------

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

void solve_main()
{
    int k;cin>>k;
    ll ans = 0;
    for(int i=1;i<=k;++i)
    {
    	for(int j=1;j<=k;++j)
    	{
    		int x = gcd(i,j);
    		for(int z=1;z<=k;++z)
    		{
    			ans+=(gcd(x,z));
    		}
    	}
    }
    cout<<ans;

}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("/home/suryakant/input.txt","r",stdin);
 //        freopen("/home/suryakant/output.txt","w",stdout);
 //    #endif
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve_main();
    }
    
}

Measured memory_bytes: 3544
#include<stdio.h>
#include<queue>
int main(){
std::queue<int>q;
int w,h,f[484],i,j,d[]={22,0,-1,0,1,0,-22},a,b,t,x,z;
char p[15];
for(;scanf("%d%d ",&h,&w),h;){
for(j=0;j<w+2;j++)f[j]=f[j-~h*22]=-9;
for(i=1;i<=h;i++){
for(j=1;j<=w;j++)
f[x=i*22+j]=-1,
z=getchar(),
z-'#'?z>65?b=x:z>64?a=x:1:--f[x];
f[i*22]=f[i*22-~w]=-9;
getchar();
}

f[a]=t=0;
q.push(0);
for(q.push(a);a=q.front(),q.size()>1;q.pop())
if(a){
for(i=0;i<7;i+=2)
if(f[x=a+d[i]]==-1)
f[x]=t,q.push(x);}
else
++t,q.push(0);

q.pop();
scanf("%s",p);
for(a=t=0;!a;){
x=b;
z=0;
for(i=0;!a&&p[i];i++){
t++;
f[j=b+d[p[i]-'2']]>-3?b=j:0;
f[b]>=0&&t>=f[b]?a=b:0;
f[b]>=0&&++z;
}
!z&!a&!p[i]&b==x&f[b]<0&&--a;
}
printf(a<0?"impossible\n":"%d %d %d\n",t,a/22-1,a%22-1);
}
}

Measured memory_bytes: 0
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;




public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7);
	static long cf = 998244353;
    static final int MAX = (int) 2e6;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static int[] Bit;
    public static long[][] dp;
    public static long[] fac,inv;
    public  static int[] prime; 
	public static Map<Integer, Integer> map; 
	public static void main(String[] args) {
	
	FastReader sc = new FastReader();
	
	 prime = new int[MAX];
	 map = new HashMap<>();
	 sieve(); 
	 int n = sc.nextInt();
	 int[] a = new int[n];
	 for(int i=0;i<n;++i)
		 a[i] = sc.nextInt();
	
	  long lcm = lcmModuloM(a, n); 
	  long ans = 0;
	 
	  for(int i=0;i<n;++i) { 
		  ans += (lcm*power(a[i],mod-2))%mod;
		  if(ans >= mod) ans-=mod;
	  }
	  out.println(ans);
	out.close();

	}

	
	static long power(int a, int n) 
	{ 
	    if (n == 0) 
	        return 1; 
	    long p = power(a, n / 2) % mod; 
	    p = (p * p) % mod; 
	    if ((n & 1) == 1) 
	        p = (p * a) % mod; 
	    return p; 
	} 
	
	static void sieve() 
	{ 
	    prime[0] = prime[1] = 1; 
	    for (int i = 2; i < MAX; i++) { 
	        if (prime[i] == 0) { 
	            for (int j = i * 2; j < MAX; j += i) { 
	                if (prime[j] == 0) { 
	                    prime[j] = i; 
	                } 
	            } 
	            prime[i] = i; 
	        } 
	    } 
	} 
	  
	
	static long lcmModuloM(int[] ar, int n) 
	{ 
	  
	    for (int i = 0; i < n; i++) { 
	        int num = ar[i]; 
	        Map<Integer,Integer> temp = new HashMap<>(); 
	  
	        while (num > 1) {
	            int factor = prime[num]; 
	            temp.put(factor,temp.getOrDefault(factor,0)+1); 
	            num /= factor; 
	        } 
	  
	        for (int key : temp.keySet()) { 
	        	map.put(key, Math.max(map.getOrDefault(key,0),temp.get(key)));
	        } 
	    } 
	  
	    long ans = 1; 
	  
	    for (int key : map.keySet()) {
	        ans = (ans * power(key,map.get(key))) % mod; 
	    } 
	    return ans; 
	} 
	  
}

Measured memory_bytes: 37380
#include <set>          
#include <map>           
#include <list>
#include <ctime>
#include <deque>         
#include <bitset>        
#include <vector>
#include <list>
#include <stack>
#include <random>		 
#include <string>       
#include <numeric>      //  needed for  accumulate
#include <utility>      // needed for std:: move
#include <iterator> 
#include <iostream>   
#include <algorithm> 
#include <functional>    
#include <cmath>         
#pragma warning(disable:4996) // ignore this
#define ve vector
#define pb push_back
#define mp make_pair                     
#define srt(x) sort(x.begin(),x.end())         
#define mod static_cast<long long> (1e9+7)     
#define sumx(x) accumulate(x.begin(),x.end(),0LL)
#define pi 3.14159265358979323846
#define testing 0
using namespace std;
template<typename T>
istream& operator >> (istream& in, ve<T> &v)
{
	for (auto &x : v)
		in >> x;
	return in;
}
template<typename T>
ostream& operator<<(ostream& in, ve<T> &v)
{
	for (auto &x : v)
		in << x << " ";
	return in;
}
long long fast(long long a, long long b, long long mid)
{
	if (b == 0)
		return 1;
	a %= mid;
	long long ans = 1;
	while (b)
	{
		if (b & 1)
		{
			ans = (ans*a) % mid;
		}
		a *= a;
		a %= mid;
		b >>= 1;
	}
	return ans;
}
class solve
{
	int n;
public:
	solve()
	{
		cin >> n;
		ve<int> v(n);
		cin >> v;
		long long sum=sumx(v)-v[0];
		long long sum2=v[0];
		long long ans=abs(sum-sum2);
		for(int i=1;i<n-1;i++)
		{
			sum2+=v[i];
			sum-=v[i];
			ans=min(abs(sum-sum2),ans);
		}
		cout << ans; 
		return;
	}
};
 
int32_t main()
{
	int t = 1, i = 1;
//	scanf("%d", &t);
	while (t--)
	{
		new solve;
	}
	return 0;
}

Measured memory_bytes: 1024
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

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 vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//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) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n; cin >> n;
	
	int now = 1;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int v; cin >> v;
		if (v == now) {
			now++;
			cnt++;
		}
	}

	if (now == 1) {
		cout << "-1" << endl;
	}
	else {
		cout << n-cnt << endl;
	}

	
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    d, t, s = MI()
    if s * t >= d:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    solve()



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

int top;
char b[6005],a[6005];
int main()
{
    cin>>b;
    int l=strlen(b);
    for (int i=0; i<l; i++)
    {
        if (b[i]=='B')
        {
            if (top>0) top--;
        }
        else 
            a[++top]=b[i];
    }
    for (int i=1; i<=top; i++)
        cout<<a[i];
    cout<<endl; 

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	int x, y;
	cin >> x >> y;
	if (x == 1) x = 14;
	if (y == 1) y = 14;
	if (x > y) {
		cout << "Alice" << endl;
	}
	else if (x < y) {
		cout << "Bob" << endl;
	}
	else {
		cout << "Draw" << endl;
	}
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;

int main(){
  int r, D, x0, x;
  cin >> r >> D >> x0;
  x = x0;
  REP(i, 10){
    x = r*x - D;
    cout << x << endl;;
  }
  
  return 0;
}

Measured memory_bytes: 256
import fractions
a,b,c,d = map(int, input().split())
cnt=0
num_c = b//c - (a-1)//c
num_d = b//d - (a-1)//d
num_c_d = b//((c*d)//fractions.gcd(c,d))- (a-1)//((c*d)//fractions.gcd(c,d))
total = num_c + num_d - num_c_d
print(int((b-a+1) - total))

Measured memory_bytes: 5048
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
         var data = ReadLine().Split(' ').Select(int.Parse).ToArray();
         if(data[0] <= data[1] * data[2]) WriteLine("Yes");
         else WriteLine("No");
      }
   }
}

Measured memory_bytes: 28084
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

vector<ll> z;
//約数列挙
void comdiv(ll x){
    stack<ll> big;
    for(ll i = 2; i*i <= x; i++){
        if(x%i == 0){
            z.push_back(i);
            big.push(x/i);
        } 
    }
    while(!big.empty()){
        z.push_back(big.top());
        big.pop();
    }
    z.push_back(x);
    return;
}

bool factor(ll x){
    vector<ll> prime;
    for (ll i = 2; i<=sqrt(x); i++) {
        if(x%i==0){
            while(x%i==0)x/=i;
            prime.push_back(i);
        }
        if(x==1)break;
    }
    if(x!=1)prime.push_back(x);
    if(prime.size() == 1) return true;
    else return false;
}

int main(){
    ll n;
    cin >> n;
    comdiv(n);
    vector<bool> p(z.size());
    vector<ll> can;
    for(int i = 0; i < z.size(); i++){
        if(factor(z[i])) can.push_back(z[i]);
    }
    int j = 0;
    int ans = 0;
    while(j < can.size()){
        if(n < can[j]) break;
        if(n%can[j] == 0){
            n /= can[j]; 
            ans++;
        }
        j++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size()
#define int long long

using namespace std;

struct tw {
	int a, b;
};

int n, wei, dp[112][100012];

tw m[112];

void Speed() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

main () {
	Speed();
	cin >> n >> wei;
	for (int i = 1; i <= n; ++ i) {
		cin >> m[i].a >> m[i].b;
	}
	for (int i = 1; i <= n; ++ i) {
		for (int j = 1; j <= wei; ++ j) {
			if (m[i].a > j) {
				dp[i][j] = dp[i - 1][j];
			} else {
				dp[i][j] = max(dp[i - 1][j], m[i].b + dp[i - 1][abs(m[i].a - j)]);
			}
		}
	}
	cout << dp[n][wei];
}

Measured memory_bytes: 79360
#include <iostream>

using namespace std;
int x, n, res;
int main()
{
  
   cin >> n;
   for (int i = 1 ; i <= n; i++) {
       cin >> x;
       if (x % 2 == 1 && i % 2 == 1) res ++;}
   cout << res;
   
   return 0;
}

Measured memory_bytes: 3552
# -*-coding:utf-8

def main():

    r, c = map(int, input().split())

    #A = [[0 for i2 in range(c+1)] for i1 in range(r+1)]
    A = []
    for i in range(r):
        tokens = list(map(int, input().split()))
        tokens.append(sum(tokens))
        A.append(tokens)

    rowSumList = []
    for i in range(c+1):
        rowSum = 0
        for j in range(r):
            rowSum += A[j][i]
        rowSumList.append(rowSum)

    A.append(rowSumList)

    for i in range(r+1):
        for j in range(c+1):
            if(j == c):
                print('%d' % A[i][j])
            else:
                print('%d ' % A[i][j], end='')

if __name__ == '__main__':
    main()

Measured memory_bytes: 8396
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#ifdef __has_include
  #if __has_include(<boost/version.hpp>)
    #include <boost/range.hpp>
    #include <boost/range/irange.hpp>
    #include <boost/range/adaptors.hpp>
    #include <boost/range/algorithm.hpp>
    #include <boost/range/algorithm_ext.hpp>
    using namespace boost;
    using namespace boost::adaptors;
  #endif
#endif

auto init_ = []{
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed;
	return 0;
}();

template <typename T>
inline T in() {
    T x;
    std::cin >> x;
    return x;
}

template <typename T, typename U = std::vector<T>>
inline U in(int n) {
    U v(n);
    for(int i = 0; i < n; ++i) {
        std::cin >> v[i];
    }
    return v;
}

template <typename T, typename U = std::vector<T>, typename V = std::vector<U>>
inline V in(int h, int w) {
    V vv(h, U(w));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j) {
            std::cin >> vv[i][j];
        }
    }
   return vv;
}

template <typename T>
inline void out(const T& x) {
	std::cout << x << std::endl;
}

template <char delimiter = ' ', typename T, typename... Ts>
inline void out(const T& t, const Ts&... ts) {
	std::cout << t << delimiter;
	out(ts...);
}

template <char delimiter = ' ', typename T>
inline void vout(const T& v, int n) {
	for(int i = 0; i < n; ++i) {
		if(i) std::cout << delimiter;
		std::cout << v[i];
	}
	std::cout << std::endl;
}


int main() {
    auto k = in<int>();
    auto t = in<int>();
    auto a = in<int>(t);

    vector<pair<int, int>> v;
    for(int i = 0; i < a.size(); ++i) {
        v.emplace_back(a[i], i);
    }

    if(t == 1) {
        out(a[0] - 1);
    } else {
        int ans = 0;
        int pr = -1;
    
        priority_queue<pair<int, int>> que(v.begin(), v.end());

        while(que.size() > 1) {
            auto x = que.top(); que.pop();
            auto y = que.top(); que.pop();

            if(x.second == pr) {
                ans++;
            }

            pr = x.second;

            x.first--;

            if(x.first != 0) {
                que.push(x);
            }

            if(y.second == pr) {
                ans++;
            }

            pr = y.second;

            y.first--;

            if(y.first != 0) {
                que.push(y);
            }
        }

        if(que.size() == 1) {
            auto x = que.top();

            if(x.second == pr) {
                ans += x.first;
            } else {
                ans += x.first - 1;
            }
        }

        out(ans);
    } 
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
S=str(input())
n=len(S)
p=0
if(n==1):
    if(S=="L"):print("No")
    else:print("Yes")
else:
    for i in range(1,n,2):
        if(S[i-1]=="L"):
            print("No")
            break
        if(S[i]=="R"):
            print("No")
            break
        else: p+=1
    if(p == n//2):print("Yes")


Measured memory_bytes: 3064
import heapq

n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)], reverse=True)

c = []
ans = 0
for i in range(m):
    while len(ab) != 0 and ab[-1][0] <= i+1:
        _, b = ab.pop()
        heapq.heappush(c, -b)
    if c:
        ans += -heapq.heappop(c)
print(ans)

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

int main(){
  int N,M,L,R,l,r; cin >> N >> M;
  L=1; R=N;
  for(int i=0; i<M; i++){
    cin >> l >> r;
    L = max(L,l); R = min(R,r);
    if(L>R){break;}
  }
  
  cout << max(R-L+1, 0);
  
  return 0;
}

Measured memory_bytes: 888
def xC2(x):
    if x == 1:
        return 0
    else:
        return x * (x-1) // 2

class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return 0

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        nx, ny = - self.parents[x],  - self.parents[y]

        self.parents[x] += self.parents[y]
        self.parents[y] = x

        return xC2(nx + ny) - xC2(nx) - xC2(ny)

import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ab.reverse()
ans = [xC2(n)]

uf = UnionFind(n)
for a, b in ab:
    ans.append(ans[-1] - uf.union(a-1, b-1))

ans.reverse()

for ai in ans[1:]:
    print(ai)


Measured memory_bytes: 96220
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),s = a + b;
            if(a == -1 && b == -1 && c == -1) break;
            else if(a == -1 || b == -1) System.out.println("F");
            else if(s >= 80) System.out.println("A");
            else if(s >= 65) System.out.println("B");
            else if(s >= 50) System.out.println("C");
            else if(s >= 30){
                if(c >= 50) System.out.println("C");
                else System.out.println("D");
            }else System.out.println("F");
        }
    }

}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

int main() {
  int H, W; cin >> H >> W;
  string A[H]; rep(i,H) cin >> A[i];
  int num = 0; rep(i,H) rep(j,W) if (A[i][j]=='#') num++;
  string result = (num==H+W-1) ? "Possible" : "Impossible";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
init=sum(A)
A=Counter(A)

for _ in range(Q):
    B,C=map(int,input().split())
    A[C]+=A[B]
    init=init-(B*A[B])+(C*A[B])
    print(init)
    A[B]=0

Measured memory_bytes: 23220
# -*- coding: utf-8 -*-

from queue import Queue
import sys
import subprocess
import json
import time
import math
import re
#import sqlite3
import random
import numpy as np
#from sklearn.datasets import fetch_mldata
from statistics import mean, median, variance, stdev
#from chainer import cuda, Variable, FunctionSet, optimizers
#import chainer.functions  as F

X, Y = input().split()
if (X <  Y): print("<")
if (X >  Y): print(">")
if (X == Y): print("=")

Measured memory_bytes: 22636
N = int(input())
li = list(map(int,input().split()))

from itertools import combinations

ans = 0
for k in combinations(li,3):
    k = list(k)
    k.sort()
    if k[0]+k[1]>k[2] and k[0]!=k[1] and k[1]!=k[2]:
        ans += 1
print(ans)

Measured memory_bytes: 9048
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	m := scanInt()

	cntac := make([]int, n)
	cntwa := make([]int, n)

	for i := 0; i < m; i++ {
		p,s := scanInt()-1, scanText()
		if s=="AC" {
			cntac[p]++
		} else {
			if cntac[p]==0 {
				cntwa[p]++
			}
		}
	}

	ans := 0
	ac := 0

	for i := 0; i < n; i++ {
		if cntac[i]>0 {
			ac++
			ans+=cntwa[i]
		}
	}

	fmt.Println(ac,ans)
}


Measured memory_bytes: 2944
h, w = gets.chomp.split(" ").map(&:to_i)
grids = []
h.times do
  grids << gets.chomp.split("").map(&:to_s)
end

grids.delete_if {|item| item.uniq.size == 1 && item.uniq[0] == "."}

transposed_grids = grids.transpose

transposed_grids.delete_if {|item| item.uniq.size == 1 && item.uniq[0] == "."}

grids = transposed_grids.transpose

grids.each do |grid|
  puts grid.join
end

Measured memory_bytes: 2428
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

void solve() {
	ll h,k;
	cin >> h >> k;
	vector<ll> v;
	ll sum=0;
	for(int i=0;i<k;i++) {
		ll x;
		cin >>x;
		v.pb(x);
		sum+=x;
	}
	if(h>sum) {
		cout << "No\n";
	}
	else cout<<"Yes\n";
}

signed main() {
	boost;
	solve();
}

Measured memory_bytes: 1400