akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
#include <cassert>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

ll N,K;
ll A[200010];
ll acc[200010];

int main ()
{
    cin >> N >> K;
    REP(i,N) cin >> A[i];

    REP(i,N) {
        A[i]--;
        A[i] %= K;
        acc[i + 1] = A[i];
    }

    REP(i,200005) {
        acc[i + 1] = acc[i] + acc[i + 1];
        acc[i + 1] %= K;
    }

    ll ans = 0;
    map<ll, ll> cnt;
    REP(i,min(K, N + 1)){
        cnt[acc[i]]++;
    }

    REP(i,N + 1) {
        ans += cnt[acc[i]] - 1;
        cnt[acc[i]]--;
        if (i + K < N + 1) {
            cnt[acc[i + K]]++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}


 long long a,b,c,s,t,x,y,z;
 long long A,B,C,S,T,X,Y,Z;

 long long cnt;

 long double pi=3.14159265358979323846;

 string N,M;

unsigned long long D;

//long long mam(long long a, long long b){}

int main(){

	cin>>a;

	vector<int> co(2);

	REP(i,a){
		cin>>co[0]>>co[1];
		if(co[1]==co[0]) cnt++;
		x=max(x,cnt);
		if(co[0]!=co[1]) cnt=0;

	}

	if(x>2) cout<<"Yes";
	else cout<<"No";

	return 0;

}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    if(a=="A") cout<<"T"<<endl;
    if(a=="T") cout<<"A"<<endl;
    if(a=="C") cout<<"G"<<endl;
    if(a=="G") cout<<"C"<<endl;
}

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

int main(void){
    ll n, W;
    cin >> n >> W;

    ll w[n], v[n];
    rep(i, n){
        cin >> w[i] >> v[i];
    }

    ll dp[n+1][100001];
    fill(dp[0], dp[0] + 100001, 10000000000);
    dp[0][0] = 0;
    int ma = 0;
    rep(i, n){
        rep(j, 100001){
            if(j >= v[i]){
                dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]] + w[i]);
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    rep(i, 100001){
        if(dp[n][i] <= W)
            ma = max(ma, i);
    }

    cout << ma << endl;

}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
const int N=410,M=1e5+10;
bitset<N> S[N];//S[i]表示让i活下来,哪些必死 
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		if (S[x][x]||S[y][y]||S[x][y]||S[y][x]||(S[x]&S[y]).any()) S[x][x]=S[y][y]=1;
		S[x]=(S[y]|=S[x]);
		S[x][y]=S[y][x]=1;
	}
	int cnt=0;
	for (int i=1;i<=n;i++)
	for (int j=1;j<i;j++)
	if (!S[i][i]&&!S[j][j]&&!S[i][j]&&!S[j][i]&&(S[i]&S[j]).none()) cnt++;
	printf("%d\n",cnt);
	return 0;
}

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

using namespace std;

int main() {
    int N;
    int K;
    long long int sum = 0;
    cin >> N >> K;
    long long int H[N];
    for(int i=0; i<N; i++){
        cin >> H[i];
    }
    sort(H, H+N);
    if(N-K > 0){
    for(int i=0; i<(N-K); i++){
        sum += H[i];
    }
    }else{
        sum = 0;
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cstdint>
  
using namespace std;
  
const int INF = 10000000;
  
int solve(vector<vector<int>> &dists)
{
    const int v = dists.size();
  
    vector<vector<int>> dp(1 << v, vector<int>(v, INF));
    dp[1][0] = 0;
  
    const int all = (1 << v) - 1;
  
    for (std::size_t S = 1; S <= all; S++)
    {
        std::size_t tS = S;
        while (tS > 0) {
            int bs = tS & ~(tS - 1);
            int s = __builtin_ctzll(bs);
            for (int e = 0; e < v; e++) {
                if (dists[s][e] != INF && (~S & (1 << e)) != 0) {
                    const int nS = S | (1 << e);
                    if (nS == all) {
                        dp[nS][e] = min(dp[nS][e], dp[S][s] + dists[s][e] + dists[e][0]);
                    } else {
                        dp[nS][e] = min(dp[nS][e], dp[S][s] + dists[s][e]);
                    }
                }
            }
            tS -= bs;
        }
    }
  
    int ans = INF;
    for (int i = 0; i < v; i++) {
        ans = min(ans, dp[all][i]);
    }
    return ans == INF ? -1 : ans;
}
  
int main()
{
    int v, e;
    cin >> v >> e;
      
    vector<vector<int>> dists(v, vector<int>(v, INF));
    for (int i = 0; i < e; i++) {
        int s, e, d;
        cin >> s >> e >> d;
        dists[s][e] = d;
    }
  
    cout << solve(dists) << endl;
  
    return 0;
}


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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;
using vb=vector<bool>;using vs=vector<string>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<typename T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<'('<<p.fst<<", "<<p.snd<<')';}
template<class T>ostream&operator<<(ostream&o,const vector<T>&t){o<<"{";rep(i,sz(t))o<<t[i]<<",";o<<"}";return o;}
#define out(args...){vector<string> a_r_g_s=__split(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> __split(const string& s,char c){vector<string>v;stringstream ss(s);string x;while(getline(ss,x,c))v.emplace_back(x);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T,typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){if(*it==" 1"||*it=="1")cerr<<endl;else cerr<<it->substr((*it)[0]==' ',it->length())<<" = "<<a<<", ";e_r_r(++it, args...);}

void Main() {
  int n = read<int>();

  vector<int> A(n);
  map<int, vi> M;

  rep(i, 1, n) {
    A[i] = read<int>()-1;
    M[A[i]].push_back(i);
  }
  A[0] = -1;
  //out(A, 1);

  /*
  forr(p, M) {
    cout << "p.fst: "<<p.fst << endl;
    cout << "p.snd:"; rep(ii,sz(p.snd)) cout << ' ' << p.snd[ii]; cout << endl;
  }
  */

  function<int(int)> rec = [&](int cur) {
    //_p("rec(%d)\n", cur);
    vi D;
    forr(m, M[cur]) {
      int ret = rec(m);
      //out(m, ret, 1);
      D.push_back(ret);
    }
    if (sz(D) == 0) return 0;
    sort(all(D), greater<decltype(D)::value_type>());
    //out(cur, D, 1);
    rep(i, sz(D)) {
      D[i] += i + 1;
    }
    //out(cur, D, 1);

    return *max_element(all(D));
  };

  int ans = rec(0);
  cout << ans << endl;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	int n;
	cin >> n;

	vector<int> input;
	vector<bool> fig(1'000'001, false);

	rep(i, n){
		int a;
		cin >> a;
		input.push_back(a);
	}
	
	sort(input.begin(), input.end());

	int ans = 0;
	rep(i, n){
		int a = input[i];

		if(!fig[a]){
			if(i == 0 && input[i] != input[i + 1]) ans++;
			else if(i == n - 1 && input[i] != input[i - 1]) ans++;
			else if(input[i] != input[i - 1] && input[i] != input[i + 1]) ans++; 

			for(int i = 0; i * a < 1'000'001; i++){
				fig[i * a] = true;
			}
		}
	}
	
	cout << ans;
	return 0;
}

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

int main(){
  int W,a,b;
  cin >> W >> a  >>b;
  int res;
  if(abs(a-b)<=W){
    res=0;
  }
  else{
    res=abs(a-b)-W;
  }
  cout << res << endl;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	int X;
	cin >> X;

	ll ans = 0;

	// 貪欲に換金
	ans += (X / 500) * 1000;
	if((X / 500) > 0){
		X = X % 500;
	}
	ans += (X / 5) * 5;

	cout << ans << endl;

	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    b = max(0LL, min(b, b-(k-a)));
    a = max(0LL, a-k);
    cout << a << " " << b << endl;

    return 0;
}


Measured memory_bytes: 3628
h, w = map(int, input().split())
s = [input() for i in range(h)]
yoko = [([0] * w) for i in range(h)]
tate = [([0] * w) for i in range(h)]
 
for i in range(h):
    f = 0
    j = 0
    m = 0
    while j < w:
        if s[i][j] == ".":
            if m == 0:
                j += 1
            else:
                f = j
                m = 0
                j += 1
        else:
            if m == 0:
                for p in range(f, j):
                    yoko[i][p] = j - f
            m = 1
            j += 1
    if m == 0:
        for p in range(f, j):
            yoko[i][p] = j - f
 
for i in range(w):
    f = 0
    j = 0
    m = 0
    while j < h:
        if s[j][i] == ".":
            if m == 0:
                j += 1
            else:
                f = j
                m = 0
                j += 1
        else:
            if m == 0:
                for p in range(f, j):
                    tate[p][i] = j - f
            m = 1
            j += 1
    if m == 0:
        for p in range(f, j):
            tate[p][i] = j - f
ans = 0
for i in range(h):
    for j in range(w):
        q = yoko[i][j] + tate[i][j] - 1
        if q > ans:
            ans = q
print(ans)

Measured memory_bytes: 123224
#include<stdio.h>
#include<string.h>
#define max(a,b)a>b?a:b
int r,c,m[99][99],i,j,t,a,v[5]={0,1,0,-1,0};

int f(int p,int q)
{
	int i,an=1,t;
	m[p][q]=0;
	for(i=0;i<4;i++)
		if(m[p+v[i]][q+v[i+1]])
		{
			t=f(p+v[i],q+v[i+1])+1;
			an=max(an,t);
		}
	m[p][q]=1;
	return an;
}

int main()
{
	for(;scanf("%d%d",&r,&c),r;)
	{
		memset(m,0,sizeof(m));
		for(i=1;i<=r;i++)
			for(j=1;j<=c;j++)
				scanf("%d",&m[i][j]);
		for(i=1,a=0;i<=r;i++)
			for(j=1;j<=c;j++)
				if(m[i][j])
				{
					t=f(i,j);
					a=max(a,t);
				}
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,x,i,j;
    cin>>n;
    int dp[1][3];
    for(i=0;i<3;++i)
    {
        cin>>x;
        dp[0][i] = x;
    }
    for(i=1;i<n;++i)
    {
        for(j=0;j<3;++j)
        {
            cin>>x;
            dp[1][j] = max(dp[0][(j+1)%3],dp[0][(j+2)%3]) + x;
        }
        for(j=0;j<3;++j)
            dp[0][j] = dp[1][j];
    }
    cout<<max({dp[(n==1)?0:1][0],dp[(n==1)?0:1][1],dp[(n==1)?0:1][2]});
}

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

#pragma GCC optimize ("-O2")
#define ll long long
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define testcase(t) int t;cin>>t;while(t--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
#define what_is(x)  cerr << #x << " is " << x << endl;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

const int N=1e5+5,MOD=1e9+7;

int main(){

	IOS;

	ll n;
	cin>>n;

	while(n!=0){
		ll d=n%10;
		if(d==7){
			cout<<"Yes"<<endl;
			return 0;
		}
		n/=10;
	}

	cout<<"No"<<endl;
	






	return 0;
}
 
/*

*/









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

int main(){
  int n; cin >> n;
  vector<int> a(n+1);
  vector<int> b(n+1);
  for(int i = 1; i < n+1; i++) cin >> a[i];
  int m = 0;
  for(int i = n; i > 0; i--){
    int sum = 0;
    for(int j = 2*i; j < n+1; j+=i){
      sum+=b[j];
    }
    if(sum%2!=a[i]){
      b[i] = 1;
      m++;
    }
  }
  cout << m << endl;
  for(int i = 1; i < n+1; i++){
    if(b[i]==1) cout << i << " ";
  }
}


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

int main() {
	int n , q; cin >> n >> q;
	string s;
	cin >> s;
	for(int i = 0 ; i < n ; i++){
		if(s[i] == 'A' && s[i+1] == 'C') s[i] = 'a';
	}
	vector<int> a(n,0), sum(n+1,0);
	for(int i = 0 ; i < n ; i++){
		if(s[i] == 'a') a[i] = 1;
	}
	for(int i = 0 ; i < n ; i++){
		sum[i+1] = sum[i] + a[i];
	}
	for(int i = 0 ; i < q ; i++){
		int l,r; cin >> l >> r;
		cout << sum[r-1] - sum[l-1] << endl;
	}
}

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

int main(){
    char o[51], e[51];
    char ans[103];
    cin >> o >> e;
    for(int i=0; i<51; i++){
        ans[2*i]=o[i];
        ans[2*i+1]=e[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool prime[1000001];  //sieve of erastothenes(primality check 1 to 10^6)
void sieve()
{
	for(int i=2;i<1000000;i++)
		prime[i]=true;
	for(int i=2;i<=1000;i++)
	{
		if(prime[i])
		{
			for(int j=i*i;j<=1000000;j+=i)
				prime[j]=false;
		}
	}
}
ll binpow(ll a, ll b) {      
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	ll dividend = a>=b ? a:b;
	ll divisor = a<=b ? a:b;
	
	while(divisor!=0)
	{
		ll remainder = dividend%divisor;
		dividend = divisor;
		divisor = remainder;
	}
	return dividend;
}
int main()
{
    ios_base::sync_with_stdio(false);   
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll val,num;
	 cin >> val;
    num = val;
    ll sum =0;
    while (num != 0)
    {
        sum = sum + num % 10;
        num = num / 10;
    }
	if(val%sum==0)
	{
		cout<<"Yes";
	}
	else
	cout<<"No";
}

Measured memory_bytes: 256
N, M = gets.chomp.split(" ").map(&:to_i)
H = gets.chomp.split(" ").map(&:to_i)

nb = {}
M.times do |i|
  a, b = gets.chomp.split(" ").map(&:to_i)
  a -= 1
  b -= 1
  nb[a] ||= []
  nb[b] ||= []
  nb[a] << b
  nb[b] << a
end

ans = 0
0.upto(N-1) do |i|
  if nb[i].nil?
    ans += 1
  else
    hs = (nb[i] || []).map {|v| H[v]}.sort.reverse
    if H[i] > hs.max
      ans += 1
    end
  end
end
puts ans


Measured memory_bytes: 33132
#include <iostream>
#include <algorithm>

int main()
{
	int n;
	std::cin >> n;

	int a[ n ];
	for( int i = 0; i < n; i++ ) {
		std::cin >> a[ i ];
	}

	std::sort( a, a + n, std::greater<int> () );

	int ans = 0;
	for( int i = 0; i < n; i++ ) {
		if( i % 2 == 0 ) {
			ans += a[ i ];
		}
		else {
			ans -= a[ i ];
		}
	}

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


Measured memory_bytes: 256
A, B, C, D, E, F = map(int, input().split())
water = [(A * i + B * j) * 100 for i in range(31) for j in range(31)][1:]
sugar = [C * i + D * j for i in range(101) for j in range(101)]

res = [100, -1]
for w in water:
    for s in sugar:
        if w + s <= F and s <= w * E // 100:
            if s / (w + s) > res[1] / res[0]:
                res = [w + s, s]

print(" ".join(map(str, res)))


Measured memory_bytes: 3444
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define int      long long int
#define MOD      1000000007
#define pb       push_back
#define mp       make_pair
#define vi       vector<int>
#define mi  	 map<int,int>
#define umi		 unordered_map<int,int>
#define pii      pair<int,int>
#define ff 		 first
#define ss 		 second
#define inf		 1e18
#define case	int t;cin>>t;while(t--)
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void pre()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int32_t main()
{	//pre();
	//case
	{	int n;
		cin >> n;
		double p[n];
		for (int i = 0; i < n; i++)
			cin >> p[i];
		double dp[n][n];
		dp[0][0] = p[0];
		double ck[n];
		ck[0] = 1 - p[0];
		for (int i = 1; i < n; i++)
		{	dp[i][i] = dp[i - 1][i - 1] * p[i];
			ck[i] = ck[i - 1] * (1 - p[i]);
			dp[0][i] = dp[0][i - 1] * (1 - p[i]);
			//		if (i == 1)
			//			cout << dp[0][i] << endl;
			dp[0][i] += p[i] * ck[i - 1];
			//		if (i == 1)
			//			cout << p[i] * ck[i - 1] << endl;

		}
		//	for (int i = 0; i < n; i++)
		//cout << dp[1][2] << " ";
		int tp = n / 2;
		double ans = 0;
		for (int i = 1; i < n; i++)
		{	for (int j = i + 1; j < n; j++)
			{	dp[i][j] = dp[i][j - 1] * (1 - p[j]);
				//	if (i == 1 && j == 2)
				//		cout << dp[1][2] << endl;
				dp[i][j] += dp[i - 1][j - 1] * p[j];
				if (j == n - 1 && i >= tp)
					ans += dp[i][j];
			}
		}

		cout << fixed << setprecision(10) << ans + dp[n - 1][n - 1];

	}
	return 0;
}

Measured memory_bytes: 70528
#include <bits/stdc++.h>
#define le 52
using namespace std;
int n[le];
int main(){
  //freopen("input.txt", "r", stdin);
  int len, m, a, b;
  cin >> len >> m;
  for(int i = 0; i < m; i++){
    cin >> a >> b;
    n[a]++;
    n[b]++;
  }
  for(int i = 1; i < len + 1; i++){
    cout << n[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
class PriorityQueue
  
  def initialize
    @heap = Array.new
    @sz = 0
  end
  
  def push x
    i = @sz
    @sz += 1
    while i > 0 do
      p = ( i - 1 ) / 2
      break if @heap[p] <= x
      @heap[i] = @heap[p]
      i = p
    end
    @heap[i] = x
  end
  
  def pop
    
    ret = @heap[0]
    x = @heap[@sz-=1]
    
    i = 0
    while i * 2 + 1 < @sz do
      a = i * 2 + 1
      b = i * 2 + 2
      a = b if b < @sz && @heap[b] < @heap[a]
      break if @heap[a] >= x
      @heap[i] = @heap[a]
      i = a
    end
    
    @heap[i] = x
    @heap.delete_at(-1)
    ret
  end
  
  def top
    @heap[0]
  end
  
  def empty?
    @sz == 0
  end
  
  def all
    @heap
  end
end

n, m = gets.to_s.split.map{|t| t.to_i }
dr   = Array.new(n){ gets.to_s.split.map{|t| t.to_i } }.sort_by{|_,r|-r}.sort_by{|d,_|d}

pq = PriorityQueue.new

ans = 0
cur = 0
(1..m).each do |i|
  
  while dr[cur] && dr[cur][0] == i do
    pq.push -dr[cur][1]
    cur += 1
  end
  pq.empty? || ans += -pq.pop
end

puts ans

Measured memory_bytes: 13520
#include <iostream>
#include <cstdio>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define all(x) (x).begin(), (x).end()

#ifdef LOCAL
#define dbg(x) cerr << #x " = " << x << endl;
#define idbg(x) #x " = " << x
#include "pretty_print.h"
#else
#define dbg(x)
#define idbg(x) ""
#endif

#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

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

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }


int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif


    ll a, b, v, w, t;
    while (cin >> a >> v >> b >> w >> t) {
        cout << ((v - w) * t >= abs(a - b)? "YES" : "NO") << endl;
    }

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


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

int main()
{  
    long long a,b,k;
    cin>>a>>b>>k;
    if(k>a+b)
    {
        cout<<0<<" "<<0<<endl;
    }
    else if(k>a)
    {
        cout<<0<<" "<<a+b-k<<endl;
    }
    else
    {
        cout<<a-k<<" "<<b<<endl;
    }        
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
//#include <algorithm>
#include<set>
#include <limits>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
#define d9_7 1000000007
struct result{
  int x1;
  int y1;
  int x2;
  int y2;
};
int main(void){
  int H,W;
  cin >> H >> W;
  int a[H][W];
  rep(i,H){
    rep(j,W){
      cin >> a[i][j];
    }
  }
  int N=0;
  vector<result> results;
  rep(i,H){
    rep(j,W){
      /*rep(k,H){
        rep(l,W){
          cout<<a[k][l]<<" ";
        }
        cout<<endl;
      }
      cout << endl;*/
      if(i>0){
        if(a[i][j]%2==1){
          if(a[i-1][j]%2==1){
            N++;
            results.push_back({i+1,j+1,i,j+1});
            a[i][j]--;
            a[i-1][j]++;
            continue;
          }
        }
      }
      if(j>0){
        if(a[i][j]%2==1){
          if(a[i][j-1]%2==1){
            N++;
            results.push_back({i+1,j+1,i+1,j});
            a[i][j]--;
            a[i][j-1]++;
            continue;
          }
        }
      }
      if(a[i][j]%2==1){
        if(i<H-1){
            N++;
            results.push_back({i+1,j+1,i+2,j+1});
            a[i][j]--;
            a[i+1][j]++;
            continue;
        }
        if(j<W-1){
            N++;
            results.push_back({i+1,j+1,i+1,j+2});
            a[i][j]--;
            a[i][j+1]++;
            continue;
        }
      }
    }
  }
  cout << N << endl;
  rep(i,N){
    cout<< results[i].x1 << " "<< results[i].y1 << " "<<results[i].x2 << " "<<results[i].y2 << endl;
  }
  /*cout << endl;
      rep(k,H){
        rep(l,W){
          cout<<a[k][l]<<" ";
        }
        cout<<endl;
      }
      cout << endl;*/
	return 0;
}

Measured memory_bytes: 5104
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(X: int):
    if X >= 30:
        ret = YES
    else:
        ret = NO
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61576
#include<bits/stdc++.h>
using namespace std;
string S;
int n,d,c;
int main(){
	cin>>n>>S;
	for(int i=0;i<S.size();i++)
	{
		if(S[i]=='(')c++;
		else c--;
		d=min(d,c);
	}
	for(int i=0;i<-d;i++)
		cout<<"(";
	cout<<S;
	for(int i=0;i<c-d;i++)
		cout<<")";
	return 0;
}

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

#define int long long

using namespace std;

int dp[3010][3010];

int32_t main()
{
    string s1,s2;
    int n,m;
    cin >> s1 >> s2;
    n = s1.size();
    m = s2.size();

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s1[i-1] == s2[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }

    string ans;

    while(dp[n][m] != 0)
    {
        if(s1[n-1] == s2[m-1])
        {
            ans += s1[n-1];
            n--;
            m--;
        }
        else if(dp[n-1][m] == dp[n][m])
            n--;
        else
            m--;
    }

    reverse(ans.begin(),ans.end());

    cout << ans << endl;
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int N, Q;
  cin >> N >> Q;

  string s;
  cin >> s;
  s = " " + s + " ";

  vector<char> t(Q), d(Q);
  REP(i, Q) cin >> t[i] >> d[i];

  int low = 0;
  int high = N + 1;
  while (high - low > 1) {
    int mid = (high + low) / 2;

    bool isin = true;
    int idx = mid;
    REP(i, Q) {

      if (t[i] == s[idx]) {
        if (d[i] == 'L')
          idx--;
        else
          idx++;
      }

      if (idx < 1 or N < idx) {
        isin = false;
        break;
      }
    }

    if (isin)
      high = mid;
    else
      low = mid;
  }

  int lans = high;
  // cout << high << " " << low << endl;

  low = 0;
  high = N + 1;
  while (high - low > 1) {
    int mid = (high + low) / 2;

    bool isin = true;
    int idx = mid;
    REP(i, Q) {

      if (t[i] == s[idx]) {
        if (d[i] == 'L')
          idx--;
        else
          idx++;
      }

      if (idx < 1 or N < idx) {
        isin = false;
        break;
      }
    }

    if (isin)
      low = mid;
    else
      high = mid;
  }
  int rans = low;

  // cout << high << " " << low << endl;
  cout << max(rans - lans + 1, 0) << endl;

  return 0;
}


Measured memory_bytes: 952
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
struct P : IEquatable<P>
{
	public int I, C;
	public P(int i, int c)
	{
		I = i;
		C = c;
	}
	public bool Equals(P p) => I == p.I;
	public override int GetHashCode() => I.GetHashCode();
	public override bool Equals(object obj) => obj is P && Equals((P)obj);
}
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int n, log;
	HashSet<P>[] es;
	int[] par;
	long[] dist;
	void Solve()
	{
		int[] I;
		n = F();
		while (n > (1 << log)) log++;
		es = new HashSet<P>[n];
		for (int i = 0; i < n; i++) es[i] = new HashSet<P>();
		for (int i = 1; i < n; i++)
		{
			I = G();
			int a = I[0] - 1, b = I[1] - 1, c = I[2];
			es[a].Add(new P(b, c));
			es[b].Add(new P(a, c));
		}
		par = new int[n];
		dist = new long[n];
		I = G();
		int Q = I[0], K = I[1] - 1;
		DFS(K, -1, 0);
		for (int i = 0; i < Q; i++)
		{
			I = G();
			int x = I[0] - 1, y = I[1] - 1;
			Console.WriteLine(dist[x] + dist[y]);
		}
	}
	void DFS(int u, int p, long d)
	{
		dist[u] = d;
		par[u] = p;
		es[u].Remove(new P(p, 0));
		foreach (var v in es[u]) DFS(v.I, u, d + v.C);
	}
}


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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  ll A, B, K;
  std::cin >> A >> B >> K;

  if(K <= A) {
    std::cout << A - K << ' ' << B << '\n';
  } else {
    std::cout << 0 << ' ' << std::max(0LL, B - (K - A)) << '\n';
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int MOD = 1e9 + 7;
constexpr int M = 3;

int main() {
  int n;
  cin >> n;

  vector<ll> dp(n + 1);
  dp[0] = 1;
  for (int i = 0; i <= n - M; i++) {
    for (int j = M; j <= n; j++) (dp[i + j] += dp[i]) %= MOD;
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,k,l,s;
    cin>>n;
    s=0;
    for(i=0;i<n;i++)
    {
        cin>>k;
        s+=k;
    }
    s-=n;
    cout<<s<<endl;
    return 0;
}


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

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


Measured memory_bytes: 256
n = int(input())
monst = list(map(int,input().split()))
hero = list(map(int,input().split()))
attack = 0

for i in range(n):
    if monst[i] >= hero[i]:
        attack += hero[i]
    else:
        attack += monst[i]
        hero[i] = hero[i] - monst[i]
        if monst[i+1] > hero[i]:
            attack += hero[i]
            monst[i+1] = monst[i+1] - hero[i]
        else:
            attack +=  monst[i+1]
            monst[i+1] = 0
print(attack)


Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	vector<int> a(3);
	rep(i,3)cin >> a[i];
	sort(ALL(a));
	rep(i,3)
	{
		if(i)cout<<' ';
		cout<<a[i];
		
	}cout<<endl;
	return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <algorithm>

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

#define INFTY 1000000007

using namespace std;

int n;
int A[7000000];
int cnt=0;

void merge(int left, int mid, int right){

    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1+1], R[n2+1];
    for(int i=0; i<n1; i++) L[i] = A[left+i];
    for(int i=0; i<n2; i++) R[i] = A[mid+i];

    L[n1] = INFTY;
    R[n2] = INFTY;
    int i = 0, j = 0;

    for(int k=left; k<right; k++){
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
        cnt++;
    }
}

void mergeSort(int left, int right){
    if(left+1 < right){
        int mid = (left + right) / 2;
        mergeSort(left, mid);
        mergeSort(mid, right);
        merge(left, mid , right);
    }
}


int main(){

    cin >> n;
    for(int i=0; i<n; i++) cin >> A[i];
    int l, r;
    l = 0;
    r = n;

    mergeSort(l, r);
    for(int i=0; i<n-1; i++) cout << A[i] << " ";
    cout << A[n-1] << endl;
    cout << cnt << endl;

    return 0;
}

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

int main(){
  string o,e;
  cin>>o>>e;
  int n=min(o.size(),e.size());
  REP(i,n){
    cout<<o[i]<<e[i];
  }
  if (o.size()>e.size())
  {
    /* code */
    cout<<o[n]<<endl;
  }

  }

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
#include<string>

using namespace std;
#define N2 9
#define N  3
struct Puzzle
{
    int f[N2];
    int space;
    string path;
    bool operator < (const Puzzle &p)const {
            for(int i=0;i<N2;i++){
            if(f[i]==p.f[i])continue;
            return f[i]>p.f[i];
            }
        return false;
    }
};
const int dx[4]={-1,0,1,0};
const int dy[4]={0,-1,0,1};
const char dir[4]={'u','l','d','r'};
bool isTarge(Puzzle p)
{
    for(int i=0;i<N2;i++)if(p.f[i]!=i+1)return false ;
    return true;
}
string bfs(Puzzle s)
{
    queue<Puzzle> q;
    map<Puzzle,bool>V;
    Puzzle u,v;
    s.path="";
    q.push(s);
    V[s]=true;
    while(!q.empty())
    {
        u=q.front();q.pop();
        if(isTarge(u))return u.path;
        int sx=u.space/N;
        int sy=u.space%N;
        for(int i=0;i<4;i++)
        {
            int nx=sx+dx[i];
            int ny=sy+dy[i];
            if(nx<0||ny<0||nx>=N||ny>=N)continue;
            v=u;
            swap(v.f[u.space],v.f[nx*N+ny]);
            v.space=nx*N+ny;
            if(!V[v])
            {
                V[v]=true;
                v.path+=dir[i];
                q.push(v);
            }
        }
    }
    return "unsovleable";
}
int main()
{
    Puzzle in;
    for(int i=0;i<N2;i++)
    {
        cin>>in.f[i];
        if(in.f[i]==0)
        {
            in.f[i]=N2;
            in.space=i;
        }
    }
    string ans=bfs(in);
    cout<<ans.size()<<endl;
    return 0;
}



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

int a, b;

int main() { // claudio van
  cin >> a >> b;
  if (a < 10 and b < 10) {
    cout << a * b << "\n";
  } else {
    cout << -1 << "\n";
  }
  return 0;
}

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

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

template <typename T> constexpr T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;
template <> constexpr double inf<double> = 1e18;

int main() {
    int N; scanf("%d", &N);
    vector<int> a(N), b(N);
    for(int i = 0; i < N; ++i) {
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < N; ++i) {
        scanf("%d", &b[i]);
    }

    vector<vector<vector<int>>> c(32, vector<vector<int>>(2));
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < 29; ++j) {
            c[j][(b[i] >> j) & 1].push_back(b[i] & ((1 << j) - 1));
        }
    }
    for(int i = 0; i < 32; ++i) {
        for(int j = 0; j < 2; ++j) {
            sort(begin(c[i][j]), end(c[i][j]));
        }
    }

    int ans = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < 29; ++j) {
            int b = (a[i] >> j) & 1;
            int x = a[i] & ((1 << j) - 1);
            if(b) {
                int cnt = (lower_bound(begin(c[j][0]), end(c[j][0]), (1 << j) - x) - begin(c[j][0]));
                cnt += c[j][1].size() - (lower_bound(begin(c[j][1]), end(c[j][1]), (1 << j) - x) - begin(c[j][1]));
                ans ^= (cnt & 1) << j;
            } else {
                int cnt = (lower_bound(begin(c[j][1]), end(c[j][1]), (1 << j) - x) - begin(c[j][1]));
                cnt += c[j][0].size() - (lower_bound(begin(c[j][0]), end(c[j][0]), (1 << j) - x) - begin(c[j][0]));
                ans ^= (cnt & 1) << j;
            }
        }
    }

    cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

const int INF = 1001001001;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

template <int mod>
struct ModInt {
  int x;
  ModInt(): x(0) {}
  ModInt(long long a) { x = a % mod; if (x < 0) x += mod; }
  ModInt &operator+=(ModInt that) { x = (x + that.x) % mod; return *this; }
  ModInt &operator-=(ModInt that) { x = (x + mod - that.x) % mod; return *this; }
  ModInt &operator*=(ModInt that) { x = (long long) x * that.x % mod; return *this; }
  ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
  ModInt inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return ModInt(u);
  }
  #define op(o, p) ModInt operator o(ModInt that) { return ModInt(*this) p that; }
    op(+, +=) op(-, -=) op(*, *=) op(/, /=)
  #undef op
  friend ostream& operator<<(ostream &os, ModInt m) { return os << m.x; }
};

using mint = ModInt<1000000007>;

void solve() {
  int n, m;
  cin >> n >> m;
  vi32 x(n), y(m);
  cin >> x >> y;
  mint xsum = 0;
  mint ysum = 0;
  rep(i, n) {
    int a = (n / 2) * -2 + (n % 2 == 0) + i * 2;
    xsum += (mint) x[i] * a;
  }
  rep(i, m) {
    int a = (m / 2) * -2 + (m % 2 == 0) + i * 2;
    ysum += (mint) y[i] * a;
  }
  cout << xsum * ysum << endl;
}


Measured memory_bytes: 1024
s = int(input())
al = [s]
def modify(n):
  if n % 2 == 0:
    return n // 2
  else:
    return 3 * n + 1
for i in range(2,10 ** 6 + 1):
  a = modify(al[i - 2])
  if a in al:
    print(i)
    break
  else:
    al.append(a)

Measured memory_bytes: 3060
# include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){

  int N; cin >> N;
  int d[N];
  for(int i=0; i < N; i++){
    cin >> d[i];
  }
  sort(d, d+N);
  int ans = d[N/2] - d[N/2-1];
  cout << ans << endl;
}


Measured memory_bytes: 640
// Problem : H - Grid 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_h
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define tc ll t;cin>>t;while(t--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF 1e18

int main()
{
	io;

	ll h,w;
	cin>>h>>w;
	
	vector< vector<char> > g(h,vector<char>(w));
	FOR(i,0,h)
	{
		FOR(j,0,w)
		{
			cin>>g[i][j];
		}
	}
	
	vvll dp(h,vll(w,0));
	
	FOR(i,1,h)
	{
		if(g[i][0]=='.')
		{
			dp[i][0]=1;
		}
		else{break;}
	}
	FOR(j,1,w)
	{
		if(g[0][j]=='.')
		{
			dp[0][j]=1;
		}
		else{break;}
	}
	FOR(i,1,h)
	{
		FOR(j,1,w)
		{
			if(g[i][j]=='.')
			{
				dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
			}
		}
	}
	cout<<dp[h-1][w-1];
	return 0;
}


Measured memory_bytes: 11008
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
//        Int R;
//        cin >> R;
//
//        double ans = 6.28318530717958623200 * R;
//        cout << ans << endl;

        Int N, M;
        cin >> N >> M;
        rep(i, 0, M) {
            Int tmp;
            cin >> tmp;
            N -= tmp;
        }
        if (N < 0) cout << -1 << endl;
        else cout << N << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    Solve().solve();


    return 0;
}


Measured memory_bytes: 3192
S = input()

S1 = S[0:2]
S2 = S[2:5]

if 1 <= int(S1) <= 12:
    if 1 <= int(S2) <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1 <= int(S2) <= 12:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 200
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 1000000009
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(int N, int pos){return (bool)(N & (1<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    int n;
    cin>>n;
    map<string, int>mp;
    for(int i = 0; i < n; i++)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    multimap<int, string, greater<int> >ans;
    for(auto X : mp)
    {
        ///cout<<X.first<<" "<<X.second<<endl;
        ans.insert({X.second, X.first});
    }
    int last = -1;
    for(auto u : ans)
    {
        if(last==-1 || last==u.first)
            cout<<u.second<<endl;
        else
            break;
        last = u.first;
    }

    //End();
    return 0;
}


Measured memory_bytes: 38528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
/*LCS gfg*/

void solve()
{
    ll n,w,i,j,m,z,k,h,mod = 1e9+7;
    double x,y;
    cin >> n;
    double a[n];
    for(i=0;i<n;i++)
        cin >> a[i];
    double dp[n][n+1];
    memset(dp,0.0,sizeof(dp));
    dp[0][0] = 1.0 - a[0];
    dp[0][1] = a[0];
    for(i=1;i<n;i++)
    {
        for(j=0;j<n+1;j++)
        {
            x = 0;
            y = 0;

            if(j>=1)
            {
                x = a[i]*dp[i-1][j-1];
                //cout << "here = " << x << "\n";
            }

            y = (1-a[i])*dp[i-1][j];

            dp[i][j] = x+y;

        }
    }


    double ans = 0.0;
    x = (n+1)/2;
    for(i=x;i<n+1;i++)
        ans += dp[n-1][i];
    cout << setprecision(10) << ans;



}
int main()
{

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
	//cin >> t;
	while(t-- > 0)
	{
		solve();
	}

}


Measured memory_bytes: 74096
#include <stdio.h>
int casep(int i);

int main(void) {
    int i = 1;
    
    while(1){
    	if(casep(i) == 0)break;
    	i++;
    }
return 0;
}

int casep(int i){
	int x ;
	
	scanf("%d",&x);
	if (x == 0) return 0;
	else{
		printf("Case %d: %d\n",i,x);
		return 1;
		}
	
}

Measured memory_bytes: 600