akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_BC = [list(map(int, input().split())) for _ in range(M)]


lst_A.sort()
# lst_BC.sort(key=lambda x:-x[1])
lst_BC.sort(key=lambda x:x[1], reverse=True)
# print(lst_A)
# print(lst_BC)


lst_D = []
for b, c in lst_BC:
    lst_D += [c] * min(b, N - len(lst_D))
lst_D = lst_D + [0] * (N - len(lst_D))
# print(lst_D)


for i in range(N):
    if lst_A[i] >= lst_D[i]:
        break
    lst_A[i] = lst_D[i]
# print(lst_A)


print(sum(lst_A))

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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, r;
    cin >>n >> r;
    if(n<10)
        r+=(10-n)*100;
    cout << r;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

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

using namespace std;
using ll = long long;

const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  int N;
  cin >> N;
  vector<ll> A(N + 1), B(N);
  for(int i = 0; i < N + 1; i++) {
    cin >> A[i];
  }
  for(int i = 0; i < N; i++) {
    cin >> B[i];
  }

  ll ans = 0;
  for(int i = 0; i < N; i++) {
    ll diff = min(A[i], B[i]);
    ans += diff;
    B[i] -= diff;
    if(B[i] != 0) {
      diff = min(A[i + 1], B[i]);
      A[i + 1] -= diff;
      ans += diff;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int out[10]={0};
    rep(i,n){
      int a;cin>>a;
      out[a]++;
    }
    rep(i,10){if(out[i])rep(j,out[i])cout<<'*';else cout<<'-';cout<<endl;}
  }
}

Measured memory_bytes: 1152
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 1400

int dp[MAX][MAX], G[MAX][MAX];

int getLargestSquare(int H, int W){
int maxWidth = 0;
for(int i = 0; i < H; ++i){
for(int j = 0; j < W; ++j){
dp[i][j] = (G[i][j] + 1) % 2;
maxWidth |= dp[i][j];
}
}
for(int i = 1; i < H; ++i){
for(int j = 1; j < W; ++j){
if(G[i][j]){
dp[i][j] = 0;
}else{
dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
maxWidth = max(maxWidth, dp[i][j]);
}
}
}
return maxWidth * maxWidth;
}

int main(void){
int H, W;
cin >> H >> W;
for(int i = 0; i < H; ++i){
for(int j = 0; j < W; j++) {
cin >> G[i][j];
}
}

     cout << getLargestSquare(H, W) << endl;

     return 0;
}


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

using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;
const int MAXN = 1e4 + 10;
ll dp[MAXN][128], num[MAXN];
char s[MAXN];
int len, D;

ll dfs(int pos, int tot, bool lim) {
	if (pos == len + 1) return dp[pos][tot] = (tot == 0);
	if (!lim && dp[pos][tot] != -1) return dp[pos][tot];
	int up = lim ? num[pos] : 9;
	ll ret = 0;
	for (int i = 0; i <= up; i++) {
		ret += dfs(pos + 1, (tot + i) % D, lim && (i == up));
		ret %= mod;
	}
	if (!lim) dp[pos][tot] = ret;
	return ret;
}

int main() {
	memset(dp, -1, sizeof(dp));
	scanf("%s%d", s + 1, &D);
	len = strlen(s + 1);
	for (int i = 1; i <= len; i++) num[i] = s[i] - '0';
	ll ans = (dfs(1, 0, 1) - 1 + mod) % mod;
// minus one to deduct the zero
	cout << ans << endl;
	return 0;
}
 

Measured memory_bytes: 14632
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{
  unsigned long int N, A, B;
  cin >> N >> A >> B;

  unsigned long int Nb = 0;

  unsigned long int set = (unsigned long int)(N/(A+B));
  Nb = set * A;

  if(N%(A+B) >= A){
    Nb += A;
  }
  else{
    Nb += (N%(A+B));
  }

  cout << Nb << endl;

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int h, w;
    cin >> h >> w;
    vector< vector<char> > p(h+2);
    rep(i, h+2){
        p[i].resize(w+2, '#');
    }
    rep(i, h){
        rep(j, w){
            cin >> p[i+1][j+1];
        }
    }
    rep(i, h+2){
        rep(j, w+2){
            cout << p[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (110)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

void Main() {
  const ll num = 41;
  ll N, K; cin >> N >> K;
  vector<ll> A(N);
  rep(i, 0, N) cin >> A[i];
  vector<ll> cnt(num, 0);

  rep(i, 0, N){
    ll a = A[i];
    rep(n, 0, num){
      if(a % 2 == 1) cnt[n]++;
      else cnt[n]--;
      a /= 2;
    }
  }
  
  ll X = 0;
  rep(i, 0, num){
    if(cnt[num - i - 1] < 0){
      if(X + pow(2, num - i - 1) <= K) X += pow(2, num - i - 1);
    }
  }

  ll res = 0;
  rep(i, 0, N){
    res += X ^ A[i];
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false);}
#define rmod(x, y) ((((x)%y)+y)%y)
using namespace std;
typedef long long ll;
typedef long double ld;

const ll mod = 1e9+7;
const int maxn = 1e5+5;
ll f[maxn];

ll fpow(ll a, ll b, ll p){
	a%=p; ll res = 1;
	while(b>0){
		if(b&1ll) res = res*a%p;
		a= a*a%p;
		b>>=1;
	}
	return res;
}

ll inv(ll x){return fpow(x, mod-2, mod);}
ll comb(ll n, ll k){
	if (k == 0 or n == k) return 1ll;
	ll ans = f[n]*inv(f[k])%mod * inv(f[n-k])%mod;
	return ans%mod;
}

int a[maxn];
int main(){
	f[0] = f[1] = 1;
	for(ll i = 2; i<maxn; i++) f[i] = (i*f[i-1])%mod;
	int n, k; scanf("%d %d", &n, &k);
	for(int i = 0; i<n; i++) scanf("%d", &a[i]);
	sort(a, a+n);
	ll add = 0, sub = 0;
	for(int i = 0; i<=n-k; i++) sub = rmod(sub+(rmod(ll(a[i])*comb(n-i-1, k-1), mod)), mod);
	reverse(a, a+n);
	for(int i = 0; i<=n-k; i++) add = rmod(add+(rmod(ll(a[i])*comb(n-i-1, k-1), mod)), mod);
	ll ans = rmod(add-sub, mod);
	cout << ans << endl;
	
	return 0;
}


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

void solve()
{
  int N; cin >> N;
  vector<pi> A(N);
  rep(i,N){
    int x; cin >> x;
    A[i]=pi(x,i);
  }
  sort(A.begin(),A.end());
  rep(i,N){
    cout << (A[i].second+1) << " ";
  }
  cout << endl;
}
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(11);
  solve();
  return 0; 
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;

  for (int i = 0 ; i < S.size(); ++i) {
    char c = S.at(i) - 'A' + N;
    S.at(i) = 'A' + c % 26;
  }
  cout << S << endl;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
int main() {
  int n,m,c;cin>>n>>m>>c;
  vector<int> b(m);
  REP(i,m){
    cin>>b[i];
  }
  int ans=0;
  REP(i,n){
    int sum=0;
    REP(j,m){
      int a;cin>>a;
      sum+=a*b[j];
    }
    sum+=c;
    if(sum>0){
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main()
{
  int n;
  cin >> n;
  int n2 = n;
  int t = 0;
  while(n2 != 0){
    t += n2 % 10;
    n2 /= 10;
  }
  if(n% t == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int a;
	cin>>a;
	string b;
	cin>>b;
	
	int c=0;
	for(int i=1;i<a;i++){
		int d=0;
		
		for(char k='a';k<='z';k++){
			bool left=false,right=false;
			
			for(int j=0;j<i;j++)
				if(b[j]==k)
					left=true;
			
			for(int j=i;j<a;j++)
				if(b[j]==k)
					right=true;
			
			if(left&&right)
				d++;
		}
		
	
			c = max(c,d);
	}
	
	cout<< c <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd>> Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod

int main(){
    ll N; cin>>N;
    vec d(N);
    rep(i,N) cin>>d[i];
    ll SUM=0;
    rep(i,N) SUM=(SUM^d[i]);
    rep(i,N) cout<<(SUM^d[i])<<' ';
    cout<<endl;
}

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

struct UnionFind {
  vector<int> d; // 親の番号、但し根の場合はサイズのマイナス
  UnionFind(int n): d(n,-1) {}
  int root(int x) { // 根を見つける
    if (d[x] < 0) return x;
    return d[x] = root(d[x]); // 経路圧縮
  }
  bool unite(int x, int y) { // 結合
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);} // 親が一緒
  int size(int x) { return -d[root(x)];} // サイズ
};

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> p(n);
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    UnionFind uf(n); // 初期化
    int x,y;
    rep(i,m){ 
        cin>>x>>y;
        x--;
        y--;
        uf.unite(x,y);
    }
    ll ans=0;
    rep(i,n){ 
        if(uf.root(p[i])==uf.root(i)) ans++;
    }
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  int n, m;
  cin >> n >> m;
  vi a(n);
  vi div;
  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      div.push_back(i);
      div.push_back(m / i);
    }
  }
  sort(all(div));
  rrep (i, div.size()) {
    if (m / div[i] >= n) {
      cout << div[i] << endl;
      return 0;
    }
  }
}


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

#define REP(i, stop) for (signed i = 0; i < stop; ++i)

#define S(i, j) ip[i * (N + 1) + j]

const signed is = 1 << 16;
char ib[is], *ip = ib, it;

using P = pair<int, int>;
signed N;
queue<P> que;
int parity[200];
P bfs(int s) {
	REP(i, N) parity[i] = -1;
	P p;
	que.push({s, 1});
	parity[s] = 0;
	while (!que.empty()) {
		p = que.front();
		que.pop();
		int i = p.first;
		int d = p.second;
		REP(j, N) {
			if (S(i, j) == '0') continue;
			if (parity[j] == -1) {
				parity[j] = 1 - parity[i];
				que.push({j, d + 1});
			} else if (parity[i] == parity[j]) {
				puts("-1\n");
				exit(0);
			}
		}
	}
	return p;
}

signed main() {
	fread_unlocked(ib, 1, is, stdin);
	while ((it = *ip++) != '\n') {
		N = N * 10 + it - '0';
	}
	P p = bfs(1);
	p = bfs(p.first);
	printf("%d\n", p.second);
}


Measured memory_bytes: 256
import numpy as np
n,m,x = map(int,input().split())
info = []
for i in range(n):
    info.append(list(map(int,input().split())))
info = np.array(info)


money = np.sum(info, axis = 0)[0]
flag = 0
for i in range(2**n):
    tem = np.zeros(m+1, dtype = int)
    for j in range(n):
        if ((i >> j) & 1):
            tem += info[j]
    skill = tem[1:]
    non = np.all(skill >= x)
    if non:
        flag = 1
        if tem[0] < money:
            money = tem[0]

if flag == 0:
    print(-1)
else:
    print(money)

Measured memory_bytes: 27312
#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int main(){
	ll n;
	string temp;
	cin >> n;
	map<string,ll> record;

	while(n--){ 
		cin >> temp;
		record[temp]++;
	}

	cout << "AC x " << record["AC"] << endl;
	cout << "WA x " << record["WA"] << endl;
	cout << "TLE x " << record["TLE"] << endl;
	cout << "RE x " << record["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            var result = 0;

            //重複を除く
            //var strD = str.Distinct().ToArray();
            //要素数
            //var strC = str.Count();

            for (int i = 0; i < n - 2; i++)
            {
                for (int j = (i+1); j < n - 1; j++)
                {
                    for (int k = (j+1); k < n; k++)
                    {
                        var triangle = TriangleSearch(int.Parse(str[i]), int.Parse(str[j]), int.Parse(str[k]));
                        if (triangle && str[i] != str[j] && str[i] != str[k] && str[j] != str[k])
                        {
                            //debug
                            //Console.WriteLine("--------debug--------");
                            //Console.WriteLine($"{i}, {j}, {k}");
                            result++;
                        }
                    }
                }
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }

        //三角形になるかどうか判定
        static bool TriangleSearch(int a, int b, int c)
        {
            if ((a + b) > c && (a + c) > b && (b + c) > a)
            {
                return true;
            }
            return false;
        }
    }
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n; std::cin >> n;
    vi h(n); rep(i, n) std::cin >> h[i];
    int ans = h[0];
    srep(i, 1, n) {
        if (h[i-1] < h[i]) ans += h[i]-h[i-1];
    }
    std::cout << ans << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main(){

    ll h, n;
    cin >> h >> n;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    vector<ll> dp(h + 10, MAX);
    rep(i, h) {
        rep(j, n) {
            if (i + 1 > a[j]) {
                dp[i + 1] = min(dp[i + 1], dp[i + 1 - a[j]] + b[j]);
            } else {
                dp[i + 1] = min(dp[i + 1], b[j]);
            }
        }
    }
    cout << dp[h] << endl;

}

Measured memory_bytes: 3700
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
  [n, m] <- readInts
  ass <- sortOn last <$> replicateM m readInts
  print $ solve 0 ass

readInts :: IO [Int]
readInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

solve :: Int -> [[Int]] -> Int
solve _ [] = 0
solve p ([a, b]:ass)
  | a >= p
    = 1 + solve b ass
  | a < p
    = solve p ass


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

ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

int main(){
    ll h,w;
    cin>>h>>w;
    vector<string> board(h);
    rep(i,h) cin>>board[i];
    ll cnt=0;
    rep(i,h)rep(j,w) if(board[i][j]=='#') cnt++;
    queue<pair<ll,ll>> q;
    vector<vector<ll>> dist(h,vector<ll>(w,-1)); 
    q.push(make_pair(0,0));
    dist[0][0]=0;
    while(!q.empty()){
        ll f=q.front().first;
        ll s=q.front().second;
        q.pop();
        rep(i,4){
            ll y=f+dy[i],x=s+dx[i];
            if(y>=0&&y<h&&x>=0&&x<w&&board[y][x]=='.'&&dist[y][x]==-1){
                q.push(make_pair(y,x));
                dist[y][x]=dist[f][s]+1;
            }
        }
    }
    if(dist[h-1][w-1]==-1) cout<<-1<<endl;
    else cout<<h*w-cnt-dist[h-1][w-1]-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    s = S()
    t = S()
    ans = 0
    for i, si in enumerate(s):
        ans += si != t[i]
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 84084
[N,M] = list(map(int,input().split()))
H = list(map(int,input().split()))
AB = []
for i in range(M):
    AB.append(list(map(int,input().split())))

L = [1]*N

for i in range(M):
    A = AB[i][0]
    B = AB[i][1]
    if H[A-1] > H[B-1]:
        L[B-1] = 0
    if H[A-1] < H[B-1]:
        L[A-1] = 0
    if H[A-1] == H[B-1]:
        L[A-1] = 0
        L[B-1] = 0

print(sum(L))

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    int N, K;
    cin >> N >> K;
    int t[N];
    ll d[N];
    vector<pair<ll, ll>> sushiVec;
    REP(i, N)
    {
        cin >> t[i] >> d[i];
        t[i]--;
        sushiVec.push_back(make_pair(d[i], t[i]));
    }

    sort(sushiVec.begin(), sushiVec.end());
    reverse(sushiVec.begin(), sushiVec.end());

    ll f[N + 1] = {0};
    ll score = 0;
    int countSushiKind = 0;
    map<int, bool> usedSushiMap;
    priority_queue<ll, vector<ll>, greater<ll>> avalableSushiQueue;
    REP(i, N) usedSushiMap[i] = false;
    REP(i, K)
    {
        ll currentD = sushiVec[i].first;
        int currentT = sushiVec[i].second;
        if (!usedSushiMap[currentT])
        {
            countSushiKind++;
            usedSushiMap[currentT] = true;
        }
        else 
        {
            avalableSushiQueue.push(currentD);
        }
        score += currentD;
    }
    f[countSushiKind] = score;

    for (int i = K; i < N; ++i)
    {
        ll currentD = sushiVec[i].first;
        int currentT = sushiVec[i].second;
        if (avalableSushiQueue.empty()) break;
        if (usedSushiMap[currentT]) continue;
        f[countSushiKind + 1] = f[countSushiKind] - avalableSushiQueue.top() + currentD;
        countSushiKind++;
        avalableSushiQueue.pop();
        usedSushiMap[currentT] = true;
    }

    ll ans = 0;
    for (ll i = 0; i <= N; ++i) if (f[i] != 0) ans = max(ans, f[i] + i * i);
    cout << ans << endl;
}


Measured memory_bytes: 9200
#!/usr/bin/env python
# -*- coding: utf-8 -*-

input = raw_input()

result = " "
for i in range(0, 3):
    if input[i] == "1":
        result += "9"
    elif input[i] == "9":
        result += "1"
    else:
        result += input[i]

print int(result)


Measured memory_bytes: 2568
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <queue>

#define fr first
#define sc second
#define mk make_pair

using namespace std;

int n, m, color[100001], t[100001], dis[100001];
bool u[100001];
vector<int> vec[100001];
pair<int, int> ar[100001];

int main()
{
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        vec[a].push_back(b);
        vec[b].push_back(a);
    }

    int q;
    cin >> q;
    for(int i = 0; i < q; i++)
        scanf("%d%d%d", &ar[i].fr, &ar[i].sc, &t[i]);

    int v, d, col;
    queue <int> a, b, c;
    for(int i = q - 1; i >= 0; i--)
    {
        a.push(ar[i].fr);
        u[ar[i].fr] = 1;
        b.push(ar[i].sc);
        c.push(t[i]);
        while(!a.empty())
        {
            v = a.front(), d = b.front(), col = c.front();
           // cout << v << " " << d << " " << col << endl;
            u[v] = 0;
            a.pop();
            b.pop();
            c.pop();
            if(color[v] == 0 || dis[v] < d)
            {
                if(color[v] == 0)
                {
                    color[v] = col;
                    dis[v] = d;
                }else
                {
                    dis[v] = d;
                }
                if(d > 0)
                for(int i = 0; i < vec[v].size(); i++)
                {
                    if(color[vec[v][i]] == 0 || dis[vec[v][i]] < d - 1 && u[vec[v][i]] == 0)
                    {
                        u[vec[v][i]] = 1;
                        a.push(vec[v][i]);
                        b.push(d - 1);
                        c.push(col);
                    }
                }
            }
        }
    }

    for(int i = 1; i <= n; i++)
    {
        //cout << color[i] << endl;
        printf("%d\n", color[i]);
    }
    return 0;
}



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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    ll a, b, c, x, y, ans = 0;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    rep(i, 0, a) cin >> p[i];
    rep(i, 0, b) cin >> q[i];
    rep(i, 0, c) cin >> r[i];
    sort(all(p),greater<ll>());
    sort(all(q),greater<ll>());
    sort(all(r),greater<ll>());
    rep(i, 0, x) ans += p[i];
    rep(i, 0, y) ans += q[i];
    ll xx = x - 1, yy = y - 1, zz = 0;
    while(zz < c){
        if(xx == -1 && yy == -1) break;
        else if(xx != -1 && yy != -1){
            if(p[xx] > q[yy]){
                if(r[zz] > q[yy]){
                    ans -= q[yy];
                    ans += r[zz];
                    yy--;
                    zz++;
                }else{
                    cout << ans << endl;
                    return 0;
                }
            }else{
                if(r[zz] > p[xx]){
                    ans -= p[xx];
                    ans += r[zz];
                    xx--;
                    zz++;
                }else{
                    cout << ans << endl;
                    return 0;
                }
            }
        }else if(xx == -1 && yy != -1){
            if(r[zz] > q[yy]){
                ans -= q[yy];
                ans += r[zz];
                yy--;
                zz++;
            }else{
                cout << ans << endl;
                return 0;
            }
        }else if(xx != -1 && yy == -1){
            if(r[zz] > p[xx]){
                ans -= p[xx];
                ans += r[zz];
                xx--;
                zz++;
            }else{
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 2688
#include<stdio.h>
	int main()
	{
		int x,n=0;
		scanf("%d",&x);
		
		long long max=0,sum=0;
		while(x--)
		{
			long long y,z;
			scanf("%lld%lld",&y,&z);
			if(max<y)
			{
				max=y;
				sum=y+z;
			}
			
			
			
		}
		
		printf("%lld\n",sum);
		
		return 0;
	 } 

Measured memory_bytes: 128
#include<stdio.h>

int main(void){
    int n,k,i;
    long long int a,e,c ;
    scanf("%d %d",&n,&k);

        c=n/k;

        e=(n+k/2)/k;

    if(k%2==1){
        a=c*c*c;
    }else{
        a=c*c*c+e*e*e;
    }
    printf("%lld",a);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 1e3 + 10;

int n;
int x, y, z, k;

int32_t main(){_

   cin>>x>>y>>z>>k;
   vector<int> a(x), b(y), c(z);

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

   for (int i = 0; i < y; ++i)
   {
      cin>>b[i];
   }

   for (int i = 0; i < z; ++i)
   {
      cin>>c[i];
   }

   sort(a.rbegin(), a.rend());
   sort(b.rbegin(), b.rend());
   sort(c.rbegin(), c.rend());

   priority_queue<P> pq;
   
   for (int i = 0; i < x; ++i)
   {
      for (int j = 0; j < y; ++j)
      {
         pq.push({a[i]+b[j]+c[0], 0});
      }
   }

   // tr(a, b, c);

   for (int i = 0; i < k; ++i)
   {
      auto it = pq.top();
      pq.pop();
      cout<<it.F<<endl;
      if (it.S == z-1)
         continue;
      int sum = it.F, idx = it.S;
      pq.push({sum-c[idx]+c[idx+1], idx+1});
   }


   return 0;
}

// Common sense: do smth instead of nothing
// Even a single second counts...
// If other's can do it, even I can do it. It wouldn't be that tough. Let me give it a try.
// Mistakes made in past
// -Ques. ask for max-min => think binary_search, DP, greedy
// -not reading question properly / skipping to read & understand all samples properly & wasting time in wrong direction.
// -Using wrong indexing in nested loops something like a[i], when it is supposed to be a[j](WA)
// -value of const int N is not correct (WA/RTE).
// -Did you memset dp to -1 ?
// -check for small edges cases and work on small test cases manually if WA
// -not deallocating memory to pointers can lead to MLE. Use delete :))
// -not reading problem statements of harder problems E,..., thinking it couldn't be solved, but it isn't the case.
// -Avoid using #define int long long as much as possible when it's dp problem and requires high memory say, O(N^2, N=5000) (MLE)
// -Check Bitwise Operator Precedence 
// -Use pragmas to optimize (by constant factor) when necessary..
// -Think before coding & starting to debug. Have patience to look inside code and actually see how it works

Measured memory_bytes: 18540
package main

import (
	"fmt"
	"math"
	"strconv"
)

func main() {
	var a, b string
	fmt.Scan(&a, &b)
	s := a + b
	i, _ := strconv.Atoi(s)
	n := math.Sqrt(float64(i))
	if n == math.Trunc(n) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
//ABC110A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int ans = max({10*a+b+c,a+10*b+c,a+b+10*c});
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
	int N, M;

	cin >> N >> M;

	vector<int> D;

	//MのM/N +1以下の約数
	for (int i = 1; i*i <= M; i++) {
		if (M%i == 0) {
			D.push_back(i);
			D.push_back(M / i);
		}
	}

	sort(D.begin(), D.end());

	auto ite = lower_bound(D.begin(), D.end(), M / N + 1);

	cout << D[ite - D.begin() - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        //System.out.println("n = " + n);
        int ans = 1;
        for(int i = 1; i * i <= n; i++) {
            ans = i * i;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22608
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll dp[50][500][500]; // i番目まで見て、maをj、mbをk取ることができる最小予算
int a[50], b[50], c[50];

int main(){
    int n, ma, mb;
    cin >> n >> ma >> mb;
    rep(i, n) cin >> a[i] >> b[i] >> c[i];

    rep(i, 50) rep(j, 500) rep(k, 500) dp[i][j][k] = LINF;
    dp[0][0][0] = 0;

    for(int i = 1; i <= n; i++){
        rep(j, 450) rep(k, 450){
            if (j >= a[i-1] && k >= b[i-1]) dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-a[i-1]][k-b[i-1]]+c[i-1]);
            dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k]);
        }
    }

    ll ans = LINF;

    for(int i = 1; i < 500; i++){
        if (i * ma >= 500 || i * mb >= 500) continue;
        ans = min(ans, dp[n][i*ma][i*mb]);
    }

    if (ans == LINF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 101256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

ll groupingRec(vector<vector<ll>> &arr, int n, int mask, vector<ll> &dp,
               vector<ll> &scores){

    if(dp[mask] != -1)
        return dp[mask];
    // Pick a non-empty subset of not chosen rabbits among 2^n possible subsets
    // and take that as one group
    ll ans = 0;
    for(int group = 1; group<(1<<n); group++){
        if(!(group&mask)){ // If these rabbits are not yet taken
            ll currGroupScore = scores[group];
            ll currRecAns = groupingRec(arr, n, mask|group, dp, scores) +
                            currGroupScore;
            if(currRecAns > ans)
                ans = currRecAns;
        }
    }
    dp[mask] = ans;
    return ans;
}

void precalculateScores(vector<vector<ll>> &arr, int n, vector<ll> &scores){

    // Store the score for every group combinations

    for(int group=0; group<(1<<n); group++){
        ll score = 0;
        for(int i=0; i<n; i++)
            if((group&(1<<i)))
                for(int j=i+1; j<n; j++)
                    if((group&(1<<j)))
                        score += arr[i][j];
        scores[group] = score;
    }
}

ll grouping(vector<vector<ll>> &arr, int n){

    // O(2^(2n))
    vector<ll> dp(1<<n, -1);
    vector<ll> scores(1<<n);
    precalculateScores(arr, n, scores);
    ll ans = groupingRec(arr, n, 0, dp, scores);
    return ans;
}

int main()
{
 int n;
 cin>>n;
 vector<vector<ll>> arr(n, vector<ll>(n));
 for(int i=0; i<n; i++)
    for(int j=0; j<n; j++)
        cin>>arr[i][j];
 ll ans = grouping(arr, n);
 cout<<ans;
 return 0;
}



Measured memory_bytes: 4280
# coding: utf-8
# Your code here!
tensu = int(input())

if 400 <= tensu <= 599:
    print("8")

elif 600 <= tensu <= 799:
    print("7")
    
elif 800 <= tensu <= 999:
    print("6")
    
elif 1000 <= tensu <= 1199:
    print("5")
    
elif 1200 <= tensu <= 1399:
    print("4")
    
elif 1400 <= tensu <= 1599:
    print("3")
    
elif 1600 <= tensu <= 1799:
    print("2")
    
elif 1800 <= tensu <= 1999:
    print("1")
 

Measured memory_bytes: 9124
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;

int main() {
    cin >> n;
    Vi x(n);
    REP(i, n) cin >> x[i];
    Vi y(x);

    sort(ALL(x));
    int l = x[n/2-1], r = x[n/2];

    REP(i, n) {
        if (y[i] <= l) {
            cout << r << '\n';
        } else {
            cout << l << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 3712
import sys
s=input()
for op1 in '+-':
  for op2 in '+-':
    for op3 in '+-':
      if eval(s[0]+op1+s[1]+op2+s[2]+op3+s[3]) == 7:
        print(s[0]+op1+s[1]+op2+s[2]+op3+s[3]+'=7')
        sys.exit(0)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin >> n;
  string name;
  long long m=0,a=0,r=0,c=0,h=0;
  for(int i=0;i<n;i++){
    cin >> name;
    switch(name[0]){
    case 'M':
      m++;
      break;
    case 'A':
      a++;
      break;
    case 'R':
      r++;
      break;
    case 'C':
      c++;
      break;
    case 'H':
      h++;
      break;
    }
  }
  long long pat;
  pat = m*a*c+m*a*r+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;
  cout << pat << "\n";




  return 0;
}


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

using namespace std;

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

    vector<vector<char>> masu(h, vector<char>(w, '#'));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int cnt = 0;
            if (s.at(i).at(j) == '#') continue;
            if (i != 0) {
                if (s.at(i-1).at(j) == '#') cnt++;
                if (j != 0 && s.at(i-1).at(j-1) == '#') cnt++;
                if (j != w-1 && s.at(i-1).at(j+1) == '#') cnt++;
            }
            if (i != h-1) {
                if (s.at(i+1).at(j) == '#') cnt++;
                if (j != 0 && s.at(i+1).at(j-1) == '#') cnt++;
                if (j != w-1 && s.at(i+1).at(j+1) == '#') cnt++;
            }
            if (j != 0 && s.at(i).at(j-1) == '#') cnt++;
            if (j != w-1 && s.at(i).at(j+1) == '#') cnt++;
            masu.at(i).at(j) = cnt+'0';
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << masu.at(i).at(j);
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  string S;
  int K;
  cin>>S>>K;
  for(int i=0;i<min((int)S.size(),K);i++){
    if(S[i]!='1'){
      cout<<S[i]<<endl;
      return 0;
    }
  }
  cout<<1<<endl;
}

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

int main() {
  int a, b, sum;
  cin >> a >> b;
  sum = 0;

  // ここにプログラムを追記
  rep2 (i, a, b+1) {
    int x0, x1, x2, x3, x4;
    x0 = i % 10;
    x1 = (i / 10) % 10;
    x3 = (i / 1000) % 10;
    x4 = (i / 10000);
    if ((x0 == x4) && (x1 == x3)) {
      sum++;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3604
#include<stdio.h>
#include<stdlib.h>

int main(void){
    int N, M;
    scanf("%d %d", &N, &M);

    int *a = (int*)malloc(N * sizeof(int));
    int i;
    int temp;
    for(i=0; i<2*M; i++) {
        scanf("%d", &temp);
        a[temp-1] ++;
    }
    for(i=0; i<N; i++) {
        printf("%d\n", a[i]);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
vl ans;
void dfs(ll &n){
    if(n>3234566667)return;
    ans.pb(n);
    ll p=n%10;
    rep(i,3){
        if(p-1+i<0)continue;
        if(p-1+i>9)continue;
        n*=10;
        n+=p-1+i;
        dfs(n);
        n/=10;
    }
}
int main(){
    ll k;cin >> k;
    rep(i,9){
        ll x=i+1;
        dfs(x);
    }
    sort(all(ans));
    cout << ans[k-1] <<endl;
}

Measured memory_bytes: 1400
from fractions import*
a=int(input())
b=list(map(int,input().split()))
alis=[b[0]]
blis=[b[-1]]
for i in range(a-1):
  alis.extend([gcd(alis[-1],b[i+1])])
  blis.extend([gcd(blis[-1],b[-i-2])])
blis=list(reversed(blis))+[0]
alis=[0]+alis
ans=[]
for i in range(a):
	ans+=[gcd(alis[i],blis[i+1])]
print(max(ans))


Measured memory_bytes: 16132
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  map<long, long> mp;
  for(long i = 2; i <= sqrt(N); i++){
    while(N % i == 0){
      mp[i]++;
      N /= i;
    }
  }
  if(N != 1)mp[N]++;
  vector<long> sub;
  long a = 0;
  for(int i = 1; i < 20; i++){
    a += i;
    sub.push_back(a);
  }
  long ans = 0;
  for(auto i = mp.begin(); i != mp.end(); i++){
    for(int j = 0; j < 19; j++){
      if(sub.at(j) > (i->second)){
        ans += j;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
n,m = map(int, input().split())
a = [0]*n
ans = 1
for i in range(m):
  s,c = map(int,input().split())
  if (s != 1 or c != 0 or len(a) == 1) and (a[s-1] == 0 or a[s-1] == c):
    a[s-1] = c
  else:
    ans = -1
    break
if ans != -1:
  if a[0] == 0 and len(a) > 1:
    a[0] = 1
  a = map(str, a)
  print("".join(a))
else:
  print(-1)

Measured memory_bytes: 3064
using System;
using System.Text;

namespace ALDS1_9_B
{
    class Program
    {
        static int parent(int i) { return i / 2; }
        static int left(int i) { return 2 * i; }
        static int right(int i) { return 2 * i + 1; }
        static void Main(string[] args)
        {
            var H = scan()[0];
            var b = scan();
            var A = new int[H + 1];
            for (int i = 1; i <= H; i++)
            {
                A[i] = b[i - 1];
            }
            for (int i = H/2; i > 0; i--)
            {
                maxheapify(A, i,H);
            }
            var sb = new StringBuilder();
            for (int i = 1; i <= H ; i++)
            {
                sb.Append(" " + A[i]);
            }
            Console.WriteLine(sb);
        }
        static void maxheapify(int[] A,int i,int H)
        {
            int l = left(i);
            int r = right(i);
            //????????????????????????????????§?????§????????????
            int largest;
            if (l <= H && A[l] > A[i]) largest = l;
            else largest = i;
            if (r <= H && A[r] > A[largest]) largest = r;

            if (largest != i)
            {
                int tmp = A[i];
                A[i] = A[largest];
                A[largest] = tmp;
                maxheapify(A, largest, H);
            }
        }
        static int[] scan()
        {
            return Array.ConvertAll
                (Console.ReadLine().Split(' '),int.Parse);
        }
    }
}

Measured memory_bytes: 62684
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
//using fs = unordered_set;
//#define fs set//unordered_set

struct UnionF {
    vector<ll> S;
    
    UnionF(ll a){
        S=vector<ll>(a);
        for(ll i=0;i<a;i++)S[i]=i;
    }

    ll FFi(ll i){
        if(S[i]==i)return i;
        S[i]=FFi(S[i]);
        return S[i];
    }

    void marge(ll a,ll b){
        ll aa=FFi(a),bb=FFi(b);
        if(aa==bb)return;
        ll mms = (aa<bb)?aa:bb;
        S[aa]=mms;S[bb]=mms;
    }
    
    bool equalU(ll a,ll b){return (FFi(S[a])==FFi(S[b]));}
    
};

int main() {
    ll N,Q;
    cin >> N >> Q;
    UnionF U(N);
    while(Q){
        ll sub1,sub2,sub3;
        
        cin >> sub1 >> sub2 >> sub3;
        
        if(sub1==0)U.marge(sub2, sub3);
        else {
            if(U.equalU(sub2, sub3))cout << 1 << endl;
            else cout << 0 << endl;
        }
        
        Q--;
    }
    
    
}


Measured memory_bytes: 4724
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define MP make_pair

inline int gn(){
    int s=0,f=1; 
    char ch = getchar();
    while(!isdigit(ch)) {if(ch == '-') f=-1;ch = getchar();}
    while(isdigit(ch)) {s=s*10+ch-'0';ch = getchar();}
    return s*f;
}

inline ll gl(){
    ll s=0,f=1; 
    char ch = getchar();
    while(!isdigit(ch)) {if(ch == '-') f=-1;ch = getchar();}
    while(isdigit(ch)) {s=s*10+ch-'0';ch = getchar();}
    return s*f;
}

const int N=2e5+100;
int a[105];
void solve(){
    int n=gn(),k=gn();
    for(int i=0;i<k;++i){
        int d=gn();
        for(int j=0;j<d;++j){
            int z=gn();
            a[z]=1;
        }
    }
    int cnt=0;
    for(int i=1;i<=n;++i){
        if(a[i]==0)cnt++;
    }
    cout<<cnt<<endl;
}

int main(){
    // int t;
    // t=gn();
    // while(t--)
        solve();
}

/**
* In every life we have some trouble
* When you worry you make it double
* Don't worry,be happy.
**/


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<string>

using namespace std;

#define int long long

signed main(){

  int N, con1 = 0, con2 = 0, con4 = 0;
  vector<int> A;

  cin>>N;

  for(int i = 0; i < N; i++){
    int num;

    cin>>num;

    if(num%4 == 0)con4++;
    else if(num%2 == 0)con2++;
    else con1++;
  }

  if(con2 == 0){
    if(con1 == 0){
      cout<<"Yes"<<endl;
    } else {
      if(con1 <= con4 + 1) cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }
  } else {
    if(con1 == 0){
      cout<<"Yes"<<endl;
    } else {
      if(con1 > con4) cout<<"No"<<endl;
      else cout<<"Yes"<<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256