akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
const ll M = MOD;

vector<ll> fac(2001); //n!(mod M)
vector<ll> ifac(2001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main(){
    int N,K;
    cin >> N >> K;
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<2000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    rep(i,K){
        ll tmp = comb(N - K + 1,i+1);
        ll tmp2 = comb(K-1,i);
        cout << tmp*tmp2 % MOD << endl;
    }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll n,m,a[1000010],tot=0;

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

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m;
    cin >> n >> m;
    vector<int64_t> a(n);
    vector<int64_t> b(n);
    vector<int64_t> c(m);
    vector<int64_t> d(m);
    for(int i = 0;i < n;i++) {
        cin >> a.at(i) >> b.at(i);
    }
    for(int i = 0;i < m;i++) {
        cin >> c.at(i) >> d.at(i);
    }
    int64_t sum;
    int64_t min;
    int64_t min_j;
    for(int i = 0;i < n;i++) {
        sum = 0;
        min = 4000000001;
        min_j = 0;
        for(int j = 0;j < m;j++) {
            if(abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j)) < min) {
                min = abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j));
                min_j = j + 1;
            }
        }
        cout << min_j << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n,k,pre[3000][3000],c[3000][3000],mx;
void add (int x, int y1, int y2){
    if(x<0){
        x += k; y1 += k; y2 += k;
    }
    else if(x>=k){
        x -= k; y1 += k; y2 += k;
    }
    //cout<<x<<" "<<y1<<" "<<y2<<newl;
    y1 %= (2*k);
    y2 %= (2*k);
    if(y1<0)y1+=(2*k);
//    cout<<x<<" "<<y1<<" "<<y2<<newl;
    if(y1>y2){
        pre[x][0]++;pre[x][y2+1]--;
        pre[x][y1]++;pre[x][2*k]--;
    }
    else{
        pre[x][y1]++;pre[x][y2+1]--;
    }

}
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        ll x,y;char z;
        cin>>x>>y>>z;
        if(z=='W')x+=k;
        x%= (2*k); y %= (2*k);
        ll lx,rx,ry,ly;
        rx = x;
        lx = x-k+1;
        ry = y;
        ly = y-k+1;
        for(int i=rx;i>=lx;i--){
            add(i,ly,ry);
        }
    }
    for(int i=0;i<k;i++){
        for(int j=0;j<2*k;j++){
            if(j==0){c[i][j]=0;}
            else{c[i][j]=c[i][j-1];}

            c[i][j]+=pre[i][j];
            mx = max(mx,c[i][j]);
        }
    }
    cout<<mx<<newl;

}


Measured memory_bytes: 24832
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int cnt=n,sum=0;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=n-1;i>=0;i--){
        if(sum+a[i]<k) sum+=a[i];
        else cnt=i;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
### main

id = 0

loop do
  n = gets.to_i
  break if n == 0

  rects = []
  xhash = {}
  yhash = {}

  n.times do
    xi, yi, ri = gets.split.map(&:to_f)
    rect = [xi - ri, yi - ri, xi + ri, yi + ri]
    xhash[rect[0]] = xhash[rect[2]] = 1
    yhash[rect[1]] = yhash[rect[3]] = 1
    rects << rect
  end

  xs = xhash.keys.sort
  ys = yhash.keys.sort
  #p [xs, ys]

  xs.each_with_index{|f, i| xhash[f] = i}
  ys.each_with_index{|f, i| yhash[f] = i}
  #p [xhash, yhash]

  w = xs.length - 1
  h = ys.length - 1

  cells = h.times.map{w.times.map{false}}

  rects.each do |x0, y0, x1, y1|
    i0 = xhash[x0]
    i1 = xhash[x1]
    j0 = yhash[y0]
    j1 = yhash[y1]
    for j in (j0...j1)
      for i in (i0...i1)
        cells[j][i] = true
      end
    end
  end
  #p cells

  ar = 0.0
  for j in (0...h)
    for i in (0...w)
      if cells[j][i]
        ar += (xs[i + 1] - xs[i]) * (ys[j + 1] - ys[j])
      end
    end
  end

  id += 1
  puts [id, "%.2f" % ar.round(2)].join(' ')
end

Measured memory_bytes: 6264
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

int main()
{
  int n, i;
  double sum;
  double m, aa, a;
  
  while(1)
  {
    sum = 0;
    aa = 0;
      
    cin >> n;
    if(n == 0) break;
    int s[n];
    
    for(i = 0; i < n; i++)
    {
      s[i] = 0;
        
      cin >> s[i];
      sum += s[i];
    }
      
    m = sum / n;
      
    for(i = 0; i < n; i++)
    {
      aa += (s[i] - m) * (s[i] - m) / n;
    }
        
    a = sqrt(aa);
      
    printf("%.8f\n", a);
  }
    
  return 0;
}


Measured memory_bytes: 3116
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}

long double eps=1e-8;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int n){
    return uniform_int_distribution<int>(0, n)(rng);
}
double drnd(){
    return (double)(rnd(INT_MAX))/INT_MAX;
}
main(){
    string n;cin>>n;
    int k=in();
    ll dp[110][4][2]={};
    dp[0][0][0]=1;
    rep(i,n.size()){
        rep(j,k+1){
            dp[i+1][j][(n[i]!='0')]+=dp[i][j][0];
            dp[i+1][j][1]+=dp[i][j][1];
            if(j<k){
                dp[i+1][j+1][1]+=dp[i][j][0]*max(0,(n[i]-'0'-1));
                dp[i+1][j+1][0]+=dp[i][j][0]*(n[i]!='0');
                dp[i+1][j+1][1]+=dp[i][j][1]*9;
            }
        }
    }
    cout<<(dp[n.size()][k][0]+dp[n.size()][k][1])<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#define STOP {printf("NO\n"); return 0;}

using namespace std;

const int Nmax = 1e5+5;
int a[Nmax], nr, n, i, dif;
long long op, nrOp;

int main()
{
    cin >> n;
    for(i=1; i<=n; ++i)
    {
        cin >> a[i];
        op += a[i];
    }

    nrOp = 1LL*n*(n+1)/2;
    if( op % nrOp ) STOP

    nr = op / nrOp;

    a[0] = a[n];
    for(i=1; i<=n; ++i)
    {
        dif = a[i] - a[i-1];        /// dif = (nr - cnt[i]) - cnt[i]*(n-1)
        dif = nr - dif;             /// cnt[i]*n = nr - dif
        if(dif%n!=0 || dif<0) STOP
    }

    printf("YES\n");

    return 0;
}


Measured memory_bytes: 640
n = int(input())
s = []
for i in range(n):
    s.append(''.join(sorted(input())))
s.sort()
count = 1
counts = []
now = s[0]
for i in range(1, n):
    if s[i] == now:
        count += 1
    else:
        if count > 1:
            counts.append(count)
        count = 1
        now = s[i]
if count > 1:
    counts.append(count)
c = 0
for i in counts:
    c += i * (i-1) // 2
print(c)

Measured memory_bytes: 10640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

#define MOD 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_V 100
#define MAX_E 100

//--------------------------

ll N, res1, res2;

ll A[MAX_N+1];
ll B[MAX_N];

int main() {

  cin >> N;
  rep(i, N+1) {
    cin >> A[i];
    res1 += A[i];
  }
  rep(i, N) cin >> B[i];

  rep(i, N) {

    if(B[i]>=A[i]) {
      B[i] -= A[i];
      A[i] = 0;
    }else {
      A[i] -= B[i];
      B[i] = 0;
    }

    if(B[i]>0) {
      if(B[i]>=A[i+1]) {
        A[i+1] = 0;
      }else {
        A[i+1] -= B[i];
      }
    }
  }

  rep(i, N+1) res2 += A[i];

  cout << res1-res2 << endl;

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    int l, r;
    int cus = 0;
    for(int i=0; i<N; i++){
        scanf("%d %d", &l, &r);
        cus += r-l+1;
    }
    cout << cus << endl;
    return 0;
}

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

int str[100];
int top;

void push(int);
int pop();
int isEmpty(int);

int main() {
  char s[100];
  int a,b;

  top = 0;

  while(scanf("%s",s)!=EOF) {
    if(s[0]=='+'){
      a = pop();
      b = pop();
      push(a+b);
    } else if(s[0]=='-'){
      b = pop();
      a = pop();
      push(a-b);
    } else if(s[0]=='*'){
      a = pop();
      b = pop();
      push(a*b);
    } else {
      push(atoi(s));
    }
  }


  printf("%d\n",pop());
return 0;
}


void push(int x){
  top++;
  str[top] = x;
}

int pop(){
  if(isEmpty(top)==0) printf("underflow\n");
  else top--;
  return str[top+1];
}

int isEmpty(int top){
  if(top==0)return 0;
  else return 1;
}



Measured memory_bytes: 2108
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;
int n,m,q,d[100010],used[100100];
vector <int> g[100010];
vector <string> str;

//numは連結成分の番号
void dfs(int v,int num){
  used[v]=true;
  d[v]=num;
  REP(i,g[v].size()){
    if(!used[g[v][i]])dfs(g[v][i],num);
  }

}



int main(){
  cin >>n>>m;
  REP(i,m){
    int s,t;
    cin >>s>>t;
    g[s].push_back(t);
    g[t].push_back(s);
  }
  REP(i,n)used[i]=false;

  REP(i,n){
    if(!used[i])dfs(i,i);
  }
  cin >>q;
  REP(i,q){
    int s,t;
    cin >>s>>t;
    if(d[s]==d[t])str.push_back("yes");
    else str.push_back("no");
  }
  REP(i,str.size()){
    cout <<str[i]<<endl;
  }
}



Measured memory_bytes: 14524
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstdlib>
#include <clocale>
#include<cmath>
#include<sstream>
#include<set>
#include<stack>
using namespace std;
const int INF=0x3f3f3f3f;
const int MX=1e4+10;
typedef long long ll;
typedef pair<int ,int> p;
int main(){
	char o[55],e[55];
	scanf("%s %s",o,e);
	int m=strlen(o)+strlen(e);
	int oo=0,ee=0;
	for(int i=1;i<=m;i++)
		if(i&1)printf("%c",o[oo++]);
		else printf("%c",e[ee++]);
		printf("\n");
    system("pause");
    return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
int main(){
  bool used[100000] = {};
  int n, tar = 0, cnt = 0;
  int a[100000];
  cin >> n;
  for(int i=0;i<n;i++) cin >> a[i];
  while(tar != 1){
    cnt++;
    if(used[tar]){
      cout << -1 << endl;
      return 0;
    }
    used[tar] = true;
    tar = a[tar] - 1;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 768
import Data.List
import qualified Data.ByteString.Char8 as B
main=do
  n<-readLn::IO Int
  as<-sort.zipWith (flip (-)) [1..].unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
  print.minimum.map (f as) $ [as !! (n `div` 2), as !! (min (n-1) (n `div` 2 + 1))]

f as m = sum.map abs.map ((-) m) $ as


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

int main() {
    for(int i = 0; i < 3; ++i) {
        char s;
        cin >> s;
        cout << 10 - (s - '0');
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
INF=10**18
e=[[]for _ in range(n+1)]
for _ in range(m):
  l,r,d=map(int,input().split())
  e[l]+=[(r,d)]
  e[r]+=[(l,-d)]
d=[INF]*(n+1)
for i in range(n+1):
  if d[i]!=INF:continue
  d[i]=0
  q=[i]
  while q:
    now=q.pop()
    for to,dist in e[now]:
      if d[to]==INF:
        d[to]=d[now]+dist
        q+=[to]
      else:
        if d[to]!=d[now]+dist:
          print('No')
          exit()
print('Yes')

Measured memory_bytes: 110888
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 51;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<ll> cntP(MAX), height(MAX);
/* function */
void init() {
    cntP[0] = height[0] = 1;
    for (int i = 0; i < MAX - 1; i++) {
        cntP[i+1] = cntP[i] * 2 + 1;
        height[i+1] = 1 + height[i] + 1 + height[i] + 1;
    }
}
ll f(int n, ll x) {
    ll harf = height[n] / 2;
    // n = P
    // x = 1 0
    if (n == 0) {
        if (x <= 0) return 0;
        else return 1;
    }
    // B + height[n-1] + P + height[n-1] + B;
    //                      |  x - 1   |
    if (x <= harf) return f(n - 1, x - 1);
    // B + height[n-1] + P + height[n-1] + B;
    //    | x-harf-1 | + 1 + cntP[n-1]
    else return f(n - 1, min(x - harf - 1, harf)) + cntP[n - 1] + 1;
}
/* main */
int main(){
    int N;
    ll X;
    cin >> N >> X;
    init();
    cout << f(N, X) << '\n';
}


Measured memory_bytes: 256
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).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(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    solve();
}

void solve(){
    ll n,k;cin>>n>>k;
    string s;cin>>s;

    //01 0101
    vl a={0};
    ll mode=1;
    ll cnt=0;
    rep(i,n){
        if(s[i]-'0'==mode)++cnt;
        else{
            a.push_back(cnt);
            cnt=1;
            mode=1-mode;
        }
    }
    a.push_back(cnt);
    if(s[n-1]=='0')a.push_back(0);

    ll m=a.size();
    rep(i,m-1){
        a[i+1]+=a[i];
    }

    ll ans=0;
    rep(i,m){
        if(i%2)continue;
        ll to=min(m-1,i+k*2+1);
        chmax(ans,a[to]-a[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1528
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<int,ii> P;
typedef unsigned long long int ull;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[rx]<rank[ry]){
            par[rx]=ry;
        }else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[ry]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

ll n,m;
vector<vector<int> > G(MAXN);
vector<int> cl(MAXN,0);

bool dfs(int u,int c){
    cl[u]=c;
    for(auto v:G[u]){
        if(cl[v]==c) return false;
        if(cl[v]==0&&!dfs(v,-c)) return false;
    }
    return true;
}

int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    if(!dfs(0,1)){
        cout<<n*(n-1)/2-m<<endl;
        return 0;
    }
    ll b=0,w=0;
    for(int i=0;i<n;i++){
        if(cl[i]==1) b++;
        else w++;
    }
    cout<<b*w-m<<endl;
    return 0;
}

Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 100000000000000
signed main()
{
    SPEED;
    int n;
    cin>>n;
    int a[n+1],dp[n+1]={0},sum=0,mx[n+1]={0};
    for(int i=0;i<=n;i++)
    {
        cin>>a[i];
    }
    if(n==0)
    {
        if(a[0]==1)
        {
            cout<<1;
            return 0;
        }
        else
        {
            cout<<-1;
            return 0;
        }
    }
    if(n>0 && a[0]>0)
    {
        cout<<-1;
        return 0;
    }
    dp[0]=1;
    for(int i=1;i<n;i++)
    {
        if((dp[i-1]-a[i-1])*2>MOD)
        {
            dp[i]=MOD;
        }
        else
        {
            dp[i]=(dp[i-1]-a[i-1])*2;
        }
        if(dp[i]<=0)
        {
            cout<<-1;
            return 0;
        }
    }
    if(a[n]>(dp[n-1]-a[n-1])*2)
    {
        cout<<-1;
        return 0;
    }
    mx[n]=a[n];
    sum+=a[n];
    for(int i=n-1;i>=0;--i)
    {
       mx[i]=min(dp[i],mx[i+1]+a[i]);
       sum+=mx[i];
    }
    cout<<sum;
}

Measured memory_bytes: 5888
#include<stdio.h>
int main(void){
int W, H, x, y, r;
scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
if(x >= r && y >= r){
if( W - x >= r && H - y >= r){
printf("Yes\n");
}else{
printf("No\n");
}
}else{
printf("No\n");
}
return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
ll gcd(ll x,ll y){
    if (y == 0) return x;
    return gcd(y, x%y);
}
int main(void){
    int k;cin>>k;
    int res=0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                int buf=gcd(i,j);
                buf=gcd(buf,l);
                res+=buf;
            }
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(){
	int angka;
	scanf("%d", &angka);
	int count = 0;
	for(int i = 1; i <= 9; i++){
		for(int j = 1; j <= 9; j++){
			if(angka == i * j){
				count++;
			}
		}
	}
	if(count != 0){
		puts("Yes");
	} else{
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 1656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main{

    public static void main(String[] args) throws IOException {

        ArrayList<Integer> m_list = new ArrayList<>();
        ArrayList<Integer> f_list = new ArrayList<>();
        ArrayList<Integer> r_list = new ArrayList<>();

        int m;
        int f;
        int r;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        while(true) {
            String[] line = br.readLine().split(" ");
            m = Integer.parseInt(line[0]);
            f = Integer.parseInt(line[1]);
            r = Integer.parseInt(line[2]);

            if (m == -1 && f == -1 && r == -1) {
                break;
            }

            m_list.add(m);
            f_list.add(f);
            r_list.add(r);

        }

        for (int i = 0; i < m_list.size(); i++) {
            
            if(m_list.get(i) == -1 || f_list.get(i) == -1){
                System.out.println("F");
            }
            else {
                
                if(m_list.get(i) + f_list.get(i) >= 80) System.out.println("A");
                
                if(65 <= m_list.get(i) + f_list.get(i) && 
                        m_list.get(i) + f_list.get(i) < 80) System.out.println("B");
                
                if(50 <= m_list.get(i) + f_list.get(i) && 
                        m_list.get(i) + f_list.get(i) < 65) System.out.println("C");
                
                if(30 <= m_list.get(i) + f_list.get(i) && 
                        m_list.get(i) + f_list.get(i) < 50) {
                    
                    if(r_list.get(i) >= 50) { System.out.println("C"); }
                    else { System.out.println("D"); }
                    
                }
                
                if(m_list.get(i) + f_list.get(i) < 30) System.out.println("F");
                
            }
            
        }
        

    }

}

Measured memory_bytes: 24264
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		
		int max = 0;
		for (int i = 1; i < n - 1; i++) {
			String x = s.substring(0, i);
			String y = s.substring(i);
			
			int cnt = 0;
			for (char c = 'a'; c <= 'z'; c++) {
				String key = String.valueOf(c);
				if (x.contains(key) && y.contains(key)) cnt++;
			}
			
			max = Math.max(max, cnt);
		}
		
		System.out.println(max);
		
		sc.close();
	}
}




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

int main() {
  int N;
  cin >> N;
  vector<int> ans(N+1);
  for(int x=1;x<=100;x++) {
    for(int y=1;y<=100;y++) {
      for(int z=1;z<=100;z++) {
        int a = x*x+y*y+z*z+x*y+y*z+z*x;
        if(a<=N) ans[a]++;
      }
    }
  }
  for(int i=1;i<=N;i++) {
    cout << ans[i] << endl;
  }
}


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

int main()
{
  i64 n;
  cin >> n;
  if (n % 2 == 0)
  {
    n /= 2;
    i64 ans = 0, t = 5;
    while (0 < n / t)
    {
      ans += n / t;
      t *= 5;
    }
    cout << ans << endl;
  }
  else
    cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <random>
#include <sstream>
#include <stack>
#include <deque>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

int N;
int ans = 0;

int main() {
    cin >> N;
    rep(i,N) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define cases long long test;cin>>test;while(test--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
int main()
{
    int h,w;
    cin>>h>>w;
    char ch[h+1][w+1];
    int dp[h+1][w+1];
    foi(1,h+1)
    {
        foj(1,w+1)
        {
            cin>>ch[i][j];
        }
    }
    memset(dp,0,sizeof(dp));
    foi(1,h+1)
    {
        foj(1,w+1)
        {
            if(ch[i][j]=='.')
            {
                if(i==1 && j==1)
                {
                    dp[i][j]=1;
                }
                else
                {
                    if(i-1>=1)
                    {
                        dp[i][j]+=dp[i-1][j]%MOD;
                    }
                    if(j-1>=1)
                    {
                        dp[i][j]+=dp[i][j-1]%MOD;
                    }
                }
            }
            
        }
    }
    cout<<dp[h][w]%MOD;
    
}

Measured memory_bytes: 5120
/*
    Take me to church
    I'll worship like a dog at the shrine of your lies
    I'll tell you my sins and you can sharpen your knife
    Offer me that deathless death
    Good God, let me give you my life
*/
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int N = 100005, Mod = 1e9 + 7;
int n, m, s, t, dp[N][2];
long long D[N][2];
vector < pair < int , int > > Adj[N];
priority_queue < pair < long long , int > > Pq;
inline void SSSP(int st, int w)
{
    D[st][w] = 0;
    dp[st][w] = 1;
    Pq.push({0, st});
    while (Pq.size())
    {
        int v = Pq.top().y;
        long long d = - Pq.top().x;
        Pq.pop();
        if (d > D[v][w])
            continue;
        for (auto u : Adj[v])
        {
            if (D[u.x][w] > D[v][w] + u.y)
            {
                dp[u.x][w] = 0;
                D[u.x][w] = D[v][w] + u.y;
                Pq.push({- D[u.x][w], u.x});
            }
            if (D[u.x][w] == D[v][w] + u.y)
            {
                dp[u.x][w] += dp[v][w];
                if (dp[u.x][w] >= Mod)
                    dp[u.x][w] -= Mod;
            }
        }
    }
}
int main()
{
    scanf("%d%d%d%d", &n, &m, &s, &t);
    for (int i = 1; i <= m; i ++)
    {
        int v, u, d;
        scanf("%d%d%d", &v, &u, &d);
        Adj[v].push_back({u, d});
        Adj[u].push_back({v, d});
    }
    memset(D, 63, sizeof(D));
    SSSP(s, 0); SSSP(t, 1);
    int tot = 1LL * dp[t][0] * dp[t][0] % Mod;
    for (int i = 1; i <= n; i ++)
        if (D[i][0] * 2 == D[t][0] && D[i][1] * 2 == D[t][0])
            tot = (tot - 1LL * dp[i][0] * dp[i][1] % Mod * dp[i][0] % Mod * dp[i][1] % Mod + Mod) % Mod;
    for (int i = 1; i <= n; i ++)
        for (auto u : Adj[i])
            if (D[i][0] + u.y + D[u.x][1] == D[t][0] && D[i][0] * 2 < D[t][0] && D[u.x][1] * 2 < D[t][0])
                tot = (tot - 1LL * dp[i][0] * dp[u.x][1] % Mod * dp[i][0] % Mod * dp[u.x][1] % Mod + Mod) % Mod;
    return !printf("%d\n", tot);
}

Measured memory_bytes: 12916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int k; sc(k);
    string s; cin >> s;
    if (s.size() <= k){
        cout << s << endl;
    }else{
        s = s.substr(0,k);
        cout << s + "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string N;
    cin >> N;
    int mod = 0;
    for(int i=0;i<N.size();i++){
        mod = (mod + (N[i] - 48)) % 9;
    }
    string ans = "No";
    if(mod == 0){
        ans = "Yes";
    }
    cout << ans << endl;
}


Measured memory_bytes: 3276
using System;
using System.Linq;
using System.Collections.Generic;

namespace lineAralgebra
{
	class Program
	{
		public static void Main(String[] args)
		{
			var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
			if ((input[0] == input[1] || input[1] == input[2] || input[0] == input[2]) && !(input[0] == input[1] && input[1] == input[2]))
			{
				System.Console.WriteLine("Yes");
			}
			else
			{
				System.Console.WriteLine("No");
			}

		}
	}
}



Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#include "string"

const int M = 1e9 + 7;

int mod( int m ,int mod = M) {
   m %= mod;
   return (m + mod) % mod;
}

// find y - x = x ^ y && L <= x <= y <= R

int dp[60][2][2][2];
int L,R;
int solve(int id, int l, int r, int cur) {
	if(id < 0)
		return 1;
	int &tmp = dp[id][l][r][cur];
	if(tmp != -1)
		return tmp;
	tmp = 0;
	if(l  or !((L >> id) & 1ll))
		tmp = mod(tmp + solve(id - 1, l, r | ((R >> id) & 1ll), cur) );

	if((l or !((L >> id) & 1LL)) && (r or ((R >> id) & 1ll)) && cur)
		tmp = mod(tmp + solve(id - 1, l, r, cur));
	if(r or ((R >> id) & 1ll))
		tmp = mod(tmp  + solve(id - 1, l | !((L >> id) & 1ll) , r, 1) );
	return tmp;
}

int32_t main(){
	boost;
	int t = 1;
	//cin >> t;
	while(t--) {
		cin >> L >> R;
		memset(dp, -1, sizeof dp);
		int ans = solve(59, 0, 0, 0);
		cout << ans << endl;
	}
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
inline int popcount(const int x) { return __builtin_popcount(x);}
template<class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b;}
template<class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct InitIO{
  InitIO() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
  }
}init_io;

const double eps = 1e-6;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  double ng = 0, ok = 1LL<<50;
  auto check = [&](double x) {
    ll sum = 0;
    rep(i,n) sum += ll(a[i] / x);
    return k >= sum;
  };
  while(ok - ng > eps) {
    double mid = (ok + ng) / 2;
    if (check(mid)) ok = mid;
    else ng = mid;
  }
  // debug(ok, ok - (ok - ng));
  ll ans = ceil(ok - (ok - ng));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4736
s = [s for s in input()]
t = [t for t in input()]
n = len(s)
l = len(t)
ans = 0
tmp = 0
for i in range(n-l+1):
    for j in range(l):
        if s[i+j]==t[j]:
            tmp += 1 
    ans = max(ans,tmp)
    tmp = 0
print(l-ans)

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

int main() {
    int num_query; scanf("%d", &num_query);
    int command, x, left, right;
    multiset<int> S;
    
    for (int i = 0; i < num_query; ++i) {
        scanf("%d", &command);
        
        switch (command) {
            case 0:
                scanf("%d", &x);
                S.insert(x);
                printf("%d\n", (int) S.size());
                break;
            case 1:
                scanf("%d", &x);
                printf("%d\n", S.count(x));
                break;
            case 2:
                scanf("%d", &x);
                S.erase(x);
                break;
            case 3:
                scanf("%d%d", &left, &right);
                auto lower_itr = S.lower_bound(left);
                auto upper_itr = S.upper_bound(right);
                
                for (auto itr = lower_itr; itr != upper_itr; ++itr) printf("%d\n", *itr);
                break;
        }
    }
    return 0;
}


Measured memory_bytes: 12424
#include "bits/stdc++.h"
using namespace std;

#define ul unsigned long int
#define ull unsigned long long
#define li long long int


int main()
{
  int n;
  cin>>n;
  string sp = "####################\n";

  int d[4][3][10];
  fill(d[0][0],d[0][0]+4*3*10,0);

  int b,f,r,v;

  for (int i=0;i<n;i++) {
    cin >>b>>f>>r>>v;
    b--;f--;r--;
    d[b][f][r]+=v;
  }

  for (int a=0;a<4;a++) {
    for (int b=0;b<3;b++) {
      for (int c=0;c<10;c++) {
        cout << " " << d[a][b][c];
      }
      cout <<endl;
    }

    if (a<3) cout <<sp;
  }

  return 0;
}



Measured memory_bytes: 3160
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const long long INF = 1LL << 60;
ll MOD = 1e9+7;

int main() {

    int N; cin>>N;
    int Y; cin>>Y;

    for (int i = 0; i <= N; ++i) { // 10000
        for (int j = 0; j <= N-i; ++j) { // 5000
            int k = N-i-j;
            if(10000*i+5000*j+1000*k==Y){
                cout<<i<<" "<<" "<<j<<" "<<k<<endl;
                return 0;
            }
        }
    }

    cout<<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

long long gcd(long long a, long long b){ // Ååöñ
    if(a == 0 || b == 0)
        return 0;
    if(b > a)
        swap(a, b);
    long long tmp;
    while((tmp = a % b) != 0){
        a = b;
        b = tmp;
    }
    return b;
}

long long lcm(long long a, long long b){ // Å¬ö{
    return a / gcd(a, b) * b;
}

int main()
{
    for(;;){
        vector<int> a(3), m(3);
        for(int i=0; i<3; ++i)
            cin >> a[i] >> m[i];
        if(a[0] == 0)
            return 0;

        long long ret = 1;
        for(int i=0; i<3; ++i){
            int x = 1;
            int tmp = 0;
            do{
                x *= a[i];
                x %= m[i];
                ++ tmp;
            }while(x != 1);
            ret = lcm(ret, tmp);
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
import java.util.*;

public class Main {

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

        int zenhan = Integer.parseInt(s.substring(0,2));
        int kouhan = Integer.parseInt(s.substring(2));

        if (isTuki(zenhan)){
            if (isTuki(kouhan)){
                System.out.println("AMBIGUOUS");
            }else {
                System.out.println("MMYY");
            }
        }
        else {
            if (isTuki(kouhan)){
                System.out.println("YYMM");
            }
            else {
                System.out.println("NA");
            }
        }
    }

    private static boolean isTuki (int a){
        return a >= 1 && a <=12;
    }
}

Measured memory_bytes: 22100
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = array[0];
            var B = array[1];

            var result = A - B * 2;
            Console.WriteLine(result < 0 ? 0 : result);
        }

    }
}


Measured memory_bytes: 13268
n=input()
last=-1
#q=[0]*n
now=0
ans=-1
for i in range(n):
    now=input()
    if now>i or now-last>1:
        print -1
        break
    if now==last+1:
        ans+=1
    elif now<=last:
        ans+=now
    last=now
else:
    print ans

Measured memory_bytes: 11012
#include<bits/stdc++.h>
using namespace std;
int main(void){
  signed long long a,b,c,k;cin>>a>>b>>c>>k;
  signed long long cnt=a;
  if(k<a) cnt-=(a-k);
  if((a+b)<k) cnt-=k-(a+b);
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define out(a) printf("%d",a)
using namespace std;
int n;
char c1,c2,c3;
int a,b,c;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
  a=read(); b=read(); c=read();
  a-=c;
  out(a/(b+c));
}

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

int solve(int n, vector<int> &s) {
  vector<bitset<50> > m(n);
  for(int i = 0; i < n; i++)
    m[i].set(i);
    
  for(int i = 1; i <= 30; i++){
    bitset<50> buf;
    for(int j = 0; j < n; j++){
      if(s[j] & (1 << i)){
	buf |= m[j];
	  
	if(buf.count() == n){
	  return i;
	}
      }
    }

    for(int j = 0; j < n; j++)
      if(s[j] & (1 << i))
	m[j] = buf;
      
  }
  return -1;
}

int main() {
  int n;

  while(cin >> n, n) {
    vector<int> s(n, 0);
    int fi, d;
    for(int i = 0; i < n; i++){
      cin >> fi;
      for(int j = 0; j < fi; j++) {
	cin >> d;
	s[i] |= 1 << d;
      } 
    }
    cout << solve(n, s) << endl;
  }
  
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, ans = 0, t, m;
  cin >> n;
  unordered_map<int, int> mp;

  rep(i, n) cin >> t, mp[t]++;

  cin >> m;
  bool flg = true;
  rep(i, m) {
    cin >> t;
    mp[t]--;
    if (mp[t] < 0) {
      flg = false;
      break;
    }
  }

  cout << (flg ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 8520
n, m = map(int, input().split())
edges = [tuple(map(int, input().split())) for _ in range(m)]

par = [i for i in range(n + 1)]
rank = [1 for _ in range(n + 1)]

def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x]

def same(x, y):
    return root(x) == root(y)

def unite(x, y):
    x = root(x)
    y = root(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

for a, b in edges:
    unite(a, b)
memo = [False for _ in range(n + 1)]
ans = 0
for i in range(1, n + 1):
    r = root(i)
    if memo[r] == False:
        memo[r] = True
        ans += 1

print(ans - 1)

Measured memory_bytes: 28048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // Atcoder
    // template: cpp
    ll n, q;
    string s;
    cin >> n >> q;
    cin >> s;
    vector<ll> l(q), r(q);
    rep(i, q) cin >> l[i] >> r[i];

    vector<ll> sum(n + 1, 0);

    for(size_t i = 1; i < n; i++) {
        if(s.at(i - 1) == 'A' && s.at(i) == 'C')
            sum.at(i + 1) = sum.at(i) + 1;
        else
            sum.at(i + 1) = sum.at(i);
    }

    rep(i, q) {
        ll ans = sum.at(r.at(i)) - sum.at(l.at(i));
        cout << ans << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MAX=100005;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,n){cout<<arr[i][j]<<" ";}cout<<endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    Vec b(n-1);
    rep(i,n-1){
        cin>>b[i];
    }
    ll ans=0;

    reverse(ALL(b));
    //dbg(b);
    REP(i,0,n){
        if(i==0){
            ans += b[i];
        }else if(i<n-1){
            ans += min(b[i],b[i-1]);
        }else{
            ans += b[n-2];
        }
        //dbg(ans);
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
inline int newline() { putchar('\n'); return 0; }

int main() {
    ll a, b, c, k;
    cin(a);
    cin(b);
    cin(c);
    cin(k);

    if (a >= k) {
        print(k);
        return 0;
    } else {
        ll h = k - a;
        if (b >= h) {
            print(a);
            return 0;
        } else {
            ll j = h - b;
            print(a - j);
        }
    }

    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int main(){
	int n,x;
	cin >> n >> x;
	vector<long> val(n,0);
	long sum=0;
	for(int i=0;i<n;i++){
		cin >> val[i];
		sum+=val[i];
	}
	long nokori=x-sum;
	sort(val.begin(),val.end());
	long ans=n+nokori/val[0];	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  string s; cin >> s;
  string t; cin >> t;
  int cnt = 0;
  if(s[0] == t[0]) cnt++;
  if(s[1] == t[1]) cnt++;
  if(s[2] == t[2]) cnt++;
  cout << cnt << endl;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())
    ans = 0
    for i in range(1, N + 1):
        ans += len(str(i)) % 2 == 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948